myserver-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myserver-commit] [2924] Reduced `Http::sendHTTPResource' function compl


From: Giuseppe Scrivano
Subject: [myserver-commit] [2924] Reduced `Http::sendHTTPResource' function complexity.
Date: Wed, 29 Oct 2008 22:28:24 +0000

Revision: 2924
          http://svn.sv.gnu.org/viewvc/?view=rev&root=myserver&revision=2924
Author:   gscrivano
Date:     2008-10-29 22:28:23 +0000 (Wed, 29 Oct 2008)

Log Message:
-----------
Reduced `Http::sendHTTPResource' function complexity.

Modified Paths:
--------------
    trunk/myserver/include/protocol/http/dyn_http_manager_list.h
    trunk/myserver/include/protocol/http/http.h
    trunk/myserver/src/protocol/http/dyn_http_manager_list.cpp
    trunk/myserver/src/protocol/http/http.cpp

Modified: trunk/myserver/include/protocol/http/dyn_http_manager_list.h
===================================================================
--- trunk/myserver/include/protocol/http/dyn_http_manager_list.h        
2008-10-29 21:27:40 UTC (rev 2923)
+++ trunk/myserver/include/protocol/http/dyn_http_manager_list.h        
2008-10-29 22:28:23 UTC (rev 2924)
@@ -1,7 +1,7 @@
 /* -*- mode: c++ -*- */
 /*
 MyServer
-Copyright (C) 2005, 2007 Free Software Foundation, Inc.
+Copyright (C) 2005, 2007, 2008 Free Software Foundation, Inc.
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 3 of the License, or
@@ -29,28 +29,34 @@
 #include <string>
 using namespace std;
 
-class DynamicHttpManager;
+class HttpDataHandler;
 
 class DynHttpManagerList
 {
 public:
-  DynamicHttpManager* getHttpManager(string& name);
+  HttpDataHandler *getHttpManager (string& name);
 
-  HashMap<string, DynamicHttpManager*>::Iterator begin(){return 
dynamicHttpManagers.begin();}
-  HashMap<string, DynamicHttpManager*>::Iterator end(){return 
dynamicHttpManagers.end();}
+  HttpDataHandler *getHttpManager (const char *name)
+  {
+       string strName (name);
+       return getHttpManager (strName);
+  }
 
-  void addHttpManager(string& name, DynamicHttpManager* httpManager);
+  HashMap<string, HttpDataHandler*>::Iterator begin (){return 
dynamicHttpManagers.begin ();}
+  HashMap<string, HttpDataHandler*>::Iterator end (){return 
dynamicHttpManagers.end ();}
 
-  void addHttpManager(char* name, DynamicHttpManager* httpManager)
+  void addHttpManager (string& name, HttpDataHandler* httpManager);
+
+  void addHttpManager (const char* name, HttpDataHandler* httpManager)
   {
-       string strName(name);
-       addHttpManager(strName, httpManager);
+       string strName (name);
+       addHttpManager (strName, httpManager);
   }
 
-  DynHttpManagerList();
-  ~DynHttpManagerList();
+  DynHttpManagerList ();
+  ~DynHttpManagerList ();
 private:
-       HashMap<string, DynamicHttpManager*> dynamicHttpManagers;
+       HashMap<string, HttpDataHandler*> dynamicHttpManagers;
 };
 
 #endif

Modified: trunk/myserver/include/protocol/http/http.h
===================================================================
--- trunk/myserver/include/protocol/http/http.h 2008-10-29 21:27:40 UTC (rev 
2923)
+++ trunk/myserver/include/protocol/http/http.h 2008-10-29 22:28:23 UTC (rev 
2924)
@@ -49,19 +49,32 @@
     return MulticastRegistry<string, void*, int>::getHandlers(msg);
   }
 
+  HttpStaticData ();
+  virtual ~HttpStaticData ();
+
   void clear()
   {
     clearMulticastRegistry();
   }
 
-  DynHttpCommandManager dynCmdManager;
-  DynHttpManagerList dynManagerList;
-
   string browseDirCSSpath;
   u_long gzipThreshold;
   vector<string> defaultFilename;
   int cgiTimeout;
   int allowVhostMime;
+
+  HttpDataHandler *mscgi;
+  HttpDataHandler *wincgi;
+  HttpDataHandler *isapi;
+  HttpDataHandler *cgi;
+  HttpDataHandler *scgi;
+  HttpDataHandler *fastcgi;
+  HttpDataHandler *httpFile;
+  HttpDataHandler *httpDir;
+
+
+  DynHttpCommandManager dynCmdManager;
+  DynHttpManagerList dynManagerList;
 };
 
 /*!
@@ -193,14 +206,6 @@
 
   int processDefaultFile (string& uri, int permissions, int onlyHeader);
 
-  HttpDataHandler* mscgi;
-  HttpDataHandler* wincgi;
-  HttpDataHandler* isapi;
-  HttpDataHandler* cgi;
-  HttpDataHandler* scgi;
-  HttpDataHandler* fastcgi;
-  HttpDataHandler* httpFile;
-  HttpDataHandler* httpDir;
   struct HttpThreadContext *td;
   void clean();
   void computeDigest(char*, char*);

Modified: trunk/myserver/src/protocol/http/dyn_http_manager_list.cpp
===================================================================
--- trunk/myserver/src/protocol/http/dyn_http_manager_list.cpp  2008-10-29 
21:27:40 UTC (rev 2923)
+++ trunk/myserver/src/protocol/http/dyn_http_manager_list.cpp  2008-10-29 
22:28:23 UTC (rev 2924)
@@ -26,7 +26,7 @@
 /*!
  *Initialize the object.
  */
-DynHttpManagerList::DynHttpManagerList() 
+DynHttpManagerList::DynHttpManagerList () 
 {
 
 }
@@ -34,27 +34,26 @@
 /*!
  *Destroy the object.
  */
-DynHttpManagerList::~DynHttpManagerList()
+DynHttpManagerList::~DynHttpManagerList ()
 {
 
 }
 
 /*!
- *Get the DynamicHttpManagers.
+ *Get the HttpDataHandlers.
  *\param name http manager name.
  */
-DynamicHttpManager* DynHttpManagerList::getHttpManager(string& name)
+HttpDataHandler* DynHttpManagerList::getHttpManager (string& name)
 {
-  return dynamicHttpManagers.get(name);
+  return dynamicHttpManagers.get (name);
 }
 
 /*!
- *Add the DynamicHttpManagers.
+ *Add the HttpDataHandlers.
  *\param name http manager name.
  *\param httpManager http manager to add.
  */
-void DynHttpManagerList::addHttpManager(string& name, DynamicHttpManager* 
httpManager)
+void DynHttpManagerList::addHttpManager (string& name, HttpDataHandler* 
httpManager)
 {
-  dynamicHttpManagers.put(name,httpManager);
+  dynamicHttpManagers.put (name, httpManager);
 }
-

Modified: trunk/myserver/src/protocol/http/http.cpp
===================================================================
--- trunk/myserver/src/protocol/http/http.cpp   2008-10-29 21:27:40 UTC (rev 
2923)
+++ trunk/myserver/src/protocol/http/http.cpp   2008-10-29 22:28:23 UTC (rev 
2924)
@@ -66,12 +66,37 @@
 /*!
  *Get a pointer to a structure shared among all the instances.
  */
-HttpStaticData* Http::getStaticData()
+HttpStaticData* Http::getStaticData ()
 {
   return &staticHttp;
 }
 
 
+HttpStaticData::HttpStaticData ()
+{
+  mscgi = new MsCgi();
+  wincgi = new WinCgi();
+  isapi = new Isapi();
+  cgi = new Cgi();
+  scgi = new Scgi();
+  fastcgi = new FastCgi();
+  httpFile = new HttpFile();
+  httpDir = new HttpDir();
+}
+
+HttpStaticData::~HttpStaticData ()
+{
+  delete mscgi;
+  delete wincgi;
+  delete isapi;
+  delete cgi;
+  delete scgi;
+  delete fastcgi;
+  delete httpFile;
+  delete httpDir;
+}
+
+
 /*!
  *Build a response for an OPTIONS request.
  */
@@ -776,7 +801,7 @@
   int ret;
   string directory;
   string file;
-  DynamicHttpManager *manager;
+  HttpDataHandler *manager;
 
   /*! By default allows only few actions. */
   permissions = MYSERVER_PERMISSION_READ | MYSERVER_PERMISSION_BROWSE ;
@@ -822,205 +847,37 @@
     }
 
 
-    if(td->mime && !td->mime->cmdName.compare ("CGI"))
+    if (td->mime && (manager = staticHttp.dynManagerList.getHttpManager 
(td->mime->cmdName)))
     {
-      int allowCgi = 1;
-      const char *dataH = td->connection->host->getHashedData("ALLOW_CGI");
-      if(dataH)
+      if (manager)
       {
-        if(!strcmpi(dataH, "YES"))
-          allowCgi = 1;
-        else
-          allowCgi = 0;
-      }
+        if (!(permissions & MYSERVER_PERMISSION_EXECUTE))
+            return sendAuth();
 
-      if(!allowCgi || !(permissions & MYSERVER_PERMISSION_EXECUTE))
-      {
-        return sendAuth();
+        return manager->send (td,
+                              td->connection,
+                              td->filenamePath.c_str(),
+                              cgiManager,
+                              td->mime->selfExecuted,
+                              onlyHeader);
       }
-      ret = cgi->send(td, td->connection, td->filenamePath.c_str(),
-                      cgiManager, td->mime->selfExecuted,  onlyHeader);
-      return ret;
     }
-    else if(td->mime && !td->mime->cmdName.compare ("ISAPI"))
-    {
-      int allowIsapi = 1;
-      const char *dataH = td->connection->host->getHashedData("ALLOW_ISAPI");
-      if(dataH)
-      {
-        if(!strcmpi(dataH, "YES"))
-          allowIsapi = 1;
-        else
-          allowIsapi = 0;
-      }
-      if(!allowIsapi || !(permissions & MYSERVER_PERMISSION_EXECUTE))
-      {
-        return sendAuth();
-      }
-      ret = isapi->send(td, td->connection, td->filenamePath.c_str(),
-                        cgiManager, td->mime->selfExecuted, onlyHeader);
-      return ret;
-    }
-    else if(td->mime && !td->mime->cmdName.compare ("MSGI"))
-    {
-      char* target;
-      int allowMscgi = 1;
-      const char *dataH = td->connection->host->getHashedData("ALLOW_MSCGI");
-      if(dataH)
-      {
-        if(!strcmpi(dataH, "YES"))
-          allowMscgi = 1;
-        else
-          allowMscgi = 0;
-      }
 
-      if(!allowMscgi || !(permissions & MYSERVER_PERMISSION_EXECUTE))
-      {
-        return sendAuth();
-      }
-      if(td->request.uriOptsPtr)
-        target = td->request.uriOptsPtr;
-      else
-        target = (char*)td->request.uriOpts.c_str();
 
-      ret = mscgi->send(td, td->connection, td->filenamePath.c_str(),
-                        target, td->mime->selfExecuted, onlyHeader);
-      return ret;
-    }
-    else if(td->mime && !td->mime->cmdName.compare ("WINCGI"))
-    {
-      int allowWincgi = 1;
-      const char *dataH = td->connection->host->getHashedData("ALLOW_WINCGI");
-      if(dataH)
-      {
-        if(!strcmpi(dataH, "YES"))
-          allowWincgi = 1;
-        else
-          allowWincgi = 0;
-      }
+    if (!(permissions & MYSERVER_PERMISSION_READ))
+      return sendAuth ();
 
-      if(!allowWincgi || !(permissions & MYSERVER_PERMISSION_EXECUTE))
-      {
-        return sendAuth();
-      }
+    manager = staticHttp.dynManagerList.getHttpManager ("FILE");
 
-      ret = wincgi->send(td, td->connection, 
-                         td->filenamePath.c_str(),
-                         cgiManager,
-                         td->mime->selfExecuted, onlyHeader);
-      return ret;
-    }
-    else if(td->mime && !td->mime->cmdName.compare ("FASTCGI"))
-    {
-      int allowFastcgi = 1;
-      const char *dataH = td->connection->host->getHashedData("ALLOW_FASTCGI");
-      if(dataH)
-      {
-        if(!strcmpi(dataH, "YES"))
-          allowFastcgi=1;
-        else
-          allowFastcgi=0;
-      }
-      if(!allowFastcgi || !(permissions & MYSERVER_PERMISSION_EXECUTE))
-      {
-        return sendAuth();
-      }
-      ret = fastcgi->send(td, td->connection, td->filenamePath.c_str(),
-                          cgiManager, td->mime->selfExecuted, onlyHeader);
-      return ret;
-    }
-    else if(td->mime && !td->mime->cmdName.compare ("SCGI"))
-    {
-      int allowScgi = 1;
-      const char *dataH = td->connection->host->getHashedData("ALLOW_SCGI");
-      if(dataH)
-      {
-        if(!strcmpi(dataH, "YES"))
-          allowScgi = 1;
-        else
-          allowScgi = 0;
-      }
-      if(!allowScgi || !(permissions & MYSERVER_PERMISSION_EXECUTE))
-      {
-        return sendAuth();
-      }
-      ret = scgi->send(td, td->connection, td->filenamePath.c_str(),
-                       cgiManager, td->mime->selfExecuted, onlyHeader);
-      return ret;
-    }
-    else if (td->mime && (manager = staticHttp.dynManagerList.getHttpManager 
(td->mime->cmdName)))
-    {
-      int allowScgi = 1;
-      const char *dataH = td->connection->host->getHashedData("ALLOW_SCGI");
-      if(dataH)
-      {
-        if(!strcmpi(dataH, "YES"))
-          allowScgi = 1;
-        else
-          allowScgi = 0;
-      }
-      if(!allowScgi || !(permissions & MYSERVER_PERMISSION_EXECUTE))
-      {
-        return sendAuth();
-      }
-      ret = scgi->send(td, td->connection, td->filenamePath.c_str(),
-                       cgiManager, 1, onlyHeader);
-      return ret;
-    }
-    else if (td->mime && (manager = 
staticHttp.dynManagerList.getHttpManager(td->mime->cmdName)))
-    {
-      int allowExternal = 1;
-      const char *dataH =
-        td->connection->host->getHashedData ("ALLOW_EXTERNAL_COMMANDS");
+    if (!manager)
+      return raiseHTTPError (500);
 
-      if(dataH)
-      {
-        if(!strcmpi(dataH, "YES"))
-          allowExternal = 1;
-        else
-          allowExternal = 0;
-      }
-
-      if(allowExternal && td->mime)
-      {
-        if(manager)
-          return manager->send(td,
-                               td->connection,
-                               td->filenamePath.c_str(),
-                               cgiManager,
-                               td->mime->selfExecuted,
-                               onlyHeader);
-        else
-          return raiseHTTPError(501);
-      }
-    }
-
-    int allowSend = 1;
-    const char *data = td->connection->host->getHashedData("ALLOW_SEND_FILE");
-    if(data)
-    {
-      if(!strcmpi(data, "YES"))
-        allowSend = 1;
-      else
-        allowSend = 0;
-    }
-
-    if(!allowSend)
-    {
-      return sendAuth();
-    }
-
-    if(!(permissions & MYSERVER_PERMISSION_READ))
-    {
-      return sendAuth();
-    }
-
-    ret = httpFile->send(td, td->connection, td->filenamePath.c_str(),
-                         0, onlyHeader);
+    return manager->send (td, td->connection, td->filenamePath.c_str(),
+                          0, onlyHeader);
   }
-  catch(...)
+  catch (...)
   {
-    return raiseHTTPError(500);
+    return raiseHTTPError (500);
   };
 
   return ret;
@@ -2007,11 +1864,6 @@
   int i;
   int ret;
 
-  if( !(permissions & MYSERVER_PERMISSION_BROWSE) )
-    {
-      return sendAuth();
-    }
-
   for(i = 0;; i++)
     {
       const char *defaultFileNamePath = getDefaultFilenamePath(i);
@@ -2055,8 +1907,17 @@
           return ret;
         }
     }
-  return httpDir->send(td, td->connection, td->filenamePath.c_str(), 0,
-                       onlyHeader);
+
+  if( !(permissions & MYSERVER_PERMISSION_BROWSE) )
+      return sendAuth();
+
+  HttpDataHandler *handler = staticHttp.dynManagerList.getHttpManager ("DIR");
+
+  if (!handler)
+    return raiseHTTPError (500);
+
+  return handler->send (td, td->connection, td->filenamePath.c_str(),
+                        0, onlyHeader);
 }
 
 /*!
@@ -2173,24 +2034,33 @@
   Server::getInstance()->setGlobalData("http-static", getStaticData());
 
   /* Load the HTTP errors.  */
-  HttpErrors::load();
+  HttpErrors::load ();
 
   /* Initialize ISAPI.  */
-  Isapi::load(configurationFileManager);
+  Isapi::load (configurationFileManager);
 
   /* Initialize FastCGI.  */
-  FastCgi::load(configurationFileManager);
+  FastCgi::load (configurationFileManager);
 
   /* Initialize SCGI.  */
-  Scgi::load(configurationFileManager);
+  Scgi::load (configurationFileManager);
 
   /* Load the MSCGI library.  */
-  MsCgi::load(configurationFileManager);
+  MsCgi::load (configurationFileManager);
 
-  HttpFile::load(configurationFileManager);
-  HttpDir::load(configurationFileManager);
+  HttpFile::load (configurationFileManager);
+  HttpDir::load (configurationFileManager);
 
-  /*! Determine the min file size that will use GZIP compression.  */
+  staticHttp.dynManagerList.addHttpManager ("FILE", staticHttp.httpFile);
+  staticHttp.dynManagerList.addHttpManager ("DIR", staticHttp.httpDir);
+  staticHttp.dynManagerList.addHttpManager ("CGI", staticHttp.cgi);
+  staticHttp.dynManagerList.addHttpManager ("MSCGI", staticHttp.mscgi);
+  staticHttp.dynManagerList.addHttpManager ("SCGI", staticHttp.scgi);
+  staticHttp.dynManagerList.addHttpManager ("WINCGI", staticHttp.wincgi);
+  staticHttp.dynManagerList.addHttpManager ("FASTCGI", staticHttp.fastcgi);
+  staticHttp.dynManagerList.addHttpManager ("ISAPI", staticHttp.isapi);
+
+  /* Determine the min file size that will use GZIP compression.  */
   data = configurationFileManager->getValue("GZIP_THRESHOLD");
   if(data)
   {
@@ -2329,15 +2199,6 @@
   td->scriptFile.assign("");
   td->inputDataPath.assign("");
   td->outputDataPath.assign("");
-
-  mscgi = new MsCgi();
-  wincgi = new WinCgi();
-  isapi = new Isapi();
-  cgi = new Cgi();
-  scgi = new Scgi();
-  fastcgi = new FastCgi();
-  httpFile = new HttpFile();
-  httpDir = new HttpDir();
 }
 
 /*!
@@ -2363,15 +2224,5 @@
   td->scriptFile.assign("");
   td->inputDataPath.assign("");
   td->outputDataPath.assign("");
-
-  delete mscgi;
-  delete wincgi;
-  delete isapi;
-  delete cgi;
-  delete scgi;
-  delete fastcgi;
-  delete httpFile;
-  delete httpDir;
-  
   delete td;
 }






reply via email to

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