myserver-commit
[Top][All Lists]
Advanced

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

[myserver-commit] [2910] Cleaned HTTP managers interface, (EXECUTE|RUN)


From: Giuseppe Scrivano
Subject: [myserver-commit] [2910] Cleaned HTTP managers interface, (EXECUTE|RUN) METHOD simplified to METHOD and an additional attribute in the MIME definition .
Date: Sun, 26 Oct 2008 14:12:10 +0000

Revision: 2910
          http://svn.sv.gnu.org/viewvc/?view=rev&root=myserver&revision=2910
Author:   gscrivano
Date:     2008-10-26 14:12:09 +0000 (Sun, 26 Oct 2008)

Log Message:
-----------
Cleaned HTTP managers interface, (EXECUTE|RUN)METHOD simplified to METHOD and 
an additional attribute in the MIME definition.

Modified Paths:
--------------
    trunk/myserver/binaries/MIMEtypes.xml.default
    trunk/myserver/binaries/MIMEtypes.xml.unix.default
    trunk/myserver/documentation/mime_types.texi
    trunk/myserver/include/conf/mime/mime_manager.h
    trunk/myserver/include/conf/vhost/vhost_manager.h
    trunk/myserver/include/plugin/http_manager/dyn_http_manager.h
    trunk/myserver/include/protocol/http/http.h
    trunk/myserver/src/conf/mime/mime_manager.cpp
    trunk/myserver/src/conf/vhost/vhost_manager.cpp
    trunk/myserver/src/plugin/http_manager/dyn_http_manager.cpp
    trunk/myserver/src/protocol/http/http.cpp

Modified: trunk/myserver/binaries/MIMEtypes.xml.default
===================================================================
--- trunk/myserver/binaries/MIMEtypes.xml.default       2008-10-26 12:01:40 UTC 
(rev 2909)
+++ trunk/myserver/binaries/MIMEtypes.xml.default       2008-10-26 14:12:09 UTC 
(rev 2910)
@@ -2,23 +2,23 @@
 
 <MIMES>
 
-<MIME mime="text/html" handler="RUNMSCGI" param="">
+<MIME mime="text/html" handler="MSCGI" param="">
 <EXTENSION value="mscgi"/>
 </MIME>
 
-<MIME mime="text/html" handler="EXECUTE" param="">
+<MIME mime="text/html" handler="CGI" self="YES" param="">
 <EXTENSION value="cgi"/>
 </MIME>
 
-<MIME mime="text/html" handler="EXECUTEISAPI" param="">
+<MIME mime="text/html" handler="ISAPI" param="">
 <EXTENSION value="isapi"/>
 </MIME>
 
-<MIME mime="text/html" handler="EXECUTEFASTCGI" param="">
+<MIME mime="text/html" handler="FASTCGI" param="">
 <EXTENSION value="fcgi"/>
 </MIME>
 
-<MIME mime="text/html" handler="EXECUTEWINCGI" param="">
+<MIME mime="text/html" handler="WINCGI" param="">
 <EXTENSION value="wincgi"/>
 </MIME>
 
@@ -562,4 +562,4 @@
 <EXTENSION value="html"/>
 </MIME>
 
-</MIMES>
\ No newline at end of file
+</MIMES>

Modified: trunk/myserver/binaries/MIMEtypes.xml.unix.default
===================================================================
--- trunk/myserver/binaries/MIMEtypes.xml.unix.default  2008-10-26 12:01:40 UTC 
(rev 2909)
+++ trunk/myserver/binaries/MIMEtypes.xml.unix.default  2008-10-26 14:12:09 UTC 
(rev 2910)
@@ -2,23 +2,23 @@
 
 <MIMES>
 
-<MIME mime="text/html" handler="RUNMSCGI" param="">
+<MIME mime="text/html" handler="MSCGI" param="">
 <EXTENSION value="mscgi"/>
 </MIME>
 
-<MIME mime="text/html" handler="EXECUTE" param="">
+<MIME mime="text/html" handler="CGI" self="YES" param="">
 <EXTENSION value="cgi"/>
 </MIME>
 
