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


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. b9fbdcecc5bccd3e9f027201557eaa656194319d
Date: Sun, 02 Aug 2009 11:02:41 +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  b9fbdcecc5bccd3e9f027201557eaa656194319d (commit)
       via  e3a9db94e29ba31a5312a5896bb49de8c97bf6ce (commit)
       via  f13e2b6d1fb952d4684eb6f12def7b9cf73fb44e (commit)
      from  8fe2ee5ff7da322945a84c44f7c06fdfdcaeeb4f (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 b9fbdcecc5bccd3e9f027201557eaa656194319d
Author: Giuseppe Scrivano <address@hidden>
Date:   Sun Aug 2 12:15:58 2009 +0200

    Use socklen_t instead of int as parameter type to Socket::accept.

diff --git a/myserver/include/base/socket/socket.h 
b/myserver/include/base/socket/socket.h
index f3f5771..5d9ccf5 100644
--- a/myserver/include/base/socket/socket.h
+++ b/myserver/include/base/socket/socket.h
@@ -89,7 +89,7 @@ public:
   Socket(Socket*);
   Socket(SocketHandle);
 
-  Socket accept(MYSERVER_SOCKADDR*, int*);
+  Socket accept(MYSERVER_SOCKADDR*, socklen_t*);
   int setsockopt(int,int, const char*,int);
 
   virtual int connect(MYSERVER_SOCKADDR*, int);
diff --git a/myserver/src/base/socket/socket.cpp 
b/myserver/src/base/socket/socket.cpp
index 7664dff..49d84fe 100644
--- a/myserver/src/base/socket/socket.cpp
+++ b/myserver/src/base/socket/socket.cpp
@@ -197,7 +197,7 @@ int Socket::listen(int max)
 /*!
  *Accept a new connection.
  */
-Socket Socket::accept(MYSERVER_SOCKADDR* sa, int* sockaddrlen)
+Socket Socket::accept(MYSERVER_SOCKADDR* sa, socklen_t* sockaddrlen)
 {
   Socket s;
 
diff --git a/myserver/src/base/unix_socket/unix_socket.cpp 
b/myserver/src/base/unix_socket/unix_socket.cpp
index af63545..8cd55ca 100644
--- a/myserver/src/base/unix_socket/unix_socket.cpp
+++ b/myserver/src/base/unix_socket/unix_socket.cpp
@@ -113,7 +113,7 @@ Socket UnixSocket::accept ()
 
 #ifdef AF_UNIX
   sockaddr_un addr;
-  int len = sizeof (addr);
+  socklen_t len = sizeof (addr);
   return Socket::accept ((MYSERVER_SOCKADDR*)&addr, &len);
 #else
   Socket s;
diff --git a/myserver/src/connections_scheduler/connections_scheduler.cpp 
b/myserver/src/connections_scheduler/connections_scheduler.cpp
index 865bc91..803dc6e 100644
--- a/myserver/src/connections_scheduler/connections_scheduler.cpp
+++ b/myserver/src/connections_scheduler/connections_scheduler.cpp
@@ -135,25 +135,21 @@ static void listenerHandler (int fd, short event, void 
*arg)
   ConnectionsScheduler::ListenerArg* s = 
(ConnectionsScheduler::ListenerArg*)arg;
 
   if (event == EV_TIMEOUT)
-  {
     event_add (&(s->ev), &tv);
-  }
   else if (event == EV_READ)
-  {
-    MYSERVER_SOCKADDRIN asockIn;
-    int asockInLen = 0;
-    Socket asock;
+    {
+      MYSERVER_SOCKADDRIN asockIn;
+      socklen_t asockInLen = 0;
+      Socket clientSock;
 
-    asockInLen = sizeof (asockIn);
-    asock = s->serverSocket->accept (&asockIn, &asockInLen);
+      asockInLen = sizeof (asockIn);
+      clientSock = s->serverSocket->accept (&asockIn, &asockInLen);
 
-    if (s->server && (SocketHandle)asock.getHandle() != INVALID_SOCKET)
-    {
-      s->server->addConnection (asock, &asockIn);
-    }
+      if (s->server && (SocketHandle)clientSock.getHandle () != INVALID_SOCKET)
+        s->server->addConnection (clientSock, &asockIn);
 
-    event_add (&(s->ev), &tv);
-  }
+      event_add (&(s->ev), &tv);
+    }
 }
 
 /*!
diff --git a/myserver/src/protocol/ftp/ftp.cpp 
b/myserver/src/protocol/ftp/ftp.cpp
index 23e13d0..567e22b 100755
--- a/myserver/src/protocol/ftp/ftp.cpp
+++ b/myserver/src/protocol/ftp/ftp.cpp
@@ -582,15 +582,14 @@ void Ftp::pasv ()
   timeoutvalue = 5;
 #endif
   MYSERVER_SOCKADDRIN asockIn;
-  int asockInLen = 0;
+  socklen_t asockInLen = 0;
   Socket asock;
   if (pFtpuserData->m_pDataConnection->socket->dataOnRead (timeoutvalue, 0)
       == 1)
     {
       asockInLen = sizeof (sockaddr_in);
-      asock =
-        pFtpuserData->m_pDataConnection->socket->accept (&asockIn,
-                                                         &asockInLen);
+      asock =pFtpuserData->m_pDataConnection->socket->accept (&asockIn,
+                                                           &asockInLen);
       if (asock.getHandle () == (Handle) INVALID_SOCKET)
         return;
 
diff --git a/myserver/tests/test_socket.cpp b/myserver/tests/test_socket.cpp
index 74ecf25..e7018f9 100644
--- a/myserver/tests/test_socket.cpp
+++ b/myserver/tests/test_socket.cpp
@@ -93,7 +93,7 @@ public:
     ((sockaddr_in*) (&sockIn))->sin_addr.s_addr = inet_addr ( "127.0.0.1" );
     ((sockaddr_in*) (&sockIn))->sin_port = htons ( port );
     
-    int sockInLen = sizeof ( sockaddr_in );
+    socklen_t sockInLen = sizeof ( sockaddr_in );
     
     CPPUNIT_ASSERT( obj->socket ( AF_INET, SOCK_STREAM, 0 ) != -1 );
     
diff --git a/myserver/tests/test_ssl_socket.cpp 
b/myserver/tests/test_ssl_socket.cpp
index 2532028..c9a5e00 100644
--- a/myserver/tests/test_ssl_socket.cpp
+++ b/myserver/tests/test_ssl_socket.cpp
@@ -137,7 +137,7 @@ public:
     ((sockaddr_in*) (&sockIn))->sin_addr.s_addr = inet_addr ( "127.0.0.1" );
     ((sockaddr_in*) (&sockIn))->sin_port = htons ( port );
     
-    int sockInLen = sizeof ( sockaddr_in );
+    socklen_t sockInLen = sizeof ( sockaddr_in );
     
     CPPUNIT_ASSERT( obj->socket ( AF_INET, SOCK_STREAM, 0 ) != -1 );
     



commit e3a9db94e29ba31a5312a5896bb49de8c97bf6ce
Author: Giuseppe Scrivano <address@hidden>
Date:   Sun Aug 2 11:33:04 2009 +0200

    Code refactoring for the HttpFile class.

diff --git a/myserver/src/http_handler/http_file/http_file.cpp 
b/myserver/src/http_handler/http_file/http_file.cpp
index 26cebd2..9a15cce 100644
--- a/myserver/src/http_handler/http_file/http_file.cpp
+++ b/myserver/src/http_handler/http_file/http_file.cpp
@@ -40,7 +40,7 @@ extern "C"
 }
 
 /*!
- *Main function to handle the HTTP PUT command.
+ * Main function to handle the HTTP PUT command.
  */
 int HttpFile::putFile (HttpThreadContext* td,
                        string& filename)
@@ -54,113 +54,106 @@ int HttpFile::putFile (HttpThreadContext* td,
     HttpHeaders::buildDefaultHTTPResponseHeader(&td->response);
 
     if(td->request.isKeepAlive())
-    {
-      td->response.connection.assign("keep-alive");
-      keepalive = 1;
-    }
+      {
+        td->response.connection.assign("keep-alive");
+        keepalive = 1;
+      }
 
     if(!(td->permissions & MYSERVER_PERMISSION_WRITE))
-    {
       return td->http->sendAuth();
-    }
 
-    if(FilesUtility::fileExists(td->filenamePath.c_str()))
-    {
-      /*! If the file exists update it. */
-      File file;
-      if(file.openFile(td->filenamePath.c_str(), File::OPEN_IF_EXISTS |
-                       File::WRITE))
-      {
-        /*! Return an internal server error. */
-        return td->http->raiseHTTPError(500);
-      }
-      file.seek (firstByte);
-      for(;;)
+    if(FilesUtility::fileExists (td->filenamePath.c_str()))
       {
-        u_long nbr = 0, nbw = 0;
-        if(td->inputData.read (td->buffer->getBuffer(),
-                               td->buffer->getRealLength(), &nbr))
-        {
-          file.close();
-          /*! Return an internal server error.  */
-          return td->http->raiseHTTPError(500);
-        }
-        if(nbr)
-        {
-          if(file.writeToFile(td->buffer->getBuffer(), nbr, &nbw))
+        File file;
+        if (file.openFile (td->filenamePath.c_str(), File::OPEN_IF_EXISTS |
+                           File::WRITE))
+          return td->http->raiseHTTPError (500);
+
+        file.seek (firstByte);
+
+        for(;;)
           {
-            file.close();
-            /*! Return an internal server error.  */
-            return td->http->raiseHTTPError(500);
-          }
-        }
-        else
-          break;
-        if(nbw != nbr)
-        {
-          file.close();
-          /*! Internal server error.  */
-          return td->http->raiseHTTPError(500);
+            u_long nbr = 0, nbw = 0;
+            if(td->inputData.read (td->buffer->getBuffer(),
+                                   td->buffer->getRealLength(), &nbr))
+              {
+                file.close ();
+                return td->http->raiseHTTPError(500);
+              }
+
+            if(nbr)
+              {
+                if (file.writeToFile (td->buffer->getBuffer (), nbr, &nbw))
+                  {
+                    file.close ();
+                  return td->http->raiseHTTPError (500);
+                  }
+              }
+            else
+              break;
+
+          if (nbw != nbr)
+            {
+              file.close ();
+              return td->http->raiseHTTPError (500);
+            }
         }
-      }
-      file.close();
-      /*! Successful updated.  */
-      td->http->raiseHTTPError(200);
+        file.close ();
 
-      return keepalive;
-    }
-    else
-    {
-      /*!
-       *If the file doesn't exist create it.
-       */
-      File file;
-      if(file.openFile(td->filenamePath.c_str(),
-                       File::FILE_CREATE_ALWAYS |
-                       File::WRITE))
-      {
-        /*! Internal server error. */
-        return td->http->raiseHTTPError(500);
+        td->http->raiseHTTPError (200);
+        return keepalive;
       }
-      for(;;)
+    else
       {
-        u_long nbr = 0, nbw = 0;
-        if(td->inputData.read(td->buffer->getBuffer(),
-                                      td->buffer->getRealLength(), &nbr))
-        {
-          file.close();
-          return td->http->raiseHTTPError(500);
-        }
-        if(nbr)
-        {
-          if(file.writeToFile(td->buffer->getBuffer(), nbr, &nbw))
+        /* The file doesn't exist.  */
+        File file;
+        if(file.openFile(td->filenamePath.c_str(),
+                         File::FILE_CREATE_ALWAYS |
+                         File::WRITE))
           {
-            file.close();
+            /* Internal server error. */
             return td->http->raiseHTTPError(500);
           }
-        }
-        else
-          break;
-        if( nbw != nbr )
-        {
-          file.close();
-          return td->http->raiseHTTPError(500);
-        }
+
+        for (;;)
+          {
+            u_long nbr = 0, nbw = 0;
+            if (td->inputData.read (td->buffer->getBuffer (),
+                                    td->buffer->getRealLength (), &nbr))
+              {
+                file.close ();
+                return td->http->raiseHTTPError (500);
+              }
+            if(nbr)
+              {
+                if (file.writeToFile (td->buffer->getBuffer (), nbr, &nbw))
+                  {
+                    file.close ();
+                    return td->http->raiseHTTPError (500);
+                  }
+              }
+            else
+              break;
+            if( nbw != nbr )
+              {
+                file.close ();
+                return td->http->raiseHTTPError (500);
+              }
+          }
+        file.close ();
+
+        td->http->raiseHTTPError (201);
+        return 1;
       }
-      file.close();
-      /*! Successful created. */
-      td->http->raiseHTTPError(201);
-      return 1;
-    }
   }
-  catch(...)
-  {
-    return td->http->raiseHTTPError(500);
-  };
+  catch (...)
+    {
+      return td->http->raiseHTTPError (500);
+    };
 }
 
 /*!
- *Delete the resource identified by filename.
+ * Delete the resource identified by filename.
  */
 int HttpFile::deleteFile (HttpThreadContext* td,
                           string& filename)
