[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[myserver-commit] [3065] Delegate the HTTP PUT/ DELETE commands to the H
From: |
Giuseppe Scrivano |
Subject: |
[myserver-commit] [3065] Delegate the HTTP PUT/ DELETE commands to the HTTP handlers instead of handling them in the manager . |
Date: |
Sat, 02 May 2009 10:54:26 +0000 |
Revision: 3065
http://svn.sv.gnu.org/viewvc/?view=rev&root=myserver&revision=3065
Author: gscrivano
Date: 2009-05-02 10:54:25 +0000 (Sat, 02 May 2009)
Log Message:
-----------
Delegate the HTTP PUT/DELETE commands to the HTTP handlers instead of handling
them in the manager.
Modified Paths:
--------------
trunk/myserver/include/http_handler/http_file/http_file.h
trunk/myserver/include/protocol/http/http.h
trunk/myserver/src/http_handler/http_file/http_file.cpp
trunk/myserver/src/protocol/http/http.cpp
Modified: trunk/myserver/include/http_handler/http_file/http_file.h
===================================================================
--- trunk/myserver/include/http_handler/http_file/http_file.h 2009-05-01
16:34:56 UTC (rev 3064)
+++ trunk/myserver/include/http_handler/http_file/http_file.h 2009-05-02
10:54:25 UTC (rev 3065)
@@ -1,7 +1,7 @@
/* -*- mode: c++ -*- */
/*
MyServer
-Copyright (C) 2005, 2008 Free Software Foundation, Inc.
+Copyright (C) 2005, 2008, 2009 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
@@ -35,6 +35,12 @@
int execute = 0, int OnlyHeader = 0);
HttpFile();
virtual ~HttpFile();
+
+protected:
+ int putFile (HttpThreadContext* td,
+ string& filename);
+ int deleteFile (HttpThreadContext* td,
+ string& filename);
private:
static int appendDataToHTTPChannel(HttpThreadContext* td,
char* buffer,
Modified: trunk/myserver/include/protocol/http/http.h
===================================================================
--- trunk/myserver/include/protocol/http/http.h 2009-05-01 16:34:56 UTC (rev
3064)
+++ trunk/myserver/include/protocol/http/http.h 2009-05-02 10:54:25 UTC (rev
3065)
@@ -129,7 +129,9 @@
int traceHTTPRESOURCE(string& filename,
int yetMapped = 0);
- int deleteHTTPRESOURCE(string& filename,
+ int deleteHTTPRESOURCE(string &filename,
+ int systemrequest = 0,
+ int onlyHeader = 0,
int yetMapped = 0);
bool allowMethod(const char *name);
Modified: trunk/myserver/src/http_handler/http_file/http_file.cpp
===================================================================
--- trunk/myserver/src/http_handler/http_file/http_file.cpp 2009-05-01
16:34:56 UTC (rev 3064)
+++ trunk/myserver/src/http_handler/http_file/http_file.cpp 2009-05-02
10:54:25 UTC (rev 3065)
@@ -39,6 +39,163 @@
}
/*!
+ *Main function to handle the HTTP PUT command.
+ */
+int HttpFile::putFile (HttpThreadContext* td,
+ string& filename)
+{
+ u_long firstByte = td->request.rangeByteBegin;
+ int keepalive = 0;
+ int ret;
+
+ try
+ {
+ HttpHeaders::buildDefaultHTTPResponseHeader(&td->response);
+
+ if(td->request.isKeepAlive())
+ {
+ td->response.connection.assign("keep-alive");
+ keepalive = 1;
+ }
+
+ if(!(td->permissions & MYSERVER_PERMISSION_WRITE))
+ {
+ return td->http->sendAuth();
+ }
+
+ if(FilesUtility::fileExists(td->filenamePath.c_str()))
+ {
+ /*! If the file exists update it. */
+ File file;
+ if(file.openFile(td->filenamePath.c_str(), File::MYSERVER_OPEN_IFEXISTS |
+ File::MYSERVER_OPEN_WRITE))
+ {
+ /*! Return an internal server error. */
+ return td->http->raiseHTTPError(500);
+ }
+ file.seek (firstByte);
+ for(;;)
+ {
+ u_long nbr = 0, nbw = 0;
+ if(td->inputData.read (td->buffer->getBuffer(),
+ td->buffer->getRealLength(), &nbr))
+ {
+ file.close();
+ /*! Return an internal server error. */
+ return td->http->raiseHTTPError(500);
+ }
+ if(nbr)
+ {
+ if(file.writeToFile(td->buffer->getBuffer(), nbr, &nbw))
+ {
+ file.close();
+ /*! Return an internal server error. */
+ return td->http->raiseHTTPError(500);
+ }
+ }
+ else
+ break;
+ if(nbw != nbr)
+ {
+ file.close();
+ /*! Internal server error. */
+ return td->http->raiseHTTPError(500);
+ }
+ }
+ file.close();
+ /*! Successful updated. */
+ td->http->raiseHTTPError(200);
+
+ return keepalive;
+ }
+ else
+ {
+ /*!
+ *If the file doesn't exist create it.
+ */
+ File file;
+ if(file.openFile(td->filenamePath.c_str(),
+ File::MYSERVER_CREATE_ALWAYS |
+ File::MYSERVER_OPEN_WRITE))
+ {
+ /*! Internal server error. */
+ return td->http->raiseHTTPError(500);
+ }
+ for(;;)
+ {
+ u_long nbr = 0, nbw = 0;
+ if(td->inputData.read(td->buffer->getBuffer(),
+ td->buffer->getRealLength(), &nbr))
+ {
+ file.close();
+ return td->http->raiseHTTPError(500);
+ }
+ if(nbr)
+ {
+ if(file.writeToFile(td->buffer->getBuffer(), nbr, &nbw))
+ {
+ file.close();
+ return td->http->raiseHTTPError(500);
+ }
+ }
+ else
+ break;
+ if( nbw != nbr )
+ {
+ file.close();
+ return td->http->raiseHTTPError(500);
+ }
+ }
+ file.close();
+ /*! Successful created. */
+ td->http->raiseHTTPError(201);
+ return 1;
+ }
+ }
+ catch(...)
+ {
+ return td->http->raiseHTTPError(500);
+ };
+}
+
+/*!
+ *Delete the resource identified by filename.
+ */
+int HttpFile::deleteFile (HttpThreadContext* td,
+ string& filename)
+{
+ int permissions = -1;
+ string directory;
+ string file;
+ int ret;
+ try
+ {
+ HttpHeaders::buildDefaultHTTPResponseHeader(&td->response);
+
+ if(!(td->permissions & MYSERVER_PERMISSION_DELETE))
+ return td->http->sendAuth();
+
+ if(FilesUtility::fileExists(td->filenamePath))
+ {
+ FilesUtility::deleteFile(td->filenamePath.c_str());
+
+ /*! Successful deleted. */
+ return td->http->raiseHTTPError(202);
+ }
+ else
+ {
+ /*! No content. */
+ return td->http->raiseHTTPError(204);
+ }
+ }
+ catch(...)
+ {
+ return td->http->raiseHTTPError(500);
+ };
+
+}
+
+/*!
*Send a file to the client using the HTTP protocol.
*\param td The current HTTP thread context.
*\param s A pointer to the connection.
@@ -47,9 +204,12 @@
*\param execute Not used.
*\param onlyHeader Specify if send only the HTTP header.
*/
-int HttpFile::send(HttpThreadContext* td, ConnectionPtr s,
- const char *filenamePath, const char* exec,
- int execute, int onlyHeader)
+int HttpFile::send(HttpThreadContext* td,
+ ConnectionPtr s,
+ const char *filenamePath,
+ const char* exec,
+ int execute,
+ int onlyHeader)
{
/*
*With this routine we send a file through the HTTP protocol.
@@ -80,6 +240,12 @@
try
{
+ if(!td->request.cmd.compare("PUT"))
+ return putFile (td, td->filenamePath);
+
+ if(!td->request.cmd.compare("DELETE"))
+ return deleteFile (td, td->filenamePath);
+
if ( !(td->permissions & MYSERVER_PERMISSION_READ))
return td->http->sendAuth ();
Modified: trunk/myserver/src/protocol/http/http.cpp
===================================================================
--- trunk/myserver/src/protocol/http/http.cpp 2009-05-01 16:34:56 UTC (rev
3064)
+++ trunk/myserver/src/protocol/http/http.cpp 2009-05-02 10:54:25 UTC (rev
3065)
@@ -236,127 +236,12 @@
/*!
*Main function to handle the HTTP PUT command.
*/
-int Http::putHTTPRESOURCE(string& filename, int, int,
+int Http::putHTTPRESOURCE(string& filename,
+ int sysReq,
+ int onlyHeader,
int yetmapped)
{
- u_long firstByte = td->request.rangeByteBegin;
- int permissions = -1;
- int keepalive = 0;
- int ret;
-
- try
- {
- HttpHeaders::buildDefaultHTTPResponseHeader(&td->response);
-
- if(td->request.isKeepAlive())
- {
- td->response.connection.assign("keep-alive");
- keepalive = 1;
- }
-
- ret = Http::preprocessHttpRequest(filename, yetmapped, &permissions);
-
- if(ret != 200)
- return raiseHTTPError(ret);
-
- if(!(permissions & MYSERVER_PERMISSION_WRITE))
- {
- return sendAuth();
- }
-
- if(FilesUtility::fileExists(td->filenamePath.c_str()))
- {
- /*! If the file exists update it. */
- File file;
- if(file.openFile(td->filenamePath.c_str(), File::MYSERVER_OPEN_IFEXISTS |
- File::MYSERVER_OPEN_WRITE))
- {
- /*! Return an internal server error. */
- return raiseHTTPError(500);
- }
- file.seek (firstByte);
- for(;;)
- {
- u_long nbr = 0, nbw = 0;
- if(td->inputData.read (td->buffer->getBuffer(),
- td->buffer->getRealLength(), &nbr))
- {
- file.close();
- /*! Return an internal server error. */
- return raiseHTTPError(500);
- }
- if(nbr)
- {
- if(file.writeToFile(td->buffer->getBuffer(), nbr, &nbw))
- {
- file.close();
- /*! Return an internal server error. */
- return raiseHTTPError(500);
- }
- }
- else
- break;
- if(nbw != nbr)
- {
- file.close();
- /*! Internal server error. */
- return raiseHTTPError(500);
- }
- }
- file.close();
- /*! Successful updated. */
- raiseHTTPError(200);
-
- return keepalive;
- }
- else
- {
- /*!
- *If the file doesn't exist create it.
- */
- File file;
- if(file.openFile(td->filenamePath.c_str(),
- File::MYSERVER_CREATE_ALWAYS |
- File::MYSERVER_OPEN_WRITE))
- {
- /*! Internal server error. */
- return raiseHTTPError(500);
- }
- for(;;)
- {
- u_long nbr = 0, nbw = 0;
- if(td->inputData.read(td->buffer->getBuffer(),
- td->buffer->getRealLength(), &nbr))
- {
- file.close();
- return raiseHTTPError(500);
- }
- if(nbr)
- {
- if(file.writeToFile(td->buffer->getBuffer(), nbr, &nbw))
- {
- file.close();
- return raiseHTTPError(500);
- }
- }
- else
- break;
- if( nbw != nbr )
- {
- file.close();
- return raiseHTTPError(500);
- }
- }
- file.close();
- /*! Successful created. */
- raiseHTTPError(201);
- return 1;
- }
- }
- catch(...)
- {
- return raiseHTTPError(500);
- };
+ return sendHTTPResource (filename, sysReq, onlyHeader, yetmapped);
}
/*!
@@ -654,42 +539,12 @@
/*!
*Delete the resource identified by filename.
*/
-int Http::deleteHTTPRESOURCE(string& filename, int yetmapped)
+int Http::deleteHTTPRESOURCE(string& filename,
+ int sysReq,
+ int onlyHeader,
+ int yetmapped)
{
- int permissions = -1;
- string directory;
- string file;
- int ret;
- try
- {
- HttpHeaders::buildDefaultHTTPResponseHeader(&td->response);
-
- ret = Http::preprocessHttpRequest(filename, yetmapped, &permissions);
-
- if(ret != 200)
- return raiseHTTPError(ret);
-
- if(FilesUtility::fileExists(td->filenamePath))
- {
- if(!(permissions & MYSERVER_PERMISSION_DELETE))
- return 401;
-
- FilesUtility::deleteFile(td->filenamePath.c_str());
-
- /*! Successful deleted. */
- return raiseHTTPError(202);
- }
- else
- {
- /*! No content. */
- return raiseHTTPError(204);
- }
- }
- catch(...)
- {
- return raiseHTTPError(500);
- };
-
+ return sendHTTPResource (filename, sysReq, onlyHeader, yetmapped);
}
/*!
@@ -1205,7 +1060,8 @@
}
}
- if(td->request.uri.length() > 2 && td->request.uri[1] == '~'){
+ if(td->request.uri.length() > 2 && td->request.uri[1] == '~')
+ {
string documentRoot;
u_long pos = 2;
string user;
@@ -1228,23 +1084,22 @@
MYSERVER_SERVER_CONF,
"public_html");
- if (strcmpi (useHomeDir, "YES"))
- return raiseHTTPError (404);
+ if (strcmpi (useHomeDir, "YES"))
+ return raiseHTTPError (404);
- td->vhostDir.assign (documentRoot);
- td->vhostDir.append ("/");
- td->vhostDir.append (homeDir);
+ td->vhostDir.assign (documentRoot);
+ td->vhostDir.append ("/");
+ td->vhostDir.append (homeDir);
+
+ if(!td->request.uriEndsWithSlash && !(td->request.uri.length() -
pos))
+ {
+ td->request.uri.append("/");
+ return sendHTTPRedirect(td->request.uri.c_str());
+ }
- if(!td->request.uriEndsWithSlash && !(td->request.uri.length() - pos))
- {
- td->request.uri.append("/");
-
- return sendHTTPRedirect(td->request.uri.c_str());
- }
-
- if(td->request.uri.length() - pos)
- td->request.uri.assign(td->request.uri.substr(pos,
- td->request.uri.length()));
+ if(td->request.uri.length() - pos)
+ td->request.uri.assign(td->request.uri.substr(pos,
+
td->request.uri.length()));
else
td->request.uri.assign("");
}
@@ -1365,7 +1220,7 @@
}
/* DELETE REQUEST. */
else if(!td->request.cmd.compare("DELETE"))
- ret = deleteHTTPRESOURCE(td->request.uri, 0);
+ ret = deleteHTTPRESOURCE(td->request.uri, 0, 1);
/* PUT REQUEST. */
else if(!td->request.cmd.compare("PUT"))
ret = putHTTPRESOURCE(td->request.uri, 0, 1);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [myserver-commit] [3065] Delegate the HTTP PUT/ DELETE commands to the HTTP handlers instead of handling them in the manager .,
Giuseppe Scrivano <=