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. 0_9_2-142-


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. 0_9_2-142-gf279655
Date: Fri, 16 Apr 2010 10:16:28 +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  f279655f07393b44d1cc8860ea6dbf4ddce4f3fe (commit)
       via  361b27bfac39972528beffa75956112d82a69afc (commit)
      from  31db1be72710a7980801f6f364d17efadffe6345 (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 f279655f07393b44d1cc8860ea6dbf4ddce4f3fe
Author: Giuseppe Scrivano <address@hidden>
Date:   Fri Apr 16 12:12:28 2010 +0200

    HttpFile logs errors

diff --git a/myserver/src/http_handler/http_file/http_file.cpp 
b/myserver/src/http_handler/http_file/http_file.cpp
index c23a060..5dc253a 100644
--- a/myserver/src/http_handler/http_file/http_file.cpp
+++ b/myserver/src/http_handler/http_file/http_file.cpp
@@ -63,7 +63,7 @@ int HttpFile::putFile (HttpThreadContext* td, string& 
filename)
         catch (exception & e)
           {
             td->connection->host->warningsLogWrite
-              (_("HttpFile: error accessing file %s : %e"),
+              (_E ("HttpFile: error accessing file %s"),
                td->filenamePath.c_str (), &e);
             return td->http->raiseHTTPError (500);
           }
@@ -114,7 +114,7 @@ int HttpFile::putFile (HttpThreadContext* td, string& 
filename)
         catch (exception & e)
           {
             td->connection->host->warningsLogWrite
-              (_("HttpFile: error accessing file %s : %e"),
+              (_E ("HttpFile: error accessing file %s"),
                td->filenamePath.c_str (), &e);
             return td->http->raiseHTTPError (500);
           }
@@ -152,8 +152,10 @@ int HttpFile::putFile (HttpThreadContext* td, string& 
filename)
         return HttpDataHandler::RET_OK;
       }
   }
-  catch (...)
+  catch (exception & e)
     {
+      td->connection->host->warningsLogWrite (_E ("HttpFile: internal error"),
+                                              &e);
       return td->http->raiseHTTPError (500);
     };
 }
