EHS Embedded HTTP Server  1.5.1.173
EHS Class Reference

EHS provides HTTP server functionality to a child class. More...

#include <ehs.h>

+ Inheritance diagram for EHS:
+ Collaboration diagram for EHS:

Public Member Functions

 EHS (EHS *parent=NULL, std::string registerpath="")
 Constructs a new instance as child of another EHS instance. More...
 
virtual ~EHS ()
 Destructor.
 
virtual const std::string GetPassphrase (bool twice)
 Default PassphraseHandler implementation. More...
 
void RegisterEHS (EHS *child, const char *uripath)
 Instructs this EHS instance to invoke HandleRequest of another EHS instance whenever a specific URI is requested. More...
 
void UnregisterEHS (const char *uripath)
 Removes a previously registered path registration. More...
 
ehs_autoptr< HttpResponseRouteRequest (HttpRequest *request)
 Routes a request to the appropriate instance. More...
 
virtual ResponseCode HandleRequest (HttpRequest *request, HttpResponse *response)
 Main request handler. More...
 
void SetSourceEHS (EHS &source)
 Establishes this EHS instance as request handler of another EHS instance. More...
 
void StartServer (EHSServerParameters &params)
 Starts up this instance. More...
 
void StopServer ()
 Shuts down this instance. More...
 
void HandleData (int timeout=0)
 Dispatches incoming data.
 
virtual bool ThreadInitHandler ()
 Hook for thread startup. More...
 
virtual void ThreadExitHandler ()
 Hook for thread shutdown. More...
 
virtual HttpResponseHandleThreadException (ehs_threadid_t tid, HttpRequest *request, std::exception &ex)
 Hook for handling exceptions in threads. More...
 
bool ShouldTerminate () const
 Retrieve the server's exception status. More...
 
void SetBindHelper (PrivilegedBindHelper *helper)
 Sets a PrivilegedBindHelper for use by the network abstraction layer. More...
 
PrivilegedBindHelperGetBindHelper () const
 Retieves our PrivilegedBindHelper. More...
 
void SetRawSocketHandler (RawSocketHandler *helper)
 Sets a RawSocketHandler for use by the network abstraction layer. More...
 
RawSocketHandlerGetRawSocketHandler () const
 Retrieves our RawSocketHandler. More...
 
void AddResponse (ehs_autoptr< GenericResponse > ehs_rvref response)
 Enqueues a generic response. More...
 
- Public Member Functions inherited from PassphraseHandler
virtual ~PassphraseHandler ()
 Destructor.
 

Public Attributes

EHSServerParameters m_oParams
 Stores a map with server parameters.
 

Protected Attributes

EHSMap m_oEHSMap
 Stores path => EHSConnection pairs for path/tree traversal.
 
EHSm_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.
 
EHSServerm_poEHSServer
 EHSServer object associated with this EHS object.
 
EHSm_poSourceEHS
 Source EHS object to route requests to for data instead of processing it ourselves.
 
PrivilegedBindHelperm_poBindHelper
 Our bind helper.
 
RawSocketHandlerm_poRawSocketHandler
 Our RawSocketHandler.
 
bool m_bNoRouting
 Flag: We don't do request routing.
 

Detailed Description

EHS provides HTTP server functionality to a child class.

The child class must inherit from it and then override the HandleRequest method.

Examples:
ehs_basicauth.cpp, ehs_exception.cpp, ehs_formtest.cpp, ehs_https.cpp, ehs_mirror.cpp, ehs_privport.cpp, ehs_simple.cpp, ehs_test.cpp, ehs_testharness.cpp, ehs_uploader.cpp, and ehs_wsgate.cpp.

Definition at line 147 of file ehs.h.

Constructor & Destructor Documentation

◆ EHS()

EHS ( EHS parent = NULL,
std::string  registerpath = "" 
)

Constructs a new instance as child of another EHS instance.

Parameters
parentThe parent EHS instance.
registerpathThe URI path which the new instance should handle.

Member Function Documentation

◆ AddResponse()

void AddResponse ( ehs_autoptr< GenericResponse > ehs_rvref  response)

Enqueues a generic response.

