| 1 | // -------------------------------------------------------------------------- |
|---|
| 2 | // |
|---|
| 3 | // File |
|---|
| 4 | // Name: HTTPServer.h |
|---|
| 5 | // Purpose: HTTP server class |
|---|
| 6 | // Created: 26/3/04 |
|---|
| 7 | // |
|---|
| 8 | // -------------------------------------------------------------------------- |
|---|
| 9 | |
|---|
| 10 | #ifndef HTTPSERVER__H |
|---|
| 11 | #define HTTPSERVER__H |
|---|
| 12 | |
|---|
| 13 | #include "ServerStream.h" |
|---|
| 14 | #include "SocketStream.h" |
|---|
| 15 | |
|---|
| 16 | class HTTPRequest; |
|---|
| 17 | class HTTPResponse; |
|---|
| 18 | |
|---|
| 19 | // -------------------------------------------------------------------------- |
|---|
| 20 | // |
|---|
| 21 | // Class |
|---|
| 22 | // Name: HTTPServer |
|---|
| 23 | // Purpose: HTTP server |
|---|
| 24 | // Created: 26/3/04 |
|---|
| 25 | // |
|---|
| 26 | // -------------------------------------------------------------------------- |
|---|
| 27 | class HTTPServer : public ServerStream<SocketStream, 80> |
|---|
| 28 | { |
|---|
| 29 | public: |
|---|
| 30 | HTTPServer(); |
|---|
| 31 | ~HTTPServer(); |
|---|
| 32 | private: |
|---|
| 33 | // no copying |
|---|
| 34 | HTTPServer(const HTTPServer &); |
|---|
| 35 | HTTPServer &operator=(const HTTPServer &); |
|---|
| 36 | public: |
|---|
| 37 | |
|---|
| 38 | int GetTimeout() const {return mTimeout;} |
|---|
| 39 | |
|---|
| 40 | // -------------------------------------------------------------------------- |
|---|
| 41 | // |
|---|
| 42 | // Function |
|---|
| 43 | // Name: HTTPServer::Handle(const HTTPRequest &, HTTPResponse &) |
|---|
| 44 | // Purpose: Response to a request, filling in the response object for sending |
|---|
| 45 | // at some point in the future. |
|---|
| 46 | // Created: 26/3/04 |
|---|
| 47 | // |
|---|
| 48 | // -------------------------------------------------------------------------- |
|---|
| 49 | virtual void Handle(HTTPRequest &rRequest, HTTPResponse &rResponse) = 0; |
|---|
| 50 | |
|---|
| 51 | // For notifications to derived classes |
|---|
| 52 | virtual void HTTPConnectionOpening(); |
|---|
| 53 | virtual void HTTPConnectionClosing(); |
|---|
| 54 | |
|---|
| 55 | protected: |
|---|
| 56 | void SendInternalErrorResponse(const std::string& rErrorMsg, |
|---|
| 57 | HTTPResponse& rResponse); |
|---|
| 58 | int GetTimeout() { return mTimeout; } |
|---|
| 59 | |
|---|
| 60 | private: |
|---|
| 61 | int mTimeout; // Timeout for read operations |
|---|
| 62 | const char *DaemonName() const; |
|---|
| 63 | const ConfigurationVerify *GetConfigVerify() const; |
|---|
| 64 | void Run(); |
|---|
| 65 | void Connection(SocketStream &rStream); |
|---|
| 66 | }; |
|---|
| 67 | |
|---|
| 68 | // Root level |
|---|
| 69 | #define HTTPSERVER_VERIFY_ROOT_KEYS \ |
|---|
| 70 | ConfigurationVerifyKey("AddressPrefix", \ |
|---|
| 71 | ConfigTest_Exists | ConfigTest_LastEntry) |
|---|
| 72 | |
|---|
| 73 | // AddressPrefix is, for example, http://localhost:1080 -- ie the beginning of the URI |
|---|
| 74 | // This is used for handling redirections. |
|---|
| 75 | |
|---|
| 76 | // Server level |
|---|
| 77 | #define HTTPSERVER_VERIFY_SERVER_KEYS(DEFAULT_ADDRESSES) \ |
|---|
| 78 | SERVERSTREAM_VERIFY_SERVER_KEYS(DEFAULT_ADDRESSES) |
|---|
| 79 | |
|---|
| 80 | #endif // HTTPSERVER__H |
|---|
| 81 | |
|---|