summaryrefslogtreecommitdiffstats
path: root/source/HTTPServer/HTTPServer.cpp
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-09-27 21:28:41 +0200
committermadmaxoft <github@xoft.cz>2013-09-27 21:28:41 +0200
commit5cf8fc12ae000cd2d2b54a2bf158f82bdb8a0e67 (patch)
tree9c1f8b1f21555751b6a5886cf32a492a1e504c85 /source/HTTPServer/HTTPServer.cpp
parentFixed leaking HTTPRequest objects (diff)
downloadcuberite-5cf8fc12ae000cd2d2b54a2bf158f82bdb8a0e67.tar
cuberite-5cf8fc12ae000cd2d2b54a2bf158f82bdb8a0e67.tar.gz
cuberite-5cf8fc12ae000cd2d2b54a2bf158f82bdb8a0e67.tar.bz2
cuberite-5cf8fc12ae000cd2d2b54a2bf158f82bdb8a0e67.tar.lz
cuberite-5cf8fc12ae000cd2d2b54a2bf158f82bdb8a0e67.tar.xz
cuberite-5cf8fc12ae000cd2d2b54a2bf158f82bdb8a0e67.tar.zst
cuberite-5cf8fc12ae000cd2d2b54a2bf158f82bdb8a0e67.zip
Diffstat (limited to '')
-rw-r--r--source/HTTPServer/HTTPServer.cpp80
1 files changed, 69 insertions, 11 deletions
diff --git a/source/HTTPServer/HTTPServer.cpp b/source/HTTPServer/HTTPServer.cpp
index d518df10d..8494d6fce 100644
--- a/source/HTTPServer/HTTPServer.cpp
+++ b/source/HTTPServer/HTTPServer.cpp
@@ -22,10 +22,43 @@
+class cDebugCallbacks :
+ public cHTTPServer::cCallbacks
+{
+ virtual void OnRequestBegun(cHTTPConnection & a_Connection, cHTTPRequest & a_Request) override
+ {
+ // Nothing needed
+ }
+
+
+ virtual void OnRequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, int a_Size) override
+ {
+ // TODO
+ }
+
+
+ virtual void OnRequestFinished(cHTTPConnection & a_Connection, cHTTPRequest & a_Request) override
+ {
+ cHTTPResponse Resp;
+ Resp.SetContentType("text/plain");
+ a_Connection.Send(Resp);
+ a_Connection.Send("Hello, world");
+ }
+
+
+} g_DebugCallbacks;
+
+
+
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// cHTTPServer:
+
cHTTPServer::cHTTPServer(void) :
m_ListenThreadIPv4(*this, cSocket::IPv4, "WebServer IPv4"),
m_ListenThreadIPv6(*this, cSocket::IPv6, "WebServer IPv6"),
- m_SocketThreads()
+ m_Callbacks(NULL)
{
}
@@ -48,6 +81,20 @@ bool cHTTPServer::Initialize(cIniFile & a_IniFile)
LOG("WebAdmin is disabled");
return false;
}
+
+ // DEBUG:
+ return Start(g_DebugCallbacks);
+
+ return true;
+}
+
+
+
+
+
+bool cHTTPServer::Start(cCallbacks & a_Callbacks)
+{
+ m_Callbacks = &a_Callbacks;
if (!m_ListenThreadIPv4.Start())
{
return false;
@@ -64,6 +111,23 @@ bool cHTTPServer::Initialize(cIniFile & a_IniFile)
+void cHTTPServer::Stop(void)
+{
+ m_ListenThreadIPv4.Stop();
+ m_ListenThreadIPv6.Stop();
+
+ // Drop all current connections:
+ cCSLock Lock(m_CSConnections);
+ for (cHTTPConnections::iterator itr = m_Connections.begin(), end = m_Connections.end(); itr != end; ++itr)
+ {
+ m_SocketThreads.RemoveClient(*itr);
+ } // for itr - m_Connections[]
+}
+
+
+
+
+
void cHTTPServer::OnConnectionAccepted(cSocket & a_Socket)
{
cHTTPConnection * Connection = new cHTTPConnection(*this);
@@ -105,7 +169,7 @@ void cHTTPServer::NotifyConnectionWrite(cHTTPConnection & a_Connection)
void cHTTPServer::NewRequest(cHTTPConnection & a_Connection, cHTTPRequest & a_Request)
{
- // TODO
+ m_Callbacks->OnRequestBegun(a_Connection, a_Request);
}
@@ -114,7 +178,7 @@ void cHTTPServer::NewRequest(cHTTPConnection & a_Connection, cHTTPRequest & a_Re
void cHTTPServer::RequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, int a_Size)
{
- // TODO
+ m_Callbacks->OnRequestBody(a_Connection, a_Request, a_Data, a_Size);
}
@@ -123,14 +187,8 @@ void cHTTPServer::RequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_R
void cHTTPServer::RequestFinished(cHTTPConnection & a_Connection, cHTTPRequest & a_Request)
{
- // TODO
-
- // DEBUG: Send a debug response:
- cHTTPResponse Resp;
- Resp.SetContentType("text/plain");
- a_Connection.Send(Resp);
- a_Connection.Send("Hello");
- a_Connection.FinishResponse();
+ m_Callbacks->OnRequestFinished(a_Connection, a_Request);
+ a_Connection.AwaitNextRequest();
}