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. 3e407b8a4b


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. 3e407b8a4b2400dcd8e99b58ecec073bbed2acae
Date: Mon, 05 Oct 2009 21:08:16 +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  3e407b8a4b2400dcd8e99b58ecec073bbed2acae (commit)
      from  0dbe2eec5ec1ae7b563ebe861484111d1fbe92fa (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 3e407b8a4b2400dcd8e99b58ecec073bbed2acae
Author: Giuseppe Scrivano <address@hidden>
Date:   Mon Oct 5 23:08:17 2009 +0200

    The Server delegates configuration values loading to the 
`MainConfiguration' class.  Also, the Server now accepts a builder function to 
create a `MainConfiguration' instance.

diff --git a/myserver/include/conf/main/main_configuration.h 
b/myserver/include/conf/main/main_configuration.h
index 4cd20a0..02ba8ca 100644
--- a/myserver/include/conf/main/main_configuration.h
+++ b/myserver/include/conf/main/main_configuration.h
@@ -20,7 +20,11 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>.
 # define MAIN_CONFIGURATION_H
 
 # include "stdafx.h"
+# include <include/base/hash_map/hash_map.h>
+# include <include/conf/nodetree.h>
+
 # include <string>
+# include <list>
 
 using namespace std;
 
@@ -36,6 +40,8 @@ public:
   {
     return 0;
   }
+  virtual void readData (list<NodeTree<string>*> *hashedDataTrees,
+                         HashMap<string, NodeTree<string>*> *hashedData);
 private:
 
 };
diff --git a/myserver/include/conf/main/xml_main_configuration.h 
b/myserver/include/conf/main/xml_main_configuration.h
index 8ff9941..51d9d79 100644
--- a/myserver/include/conf/main/xml_main_configuration.h
+++ b/myserver/include/conf/main/xml_main_configuration.h
@@ -60,6 +60,9 @@ public:
     return xmlParser.getDoc ();
   }
 
+  virtual void readData (list<NodeTree<string>*> *hashedDataTrees,
+                         HashMap<string, NodeTree<string>*> *hashedData);
+
 private:
   XmlParser xmlParser;
 };
diff --git a/myserver/include/server/server.h b/myserver/include/server/server.h
index 90cb792..2575149 100644
--- a/myserver/include/server/server.h
+++ b/myserver/include/server/server.h
@@ -125,7 +125,8 @@ public:
   const char *getServerName ();
   int getMaxLogFileSize ();
   int mustUseLogonOption ();
-  void start (string &, string &, string &, string &);
+  void start (string &, string &, string &, string &,
+           MainConfiguration* (*genMainConf) (Server *server, const char 
*arg));
   void stop ();
   void finalCleanup ();
   int terminate ();
@@ -166,6 +167,7 @@ private:
   XmlValidator *xmlValidator;
 
   MainConfiguration *configurationFileManager;
+  MainConfiguration* (*genMainConf) (Server *server, const char *arg);
 
 # ifdef WIN32
   friend int __stdcall control_handler (u_long control_type);
@@ -188,7 +190,6 @@ private:
   /*! Do not allow to create directly objects.  */
   Server ();
 
-  void readHashedData (xmlNodePtr lcur);
   void mainLoop ();
   void loadPlugins ();
   void displayBoot ();
diff --git a/myserver/src/conf/main/main_configuration.cpp 
b/myserver/src/conf/main/main_configuration.cpp
index 73561e7..cd09f41 100644
--- a/myserver/src/conf/main/main_configuration.cpp
+++ b/myserver/src/conf/main/main_configuration.cpp
@@ -33,3 +33,9 @@ const char *MainConfiguration::getValue (string const &field)
   return getValue (field.c_str ());
 };
 
+
+void MainConfiguration::readData (list<NodeTree<string>*> *hashedDataTrees,
+                         HashMap<string, NodeTree<string>*> *hashedData)
+{
+
+}
diff --git a/myserver/src/conf/main/xml_main_configuration.cpp 
b/myserver/src/conf/main/xml_main_configuration.cpp
index 0dba02f..56ce4ce 100644
--- a/myserver/src/conf/main/xml_main_configuration.cpp
+++ b/myserver/src/conf/main/xml_main_configuration.cpp
@@ -16,6 +16,7 @@
 */
 
 #include <include/conf/main/xml_main_configuration.h>