@@ -171,53 +164,48 @@ int HttpFile::deleteFile (HttpThreadContext* td,
   int ret;
   try
   {
-    HttpHeaders::buildDefaultHTTPResponseHeader(&td->response);
-
-    if(!(td->permissions & MYSERVER_PERMISSION_DELETE))
-      return td->http->sendAuth();
+    HttpHeaders::buildDefaultHTTPResponseHeader (&td->response);
 
-    if(FilesUtility::fileExists(td->filenamePath))
-    {
-      FilesUtility::deleteFile(td->filenamePath.c_str());
+    if (!(td->permissions & MYSERVER_PERMISSION_DELETE))
+      return td->http->sendAuth ();
 
-      /*! Successful deleted.  */
-      return td->http->raiseHTTPError(202);
-    }
+    if (FilesUtility::fileExists (td->filenamePath))
+      {
+        FilesUtility::deleteFile (td->filenamePath.c_str ());
+        return td->http->raiseHTTPError (202);
+      }
     else
-    {
-      /*! No content.  */
-      return td->http->raiseHTTPError(204);
-    }
+      return td->http->raiseHTTPError (204);
   }
   catch(...)
-  {
-    return td->http->raiseHTTPError(500);
-  };
+    {
+      return td->http->raiseHTTPError (500);
+    };
 
 }
 
 /*!
- *Send a file to the client using the HTTP protocol.
- *\param td The current HTTP thread context.
- *\param filenamePath The path of the static file to send.
- *\param exec Not used.
- *\param execute Not used.
- *\param onlyHeader Specify if send only the HTTP header.
+ * Send a file to the client using the HTTP protocol.
+ * \param td The current HTTP thread context.
+ * \param filenamePath The path of the static file to send.
+ * \param exec Not used.
+ * \param execute Not used.
+ * \param onlyHeader Specify if send only the HTTP header.
   */