-<MIME mime="text/html" handler="EXECUTEISAPI" param="">
+<MIME mime="text/html" handler="ISAPI" param="">
 <EXTENSION value="isapi"/>
 </MIME>
 
-<MIME mime="text/html" handler="EXECUTEFASTCGI" param="">
+<MIME mime="text/html" handler="FASTCGI" param="">
 <EXTENSION value="fcgi"/>
 </MIME>
 
-<MIME mime="text/html" handler="EXECUTEWINCGI" param="">
+<MIME mime="text/html" handler="WINCGI" param="">
 <EXTENSION value="wincgi"/>
 </MIME>
 

Modified: trunk/myserver/documentation/mime_types.texi
===================================================================
--- trunk/myserver/documentation/mime_types.texi        2008-10-26 12:01:40 UTC 
(rev 2909)
+++ trunk/myserver/documentation/mime_types.texi        2008-10-26 14:12:09 UTC 
(rev 2910)
@@ -8,7 +8,7 @@
 <EXTENSION value="html"/>
 </MIME>
 
-<MIME mime="text/html" handler="RUNCGI" param="/usr/bin/perl">
+<MIME mime="text/html" handler="RUNCGI" param="/usr/bin/perl" 
selfExecuted="NO">
 <FILTER value="gzip"/>
 <EXTENSION value="pl"/>
 </MIME>
@@ -32,6 +32,13 @@
 @item param
 specifies additional params for the handler.
 
address@hidden selfExecuted
+where it is supported, lanuch the accessed resource as a process or a
+server.
+For example, there is need to use selfExecuted on the CGI protocol if
+the accessed resource can be used as a process.  Differently if it is
+not specified the resource mapped by the URI will be used as an
+argument to @code{param}.
 @end itemize
 
 @code{<FILTER>} defines a filter for the MIME type.  The data will
@@ -49,35 +56,20 @@
 Send the file statically as is.  This command is used for files
 extensions such as .html and .jpg that don't need any external
 intervention from the web server.
address@hidden RUNCGI
address@hidden CGI
 Run the CGI script indicated in the path.  It is used for file
 extensions such as .php and .pl that need to be processed before
 sending any data to the client.
address@hidden RUNFASTCGI
address@hidden FASTCGI
 Run the Fastcgi script.  This type will need a fastcgi parser
 downloaded (see the PHP page).  It is also used for file extensions
 such as .php and .pl.
address@hidden EXECUTEFASTCGI
-This also runs the Fastcgi script, but unlike the RUNFASTCGI above, it
-does not need a server to run the script, instead it acts as a self
-server.
address@hidden RUNSCGI
address@hidden SCGI
 Handle a specified mime type with this SCGI server.
address@hidden EXECUTESCGI
-Handle the file as a self SCGI process.
address@hidden RUNMSCGI
address@hidden MSCGI
 Run the MSCGI script. This library is only available for MyServer. It
 is used to build fast and efficient CGIs that needs to access MyServer
 internal data.
address@hidden EXECUTE
-Treat the file as an executable and send the output to the client. 
address@hidden SENDLINK
-Send the file that is contained in a link.
address@hidden EXECUTEWINCGI
-Send the file as a WinCGI
address@hidden RUNISAPI
address@hidden ISAPI
 Run the ISAPI script.  
address@hidden EXECUTEISAPI
-Run the ISAPI script but does not need a server to run. Instead, it
-acts as a self server.
 @end enumerate

Modified: trunk/myserver/include/conf/mime/mime_manager.h
===================================================================
--- trunk/myserver/include/conf/mime/mime_manager.h     2008-10-26 12:01:40 UTC 
(rev 2909)
+++ trunk/myserver/include/conf/mime/mime_manager.h     2008-10-26 14:12:09 UTC 
(rev 2910)
@@ -53,6 +53,7 @@
        string mimeType;
        string cmdName;
        string cgiManager;
+  bool selfExecuted;
        MimeRecord ();
        MimeRecord (MimeRecord&);
        int addFilter (const char*, bool acceptDuplicate = true);