+#include <include/conf/xml_conf.h>
 
 XmlMainConfiguration::XmlMainConfiguration ()
 {
@@ -26,3 +27,10 @@ XmlMainConfiguration::~XmlMainConfiguration ()
 {
 
 }
+
+void XmlMainConfiguration::readData (list<NodeTree<string>*> *hashedDataTrees,
+                                 HashMap<string, NodeTree<string>*> 
*hashedData)
+{
+  xmlNodePtr root = xmlDocGetRootElement (xmlParser.getDoc 
())->xmlChildrenNode;
+  XmlConf::build (root, hashedDataTrees, hashedData);
+}
diff --git a/myserver/src/myserver.cpp b/myserver/src/myserver.cpp
index b9db330..5425ba1 100644
--- a/myserver/src/myserver.cpp
+++ b/myserver/src/myserver.cpp
@@ -20,6 +20,7 @@
 #include <include/base/file/files_utility.h>
 #include <include/base/string/stringutils.h>
 #include <include/base/process/process.h>
+#include <include/conf/main/xml_main_configuration.h>
 
 extern "C"
 {
@@ -46,7 +47,8 @@ extern "C"
 #define MYSERVER_RUNAS_CONSOLE 1
 #define MYSERVER_RUNAS_SERVICE 2
 
-void consoleService (string &, string &, string &, string &);
+void consoleService (string &, string &, string &, string &,
+           MainConfiguration* (*genMainConf) (Server *server, const char 
*arg));
 
 #ifdef WIN32
 void __stdcall myServerCtrlHandler (u_long fdwControl);
@@ -326,6 +328,17 @@ int loadConfFilesLocation (string &mainConfigurationFile,
   return 0;
 }
 
+static MainConfiguration *genMainConf (Server *server, const char *arg)
+{
+  XmlMainConfiguration *conf = new XmlMainConfiguration ();
+  if (conf->open (arg))
+    {
+      delete conf;
+      return NULL;
+    }
+    return conf;
+}
+
 int main  (int argn, char **argv)
 {
   int runas = MYSERVER_RUNAS_CONSOLE;
@@ -359,41 +372,38 @@ int main  (int argn, char **argv)
       return (1);
     };
 
-  {
-    u_int pathLen = 0;
-    u_int len = 0;
-    bool differentCwd = false;
-    char *path;
-
-    pathLen = strlen (argv[0]);
-    path = new char[pathLen + 1];
-    if (path == 0)
-      return 1;
-    strncpy (path, argv[0], pathLen);
+  u_int pathLen = 0;
+  u_int len = 0;
+  bool differentCwd = false;
+  char *path;
+
+  pathLen = strlen (argv[0]);
+  path = new char[pathLen + 1];
+  if (path == 0)
+    return 1;
+  strncpy (path, argv[0], pathLen);
 
-    for (len = 0; len < pathLen; len++)
-      {
-        if (path[len] == '/' || path[len] == '\\')
-          {
-            differentCwd = true;
-            break;
-          }
-      }
+  for (len = 0; len < pathLen; len++)
+    {
+      if (path[len] == '/' || path[len] == '\\')
+        {
+          differentCwd = true;
+          break;
+        }
+    }
 
-    /* Current working directory is where the myserver executable is.  */
-    if (differentCwd)
-      {
-        len = pathLen;
-        while ((path[len] != '\\') && (path[len] != '/'))
-          len--;
-        path[len] = '\0';
+  if (differentCwd)
+    {
+      len = pathLen;
+      while ((path[len] != '\\') && (path[len] != '/'))
+        len--;
+      path[len] = '\0';
 
-        setcwd (path);
-      }
+      setcwd (path);
+    }
 
-    /* We can free path memory now.  */
-    delete [] path;
-  }
+  /* We can free path memory now.  */
+  delete [] path;
 
 
 #ifdef ARGP
@@ -489,9 +499,6 @@ int main  (int argn, char **argv)
 
       switch (runas)
         {
-        case MYSERVER_RUNAS_CONSOLE:
-          consoleService (mainConf, mimeConf, vhostConf, externPath);
-          break;
         case MYSERVER_RUNAS_SERVICE:
 #ifdef WIN32
           runService ();
@@ -529,10 +536,9 @@ int main  (int argn, char **argv)
           sid = setsid ();
           if (sid < 0)
             return 1;
-
-          consoleService (mainConf, mimeConf, vhostConf, externPath);
 #endif
-          break;
+        case MYSERVER_RUNAS_CONSOLE:
+          consoleService (mainConf, mimeConf, vhostConf, externPath, 
&genMainConf);
         }
     }
   catch (...)
@@ -589,9 +595,10 @@ int writePidfile (const char* filename)
 /*!
  * Start MyServer in console mode.
  */
-void consoleService (string &mainConf, string &mimeConf, string &vhostConf, 
string &externPath)
+ void consoleService (string &mainConf, string &mimeConf, string &vhostConf, 
string &externPath,
+                      MainConfiguration* (*genMainConf) (Server *server, const 
char *arg))
 {
-  Server::getInstance ()->start (mainConf, mimeConf, vhostConf, externPath);
+  Server::getInstance ()->start (mainConf, mimeConf, vhostConf, externPath, 
genMainConf);
 }
 
 
diff --git a/myserver/src/server/server.cpp b/myserver/src/server/server.cpp
index 6cd4b83..e810a37 100644
--- a/myserver/src/server/server.cpp
+++ b/myserver/src/server/server.cpp
@@ -31,7 +31,6 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>.
 #include <include/base/ssl/ssl.h>
 #include <include/base/socket/ssl_socket.h>
 
-#include <include/conf/xml_conf.h>
 #include <include/conf/main/xml_main_configuration.h>
 
 #include <cstdarg>
@@ -84,6 +83,7 @@ Server::Server () : connectionsScheduler (this),
   initLogManager ();
   connectionsPoolLock.init ();
   configurationFileManager = NULL;
+  genMainConf = NULL;
 }
 
 void