-int HttpFile::send(HttpThreadContext* td,
-                   const char *filenamePath,
-                   const char* exec,
-                   bool execute,
-                   bool onlyHeader)
+int HttpFile::send (HttpThreadContext* td,
+                    const char *filenamePath,
+                    const char* exec,
+                    bool execute,
+                    bool onlyHeader)
 {
   /*
-   *With this routine we send a file through the HTTP protocol.
-   *Open the file and save its handle.
+   * With this routine we send a file through the HTTP protocol.
+   * Open the file and save its handle.
    */
   int ret;
 
   /* 
-   *Will we use GZIP compression to send data?
+   * Will we use GZIP compression to send data?
    */
   bool useGzip = false;
   u_long filesize = 0;
@@ -228,7 +216,7 @@ int HttpFile::send(HttpThreadContext* td,
   bool keepalive = false;
   bool useChunks = false;
   bool useModifiers = false;
-  MemoryStream memStream(td->secondaryBuffer);
+  MemoryStream memStream (td->secondaryBuffer);
   FiltersChain chain;
   u_long nbw;
   u_long nbr;
@@ -239,54 +227,52 @@ int HttpFile::send(HttpThreadContext* td,
   try
   {
 
-    if(!td->request.cmd.compare("PUT"))
+    if (!td->request.cmd.compare ("PUT"))
       return putFile (td, td->filenamePath);
 
-    if(!td->request.cmd.compare("DELETE"))
+    if (!td->request.cmd.compare ("DELETE"))
       return deleteFile (td, td->filenamePath);
 
-    if ( !(td->permissions & MYSERVER_PERMISSION_READ))
+    if (!(td->permissions & MYSERVER_PERMISSION_READ))
       return td->http->sendAuth ();
 
     if (!FilesUtility::fileExists (filenamePath))
       return td->http->raiseHTTPError(404);
 
-    lastMT = FilesUtility::getLastModTime(td->filenamePath.c_str());
-    if(lastMT == -1)
+    lastMT = FilesUtility::getLastModTime (td->filenamePath.c_str());
+
+    if (lastMT == -1)
       return td->http->raiseHTTPError(500);
 
-    getRFC822GMTTime(lastMT, tmpTime, HTTP_RESPONSE_LAST_MODIFIED_DIM);
-    td->response.lastModified.assign(tmpTime);
+    getRFC822GMTTime (lastMT, tmpTime, HTTP_RESPONSE_LAST_MODIFIED_DIM);
+    td->response.lastModified.assign (tmpTime);
 
     HttpRequestHeader::Entry *ifModifiedSince = 
-      td->request.other.get("Last-Modified");
+      td->request.other.get ("Last-Modified");
 
-    if(ifModifiedSince && ifModifiedSince->value->length() && 
-       !ifModifiedSince->value->compare(td->response.lastModified.c_str()))
-          return td->http->sendHTTPNonModified();
+    if (ifModifiedSince && ifModifiedSince->value->length () && 
+       !ifModifiedSince->value->compare(td->response.lastModified.c_str ()))
+          return td->http->sendHTTPNonModified ();
+
+    file = Server::getInstance ()->getCachedFiles ()->open (filenamePath);
+    if (file == 0)
+      return td->http->raiseHTTPError (500);
 
-    file = Server::getInstance()->getCachedFiles()->open(filenamePath);
-    if(file == 0)
-    {  
-      return td->http->raiseHTTPError(500);
-    }
     /*
-     *Check how many bytes are ready to be send.  
+     * Check how many bytes are ready to be send.  
      */
-    filesize = file->getFileSize();
+    filesize = file->getFileSize ();
     bytesToSend = filesize;
-    if(lastByte == 0)
-    {
+    if (lastByte == 0)
       lastByte = bytesToSend;
-    }
     else
-    {
-      /* 
-       *If the client use ranges set the right value 
-       *for the last byte number.  
-       */
-      lastByte = std::min(lastByte + 1, bytesToSend);
-    }
+      {
+        /* 
+         * If the client use ranges set the right value 
+         * for the last byte number.  
+         */
+        lastByte = std::min (lastByte + 1, bytesToSend);
+      }
 
     /*
      * bytesToSend is the interval between the first and the last byte.  
@@ -297,412 +283,361 @@ int HttpFile::send(HttpThreadContext* td,
      * If fail to set the file pointer returns an internal server error.  
      */
     ret = file->seek (firstByte);
-    if(ret)
-    {
-      file->close();
-      delete file;
-      return td->http->raiseHTTPError(500);
-    }
-
+    if (ret)
+      {
+        file->close();
+        delete file;
+        return td->http->raiseHTTPError(500);
+      }
 
-    {
-      /* 
-       *Use GZIP compression to send files bigger than GZIP threshold.  
-       */
-      const char *val = td->securityToken.getHashedData ("gzip.threshold", 
-                                                         
MYSERVER_SECURITY_CONF | 
-                                                         MYSERVER_VHOST_CONF |
-                                                         MYSERVER_MIME_CONF |
-                                                         MYSERVER_SERVER_CONF, 
"0");
+    /*
+     * Use GZIP compression to send files bigger than GZIP threshold.
+     */
+    const char *val = td->securityToken.getHashedData ("gzip.threshold",
+                                                       MYSERVER_SECURITY_CONF
+                                                       | MYSERVER_VHOST_CONF
+                                                       | MYSERVER_MIME_CONF
+                                                       | MYSERVER_SERVER_CONF, 
"0");
 
-      useGzip = false;
-      if (val)
+    useGzip = false;
+    if (val)
       {
         u_long gzipThreshold = atoi (val);
-        if(bytesToSend >= gzipThreshold)
+        if (bytesToSend >= gzipThreshold)
           useGzip = true;
       }
 
-    }
-
-    keepalive = td->request.isKeepAlive();
+    keepalive = td->request.isKeepAlive ();
 
 #ifndef DO_NOT_USEGZIP
     /*
-     *Be sure that the client accept GZIP compressed data.  
+     * Be sure that the client accept GZIP compressed data.
      */
-    if(useGzip)
-    {
-      HttpRequestHeader::Entry* e = td->request.other.get("Accept-Encoding");
-      if(e)
+    if (useGzip)
       {
-        useGzip &= (e->value->find("gzip") != string::npos);
+        HttpRequestHeader::Entry* e = td->request.other.get("Accept-Encoding");
+        if(e)
+          useGzip &= (e->value->find("gzip") != string::npos);
+        else
+          useGzip = false;
       }
-      else
-        useGzip = false;
-
-    }
 #else
-    /* 
-     * If compiled without GZIP support force the server to don't use it.  
-     */
+    /* If compiled without GZIP support force the server to don't use it.  */
     useGzip = false;
 #endif  
-    if(td->appendOutputs)
+    if (td->appendOutputs)
       useGzip = false;
 
-    td->buffer->setLength(0);
+    td->buffer->setLength (0);
 
     /* If a Range was requested send 206 and not 200 for success.  */
-    if( td->request.rangeByteBegin ||  td->request.rangeByteEnd )
-    {  
-      HttpResponseHeader::Entry *e;
-      ostringstream buffer;
-      td->response.httpStatus = 206;
-      buffer << "bytes "<< (u_long)firstByte << "-" 
-             << (u_long)lastByte << "/" << (u_long)filesize ;
-
-      e = td->response.other.get("Content-Range");
-      if(e)
-        e->value->assign(buffer.str());
-      else
+    if (td->request.rangeByteBegin || td->request.rangeByteEnd)
       {
-        e = new HttpResponseHeader::Entry();
-        e->name->assign("Content-Range");
-        e->value->assign(buffer.str());
-        td->response.other.put(*(e->name), e);
-      }
-
+        HttpResponseHeader::Entry *e;
+        ostringstream buffer;
+        td->response.httpStatus = 206;
+        buffer << "bytes "<< (u_long)firstByte << "-"
+               << (u_long)lastByte << "/" << (u_long)filesize ;
+
+        e = td->response.other.get ("Content-Range");
+        if (e)
+          e->value->assign (buffer.str ());
+      else
+        {
+          e = new HttpResponseHeader::Entry ();
+          e->name->assign ("Content-Range");
+          e->value->assign (buffer.str());
+          td->response.other.put (*(e->name), e);
+        }
 
-      e = td->response.other.get("Transfer-Encoding");
-      if(e)
-        e->value->assign("chunked");
+      e = td->response.other.get ("Transfer-Encoding");
+      if (e)
+        e->value->assign ("chunked");
       else
-      {
-        e = new HttpResponseHeader::Entry();
-        e->name->assign("Transfer-Encoding");
-        e->value->assign("chunked");
-        td->response.other.put(*(e->name), e);
-      }
+        {
+          e = new HttpResponseHeader::Entry();
+          e->name->assign ("Transfer-Encoding");
+          e->value->assign ("chunked");
+          td->response.other.put (*(e->name), e);
+        }
 
       useGzip = false;
     }
-    chain.setProtocol(td->http);
-    chain.setProtocolData(td);
-    chain.setStream(&memStream);
-    if(td->mime)
-    {
-      if(td->mime && 
-         Server::getInstance()->getFiltersFactory()->chain (&chain,
-                                                            td->mime->filters,
-                                                            &memStream,
-                                                            &nbw))
+    chain.setProtocol (td->http);
+    chain.setProtocolData (td);
+    chain.setStream (&memStream);
+    if (td->mime)
       {
-        file->close();
-        delete file;
-        chain.clearAllFilters();
-        return 0;
-      }
+        if (td->mime &&
+            Server::getInstance()->getFiltersFactory()->chain (&chain,
+                                                               
td->mime->filters,
+                                                               &memStream,
+                                                               &nbw))
+          {
+            file->close ();
+            delete file;
+            chain.clearAllFilters ();
+            return 0;
+          }
       memStream.refresh();
-
       dataSent += nbw;
     }
     
-    if(useGzip && !chain.isFilterPresent("gzip"))
-    {
-      Filter* gzipFilter = 
-        Server::getInstance()->getFiltersFactory()->getFilter("gzip");
-      u_long nbw;
-      if(!gzipFilter)
-      {
-        file->close();
-        delete file;
-        chain.clearAllFilters();
-        return 0;
-      }
-      if(chain.addFilter (gzipFilter, &nbw))
+    if (useGzip && !chain.isFilterPresent ("gzip"))
       {
-        delete gzipFilter;
-        file->close();
-        delete file;
-        chain.clearAllFilters();
-        return 0;
+        Filter* gzipFilter =
+          Server::getInstance()->getFiltersFactory()->getFilter ("gzip");
+        u_long nbw;
+        if (!gzipFilter)
+          {
+            file->close ();
+            delete file;
+            chain.clearAllFilters ();
+            return 0;
+          }
+        if (chain.addFilter (gzipFilter, &nbw))
+          {
+            delete gzipFilter;
+            file->close ();
+            delete file;
+            chain.clearAllFilters ();
+            return 0;
+          }
+        dataSent += nbw;
       }
-      dataSent += nbw;
-    }
 
-    useModifiers = chain.hasModifiersFilters();
+    useModifiers = chain.hasModifiersFilters ();
  
-    if(keepalive && !useModifiers)
-    {
-      ostringstream buffer;
-      buffer << (u_int)bytesToSend;
-      td->response.contentLength.assign(buffer.str());
-    }
+    if (keepalive && !useModifiers)
+      {
+        ostringstream buffer;
+        buffer << (u_int)bytesToSend;
+        td->response.contentLength.assign (buffer.str ());
+      }
 
-    /* Specify the connection type.  */
-    if(keepalive)
-    {
+    if (keepalive)
       td->response.connection.assign("keep-alive");
-    }
     else
-    {
       td->response.connection.assign("close");
-    }
 
-    if(useModifiers)
-    {
-      string s;
-      HttpResponseHeader::Entry *e;
-      chain.getName(s);
-      e = td->response.other.get("Content-Encoding");
-      if(e)
-        e->value->assign(s);
-      else
-      {
-        e = new HttpResponseHeader::Entry();
-        e->name->assign("Content-Encoding");
-        e->value->assign(s);
-        td->response.other.put(*(e->name), e);
-      }
-      /* Do not use chunked transfer with old HTTP/1.0 clients.  */
-      if(keepalive)
+    if (useModifiers)
       {
+        string s;
         HttpResponseHeader::Entry *e;
-        e = td->response.other.get("Transfer-Encoding");
-        if(e)
-          e->value->assign("chunked");
+        chain.getName(s);
+        e = td->response.other.get ("Content-Encoding");
+        if (e)
+        e->value->assign (s);
         else
+          {
+            e = new HttpResponseHeader::Entry ();
+            e->name->assign ("Content-Encoding");
+            e->value->assign (s);
+            td->response.other.put (*(e->name), e);
+          }
+        /* Do not use chunked transfer with old HTTP/1.0 clients.  */
+      if (keepalive)
         {
-          e = new HttpResponseHeader::Entry();
-          e->name->assign("Transfer-Encoding");
-          e->value->assign("chunked");
-          td->response.other.put(*(e->name), e);
+          HttpResponseHeader::Entry *e;
+          e = td->response.other.get ("Transfer-Encoding");
+          if(e)
+            e->value->assign ("chunked");
+          else
+            {
+              e = new HttpResponseHeader::Entry ();
+              e->name->assign ("Transfer-Encoding");
+              e->value->assign ("chunked");
+              td->response.other.put (*(e->name), e);
+            }
+          useChunks = true;
         }
-
-        useChunks = true;
       }
-    }
  
-    u_long hdrLen = 
HttpHeaders::buildHTTPResponseHeader(td->buffer->getBuffer(), 
-                                                         &td->response);
+    u_long hdrLen = HttpHeaders::buildHTTPResponseHeader 
(td->buffer->getBuffer(),
+                                                          &td->response);
 
-    td->buffer->setLength(hdrLen);
+    td->buffer->setLength (hdrLen);
 
-    if(!td->appendOutputs)
-    {
-      /* Send the HTTP header.  */
-      if(td->connection->socket->send(td->buffer->getBuffer(),
-                         (u_long)td->buffer->getLength(), 0) == SOCKET_ERROR)
+    if (!td->appendOutputs)
       {
-        file->close();
-        delete file;
-        chain.clearAllFilters();
+        /* Send the HTTP header.  */
+      if (td->connection->socket->send(td->buffer->getBuffer(),
+                                       (u_long)td->buffer->getLength(),
+                                       0) == SOCKET_ERROR)
+        {
+          file->close ();
+          delete file;
+        chain.clearAllFilters ();
         return 1;
+        }
       }
-    }
 
     /*
-     *If is requested only the header exit from the function; 
-     *used by the HEAD request.  
+     * If is requested only the header exit from the function;
+     * used by the HEAD request.
      */
-    if(onlyHeader)
-    {
-      file->close();
-      delete file;
-      chain.clearAllFilters();
-      return 0;
-    }
+    if (onlyHeader)
+      {
+        file->close ();
+        delete file;
+        chain.clearAllFilters ();
+        return 0;
+      }
 
-    /* 
+    /*
      * Check if there are all the conditions to use a direct copy from the 
      * file to the socket.
      */
-    if(!useChunks && chain.isEmpty() && 
-       !td->appendOutputs &&
-       !(td->http->getProtocolOptions() & PROTOCOL_USES_SSL))
-    {
-      u_long nbw = 0;
-      int ret = file->fastCopyToSocket (td->connection->socket, firstByte,
-                                        td->buffer, &nbw);
+    if (!useChunks && chain.isEmpty () && !td->appendOutputs
+        && !(td->http->getProtocolOptions() & PROTOCOL_USES_SSL))
+      {
+        u_long nbw = 0;
+        int ret = file->fastCopyToSocket (td->connection->socket, firstByte,
+                                          td->buffer, &nbw);
 
-      file->close();
-      delete file;
+        file->close ();
+        delete file;
 
-      chain.clearAllFilters();
+        chain.clearAllFilters ();
 
-      td->sentData += nbw;
+        td->sentData += nbw;
 
-      return ret;
-    }
+        return ret;
+      }
 
-    if(td->appendOutputs)
-      chain.setStream(&(td->outputData));
+    if (td->appendOutputs)
+      chain.setStream (&(td->outputData));
     else
-      chain.setStream(td->connection->socket);
+      chain.setStream (td->connection->socket);
 
     /*
-     *Flush initial data.  This is data that filters could have added
-     *and we have to send before the file itself, for example the gzip
-     *filter add a header to file.
+     * Flush initial data.  This is data that filters could have added
+     * and we have to send before the file itself, for example the gzip
+     * filter add a header to file.
      */
-    if(memStream.availableToRead())
-    {
-      ret = memStream.read(td->buffer->getBuffer(),
-                           td->buffer->getRealLength(), 
-                           &nbr);
-      
-      if(ret)
+    if (memStream.availableToRead ())
       {
-        file->close();
-        delete file;
-        chain.clearAllFilters();
-        return 0;
-      }
+        if (memStream.read (td->buffer->getBuffer(),
+                              td->buffer->getRealLength(),
+                            &nbr))
+          {
+            file->close ();
+            delete file;
+            chain.clearAllFilters ();
+            return 0;
+          }
 
-      memStream.refresh();
-
-      if(nbr)
-      {
-        if(HttpDataHandler::appendDataToHTTPChannel(td, 
-                                                    td->buffer->getBuffer(), 
-                                                    nbr,
-                                                    &(td->outputData), 
-                                                    &chain,
-                                                    td->appendOutputs, 
-                                                    useChunks))
-        {
-          file->close();
-          delete file;
-          chain.clearAllFilters();
-          return 1;
-          dataSent += nbw;
-        }
-      } /* nbr.  */
-    } /* memStream.availableToRead().  */
+        memStream.refresh ();
 
+        if (nbr)
+          {
+            if (HttpDataHandler::appendDataToHTTPChannel(td,
+                                   td->buffer->getBuffer(),
+                                   nbr, &(td->outputData),
+                                   &chain, td->appendOutputs,
+                                   useChunks))
+              {
+                file->close ();
+                delete file;
+                chain.clearAllFilters ();
+                return 1;
+                dataSent += nbw;
+              }
+          } /* nbr.  */
+      } /* memStream.availableToRead().  */
 
     /* Flush the rest of the file.  */
-    for(;;)
-    {
-      u_long nbr;
-      u_long nbw;
-
-      /* Check if there are other bytes to send.  */
-      if(bytesToSend)
+    for (;;)
       {
-        /* Read from the file the bytes to send.  */
-        ret = file->read(td->buffer->getBuffer(),
-                                 std::min(static_cast<u_long>(bytesToSend), 
-                                          
static_cast<u_long>(td->buffer->getRealLength()/2)), 
-                                 &nbr);
-        if(ret)
-          break;
-
-        if(nbr == 0)
-        {
-          bytesToSend = 0;
-          continue;
-        }
-        
-        bytesToSend -= nbr;
-
-
-        ret = appendDataToHTTPChannel (td, td->buffer->getBuffer (),
-                                       nbr,
-                                       &(td->outputData),
-                                       &chain,
-                                       td->appendOutputs,
-                                       useChunks,
-                                       td->buffer->getRealLength (),
-                                       &memStream);
-        if(ret)
-          break;     
-          
-        dataSent += nbr;
-      }
-      else /* if(bytesToSend) */
-      {
-        /* If we don't use chunks we can flush directly.  */
-        if(!useChunks)
-        {
-          ret = chain.flush(&nbw);
-
-          break;
-        }
-        else
-        {
-          /*
-           *Replace the final stream before the flush and write to a
-           *memory buffer, after all the data is flushed from the
-           *chain we can replace the stream with the original one and
-           *write there the HTTP data chunk.
-           */
-          Stream* tmpStream = chain.getStream();
-
-          chain.setStream(&memStream);
-
-          memStream.refresh();
-
-          ret = chain.flush(&nbw);
-
-          if(ret)
-            break;
-
-          chain.setStream(tmpStream);
-
-          ret = memStream.read(td->buffer->getBuffer(), 
-                               td->buffer->getRealLength(), 
-                               &nbr);
-          if(ret)
-            break;
-
-          ret = HttpDataHandler::appendDataToHTTPChannel(td,
-                                                         
td->buffer->getBuffer(), 
-                                                         nbr,
-                                                         &(td->outputData), 
-                                                         &chain,
-                                                         td->appendOutputs, 
-                                                         useChunks);
-          if(ret)
-            break;
-          
-          ret = HttpDataHandler::appendDataToHTTPChannel(td, 
-                                                         0,
-                                                         0,
-                                                         &(td->outputData), 
-                                                         &chain,
-                                                         td->appendOutputs, 
-                                                         useChunks);
-        
-          break;
-        }
-      }
-
-      memStream.refresh();
+        u_long nbr;
+        u_long nbw;
 
+        /* Check if there are other bytes to send.  */
+        if (bytesToSend)
+          {
+            /* Read from the file the bytes to send.  */
+            if (ret = file->read (td->buffer->getBuffer(),
+                  std::min (static_cast<u_long> (bytesToSend),
+                  static_cast<u_long> (td->buffer->getRealLength() / 2)),
+                  &nbr))
+              break;
+
+            if (nbr == 0)
+              {
+                bytesToSend = 0;
+                continue;
+              }
+
+            bytesToSend -= nbr;
+
+            if (ret = appendDataToHTTPChannel (td, td->buffer->getBuffer (),
+                     nbr, &(td->outputData), &chain, td->appendOutputs,
+                     useChunks, td->buffer->getRealLength (), &memStream))
+              break;
+
+            dataSent += nbr;
+          }
+        else /* if(bytesToSend) */
+          {
+            /* If we don't use chunks we can flush directly.  */
+            if (!useChunks)
+              {
+                ret = chain.flush (&nbw);
+                break;
+              }
+            else
+              {
+                /*
+                 * Replace the final stream before the flush and write to a
+                 * memory buffer, after all the data is flushed from the
+                 * chain we can replace the stream with the original one and
+                 * write there the HTTP data chunk.
+                 */
+                Stream* tmpStream = chain.getStream ();
+                chain.setStream (&memStream);
+                memStream.refresh ();
+                if (ret = chain.flush (&nbw))
+                  break;
+
+                chain.setStream (tmpStream);
+                if (ret = memStream.read (td->buffer->getBuffer (),
+                    td->buffer->getRealLength(), &nbr))
+                  break;
+
+                if (ret = HttpDataHandler::appendDataToHTTPChannel (td,
+                    td->buffer->getBuffer (), nbr, &(td->outputData),
+                    &chain, td->appendOutputs, useChunks))
+                  break;
+
+                ret = HttpDataHandler::appendDataToHTTPChannel (td, 0, 0,
+                                         &(td->outputData), &chain,
+                                         td->appendOutputs,useChunks);
+                break;
+              }
+          }
+        memStream.refresh ();
     }/* End for loop.  */
 
-    file->close();
-    delete file;
-  }
-  catch (bad_alloc &ba)
-  {
     file->close ();
     delete file;
-    td->connection->host->warningsLogWrite ("HttpFile: Error allocating 
memory");
-    chain.clearAllFilters ();
-    return td->http->raiseHTTPError (500);
   }
+  catch (bad_alloc &ba)
+    {
+      file->close ();
+      delete file;
+      td->connection->host->warningsLogWrite ("HttpFile: Error allocating 
memory");
+      chain.clearAllFilters ();
+      return td->http->raiseHTTPError (500);
+    }
   catch (...)
-  {
-    file->close ();
-    delete file;
-    td->connection->host->warningsLogWrite ("HttpFile: Internal error");
-    chain.clearAllFilters();
-    return td->http->raiseHTTPError (500);
-  };
- 
+    {
+      file->close ();
+      delete file;
+      td->connection->host->warningsLogWrite ("HttpFile: Internal error");
+      chain.clearAllFilters ();
+      return td->http->raiseHTTPError (500);
+    };
+
   /* For logging activity.  */
   td->sentData += dataSent;
 
@@ -711,7 +646,7 @@ int HttpFile::send(HttpThreadContext* td,
 }
 
 /*!
- *Constructor for the class.
+ * Constructor for the class.
  */
 HttpFile::HttpFile ()
 {
@@ -719,7 +654,7 @@ HttpFile::HttpFile ()
 }
 
 /*!
- *Destroy the object.
+ * Destroy the object.
  */
 HttpFile::~HttpFile ()
 {
@@ -727,8 +662,8 @@ HttpFile::~HttpFile ()
 }
 
 /*!
- *Load the static elements.
- *\param confFile Not used.
+ * Load the static elements.
+ * \param confFile Not used.
  */
 int HttpFile::load ()
 {
@@ -736,7 +671,7 @@ int HttpFile::load ()
 }
 
 /*!
- *Unload the static elements.
+ * Unload the static elements.
  */
 int HttpFile::unLoad ()
 {



commit f13e2b6d1fb952d4684eb6f12def7b9cf73fb44e
Author: Giuseppe Scrivano <address@hidden>
Date:   Sun Aug 2 10:17:57 2009 +0200

    Code refactoring: code indentation.

diff --git a/myserver/src/protocol/ftp/ftp.cpp 
b/myserver/src/protocol/ftp/ftp.cpp
index 46ad2f6..23e13d0 100755
--- a/myserver/src/protocol/ftp/ftp.cpp
+++ b/myserver/src/protocol/ftp/ftp.cpp
@@ -32,12 +32,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
MA  02110-1301  USA
 #include <include/conf/security/auth_domain.h>
 
 #ifndef WIN32
-#include <netinet/in.h>
-#ifdef SENDFILE
-#include <sys/sendfile.h>
-#endif
-#include <sys/socket.h>
-#include <arpa/inet.h>
+# include <netinet/in.h>
+# ifdef SENDFILE
+#  include <sys/sendfile.h>
+# endif
+# include <sys/socket.h>
+# include <arpa/inet.h>
 #endif
 
 static DEFINE_THREAD (SendAsciiFile, pParam);
@@ -174,8 +174,6 @@ int FtpuserData::closeDataConnection ()
       m_pDataConnection->socket = NULL;
       m_pDataConnection->setScheduled (0);
     }
-
-  //m_DataConnBusy.unlock();
   m_nFtpstate = USER_LOGGED_IN;
   return 1;
 }
@@ -293,6 +291,7 @@ void ftpReply (ConnectionPtr pConnection, int nReplyCode,
       else
         buffer << nReplyCode << "-" << sReplyText << "\r\n";
     }
+
   pConnection->socket->send (buffer.str ().c_str (),
                             strlen (buffer.str ().c_str ()), 0);
 }
@@ -574,7 +573,7 @@ void Ftp::pasv ()
 #endif //WIN32
   ftpReply (227, sTempText);
 
-  //wait for incoming connection
+  // wait for incoming connection
   int timeoutvalue = 3;
 #ifdef __linux__
   timeoutvalue = 1;
@@ -585,21 +584,22 @@ void Ftp::pasv ()
   MYSERVER_SOCKADDRIN asockIn;
   int asockInLen = 0;
   Socket asock;
-  if (pFtpuserData->m_pDataConnection->socket->dataOnRead (timeoutvalue, 0) ==
-      1)
+  if (pFtpuserData->m_pDataConnection->socket->dataOnRead (timeoutvalue, 0)
+      == 1)
     {
       asockInLen = sizeof (sockaddr_in);
       asock =
-       pFtpuserData->m_pDataConnection->socket->accept (&asockIn,
-                                                        &asockInLen);
+        pFtpuserData->m_pDataConnection->socket->accept (&asockIn,
+                                                         &asockInLen);
       if (asock.getHandle () == (Handle) INVALID_SOCKET)
-       return;
+        return;
 
       pFtpuserData->m_pDataConnection->socket->shutdown (SD_BOTH);
       pFtpuserData->m_pDataConnection->socket->close ();
       delete pFtpuserData->m_pDataConnection->socket;
       pFtpuserData->m_pDataConnection->socket = new Socket (asock);
     }
+
   pFtpuserData->m_bPassiveSrv = false;
 }
 
@@ -607,29 +607,23 @@ void Ftp::retrstor (bool bretr, bool bappend, const 
std::string & sPath)
 {
   std::string sLocalPath;
   if (!userLoggedIn ())
-    {
-      //closeDataConnection();
-      return;
-    }
+    return;
+
   if ((bretr && !getLocalPath (sPath, sLocalPath)) ||
       (!bretr && !buildLocalPath (sPath, sLocalPath)))
-    {
-      //closeDataConnection();
-      return;
-    }
+    return;
 
   std::string sLocalDir, sLocalFileName;
   FilesUtility::splitPath (sLocalPath, sLocalDir, sLocalFileName);
 
   /* The security file doesn't exist in any case.  */
   const char *secName = td.st.getHashedData ("security.filename",
-                                            MYSERVER_VHOST_CONF |
-                                            MYSERVER_SERVER_CONF,
-                                            ".security.xml");
+                                             MYSERVER_VHOST_CONF |
+                                             MYSERVER_SERVER_CONF,
+                                             ".security.xml");
   if (!strcmpi (sLocalFileName.c_str (), secName))
     {
       ftpReply (550);
-      //closeDataConnection();
       return;
     }
 
@@ -642,12 +636,10 @@ void Ftp::retrstor (bool bretr, bool bappend, const 
std::string & sPath)
   FtpuserData *pFtpuserData =
     static_cast < FtpuserData * >(td.pConnection->protocolBuffer);
 
-  if (checkRights
-      (pFtpuserData->m_suserName, pFtpuserData->m_sPass, sLocalPath,
-       nMask) == 0)
+  if (checkRights (pFtpuserData->m_suserName, pFtpuserData->m_sPass,
+                   sLocalPath, nMask) == 0)
     {
       ftpReply (530);
-      //closeDataConnection();
       return;
     }
 
@@ -1015,22 +1007,22 @@ DEFINE_THREAD (SendImageFile, pParam)
                                                       c_str ());
     if (file == NULL)
       {
-       ftpReply (pConnection, 451);
-       pFtpuserData->closeDataConnection ();
-       pFtpuserData->m_DataConnBusy.unlock ();
-       delete pWt;
+        ftpReply (pConnection, 451);
+        pFtpuserData->closeDataConnection ();
+        pFtpuserData->m_DataConnBusy.unlock ();
+        delete pWt;
 #ifdef WIN32
-       return 0;
+        return 0;
 #elif HAVE_PTHREAD
-       return (void *) 0;
+        return (void *) 0;
 #endif
       }
     u_long filesize = file->getFileSize ();
     u_long nbr, nBufferSize = 0;
     if (pWt->m_bappend && pFtpuserData->m_nrestartOffset < filesize)
       {
-       file->seek (pFtpuserData->m_nrestartOffset);
-       filesize -= pFtpuserData->m_nrestartOffset;
+        file->seek (pFtpuserData->m_nrestartOffset);
+        filesize -= pFtpuserData->m_nrestartOffset;
       }
 
     pFtpuserData->m_sCurrentFileName = pWt->m_sFilePath;