Parameters
responseThe response to enqueue

◆ GetBindHelper()

PrivilegedBindHelper* GetBindHelper ( ) const
inline

Retieves our PrivilegedBindHelper.

Returns
The current helper, or NULL if no helper was set.

Definition at line 331 of file ehs.h.

References m_poBindHelper.

◆ GetPassphrase()

virtual const std::string GetPassphrase ( bool  twice)
virtual

Default PassphraseHandler implementation.

Takes passphrase from server parameters without prompting.

Parameters
twiceIf true, an interactive implementation should ask twice for a passphrase in order to eliminate typing errors.
Returns
A std::string holding the passphrase.

Implements PassphraseHandler.

◆ GetRawSocketHandler()

RawSocketHandler* GetRawSocketHandler ( ) const
inline

Retrieves our RawSocketHandler.

Returns
The current RawSocketHandler, or NULL if no RawSocketHandler was set.

Definition at line 349 of file ehs.h.

References m_poRawSocketHandler.

◆ HandleRequest()

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.

Parameters
requestPointer to the HTTP request that triggered invocation of this method.
responsePointer to the HTTP response that is going to be sent to the client. In derived methods, populate the HttpResponse with your data.
Returns
The HTTP response code to be sent to the client.

◆ HandleThreadException()

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.

Parameters
tidThe thread ID of the thread that has thrown the exception.
requestThe current HTTP request that was active wile the exception was thrown.
exThe exception that was thrown. Any C-Style exceptions are thrown as runtime_exception("unspecified").
Returns
NULL if the thread should exit; an appropriate HTTP response, if the thread should continue.

◆ RegisterEHS()

void RegisterEHS ( EHS child,
const char *  uripath 
)

Instructs this EHS instance to invoke HandleRequest of another EHS instance whenever a specific URI is requested.

Parameters
childThe foreign EHS instance which shall handle the requests.
uripathThe relative URI path, that shall be handled by the child.
Exceptions
std:runtime_error,ifanother instance is already registered with the same path.

◆ RouteRequest()

ehs_autoptr<HttpResponse> RouteRequest ( HttpRequest request)

Routes a request to the appropriate instance.

Parameters
requestThe HTTP request to be routed.
Returns
A pointer to the HttpResponse object, to be sent back to the client.

◆ SetBindHelper()

void SetBindHelper ( PrivilegedBindHelper helper)
inline

Sets a PrivilegedBindHelper for use by the network abstraction layer.

Parameters
helperA 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.
Examples:
ehs_https.cpp.

Definition at line 322 of file ehs.h.

References m_poBindHelper.

◆ SetRawSocketHandler()

void SetRawSocketHandler ( RawSocketHandler helper)
inline

Sets a RawSocketHandler for use by the network abstraction layer.

Parameters
helperA pointer to a RawSocketHandler instance.

Definition at line 340 of file ehs.h.

References m_poRawSocketHandler.

◆ SetSourceEHS()

void SetSourceEHS ( EHS source)

Establishes this EHS instance as request handler of another EHS instance.

Any HTTP request received by the other EHS instance will be handled by this instance's HandleRequest method.

Parameters
sourceA reference to the source EHS instance.

◆ ShouldTerminate()

bool ShouldTerminate ( ) const

Retrieve the server's exception status.

Returns
true if the server should terminate.
Examples:
ehs_https.cpp, and ehs_simple.cpp.

◆ StartServer()

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.

Parameters
paramsAn EHSServerParameters map used for configuring this instance.
Exceptions
Astd:runtime_error if an error happens.
Examples:
ehs_https.cpp, and ehs_simple.cpp.

◆ StopServer()

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.

Examples:
ehs_https.cpp, and ehs_simple.cpp.

◆ ThreadExitHandler()

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.

◆ ThreadInitHandler()

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.

Returns
true, if everything is OK, false otherwise.

◆ UnregisterEHS()

void UnregisterEHS ( const char *  uripath)

Removes a previously registered path registration.

Parameters
uripathThe URI path to be removed.
Exceptions
std:runtime_error,ifnothing registered with the given path.

The documentation for this class was generated from the following file: