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. 9b1f8b776b


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. 9b1f8b776b7cc4ceb446bf37c61d7434bd4f6b0c
Date: Wed, 28 Oct 2009 14:45:48 +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  9b1f8b776b7cc4ceb446bf37c61d7434bd4f6b0c (commit)
       via  2636ed562f4cc226b4d0a452f07f2ac8a68b3483 (commit)
      from  2888db883335358e639aaebe14c268e8a50a9c58 (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 9b1f8b776b7cc4ceb446bf37c61d7434bd4f6b0c
Author: Giuseppe Scrivano <address@hidden>
Date:   Wed Oct 28 12:14:18 2009 +0100

    Remove protocolData from filters.

diff --git a/myserver/include/filter/filter.h b/myserver/include/filter/filter.h
index 337239f..403738b 100644
--- a/myserver/include/filter/filter.h
+++ b/myserver/include/filter/filter.h
@@ -23,14 +23,10 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>.
 # include <include/protocol/protocol.h>
 
 /*!
- *Abstract class to handle virtual data filters.
+ * Abstract class to handle virtual data filters.
  */
 class Filter : public Stream
 {
-protected:
-  Protocol *protocol;
-  Stream *parent;
-  void* protocolData;
 public:
   Protocol* getProtocol ()
   {
@@ -40,14 +36,6 @@ public:
   {
     protocol = pr;
   }
-  void* getProtocolData ()
-  {
-    return protocolData;
-  }
-  void setProtocolData (void* prd)
-  {
-    protocolData = prd;
-  }
   virtual int getHeader (char* buffer, u_long len, u_long* nbw);
   virtual int getFooter (char* buffer, u_long len, u_long* nbw);
   virtual int read (char* buffer, u_long len, u_long*);
@@ -59,8 +47,11 @@ public:
   Stream* getParent ();
   Filter ();
   /*! Avoid direct instances of this class. */
-  virtual ~Filter ()=0;
-};
+  virtual ~Filter () = 0;
 
+protected:
+  Protocol *protocol;
+  Stream *parent;
+};
 
 #endif
diff --git a/myserver/include/filter/filters_factory.h 
b/myserver/include/filter/filters_factory.h
index ebda869..6f55b63 100644
--- a/myserver/include/filter/filters_factory.h
+++ b/myserver/include/filter/filters_factory.h
@@ -36,19 +36,21 @@ typedef Filter* (*FILTERCREATE)(const char* name);
 class FiltersFactory
 {
 public:
-       class FiltersSource
-       {
-       public:
-               virtual Filter* createFilter (const char* name) = 0;
-               virtual ~FiltersSource (){}
-       };
+  class FiltersSource
+  {
+  public:
+    virtual Filter* createFilter (const char* name) = 0;
+    virtual ~FiltersSource (){}
+  };
+
   int insert (const char*, FILTERCREATE ptr);
   int insert (const char*, FiltersSource* ptr);
   Filter *getFilter (const char*);
   FiltersChain* chain (list<string> &l, Stream* out, u_long *nbw,
-                                                                               
        int onlyNotModifiers = 0);
+                      int onlyNotModifiers = 0);
   int chain (FiltersChain*, list<string> &l, Stream* out, u_long *nbw,
-             int onlyNotModifiers = 0);
+             int onlyNotModifiers = 0, string *accepted = NULL);
+
   FiltersFactory ();
   ~FiltersFactory ();
   void free ();
diff --git a/myserver/include/filter/gzip/gzip.h 
b/myserver/include/filter/gzip/gzip.h
index f153af6..0995039 100644
--- a/myserver/include/filter/gzip/gzip.h
+++ b/myserver/include/filter/gzip/gzip.h
@@ -49,8 +49,8 @@ public:
 
   static u_long headerSize ();
   static u_long footerSize ();
-  u_long updateCRC (char* buffer,int size);
-  u_long getFooter (char *str,int size);
+  u_long updateCRC (char* buffer, int size);
+  u_long getFooter (char *str, int size);
   u_long initialize ();
   u_long compress (const char* in, u_long sizeIn,
                    char *out, u_long sizeOut);