@@ -168,7 +170,7 @@ int HttpFile::deleteFile (HttpThreadContext* td,
   string file;
   try
     {
-      if (!(td->permissions & MYSERVER_PERMISSION_DELETE))
+      if (! (td->permissions & MYSERVER_PERMISSION_DELETE))
         return td->http->sendAuth ();
 
       if (FilesUtility::nodeExists (td->filenamePath))
@@ -179,8 +181,11 @@ int HttpFile::deleteFile (HttpThreadContext* td,
       else
         return td->http->raiseHTTPError (204);
     }
-  catch (...)
+  catch (exception & e)
     {
+      td->connection->host->warningsLogWrite
+        (_E ("HttpFile: cannot delete file %s"),
+         td->filenamePath.c_str (), &e);
       return td->http->raiseHTTPError (500);
     };
 }
@@ -268,18 +273,17 @@ int HttpFile::send (HttpThreadContext* td, const char 
*filenamePath,
       try
         {
           file = Server::getInstance ()->getCachedFiles ()->open 
(filenamePath);
+          if (! file)
+            return td->http->raiseHTTPError (500);
         }
       catch (exception & e)
         {
           td->connection->host->warningsLogWrite
-            (_("HttpFile: error accessing file %s : %e"),
+            (_E ("HttpFile: error accessing file %s"),
              td->filenamePath.c_str (), &e);
           return td->http->raiseHTTPError (500);
         }
 
-      if (!file)
-        return td->http->raiseHTTPError (500);
-
     /*
      * Check how many bytes are ready to be send.
      */
@@ -289,7 +293,7 @@ int HttpFile::send (HttpThreadContext* td, const char 
*filenamePath,
     generateEtag (etag, lastMT, filesize);
 
     HttpRequestHeader::Entry *etagHeader = td->request.other.get ("etag");
-    if (etagHeader &&  !etagHeader->value->compare (etag))
+    if (etagHeader && !etagHeader->value->compare (etag))
       return td->http->sendHTTPNonModified ();
     else
       {
@@ -325,13 +329,7 @@ int HttpFile::send (HttpThreadContext* td, const char 
*filenamePath,
     /*
      * 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);
-      }
+    file->seek (firstByte);
 
     keepalive = td->request.isKeepAlive ();
 
@@ -363,18 +361,12 @@ int HttpFile::send (HttpThreadContext* td, const char 
*filenamePath,
     if (td->mime)
       {
         HttpRequestHeader::Entry* e = td->request.other.get 
("accept-encoding");
-        if (td->mime &&
-            Server::getInstance ()->getFiltersFactory ()->chain (&chain,
-                                                                 
td->mime->filters,
-                                                                 &memStream,
-                                                                 &nbw, 0,
-                                                                 e ? e->value 
: NULL))
-          {
-            file->close ();
-            delete file;
-            chain.clearAllFilters ();
-            return HttpDataHandler::RET_FAILURE;
-          }
+        if (td->mime)
+          Server::getInstance ()->getFiltersFactory ()->chain (&chain,
+                                                               
td->mime->filters,
+                                                               &memStream,
+                                                               &nbw, 0,
+                                                               e ? e->value : 
NULL);
         memStream.refresh ();
         dataSent += nbw;
       }
@@ -384,7 +376,7 @@ int HttpFile::send (HttpThreadContext* td, const char 
*filenamePath,
     if (!useModifiers)
       {
         ostringstream buffer;
-        buffer << (u_int)bytesToSend;
+        buffer << (u_int) bytesToSend;
         td->response.contentLength.assign (buffer.str ());
       }
 
@@ -435,14 +427,8 @@ int HttpFile::send (HttpThreadContext* td, const char 
*filenamePath,
           delete e;
       }
 
-    if (HttpHeaders::sendHeader (td->response, *td->connection->socket,
-                                 *td->buffer, td))
-      {
-        file->close ();
-        delete file;
-        chain.clearAllFilters ();
-        return HttpDataHandler::RET_FAILURE;
-      }
+    HttpHeaders::sendHeader (td->response, *td->connection->socket,
+                             *td->buffer, td);
 
     /*
       If is requested only the header exit from the function;
@@ -464,8 +450,8 @@ int HttpFile::send (HttpThreadContext* td, const char 
*filenamePath,
         && !(td->http->getProtocolOptions () & Protocol::SSL))
       {
         u_long nbw = 0;
-        int ret = file->fastCopyToSocket (td->connection->socket, firstByte,
-                                          td->buffer, &nbw);
+        file->fastCopyToSocket (td->connection->socket, firstByte,
+                                td->buffer, &nbw);
 
         file->close ();
         delete file;
@@ -474,10 +460,7 @@ int HttpFile::send (HttpThreadContext* td, const char 
*filenamePath,
 
         td->sentData += nbw;
 
-        if (ret)
-          return HttpDataHandler::RET_FAILURE;
-        else
-          return HttpDataHandler::RET_OK;
+        return HttpDataHandler::RET_OK;
       }
 
     if (td->appendOutputs)
@@ -492,29 +475,16 @@ int HttpFile::send (HttpThreadContext* td, const char 
*filenamePath,
     */
     if (memStream.availableToRead ())
       {
-        if (memStream.read (td->buffer->getBuffer (),
-                            td->buffer->getRealLength (), &nbr))
-          {
-            file->close ();
-            delete file;
-            chain.clearAllFilters ();
-            return HttpDataHandler::RET_FAILURE;
-          }
+        memStream.read (td->buffer->getBuffer (),
+                        td->buffer->getRealLength (), &nbr);
 
         memStream.refresh ();
-        if (nbr
-            && HttpDataHandler::appendDataToHTTPChannel (td,
-                                                      td->buffer->getBuffer (),
-                                                     nbr, &(td->outputData),
-                                                     &chain, td->appendOutputs,
-                                                         useChunks))
-          {
-            file->close ();
-            delete file;
-            chain.clearAllFilters ();
-            dataSent += nbw;
-            return HttpDataHandler::RET_FAILURE;
-          }
+        if (nbr)
+          HttpDataHandler::appendDataToHTTPChannel (td,
+                                                    td->buffer->getBuffer (),
+                                                    nbr, &(td->outputData),
+                                                    &chain, td->appendOutputs,
+                                                    useChunks);
       } /* memStream.availableToRead ().  */
 
     /* Flush the rest of the file.  */
@@ -527,11 +497,10 @@ int HttpFile::send (HttpThreadContext* td, const char 
*filenamePath,
         if (bytesToSend)
           {
             /* Read from the file the bytes to send.  */
-            if ((ret = file->read (td->buffer->getBuffer (),
+            file->read (td->buffer->getBuffer (),
                                   std::min (static_cast<u_long> (bytesToSend),
                       static_cast<u_long> (td->buffer->getRealLength () / 2)),
-                                  &nbr)))
-              break;
+                        &nbr);
 
             if (nbr == 0)
               {
@@ -541,11 +510,9 @@ int HttpFile::send (HttpThreadContext* td, const char 
*filenamePath,
 
             bytesToSend -= nbr;
 
-            if ((ret = appendDataToHTTPChannel (td, td->buffer->getBuffer (),
+            appendDataToHTTPChannel (td, td->buffer->getBuffer (),
                            nbr, &(td->outputData), &chain, td->appendOutputs,
-                        useChunks, td->buffer->getRealLength (), &memStream)))
-              break;
-
+                               useChunks, td->buffer->getRealLength (), 
&memStream);
             dataSent += nbr;
           }
         else /* if (bytesToSend) */
@@ -553,7 +520,7 @@ int HttpFile::send (HttpThreadContext* td, const char 
*filenamePath,
             /* If we don't use chunks we can flush directly.  */
             if (!useChunks)
               {
-                ret = chain.flush (&nbw);
+                chain.flush (&nbw);
                 break;
               }
             else
@@ -567,22 +534,21 @@ int HttpFile::send (HttpThreadContext* td, const char 
*filenamePath,
                 Stream* tmpStream = chain.getStream ();
                 chain.setStream (&memStream);
                 memStream.refresh ();
-                if ((ret = chain.flush (&nbw)))
-                  break;
+                chain.flush (&nbw);
 
                 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);
+                memStream.read (td->buffer->getBuffer (),
+                                td->buffer->getRealLength (), &nbr);
+
+                HttpDataHandler::appendDataToHTTPChannel (td,
+                                                       td->buffer->getBuffer 
(),
+                                                       nbr, &(td->outputData),
+                                                       &chain, 
td->appendOutputs,
+                                                          useChunks);
+
+                HttpDataHandler::appendDataToHTTPChannel (td, 0, 0,
+                                                     &(td->outputData), &chain,
+                                                 td->appendOutputs, useChunks);
                 break;
               }
           }
@@ -592,15 +558,16 @@ int HttpFile::send (HttpThreadContext* td, const char 
*filenamePath,
     file->close ();
     delete file;
   }
-  catch (...)
+  catch (exception & e)
     {
       if (file)
         {
           file->close ();
           delete file;
         }
-      td->connection->host->warningsLogWrite (_("HttpFile: internal error"));
       chain.clearAllFilters ();
+      td->connection->host->warningsLogWrite (_E ("HttpFile: internal error"),
+                                              &e);
       return td->http->raiseHTTPError (500);
     }
 
@@ -608,10 +575,7 @@ int HttpFile::send (HttpThreadContext* td, const char 
*filenamePath,
   td->sentData += dataSent;
   chain.clearAllFilters ();
 
-  if (ret)
-    return HttpDataHandler::RET_FAILURE;
-  else
-    return HttpDataHandler::RET_OK;
+  return HttpDataHandler::RET_OK;
 }
 
 /*!



commit 361b27bfac39972528beffa75956112d82a69afc
Author: Giuseppe Scrivano <address@hidden>
Date:   Fri Apr 16 12:10:48 2010 +0200

    Define a macro _E which helps to format error messages with an exception
    
    It automatically appends the exception formatter to the message string

diff --git a/myserver/myserver.h b/myserver/myserver.h
index 013c606..566b916 100644
--- a/myserver/myserver.h
+++ b/myserver/myserver.h
@@ -60,3 +60,9 @@ typedef void* HANDLE;
 #else
 # define _(X) X
 #endif
+
+/*
+ * Automatically append an exception to the formatting string.
+ * Don't forget to pass as last parameter a pointer to an exception.
+ */
+#define _E(X) _(X " : %e")

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

Summary of changes:
 myserver/myserver.h                               |    6 +
 myserver/src/http_handler/http_file/http_file.cpp |  150 ++++++++-------------
 2 files changed, 63 insertions(+), 93 deletions(-)


hooks/post-receive
-- 
GNU MyServer




reply via email to

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