Cuberite
A lightweight, fast and extensible game server for Minecraft
HTTPServer.h
Go to the documentation of this file.
1 
2 // HTTPServer.h
3 
4 // Declares the cHTTPServer class representing a HTTP webserver that uses cListenThread and cSocketThreads for processing
5 
6 
7 
8 
9 
10 #pragma once
11 
12 #include "../OSSupport/Network.h"
13 #include "../IniFile.h"
14 #include "../mbedTLS++/CryptoKey.h"
15 #include "../mbedTLS++/X509Cert.h"
16 
17 
18 
19 
20 
21 // fwd:
24 class cSslConfig;
25 
26 
27 
28 
29 
31 {
32 public:
33  class cCallbacks
34  {
35  public:
36  virtual ~cCallbacks() {}
37 
40  virtual void OnRequestBegun(cHTTPServerConnection & a_Connection, cHTTPIncomingRequest & a_Request) = 0;
41 
44  virtual void OnRequestBody(cHTTPServerConnection & a_Connection, cHTTPIncomingRequest & a_Request, const char * a_Data, size_t a_Size) = 0;
45 
47  virtual void OnRequestFinished(cHTTPServerConnection & a_Connection, cHTTPIncomingRequest & a_Request) = 0;
48  } ;
49 
50  cHTTPServer(void);
51  virtual ~cHTTPServer();
52 
54  bool Initialize(void);
55 
57  bool Start(cCallbacks & a_Callbacks, const AStringVector & a_Ports);
58 
60  void Stop(void);
61 
62 protected:
63  friend class cHTTPServerConnection;
66 
69 
72 
74  std::shared_ptr<const cSslConfig> m_SslConfig;
75 
76 
79  cTCPLink::cCallbacksPtr OnIncomingConnection(const AString & a_RemoteIPAddress, UInt16 a_RemotePort);
80 
82  void NewRequest(cHTTPServerConnection & a_Connection, cHTTPIncomingRequest & a_Request);
83 
86  void RequestBody(cHTTPServerConnection & a_Connection, cHTTPIncomingRequest & a_Request, const void * a_Data, size_t a_Size);
87 
89  void RequestFinished(cHTTPServerConnection & a_Connection, cHTTPIncomingRequest & a_Request);
90 } ;
91 
92 
93 
94 
95 
unsigned short UInt16
Definition: Globals.h:158
std::vector< cServerHandlePtr > cServerHandlePtrs
Definition: Network.h:30
std::vector< AString > AStringVector
Definition: StringUtils.h:12
std::string AString
Definition: StringUtils.h:11
Provides storage for an incoming HTTP request.
Definition: HTTPMessage.h:90
cCallbacks * m_Callbacks
The callbacks to call for various events.
Definition: HTTPServer.h:71
bool Initialize(void)
Initializes the server - reads the cert files etc.
Definition: HTTPServer.cpp:85
void NewRequest(cHTTPServerConnection &a_Connection, cHTTPIncomingRequest &a_Request)
Called by cHTTPServerConnection when it finishes parsing the request header.
Definition: HTTPServer.cpp:208
void RequestBody(cHTTPServerConnection &a_Connection, cHTTPIncomingRequest &a_Request, const void *a_Data, size_t a_Size)
Called by cHTTPConenction when it receives more data for the request body.
Definition: HTTPServer.cpp:217
cServerHandlePtrs m_ServerHandles
The cNetwork API handle for the listening socket.
Definition: HTTPServer.h:68
cTCPLink::cCallbacksPtr OnIncomingConnection(const AString &a_RemoteIPAddress, UInt16 a_RemotePort)
Called by cHTTPServerListenCallbacks when there's a new incoming connection.
Definition: HTTPServer.cpp:189
void Stop(void)
Stops the server, drops all current connections.
Definition: HTTPServer.cpp:176
cHTTPServer(void)
Definition: HTTPServer.cpp:67
bool Start(cCallbacks &a_Callbacks, const AStringVector &a_Ports)
Starts the server and assigns the callbacks to use for incoming requests.
Definition: HTTPServer.cpp:134
virtual ~cHTTPServer()
Definition: HTTPServer.cpp:76
std::shared_ptr< const cSslConfig > m_SslConfig
Configuration for server ssl connections.
Definition: HTTPServer.h:74
void RequestFinished(cHTTPServerConnection &a_Connection, cHTTPIncomingRequest &a_Request)
Called by cHTTPServerConnection when it detects that the request has finished (all of its body has be...
Definition: HTTPServer.cpp:226
virtual void OnRequestBody(cHTTPServerConnection &a_Connection, cHTTPIncomingRequest &a_Request, const char *a_Data, size_t a_Size)=0
Called when another part of request body has arrived.
virtual void OnRequestBegun(cHTTPServerConnection &a_Connection, cHTTPIncomingRequest &a_Request)=0
Called when a new request arrives over a connection and all its headers have been parsed.
virtual void OnRequestFinished(cHTTPServerConnection &a_Connection, cHTTPIncomingRequest &a_Request)=0
Called when the request body has been fully received in previous calls to OnRequestBody()
std::shared_ptr< cCallbacks > cCallbacksPtr
Definition: Network.h:71