Modified: trunk/myserver/include/conf/vhost/vhost_manager.h
===================================================================
--- trunk/myserver/include/conf/vhost/vhost_manager.h   2008-10-26 12:01:40 UTC 
(rev 2909)
+++ trunk/myserver/include/conf/vhost/vhost_manager.h   2008-10-26 14:12:09 UTC 
(rev 2910)
@@ -64,7 +64,6 @@
   void changeLocationsOwner ();
 private:
   void loadXMLlogData (string, Vhost*, xmlNode*);
-  string saveXMLlogData (string, Vhost*);
   ListenThreads* listenThreads;
   Mutex mutex;
   VhostSource* extSource;

Modified: trunk/myserver/include/plugin/http_manager/dyn_http_manager.h
===================================================================
--- trunk/myserver/include/plugin/http_manager/dyn_http_manager.h       
2008-10-26 12:01:40 UTC (rev 2909)
+++ trunk/myserver/include/plugin/http_manager/dyn_http_manager.h       
2008-10-26 14:12:09 UTC (rev 2910)
@@ -1,7 +1,7 @@
 /* -*- mode: c++ -*- */
 /*
 MyServer
-Copyright (C) 2005 Free Software Foundation, Inc.
+Copyright (C) 2005, 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
@@ -38,7 +38,7 @@
        DynamicHttpManager();
        virtual ~DynamicHttpManager();
        virtual int send(HttpThreadContext*, ConnectionPtr s, const char 
*filenamePath,
-                   const char* cgi, int onlyHeader = 0);
+                   const char* cgi, int selfExecuted, int onlyHeader = 0);
 
 };
 

Modified: trunk/myserver/include/protocol/http/http.h
===================================================================
--- trunk/myserver/include/protocol/http/http.h 2008-10-26 12:01:40 UTC (rev 
2909)
+++ trunk/myserver/include/protocol/http/http.h 2008-10-26 14:12:09 UTC (rev 
2910)
@@ -190,6 +190,9 @@
   SecurityToken *getSecurityToken (){return &(td->securityToken);}
 
 protected:
+
+  int processDefaultFile (string& uri, int permissions, int onlyHeader);
+
   HttpDataHandler* mscgi;
   HttpDataHandler* wincgi;
   HttpDataHandler* isapi;

Modified: trunk/myserver/src/conf/mime/mime_manager.cpp
===================================================================
--- trunk/myserver/src/conf/mime/mime_manager.cpp       2008-10-26 12:01:40 UTC 
(rev 2909)
+++ trunk/myserver/src/conf/mime/mime_manager.cpp       2008-10-26 14:12:09 UTC 
(rev 2910)
@@ -38,6 +38,7 @@
   mimeType.assign ("");
   cgiManager.assign ("");
   cmdName.assign ("");
+  selfExecuted = false;
 }
 
 /*!
@@ -90,6 +91,7 @@
     filters.push_back (*i);
   }
 
+  selfExecuted = m.selfExecuted;
   mimeType.assign (m.mimeType);
   cmdName.assign (m.cmdName);
   cgiManager.assign (m.cgiManager);
@@ -130,7 +132,12 @@
     if (!xmlStrcmp (attrs->name, (const xmlChar *)"handler") && 
         attrs->children && attrs->children->content)
       rc->cmdName.assign ((const char*)attrs->children->content);
-    
+ 
+    if (!xmlStrcmp (attrs->name, (const xmlChar *)"self") && 
+        attrs->children && attrs->children->content)
+      rc->selfExecuted = xmlStrcmp (attrs->children->content, 
+                                    (const xmlChar *)"YES");
+   
     if (!xmlStrcmp (attrs->name, (const xmlChar *)"param") && 
         attrs->children && attrs->children->content)
       rc->cgiManager.assign ((const char*)attrs->children->content);

Modified: trunk/myserver/src/conf/vhost/vhost_manager.cpp
===================================================================
--- trunk/myserver/src/conf/vhost/vhost_manager.cpp     2008-10-26 12:01:40 UTC 
(rev 2909)
+++ trunk/myserver/src/conf/vhost/vhost_manager.cpp     2008-10-26 14:12:09 UTC 
(rev 2910)
@@ -200,13 +200,10 @@
        *Change the log files owner if a different user or group
        *identifier is specified.
        */