@@ -1040,47 +1032,45 @@ DEFINE_THREAD (SendImageFile, pParam)
     secondaryBuffer.setLength (1024);
     while (filesize != 0)
       {
-       nBufferSize =
-         std::min (static_cast < u_long > (filesize),
-                   static_cast < u_long >
-                   (secondaryBuffer.getRealLength () / 2));
-       if (file->read (secondaryBuffer.getBuffer (), nBufferSize, &nbr)
-           || pFtpuserData->m_pDataConnection->socket->send (secondaryBuffer.
-                                                             getBuffer (),
-                                                             (u_long)
-                                                             nBufferSize,
-                                                             0) ==
-           SOCKET_ERROR)
-         {
-           ftpReply (pConnection, 451);
-           file->close ();
-           delete file;
-           pFtpuserData->closeDataConnection ();
-           pFtpuserData->m_DataConnBusy.unlock ();
-           delete pWt;
+        nBufferSize =
+          std::min (static_cast < u_long > (filesize),
+                    static_cast < u_long >
+                    (secondaryBuffer.getRealLength () / 2));
+
+        if (file->read (secondaryBuffer.getBuffer (), nBufferSize, &nbr)
+            || pFtpuserData->m_pDataConnection->socket->send 
(secondaryBuffer.getBuffer (),
+                                                              
(u_long)nBufferSize, 0)
+            == SOCKET_ERROR)
+          {
+            ftpReply (pConnection, 451);
+            file->close ();
+            delete file;
+            pFtpuserData->closeDataConnection ();
+            pFtpuserData->m_DataConnBusy.unlock ();
+            delete pWt;
 #ifdef WIN32
-           return 0;
+            return 0;
 #elif HAVE_PTHREAD
-           return (void *) 0;
+            return (void *) 0;
 #endif
-         }
-       filesize -= nbr;
-       pFtpuserData->m_nBytesSent += nbr;
-       pFtpuserData->m_nrestartOffset += nbr;
-       if (pFtpuserData->m_bBreakDataConnection)
-         {
-           pFtpuserData->m_bBreakDataConnection = false;
-           file->close ();
-           delete file;
-           pFtpuserData->closeDataConnection ();
-           pFtpuserData->m_DataConnBusy.unlock ();
-           delete pWt;
+          }
+        filesize -= nbr;
+        pFtpuserData->m_nBytesSent += nbr;
+        pFtpuserData->m_nrestartOffset += nbr;
+        if (pFtpuserData->m_bBreakDataConnection)
+          {
+            pFtpuserData->m_bBreakDataConnection = false;
+            file->close ();
+            delete file;
+            pFtpuserData->closeDataConnection ();
+            pFtpuserData->m_DataConnBusy.unlock ();
+            delete pWt;
 #ifdef WIN32
-           return 1;
+            return 1;
 #elif HAVE_PTHREAD
-           return (void *) 1;
+            return (void *) 1;
 #endif
-         }
+          }
       }
     file->close ();
     delete file;