diff --git a/myserver/src/filter/filter.cpp b/myserver/src/filter/filter.cpp
index 59bfffa..5be60a7 100644
--- a/myserver/src/filter/filter.cpp
+++ b/myserver/src/filter/filter.cpp
@@ -25,22 +25,22 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>.
 using namespace std;
 
 /*!
- *Read [len] characters using the filter. Returns -1 on errors.
- *\param buffer The buffer where receive read data.
- *\param len The buffer length in bytes.
- *\param nbr A pointer to receive the number of read bytes.
+ * Read [len] characters using the filter. Returns -1 on errors.
+ * \param buffer The buffer where receive read data.
+ * \param len The buffer length in bytes.
+ * \param nbr A pointer to receive the number of read bytes.
  */
 int Filter::read (char* buffer, u_long len, u_long *nbr)
 {
-  *nbr=0;
+  *nbr = 0;
   return 0;
 }
 
 /*!
- *Write [len] characters to the stream. Returns -1 on errors.
- *\param buffer The buffer with the data to write.
- *\param len Number of bytes to use.
- *\param nbw A pointer to receive the number of written bytes.
+ * Write [len] characters to the stream. Returns -1 on errors.
+ * \param buffer The buffer with the data to write.
+ * \param len Number of bytes to use.
+ * \param nbw A pointer to receive the number of written bytes.
  */
 int Filter::write (const char* buffer, u_long len, u_long* nbw)
 {
@@ -49,10 +49,10 @@ int Filter::write (const char* buffer, u_long len, u_long* 
nbw)
 }
 
 /*!
- *Get an header for the filter. Returns -1 on errors.
- *\param buffer The buffer where receive read data.
- *\param len The buffer length in bytes.
- *\param nbr A pointer to receive the number of read bytes.
+ * Get an header for the filter. Returns -1 on errors.
+ * \param buffer The buffer where receive read data.
+ * \param len The buffer length in bytes.
+ * \param nbr A pointer to receive the number of read bytes.
  */
 int Filter::getHeader (char* buffer, u_long len, u_long* nbr)
 {
@@ -61,10 +61,10 @@ int Filter::getHeader (char* buffer, u_long len, u_long* 
nbr)
 }
 
 /*!
- *Get a footer for the filter. Returns -1 on errors.
- *\param buffer The buffer where receive read data.
- *\param len The buffer length in bytes.
- *\param nbr A pointer to receive the number of read bytes.
+ * Get a footer for the filter. Returns -1 on errors.
+ * \param buffer The buffer where receive read data.
+ * \param len The buffer length in bytes.
+ * \param nbr A pointer to receive the number of read bytes.
  */
 int Filter::getFooter (char* buffer, u_long len, u_long* nbr)
 {
@@ -73,18 +73,17 @@ int Filter::getFooter (char* buffer, u_long len, u_long* 
nbr)
 }
 
 /*!
- *Default constructor.
+ * Default constructor.
  */
 Filter::Filter ()
 {
   protocol = 0;
-  protocolData = 0;
   parent = 0;
 }
 
 
 /*!
- *Default destructor.
+ * Default destructor.
  */
 Filter::~Filter ()
 {
@@ -92,8 +91,8 @@ Filter::~Filter ()
 }
 
 /*!
- *Set the stream where apply the filter.
- *\param parentStream The stream to use as parent.
+ * Set the stream where apply the filter.
+ * \param parentStream The stream to use as parent.
  */
 void Filter::setParent (Stream* parentStream)
 {
@@ -101,8 +100,8 @@ void Filter::setParent (Stream* parentStream)
 }
 
 /*!
- *Flush everything to the stream. Returns -1 on errors.
- *\param nbw A pointer to receive the number of read bytes.
+ * Flush everything to the stream. Returns -1 on errors.
+ * \param nbw A pointer to receive the number of read bytes.
  */
 int Filter::flush (u_long *nbw)
 {
@@ -111,7 +110,7 @@ int Filter::flush (u_long *nbw)
 }
 
 /*!
- *Get the stream used by the filter.
+ * Get the stream used by the filter.
  */
 Stream* Filter::getParent ()
 {
@@ -119,7 +118,7 @@ Stream* Filter::getParent ()
 }
 
 /*!
- *Returns a nonzero value if the filter modify the input/output data.
+ * Returns a nonzero value if the filter modify the input/output data.
  */
 int Filter::modifyData ()
 {
@@ -127,17 +126,16 @@ int Filter::modifyData ()
 }
 
 /*!
- *Return a string with the filter name.
- *If an external buffer is provided write the name there too.
- *\param name The buffer where write the filter name.
- *\param len The buffer length.
+ * Return a string with the filter name.
+ * If an external buffer is provided write the name there too.
+ * \param name The buffer where write the filter name.
+ * \param len The buffer length.
  */
 const char* Filter::getName (char* name, u_long len)
 {
   /* No name by default.  */
   if (name)
-  {
     name[0] = '\0';
-  }
+
   return "\0";
 }
