pion-net
4.0.9
|
#include <WebServer.hpp>
Inherits pion::net::HTTPServer.
Classes | |
class | AuthConfigException |
exception thrown if there is an error parsing the authorization config More... | |
class | ConfigNotFoundException |
exception thrown if the web service configuration file cannot be found More... | |
class | ConfigParsingException |
exception thrown if the plug-in file cannot be opened More... | |
class | ServiceNotFoundException |
exception thrown if a web service cannot be found More... | |
class | WebServiceException |
exception used to propagate exceptions thrown by web services More... | |
Public Member Functions | |
virtual | ~WebServer () |
default destructor | |
WebServer (const unsigned int tcp_port=0) | |
WebServer (const boost::asio::ip::tcp::endpoint &endpoint) | |
WebServer (PionScheduler &scheduler, const unsigned int tcp_port=0) | |
WebServer (PionScheduler &scheduler, const boost::asio::ip::tcp::endpoint &endpoint) | |
void | addService (const std::string &resource, WebService *service_ptr) |
void | loadService (const std::string &resource, const std::string &service_name) |
void | setServiceOption (const std::string &resource, const std::string &name, const std::string &value) |
void | loadServiceConfig (const std::string &config_name) |
virtual void | clear (void) |
clears all the web services that are currently configured | |
![]() | |
virtual | ~HTTPServer () |
default destructor | |
HTTPServer (const unsigned int tcp_port=0) | |
HTTPServer (const boost::asio::ip::tcp::endpoint &endpoint) | |
HTTPServer (PionScheduler &scheduler, const unsigned int tcp_port=0) | |
HTTPServer (PionScheduler &scheduler, const boost::asio::ip::tcp::endpoint &endpoint) | |
void | addResource (const std::string &resource, RequestHandler request_handler) |
void | removeResource (const std::string &resource) |
void | addRedirect (const std::string &requested_resource, const std::string &new_resource) |
void | setBadRequestHandler (RequestHandler h) |
sets the function that handles bad HTTP requests | |
void | setNotFoundHandler (RequestHandler h) |
sets the function that handles requests which match no other web services | |
void | setServerErrorHandler (ServerErrorHandler h) |
sets the function that handles requests which match no other web services | |
void | setAuthentication (HTTPAuthPtr auth) |
void | setMaxContentLength (std::size_t n) |
sets the maximum length for HTTP request payload content | |
![]() | |
virtual | ~TCPServer () |
default destructor | |
void | start (void) |
starts listening for new connections | |
void | stop (bool wait_until_finished=false) |
void | join (void) |
the calling thread will sleep until the server has stopped listening for connections | |
void | setSSLKeyFile (const std::string &pem_key_file) |
std::size_t | getConnections (void) const |
returns the number of active tcp connections | |
unsigned int | getPort (void) const |
returns tcp port number that the server listens for connections on | |
void | setPort (unsigned int p) |
sets tcp port number that the server listens for connections on | |
boost::asio::ip::address | getAddress (void) const |
returns IP address that the server listens for connections on | |
void | setAddress (const boost::asio::ip::address &addr) |
sets IP address that the server listens for connections on | |
const boost::asio::ip::tcp::endpoint & | getEndpoint (void) const |
returns tcp endpoint that the server listens for connections on | |
void | setEndpoint (const boost::asio::ip::tcp::endpoint &ep) |
sets tcp endpoint that the server listens for connections on | |
bool | getSSLFlag (void) const |
returns true if the server uses SSL to encrypt connections | |
void | setSSLFlag (bool b=true) |
sets value of SSL flag (true if the server uses SSL to encrypt connections) | |
TCPConnection::SSLContext & | getSSLContext (void) |
returns the SSL context for configuration | |
bool | isListening (void) const |
returns true if the server is listening for connections | |
void | setLogger (PionLogger log_ptr) |
sets the logger to be used | |
PionLogger | getLogger (void) |
returns the logger currently in use | |
Protected Member Functions | |
virtual void | beforeStarting (void) |
called before the TCP server starts listening for new connections | |
virtual void | afterStopping (void) |
called after the TCP server has stopped listening for new connections | |
![]() | |
virtual void | handleConnection (TCPConnectionPtr &tcp_conn) |
virtual void | handleRequest (HTTPRequestPtr &http_request, TCPConnectionPtr &tcp_conn, const boost::system::error_code &ec) |
virtual bool | findRequestHandler (const std::string &resource, RequestHandler &request_handler) const |
![]() | |
TCPServer (const unsigned int tcp_port) | |
TCPServer (const boost::asio::ip::tcp::endpoint &endpoint) | |
TCPServer (PionScheduler &scheduler, const unsigned int tcp_port=0) | |
TCPServer (PionScheduler &scheduler, const boost::asio::ip::tcp::endpoint &endpoint) | |
boost::asio::io_service & | getIOService (void) |
returns an async I/O service used to schedule work | |
Additional Inherited Members | |
![]() | |
typedef boost::function2< void, HTTPRequestPtr &, TCPConnectionPtr & > | RequestHandler |
type of function that is used to handle requests | |
typedef boost::function3< void, HTTPRequestPtr &, TCPConnectionPtr &, const std::string & > | ServerErrorHandler |
handler for requests that result in "500 Server Error" | |
![]() | |
static std::string | stripTrailingSlash (const std::string &str) |
static void | handleBadRequest (HTTPRequestPtr &http_request, TCPConnectionPtr &tcp_conn) |
static void | handleNotFoundRequest (HTTPRequestPtr &http_request, TCPConnectionPtr &tcp_conn) |
static void | handleServerError (HTTPRequestPtr &http_request, TCPConnectionPtr &tcp_conn, const std::string &error_msg) |
static void | handleForbiddenRequest (HTTPRequestPtr &http_request, TCPConnectionPtr &tcp_conn, const std::string &error_msg) |
static void | handleMethodNotAllowed (HTTPRequestPtr &http_request, TCPConnectionPtr &tcp_conn, const std::string &allowed_methods="") |
![]() | |
PionLogger | m_logger |
primary logging interface used by this class | |
WebServer: a server that handles HTTP connections using WebService plug-ins
Definition at line 31 of file WebServer.hpp.
|
inlineexplicit |
creates a new WebServer object
tcp_port | port number used to listen for new connections (IPv4) |
Definition at line 83 of file WebServer.hpp.
|
inlineexplicit |
creates a new WebServer object
endpoint | TCP endpoint used to listen for new connections (see ASIO docs) |
Definition at line 94 of file WebServer.hpp.
|
inlineexplicit |
creates a new WebServer object
scheduler | the PionScheduler that will be used to manage worker threads |
tcp_port | port number used to listen for new connections (IPv4) |
Definition at line 106 of file WebServer.hpp.
|
inline |
creates a new WebServer object
scheduler | the PionScheduler that will be used to manage worker threads |
endpoint | TCP endpoint used to listen for new connections (see ASIO docs) |
Definition at line 118 of file WebServer.hpp.
void pion::net::WebServer::addService | ( | const std::string & | resource, |
WebService * | service_ptr | ||
) |
adds a new web service to the web server
resource | the resource name or uri-stem to bind to the web service |
service_ptr | a pointer to the web service |
Definition at line 25 of file WebServer.cpp.
References pion::PluginManager< PLUGIN_TYPE >::add(), pion::net::HTTPServer::addResource(), pion::net::TCPServer::m_logger, pion::net::WebService::setResource(), and pion::net::HTTPServer::stripTrailingSlash().
void pion::net::WebServer::loadService | ( | const std::string & | resource, |
const std::string & | service_name | ||
) |
loads a web service from a shared object file
resource | the resource name or uri-stem to bind to the web service |
service_name | the name of the web service to load (searches plug-in directories and appends extensions) |
Definition at line 41 of file WebServer.cpp.
References pion::net::HTTPServer::addResource(), pion::PluginManager< PLUGIN_TYPE >::load(), pion::net::TCPServer::m_logger, pion::net::WebService::setResource(), and pion::net::HTTPServer::stripTrailingSlash().
Referenced by loadServiceConfig().
void pion::net::WebServer::loadServiceConfig | ( | const std::string & | config_name | ) |
Parses a simple web service configuration file. Each line in the file starts with one of the following commands:
path VALUE : adds a directory to the web service search path service RESOURCE FILE : loads web service bound to RESOURCE from FILE option RESOURCE NAME=VALUE : sets web service option NAME to VALUE
Blank lines or lines that begin with # are ignored as comments.
config_name | the name of the config file to parse |
Definition at line 74 of file WebServer.cpp.
References pion::PionPlugin::addPluginDirectory(), pion::PionPlugin::findConfigFile(), loadService(), pion::net::TCPServer::m_logger, pion::net::HTTPServer::setAuthentication(), and setServiceOption().
void pion::net::WebServer::setServiceOption | ( | const std::string & | resource, |
const std::string & | name, | ||
const std::string & | value | ||
) |
sets a configuration option for the web service associated with resource
resource | the resource name or uri-stem that identifies the web service |
name | the name of the configuration option |
value | the value to set the option to |
Definition at line 57 of file WebServer.cpp.
References pion::net::TCPServer::m_logger, pion::PluginManager< PLUGIN_TYPE >::run(), pion::net::WebService::setOption(), and pion::net::HTTPServer::stripTrailingSlash().
Referenced by loadServiceConfig().