@@ -1090,7 +1080,6 @@ DEFINE_THREAD (SendImageFile, pParam)
     if (file != NULL)
       file->close ();
     delete file;
-    //report error
   }
 
   pFtpuserData->m_sCurrentFileName = "";
@@ -1168,17 +1157,17 @@ DEFINE_THREAD (ReceiveAsciiFile, pParam)
     {
       ftpReply (pConnection, 150);
       if (pWt->m_pFtp->OpenDataConnection () == 0)
-       {
-         ftpReply (pConnection, 425);
-         pFtpuserData->closeDataConnection ();
-         pFtpuserData->m_DataConnBusy.unlock ();
-         delete pWt;
+        {
+          ftpReply (pConnection, 425);
+          pFtpuserData->closeDataConnection ();
+          pFtpuserData->m_DataConnBusy.unlock ();
+          delete pWt;
 #ifdef WIN32
-         return 0;
+          return 0;
 #elif HAVE_PTHREAD
-         return (void *) 0;
+          return (void *) 0;
 #endif
-       }
+        }
     }
 
   if (pFtpuserData->m_pDataConnection == NULL ||
@@ -1197,106 +1186,102 @@ DEFINE_THREAD (ReceiveAsciiFile, pParam)
 
   File file;
   try
-  {
-    u_long flags = 0;
-    if (pWt->m_bappend)
-      flags = File::APPEND | File::WRITE;
-    else
-      flags = File::FILE_CREATE_ALWAYS | File::WRITE;
-    if (file.openFile (pWt->m_sFilePath.c_str (), flags))
-      {
-       ftpReply (pConnection, 451);
-       pFtpuserData->closeDataConnection ();
-       pFtpuserData->m_DataConnBusy.unlock ();
-       delete pWt;
+    {
+      u_long flags = 0;
+      if (pWt->m_bappend)
+        flags = File::APPEND | File::WRITE;
+      else
+        flags = File::FILE_CREATE_ALWAYS | File::WRITE;
+      if (file.openFile (pWt->m_sFilePath.c_str (), flags))
+        {
+          ftpReply (pConnection, 451);
+          pFtpuserData->closeDataConnection ();
+          pFtpuserData->m_DataConnBusy.unlock ();
+          delete pWt;
 #ifdef WIN32
-       return 0;
+          return 0;
 #elif HAVE_PTHREAD
-       return (void *) 0;
+          return (void *) 0;
 #endif
-      }
+        }
 
-    MemBuf buffer, secondaryBuffer;
-    buffer.setLength (1024);
-    memset (buffer.getBuffer (), 0, buffer.getRealLength ());
-    char *pLine = NULL;
-    int nLineLength = 0;
-    std::string sLine;
-    u_long nbr;
-    while (pFtpuserData->m_pDataConnection->socket->read (buffer.getBuffer (),
-                                                         (u_long) buffer.
-                                                         getRealLength () -
-                                                         1,
-                                                         &nbr) !=
-          SOCKET_ERROR && nbr != 0)
-      {
-       memset (secondaryBuffer.getBuffer (), 0,
-               secondaryBuffer.getRealLength ());
-       secondaryBuffer.setLength (0);
-       pLine = buffer.getBuffer ();
-       if (pLine == NULL)
-         {
-           ftpReply (pConnection, 451);
-           file.close ();
-           pFtpuserData->closeDataConnection ();
-           pFtpuserData->m_DataConnBusy.unlock ();
-           delete pWt;
+      MemBuf buffer, secondaryBuffer;
+      buffer.setLength (1024);
+      memset (buffer.getBuffer (), 0, buffer.getRealLength ());
+      char *pLine = NULL;
+      int nLineLength = 0;
+      std::string sLine;
+      u_long nbr;
+      while (pFtpuserData->m_pDataConnection->socket->read (buffer.getBuffer 
(),
+                                (u_long) buffer.getRealLength () - 1, &nbr)
+            != SOCKET_ERROR && nbr != 0)
+        {
+          memset (secondaryBuffer.getBuffer (), 0,
+                  secondaryBuffer.getRealLength ());
+          secondaryBuffer.setLength (0);
+          pLine = buffer.getBuffer ();
+          if (pLine == NULL)
+            {
+              ftpReply (pConnection, 451);
+              file.close ();
+              pFtpuserData->closeDataConnection ();
+              pFtpuserData->m_DataConnBusy.unlock ();
+              delete pWt;
 #ifdef WIN32
-           return 0;
+              return 0;
 #elif HAVE_PTHREAD
-           return (void *) 0;
+              return (void *) 0;
 #endif
-         }
-       while (*pLine != 0)
-         {
-           nLineLength = getEndLine (pLine, 0);
-           if (nLineLength < 0)        //last line
-             {
-               sLine.assign (pLine, strlen (pLine));
-               if (!sLine.empty ())
-                 secondaryBuffer << sLine;
-               pLine += strlen (pLine);
-             }
-           else
-             {
-               sLine.assign (pLine, nLineLength);
+            }
+        while (*pLine != 0)
+          {
+            nLineLength = getEndLine (pLine, 0);
+            if (nLineLength < 0)       //last line
+              {
+                sLine.assign (pLine, strlen (pLine));
+                if (!sLine.empty ())
+                  secondaryBuffer << sLine;
+                pLine += strlen (pLine);
+              }
+            else
+              {
+                sLine.assign (pLine, nLineLength);
 #ifdef WIN32
-               secondaryBuffer << sLine << "\r\n";
+                secondaryBuffer << sLine << "\r\n";
 #else
-               secondaryBuffer << sLine << "\n";
+                secondaryBuffer << sLine << "\n";
 #endif
-               if (*(pLine + nLineLength) == '\r')
-                 nLineLength++;
-               if (*(pLine + nLineLength) == '\n')
-                 nLineLength++;
-               pLine += nLineLength;
-             }
-         }
-       file.write (secondaryBuffer.getBuffer (),
-                   (u_long) secondaryBuffer.getLength (), &nbr);
-
-       if (pFtpuserData->m_bBreakDataConnection)
-         {
-           pFtpuserData->m_bBreakDataConnection = false;
-           file.close ();
-           pFtpuserData->closeDataConnection ();
-           pFtpuserData->m_DataConnBusy.unlock ();
-           delete pWt;
+                if (*(pLine + nLineLength) == '\r')
+                  nLineLength++;
+                if (*(pLine + nLineLength) == '\n')
+                  nLineLength++;
+                pLine += nLineLength;
+              }
+          }
+        file.write (secondaryBuffer.getBuffer (),
+                    (u_long) secondaryBuffer.getLength (), &nbr);
+
+        if (pFtpuserData->m_bBreakDataConnection)
+          {
+            pFtpuserData->m_bBreakDataConnection = false;
+            file.close ();
+            pFtpuserData->closeDataConnection ();
+            pFtpuserData->m_DataConnBusy.unlock ();
+            delete pWt;
 #ifdef WIN32
-           return 1;
+            return 1;
 #elif HAVE_PTHREAD
-           return (void *) 1;
+            return (void *) 1;
 #endif
-         }
-       memset (buffer.getBuffer (), 0, buffer.getRealLength ());
+          }
+        memset (buffer.getBuffer (), 0, buffer.getRealLength ());
       }
-    file.close ();
-  }
+      file.close ();
+    }
   catch (bad_alloc & ba)
-  {
-    file.close ();
-    //report error
-  }
+    {
+      file.close ();
+    }
 
   ftpReply (pConnection, 226);
   pFtpuserData->closeDataConnection ();
@@ -1369,19 +1354,19 @@ DEFINE_THREAD (ReceiveImageFile, pParam)
     {
       ftpReply (pConnection, 150);
       if (pWt->m_pFtp->OpenDataConnection () == 0)
-       {
-         ftpReply (pConnection, 425);
-         pFtpuserData->closeDataConnection ();
-         pFtpuserData->m_DataConnBusy.unlock ();
-         delete pWt;
+        {
+          ftpReply (pConnection, 425);
+          pFtpuserData->closeDataConnection ();
+          pFtpuserData->m_DataConnBusy.unlock ();
+          delete pWt;
 #ifdef WIN32
-         return 0;
+          return 0;
 #elif HAVE_PTHREAD
-         return (void *) 0;
+          return (void *) 0;
 #endif
-       }
+        }
     }
-
+  
   if (pFtpuserData->m_pDataConnection == NULL ||
       pFtpuserData->m_pDataConnection->socket == NULL)
     {
@@ -1398,57 +1383,56 @@ DEFINE_THREAD (ReceiveImageFile, pParam)
 
   File file;
   try
-  {
-    u_long flags = 0;
-    if (pWt->m_bappend)
-      flags = File::APPEND | File::WRITE;
-    else
-      flags = File::FILE_CREATE_ALWAYS | File::WRITE;
-    if (file.openFile (pWt->m_sFilePath.c_str (), flags))
-      {
-       ftpReply (pConnection, 451);
-       pFtpuserData->closeDataConnection ();
-       pFtpuserData->m_DataConnBusy.unlock ();
-       delete pWt;
+    {
+      u_long flags = 0;
+      if (pWt->m_bappend)
+        flags = File::APPEND | File::WRITE;
+      else
+        flags = File::FILE_CREATE_ALWAYS | File::WRITE;
+      if (file.openFile (pWt->m_sFilePath.c_str (), flags))
+        {
+          ftpReply (pConnection, 451);
+          pFtpuserData->closeDataConnection ();
+          pFtpuserData->m_DataConnBusy.unlock ();
+          delete pWt;
 #ifdef WIN32
-       return 0;
+          return 0;
 #elif HAVE_PTHREAD
-       return (void *) 0;
+          return (void *) 0;
 #endif
-      }
-    u_long nbr;
-    MemBuf buffer;
-    buffer.setLength (1024);
-    memset (buffer.getBuffer (), 0, buffer.getRealLength ());
-    while (pFtpuserData->m_pDataConnection->socket->read (buffer.getBuffer (),
-                                                         (u_long) buffer.
-                                                         getRealLength () -
-                                                         1,
-                                                         &nbr) !=
-          SOCKET_ERROR && nbr != 0)
-      {
-       file.write (buffer.getBuffer (), nbr, &nbr);
-       if (pFtpuserData->m_bBreakDataConnection)
-         {
-           pFtpuserData->m_bBreakDataConnection = false;
-           file.close ();
-           pFtpuserData->closeDataConnection ();
-           pFtpuserData->m_DataConnBusy.unlock ();
-           delete pWt;
+        }
+      u_long nbr;
+      MemBuf buffer;
+      buffer.setLength (1024);
+      memset (buffer.getBuffer (), 0, buffer.getRealLength ());
+      while (pFtpuserData->m_pDataConnection->socket->read (buffer.getBuffer 
(),
+                                                            (u_long) buffer.
+                                                            getRealLength () -
+                                                            1,
+                                                            &nbr) !=
+             SOCKET_ERROR && nbr != 0)
+        {
+          file.write (buffer.getBuffer (), nbr, &nbr);
+          if (pFtpuserData->m_bBreakDataConnection)
+            {
+              pFtpuserData->m_bBreakDataConnection = false;
+              file.close ();
+              pFtpuserData->closeDataConnection ();
+              pFtpuserData->m_DataConnBusy.unlock ();
+              delete pWt;
 #ifdef WIN32
-           return 1;
+              return 1;
 #elif HAVE_PTHREAD
-           return (void *) 1;
+              return (void *) 1;
 #endif
-         }
-      }
-    file.close ();
-  }
+            }
+        }
+      file.close ();
+    }
   catch (bad_alloc & ba)
-  {
-    //report error
-    file.close ();
-  }
+    {
+      file.close ();
+    }
 
   ftpReply (pConnection, 226);
   pFtpuserData->closeDataConnection ();
@@ -1536,7 +1520,6 @@ bool Ftp::getLocalPath (const std::string & sPath, 
std::string & sOutPath)
       ftpReply (550);
       return false;
     }
-
   return true;
 }
 
@@ -1580,9 +1563,8 @@ Ftp::OpenDataConnection ()
   if (pFtpuserData->m_nFtpstate == FtpuserData::DATA_CONNECTION_UP)
     return 1;
 
-  //pFtpuserData->m_DataConnBusy.lock();
-  int nRet =
-    pFtpuserData->m_bPassiveSrv ? openDataPassive () : openDataActive ();
+  int nRet = pFtpuserData->m_bPassiveSrv ? openDataPassive () 
+                                         : openDataActive ();
   if (nRet != 0)
     pFtpuserData->m_nFtpstate = FtpuserData::DATA_CONNECTION_UP;
   return nRet;
@@ -1617,8 +1599,9 @@ Ftp::openDataPassive ()
     htons (getPortNo (pFtpuserData->m_cdh));
   if (pSocket->
       setsockopt (SOL_SOCKET, SO_REUSEADDR, (const char *) &nReuseAddr,
-                 sizeof (nReuseAddr)) < 0)
+                  sizeof (nReuseAddr)) < 0)
     return 0;