diff --git a/myserver/src/filter/filters_chain.cpp 
b/myserver/src/filter/filters_chain.cpp
index 9f73b77..da447eb 100644
--- a/myserver/src/filter/filters_chain.cpp
+++ b/myserver/src/filter/filters_chain.cpp
@@ -84,7 +84,6 @@ FiltersChain::FiltersChain ()
   stream = NULL;
   firstFilter = NULL;
   protocol = NULL;
-  protocolData = NULL;
 }
 
 /*!
@@ -161,7 +160,6 @@ int FiltersChain::addFilter (Filter* f, u_long *nbw, int 
sendData)
   firstFilter = f;
 
   f->setProtocol (protocol);
-  f->setProtocolData (protocolData);
 
   /*! Add the filters in the list in the same order they are used. */
   filters.push_front (f);
diff --git a/myserver/src/filter/filters_factory.cpp 
b/myserver/src/filter/filters_factory.cpp
index c8c11dd..2eacac2 100644
--- a/myserver/src/filter/filters_factory.cpp
+++ b/myserver/src/filter/filters_factory.cpp
@@ -27,7 +27,7 @@ using namespace std;
 
 
 /*!
- *Initialize the object.
+ * Initialize the object.
  */
 FiltersFactory::FiltersFactory ()
 {
@@ -35,7 +35,7 @@ FiltersFactory::FiltersFactory ()
 }
 
 /*!
- *Destroy the object.
+ * Destroy the object.
  */
 FiltersFactory::~FiltersFactory ()
 {
@@ -43,8 +43,8 @@ FiltersFactory::~FiltersFactory ()
 }
 
 /*!
- *Insert a filter by name and factory object. Returns 0 if the entry
- *was added correctly.
+ * Insert a filter by name and factory object. Returns 0 if the entry
+ * was added correctly.
  */
 int FiltersFactory::insert (const char* name, FiltersSource* ptr)
 {
@@ -54,8 +54,8 @@ int FiltersFactory::insert (const char* name, FiltersSource* 
ptr)
 }
 
 /*!
- *Insert a filter by name and factory routine. Returns 0 if the entry
- *was added correctly.
+ * Insert a filter by name and factory routine. Returns 0 if the entry
+ * was added correctly.
  */
 int FiltersFactory::insert (const char* name, FILTERCREATE fnc)
 {
@@ -65,20 +65,20 @@ int FiltersFactory::insert (const char* name, FILTERCREATE 
fnc)
 }
 
 /*!
- *Get a new filter by its name.
- *The object have to be freed after its use to avoid memory leaks.
- *Returns the new created object on success.
- *Returns 0 on errors.
+ * Get a new filter by its name.
+ * The object have to be freed after its use to avoid memory leaks.
+ * Returns the new created object on success.
+ * Returns 0 on errors.
  */
 Filter *FiltersFactory::getFilter (const char* name)
 {
   FILTERCREATE staticFactory = staticFilters.get (name);
   FiltersSource* dynamicFactory;
-  /*! If the filter exists create a new object and return it. */
+
+  /* If the filter exists create a new object and return it. */
   if (staticFactory)
     return staticFactory (name);
 
-
   dynamicFactory = dynamicFilters.get (name);
 
   if (dynamicFactory)
@@ -88,11 +88,11 @@ Filter *FiltersFactory::getFilter (const char* name)
 }
 
 /*!
- *Create a FiltersChain starting from a list of strings.
- *On success returns the new object.
- *If specified [onlyNotModifiers] the method wil check that all the filters
- *will not modify the data.
- *On errors returns 0.
+ * Create a FiltersChain starting from a list of strings.
+ * On success returns the new object.
+ * If specified [onlyNotModifiers] the method wil check that all the filters
+ * will not modify the data.
+ * On errors returns 0.
  */
 FiltersChain* FiltersFactory::chain (list<string> &l, Stream* out, u_long *nbw,
                                     int onlyNotModifiers)