-      for(int i = 0; ; i++)
+      for(list<Vhost*>::iterator it = hostList.begin (); it != hostList.end 
(); it++)
         {
           int err;
-          Vhost* vh = getVHostByNumber(i);
-          /* Break if we reach the end of the list.  */
-          if(!vh)
-            break;
+          Vhost* vh = *it;
 
           /* Chown the log files.  */
           err = logManager->chown (vh, "ACCESSLOG", uid, gid);
@@ -235,48 +232,10 @@
   return hostList.size();
 }
 
-string
-VhostManager::saveXMLlogData (string name, Vhost* vh)
-{
-  list<string> l;
-  ostringstream oss;
-  if (!logManager->get (vh, name, &l))
-    {
-      list<string>::iterator it;
-      oss << "<STREAMS>\r\n";
-      for (it = l.begin (); it != l.end (); it++)
-        {
-          oss << "<STREAM>\r\n";
-          oss << "<LOCATION>";
-          oss << *it;
-          oss << "</LOCATION>\r\n";
-          u_long cycle = 0;
-          if (!logManager->getCycle (*it, &cycle))
-            {
-              oss << "<CYCLE>";
-              oss << cycle;
-              oss << "</CYCLE>\r\n";
-            }
-          list<string> f;
-          if (!logManager->getFilters (*it, &f))
-            {
-              oss << "<FILTERS>\r\n";
-              list<string>::iterator it_1;
-              for (it_1 = f.begin (); it_1 != f.end (); it_1++)
-                {
-                  oss << "<FILTER>";
-                  oss << *it_1;
-                  oss << "</FILTER>\r\n";
-                }
-              oss << "</FILTERS>\r\n";
-            }
-          oss << "</STREAM>\r\n";
-        }
-      oss << "</STREAMS>\r\n";
-    }
-  return oss.str ();
-}
 
+/*!
+ *Load a log XML node.
+ */
 void
 VhostManager::loadXMLlogData (string name, Vhost* vh, xmlNode* lcur)
 {

Modified: trunk/myserver/src/plugin/http_manager/dyn_http_manager.cpp
===================================================================
--- trunk/myserver/src/plugin/http_manager/dyn_http_manager.cpp 2008-10-26 
12:01:40 UTC (rev 2909)
+++ trunk/myserver/src/plugin/http_manager/dyn_http_manager.cpp 2008-10-26 
14:12:09 UTC (rev 2910)
@@ -23,7 +23,7 @@
 #include <string>
 
 typedef int (*sendManagerPROC)(volatile void*, volatile void*, const char*, 
-                               const char*, int); 
+                               const char*, int, int); 
 
 
 /*!
@@ -47,11 +47,11 @@
  */
 int DynamicHttpManager::send(HttpThreadContext* context, ConnectionPtr s, 
                              const char *filenamePath, const char* cgi, 
-                             int onlyHeader)
+                             int selfExecuted, int onlyHeader)
 {
   sendManagerPROC control = (sendManagerPROC)hinstLib.getProc("sendManager");
   if(control)
-    return control(context, s, filenamePath, cgi, onlyHeader);
+    return control(context, s, filenamePath, cgi, selfExecuted, onlyHeader);
   else
     return 0;
 }

Modified: trunk/myserver/src/protocol/http/http.cpp
===================================================================
--- trunk/myserver/src/protocol/http/http.cpp   2008-10-26 12:01:40 UTC (rev 
2909)
+++ trunk/myserver/src/protocol/http/http.cpp   2008-10-26 14:12:09 UTC (rev 
2910)
@@ -778,7 +778,7 @@
   string tmpTime;
   string directory;
   string file;
-  DynamicHttpManager* manager;
+  DynamicHttpManager *manager;
 
   /*! By default allows only few actions. */
   permissions = MYSERVER_PERMISSION_READ | MYSERVER_PERMISSION_BROWSE ;
@@ -804,69 +804,9 @@
         return raiseHTTPError(ret);
     }
 