+
   if (pSocket->bind (&storage, sizeof (sockaddr_in)) != 0
       || pSocket->listen (SOMAXCONN) != 0)
     return 0;
@@ -1674,17 +1657,18 @@ Ftp::type (int ntypeCode, int nFormatControlCode /* = 
-1 */ )
     {
     case FtpuserData::NON_PRINT:
       if (ntypeCode == FtpuserData::REPR_ASCII)
-       pFtpuserData->m_nFtpFormatControl =
-         (FtpuserData::FtpFormatControl) nFormatControlCode;
+        pFtpuserData->m_nFtpFormatControl =
+          (FtpuserData::FtpFormatControl) nFormatControlCode;
       else
-       {
-         ftpReply (501);
-         return 0;
-       }
+        {
+          ftpReply (501);
+          return 0;
+        }
       break;
+
     case FtpuserData::REPR_IMAGE:
       pFtpuserData->m_nFtpFormatControl =
-       (FtpuserData::FtpFormatControl) nFormatControlCode;
+        (FtpuserData::FtpFormatControl) nFormatControlCode;
       break;
     }
 
@@ -1771,96 +1755,96 @@ Ftp::list (const std::string & sParam /*= ""*/ )
       FindData fd;
       //dir MUST ends with '/'
       if (fd.findfirst (sPath))
-       {
-         ftpReply (450);
-         closeDataConnection ();
-         return;
-       }
+        {
+          ftpReply (450);
+          closeDataConnection ();
+          return;
+        }
 
       const char *secName = td.st.getHashedData ("security.filename",
-                                                MYSERVER_VHOST_CONF |
-                                                MYSERVER_SERVER_CONF,
-                                                ".security.xml");
+                                                 MYSERVER_VHOST_CONF |
+                                                 MYSERVER_SERVER_CONF,
+                                                 ".security.xml");
       do