@@ -100,6 +100,7 @@ FiltersChain* FiltersFactory::chain (list<string> &l, 
Stream* out, u_long *nbw,
   FiltersChain *ret = new FiltersChain ();
   if (!ret)
     return 0;
+
   if (chain (ret, l, out, nbw, onlyNotModifiers))
   {
     ret->clearAllFilters ();
@@ -110,35 +111,50 @@ FiltersChain* FiltersFactory::chain (list<string> &l, 
Stream* out, u_long *nbw,
 }
 
 /*!
- *Add new filters to an existent chain.
- *If specified [onlyNotModifiers] the method wil check that all the filters
- *will not modify the data.
- *On errors returns nonzero.
+ * Add new filters to an existent chain.
+ * \param c Output object.  It will receive the chain.
+ * \param l List of filters to build.
+ * \param out Output stream.
+ * \param nbw Number of written bytes, some filters may need to send a header.
+ * \param onlyNotModifiers if non-zero the method wil check that all the 
filters
+ * will not modify the data.
+ * \param accepted If specified, include only filters present in this string.
+ * On errors returns nonzero.
  */
 int FiltersFactory::chain (FiltersChain* c, list<string> &l, Stream* out,
-                          u_long *nbw, int onlyNotModifiers)
+                          u_long *nbw, int onlyNotModifiers, string *accepted)
 {
 
-  list<string>::iterator  i =l.begin ();
-
+  list<string>::iterator  i = l.begin ();
   if (!c)
     return 1;
 
   c->setStream (out);
-  *nbw=0;
-
+  *nbw = 0;
   for ( ; i != l.end (); i++)
-  {
-    u_long tmp;
-    Filter *n = getFilter ((*i).c_str ());
-    if ( !n || ( onlyNotModifiers && n->modifyData () )  )
     {
-      c->clearAllFilters ();
-      return 1;
+      u_long tmp;
+
+      if (accepted && accepted->find (*i) == string::npos)
+       continue;
+
+      Filter *n = getFilter ((*i).c_str ());
+      if (!n)
+       {
+         c->clearAllFilters ();
+         return 1;
+       }
+
+      if (onlyNotModifiers && n->modifyData ())
+       {
+         delete n;
+         c->clearAllFilters ();
+         return 1;
+       }
+
+      c->addFilter (n, &tmp);
+      *nbw += tmp;
     }
-    c->addFilter (n, &tmp);
-    *nbw += tmp;
-  }
 
   return 0;
 }
diff --git a/myserver/src/filter/gzip/gzip.cpp 
b/myserver/src/filter/gzip/gzip.cpp
index 42befcd..2ec3a94 100644
--- a/myserver/src/filter/gzip/gzip.cpp
+++ b/myserver/src/filter/gzip/gzip.cpp
@@ -17,7 +17,6 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>.
 
 #include <include/filter/gzip/gzip.h>
 #include <include/base/string/securestr.h>
-#include <include/protocol/http/http.h>
 
 extern "C"
 {
@@ -46,18 +45,6 @@ u_long Gzip::initialize ()
 {
 #ifdef HAVE_ZLIB
   long level = Z_DEFAULT_COMPRESSION;
-
-  if (protocol && protocolData)
-    {
-      if (!strstr (protocol->registerName (0,0), "HTTP"))
-        {
-          HttpRequestHeader::Entry* e = 
((HttpThreadContext*)protocolData)->request.other.get ("Accept-Encoding");
-          if (e)
-            active &= (e->value->find ("gzip") != string::npos);
-          else
-            active = false;
-        }
-    }
   data.initialized = 1;
   data.data_size = 0;
   data.crc = crc32(0L, Z_NULL, 0);
diff --git a/myserver/src/http_handler/http_file/http_file.cpp 
b/myserver/src/http_handler/http_file/http_file.cpp
index 42f8226..4df8458 100644
--- a/myserver/src/http_handler/http_file/http_file.cpp
+++ b/myserver/src/http_handler/http_file/http_file.cpp
@@ -347,11 +347,13 @@ int HttpFile::send (HttpThreadContext* td, const char 
*filenamePath,
     chain.setStream (&memStream);
     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))
+                                                            td->mime->filters,
+                                                            &memStream,
+                                                                 &nbw, 0,
+                                                     e ? e->value : NULL))
           {
             file->close ();
             delete file;



commit 2636ed562f4cc226b4d0a452f07f2ac8a68b3483
Author: Giuseppe Scrivano <address@hidden>
Date:   Wed Oct 28 11:21:28 2009 +0100

    Now gzip compression is not handled as a special case for static files.

diff --git a/myserver/src/http_handler/http_file/http_file.cpp 
b/myserver/src/http_handler/http_file/http_file.cpp
index f92aff3..42f8226 100644
--- a/myserver/src/http_handler/http_file/http_file.cpp
+++ b/myserver/src/http_handler/http_file/http_file.cpp
@@ -19,7 +19,6 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>.
 #include <include/protocol/http/http.h>
 #include <include/protocol/http/http_headers.h>
 #include <include/http_handler/http_file/http_file.h>
-#include <include/filter/gzip/gzip.h>
 #include <include/server/server.h>
 #include <include/filter/filters_chain.h>
 #include <include/filter/memory_stream.h>
@@ -214,11 +213,6 @@ int HttpFile::send (HttpThreadContext* td, const char 
*filenamePath,
    * Open the file and save its handle.
    */
   int ret;
-
-  /*
-   * Will we use GZIP compression to send data?
-   */
-  bool useGzip = false;
   u_long filesize = 0;
   File *file = NULL;
   u_long bytesToSend;
@@ -322,44 +316,8 @@ int HttpFile::send (HttpThreadContext* td, const char 
*filenamePath,
         return td->http->raiseHTTPError (500);
       }
 
-    /*
-     * Use GZIP compression to send files bigger than GZIP threshold.
-     */
-    const char *val = td->securityToken.getData ("gzip.threshold",
-                                                 MYSERVER_SECURITY_CONF
-                                                 | MYSERVER_VHOST_CONF
-                                                 | MYSERVER_MIME_CONF
-                                                 | MYSERVER_SERVER_CONF, "0");
-
-    useGzip = false;
-    if (val)
-      {
-        u_long gzipThreshold = atoi (val);
-        if (bytesToSend >= gzipThreshold)
-          useGzip = true;
-      }
-
     keepalive = td->request.isKeepAlive ();
 
-#ifdef HAVE_ZLIB
-    /*
-     * Be sure that the client accept GZIP compressed data.
-     */
-    if (useGzip)
-      {
-        HttpRequestHeader::Entry* e = td->request.other.get 
("Accept-encoding");
-        if (e)
-          useGzip &= (e->value->find ("gzip") != string::npos);
-        else
-          useGzip = false;
-      }
-#else
-    /* If compiled without GZIP support force the server to don't use it.  */
-    useGzip = false;
-#endif
-    if (td->appendOutputs)
-      useGzip = false;
-
     td->buffer->setLength (0);
 
     /* If a Range was requested send 206 and not 200 for success.  */
@@ -383,7 +341,6 @@ int HttpFile::send (HttpThreadContext* td, const char 
*filenamePath,
           }
 
         useChunks = true;
-        useGzip = false;
       }
     chain.setProtocol (td->http);
     chain.setProtocolData (td);
@@ -405,29 +362,6 @@ int HttpFile::send (HttpThreadContext* td, const char 
*filenamePath,
         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))
