myserver-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myserver-commit] [SCM] GNU MyServer branch, master, updated. 9e8c9870f5


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. 9e8c9870f57de0a2d56861f12de6aef5b561ed45
Date: Sun, 11 Oct 2009 18:49:37 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU MyServer".

The branch, master has been updated
       via  9e8c9870f57de0a2d56861f12de6aef5b561ed45 (commit)
      from  5aeeeb1fce51521bcd6b20b15bd19e3be8173d26 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------


commit 9e8c9870f57de0a2d56861f12de6aef5b561ed45
Author: Giuseppe Scrivano <address@hidden>
Date:   Sun Oct 11 20:49:25 2009 +0200

    Refactor out XML code from `VhostManager' in the new `XmlVhostHandler' 
class.

diff --git a/myserver/include/conf/vhost/Makefile.am 
b/myserver/include/conf/vhost/Makefile.am
index a93f230..327a3ac 100644
--- a/myserver/include/conf/vhost/Makefile.am
+++ b/myserver/include/conf/vhost/Makefile.am
@@ -1,4 +1,4 @@
 vhostincludedir=$(includedir)/myserver/include/conf/vhost
-vhostinclude_HEADERS = vhost.h vhost_manager.h ip.h
+vhostinclude_HEADERS = vhost.h vhost_manager.h ip.h xml_vhost_handler.h
 SUBDIRS =
 