@@ -164,7 +164,9 @@ Server::~Server ()
  *Start the server.
  */
 void Server::start (string &mainConf, string &mimeConf, string &vhostConf,
-                    string &externPath)
+                    string &externPath, MainConfiguration* (*genMainConf)
+                    (Server *server, const char *arg))
+
 {
   int err = 0;
 #ifdef WIN32
@@ -172,6 +174,8 @@ void Server::start (string &mainConf, string &mimeConf, 
string &vhostConf,
   INPUT_RECORD irInBuf[128];
 #endif
 
+  this->genMainConf = genMainConf;
+
   displayBoot ();
 
   try
@@ -753,8 +757,6 @@ MainConfiguration *Server::getConfiguration ()
 int Server::initialize ()
 {
   const char *data;
-  XmlMainConfiguration *xmlMainConf;
-
 #ifdef WIN32
   envString = GetEnvironmentStrings ();
 #endif
@@ -773,17 +775,25 @@ int Server::initialize ()
   maxConnections = 0;
   maxConnectionsToAccept = 0;
 
-
-  xmlMainConf = new XmlMainConfiguration ();
-  if (xmlMainConf->open (mainConfigurationFile.c_str ()))
+  /* FIXME: the main configuration type is not always XmlMainConfiguration.  */
+  if (genMainConf)
     {
-      delete xmlMainConf;
-      return -1;
+        configurationFileManager =
+          static_cast<XmlMainConfiguration*> (genMainConf (this,
+                                               mainConfigurationFile.c_str 
()));
+    }
+  else
+    {
+      XmlMainConfiguration *xmlMainConf = new XmlMainConfiguration ();
+      if (xmlMainConf->open (mainConfigurationFile.c_str ()))
+        {
+          delete xmlMainConf;
+          return -1;
+        }
+      configurationFileManager = xmlMainConf;
     }
 
-  configurationFileManager = xmlMainConf;
-
-  readHashedData (xmlDocGetRootElement (xmlMainConf->getDoc 
())->xmlChildrenNode);
+  configurationFileManager->readData (&hashedDataTrees, &hashedData);
 
   /*
    * Process console colors information.
@@ -902,17 +912,6 @@ int Server::initialize ()
 }
 
 /*!
- * Read the values defined in the global configuration file.
- */
-void Server::readHashedData (xmlNodePtr lcur)
-{
-  XmlConf::build (lcur,
-                  &hashedDataTrees,
-                  &hashedData);
-}
-
-
-/*!
  * Check if there are free threads to handle a new request.  If there
  * are not enough threads create a new one.
  */

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

Summary of changes:
 myserver/include/conf/main/main_configuration.h    |    6 ++
 .../include/conf/main/xml_main_configuration.h     |    3 +
 myserver/include/server/server.h                   |    5 +-
 myserver/src/conf/main/main_configuration.cpp      |    6 ++
 myserver/src/conf/main/xml_main_configuration.cpp  |    8 ++
 myserver/src/myserver.cpp                          |   87 +++++++++++---------
 myserver/src/server/server.cpp                     |   45 +++++-----
 7 files changed, 95 insertions(+), 65 deletions(-)


hooks/post-receive
-- 
GNU MyServer




reply via email to

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