-       {
-         if (fd.name[0] == '.' || !strcmpi (fd.name, secName))
-           continue;
-
-         perm[10] = '\0';
-         perm[0] = fd.attrib == FILE_ATTRIBUTE_DIRECTORY ? 'd' : '-';
-         string completeFileName (sPath);
-         completeFileName.append (fd.name);
-         int guestMask = checkRights ("Guest", "", completeFileName, -1);
-         int pMask = checkRights (username, password, completeFileName, -1);
-
-         //Owner and group permissions are the same.
-         perm[1] = perm[4] = pMask & MYSERVER_PERMISSION_READ ? 'r' : '-';
-         perm[2] = perm[5] = pMask & MYSERVER_PERMISSION_WRITE ? 'w' : '-';
-         perm[3] = perm[6] = pMask & MYSERVER_PERMISSION_EXECUTE ? 'x' : '-';
-
-         //Permission for All are the permission for Guest
-         perm[7] = guestMask & MYSERVER_PERMISSION_READ ? 'r' : '-';
-         perm[8] = guestMask & MYSERVER_PERMISSION_WRITE ? 'w' : '-';
-         perm[9] = guestMask & MYSERVER_PERMISSION_EXECUTE ? 'x' : '-';
-
-         string date;
-         const char *datePtr = getRFC822LocalTime (fd.time_write, date, 32);
-
-         char dateFtpFormat[13];
-
-         dateFtpFormat[3] = ' ';
-         dateFtpFormat[6] = ' ';
-         dateFtpFormat[7] = ' ';
-         dateFtpFormat[12] = '\0';
-
-         int offset = datePtr[6] == ' ' ? 0 : 1;
-
-         //Day
-         dateFtpFormat[4] = datePtr[5];
-         dateFtpFormat[5] = datePtr[6];
-
-         //Month
-         dateFtpFormat[0] = datePtr[7 + offset];
-         dateFtpFormat[1] = datePtr[8 + offset];
-         dateFtpFormat[2] = datePtr[9 + offset];
-
-         //If the file was modified in the last 6 months
-         //show the hour instead of the year
-         if (now - fd.time_write < 60 * 60 * 183 && now > fd.time_write)
-           {
-             //Hour
-             dateFtpFormat[7] = datePtr[16 + offset];
-             dateFtpFormat[8] = datePtr[17 + offset];
-             dateFtpFormat[9] = ':';
-             dateFtpFormat[10] = datePtr[19 + offset];
-             dateFtpFormat[11] = datePtr[20 + offset];
-           }
-         else
-           {
-             //Year
-             dateFtpFormat[8] = datePtr[11 + offset];
-             dateFtpFormat[9] = datePtr[12 + offset];
-             dateFtpFormat[10] = datePtr[13 + offset];
-             dateFtpFormat[11] = datePtr[14 + offset];
-           }
-
-         char nlinkStr[12];
-         memset (nlinkStr, 0, sizeof (char) * 12);
+        {
+          if (fd.name[0] == '.' || !strcmpi (fd.name, secName))
+            continue;
+
+          perm[10] = '\0';
+          perm[0] = fd.attrib == FILE_ATTRIBUTE_DIRECTORY ? 'd' : '-';
+          string completeFileName (sPath);
+          completeFileName.append (fd.name);
+          int guestMask = checkRights ("Guest", "", completeFileName, -1);
+          int pMask = checkRights (username, password, completeFileName, -1);
+
+          //Owner and group permissions are the same.
+          perm[1] = perm[4] = pMask & MYSERVER_PERMISSION_READ ? 'r' : '-';
+          perm[2] = perm[5] = pMask & MYSERVER_PERMISSION_WRITE ? 'w' : '-';
+          perm[3] = perm[6] = pMask & MYSERVER_PERMISSION_EXECUTE ? 'x' : '-';
+
+          //Permission for All are the permission for Guest
+          perm[7] = guestMask & MYSERVER_PERMISSION_READ ? 'r' : '-';
+          perm[8] = guestMask & MYSERVER_PERMISSION_WRITE ? 'w' : '-';
+          perm[9] = guestMask & MYSERVER_PERMISSION_EXECUTE ? 'x' : '-';
+
+          string date;
+          const char *datePtr = getRFC822LocalTime (fd.time_write, date, 32);
+
+          char dateFtpFormat[13];
+
+          dateFtpFormat[3] = ' ';
+          dateFtpFormat[6] = ' ';
+          dateFtpFormat[7] = ' ';
+          dateFtpFormat[12] = '\0';
+
+          int offset = datePtr[6] == ' ' ? 0 : 1;
+
+          //Day
+          dateFtpFormat[4] = datePtr[5];
+          dateFtpFormat[5] = datePtr[6];
+
+          //Month
+          dateFtpFormat[0] = datePtr[7 + offset];
+          dateFtpFormat[1] = datePtr[8 + offset];
+          dateFtpFormat[2] = datePtr[9 + offset];
+
+          //If the file was modified in the last 6 months
+          //show the hour instead of the year
+          if (now - fd.time_write < 60 * 60 * 183 && now > fd.time_write)
+            {
+              //Hour
+              dateFtpFormat[7] = datePtr[16 + offset];
+              dateFtpFormat[8] = datePtr[17 + offset];
+              dateFtpFormat[9] = ':';
+              dateFtpFormat[10] = datePtr[19 + offset];
+              dateFtpFormat[11] = datePtr[20 + offset];
+            }
+          else
+            {
+              //Year
+              dateFtpFormat[8] = datePtr[11 + offset];
+              dateFtpFormat[9] = datePtr[12 + offset];
+              dateFtpFormat[10] = datePtr[13 + offset];
+              dateFtpFormat[11] = datePtr[14 + offset];
+            }
+
+          char nlinkStr[12];
+          memset (nlinkStr, 0, sizeof (char) * 12);
 #ifndef WIN32
-         nlink_t nlink = 1;
-         nlink = fd.getStatStruct ()->st_nlink;
-         sprintf (nlinkStr, "%lu", (u_long) nlink);
+          nlink_t nlink = 1;
+          nlink = fd.getStatStruct ()->st_nlink;
+          sprintf (nlinkStr, "%lu", (u_long) nlink);
 #endif
 
-         char fdSizeStr[12];
-         sprintf (fdSizeStr, "%li", fd.size);
+          char fdSizeStr[12];
+          sprintf (fdSizeStr, "%li", fd.size);
 
-         secondaryBuffer << (const char *) perm << " " << nlinkStr << " "
-           << username << " " << username << " " << fdSizeStr
-           << " " << (const char *) dateFtpFormat << " "
-           << fd.name << "\r\n";
+          secondaryBuffer << (const char *) perm << " " << nlinkStr << " "
+                          << username << " " << username << " " << fdSizeStr
+                          << " " << (const char *) dateFtpFormat << " "
+                          << fd.name << "\r\n";
 
-       }
+        }
       while (!fd.findnext ());
       fd.findclose ();
     }
@@ -1871,97 +1855,98 @@ Ftp::list (const std::string & sParam /*= ""*/ )
       FilesUtility::splitPath (sLocalPath, sDir, sFileName);
       FindData fd;
       if (fd.findfirst (sDir))
-       {
-         ftpReply (450);
-         closeDataConnection ();
-         return;
-       }
+        {
+          ftpReply (450);
+          closeDataConnection ();
+          return;
+        }
       do
-       {
-         if (strcmp (fd.name, sFileName.c_str ()) != 0)
-           continue;
-
-         perm[10] = '\0';
-         perm[0] = fd.attrib == FILE_ATTRIBUTE_DIRECTORY ? 'd' : '-';
-
-         string completeFileName (sDir);
-         completeFileName.append (fd.name);
-
-         int guestMask = checkRights ("guest", "", completeFileName, -1);
-         int pMask = checkRights (username, password, completeFileName, -1);
-         //Owner and group permissions are the same.
-         perm[1] = perm[4] = pMask & MYSERVER_PERMISSION_READ ? 'r' : '-';
-         perm[2] = perm[5] = pMask & MYSERVER_PERMISSION_WRITE ? 'w' : '-';
-         perm[3] = perm[6] = pMask & MYSERVER_PERMISSION_EXECUTE ? 'x' : '-';
-
-         //Permission for All are the permission for Guest
-         perm[7] = guestMask & MYSERVER_PERMISSION_READ ? 'r' : '-';
-         perm[8] = guestMask & MYSERVER_PERMISSION_WRITE ? 'w' : '-';
-         perm[9] = guestMask & MYSERVER_PERMISSION_EXECUTE ? 'x' : '-';
-
-         string date;
-         const char *datePtr = getRFC822LocalTime (fd.time_write, date, 32);
-
-         char dateFtpFormat[13];
-
-         dateFtpFormat[3] = ' ';
-         dateFtpFormat[6] = ' ';
-         dateFtpFormat[7] = ' ';
-         dateFtpFormat[12] = '\0';
-
-         int offset = datePtr[6] == ' ' ? 0 : 1;
-
-         //Day
-         dateFtpFormat[4] = datePtr[5];
-         dateFtpFormat[5] = datePtr[6];
-
-         //Month
-         dateFtpFormat[0] = datePtr[7 + offset];
-         dateFtpFormat[1] = datePtr[8 + offset];
-         dateFtpFormat[2] = datePtr[9 + offset];
-
-         //If the file was modified in the last 6 months
-         //show the hour instead of the year
-         if (now - fd.time_write < 60 * 60 * 183 && now > fd.time_write)
-           {
-             //Hour
-             dateFtpFormat[7] = datePtr[16 + offset];
-             dateFtpFormat[8] = datePtr[17 + offset];
-             dateFtpFormat[9] = ':';
-             dateFtpFormat[10] = datePtr[19 + offset];
-             dateFtpFormat[11] = datePtr[20 + offset];
-           }
-         else
-           {
-             //Year
-             dateFtpFormat[8] = datePtr[11 + offset];
-             dateFtpFormat[9] = datePtr[12 + offset];
-             dateFtpFormat[10] = datePtr[13 + offset];
-             dateFtpFormat[11] = datePtr[14 + offset];
-           }
-
-         char nlinkStr[12];
-         memset (nlinkStr, 0, sizeof (char) * 12);
+        {
+          if (strcmp (fd.name, sFileName.c_str ()) != 0)
+            continue;
+
+          perm[10] = '\0';
+          perm[0] = fd.attrib == FILE_ATTRIBUTE_DIRECTORY ? 'd' : '-';
+
+          string completeFileName (sDir);
+          completeFileName.append (fd.name);
+
+          int guestMask = checkRights ("guest", "", completeFileName, -1);
+          int pMask = checkRights (username, password, completeFileName, -1);
+          //Owner and group permissions are the same.
+          perm[1] = perm[4] = pMask & MYSERVER_PERMISSION_READ ? 'r' : '-';
+          perm[2] = perm[5] = pMask & MYSERVER_PERMISSION_WRITE ? 'w' : '-';
+          perm[3] = perm[6] = pMask & MYSERVER_PERMISSION_EXECUTE ? 'x' : '-';
+
+          //Permission for All are the permission for Guest
+          perm[7] = guestMask & MYSERVER_PERMISSION_READ ? 'r' : '-';
+          perm[8] = guestMask & MYSERVER_PERMISSION_WRITE ? 'w' : '-';
+          perm[9] = guestMask & MYSERVER_PERMISSION_EXECUTE ? 'x' : '-';
+
+          string date;
+          const char *datePtr = getRFC822LocalTime (fd.time_write, date, 32);
+
+          char dateFtpFormat[13];
+
+          dateFtpFormat[3] = ' ';
+          dateFtpFormat[6] = ' ';
+          dateFtpFormat[7] = ' ';
+          dateFtpFormat[12] = '\0';
+
+          int offset = datePtr[6] == ' ' ? 0 : 1;
+
+          //Day
+          dateFtpFormat[4] = datePtr[5];
+          dateFtpFormat[5] = datePtr[6];
+
+          //Month
+          dateFtpFormat[0] = datePtr[7 + offset];
+          dateFtpFormat[1] = datePtr[8 + offset];
+          dateFtpFormat[2] = datePtr[9 + offset];
+
+          //If the file was modified in the last 6 months
+          //show the hour instead of the year
+          if (now - fd.time_write < 60 * 60 * 183 && now > fd.time_write)
+            {
+              //Hour
+              dateFtpFormat[7] = datePtr[16 + offset];
+              dateFtpFormat[8] = datePtr[17 + offset];
+              dateFtpFormat[9] = ':';
+              dateFtpFormat[10] = datePtr[19 + offset];
+              dateFtpFormat[11] = datePtr[20 + offset];
+            }
+          else
+            {
+              //Year
+              dateFtpFormat[8] = datePtr[11 + offset];
+              dateFtpFormat[9] = datePtr[12 + offset];
+              dateFtpFormat[10] = datePtr[13 + offset];
+              dateFtpFormat[11] = datePtr[14 + offset];
+            }
+
+          char nlinkStr[12];
+          memset (nlinkStr, 0, sizeof (char) * 12);
 #ifndef WIN32
-         nlink_t nlink = 1;
-         nlink = fd.getStatStruct ()->st_nlink;
-         sprintf (nlinkStr, "%lu", (u_long) nlink);
+          nlink_t nlink = 1;
+          nlink = fd.getStatStruct ()->st_nlink;
+          sprintf (nlinkStr, "%lu", (u_long) nlink);
 #endif
 
-         char fdSizeStr[12];
-         sprintf (fdSizeStr, "%li", fd.size);
+          char fdSizeStr[12];
+          sprintf (fdSizeStr, "%li", fd.size);
 
-         secondaryBuffer << (const char *) perm << " " << nlinkStr << " "
-           << username << " " << username << " " << fdSizeStr
-           << " " << (const char *) dateFtpFormat << " "
-           << fd.name << "\r\n";
-       }
+          secondaryBuffer << (const char *) perm << " " << nlinkStr << " "
+                          << username << " " << username << " " << fdSizeStr
+                          << " " << (const char *) dateFtpFormat << " "
+                          << fd.name << "\r\n";
+        }
       while (!fd.findnext ());
       fd.findclose ();
     }
