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. b96d1c4562


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. b96d1c45627f35ff04385d5a7b5f8c5735947767
Date: Mon, 28 Sep 2009 20:50:56 +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  b96d1c45627f35ff04385d5a7b5f8c5735947767 (commit)
       via  9003318618f35f4cee1c5de5471d35cec1c07661 (commit)
       via  0d689f340da2601a6d4b001e9b9cb3bec9e7aa35 (commit)
      from  2257ee59d9898d39b720317246ccd4ae7febc097 (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 b96d1c45627f35ff04385d5a7b5f8c5735947767
Author: Giuseppe Scrivano <address@hidden>
Date:   Mon Sep 28 22:50:28 2009 +0200

    Accept a --cfgdir option to specify a different path where look for 
configuration files.

diff --git a/myserver/documentation/basic_configuration.texi 
b/myserver/documentation/basic_configuration.texi
index 0b5a879..d211224 100644
--- a/myserver/documentation/basic_configuration.texi
+++ b/myserver/documentation/basic_configuration.texi
@@ -24,6 +24,11 @@ following order:
 @item Global scope inside /etc/myserver.
 @end enumerate
 
+It is possible to specify a different directory where looks for
+configuration files by the @code{--cfgdir} argument to the myserver
+process.  In case a path is specified, then the configuration files
+are looked exclusively in this directory.
+
 @section Server administrator
 CGI scripts can get the server administrator e-mail and show them to
 the user (through the SERVER_ADMIN environment variable). 
diff --git a/myserver/src/myserver.cpp b/myserver/src/myserver.cpp
index 9268b3a..c7acd0b 100644
--- a/myserver/src/myserver.cpp
+++ b/myserver/src/myserver.cpp
@@ -115,7 +115,7 @@ void registerSignals ()
   sigaction(SIGCHLD, &sa, (struct sigaction *)NULL);
 #else
   SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), ENABLE_PROCESSED_INPUT);
-  SetConsoleCtrlHandler( (PHANDLER_ROUTINE) SignalHandler, TRUE );
+  SetConsoleCtrlHandler((PHANDLER_ROUTINE) SignalHandler, TRUE);
 #endif
 }
 
@@ -127,25 +127,41 @@ struct argp_input
 {
   /* Print the version for MyServer?  */
   int version;
-  char* logFileName;
+
+  /* Define the main log file.  */
+  const char *logFileName;
+
   /* Define how run the server.  */
   int runas;
-  char* pidFileName;
+
+  /* If executed as a daemon, write the pid to this file.  */
+  const char *pidFileName;
+
+  /* Define an alternate location for the configuration files.  */
+  const char *confFilesLocation;
+
+  /* Specify if the fork server is used.  */
   int useForkServer;
 };
 
 static char doc[] = "GNU MyServer ";
 static char argsDoc[] = "";
 
