diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-09-13 22:38:03 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-09-13 22:38:03 +0000 |
commit | f54aa39428e7100a331a1364664262f8b36d7082 (patch) | |
tree | a0bbf4b0b1589f4dbe7608c9ebbfb3dcc815cd7d /src/modules | |
parent | b4a34260192496f1adbf042575dbd13d28079129 (diff) |
Beginnings of postdata stuff
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5240 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/httpd.h | 10 | ||||
-rw-r--r-- | src/modules/m_httpd.cpp | 59 | ||||
-rw-r--r-- | src/modules/m_httpd_stats.cpp | 3 |
3 files changed, 44 insertions, 28 deletions
diff --git a/src/modules/httpd.h b/src/modules/httpd.h index 565648659..7738e3fe4 100644 --- a/src/modules/httpd.h +++ b/src/modules/httpd.h @@ -17,6 +17,7 @@ class HTTPRequest : public classbase std::string type; std::string document; std::string ipaddr; + std::string postdata; std::stringstream* headers; public: @@ -34,8 +35,8 @@ class HTTPRequest : public classbase * @param opaque An opaque pointer used internally by m_httpd, which you must pass back to the module in your reply. * @param ip The IP address making the web request. */ - HTTPRequest(const std::string &request_type, const std::string &uri, std::stringstream* hdr, void* opaque, const std::string &ip) - : type(request_type), document(uri), ipaddr(ip), headers(hdr), sock(opaque) + HTTPRequest(const std::string &request_type, const std::string &uri, std::stringstream* hdr, void* opaque, const std::string &ip, const std::string &pdata) + : type(request_type), document(uri), ipaddr(ip), postdata(pdata), headers(hdr), sock(opaque) { } @@ -48,6 +49,11 @@ class HTTPRequest : public classbase return headers; } + std::string& GetPostData() + { + return postdata; + } + /** Get the request type. * Any request type can be intercepted, even ones which are invalid in the HTTP/1.1 spec. * @return The request type, e.g. GET, POST, HEAD diff --git a/src/modules/m_httpd.cpp b/src/modules/m_httpd.cpp index b1dc7b610..fab4e19dd 100644 --- a/src/modules/m_httpd.cpp +++ b/src/modules/m_httpd.cpp @@ -21,7 +21,6 @@ using namespace std; #include "channels.h" #include "modules.h" #include "inspsocket.h" - #include "inspircd.h" #include "httpd.h" @@ -29,8 +28,6 @@ using namespace std; class ModuleHttp; - - static ModuleHttp* HttpModule; static bool claimed; @@ -38,7 +35,8 @@ enum HttpState { HTTP_LISTEN = 0, HTTP_SERVE_WAIT_REQUEST = 1, - HTTP_SERVE_SEND_DATA = 2 + HTTP_SERVE_RECV_POSTDATA = 2, + HTTP_SERVE_SEND_DATA = 3 }; class HttpSocket : public InspSocket @@ -46,6 +44,10 @@ class HttpSocket : public InspSocket FileReader* index; HttpState InternalState; std::stringstream headers; + std::string postdata; + std::string request_type; + std::string uri; + std::string http_version; public: @@ -186,9 +188,6 @@ class HttpSocket : public InspSocket virtual bool OnDataReady() { char* data = this->Read(); - std::string request_type; - std::string uri; - std::string http_version; /* Check that the data read is a valid pointer and it has some content */ if (data && *data) @@ -197,35 +196,49 @@ class HttpSocket : public InspSocket if (headers.str().find("\r\n\r\n") != std::string::npos) { - /* Headers are complete */ - InternalState = HTTP_SERVE_SEND_DATA; - headers >> request_type; headers >> uri; headers >> http_version; - if ((http_version != "HTTP/1.1") && (http_version != "HTTP/1.0")) + if ((InternalState == HTTP_SERVE_WAIT_REQUEST) && (request_type == "POST")) + { + /* Do we need to fetch postdata? */ + postdata = ""; + InternalState = HTTP_SERVE_RECV_POSTDATA; + /* TODO: Get content length and store */ + } + else if (InternalState == HTTP_SERVE_RECV_POSTDATA) { - SendHeaders(0, 505, ""); + /* Add postdata, once we have it all, send the event */ } else { - if ((request_type == "GET") && (uri == "/")) + /* Headers are complete */ + InternalState = HTTP_SERVE_SEND_DATA; + + if ((http_version != "HTTP/1.1") && (http_version != "HTTP/1.0")) { - SendHeaders(index->ContentSize(), 200, ""); - this->Write(index->Contents()); + SendHeaders(0, 505, ""); } else { - claimed = false; - HTTPRequest httpr(request_type,uri,&headers,this,this->GetIP()); - Event e((char*)&httpr, (Module*)HttpModule, "httpd_url"); - e.Send(this->Instance); - - if (!claimed) + if ((request_type == "GET") && (uri == "/")) { - SendHeaders(0, 404, ""); - Instance->Log(DEBUG,"Page not claimed, 404"); + SendHeaders(index->ContentSize(), 200, ""); + this->Write(index->Contents()); + } + else + { + claimed = false; + HTTPRequest httpr(request_type,uri,&headers,this,this->GetIP(),postdata); + Event e((char*)&httpr, (Module*)HttpModule, "httpd_url"); + e.Send(this->Instance); + + if (!claimed) + { + SendHeaders(0, 404, ""); + Instance->Log(DEBUG,"Page not claimed, 404"); + } } } } diff --git a/src/modules/m_httpd_stats.cpp b/src/modules/m_httpd_stats.cpp index 3343e20e9..24b5f7f91 100644 --- a/src/modules/m_httpd_stats.cpp +++ b/src/modules/m_httpd_stats.cpp @@ -22,14 +22,11 @@ using namespace std; #include "configreader.h" #include "modules.h" #include "inspsocket.h" - #include "httpd.h" #include "inspircd.h" /* $ModDesc: Provides statistics over HTTP via m_httpd.so */ - - typedef std::map<irc::string,int> StatsHash; typedef StatsHash::iterator StatsIter; |