+
   if (pFtpuserData->m_pDataConnection->socket->
       send (td.secondaryBuffer->getBuffer (),
-           (u_long) td.secondaryBuffer->getLength (), 0) == SOCKET_ERROR)
+            (u_long) td.secondaryBuffer->getLength (), 0) == SOCKET_ERROR)
     {
       ftpReply (451);
     }
@@ -2021,19 +2006,18 @@ Ftp::nlst (const std::string & sParam /* = "" */ )
   do
     {
       if (fd.name[0] == '.' || !strcmpi (fd.name, secName))
-       continue;
+        continue;
 
       if (!sParam.empty ())
-       secondaryBuffer << sParam << "/";
+        secondaryBuffer << sParam << "/";
       secondaryBuffer << fd.name << "\r\n";
     }
   while (!fd.findnext ());
-
   fd.findclose ();
 
   if (pFtpuserData->m_pDataConnection->socket->
       send (td.secondaryBuffer->getBuffer (),
-           (u_long) td.secondaryBuffer->getLength (), 0) == SOCKET_ERROR)
+            (u_long) td.secondaryBuffer->getLength (), 0) == SOCKET_ERROR)
     {
       ftpReply (451);
     }
@@ -2066,35 +2050,34 @@ Ftp::escapeTelnet (MemBuf & In, MemBuf & Out)
   while ((u_int) (pIn - In.getBuffer ()) < In.getLength ())
     {
       if (*pIn == '\377')
-       {
-         szReply[0] = *pIn++;
-         if (*pIn == '\0')
-           break;
-         switch (*pIn)
-           {
-           case '\375':        //DO
-           case '\376':        //DONT
-             szReply[1] = '\374';
-             pIn++;
-             break;
-           case '\373':        //WILL
-           case '\374':        //WONT
-             szReply[1] = '\376';
-             pIn++;
-             break;
-           case '\377':
-             szReply[1] = '\0';
-             Out << *pIn;
-             break;
-
-           default:
-             pIn++;
-             continue;
-           }
-         szReply[2] = *pIn++;
-         ftpReply (-1, szReply);
-         continue;
-       }
+        {
+          szReply[0] = *pIn++;
+          if (*pIn == '\0')
+            break;
+          switch (*pIn)
+            {
+            case '\375':       //DO
+            case '\376':       //DONT
+              szReply[1] = '\374';
+            pIn++;
+            break;
+            case '\373':       //WILL
+            case '\374':       //WONT
+              szReply[1] = '\376';
+            pIn++;
+            break;
+            case '\377':
+              szReply[1] = '\0';
+              Out << *pIn;
+              break;
+            default:
+              pIn++;
+              continue;
+            }
+          szReply[2] = *pIn++;
+          ftpReply (-1, szReply);
+          continue;
+        }
       Out << *pIn++;
     }
   Out << '\0';
@@ -2115,7 +2098,7 @@ void Ftp::removePipelinedCmds (MemBuf & In, MemBuf & Out)
     {
       Out << c;
       if (c == '\n')
-       break;
+        break;
     }
   Out << '\0';
 }
@@ -2183,8 +2166,8 @@ void Ftp::cwd (const std::string & sPath)
   else if (sPath.size () != 1 || sPath[0] != '.')
     {
       if (pFtpuserData->m_cwd.size () &&
-         pFtpuserData->m_cwd[pFtpuserData->m_cwd.size () - 1] != '/')
-       pFtpuserData->m_cwd += "/";
+          pFtpuserData->m_cwd[pFtpuserData->m_cwd.size () - 1] != '/')
+        pFtpuserData->m_cwd += "/";
       pFtpuserData->m_cwd += sPath;
     }
 
@@ -2215,7 +2198,7 @@ void Ftp::syst ()
 #ifdef WIN32
     sTempText.replace (n, 2, "WIN32");
 #else
-    sTempText.replace (n, 2, "UNIX type: L8");
+  sTempText.replace (n, 2, "UNIX type: L8");
 #endif //WIN32
   ftpReply (215, sTempText);
 }
@@ -2237,8 +2220,8 @@ void Ftp::stat (const std::string & sParam /* = "" */ )
       std::ostringstream sstat;
       sstat << "Transferring file: " << pFtpuserData->m_sCurrentFileName;
       sstat << " " << pFtpuserData->
-       m_nBytesSent << " bytes transferred from " << pFtpuserData->
-       m_nFileSize;
+        m_nBytesSent << " bytes transferred from " << pFtpuserData->
+        m_nFileSize;
       ftpReply (213, sstat.str ());
     }
   else
@@ -2275,13 +2258,13 @@ void Ftp::stou (const std::string & sPath)
   do
     {
       if (nCount >= 0)
-       {
-         std::ostringstream sRename;
-         sRename << nCount;
-         sTempPath = sPath + sRename.str ();
-       }
+        {
+          std::ostringstream sRename;
+          sRename << nCount;
+          sTempPath = sPath + sRename.str ();
+        }
       if (!buildLocalPath (sTempPath, sOutPath))
-       return;
+        return;
       nCount++;
     }
   while (FilesUtility::fileExists (sOutPath));
@@ -2304,10 +2287,9 @@ void Ftp::dele (const std::string & sPath)
 
   /* The security file doesn't exist in any case.  */
   const char *secName = td.st.getHashedData ("security.filename",
-                                            MYSERVER_VHOST_CONF |
-                                            MYSERVER_SERVER_CONF,
-                                            ".security.xml");
-
+                                             MYSERVER_VHOST_CONF |
+                                             MYSERVER_SERVER_CONF,
+                                             ".security.xml");
   if (!strcmpi (sLocalFileName.c_str (), secName))
     {
       ftpReply (550);
@@ -2320,21 +2302,22 @@ void Ftp::dele (const std::string & sPath)
   if (strcmpi (pFtpuserData->m_suserName.c_str (), "anonymous") == 0)
     {
       if (checkRights ("Guest", "", sLocalFileName, MYSERVER_PERMISSION_WRITE)
-         == 0)
-       {
-         ftpReply (550);
-         return;
-       }
+          == 0)
+        {
+          ftpReply (550);
+          return;
+        }
     }
   else
     {
       if (checkRights (pFtpuserData->m_suserName, pFtpuserData->m_sPass,
-                      sLocalFileName, MYSERVER_PERMISSION_WRITE) == 0)
-       {
-         ftpReply (550);
-         return;
-       }
+                       sLocalFileName, MYSERVER_PERMISSION_WRITE) == 0)
+        {
+          ftpReply (550);
+          return;
+        }
     }
+
   if (FilesUtility::deleteFile (sLocalPath) != 0)
     ftpReply (450);
   ftpReply (250);
@@ -2434,8 +2417,7 @@ void Ftp::rnfr (const std::string & sPath)
   FilesUtility::splitPath (sLocalPath, sLocalDir, sLocalFileName);
 
   const char *secName = td.st.getHashedData ("security.filename",
-                                            MYSERVER_VHOST_CONF |
-                                            MYSERVER_SERVER_CONF,
+                                            MYSERVER_VHOST_CONF | 
MYSERVER_SERVER_CONF,
                                             ".security.xml");
 
   /* The security file doesn't exist in any case.  */

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

Summary of changes:
 myserver/include/base/socket/socket.h              |    2 +-
 myserver/src/base/socket/socket.cpp                |    2 +-
 myserver/src/base/unix_socket/unix_socket.cpp      |    2 +-
 .../connections_scheduler.cpp                      |   24 +-
 myserver/src/http_handler/http_file/http_file.cpp  |  895 +++++++++-----------
 myserver/src/protocol/ftp/ftp.cpp                  |  897 ++++++++++----------
 myserver/tests/test_socket.cpp                     |    2 +-
 myserver/tests/test_ssl_socket.cpp                 |    2 +-
 8 files changed, 869 insertions(+), 957 deletions(-)


hooks/post-receive
-- 
GNU MyServer




reply via email to

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