-    /*!
-     *If there are not any extension then we do one of this in order:
-     *1)We send the default files in the directory in order.
-     *2)We send the directory content.
-     *3)We send an error.
-     */
     if(!td->mime && FilesUtility::isDirectory(td->filenamePath.c_str()))
     {
-      int i;
-      if(!(permissions & MYSERVER_PERMISSION_BROWSE))
-      {
-        return sendAuth();
-      }
-      for(i = 0;; i++)
-      {
-        const char *defaultFileNamePath = getDefaultFilenamePath(i);
-        ostringstream defaultFileName;
-        defaultFileName.clear();
-        if(defaultFileNamePath)
-        {
-          defaultFileName << td->filenamePath << "/" << defaultFileNamePath;
-        }
-        else
-        {
-          break;
-        }
-
-        if(FilesUtility::fileExists(defaultFileName.str().c_str()))
-        {
-          ostringstream nUrl;
-
-          if(td->request.uriEndsWithSlash)
-          {
-            nUrl << defaultFileNamePath;
-          }
-          else
-          {
-            u_long lastSlashOffset = uri.length();
-            while(lastSlashOffset && uri[lastSlashOffset] != '/')
-              --lastSlashOffset;
-
-            nUrl << &(uri.c_str()[lastSlashOffset < uri.length() ?
-                                  lastSlashOffset + 1 : 0])
-                 << "/" << defaultFileNamePath;
-          }
-
-          if(td->pathInfo.length())
-            nUrl << "/" << td->pathInfo;
-
-
-          if(td->request.uriOpts.length())
-            nUrl << "?" << td->request.uriOpts;
-
-          /*! Send a redirect to the new location.  */
-          if(sendHTTPRedirect(nUrl.str().c_str()))
-            ret = 1;
-          else
-            ret = 0;
-          return ret;
-        }
-      }
-      return httpDir->send(td, td->connection, td->filenamePath.c_str(), 0,
-                           onlyHeader);
+      return processDefaultFile (uri, permissions, onlyHeader);
     }
 
     data.assign("");
@@ -886,7 +826,7 @@
     }
 
 
-    if(td->mime && !td->mime->cmdName.compare ("RUNCGI"))
+    if(td->mime && !td->mime->cmdName.compare ("CGI"))
     {
       int allowCgi = 1;
       const char *dataH = td->connection->host->getHashedData("ALLOW_CGI");
@@ -903,31 +843,11 @@
         return sendAuth();
       }
       ret = cgi->send(td, td->connection, td->filenamePath.c_str(),
-                      data.c_str(), 0,  onlyHeader);
+                      data.c_str(), td->mime->selfExecuted,  onlyHeader);
       return ret;
     }
-    else if(td->mime && !td->mime->cmdName.compare ("EXECUTE"))
+    else if(td->mime && !td->mime->cmdName.compare ("ISAPI"))
     {
-      int allowCgi = 1;
-      const char *dataH = td->connection->host->getHashedData("ALLOW_CGI");
-      if(dataH)
-      {
-        if(!strcmpi(dataH, "YES"))
-          allowCgi = 1;
-        else
-          allowCgi = 0;
-      }
-
-      if(!allowCgi || !(permissions & MYSERVER_PERMISSION_EXECUTE))
-      {
-        return sendAuth();
-      }
-      ret = cgi->send(td, td->connection, td->filenamePath.c_str(),
-                      data.c_str(), 1, onlyHeader);
-      return ret;
-    }
-    else if(td->mime && !td->mime->cmdName.compare ("RUNISAPI"))
-    {
       int allowIsapi = 1;
       const char *dataH = td->connection->host->getHashedData("ALLOW_ISAPI");
       if(dataH)
@@ -942,22 +862,11 @@
         return sendAuth();
       }
       ret = isapi->send(td, td->connection, td->filenamePath.c_str(),
-                        data.c_str(), 0, onlyHeader);
+                        data.c_str(), td->mime->selfExecuted, onlyHeader);
       return ret;
-
     }
