summaryrefslogtreecommitdiffstats
path: root/src/HTTP/HTTPServer.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2016-02-20 11:50:52 +0100
committerMattes D <github@xoft.cz>2016-03-01 16:19:58 +0100
commit52d18b4559cbaca949f722aa6901a6eb5f505f02 (patch)
tree614a441217b9ebcef17eb62e042223da1413b4aa /src/HTTP/HTTPServer.cpp
parentHTTP: Fixed response parser, unified API. (diff)
downloadcuberite-52d18b4559cbaca949f722aa6901a6eb5f505f02.tar
cuberite-52d18b4559cbaca949f722aa6901a6eb5f505f02.tar.gz
cuberite-52d18b4559cbaca949f722aa6901a6eb5f505f02.tar.bz2
cuberite-52d18b4559cbaca949f722aa6901a6eb5f505f02.tar.lz
cuberite-52d18b4559cbaca949f722aa6901a6eb5f505f02.tar.xz
cuberite-52d18b4559cbaca949f722aa6901a6eb5f505f02.tar.zst
cuberite-52d18b4559cbaca949f722aa6901a6eb5f505f02.zip
Diffstat (limited to '')
-rw-r--r--src/HTTP/HTTPServer.cpp107
1 files changed, 5 insertions, 102 deletions
diff --git a/src/HTTP/HTTPServer.cpp b/src/HTTP/HTTPServer.cpp
index 741f5f1c5..5a5bee045 100644
--- a/src/HTTP/HTTPServer.cpp
+++ b/src/HTTP/HTTPServer.cpp
@@ -5,7 +5,7 @@
#include "Globals.h"
#include "HTTPServer.h"
-#include "HTTPRequestParser.h"
+#include "HTTPMessageParser.h"
#include "HTTPServerConnection.h"
#include "HTTPFormParser.h"
#include "SslHTTPServerConnection.h"
@@ -24,102 +24,6 @@
-class cDebugCallbacks :
- public cHTTPServer::cCallbacks,
- protected cHTTPFormParser::cCallbacks
-{
- virtual void OnRequestBegun(cHTTPServerConnection & a_Connection, cHTTPRequestParser & a_Request) override
- {
- UNUSED(a_Connection);
-
- if (cHTTPFormParser::HasFormData(a_Request))
- {
- a_Request.SetUserData(new cHTTPFormParser(a_Request, *this));
- }
- }
-
-
- virtual void OnRequestBody(cHTTPServerConnection & a_Connection, cHTTPRequestParser & a_Request, const char * a_Data, size_t a_Size) override
- {
- UNUSED(a_Connection);
-
- cHTTPFormParser * FormParser = reinterpret_cast<cHTTPFormParser *>(a_Request.GetUserData());
- if (FormParser != nullptr)
- {
- FormParser->Parse(a_Data, a_Size);
- }
- }
-
-
- virtual void OnRequestFinished(cHTTPServerConnection & a_Connection, cHTTPRequestParser & a_Request) override
- {
- cHTTPFormParser * FormParser = reinterpret_cast<cHTTPFormParser *>(a_Request.GetUserData());
- if (FormParser != nullptr)
- {
- if (FormParser->Finish())
- {
- cHTTPResponse Resp;
- Resp.SetContentType("text/html");
- a_Connection.Send(Resp);
- a_Connection.Send("<html><body><table border=1 cellspacing=0><tr><th>Name</th><th>Value</th></tr>\r\n");
- for (cHTTPFormParser::iterator itr = FormParser->begin(), end = FormParser->end(); itr != end; ++itr)
- {
- a_Connection.Send(Printf("<tr><td valign=\"top\"><pre>%s</pre></td><td valign=\"top\"><pre>%s</pre></td></tr>\r\n", itr->first.c_str(), itr->second.c_str()));
- } // for itr - FormParser[]
- a_Connection.Send("</table></body></html>");
- return;
- }
-
- // Parsing failed:
- cHTTPResponse Resp;
- Resp.SetContentType("text/plain");
- a_Connection.Send(Resp);
- a_Connection.Send("Form parsing failed");
- return;
- }
-
- // Test the auth failure and success:
- if (a_Request.GetURL() == "/auth")
- {
- if (!a_Request.HasAuth() || (a_Request.GetAuthUsername() != "a") || (a_Request.GetAuthPassword() != "b"))
- {
- a_Connection.SendNeedAuth("Cuberite WebAdmin");
- return;
- }
- }
-
- cHTTPResponse Resp;
- Resp.SetContentType("text/plain");
- a_Connection.Send(Resp);
- a_Connection.Send("Hello, world");
- }
-
-
- virtual void OnFileStart(cHTTPFormParser & a_Parser, const AString & a_FileName) override
- {
- // TODO
- }
-
-
- virtual void OnFileData(cHTTPFormParser & a_Parser, const char * a_Data, size_t a_Size) override
- {
- // TODO
- }
-
-
- virtual void OnFileEnd(cHTTPFormParser & a_Parser) override
- {
- // TODO
- }
-
-};
-
-static cDebugCallbacks g_DebugCallbacks;
-
-
-
-
-
////////////////////////////////////////////////////////////////////////////////
// cHTTPServerListenCallbacks:
@@ -280,7 +184,7 @@ cTCPLink::cCallbacksPtr cHTTPServer::OnIncomingConnection(const AString & a_Remo
-void cHTTPServer::NewRequest(cHTTPServerConnection & a_Connection, cHTTPRequestParser & a_Request)
+void cHTTPServer::NewRequest(cHTTPServerConnection & a_Connection, cHTTPIncomingRequest & a_Request)
{
m_Callbacks->OnRequestBegun(a_Connection, a_Request);
}
@@ -289,19 +193,18 @@ void cHTTPServer::NewRequest(cHTTPServerConnection & a_Connection, cHTTPRequestP
-void cHTTPServer::RequestBody(cHTTPServerConnection & a_Connection, cHTTPRequestParser & a_Request, const char * a_Data, size_t a_Size)
+void cHTTPServer::RequestBody(cHTTPServerConnection & a_Connection, cHTTPIncomingRequest & a_Request, const void * a_Data, size_t a_Size)
{
- m_Callbacks->OnRequestBody(a_Connection, a_Request, a_Data, a_Size);
+ m_Callbacks->OnRequestBody(a_Connection, a_Request, reinterpret_cast<const char *>(a_Data), a_Size);
}
-void cHTTPServer::RequestFinished(cHTTPServerConnection & a_Connection, cHTTPRequestParser & a_Request)
+void cHTTPServer::RequestFinished(cHTTPServerConnection & a_Connection, cHTTPIncomingRequest & a_Request)
{
m_Callbacks->OnRequestFinished(a_Connection, a_Request);
- a_Connection.AwaitNextRequest();
}