From fea556ca1b8aeec975f5276d5d829ee6275841d9 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 3 Jan 2016 15:59:55 +0100 Subject: Renamed HTTPServer folder to HTTP. It contains client code as well. --- src/HTTP/HTTPServer.h | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 src/HTTP/HTTPServer.h (limited to 'src/HTTP/HTTPServer.h') diff --git a/src/HTTP/HTTPServer.h b/src/HTTP/HTTPServer.h new file mode 100644 index 000000000..15202a50e --- /dev/null +++ b/src/HTTP/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/Network.h" +#include "../IniFile.h" +#include "PolarSSL++/RsaPrivateKey.h" +#include "PolarSSL++/CryptoKey.h" +#include "PolarSSL++/X509Cert.h" + + + + + +// fwd: +class cHTTPMessage; +class cHTTPRequestParser; +class cHTTPResponse; +class cHTTPServerConnection; + + + + + + +class cHTTPServer +{ +public: + class cCallbacks + { + public: + virtual ~cCallbacks() {} + + /** Called when a new request arrives over a connection and all its headers have been parsed. + The request body needn't have arrived yet. */ + virtual void OnRequestBegun(cHTTPServerConnection & a_Connection, cHTTPRequestParser & a_Request) = 0; + + /** Called when another part of request body has arrived. + May be called multiple times for a single request. */ + virtual void OnRequestBody(cHTTPServerConnection & a_Connection, cHTTPRequestParser & a_Request, const char * a_Data, size_t a_Size) = 0; + + /** Called when the request body has been fully received in previous calls to OnRequestBody() */ + virtual void OnRequestFinished(cHTTPServerConnection & a_Connection, cHTTPRequestParser & a_Request) = 0; + } ; + + cHTTPServer(void); + virtual ~cHTTPServer(); + + /** Initializes the server - reads the cert files etc. */ + bool Initialize(void); + + /** Starts the server and assigns the callbacks to use for incoming requests */ + bool Start(cCallbacks & a_Callbacks, const AStringVector & a_Ports); + + /** Stops the server, drops all current connections */ + void Stop(void); + +protected: + friend class cHTTPServerConnection; + friend class cSslHTTPServerConnection; + friend class cHTTPServerListenCallbacks; + + /** The cNetwork API handle for the listening socket. */ + cServerHandlePtrs m_ServerHandles; + + /** The callbacks to call for various events */ + cCallbacks * m_Callbacks; + + /** The server certificate to use for the SSL connections */ + cX509CertPtr m_Cert; + + /** The private key for m_Cert. */ + cCryptoKeyPtr m_CertPrivKey; + + + /** Called by cHTTPServerListenCallbacks when there's a new incoming connection. + Returns the connection instance to be used as the cTCPLink callbacks. */ + cTCPLink::cCallbacksPtr OnIncomingConnection(const AString & a_RemoteIPAddress, UInt16 a_RemotePort); + + /** Called by cHTTPServerConnection when it finishes parsing the request header */ + void NewRequest(cHTTPServerConnection & a_Connection, cHTTPRequestParser & a_Request); + + /** Called by cHTTPConenction when it receives more data for the request body. + May be called multiple times for a single request. */ + void RequestBody(cHTTPServerConnection & a_Connection, cHTTPRequestParser & a_Request, const char * a_Data, size_t a_Size); + + /** Called by cHTTPServerConnection when it detects that the request has finished (all of its body has been received) */ + void RequestFinished(cHTTPServerConnection & a_Connection, cHTTPRequestParser & a_Request); +} ; + + + + + -- cgit v1.2.3 From 52d18b4559cbaca949f722aa6901a6eb5f505f02 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sat, 20 Feb 2016 11:50:52 +0100 Subject: WebAdmin uses the new HTTP parser framework. --- src/HTTP/HTTPServer.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/HTTP/HTTPServer.h') diff --git a/src/HTTP/HTTPServer.h b/src/HTTP/HTTPServer.h index 15202a50e..d06e13cac 100644 --- a/src/HTTP/HTTPServer.h +++ b/src/HTTP/HTTPServer.h @@ -22,6 +22,7 @@ // fwd: class cHTTPMessage; class cHTTPRequestParser; +class cHTTPIncomingRequest; class cHTTPResponse; class cHTTPServerConnection; @@ -40,14 +41,14 @@ public: /** Called when a new request arrives over a connection and all its headers have been parsed. The request body needn't have arrived yet. */ - virtual void OnRequestBegun(cHTTPServerConnection & a_Connection, cHTTPRequestParser & a_Request) = 0; + virtual void OnRequestBegun(cHTTPServerConnection & a_Connection, cHTTPIncomingRequest & a_Request) = 0; /** Called when another part of request body has arrived. May be called multiple times for a single request. */ - virtual void OnRequestBody(cHTTPServerConnection & a_Connection, cHTTPRequestParser & a_Request, const char * a_Data, size_t a_Size) = 0; + virtual void OnRequestBody(cHTTPServerConnection & a_Connection, cHTTPIncomingRequest & a_Request, const char * a_Data, size_t a_Size) = 0; /** Called when the request body has been fully received in previous calls to OnRequestBody() */ - virtual void OnRequestFinished(cHTTPServerConnection & a_Connection, cHTTPRequestParser & a_Request) = 0; + virtual void OnRequestFinished(cHTTPServerConnection & a_Connection, cHTTPIncomingRequest & a_Request) = 0; } ; cHTTPServer(void); @@ -85,14 +86,14 @@ protected: cTCPLink::cCallbacksPtr OnIncomingConnection(const AString & a_RemoteIPAddress, UInt16 a_RemotePort); /** Called by cHTTPServerConnection when it finishes parsing the request header */ - void NewRequest(cHTTPServerConnection & a_Connection, cHTTPRequestParser & a_Request); + void NewRequest(cHTTPServerConnection & a_Connection, cHTTPIncomingRequest & a_Request); /** Called by cHTTPConenction when it receives more data for the request body. May be called multiple times for a single request. */ - void RequestBody(cHTTPServerConnection & a_Connection, cHTTPRequestParser & a_Request, const char * a_Data, size_t a_Size); + void RequestBody(cHTTPServerConnection & a_Connection, cHTTPIncomingRequest & a_Request, const void * a_Data, size_t a_Size); /** Called by cHTTPServerConnection when it detects that the request has finished (all of its body has been received) */ - void RequestFinished(cHTTPServerConnection & a_Connection, cHTTPRequestParser & a_Request); + void RequestFinished(cHTTPServerConnection & a_Connection, cHTTPIncomingRequest & a_Request); } ; -- cgit v1.2.3 From 71a1fa81f00cf897d91e8f76cc7e646dd61cc2ff Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sat, 20 Feb 2016 12:33:27 +0100 Subject: Renamed HTTPResponse to HTTPOutgoingResponse. --- src/HTTP/HTTPServer.h | 1 - 1 file changed, 1 deletion(-) (limited to 'src/HTTP/HTTPServer.h') diff --git a/src/HTTP/HTTPServer.h b/src/HTTP/HTTPServer.h index d06e13cac..1de0a6ce9 100644 --- a/src/HTTP/HTTPServer.h +++ b/src/HTTP/HTTPServer.h @@ -23,7 +23,6 @@ class cHTTPMessage; class cHTTPRequestParser; class cHTTPIncomingRequest; -class cHTTPResponse; class cHTTPServerConnection; -- cgit v1.2.3