diff --git a/myserver/include/conf/vhost/vhost.h 
b/myserver/include/conf/vhost/vhost.h
index f03a517..a89b9b4 100644
--- a/myserver/include/conf/vhost/vhost.h
+++ b/myserver/include/conf/vhost/vhost.h
@@ -51,8 +51,6 @@ public:
 class Vhost
 {
 public:
-  friend class VhostManager;
-
   struct StringRegex
   {
     string name;
@@ -201,6 +199,14 @@ public:
 
   MimeRecord* getLocationMime (string& loc){return locationsMime.get (loc);}
 
+  list<NodeTree<string>*> *getHashedDataTrees (){return &hashedDataTrees;}
+  HashMap<string, NodeTree<string>*>* getHashedData (){return &hashedData;}
+
+  HashMap<string, MimeRecord*>* getLocationsMime (){return &locationsMime;}
+  MimeRecord *addLocationMime (string &val, MimeRecord *r);
+  MimeManagerHandler *getMimeHandler (){return mimeHandler;}
+  void setMimeHandler (MimeManagerHandler *h){ mimeHandler = h;}
+
 private:
   const static string accessLogType;
   const static string warningLogType;
diff --git a/myserver/include/conf/vhost/vhost_manager.h 
b/myserver/include/conf/vhost/vhost_manager.h
index d2733ea..b5fcfc4 100644
--- a/myserver/include/conf/vhost/vhost_manager.h
+++ b/myserver/include/conf/vhost/vhost_manager.h
@@ -23,54 +23,31 @@
 # include <include/conf/vhost/vhost.h>
 # include <include/log/log_manager.h>
 
-class VhostSource
+class VhostManagerHandler
 {
 public:
-  VhostSource ();
-  ~VhostSource ();
-  int load ();
-  int save ();
-  int free ();
-  Vhost* getVHost (const char*, const char*, u_short);
-  Vhost* getVHostByNumber (int n);
-  int addVHost (Vhost*);
-private:
-  list<Vhost*> *hostList;
+  VhostManagerHandler ();
+  virtual ~VhostManagerHandler ();
+  virtual Vhost* getVHost (const char*, const char*, u_short);
+  virtual Vhost* getVHostByNumber (int n);
+  virtual int addVHost (Vhost*);
 };
 
+/*!
+ * Proxy class to a VhostManagerHandler object.
+*/
 class VhostManager
 {
 public:
-  void setExternalSource (VhostSource* extSource);
-  VhostManager (ListenThreads* lt, LogManager* lm);
-  ~VhostManager ();
-  int getHostsNumber ();
-  Vhost* getVHostByNumber (int n);
-  void clean ();
-  int removeVHost (int n);
-  int switchVhosts (int n1,int n2);
-  list<Vhost*>* getVHostList ();
+  VhostManager ();
+  void setHandler (VhostManagerHandler *handler);
 
   /*! Get a pointer to a vhost.  */
   Vhost* getVHost (const char*,const char*,u_short);
+  Vhost* getVHostByNumber (int n);
 
-  /*! Add an element to the vhost list.  */
-  int addVHost (Vhost*);
-
-  /*! Load the virtual hosts list from a xml configuration file.  */
-  int loadXMLConfigurationFile (const char *);
-
-  /*! Set the right owner for the log locations.  */
-  void changeLocationsOwner ();
-private:
-  void loadXMLlogData (string, Vhost*, xmlNode*);
-  ListenThreads* listenThreads;
-  Mutex mutex;
-  VhostSource* extSource;
-
-  /*! List of virtual hosts. */
-  list<Vhost*> hostList;
-  LogManager* logManager;
+protected:
+  VhostManagerHandler *handler;
 };
 
 #endif
diff --git a/myserver/include/conf/vhost/vhost_manager.h 
b/myserver/include/conf/vhost/xml_vhost_handler.h
similarity index 72%
copy from myserver/include/conf/vhost/vhost_manager.h
copy to myserver/include/conf/vhost/xml_vhost_handler.h
index d2733ea..f48b2c0 100644
--- a/myserver/include/conf/vhost/vhost_manager.h
+++ b/myserver/include/conf/vhost/xml_vhost_handler.h
@@ -16,34 +16,18 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#ifndef VHOST_MANAGER_H
-# define VHOST_MANAGER_H
+#ifndef XML_VHOST_H
+# define XML_VHOST_H
 
 # include "stdafx.h"
-# include <include/conf/vhost/vhost.h>
-# include <include/log/log_manager.h>
+# include <include/conf/vhost/vhost_manager.h>
 
-class VhostSource
+class XmlVhostHandler : public VhostManagerHandler
 {
 public:
-  VhostSource ();
-  ~VhostSource ();
-  int load ();
-  int save ();
-  int free ();
-  Vhost* getVHost (const char*, const char*, u_short);
-  Vhost* getVHostByNumber (int n);
-  int addVHost (Vhost*);
-private:
-  list<Vhost*> *hostList;
-};
-
-class VhostManager
-{
-public:
-  void setExternalSource (VhostSource* extSource);
-  VhostManager (ListenThreads* lt, LogManager* lm);
-  ~VhostManager ();
+  void setExternalSource (VhostManagerHandler* extSource);
+  XmlVhostHandler (ListenThreads* lt, LogManager* lm);
+  ~XmlVhostHandler ();
   int getHostsNumber ();
   Vhost* getVHostByNumber (int n);
   void clean ();
@@ -66,7 +50,7 @@ private:
   void loadXMLlogData (string, Vhost*, xmlNode*);
   ListenThreads* listenThreads;
   Mutex mutex;
-  VhostSource* extSource;
+  VhostManagerHandler* extSource;
 
   /*! List of virtual hosts. */
   list<Vhost*> hostList;
diff --git a/myserver/include/server/server.h b/myserver/include/server/server.h
index d438414..53e3322 100644
--- a/myserver/include/server/server.h
+++ b/myserver/include/server/server.h
@@ -29,6 +29,7 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>.
 # include <include/base/sync/event.h>
 # include <include/conf/mime/mime_manager.h>
 # include <include/conf/vhost/vhost_manager.h>
+# include <include/conf/vhost/xml_vhost_handler.h>
 # include <include/protocol/protocols_manager.h>
 # include <include/connection/connection.h>
 # include <include/log/log_manager.h>
@@ -142,7 +143,7 @@ public:
   ListenThreads *getListenThreads (){return &listenThreads;}
 
   void *getEnvString (){return envString;}
-  VhostManager *getVhosts (){return vhostList;}
+  VhostManager *getVhosts (){return &vhostList;}
   MimeManager *getMimeManager (){return &mimeManager;}
 
   void setProcessPermissions ();
@@ -167,6 +168,7 @@ private:
   friend class ClientsThread;
   XmlValidator *xmlValidator;
   XmlMimeHandler xmlMimeHandler;
+  XmlVhostHandler *vhostHandler;
 
   MainConfiguration *configurationFileManager;
   MainConfiguration* (*genMainConf) (Server *server, const char *arg);
@@ -201,7 +203,7 @@ private:
   CachedFileFactory cachedFiles;
 
   void *envString;
-  VhostManager *vhostList;
+  VhostManager vhostList;
   MimeManager mimeManager;
   HomeDir homeDir;
 
diff --git a/myserver/src/conf/vhost/Makefile.am 
b/myserver/src/conf/vhost/Makefile.am
index eae6e17..e7af0be 100644
--- a/myserver/src/conf/vhost/Makefile.am
+++ b/myserver/src/conf/vhost/Makefile.am
@@ -1,5 +1,5 @@
 lib_LIBRARIES = libvhost.a
-libvhost_a_SOURCES = vhost.cpp vhost_manager.cpp ip.cpp
+libvhost_a_SOURCES = vhost.cpp vhost_manager.cpp ip.cpp xml_vhost_handler.cpp
 SUBDIRS =
 AM_CPPFLAGS = $(all_includes)
 
diff --git a/myserver/src/conf/vhost/vhost.cpp 
b/myserver/src/conf/vhost/vhost.cpp
index 9e0ba69..869459e 100644
--- a/myserver/src/conf/vhost/vhost.cpp
+++ b/myserver/src/conf/vhost/vhost.cpp
@@ -496,3 +496,15 @@ int Vhost::freeSSL ()
 {
   return sslContext.free ();
 }
+
+/*!
+ * Add a new location->mime association.
+ *
+ * \param location Location where use the specified mime type.
+ * \param record The MIME type to use.
+ * \return The MIME record previously registered on the location, if any.
+ */
+MimeRecord *Vhost::addLocationMime (string &location, MimeRecord *record)
+{
+  return locationsMime.put (location, record);
+}
diff --git a/myserver/src/conf/vhost/vhost_manager.cpp 
b/myserver/src/conf/vhost/vhost_manager.cpp
index 8e0cfb0..868dabe 100644
--- a/myserver/src/conf/vhost/vhost_manager.cpp
+++ b/myserver/src/conf/vhost/vhost_manager.cpp
@@ -23,533 +23,62 @@
 
 #include <include/conf/xml_conf.h>
 
-/*!
- *VhostManager add function.
- *\param vh The virtual host to add.
- */
-int VhostManager::addVHost (Vhost* vh)
+VhostManagerHandler::VhostManagerHandler ()
 {
-  list<Vhost*>::iterator it;
-
-  mutex.lock ();
-
-  /* Be sure there is a listening thread on the specified port.  */
-  listenThreads->addListeningThread (vh->getPort ());
-
-  if (extSource)
-    {
-      int ret = extSource->addVHost (vh);
-      mutex.unlock ();
-      return ret;
-    }
-
-  it = hostList.begin ();
-
-  try
-    {
-      if (!vh->getProtocolName ())
-        {
-          vh->setProtocolName ("http");
-          Server::getInstance ()->log (MYSERVER_LOG_MSG_WARNING,
-                 _("Protocol not defined for vhost: %s, using HTTP by 
default"),
-                                             vh->getName ());
-        }
-      string protocol (vh->getProtocolName ());
-      if (Server::getInstance ()->getProtocolsManager ()->getProtocol 
(protocol)
-          == NULL)
-        Server::getInstance ()->log (MYSERVER_LOG_MSG_ERROR,
-                                _("The protocol \"%s\" is used but not 
loaded"),
-                                    protocol.c_str ());
-
-      hostList.push_back (vh);
-      mutex.unlock ();
-      return 0;
-    }
-  catch (...)
-    {
-      mutex.unlock ();
-      return -1;
-    };
 }
 
-/*!
- *Get the vhost for the connection. A return value of 0 means that
- *a valid host was not found.
- *\param host Hostname for the virtual host.
- *\param ip IP address for the virtual host.
- *\param port The port used by the client to connect to the server.
- */
-Vhost* VhostManager::getVHost (const char* host, const char* ip, u_short port)
+VhostManagerHandler::~VhostManagerHandler ()
 {
-  list<Vhost*>::iterator it;
-
-  mutex.lock ();
-
-  try
-    {
-      if (extSource)
-        {
-          Vhost* ret = extSource->getVHost (host, ip, port);
-          mutex.unlock ();
-          return ret;
-        }
-
-      it = hostList.begin ();
-
-      /*Do a linear search here. We have to use the first full-matching
-       *virtual host.
-       */
-      for (; it != hostList.end (); it++)
-        {
-          Vhost* vh = *it;
-          /* Control if the host port is the correct one.  */
-          if (vh->getPort () != port)
-            continue;
-          /* If ip is defined check that it is allowed to connect to the host. 
 */
-          if (ip && !vh->isIPAllowed (ip))
-            continue;
-          /* If host is defined check if it is allowed to connect to the host. 
 */
-          if (host && !vh->isHostAllowed (host))
-            continue;
-          /* We find a valid host.  */
-          mutex.unlock ();
-          /* Add a reference.  */
-          vh->addRef ();
-          return vh;
-        }
-      mutex.unlock ();
-      return 0;
-    }
-  catch (...)
-    {
-      mutex.unlock ();
-      return 0;
-    };
 }
 
-/*!
- *VhostManager costructor.
- *\param lt A ListenThreads object to use to create new threads.
- *\param lm The log manager to use.
- */
-VhostManager::VhostManager (ListenThreads* lt, LogManager* lm)
+Vhost* VhostManagerHandler::getVHost (const char*, const char*, u_short)
 {
-  listenThreads = lt;
-  hostList.clear ();
-  extSource = 0;
-  mutex.init ();
-  logManager = lm;
+  return NULL;
 }
 
-/*!
- *Clean the virtual hosts.
- */
-void VhostManager::clean ()
+Vhost* VhostManagerHandler::getVHostByNumber (int n)
 {
-  list<Vhost*>::iterator it;
-
-  mutex.lock ();
-
-  it = hostList.begin ();
-
-  try
-    {
-      for (;it != hostList.end (); it++)
-        delete *it;
-
-      hostList.clear ();
-
-      mutex.unlock ();
-    }
-  catch (...)
-    {
-      mutex.unlock ();
-      return;
-    };
+  return 0;
 }
 
-/*!
- *vhostmanager destructor.
- */
-VhostManager::~VhostManager ()
+int VhostManagerHandler::addVHost (Vhost*)
 {
-  clean ();
-  mutex.destroy ();
-}
-
-/*!
- *Returns the entire virtual hosts list.
- */
-list<Vhost*>* VhostManager::getVHostList ()
-{
-  return &(this->hostList);
+  return 0;
 }
 
 /*!
- *Change the file owner for the log locations.
+ * C'tor.
  */
-void VhostManager::changeLocationsOwner ()
+VhostManager::VhostManager ()
 {
-  if (Server::getInstance ()->getUid () ||
-     Server::getInstance ()->getGid ())
-    {
-      string uid (Server::getInstance ()->getUid ());
-      string gid (Server::getInstance ()->getGid ());
-
-      /*
-       *Change the log files owner if a different user or group
-       *identifier is specified.
-       */
-      for (list<Vhost*>::iterator it = hostList.begin (); it != hostList.end 
(); it++)
-        {
-          int err;
-          Vhost* vh = *it;
-
-          /* Chown the log files.  */
-          err = logManager->chown (vh, "ACCESSLOG", uid, gid);
-          if (err)
-            Server::getInstance ()->log (MYSERVER_LOG_MSG_ERROR,
-                    _("Error while changing accesses log locations owner"));
-
-          err = logManager->chown (vh, "WARNINGLOG", uid, gid);
-          if (err)
-            Server::getInstance ()->log (MYSERVER_LOG_MSG_ERROR,
-                    _("Error while changing log locations owner"));
-        }
-    }
+  handler = NULL;
 }
 
-
 /*!
- *Returns the number of hosts in the list
+ * Set the handler where delegate all requests.
+ *
+ *\param handler The new handler.
  */
-int VhostManager::getHostsNumber ()
+void VhostManager::setHandler (VhostManagerHandler *handler)
 {
-  return hostList.size ();
+  this->handler = handler;
 }
 
-
 /*!
- *Load a log XML node.
+ *Get the vhost for the connection. A return value of 0 means that
+ *a valid host was not found.
+ *\param host Hostname for the virtual host.
+ *\param ip IP address for the virtual host.
+ *\param port The port used by the client to connect to the server.
  */
-void
-VhostManager::loadXMLlogData (string name, Vhost* vh, xmlNode* lcur)
+Vhost* VhostManager::getVHost (const char *host, const char *ip, u_short port)
 {
-  xmlAttr *attr;
-  string opt;
-  attr = lcur->properties;
-  while (attr)
-    {
-      opt.append ((char*)attr->name);
-      opt.append ("=");
-      opt.append ((char*)attr->children->content);
-      if (attr->next)
-        {
-          opt.append (",");
-        }
-      attr = attr->next;
-    }
-  string location;
-  list<string> filters;
-  u_long cycle;
-  xmlNode* stream = lcur->children;
-  for (; stream; stream = stream->next, location.assign (""), cycle = 0, 
filters.clear ())
-    {
-      if (stream->type == XML_ELEMENT_NODE &&
-          !xmlStrcmp (stream->name, (xmlChar const*)"STREAM"))
-        {
-          xmlAttr* streamAttr = stream->properties;
-          while (streamAttr)
-            {
-              if (!strcmp ((char*)streamAttr->name, "location"))
-                {
-                  location.assign ((char*)streamAttr->children->content);
-                }
-              else if (!strcmp ((char*)streamAttr->name, "cycle"))
-                {
-                  cycle = atoi ((char*)streamAttr->children->content);
-                }
-              streamAttr = streamAttr->next;
-            }
-          xmlNode* filterList = stream->children;
-          for (; filterList; filterList = filterList->next)
-            {
-              if (filterList->type == XML_ELEMENT_NODE &&
-                  !xmlStrcmp (filterList->name, (xmlChar const*)"FILTER"))
-                {
-                  if (filterList->children && filterList->children->content)
-                    {
-                      string filter ((char*)filterList->children->content);
-                      filters.push_back (filter);
-                    }
-                }
-            }
-          int err = 1;
-          string str ("VhostManager::loadXMLlogData : Unrecognized log type");
+  if (handler)
+    return handler->getVHost (host, ip, port);
 
-          if (!name.compare ("ACCESSLOG"))
-            {
-              err = vh->openAccessLog (location, filters, cycle);
-              vh->setAccessLogOpt (opt.c_str ());
-              if (err)
-                Server::getInstance ()->log (MYSERVER_LOG_MSG_ERROR,
-                                                   _("Error opening %s"), 
location.c_str ());
-            }
-          else if (!name.compare ("WARNINGLOG"))
-            {
-              err = vh->openWarningLog (location, filters, cycle);
-              vh->setWarningLogOpt (opt.c_str ());
-              if (err)
-                Server::getInstance ()->log (MYSERVER_LOG_MSG_ERROR,
-                                                   _("Error opening %s"), 
location.c_str ());
-            }
-          else
-            Server::getInstance ()->log (MYSERVER_LOG_MSG_ERROR,
-                                               _(" Unrecognized log type"));
-        }
-    }
+  return NULL;
 }
 
-/*!
- *Load the virtual hosts from a XML configuration file
- *Returns non-null on errors.
- *\param filename The XML file to open.
- */
-int VhostManager::loadXMLConfigurationFile (const char *filename)
-{
-  XmlParser parser;
-  xmlDocPtr doc;
-  xmlNodePtr node;
-  if (parser.open (filename))
-    {
-      Server::getInstance ()->log (MYSERVER_LOG_MSG_ERROR,
-                                         _("Error opening %s"), filename);
-      return -1;
-    }
-  doc = parser.getDoc ();
-  node = doc->children->children;
-
-  for (;node;node = node->next )
-    {
-      xmlNodePtr lcur;
-      Vhost *vh;
-      if (xmlStrcmp (node->name, (const xmlChar *)"VHOST"))
-        continue;
-      lcur = node->children;
-      vh = new Vhost (logManager);
-      if (vh == 0)
-        {
-          parser.close ();
-          clean ();
-          Server::getInstance ()->log (MYSERVER_LOG_MSG_ERROR,
-                                             _("internal error"), filename);
-          return -1;
-        }
-
-      SslContext* sslContext = vh->getVhostSSLContext ();
-
-      while (lcur)
-        {
-          XmlConf::build (lcur,
-                          &vh->hashedDataTrees,
-                          &vh->hashedData);
-
-          if (!xmlStrcmp (lcur->name, (const xmlChar *)"HOST"))
-            {
-              int useRegex = 0;
-              for (xmlAttr *attrs = lcur->properties; attrs; attrs = 
attrs->next)
-                {
-                  if (!xmlStrcmp (attrs->name, (const xmlChar *)"isRegex")
-                      && attrs->children && attrs->children->content
-                      && (!xmlStrcmp (attrs->children->content,
-                                     (const xmlChar *)"YES")))
-                        useRegex = 1;
-                }
-
-              vh->addHost ((const char*)lcur->children->content, useRegex);
-            }
-          else if (!xmlStrcmp (lcur->name, (const xmlChar *)"NAME"))
-            {
-              vh->setName ((char*)lcur->children->content);
-            }
-          else if (!xmlStrcmp (lcur->name, (const xmlChar *)"LOCATION"))
-            {
-              string loc (vh->getDocumentRoot ());
-              loc.append ("/");
-              for (xmlAttr *attrs = lcur->properties; attrs; attrs = 
attrs->next)
-                {
-                  if (!xmlStrcmp (attrs->name, (const xmlChar *)"path"))
-                    loc.append ((const char*) attrs->children->content);
-                }
-
-              MimeRecord *rc = XmlMimeHandler::readRecord (lcur);
-              vh->locationsMime.put (loc, rc);
-            }
-          else if (!xmlStrcmp (lcur->name, (const xmlChar *)"SSL_PRIVATEKEY"))
-            {
-              string pk ((char*)lcur->children->content);
-              sslContext->setPrivateKeyFile (pk);
-            }
-          else if (!xmlStrcmp (lcur->name, (const xmlChar *)"SSL_CERTIFICATE"))
-            {
-              string certificate ((char*)lcur->children->content);
-              sslContext->setCertificateFile (certificate);
-            }
-          else if (!xmlStrcmp (lcur->name, (const xmlChar 
*)"CONNECTIONS_PRIORITY"))
-            {
-              vh->setDefaultPriority (atoi ((const 
char*)lcur->children->content));
-
-            }
-          else if (!xmlStrcmp (lcur->name, (const xmlChar *)"SSL_PASSWORD"))
-            {
-              string pw;
-              if (lcur->children)
-                pw.assign ((char*)lcur->children->content);
-              else
-                pw.assign ("");
-
-              sslContext->setPassword (pw);
-            }
-          else if (!xmlStrcmp (lcur->name, (const xmlChar *)"IP"))
-            {
-              int useRegex = 0;
-              xmlAttr *attrs = lcur->properties;
-
-              while (attrs)
-                {
-                  if (!xmlStrcmp (attrs->name, (const xmlChar *)"isRegex"))
-                    {
-                      if (attrs->children && attrs->children->content &&
-                          (!xmlStrcmp (attrs->children->content,
-                                      (const xmlChar *)"YES")))
-                        useRegex = 1;
-                    }
-                  attrs = attrs->next;
-                }
-              vh->addIP ((char*)lcur->children->content, useRegex);
-            }
-          else if (!xmlStrcmp (lcur->name, (const xmlChar *)"PORT"))
-            {
-              int val = atoi ((char*)lcur->children->content);
-              if (val > (1 << 16) || strlen ((const 
char*)lcur->children->content) > 6)
-                Server::getInstance ()->log (MYSERVER_LOG_MSG_ERROR,
-                       _("Specified invalid port %s"), 
lcur->children->content);
-              vh->setPort ((u_short)val);
-            }
-          else if (!xmlStrcmp (lcur->name, (const xmlChar *)"PROTOCOL"))
-            {
-              char* lastChar = (char*)lcur->children->content;
-              while (*lastChar != '\0')
-                {
-                  *lastChar = tolower (*lastChar);
-                  lastChar++;
-                }
-              vh->setProtocolName ((char*)lcur->children->content);
-            }
-          else if (!xmlStrcmp (lcur->name, (const xmlChar *)"DOCROOT"))
-            {
-              if (lcur->children && lcur->children->content)
-                {
-                  char* lastChar = (char*)lcur->children->content;
-                  while (*(lastChar+1) != '\0')
-                    lastChar++;
-
-                  if (*lastChar == '\\' || *lastChar == '/')
-                    *lastChar = '\0';
-
-                  vh->setDocumentRoot ((const char*)lcur->children->content);
-                }
-              else
-                vh->setDocumentRoot ("");
-            }
-          else if (!xmlStrcmp (lcur->name, (const xmlChar *)"SYSROOT"))
-            {
-              if (lcur->children && lcur->children->content)
-                {
-                  char* lastChar = (char*)lcur->children->content;
-
-                  while (*(lastChar+1) != '\0')
-                    lastChar++;
-
-                  if (*lastChar == '\\' || *lastChar == '/')
-                    *lastChar = '\0';
-
-                  vh->setSystemRoot ((const char*)lcur->children->content);
-                }
-              else
-                vh->setSystemRoot ("");
-            }
-          else if (!xmlStrcmp (lcur->name, (const xmlChar *)"ACCESSLOG"))
-            {
-              loadXMLlogData ("ACCESSLOG", vh, lcur);
-            }
-          else if (!xmlStrcmp (lcur->name, (const xmlChar *)"WARNINGLOG"))
-            {
-              loadXMLlogData ("WARNINGLOG", vh, lcur);
-            }
-          else if (!xmlStrcmp (lcur->name, (const xmlChar *)"MIME_FILE"))
-            {
-              if (lcur->children)
-                {
-                  const char *filename = (const char*)lcur->children->content;
-                  XmlMimeHandler *xmlHandler = new XmlMimeHandler ();
-                  try
-                    {
-                      xmlHandler->loadXML (filename);
-                    }
-                  catch (...)
-                    {
-                      delete xmlHandler;
-                      xmlHandler = NULL;
-                      Server::getInstance ()->log (MYSERVER_LOG_MSG_ERROR,
-                                               _("Error loading %s"), 
filename);
-
-                    }
-                  vh->mimeHandler = xmlHandler;
-                }
-            }
-          else if (!xmlStrcmp (lcur->name, (const xmlChar *)"THROTTLING_RATE"))
-            {
-              vh->setThrottlingRate ((u_long)atoi 
((char*)lcur->children->content));
-            }
-
-          lcur = lcur->next;
-        }// while (lcur)
-
-      if (vh->openLogFiles ())
-        {
-          Server::getInstance ()->log (MYSERVER_LOG_MSG_ERROR,
-                                             _("Error opening log files"));
-          delete vh;
-          vh = 0;
-          continue;
-        }
-
-      if (vh->initializeSSL () < 0)
-        {
-          Server::getInstance ()->log (MYSERVER_LOG_MSG_ERROR,
-                                             _("Error initializing SSL for 
%s"),
-                                             vh->getName ());
-          delete vh;
-          vh = 0;
-          continue;
-        }
-
-      if (addVHost (vh))
-        {
-          Server::getInstance ()->log (MYSERVER_LOG_MSG_ERROR,
-                                             _("Internal error"));
-          delete vh;
-          vh = 0;
-          continue;
-        }
-    }
-  parser.close ();
-
-  changeLocationsOwner ();
-
-  return 0;
-}
 
 /*!
  *Get a virtual host by its position in the list.
@@ -558,140 +87,8 @@ int VhostManager::loadXMLConfigurationFile (const char 
*filename)
  */
 Vhost* VhostManager::getVHostByNumber (int n)
 {
-  Vhost* ret = 0;
-  mutex.lock ();
-  try
-    {
-      list<Vhost*>::iterator i = hostList.begin ();
-      if (extSource)
-        {
-          ret=extSource->getVHostByNumber (n);
-          mutex.unlock ();
-          return ret;
-        }
-
-      for ( ; i != hostList.end (); i++)
-        {
-          if (!(n--))
-            {
-              ret = *i;
-              ret->addRef ();
-              break;
-            }
-        }
-      mutex.unlock ();
-
-      return ret;
-    }
-  catch (...)
-    {
-      mutex.unlock ();
-      return ret;
-    };
-}
-
-/*!
- *Remove a virtual host by its position in the list
- *First position is zero.
- *\param n The virtual host identifier in the list.
- */
-int VhostManager::removeVHost (int n)
-{
-  mutex.lock ();
-  try
-    {
-      list<Vhost*>::iterator i = hostList.begin ();
-
-      for ( ;i != hostList.end (); i++)
-        {
-          if (!(n--))
-            {
-              delete *i;
-              mutex.unlock ();
-              return 1;
-            }
-        }
-      mutex.unlock ();
-      return 0;
-    }
-  catch (...)
-    {
-      mutex.unlock ();
-      return 0;
-    };
-}
-
-/*!
- *Set an external source for the virtual hosts.
- *\param nExtSource The new external source.
- */
-void VhostManager::setExternalSource (VhostSource* nExtSource)
-{
-  mutex.lock ();
-  extSource = nExtSource;
-  mutex.unlock ();
-}
-
-/*!
- *Construct the object.
- */
-VhostSource::VhostSource ()
-{
-
-}
-
-/*!
- *Destroy the object.
- */
-VhostSource::~VhostSource ()
-{
-
-}
-
-/*!
- *Load the object.
- */
-int VhostSource::load ()
-{
-  return 0;
-}
-
-/*!
- *Save the object.
- */
-int VhostSource::save ()
-{
-  return 0;
-}
-
-/*!
- *Free the object.
- */
-int VhostSource::free ()
-{
-  return 0;
-}
+  if (handler)
+    return handler->getVHostByNumber (n);
 
-/*!
- *Add a virtual host to the source.
- */
-int VhostSource::addVHost (Vhost*)
-{
-  return 0;
-}
-
-/*!
- *Get a virtual host.
- */
-Vhost* VhostSource::getVHost (const char*, const char*, u_short)
-{
-  return 0;
-}
-
-/*!
- *Get a virtual host by its number.
- */
-Vhost* VhostSource::getVHostByNumber (int n)
-{
-  return 0;
+  return NULL;
 }
diff --git a/myserver/src/conf/vhost/vhost_manager.cpp 
b/myserver/src/conf/vhost/xml_vhost_handler.cpp
similarity index 86%
copy from myserver/src/conf/vhost/vhost_manager.cpp
copy to myserver/src/conf/vhost/xml_vhost_handler.cpp
index 8e0cfb0..8315a57 100644
--- a/myserver/src/conf/vhost/vhost_manager.cpp
+++ b/myserver/src/conf/vhost/xml_vhost_handler.cpp
@@ -14,7 +14,7 @@
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
-#include <include/conf/vhost/vhost_manager.h>
+#include <include/conf/vhost/xml_vhost_handler.h>
 #include <include/conf/vhost/vhost.h>
 #include <include/conf/mime/xml_mime_handler.h>
 #include <include/server/server.h>
@@ -24,10 +24,10 @@
 #include <include/conf/xml_conf.h>
 
 /*!
- *VhostManager add function.
+ *XmlVhostHandler add function.
  *\param vh The virtual host to add.
  */
-int VhostManager::addVHost (Vhost* vh)
+int XmlVhostHandler::addVHost (Vhost* vh)
 {
   list<Vhost*>::iterator it;
 
@@ -36,13 +36,6 @@ int VhostManager::addVHost (Vhost* vh)
   /* Be sure there is a listening thread on the specified port.  */
   listenThreads->addListeningThread (vh->getPort ());
 
-  if (extSource)
-    {
-      int ret = extSource->addVHost (vh);
-      mutex.unlock ();
-      return ret;
-    }
-
   it = hostList.begin ();
 
   try
@@ -73,13 +66,9 @@ int VhostManager::addVHost (Vhost* vh)
 }
 
 /*!
- *Get the vhost for the connection. A return value of 0 means that
- *a valid host was not found.
- *\param host Hostname for the virtual host.
- *\param ip IP address for the virtual host.
- *\param port The port used by the client to connect to the server.
+ *\see VhostManager#getVHost
  */
-Vhost* VhostManager::getVHost (const char* host, const char* ip, u_short port)
+Vhost* XmlVhostHandler::getVHost (const char* host, const char* ip, u_short 
port)
 {
   list<Vhost*>::iterator it;
 
@@ -87,13 +76,6 @@ Vhost* VhostManager::getVHost (const char* host, const char* 
ip, u_short port)
 
   try
     {
-      if (extSource)
-        {
-          Vhost* ret = extSource->getVHost (host, ip, port);
-          mutex.unlock ();
-          return ret;
-        }
-
       it = hostList.begin ();
 
       /*Do a linear search here. We have to use the first full-matching
@@ -128,15 +110,14 @@ Vhost* VhostManager::getVHost (const char* host, const 
char* ip, u_short port)
 }
 
 /*!
- *VhostManager costructor.
+ *XmlVhostHandler costructor.
  *\param lt A ListenThreads object to use to create new threads.
  *\param lm The log manager to use.
  */
-VhostManager::VhostManager (ListenThreads* lt, LogManager* lm)
+XmlVhostHandler::XmlVhostHandler (ListenThreads* lt, LogManager* lm)
 {
   listenThreads = lt;
   hostList.clear ();
-  extSource = 0;
   mutex.init ();
   logManager = lm;
 }
@@ -144,7 +125,7 @@ VhostManager::VhostManager (ListenThreads* lt, LogManager* 
lm)
 /*!
  *Clean the virtual hosts.
  */
-void VhostManager::clean ()
+void XmlVhostHandler::clean ()
 {
   list<Vhost*>::iterator it;
 
@@ -171,7 +152,7 @@ void VhostManager::clean ()
 /*!
  *vhostmanager destructor.
  */
-VhostManager::~VhostManager ()
+XmlVhostHandler::~XmlVhostHandler ()
 {
   clean ();
   mutex.destroy ();
@@ -180,7 +161,7 @@ VhostManager::~VhostManager ()
 /*!
  *Returns the entire virtual hosts list.
  */
-list<Vhost*>* VhostManager::getVHostList ()
+list<Vhost*>* XmlVhostHandler::getVHostList ()
 {
   return &(this->hostList);
 }
@@ -188,7 +169,7 @@ list<Vhost*>* VhostManager::getVHostList ()
 /*!
  *Change the file owner for the log locations.
  */
-void VhostManager::changeLocationsOwner ()
+void XmlVhostHandler::changeLocationsOwner ()
 {
   if (Server::getInstance ()->getUid () ||
      Server::getInstance ()->getGid ())
@@ -223,7 +204,7 @@ void VhostManager::changeLocationsOwner ()
 /*!
  *Returns the number of hosts in the list
  */
-int VhostManager::getHostsNumber ()
+int XmlVhostHandler::getHostsNumber ()
 {
   return hostList.size ();
 }
@@ -233,7 +214,7 @@ int VhostManager::getHostsNumber ()
  *Load a log XML node.
  */
 void
-VhostManager::loadXMLlogData (string name, Vhost* vh, xmlNode* lcur)
+XmlVhostHandler::loadXMLlogData (string name, Vhost* vh, xmlNode* lcur)
 {
   xmlAttr *attr;
   string opt;
@@ -285,7 +266,7 @@ VhostManager::loadXMLlogData (string name, Vhost* vh, 
xmlNode* lcur)
                 }
             }
           int err = 1;
-          string str ("VhostManager::loadXMLlogData : Unrecognized log type");
+          string str ("XmlVhostHandler::loadXMLlogData : Unrecognized log 
type");
 
           if (!name.compare ("ACCESSLOG"))
             {
@@ -315,7 +296,7 @@ VhostManager::loadXMLlogData (string name, Vhost* vh, 
xmlNode* lcur)
  *Returns non-null on errors.
  *\param filename The XML file to open.
  */
-int VhostManager::loadXMLConfigurationFile (const char *filename)
+int XmlVhostHandler::loadXMLConfigurationFile (const char *filename)
 {
   XmlParser parser;
   xmlDocPtr doc;
@@ -350,9 +331,8 @@ int VhostManager::loadXMLConfigurationFile (const char 
*filename)
 
       while (lcur)
         {
-          XmlConf::build (lcur,
-                          &vh->hashedDataTrees,
-                          &vh->hashedData);
+          XmlConf::build (lcur, vh->getHashedDataTrees (),
+                          vh->getHashedData ());
 
           if (!xmlStrcmp (lcur->name, (const xmlChar *)"HOST"))
             {
@@ -383,7 +363,8 @@ int VhostManager::loadXMLConfigurationFile (const char 
*filename)
                 }
 
               MimeRecord *rc = XmlMimeHandler::readRecord (lcur);
-              vh->locationsMime.put (loc, rc);
+              vh->addLocationMime (loc, rc);
+              vh->getLocationsMime ()->put (loc, rc);
             }
           else if (!xmlStrcmp (lcur->name, (const xmlChar *)"SSL_PRIVATEKEY"))
             {
@@ -505,7 +486,7 @@ int VhostManager::loadXMLConfigurationFile (const char 
*filename)
                                                _("Error loading %s"), 
filename);
 
                     }
-                  vh->mimeHandler = xmlHandler;
+                  vh->setMimeHandler (xmlHandler);
                 }
             }
           else if (!xmlStrcmp (lcur->name, (const xmlChar *)"THROTTLING_RATE"))
@@ -552,24 +533,15 @@ int VhostManager::loadXMLConfigurationFile (const char 
*filename)
 }
 
 /*!
- *Get a virtual host by its position in the list.
- *Zero based list.
- *\param n The virtual host id.
+ *\see VhostManager#getVHostByNumber
  */
-Vhost* VhostManager::getVHostByNumber (int n)
+Vhost* XmlVhostHandler::getVHostByNumber (int n)
 {
   Vhost* ret = 0;
   mutex.lock ();
   try
     {
       list<Vhost*>::iterator i = hostList.begin ();
-      if (extSource)
-        {
-          ret=extSource->getVHostByNumber (n);
-          mutex.unlock ();
-          return ret;
-        }
-
       for ( ; i != hostList.end (); i++)
         {
           if (!(n--))
@@ -595,7 +567,7 @@ Vhost* VhostManager::getVHostByNumber (int n)
  *First position is zero.
  *\param n The virtual host identifier in the list.
  */
-int VhostManager::removeVHost (int n)
+int XmlVhostHandler::removeVHost (int n)
 {
   mutex.lock ();
   try
@@ -620,78 +592,3 @@ int VhostManager::removeVHost (int n)
       return 0;
     };
 }
-
-/*!
- *Set an external source for the virtual hosts.
- *\param nExtSource The new external source.
- */
-void VhostManager::setExternalSource (VhostSource* nExtSource)
-{
-  mutex.lock ();
-  extSource = nExtSource;
-  mutex.unlock ();
-}
-
-/*!
- *Construct the object.
- */
-VhostSource::VhostSource ()
-{
-
-}
-
-/*!
- *Destroy the object.
- */
-VhostSource::~VhostSource ()
-{
-
-}
-
-/*!
- *Load the object.
- */
-int VhostSource::load ()
-{
-  return 0;
-}
-
-/*!
- *Save the object.
- */
-int VhostSource::save ()
-{
-  return 0;
-}
-
-/*!
- *Free the object.
- */
-int VhostSource::free ()
-{
-  return 0;
-}
-
-/*!
- *Add a virtual host to the source.
- */
-int VhostSource::addVHost (Vhost*)
-{
-  return 0;
-}
-
-/*!
- *Get a virtual host.
- */
-Vhost* VhostSource::getVHost (const char*, const char*, u_short)
-{
-  return 0;
-}
-
-/*!
- *Get a virtual host by its number.
- */
-Vhost* VhostSource::getVHostByNumber (int n)
-{
-  return 0;
-}
diff --git a/myserver/src/server/server.cpp b/myserver/src/server/server.cpp
index a0fe8cc..d4038fe 100644
--- a/myserver/src/server/server.cpp
+++ b/myserver/src/server/server.cpp
@@ -74,7 +74,7 @@ Server::Server () : connectionsScheduler (this),
   throttlingRate = 0;
   path = 0;
   ipAddresses = 0;
-  vhostList = 0;
+  vhostHandler = NULL;
   purgeThreadsThreshold = 1;
   freeThreads = 0;
   logManager = new LogManager (&filtersFactory);
@@ -131,14 +131,13 @@ int Server::loadLibraries ()
   return 0;
 }
 
-
 /*!
  * Destroy the object.
  */
 Server::~Server ()
 {
-  if (vhostList)
-    delete vhostList;
+  if (vhostHandler)
+    delete vhostHandler;
 
   if (xmlValidator)
     delete xmlValidator;
@@ -279,13 +278,8 @@ int Server::postLoad ()
 
   listenThreads.initialize ();
 
-  if (vhostList)
-    delete vhostList;
-
-  vhostList = new VhostManager (&listenThreads, logManager);
-
-  if (vhostList == NULL)
-    return -1;
+  vhostHandler = new XmlVhostHandler (&listenThreads, logManager);
+  vhostList.setHandler (vhostHandler);
 
   getProcessServerManager ()->load ();
 
@@ -295,7 +289,7 @@ int Server::postLoad ()
   loadPlugins ();
 
   /* Load the virtual hosts configuration from the xml file.  */
-  vhostList->loadXMLConfigurationFile (vhostConfigurationFile.c_str ());
+  vhostHandler->loadXMLConfigurationFile (vhostConfigurationFile.c_str ());
 
   if (path == 0)
     path = new string ();
@@ -432,7 +426,7 @@ void Server::mainLoop ()
                 }
               else if (hostsConfTimeNow != hostsConfTime)
                 {
-                  VhostManager* oldvhost = vhostList;
+                  VhostManagerHandler* oldvhost = vhostHandler;
                   string msg ("vhosts-conf-changed");
                   notifyMulticast (msg, 0);
 
@@ -457,15 +451,13 @@ void Server::mainLoop ()
                   connectionsScheduler.restart ();
                   listenThreads.initialize ();
 
-                  vhostList = new VhostManager (&listenThreads, logManager);
-
-                  if (!vhostList)
-                    continue;
+                  vhostHandler = new XmlVhostHandler (&listenThreads, 
logManager);
+                  vhostList.setHandler (vhostHandler);
 
                   delete oldvhost;
 
                   /* Load the virtual hosts configuration from the xml file.  
*/
-                  if (vhostList->loadXMLConfigurationFile 
(vhostConfigurationFile.c_str ()))
+                  if (vhostHandler->loadXMLConfigurationFile 
(vhostConfigurationFile.c_str ()))
                     listenThreads.rollbackFastReboot ();
                   else
                     listenThreads.commitFastReboot ();
@@ -684,8 +676,11 @@ int Server::terminate ()
 
   freeHashedData ();
 
-  ipAddresses = 0;
-  vhostList = 0;
+  ipAddresses = NULL;
+
+  if (vhostHandler)
+    delete vhostHandler;
+  vhostHandler = NULL;
 
 #ifdef WIN32
   /*
@@ -1073,11 +1068,7 @@ ConnectionPtr Server::addConnectionToList (Socket* s,
   newConnection->setLocalPort (localPort);
   newConnection->setIpAddr (ipAddr);
   newConnection->setLocalIpAddr (localIpAddr);
-  newConnection->host = vhostList->getVHost (0,
-                                             localIpAddr,
-                                             localPort);
-
-  /* No vhost for the connection so bail.  */
+  newConnection->host = vhostList.getVHost (0, localIpAddr, localPort);
   if (newConnection->host == 0)
     {
       connectionsPoolLock.lock ();

-----------------------------------------------------------------------

Summary of changes:
 myserver/include/conf/vhost/Makefile.am            |    2 +-
 myserver/include/conf/vhost/vhost.h                |   10 +-
 myserver/include/conf/vhost/vhost_manager.h        |   51 +--
 .../vhost/{vhost_manager.h => xml_vhost_handler.h} |   32 +-
 myserver/include/server/server.h                   |    6 +-
 myserver/src/conf/vhost/Makefile.am                |    2 +-
 myserver/src/conf/vhost/vhost.cpp                  |   12 +
 myserver/src/conf/vhost/vhost_manager.cpp          |  659 +-------------------
 .../{vhost_manager.cpp => xml_vhost_handler.cpp}   |  149 +----
 myserver/src/server/server.cpp                     |   41 +-
 10 files changed, 115 insertions(+), 849 deletions(-)
 copy myserver/include/conf/vhost/{vhost_manager.h => xml_vhost_handler.h} (72%)
 copy myserver/src/conf/vhost/{vhost_manager.cpp => xml_vhost_handler.cpp} (86%)


hooks/post-receive
-- 
GNU MyServer




reply via email to

[Prev in Thread] Current Thread [Next in Thread]