myserver-commit
[Top][All Lists]
Advanced

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

[myserver-commit] [2915] Restored basic HTTP error messages.


From: Giuseppe Scrivano
Subject: [myserver-commit] [2915] Restored basic HTTP error messages.
Date: Sun, 26 Oct 2008 20:01:11 +0000

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

Log Message:
-----------
Restored basic HTTP error messages.

Modified Paths:
--------------
    trunk/myserver/src/http_handler/http_file/http_file.cpp
    trunk/myserver/src/http_handler/wincgi/wincgi.cpp
    trunk/myserver/src/protocol/http/http.cpp

Modified: trunk/myserver/src/http_handler/http_file/http_file.cpp
===================================================================
--- trunk/myserver/src/http_handler/http_file/http_file.cpp     2008-10-26 
19:54:32 UTC (rev 2914)
+++ trunk/myserver/src/http_handler/http_file/http_file.cpp     2008-10-26 
20:01:10 UTC (rev 2915)
@@ -83,11 +83,30 @@
   FiltersChain chain;
   u_long nbw;
   u_long nbr;
-  
+  time_t lastMT;
+  string tmpTime;
   u_long dataSent = 0;
 
   try
   {
+
+    if (!FilesUtility::fileExists (filenamePath))
+      return td->http->raiseHTTPError(404);
+
+    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);
+
+    HttpRequestHeader::Entry *ifModifiedSince = 
+      td->request.other.get("Last-Modified");
+
+    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)
     {  

Modified: trunk/myserver/src/http_handler/wincgi/wincgi.cpp
===================================================================
--- trunk/myserver/src/http_handler/wincgi/wincgi.cpp   2008-10-26 19:54:32 UTC 
(rev 2914)
+++ trunk/myserver/src/http_handler/wincgi/wincgi.cpp   2008-10-26 20:01:10 UTC 
(rev 2915)
@@ -80,8 +80,9 @@
 /*!
  *Send the WinCGI data.
  */
-int WinCgi::send(HttpThreadContext* td,ConnectionPtr s,const char* filename, 
-                 const char* cmdLine, int /*execute*/, int onlyHeader)
+int WinCgi::send(HttpThreadContext* td,ConnectionPtr s,
+                 const char* scriptpath, const char *cgipath,
+                 int /*execute*/, int onlyHeader)
 {
 #ifdef WIN32
   FiltersChain chain;
@@ -105,10 +106,10 @@
   u_long nbw = 0;
   ostringstream stream;
 
-  if(!FilesUtility::fileExists(filename))
+  if(!FilesUtility::fileExists(scriptpath))
     return td->http->raiseHTTPError(404);
 
-  FilesUtility::splitPath(filename,pathname,execname);
+  FilesUtility::splitPath(scriptpath, pathname, execname);
   
   getdefaultwd(dataFilePath,MAX_PATH);
   GetShortPathName(dataFilePath,dataFilePath,MAX_PATH);
@@ -302,7 +303,7 @@
   }
   OutFileHandle.close();
   spi.cmdLine.assign("cmd /c \"");
-  spi.cmdLine.append(filename);
+  spi.cmdLine.append(scriptpath);
   spi.cmdLine.append("\" ");
   spi.cmdLine.append(dataFilePath);
   spi.cwd.assign(pathname);
@@ -310,7 +311,7 @@
   if (proc.execAndWait (&spi, timeout))
   {
     ostringstream msg;
-    msg << "WinCGI: Error executing process " << filename;
+    msg << "WinCGI: Error executing process " << scriptpath;
     td->connection->host->warningsLogRequestAccess(td->id);
     td->connection->host->warningsLogWrite(msg.str().c_str());
     td->connection->host->warningsLogTerminateAccess(td->id);

Modified: trunk/myserver/src/protocol/http/http.cpp
===================================================================
--- trunk/myserver/src/protocol/http/http.cpp   2008-10-26 19:54:32 UTC (rev 
2914)
+++ trunk/myserver/src/protocol/http/http.cpp   2008-10-26 20:01:10 UTC (rev 
2915)
@@ -771,11 +771,9 @@
    */
   string filename;
   int permissions;
-  string data;
+  const char *cgiManager;
   int mimecmd;
-  time_t lastMT;
   int ret;
-  string tmpTime;
   string directory;
   string file;
   DynamicHttpManager *manager;
@@ -809,20 +807,18 @@
       return processDefaultFile (uri, permissions, onlyHeader);
     }
 
-    data.assign("");
-
     td->response.contentType[0] = '\0';
 
     /* If not specified differently, set the default content type to 
text/html.  */
     if(td->mime)
     {
-      td->response.contentType.assign(td->mime->mimeType);
-      data.assign(td->mime->cgiManager);
+      td->response.contentType.assign (td->mime->mimeType);
+      cgiManager = td->mime->cgiManager.c_str ();
     }
     else
     {
       td->response.contentType.assign("text/html");
-      data.assign("");
+      cgiManager = "";
     }
 
 
@@ -843,7 +839,7 @@
         return sendAuth();
       }
       ret = cgi->send(td, td->connection, td->filenamePath.c_str(),
-                      data.c_str(), td->mime->selfExecuted,  onlyHeader);
+                      cgiManager, td->mime->selfExecuted,  onlyHeader);
       return ret;
     }
     else if(td->mime && !td->mime->cmdName.compare ("ISAPI"))