-    else if(td->mime && !td->mime->cmdName.compare ("EXECUTEISAPI"))
+    else if(td->mime && !td->mime->cmdName.compare ("MSGI"))
     {
-      if(!(permissions & MYSERVER_PERMISSION_EXECUTE))
-      {
-        return sendAuth();
-      }
-      ret = isapi->send(td, td->connection, td->filenamePath.c_str(),
-                        data.c_str(), 1, onlyHeader);
-      return ret;
-    }
-    else if(td->mime && !td->mime->cmdName.compare ("RUNMSGI"))
-    {
       char* target;
       int allowMscgi = 1;
       const char *dataH = td->connection->host->getHashedData("ALLOW_MSCGI");
@@ -979,10 +888,10 @@
         target = (char*)td->request.uriOpts.c_str();
 
       ret = mscgi->send(td, td->connection, td->filenamePath.c_str(),
-                        target, 1, onlyHeader);
+                        target, td->mime->selfExecuted, onlyHeader);
       return ret;
     }
-    else if(td->mime && !td->mime->cmdName.compare ("EXECUTEWINCGI"))
+    else if(td->mime && !td->mime->cmdName.compare ("WINCGI"))
     {
       ostringstream cgipath;
       int allowWincgi = 1;
@@ -1008,10 +917,10 @@
         cgipath << td->filenamePath;
       }
       ret = wincgi->send(td, td->connection, cgipath.str().c_str(),
-                         0, 1, onlyHeader);
+                         0, td->mime->selfExecuted, onlyHeader);
       return ret;
     }
-    else if(td->mime && !td->mime->cmdName.compare ("RUNFASTCGI"))
+    else if(td->mime && !td->mime->cmdName.compare ("FASTCGI"))
     {
       int allowFastcgi = 1;
       const char *dataH = td->connection->host->getHashedData("ALLOW_FASTCGI");
@@ -1027,30 +936,11 @@
         return sendAuth();
       }
       ret = fastcgi->send(td, td->connection, td->filenamePath.c_str(),
-                          data.c_str(), 0, onlyHeader);
+                          data.c_str(), td->mime->selfExecuted, onlyHeader);
       return ret;
     }
-    else if(td->mime && !td->mime->cmdName.compare ("EXECUTEFASTCGI"))
+    else if(td->mime && !td->mime->cmdName.compare ("SCGI"))
     {
-      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(),
-                          data.c_str(), 1, onlyHeader);
-      return ret;
-    }
-    else if(td->mime && !td->mime->cmdName.compare ("RUNSCGI"))
-    {
       int allowScgi = 1;
       const char *dataH = td->connection->host->getHashedData("ALLOW_SCGI");
       if(dataH)
@@ -1065,109 +955,14 @@
         return sendAuth();
       }
       ret = scgi->send(td, td->connection, td->filenamePath.c_str(),
-                       data.c_str(), 0, onlyHeader);
+                       data.c_str(), td->mime->selfExecuted, onlyHeader);
       return ret;
     }
