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. 122b016597


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. 122b016597f52b049121ee06db9232f8601bedb4
Date: Fri, 23 Oct 2009 15:32: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  122b016597f52b049121ee06db9232f8601bedb4 (commit)
      from  3a5db3c216a14377abc3ff4f5553e82db5e2afd7 (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 122b016597f52b049121ee06db9232f8601bedb4
Author: Giuseppe Scrivano <address@hidden>
Date:   Fri Oct 23 17:28:42 2009 +0200

    Add the `chdir-long' and `getcwd' modules from gnulib and use them to 
configure the current working directory.

diff --git a/myserver/bootstrap.conf b/myserver/bootstrap.conf
index 5e8643a..395fdce 100644
--- a/myserver/bootstrap.conf
+++ b/myserver/bootstrap.conf
@@ -23,8 +23,10 @@ SKIP_PO=t
 
 # gnulib modules used by this package.
 gnulib_modules="
+chdir-long
 gettext
 crypto/md5
 nproc
 regex
+getcwd
 "
diff --git a/myserver/include/base/utility.h b/myserver/include/base/utility.h
index d8ddc8b..067023d 100644
--- a/myserver/include/base/utility.h
+++ b/myserver/include/base/utility.h
@@ -38,12 +38,11 @@ int endPrintError ();
 
 u_long getCPUCount ();
 u_long getTicks ();
-int setcwdBuffer ();
 int getdefaultwdlen ();
-char *getdefaultwd (char* dwd,int maxlen);
+char *getdefaultwd (char *dwd, int maxlen);
 int getdefaultwd (string&);
-int setcwd (const char * cwd);
-int freecwdBuffer ();
+int setcwd (const char *cwd);
+int freecwd ();
 
 int readFileHandle (SocketHandle s, Handle* fd);
 int writeFileHandle (SocketHandle s, Handle fd);
diff --git a/myserver/include/filter/gzip/gzip.h 
b/myserver/include/filter/gzip/gzip.h
index 39d7af8..f153af6 100644
--- a/myserver/include/filter/gzip/gzip.h
+++ b/myserver/include/filter/gzip/gzip.h
@@ -35,46 +35,42 @@ class Gzip : public Filter
 {
 
 public:
-       struct GzipData
-       {
-               z_stream stream;
-               u_long crc;
-               u_long data_size;
-               u_long initialized;
-       };
-
-
-       static u_long compressBound (int size);
+  struct GzipData
+  {
+    z_stream stream;
+    u_long crc;
+    u_long data_size;
+    u_long initialized;
+  };
+  static u_long compressBound (int size);
 
   Gzip ();
   ~Gzip ();
 
-       static u_long headerSize ();
-       static u_long footerSize ();
-
-       u_long updateCRC (char* buffer,int size);
-       u_long getFooter (char *str,int size);
-       u_long initialize ();
-       u_long compress (const char* in, u_long sizeIn,
-                   char *out,u_long sizeOut);
-       u_long free ();
-       u_long flush (char *out,u_long sizeOut);
-       u_long getHeader (char *buffer,u_long buffersize);
+  static u_long headerSize ();
+  static u_long footerSize ();
+  u_long updateCRC (char* buffer,int size);
+  u_long getFooter (char *str,int size);
+  u_long initialize ();
+  u_long compress (const char* in, u_long sizeIn,
+                   char *out, u_long sizeOut);
+  u_long free ();
+  u_long flush (char *out, u_long sizeOut);
+  u_long getHeader (char *buffer, u_long buffersize);
 
   static Filter* factory (const char* name);
 
-  /*! From Filter*/
+  /*! From Filter.  */
   virtual int getHeader (char* buffer, u_long len, u_long* nbw);
   virtual int getFooter (char* buffer, u_long len, u_long* nbw);
   virtual int read (char* buffer, u_long len, u_long*);
   virtual int write (const char* buffer, u_long len, u_long*);
-       virtual int flush (u_long*);
-       virtual int modifyData ();
+  virtual int flush (u_long*);
+  virtual int modifyData ();
   virtual const char* getName (char* name, u_long len);
 private:
-       int active;
-       GzipData data;
-
+  int active;
+  GzipData data;
 };
 
 #endif
diff --git a/myserver/src/base/utility.cpp b/myserver/src/base/utility.cpp
index f2cd26e..782741f 100644
--- a/myserver/src/base/utility.cpp
+++ b/myserver/src/base/utility.cpp
@@ -19,9 +19,9 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>.
 #include "stdafx.h"
 #include <include/base/utility.h>
 #include <include/base/string/securestr.h>
-
 extern "C"
 {
+#include <chdir-long.h>
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -47,10 +47,8 @@ extern "C"
 #include <iostream>
 using namespace std;
 
-/*
- * Various utility functions.
- */
-static char *currentPath = 0;
+static char *currentPath = NULL;
+static size_t currentPathLen;
 
 /*!
  * Returns the number of processors available on the local machine.
@@ -65,58 +63,17 @@ u_long getCPUCount ()
  * Return -1 on fails.
  * Return 0 on success.
  */
-int setcwdBuffer ()
+static int initializeCwd ()
 {
-#ifdef WIN32
-  /* Under windows there is MAX_PATH, we will use it.  */
-  currentPath = new char [MAX_PATH];
-  if (currentPath == 0)
-    return (-1);
-  char* ret =(char*) _getcwd (currentPath,MAX_PATH);
-  if (ret == 0)
-    return -1;
-
-  ret = 0;
-
-  for (u_long i = 0; i<(u_long)strlen (currentPath); i++)
-    if (currentPath[i] == '\\')
-      currentPath[i] = '/';
-
-  if (currentPath[strlen (currentPath)] == '/')
-    currentPath[strlen (currentPath)] = '\0';
-  return 0;
-#endif
+  if (currentPath)
+    return 0;
 
-#ifdef __OpenBSD__
-  currentPath = getcwd (0, 0);
-  return currentPath ? 0 : 1;
-#endif
+  currentPath = getcwd (NULL, 0);
+  if (!currentPath)
+    return -1;
 
-#ifndef WIN32
-  int size = 16;
-  char *ret = 0;
-  currentPath = new char[size];
-  do
-  {
-    /*! Allocation problem is up.  */
-    if (currentPath == 0)
-      return -1;
-
-    ret = getcwd (currentPath, size);
-    /* Realloc the buffer if it cannot contain the current directory.  */
-    if (ret == 0)
-      {
-        size *= 2;
-        delete [] currentPath;
-        currentPath = new char[size];
-      }
-  }
-  while ((ret == 0) && (errno == ERANGE));
-
-  if (currentPath[strlen (currentPath)] == '/')
-    currentPath[strlen (currentPath)] = '\0';
+  currentPathLen = strlen (currentPath) + 1;
   return 0;
-#endif
 }
 
 /*!
@@ -126,9 +83,8 @@ int setcwdBuffer ()
  */
 int getdefaultwd (string& out)
 {
-  char *wd = getdefaultwd (NULL, NULL);
-
-  if (wd == 0)
+  char *wd = getdefaultwd (NULL, 0);
+  if (wd == NULL)
     return -1;
 
   out.assign (wd);
@@ -138,9 +94,13 @@ int getdefaultwd (string& out)
 /*!
  * Free the cwd buffer.
  */
-int freecwdBuffer ()
+int freecwd ()
 {
+  if (!currentPath)
+    return 0;
+
   delete [] currentPath;
+  currentPathLen = 0;
   return 0;
 }
 
@@ -149,24 +109,31 @@ int freecwdBuffer ()
  */
 int getdefaultwdlen ()
 {
-  return strlen (currentPath) + 1;
+  if (!currentPathLen && initializeCwd ())
+    return 0;
+
+  return currentPathLen;
 }
 
 /*!
- *Get the default working directory (Where is the main executable).
+ *Get the default working directory.
  *\param path The buffer where write.
  *\param len The length of the buffer.
  */
 char *getdefaultwd (char *path, int len)
 {
+  if (!currentPath && initializeCwd ())
+      return NULL;
+
   if (path)
     {
-    /* If len is equal to zero we assume no limit.  */
+      /* If len is equal to zero we assume no limit.  */
       if (len)
-        myserver_strlcpy (path, currentPath, len);
+       myserver_strlcpy (path, currentPath, len);
       else
-        strcpy (path, currentPath);
+       strcpy (path, currentPath);
     }
+
   return currentPath;
 }
 
@@ -176,13 +143,14 @@ char *getdefaultwd (char *path, int len)
  */
 int setcwd (const char *dir)
 {
-#ifdef WIN32
-  return _chdir (dir);
-#endif
+  int ret;
+  char *tmp = strdup (dir);
+  if (!tmp)
+    return -1;
 
-#ifndef WIN32
-  return chdir (dir);
-#endif
+  ret = chdir_long (tmp);
+  free (tmp);
+  return ret;
 }
 
 /*!
diff --git a/myserver/src/myserver.cpp b/myserver/src/myserver.cpp
index 5425ba1..c6a24b3 100644
--- a/myserver/src/myserver.cpp
+++ b/myserver/src/myserver.cpp
@@ -405,7 +405,6 @@ int main  (int argn, char **argv)
   /* We can free path memory now.  */
   delete [] path;
 
-
 #ifdef ARGP
   /* Reset the struct.  */
   input.version = 0;
@@ -493,7 +492,6 @@ int main  (int argn, char **argv)
    */
   try
     {
-      setcwdBuffer ();
       loadConfFilesLocation (mainConf, mimeConf, vhostConf, externPath,
                              input.confFilesLocation);
 
diff --git a/myserver/src/server/server.cpp b/myserver/src/server/server.cpp
index 2032472..f4ae668 100644
--- a/myserver/src/server/server.cpp
+++ b/myserver/src/server/server.cpp
@@ -589,7 +589,7 @@ int Server::purgeThreads ()
 void Server::finalCleanup ()
 {
   XmlParser::cleanXML ();
-  freecwdBuffer ();
+  freecwd ();
   myserver_safetime_destroy ();
 }
 
diff --git a/myserver/tests/test_file.cpp b/myserver/tests/test_file.cpp
index 731a0fa..5d6dbfb 100644
--- a/myserver/tests/test_file.cpp
+++ b/myserver/tests/test_file.cpp
@@ -47,7 +47,6 @@ class TestFile : public CppUnit::TestFixture
 public:
   void setUp ()
   {
-    setcwdBuffer ();/* Be sure the cwd buffer is initialized.  */
     FilesUtility::temporaryFileName (0, fname);
     tfile = new File;
   }
diff --git a/myserver/tests/test_file_stream.cpp 
b/myserver/tests/test_file_stream.cpp
index e24ed34..efa1f31 100644
--- a/myserver/tests/test_file_stream.cpp
+++ b/myserver/tests/test_file_stream.cpp
@@ -44,7 +44,6 @@ public:
     fsc = new FileStreamCreator ();
     ff = new FiltersFactory ();
     ff->insert ("gzip", Gzip::factory);
-    setcwdBuffer ();
   }
 
   void testCycleLog ()
diff --git a/myserver/tests/test_log_manager.cpp 
b/myserver/tests/test_log_manager.cpp
index 5036dd5..964cb0c 100644
--- a/myserver/tests/test_log_manager.cpp
+++ b/myserver/tests/test_log_manager.cpp
@@ -90,7 +90,6 @@ public:
     ff->insert ("gzip", Gzip::factory);
     ff->insert ("gunzip", GzipDecompress::factory);
     lm = new LogManager (ff);
-    setcwdBuffer ();
   }
 
   void testEmpty ()
diff --git a/myserver/tests/test_utility.cpp b/myserver/tests/test_utility.cpp
index aeea97c..7329551 100644
--- a/myserver/tests/test_utility.cpp
+++ b/myserver/tests/test_utility.cpp
@@ -65,34 +65,22 @@ public:
 
   void testCWD ()
   {
+    string strBuff;
     char *buffer;
     unsigned int bufferLen;
 
-    setcwdBuffer ();
-
     bufferLen = getdefaultwdlen ();
     CPPUNIT_ASSERT (bufferLen > 0);
 
     buffer = new char[bufferLen + 1];
-
-
     getdefaultwd (buffer, bufferLen);
-
     CPPUNIT_ASSERT ( strlen (buffer) > 0 );
     CPPUNIT_ASSERT (strlen (buffer) <= bufferLen);
 
-
-    string strBuff;
-
     int ret = getdefaultwd (strBuff);
-
     CPPUNIT_ASSERT_EQUAL (ret, 0);
-
     CPPUNIT_ASSERT (strBuff.length () > 0);
-
-
-
-    freecwdBuffer ();
+    freecwd ();
 
     delete [] buffer;
   }

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

Summary of changes:
 myserver/bootstrap.conf             |    2 +
 myserver/include/base/utility.h     |    7 +-
 myserver/include/filter/gzip/gzip.h |   50 ++++++++---------
 myserver/src/base/utility.cpp       |  104 ++++++++++++-----------------------
 myserver/src/myserver.cpp           |    2 -
 myserver/src/server/server.cpp      |    2 +-
 myserver/tests/test_file.cpp        |    1 -
 myserver/tests/test_file_stream.cpp |    1 -
 myserver/tests/test_log_manager.cpp |    1 -
 myserver/tests/test_utility.cpp     |   16 +-----
 10 files changed, 67 insertions(+), 119 deletions(-)


hooks/post-receive
-- 
GNU MyServer




reply via email to

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