|
| httpd (unsigned short port=0, unsigned int maxconn=0) |
| Constructor.
|
|
| ~httpd () |
| Destructor.
|
|
void | add_ohdr (const char *hdr, const char *value) |
| Add or modify a server response header.
|
|
void | remove_ohdr (const char *hdr) |
| Remove a server response header.
|
|
void | add_handler (const char *uri, uri_handler func, void *info=0) |
| Add or modify an URI handler function.
|
|
bool | add_user (const char *realm, const char *username, const char *pwd) |
| Add a new user to a relm or modifies password for an existing user.
|
|
bool | remove_user (const char *realm, const char *username) |
|
void | add_realm (const char *realm, const char *uri) |
| Add a new access realm.
|
|
void | add_var (const char *name, const char *fmt, void *addr, double multiplier=1.) |
| Add or modify a user variable.
|
|
std::string | get_var (const char *name) |
| Return the current string representation of a variable.
|
|
void | aquire_varlock () |
| Acquire lock on server's variables.
|
|
void | release_varlock () |
| Release lock on server's variables.
|
|
bool | try_varlock () |
| Try to acquire lock on server's variables.
|
|
void | name (const char *nam) |
| Change server name.
|
|
void | docroot (const char *path) |
| Set server root path.
|
|
const char * | docroot () const |
| Return current file origin.
|
|
void | add_alias (const char *uri, const char *path) |
| Maps a local file path to a path in the URI space.
|
|
void | default_uri (const char *name) |
|
const char * | default_uri () |
|
void | add_mime_type (const char *ext, const char *type, bool shtml=false) |
| Add/change content of table matching MIME types to file extensions.
|
|
void | delete_mime_type (const char *ext) |
| Remove a file type from the MIME type table.
|
|
bool | is_protected (const char *uri, std::string &realm) |
| Find the longest match realm that covers an uri.
|
|
bool | authenticate (const char *realm, const char *user, const char *pwd) |
| Verify user credentials for a realm.
|
|
| tcpserver (unsigned short port, const std::string &name=std::string(), unsigned int max_conn=0) |
| Opens the socket and initializes the connections table.
|
|
| ~tcpserver () |
| Terminate any connection that still exists.
|
|
sock & | socket () |
| Provides access to server listening socket.
|
|
void | foreach (conn_iter_func f, void *param) |
| Invoke an iteration function for each active connection.
|
|
thread * | get_connection_thread (const sock &conn_sock) |
| Return the thread servicing a connection.
|
|
void | close_connection (const sock &conn_sock) |
| Closes a connection.
|
|
void | terminate () |
| Terminate the tcp server.
|
|
size_t | numconn () const |
| Return number of active connections.
|
|
unsigned int | timeout () const |
| Return max interval to wait for an incoming connection (in milliseconds)
|
|
void | timeout (DWORD msec) |
| Set maximum timeout interval (in milliseconds)
|
|
void | maxconn (unsigned int new_max) |
| Set maximum number of connections accepted.
|
|
unsigned int | maxconn () const |
| Return maximum number of connections accepted.
|
|
void | set_connfunc (std::function< int(const sock &)> f) |
| Set function object that becomes the body of the thread serving a new connection.
|
|
| thread (std::function< unsigned int()> func) |
| Make a thread with the given function body.
|
|
virtual | ~thread () |
| Destructor.
|
|
virtual void | start () |
| Begin execution of a newly created thread.
|
|
void | fork () |
| Another name for start () function.
|
|
void | join () |
| Another name for wait () function.
|
|
DWORD | wait (DWORD time_limit=INFINITE) |
| Wait for thread to finish execution.
|
|
DWORD | wait_alertable (DWORD time_limit=INFINITE) |
| Wait for thread to finish or an APC, or IO completion routine to occur.
|
|
DWORD | wait_msg (DWORD time_limit=INFINITE, DWORD mask=QS_ALLINPUT) |
| Wait for thread to finish or a message to be queued.
|
|
void | rethrow_exception () const |
| Rethrow an exception usually in the context of another thread.
|
|
DWORD | id () const |
| Return thread's ID.
|
|
UINT | result () const |
| Return thread's exit code.
|
|
bool | is_running () const |
| Return true if thread is running.
|
|
state | get_state () const |
| Return thread's execution status.
|
|
int | priority () const |
| Return thread's priority.
|
|
void | priority (int pri) |
| Set thread's priority.
|
|
virtual void | name (const std::string &nam) |
| Set thread's name.
|
|
virtual const std::string & | name () const |
| Return object's name.
|
|
virtual void | name (const std::string &nam) |
| Change object's name.
|
|
| syncbase () |
| Default constructor.
|
|
| syncbase (const syncbase &e) |
| Copy constructor.
|
|
| syncbase (syncbase &&e) noexcept |
| Move constructor.
|
|
virtual | ~syncbase () |
| Destructor.
|
|
syncbase & | operator= (const syncbase &rhs) |
| Assignment operator.
|
|
syncbase & | operator= (syncbase &&rhs) noexcept |
| Move assignment operator.
|
|
int | operator== (const syncbase &rhs) const |
| Equality operator.
|
|
virtual void | wait () |
| Wait for object to become signaled.
|
|
virtual DWORD | wait (std::chrono::milliseconds limit) |
| Wait a number of milliseconds for the object to become signaled.
|
|
| operator bool () |
| Check if object is signaled.
|
|
virtual bool | is_signaled () |
| Try to wait on the object.
|
|
HANDLE | handle () const |
| Return OS handle of this object.
|
|
|
int | invoke_handler (const char *uri, http_connection &client) |
| Invoke a user defined URI handler.
|
|
bool | find_alias (const char *uri, char *path) |
| Retrieve the local file path mapped to an URI.
|
|
const char * | guess_mimetype (const char *file, bool &shtml) |
| Guess MIME type of a file and if SSI replacement should be enabled based on file extension.
|
|
http_connection * | make_thread (sock &connection) |
| Create an new http_connection object for a new incoming connection.
|
|
bool | init () override |
| Binds the server socket to listening address and places it in listen mode.
|
|
void | run () override |
| Run loop.
|
|
virtual bool | idle_action () |
| Called periodically from run loop.
|
|
virtual void | initconn (sock &conn_sock, thread *thread) |
| Initializes a connection.
|
|
virtual void | termconn (sock &conn_sock, thread *thread) |
| Finalizes a connection.
|
|
| thread (const std::string &name=std::string(), DWORD stack_size=0, PSECURITY_DESCRIPTOR sd=NULL, bool inherit=false) |
| Protected constructor for use of thread-derived objects.
|
|
virtual void | term () |
| Finalization function called after run.
|
|
| syncbase (const std::string &name) |
| Protected constructor.
|
|
void | set_handle (HANDLE h) |
| Change object's handle. Closes the previous one.
|
|
Small multi-threaded HTTP server.
This class is derived from tcpserver class and implements a basic HTTP server.
After construction, the main server thread has to be started by calling start() function. When started, the server binds to the listening socket and creates new http_connection objects for each incoming client. All the protocol is then handled by the http_connection (or derived) class.
A HTTP server can be integrated to an application by adding specific url handlers and user variables. URL handlers are registered by calling the add_handler() function.
User variables can be added by calling the add_var() function. The content of those variables is then returned in response to SSI echo directives.