diff options
Diffstat (limited to '')
-rw-r--r-- | src/HTTPServer/EnvelopeParser.cpp (renamed from source/HTTPServer/EnvelopeParser.cpp) | 0 | ||||
-rw-r--r-- | src/HTTPServer/EnvelopeParser.h (renamed from source/HTTPServer/EnvelopeParser.h) | 0 | ||||
-rw-r--r-- | src/HTTPServer/HTTPConnection.cpp (renamed from source/HTTPServer/HTTPConnection.cpp) | 0 | ||||
-rw-r--r-- | src/HTTPServer/HTTPConnection.h (renamed from source/HTTPServer/HTTPConnection.h) | 0 | ||||
-rw-r--r-- | src/HTTPServer/HTTPFormParser.cpp (renamed from source/HTTPServer/HTTPFormParser.cpp) | 0 | ||||
-rw-r--r-- | src/HTTPServer/HTTPFormParser.h (renamed from source/HTTPServer/HTTPFormParser.h) | 0 | ||||
-rw-r--r-- | src/HTTPServer/HTTPMessage.cpp (renamed from source/HTTPServer/HTTPMessage.cpp) | 0 | ||||
-rw-r--r-- | src/HTTPServer/HTTPMessage.h (renamed from source/HTTPServer/HTTPMessage.h) | 0 | ||||
-rw-r--r-- | src/HTTPServer/HTTPServer.cpp (renamed from source/HTTPServer/HTTPServer.cpp) | 0 | ||||
-rw-r--r-- | src/HTTPServer/HTTPServer.h | 101 | ||||
-rw-r--r-- | src/HTTPServer/MultipartParser.cpp (renamed from source/HTTPServer/MultipartParser.cpp) | 0 | ||||
-rw-r--r-- | src/HTTPServer/MultipartParser.h (renamed from source/HTTPServer/MultipartParser.h) | 0 | ||||
-rw-r--r-- | src/HTTPServer/NameValueParser.cpp (renamed from source/HTTPServer/NameValueParser.cpp) | 0 | ||||
-rw-r--r-- | src/HTTPServer/NameValueParser.h (renamed from source/HTTPServer/NameValueParser.h) | 0 |
14 files changed, 101 insertions, 0 deletions
diff --git a/source/HTTPServer/EnvelopeParser.cpp b/src/HTTPServer/EnvelopeParser.cpp index 8dbe05f14..8dbe05f14 100644 --- a/source/HTTPServer/EnvelopeParser.cpp +++ b/src/HTTPServer/EnvelopeParser.cpp diff --git a/source/HTTPServer/EnvelopeParser.h b/src/HTTPServer/EnvelopeParser.h index 6430fbebf..6430fbebf 100644 --- a/source/HTTPServer/EnvelopeParser.h +++ b/src/HTTPServer/EnvelopeParser.h diff --git a/source/HTTPServer/HTTPConnection.cpp b/src/HTTPServer/HTTPConnection.cpp index 68afdfc11..68afdfc11 100644 --- a/source/HTTPServer/HTTPConnection.cpp +++ b/src/HTTPServer/HTTPConnection.cpp diff --git a/source/HTTPServer/HTTPConnection.h b/src/HTTPServer/HTTPConnection.h index 14603bb70..14603bb70 100644 --- a/source/HTTPServer/HTTPConnection.h +++ b/src/HTTPServer/HTTPConnection.h diff --git a/source/HTTPServer/HTTPFormParser.cpp b/src/HTTPServer/HTTPFormParser.cpp index 596db424e..596db424e 100644 --- a/source/HTTPServer/HTTPFormParser.cpp +++ b/src/HTTPServer/HTTPFormParser.cpp diff --git a/source/HTTPServer/HTTPFormParser.h b/src/HTTPServer/HTTPFormParser.h index a554ca5a4..a554ca5a4 100644 --- a/source/HTTPServer/HTTPFormParser.h +++ b/src/HTTPServer/HTTPFormParser.h diff --git a/source/HTTPServer/HTTPMessage.cpp b/src/HTTPServer/HTTPMessage.cpp index ab23866e6..ab23866e6 100644 --- a/source/HTTPServer/HTTPMessage.cpp +++ b/src/HTTPServer/HTTPMessage.cpp diff --git a/source/HTTPServer/HTTPMessage.h b/src/HTTPServer/HTTPMessage.h index f5284c535..f5284c535 100644 --- a/source/HTTPServer/HTTPMessage.h +++ b/src/HTTPServer/HTTPMessage.h diff --git a/source/HTTPServer/HTTPServer.cpp b/src/HTTPServer/HTTPServer.cpp index f6f5b0f8b..f6f5b0f8b 100644 --- a/source/HTTPServer/HTTPServer.cpp +++ b/src/HTTPServer/HTTPServer.cpp diff --git a/src/HTTPServer/HTTPServer.h b/src/HTTPServer/HTTPServer.h new file mode 100644 index 000000000..24baf8c95 --- /dev/null +++ b/src/HTTPServer/HTTPServer.h @@ -0,0 +1,101 @@ + +// HTTPServer.h + +// Declares the cHTTPServer class representing a HTTP webserver that uses cListenThread and cSocketThreads for processing + + + + + +#pragma once + +#include "../OSSupport/ListenThread.h" +#include "../OSSupport/SocketThreads.h" +#include "inifile/iniFile.h" + + + + + +// fwd: +class cHTTPMessage; +class cHTTPRequest; +class cHTTPResponse; +class cHTTPConnection; + +typedef std::vector<cHTTPConnection *> cHTTPConnections; + + + + + + +class cHTTPServer : + public cListenThread::cCallback +{ +public: + class cCallbacks + { + public: + /** Called when a new request arrives over a connection and its headers have been parsed. + The request body needn't have arrived yet. + */ + virtual void OnRequestBegun(cHTTPConnection & a_Connection, cHTTPRequest & a_Request) = 0; + + /// Called when another part of request body has arrived. + virtual void OnRequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, int a_Size) = 0; + + /// Called when the request body has been fully received in previous calls to OnRequestBody() + virtual void OnRequestFinished(cHTTPConnection & a_Connection, cHTTPRequest & a_Request) = 0; + } ; + + cHTTPServer(void); + ~cHTTPServer(); + + /// Initializes the server on the specified ports + bool Initialize(const AString & a_PortsIPv4, const AString & a_PortsIPv6); + + /// Starts the server and assigns the callbacks to use for incoming requests + bool Start(cCallbacks & a_Callbacks); + + /// Stops the server, drops all current connections + void Stop(void); + +protected: + friend class cHTTPConnection; + + cListenThread m_ListenThreadIPv4; + cListenThread m_ListenThreadIPv6; + + cSocketThreads m_SocketThreads; + + cCriticalSection m_CSConnections; + cHTTPConnections m_Connections; ///< All the connections that are currently being serviced + + /// The callbacks to call for various events + cCallbacks * m_Callbacks; + + + // cListenThread::cCallback overrides: + virtual void OnConnectionAccepted(cSocket & a_Socket) override; + + /// Called by cHTTPConnection to close the connection (presumably due to an error) + void CloseConnection(cHTTPConnection & a_Connection); + + /// Called by cHTTPConnection to notify SocketThreads that there's data to be sent for the connection + void NotifyConnectionWrite(cHTTPConnection & a_Connection); + + /// Called by cHTTPConnection when it finishes parsing the request header + void NewRequest(cHTTPConnection & a_Connection, cHTTPRequest & a_Request); + + /// Called by cHTTPConenction when it receives more data for the request body + void RequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, int a_Size); + + /// Called by cHTTPConnection when it detects that the request has finished (all of its body has been received) + void RequestFinished(cHTTPConnection & a_Connection, cHTTPRequest & a_Request); +} ; + + + + + diff --git a/source/HTTPServer/MultipartParser.cpp b/src/HTTPServer/MultipartParser.cpp index b49f6ec07..b49f6ec07 100644 --- a/source/HTTPServer/MultipartParser.cpp +++ b/src/HTTPServer/MultipartParser.cpp diff --git a/source/HTTPServer/MultipartParser.h b/src/HTTPServer/MultipartParser.h index d853929ed..d853929ed 100644 --- a/source/HTTPServer/MultipartParser.h +++ b/src/HTTPServer/MultipartParser.h diff --git a/source/HTTPServer/NameValueParser.cpp b/src/HTTPServer/NameValueParser.cpp index a27f07d19..a27f07d19 100644 --- a/source/HTTPServer/NameValueParser.cpp +++ b/src/HTTPServer/NameValueParser.cpp diff --git a/source/HTTPServer/NameValueParser.h b/src/HTTPServer/NameValueParser.h index 07dc0b942..07dc0b942 100644 --- a/source/HTTPServer/NameValueParser.h +++ b/src/HTTPServer/NameValueParser.h |