-          {
-            delete gzipFilter;
-            file->close ();
-            delete file;
-            chain.clearAllFilters ();
-            return 0;
-          }
-        dataSent += nbw;
-      }
-
     useModifiers = chain.hasModifiersFilters ();
 
     if (!useModifiers)
@@ -549,8 +483,7 @@ int HttpFile::send (HttpThreadContext* td, const char 
*filenamePath,
     if (memStream.availableToRead ())
       {
         if (memStream.read (td->buffer->getBuffer (),
-                              td->buffer->getRealLength (),
-                            &nbr))
+                           td->buffer->getRealLength (), &nbr))
           {
             file->close ();
             delete file;
@@ -559,22 +492,18 @@ int HttpFile::send (HttpThreadContext* td, const char 
*filenamePath,
           }
 
         memStream.refresh ();
-
-        if (nbr)
+       if (nbr && HttpDataHandler::appendDataToHTTPChannel (td,
+                                       td->buffer->getBuffer (),
+                                       nbr, &(td->outputData),
+                                       &chain, td->appendOutputs,
+                                       useChunks))
           {
-            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.  */
+            file->close ();
+            delete file;
+            chain.clearAllFilters ();
+            return 1;
+            dataSent += nbw;
+          }
       } /* memStream.availableToRead ().  */
 
     /* Flush the rest of the file.  */
@@ -663,7 +592,6 @@ int HttpFile::send (HttpThreadContext* td, const char 
*filenamePath,
 
   /* For logging activity.  */
   td->sentData += dataSent;
-
   chain.clearAllFilters ();
   return !ret;
 }

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

Summary of changes:
 myserver/include/filter/filter.h                  |   21 +---
 myserver/include/filter/filters_factory.h         |   18 ++--
 myserver/include/filter/gzip/gzip.h               |    4 +-
 myserver/src/filter/filter.cpp                    |   62 ++++++-------
 myserver/src/filter/filters_chain.cpp             |    2 -
 myserver/src/filter/filters_factory.cpp           |   86 ++++++++++-------
 myserver/src/filter/gzip/gzip.cpp                 |   13 ---
 myserver/src/http_handler/http_file/http_file.cpp |  104 ++++-----------------
 8 files changed, 116 insertions(+), 194 deletions(-)


hooks/post-receive
-- 
GNU MyServer




reply via email to

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