+enum
+{
+ CONFIG_OPT = UCHAR_MAX + 1
+};
+
 /* Use the GNU C argp parser under not windows environments.  */
 static struct argp_option options[] =
   {
     /* LONG NAME - SHORT NAME - PARAMETER NAME - FLAGS - DESCRIPTION.  */
-    {"version", 'v', "VERSION", OPTION_ARG_OPTIONAL , "Print the version for 
the application"},
-    {"run", 'r', "RUN", OPTION_ARG_OPTIONAL, "Specify how run the server (by 
default console mode)"},
-    {"log", 'l', "location", 0, "Specify the location (in the format 
protocol://resource) to use to log main myserver messages"},
-    {"pidfile", 'p', "pidfile", 0, "Specify the file where write the PID"},
-    {"fork_server", 'f', "", OPTION_ARG_OPTIONAL, "Specify if use a fork 
server"},
+    {"version", 'v', "VERSION", OPTION_ARG_OPTIONAL , _("Print the version for 
the application")},
+    {"run", 'r', "RUN", OPTION_ARG_OPTIONAL, _("Specify how run the server (by 
default console mode)")},
+    {"log", 'l', "location", 0, _("Specify the location (using the format 
protocol://resource) to use as the main log.")},
+    {"pidfile", 'p', "file", 0, _("Specify the file where write the PID")},
+    {"fork_server", 'f', NULL, 0, _("Specify if use a fork server")},
+    {"cfgdir", CONFIG_OPT, "dir", 0, _("Specify an alternate directory where 
look for configuration files")},
     {0}
   };
 
@@ -182,6 +198,10 @@ static error_t parseOpt(int key, char *arg, struct 
argp_state *state)
       in->pidFileName = arg;
       break;
 
+    case CONFIG_OPT:
+      in->confFilesLocation = arg;
+      break;
+
     case ARGP_KEY_ARG:
     case ARGP_KEY_END:
       break;
@@ -231,9 +251,10 @@ int loadExternalPath(string &externalPath)
 
 /*!
  * Load the vhost configuration files locations.
+ * If DIR is specified, look only in this directory.
  * Return nonzero on errors.
  */
-int loadConfFileLocation (string &outFile, string fileName)
+int loadConfFileLocation (string &outFile, string fileName, const char *dir)
 {
   try
     {
@@ -242,6 +263,17 @@ int loadConfFileLocation (string &outFile, string fileName)
 #ifdef WIN32
       outFile = fileName;
 #else
+
+      if (dir)
+        {
+          outFile = dir;
+          if (outFile.at (outFile.length () - 1) != '/')
+            outFile += "/";
+
+          outFile += fileName;
+          return !FilesUtility::fileExists (outFile);
+        }
+
       /* Look for .xml files in the following order:
 
          1) current working directory
@@ -276,15 +308,16 @@ int loadConfFileLocation (string &outFile, string 
fileName)
 int loadConfFilesLocation (string &mainConfigurationFile,
                            string &mimeConfigurationFile,
                            string &vhostConfigurationFile,
-                           string &externalPath)
+                           string &externalPath,
+                           const char *dir)
 {
-  if (loadConfFileLocation (mainConfigurationFile, "myserver.xml"))
+  if (loadConfFileLocation (mainConfigurationFile, "myserver.xml", dir))
     return -1;
 
-  if (loadConfFileLocation (mimeConfigurationFile, "MIMEtypes.xml"))
+  if (loadConfFileLocation (mimeConfigurationFile, "MIMEtypes.xml", dir))
     return -1;
 
-  if (loadConfFileLocation (vhostConfigurationFile, "virtualhosts.xml"))
+  if (loadConfFileLocation (vhostConfigurationFile, "virtualhosts.xml", dir))
     return -1;
 
   if (loadExternalPath (externalPath))
@@ -366,22 +399,23 @@ int main  (int argn, char **argv)
 #ifdef ARGP
   /* Reset the struct.  */
   input.version = 0;
-  input.logFileName = 0;
+  input.confFilesLocation = NULL;
+  input.logFileName = NULL;
   input.runas = MYSERVER_RUNAS_CONSOLE;
-  input.pidFileName = 0;
+  input.pidFileName = NULL;
   input.useForkServer = 0;
 
   /* Call the parser.  */
   argp_parse (&myserverArgp, argn, argv, 0, 0, &input);
   runas = input.runas;
-  if (input.logFileName)
+
+  if (input.logFileName
+      && Server::getInstance ()->setLogLocation (input.logFileName))
     {
-      if (Server::getInstance ()->setLogLocation (input.logFileName))
-        {
-          cout << "Error setting the location for the MyServer's main log" << 
endl;
-          return 1;
-        }
+      cout << "Error setting the location for the MyServer's main log" << endl;
+      return 1;
     }
+
   /* If the version flag is up, show the version and exit.  */
   if (input.version)
     {
@@ -450,7 +484,8 @@ int main  (int argn, char **argv)
   try
     {
       setcwdBuffer ();
-      loadConfFilesLocation (mainConf, mimeConf, vhostConf, externPath);
+      loadConfFilesLocation (mainConf, mimeConf, vhostConf, externPath,
+                             input.confFilesLocation);
 
       switch(runas)
         {
@@ -521,7 +556,7 @@ int main  (int argn, char **argv)
 int writePidfile (const char* filename)
 {
   int pidfile;
-  pid_t pid = getpid();
+  pid_t pid = getpid ();
   char buff[12];
   int ret;
   string file = "";
@@ -594,29 +629,29 @@ void  __stdcall myServerMainNT (u_long, LPTSTR*)
     };
 
 
-  MyServiceStatusHandle = RegisterServiceCtrlHandler( "GNU MyServer",
-                                                      myServerCtrlHandler );
+  MyServiceStatusHandle = RegisterServiceCtrlHandler("GNU MyServer",
+                                                      myServerCtrlHandler);
   if(MyServiceStatusHandle)
     {
       MyServiceStatus.dwCurrentState = SERVICE_START_PENDING;
-      SetServiceStatus( MyServiceStatusHandle, &MyServiceStatus );
+      SetServiceStatus(MyServiceStatusHandle, &MyServiceStatus);
 
       MyServiceStatus.dwControlsAccepted |= (SERVICE_ACCEPT_STOP
                                              | SERVICE_ACCEPT_SHUTDOWN);
       MyServiceStatus.dwCurrentState = SERVICE_RUNNING;
-      SetServiceStatus( MyServiceStatusHandle, &MyServiceStatus );
+      SetServiceStatus(MyServiceStatusHandle, &MyServiceStatus);
 
 
-      loadConfFilesLocation (mainConf, mimeConf, vhostConf, externPath);
+      loadConfFilesLocation (mainConf, mimeConf, vhostConf, externPath, NULL);
       Server::getInstance()->start (mainConf, mimeConf, vhostConf, externPath);
 
       MyServiceStatus.dwCurrentState = SERVICE_STOP_PENDING;
-      SetServiceStatus( MyServiceStatusHandle, &MyServiceStatus );
+      SetServiceStatus(MyServiceStatusHandle, &MyServiceStatus);
 
       MyServiceStatus.dwControlsAccepted &= ~(SERVICE_ACCEPT_STOP
                                               | SERVICE_ACCEPT_SHUTDOWN);
       MyServiceStatus.dwCurrentState = SERVICE_STOPPED;
-      SetServiceStatus( MyServiceStatusHandle, &MyServiceStatus );
+      SetServiceStatus(MyServiceStatusHandle, &MyServiceStatus);
     }
 
 }
@@ -626,7 +661,7 @@ void  __stdcall myServerMainNT (u_long, LPTSTR*)
  */
 void __stdcall myServerCtrlHandler(u_long fdwControl)
 {
-  switch ( fdwControl )
+  switch (fdwControl)
     {
     case SERVICE_CONTROL_INTERROGATE:
       break;
@@ -634,8 +669,8 @@ void __stdcall myServerCtrlHandler(u_long fdwControl)
     case SERVICE_CONTROL_SHUTDOWN:
     case SERVICE_CONTROL_STOP:
       MyServiceStatus.dwCurrentState = SERVICE_STOP_PENDING;
-      SetServiceStatus( MyServiceStatusHandle, &MyServiceStatus );
-      Server::getInstance()->stop();
+      SetServiceStatus (MyServiceStatusHandle, &MyServiceStatus);
+      Server::getInstance ()->stop ();
       return;
 
     case SERVICE_CONTROL_PAUSE:
@@ -644,12 +679,12 @@ void __stdcall myServerCtrlHandler(u_long fdwControl)
     case SERVICE_CONTROL_CONTINUE:
       break;
     default:
-      if ( fdwControl >= 128 && fdwControl <= 255 )
+      if (fdwControl >= 128 && fdwControl <= 255)
         break;
       else
         break;
     }
-  SetServiceStatus( MyServiceStatusHandle, &MyServiceStatus );
+  SetServiceStatus (MyServiceStatusHandle, &MyServiceStatus);
 }
 #endif
 
@@ -669,11 +704,11 @@ void runService ()
   if (!StartServiceCtrlDispatcher (serviceTable))
     {
       if (GetLastError () == ERROR_INVALID_DATA)
-          Server::getInstance ()->log("Invalid data");
+        Server::getInstance ()->log("Invalid data");
       else if (GetLastError () == ERROR_SERVICE_ALREADY_RUNNING)
-          Server::getInstance ()->log("Already running");
+        Server::getInstance ()->log("Already running");
       else
-          Server::getInstance ()->log("Error running service");
+        Server::getInstance ()->log("Error running service");
     }
 #endif
 }



commit 9003318618f35f4cee1c5de5471d35cec1c07661
Author: Giuseppe Scrivano <address@hidden>
Date:   Mon Sep 28 21:07:52 2009 +0200

    Give a slightly saner --version message.

diff --git a/myserver/src/myserver.cpp b/myserver/src/myserver.cpp
index 7ae203e..9268b3a 100644
--- a/myserver/src/myserver.cpp
+++ b/myserver/src/myserver.cpp
@@ -385,15 +385,13 @@ int main  (int argn, char **argv)
   /* If the version flag is up, show the version and exit.  */
   if (input.version)
     {
-      cout << MYSERVER_VERSION << endl;
-
-      cout
-# ifdef __DATE__
-        << "Compiled on " << __DATE__
-# endif
-        << endl;
-
-      cout << "http://www.gnu.org/software/myserver"; << endl;
+      cout << "GNU MyServer " << MYSERVER_VERSION << endl
+           << "Copyright (C) 2009 Free Software Foundation, Inc." << endl
+           << "License GPLv3+: GNU GPL version 3 or later 
<http://gnu.org/licenses/gpl.html>." << endl
+           << "This is free software: you are free to change and redistribute 
it." << endl
+           << "There is NO WARRANTY, to the extent permitted by law." << endl
+           << endl
+           << "http://www.gnu.org/software/myserver"; << endl;
       return 0;
     }
 #else



commit 0d689f340da2601a6d4b001e9b9cb3bec9e7aa35
Author: Giuseppe Scrivano <address@hidden>
Date:   Mon Sep 28 20:51:32 2009 +0200

    Refactor the same repeated statements in a single function.

diff --git a/myserver/src/myserver.cpp b/myserver/src/myserver.cpp
index a8c1245..7ae203e 100644
--- a/myserver/src/myserver.cpp
+++ b/myserver/src/myserver.cpp
@@ -206,19 +206,17 @@ int loadExternalPath(string &externalPath)
   try
     {
       externalPath = "";
-
 #ifdef WIN32
-      externalPath.assign("plugins");
+      externalPath.assign ("plugins");
 #else
       if (FilesUtility::fileExists ("plugins"))
-        externalPath.assign("plugins");
+        externalPath.assign ("plugins");
       else
         {
 # ifdef PREFIX
-          externalPath.assign(PREFIX);
-          externalPath.append("/lib/myserver/plugins");
+          externalPath.assign (PREFIX "/lib/myserver/plugins");
 # else
-          externalPath.assign("/usr/lib/myserver/plugins");
+          externalPath.assign ("/usr/local/lib/myserver/plugins");
 # endif
         }
 
@@ -230,126 +228,63 @@ int loadExternalPath(string &externalPath)
   return 0;
 }
 
-/*!
- * Load the vhost configuration files locations.
- * Return nonzero on errors.
- */
-int loadVHostConfFilesLocation (string &vhostConfigurationFile)
-{
-  try
-    {
-      vhostConfigurationFile = "";
-
-#ifdef WIN32
-      vhostConfigurationFile.assign ("virtualhosts.xml");
-#else
-      /*
-       * Look for .xml files in the following order.
-       *1) myserver executable working directory
-       *2) ~/.myserver/
-       *3) /etc/myserver/
-       *4) default files will be copied in myserver executable working
-       */
-      if (FilesUtility::fileExists ("virtualhosts.xml"))
-        vhostConfigurationFile.assign ("virtualhosts.xml");
-      else if (FilesUtility::fileExists ("~/.myserver/virtualhosts.xml"))
-        vhostConfigurationFile.assign ("~/.myserver/virtualhosts.xml");
-      else if (FilesUtility::fileExists ("/etc/myserver/virtualhosts.xml"))
-        vhostConfigurationFile.assign("/etc/myserver/virtualhosts.xml");
-#endif
-    }
-  catch (...)
-    {
-    }
-  return 0;
-}
-
 
 /*!
- * Load the mime configuration files locations.
+ * Load the vhost configuration files locations.
  * Return nonzero on errors.
  */
-int loadMimeConfFilesLocation (string &mimeConfigurationFile)
+int loadConfFileLocation (string &outFile, string fileName)
 {
   try
     {
-      mimeConfigurationFile = "";
+      outFile = "";
 
 #ifdef WIN32
-      mimeConfigurationFile.assign ("MIMEtypes.xml");
+      outFile = fileName;
 #else
-      /*
-       *Under an *nix environment look for .xml files in the following order.
-       *1) myserver executable working directory
-       *2) ~/.myserver/
-       *3) /etc/myserver/
-       *4) default files will be copied in myserver executable working
-       */
-      if (FilesUtility::fileExists ("MIMEtypes.xml"))
-        mimeConfigurationFile.assign ("MIMEtypes.xml");
-      else if (FilesUtility::fileExists ("~/.myserver/MIMEtypes.xml"))
-        mimeConfigurationFile.assign ("~/.myserver/MIMEtypes.xml");
-      else if (FilesUtility::fileExists ("/etc/myserver/MIMEtypes.xml"))
-        mimeConfigurationFile.assign("/etc/myserver/MIMEtypes.xml");
-#endif
-    }
-  catch (...)
-    {
-    }
-  return 0;
-}
+      /* Look for .xml files in the following order:
 
+         1) current working directory
+         2) ~/.myserver/
+         3) /etc/myserver/
+      */
+      if (FilesUtility::fileExists (fileName))
+        {
+          outFile = fileName;
+          return 0;
+        }
 
-/*!
- * Load the main configuration files locations.
- * Return nonzero on errors.
- */
-int loadMainConfFilesLocation (string &mainConfigurationFile)
-{
-  try
-    {
-      mainConfigurationFile = "";
+      outFile = "~/.myserver/" + fileName;
+      if (FilesUtility::fileExists (outFile))
+        return 0;
 
-#ifdef WIN32
-      mainConfigurationFile.assign ("myserver.xml");
-#else
-      /*
-       * Look for .xml files in the following order.
-       * 1) myserver executable working directory
-       * 2) ~/.myserver/
-       * 3) /etc/myserver/
-       * 4) default files will be copied in myserver executable working
-       */
-      if (FilesUtility::fileExists ("myserver.xml"))
-        mainConfigurationFile.assign ("myserver.xml");
-      else if (FilesUtility::fileExists ("~/.myserver/myserver.xml"))
-        mainConfigurationFile.assign ("~/.myserver/myserver.xml");
-      else if (FilesUtility::fileExists ("/etc/myserver/myserver.xml"))
-        mainConfigurationFile.assign ("/etc/myserver/myserver.xml");
+      outFile = "/etc/myserver/" + fileName;
+      if (FilesUtility::fileExists (outFile))
+        return 0;
 #endif
     }
   catch (...)
     {
     }
-  return 0;
+  return 1;
 }
 
-
 /*!
  * Load the configuration files locations.
  * Return nonzero on errors.
  */
 int loadConfFilesLocation (string &mainConfigurationFile,
-     string &mimeConfigurationFile, string &vhostConfigurationFile,
+                           string &mimeConfigurationFile,
+                           string &vhostConfigurationFile,
                            string &externalPath)
 {
-  if (loadMainConfFilesLocation (mainConfigurationFile))
+  if (loadConfFileLocation (mainConfigurationFile, "myserver.xml"))
     return -1;
 
-  if (loadMimeConfFilesLocation (mimeConfigurationFile))
+  if (loadConfFileLocation (mimeConfigurationFile, "MIMEtypes.xml"))
     return -1;
 
-  if (loadVHostConfFilesLocation (vhostConfigurationFile))
+  if (loadConfFileLocation (vhostConfigurationFile, "virtualhosts.xml"))
     return -1;
 
   if (loadExternalPath (externalPath))

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

Summary of changes:
 myserver/documentation/basic_configuration.texi |    5 +
 myserver/src/myserver.cpp                       |  238 ++++++++++-------------
 2 files changed, 108 insertions(+), 135 deletions(-)


hooks/post-receive
-- 
GNU MyServer




reply via email to

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