EHS Embedded HTTP Server
1.5.0.132
|
EHS provides HTTP server functionality to a child class. More...
#include <ehs.h>
Public Member Functions | |
EHS (EHS *parent=NULL, std::string registerpath="") | |
Constructs a new instance as child of another EHS instance. | |
virtual | ~EHS () |
Destructor. | |
virtual const std::string | GetPassphrase (bool twice) |
Default PassphraseHandler implementation. | |
void | RegisterEHS (EHS *child, const char *uripath) |
Instructs this EHS instance to invoke HandleRequest of another EHS instance whenever a specific URI is requested. | |
void | UnregisterEHS (const char *uripath) |
Removes a previously registered path registration. | |
ehs_autoptr< HttpResponse > | RouteRequest (HttpRequest *request) |
Routes a request to the appropriate instance. | |
virtual ResponseCode | HandleRequest (HttpRequest *request, HttpResponse *response) |
Main request handler. | |
void | SetSourceEHS (EHS &source) |
Establishes this EHS instance as request handler of another EHS instance. | |
void | StartServer (EHSServerParameters ¶ms) |
Starts up this instance. | |
void | StopServer () |
Shuts down this instance. | |
void | HandleData (int timeout=0) |
Dispatches incoming data. | |
virtual bool | ThreadInitHandler () |
Hook for thread startup. | |
virtual void | ThreadExitHandler () |
Hook for thread shutdown. | |
virtual HttpResponse * | HandleThreadException (ehs_threadid_t tid, HttpRequest *request, std::exception &ex) |
Hook for handling exceptions in threads. | |
bool | ShouldTerminate () const |
Retrieve the server's exception status. | |
void | SetBindHelper (PrivilegedBindHelper *helper) |
Sets a PrivilegedBindHelper for use by the network abstraction layer. | |
PrivilegedBindHelper * | GetBindHelper () const |
Retieves our PrivilegedBindHelper. | |
void | SetRawSocketHandler (RawSocketHandler *helper) |
Sets a RawSocketHandler for use by the network abstraction layer. | |
RawSocketHandler * | GetRawSocketHandler () const |
Retrieves our RawSocketHandler. | |
void | AddResponse (ehs_autoptr< GenericResponse > ehs_rvref response) |
Enqueues a generic response. | |
Public Attributes | |
EHSServerParameters | m_oParams |
Stores a map with server parameters. | |
Protected Attributes | |
EHSMap | m_oEHSMap |
Stores path => EHSConnection pairs for path/tree traversal. | |
EHS * | m_poParent |
Points to the EHS object this object was registered with, NULL if top level. | |
std::string | m_sRegisteredAs |
The string that this EHS object is regestered as. | |
EHSServer * | m_poEHSServer |
EHSServer object associated with this EHS object. | |
EHS * | m_poSourceEHS |
Source EHS object to route requests to for data instead of processing it ourselves. | |
PrivilegedBindHelper * | m_poBindHelper |
Our bind helper. | |
RawSocketHandler * | m_poRawSocketHandler |
Our RawSocketHandler. | |
bool | m_bNoRouting |
Flag: We don't do request routing. |
EHS provides HTTP server functionality to a child class.
The child class must inherit from it and then override the HandleRequest method.
void AddResponse | ( | ehs_autoptr< GenericResponse > ehs_rvref | response | ) |
Enqueues a generic response.
response | The response to enqueue |
PrivilegedBindHelper* GetBindHelper | ( | ) | const [inline] |
Retieves our PrivilegedBindHelper.
Definition at line 331 of file ehs.h.
References m_poBindHelper.
virtual const std::string GetPassphrase | ( | bool | twice | ) | [virtual] |
Default PassphraseHandler implementation.
Takes passphrase from server parameters without prompting.
twice | If true, an interactive implementation should ask twice for a passphrase in order to eliminate typing errors. |
Implements PassphraseHandler.
RawSocketHandler* GetRawSocketHandler | ( | ) | const [inline] |
Retrieves our RawSocketHandler.
Definition at line 349 of file ehs.h.
References m_poRawSocketHandler.
virtual ResponseCode HandleRequest | ( | HttpRequest * | request, |
HttpResponse * | response | ||
) | [virtual] |
Main request handler.
Reimplement this method in a derived class in order to implement the actual functionality.
request | Pointer to the HTTP request that triggered invocation of this method. |
response | Pointer to the HTTP response that is going to be sent to the client. In derived methods, populate the HttpResponse with your data. |
virtual HttpResponse* HandleThreadException | ( | ehs_threadid_t | tid, |
HttpRequest * | request, | ||
std::exception & | ex | ||
) | [virtual] |
Hook for handling exceptions in threads.
Called, when an exception was thrown from within a thread. Reimplement this method in a derived class, if you want to handle your own exceptions. The default implementation prints the exception's message on cerr and returns NULL. If returning NULL, you still should invoke StopServer in order to terminate the server's remaining threads.
tid | The thread ID of the thread that has thrown the exception. |
request | The current HTTP request that was active wile the exception was thrown. |
ex | The exception that was thrown. Any C-Style exceptions are thrown as runtime_exception("unspecified"). |
void RegisterEHS | ( | EHS * | child, |
const char * | uripath | ||
) |
Instructs this EHS instance to invoke HandleRequest of another EHS instance whenever a specific URI is requested.
child | The foreign EHS instance which shall handle the requests. |
uripath | The relative URI path, that shall be handled by the child. |
std:runtime_error,if | another instance is already registered with the same path. |
ehs_autoptr<HttpResponse> RouteRequest | ( | HttpRequest * | request | ) |
Routes a request to the appropriate instance.
request | The HTTP request to be routed. |
void SetBindHelper | ( | PrivilegedBindHelper * | helper | ) | [inline] |
Sets a PrivilegedBindHelper for use by the network abstraction layer.
helper | A pointer to a PrivilegedBindHelper instance, implementing the bind operation to a privileged port. Without this helper, an instance cannot bind to privileged ports (ports < 1024) unless running as root. The BindPrivilegedPort method will only be called for ports < 1024. |
Definition at line 322 of file ehs.h.
References m_poBindHelper.
void SetRawSocketHandler | ( | RawSocketHandler * | helper | ) | [inline] |
Sets a RawSocketHandler for use by the network abstraction layer.
helper | A pointer to a RawSocketHandler instance. |
Definition at line 340 of file ehs.h.
References m_poRawSocketHandler.
void SetSourceEHS | ( | EHS & | source | ) |
bool ShouldTerminate | ( | ) | const |
Retrieve the server's exception status.
void StartServer | ( | EHSServerParameters & | params | ) |
Starts up this instance.
If configured to run in threaded mode, the main listener thread as well as all worker threads are started.
params | An EHSServerParameters map used for configuring this instance. |
A | std:runtime_error if an error happens. |
void StopServer | ( | ) |
Shuts down this instance.
If running in threaded mode, all associated threads are stopped. Stopping threads is a blocking operation. This method returns, if all relevant threads are terminated.
virtual void ThreadExitHandler | ( | ) | [virtual] |
Hook for thread shutdown.
Called at exit of a thread routine. Reimplement this method in a derived class, if you need to perform any task (like some cleanup) just before the thread is terminating.
virtual bool ThreadInitHandler | ( | ) | [virtual] |
Hook for thread startup.
Called at the start of a thread routine. Reimplement this method in a derived class, if you need to perform any task (like setting up thread-local storage) at the start of a thread.
void UnregisterEHS | ( | const char * | uripath | ) |
Removes a previously registered path registration.
uripath | The URI path to be removed. |
std:runtime_error,if | nothing registered with the given path. |