From 0f66106f8c6581ff47249b5ea9dde4157a395263 Mon Sep 17 00:00:00 2001 From: brain Date: Thu, 14 Sep 2006 11:35:43 +0000 Subject: Fix postdata stuff git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5245 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/m_httpd.cpp | 95 +++++++++++++++++++++---------------------------- 1 file changed, 40 insertions(+), 55 deletions(-) (limited to 'src/modules/m_httpd.cpp') diff --git a/src/modules/m_httpd.cpp b/src/modules/m_httpd.cpp index 276bc915f..e7b100b05 100644 --- a/src/modules/m_httpd.cpp +++ b/src/modules/m_httpd.cpp @@ -48,8 +48,8 @@ class HttpSocket : public InspSocket std::string request_type; std::string uri; std::string http_version; - int postsize; - int amount; + unsigned int postsize; + unsigned int amount; public: @@ -221,7 +221,11 @@ class HttpSocket : public InspSocket } } Instance->Log(DEBUG,"%d bytes to read for POST",postsize); + std::string::size_type x = headers.str().find("\r\n\r\n"); + postdata = headers.str().substr(x+5, headers.str().length()); /* Get content length and store */ + if (postdata.length() >= postsize) + ServeData(); } else if (InternalState == HTTP_SERVE_RECV_POSTDATA) { @@ -230,73 +234,54 @@ class HttpSocket : public InspSocket postdata.append(data); if (amount >= postsize) { - InternalState = HTTP_SERVE_SEND_DATA; - - if ((http_version != "HTTP/1.1") && (http_version != "HTTP/1.0")) - { - SendHeaders(0, 505, ""); - } - 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"); - } - - } + ServeData(); } } else { - /* Headers are complete */ - InternalState = HTTP_SERVE_SEND_DATA; - - if ((http_version != "HTTP/1.1") && (http_version != "HTTP/1.0")) - { - SendHeaders(0, 505, ""); - } - else - { - if ((request_type == "GET") && (uri == "/")) - { - 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"); - } - } - } + ServeData(); } - - return false; + return true; } return true; } else { - /* Bastard client closed the socket on us! - * Oh wait, theyre SUPPOSED to do that! - */ return false; } } + void ServeData() + { + /* Headers are complete */ + InternalState = HTTP_SERVE_SEND_DATA; + + if ((http_version != "HTTP/1.1") && (http_version != "HTTP/1.0")) + { + SendHeaders(0, 505, ""); + } + else + { + if ((request_type == "GET") && (uri == "/")) + { + 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"); + } + } + } + } + void Page(std::stringstream* n, int response, std::string& extraheaders) { Instance->Log(DEBUG,"Sending page"); -- cgit v1.2.3