-    else if(td->mime && !td->mime->cmdName.compare ("EXECUTESCGI"))
+    else if (td->mime && (manager = staticHttp.dynManagerList.getPlugin 
(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(),
-                       data.c_str(), 1, onlyHeader);
-      return ret;
-    }
-    else if(td->mime && !td->mime->cmdName.compare ("SENDLINK"))
-    {
-      u_long nbr;
-      char* linkpath;
-      char* pathInfo;
-      int linkpathSize;
-      File h;
-      int allowSendlink = 1;
-      const char *dataH =
-        td->connection->host->getHashedData("ALLOW_SEND_LINK");
-
-      if(dataH)
-      {
-        if(!strcmpi(dataH, "YES"))
-          allowSendlink = 1;
-        else
-          allowSendlink = 0;
-      }
-
-      if(!allowSendlink || !(permissions & MYSERVER_PERMISSION_READ))
-      {
-        return sendAuth();
-      }
-
-      if(h.openFile(td->filenamePath.c_str(),
-                    File::MYSERVER_OPEN_IFEXISTS|File::MYSERVER_OPEN_READ))
-      {
-        return raiseHTTPError(500);
-      }
-
-      linkpathSize = h.getFileSize() + td->pathInfo.length() + 1;
-
-      if(linkpathSize > MYSERVER_KB(10))
-        linkpathSize = MYSERVER_KB(10);
-
-      linkpath=new char[linkpathSize];
-
-      if(linkpath == 0)
-      {
-        return sendHTTPhardError500();
-      }
-
-      if(h.read(linkpath, linkpathSize, &nbr))
-      {
-        h.close();
-        delete [] linkpath;
-        return raiseHTTPError(500);/*!Internal server error*/
-      }
-
-      h.close();
-      linkpath[nbr]='\0';
-
-      pathInfo = new char[td->pathInfo.length() + 1];
-
-      if(pathInfo == 0)
-      {
-        delete [] linkpath;
-        return raiseHTTPError(500);/*!Internal server error*/
-      }
-      strcpy(pathInfo, td->pathInfo.c_str());
-      translateEscapeString(pathInfo);
-      strncat(linkpath, pathInfo,strlen(linkpath));
-
-      if(nbr)
-      {
-        string uri;
-        uri.assign(linkpath);
-        ret = sendHTTPResource(uri, systemrequest, onlyHeader, 1);
-      }
-      else
-        ret = raiseHTTPError(404);
-
-      delete [] linkpath;
-      delete [] pathInfo;
-      return ret;
-    }
-    else if (td->mime && (manager = 
staticHttp.dynManagerList.getPlugin(td->mime->cmdName)))
-    {
       int allowExternal = 1;
       const char *dataH =
-        td->connection->host->getHashedData("ALLOW_EXTERNAL_COMMANDS");
+        td->connection->host->getHashedData ("ALLOW_EXTERNAL_COMMANDS");
 
       if(dataH)
       {
@@ -1180,28 +975,30 @@
       if(allowExternal && td->mime)
       {
         if(manager)
-          return manager->send(td, td->connection, td->filenamePath.c_str(),
-                               data.c_str(), onlyHeader);
+          return manager->send(td,
+                               td->connection,
+                               td->filenamePath.c_str(),
+                               data.c_str(),
+                               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)
     {
-      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();
-      }
+      return sendAuth();
     }
 
     if(!(permissions & MYSERVER_PERMISSION_READ))
@@ -2203,7 +2000,77 @@
   return 200;
 }
 
+
+
 /*!
+ *If a directory is accessed try in order:
+ *
+ *1) The default files in order.
+ *2) The directory content.
+ *3) An error.
+ *
+ *\param uri The accessed URI.
+ *\param permissions The permission mask for the client.
+ *\param onlyHeader specify if the client requested only the header.
+ */
+int Http::processDefaultFile (string& uri, int permissions, int onlyHeader)
+{
+  int i;
+  int ret;
+
+  if( !(permissions & MYSERVER_PERMISSION_BROWSE) )
+    {
+      return sendAuth();
+    }
+
+  for(i = 0;; i++)
+    {
+      const char *defaultFileNamePath = getDefaultFilenamePath(i);
+      ostringstream defaultFileName;
+      defaultFileName.clear();
+      if(defaultFileNamePath)
+        {
+          defaultFileName << td->filenamePath << "/" << defaultFileNamePath;
+        }
+      else
+          break;
+      
+      if(FilesUtility::fileExists(defaultFileName.str().c_str()))
+        {
+          ostringstream nUrl;
+          
+          if(td->request.uriEndsWithSlash)
+              nUrl << defaultFileNamePath;
+          else
+            {
+              u_long lastSlashOffset = uri.length();
+              while(lastSlashOffset && uri[lastSlashOffset] != '/')
+                --lastSlashOffset;
+              
+              nUrl << &(uri.c_str()[lastSlashOffset < uri.length() ?
+                                    lastSlashOffset + 1 : 0])
+                   << "/" << defaultFileNamePath;
+            }
+          
+          if(td->pathInfo.length())
+            nUrl << "/" << td->pathInfo;
+
+          if(td->request.uriOpts.length())
+            nUrl << "?" << td->request.uriOpts;
+
+          /*! Send a redirect to the new location.  */
+          if(sendHTTPRedirect(nUrl.str().c_str()))
+            ret = 1;
+          else
+            ret = 0;
+          return ret;
+        }
+    }
+  return httpDir->send(td, td->connection, td->filenamePath.c_str(), 0,
+                       onlyHeader);
+}
+
+/*!
  *Get the CSS file used in a browsed directory.
  */
 const char* Http::getBrowseDirCSSFile()






reply via email to

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