@@ -862,7 +858,7 @@
         return sendAuth();
       }
       ret = isapi->send(td, td->connection, td->filenamePath.c_str(),
-                        data.c_str(), td->mime->selfExecuted, onlyHeader);
+                        cgiManager, td->mime->selfExecuted, onlyHeader);
       return ret;
     }
     else if(td->mime && !td->mime->cmdName.compare ("MSGI"))
@@ -893,7 +889,6 @@
     }
     else if(td->mime && !td->mime->cmdName.compare ("WINCGI"))
     {
-      ostringstream cgipath;
       int allowWincgi = 1;
       const char *dataH = td->connection->host->getHashedData("ALLOW_WINCGI");
       if(dataH)
@@ -908,16 +903,11 @@
       {
         return sendAuth();
       }
-      if(data.length())
-      {
-        cgipath <<  data << " \""<< td->filenamePath <<  "\"";
-      }
-      else
-      {
-        cgipath << td->filenamePath;
-      }
-      ret = wincgi->send(td, td->connection, cgipath.str().c_str(),
-                         0, td->mime->selfExecuted, onlyHeader);
+
+      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"))
@@ -936,7 +926,7 @@
         return sendAuth();
       }
       ret = fastcgi->send(td, td->connection, td->filenamePath.c_str(),
-                          data.c_str(), td->mime->selfExecuted, onlyHeader);
+                          cgiManager, td->mime->selfExecuted, onlyHeader);
       return ret;
     }
     else if(td->mime && !td->mime->cmdName.compare ("SCGI"))
@@ -955,7 +945,7 @@
         return sendAuth();
       }
       ret = scgi->send(td, td->connection, td->filenamePath.c_str(),
-                       data.c_str(), td->mime->selfExecuted, onlyHeader);
+                       cgiManager, td->mime->selfExecuted, onlyHeader);
       return ret;
     }
     else if (td->mime && (manager = staticHttp.dynManagerList.getHttpManager 
(td->mime->cmdName)))
@@ -974,87 +964,11 @@
         return sendAuth();
       }
       ret = scgi->send(td, td->connection, td->filenamePath.c_str(),
-                       data.c_str(), 1, onlyHeader);
+                       cgiManager, 1, onlyHeader);
       return ret;
     }
-    else if(!td->mime->cmdName.compare ("SENDLINK"))
+    else if (td->mime && (manager = 
staticHttp.dynManagerList.getHttpManager(td->mime->cmdName)))
     {
-      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 ((manager = 
staticHttp.dynManagerList.getHttpManager(td->mime->cmdName)))
-    {
       int allowExternal = 1;
       const char *dataH =
         td->connection->host->getHashedData ("ALLOW_EXTERNAL_COMMANDS");
@@ -1073,7 +987,7 @@
           return manager->send(td,
                                td->connection,
                                td->filenamePath.c_str(),
-                               data.c_str(),
+                               cgiManager,
                                td->mime->selfExecuted,
                                onlyHeader);
         else
@@ -1101,26 +1015,6 @@
       return sendAuth();
     }
 
-    lastMT = FilesUtility::getLastModTime(td->filenamePath.c_str());
-    if(lastMT == -1)
-    {
-      return raiseHTTPError(500);
-    }
-    getRFC822GMTTime(lastMT, tmpTime, HTTP_RESPONSE_LAST_MODIFIED_DIM);
-    td->response.lastModified.assign(tmpTime);
-
-    {
-      HttpRequestHeader::Entry *ifModifiedSince =
-        td->request.other.get("Last-Modified");
-
-      if(ifModifiedSince && ifModifiedSince->value->length())
-      {
-        if(!ifModifiedSince->value->compare(td->response.lastModified.c_str()))
-        {
-          return sendHTTPNonModified();
-        }
-      }
-    }
     ret = httpFile->send(td, td->connection, td->filenamePath.c_str(),
                          0, onlyHeader);
   }






reply via email to

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