PionNetworkLibrary
|
#include <plugin_server.hpp>
Public Member Functions | |
virtual | ~plugin_server () |
default destructor More... | |
plugin_server (const unsigned int tcp_port=0) | |
plugin_server (const boost::asio::ip::tcp::endpoint &endpoint) | |
plugin_server (scheduler &sched, const unsigned int tcp_port=0) | |
plugin_server (scheduler &sched, const boost::asio::ip::tcp::endpoint &endpoint) | |
void | add_service (const std::string &resource, http::plugin_service *service_ptr) |
void | load_service (const std::string &resource, const std::string &service_name) |
void | set_service_option (const std::string &resource, const std::string &name, const std::string &value) |
void | load_service_config (const std::string &config_name) |
virtual void | clear (void) |
clears all the web services that are currently configured More... | |
Public Member Functions inherited from pion::http::server | |
virtual | ~server () |
default destructor More... | |
server (const unsigned int tcp_port=0) | |
server (const boost::asio::ip::tcp::endpoint &endpoint) | |
server (scheduler &sched, const unsigned int tcp_port=0) | |
server (scheduler &sched, const boost::asio::ip::tcp::endpoint &endpoint) | |
void | add_resource (const std::string &resource, request_handler_t request_handler) |
void | remove_resource (const std::string &resource) |
void | add_redirect (const std::string &requested_resource, const std::string &new_resource) |
void | set_bad_request_handler (request_handler_t h) |
sets the function that handles bad HTTP requests More... | |
void | set_not_found_handler (request_handler_t h) |
sets the function that handles requests which match no other web services More... | |
void | set_error_handler (error_handler_t h) |
sets the function that handles requests which match no other web services More... | |
void | set_authentication (http::auth_ptr auth) |
void | set_max_content_length (std::size_t n) |
sets the maximum length for HTTP request payload content More... | |
Public Member Functions inherited from pion::tcp::server | |
void | start (void) |
starts listening for new connections More... | |
void | stop (bool wait_until_finished=false) |
void | join (void) |
the calling thread will sleep until the server has stopped listening for connections More... | |
void | set_ssl_key_file (const std::string &pem_key_file) |
std::size_t | get_connections (void) const |
returns the number of active tcp connections More... | |
unsigned int | get_port (void) const |
returns tcp port number that the server listens for connections on More... | |
void | set_port (unsigned int p) |
sets tcp port number that the server listens for connections on More... | |
boost::asio::ip::address | get_address (void) const |
returns IP address that the server listens for connections on More... | |
void | set_address (const boost::asio::ip::address &addr) |
sets IP address that the server listens for connections on More... | |
const boost::asio::ip::tcp::endpoint & | get_endpoint (void) const |
returns tcp endpoint that the server listens for connections on More... | |
void | set_endpoint (const boost::asio::ip::tcp::endpoint &ep) |
sets tcp endpoint that the server listens for connections on More... | |
bool | get_ssl_flag (void) const |
returns true if the server uses SSL to encrypt connections More... | |
void | set_ssl_flag (bool b=true) |
sets value of SSL flag (true if the server uses SSL to encrypt connections) More... | |
connection::ssl_context_type & | get_ssl_context_type (void) |
returns the SSL context for configuration More... | |
bool | is_listening (void) const |
returns true if the server is listening for connections More... | |
void | set_logger (logger log_ptr) |
sets the logger to be used More... | |
logger | get_logger (void) |
returns the logger currently in use More... | |
boost::asio::ip::tcp::acceptor & | get_acceptor (void) |
returns mutable reference to the TCP connection acceptor More... | |
const boost::asio::ip::tcp::acceptor & | get_acceptor (void) const |
returns const reference to the TCP connection acceptor More... | |
Protected Member Functions | |
virtual void | before_starting (void) |
called before the TCP server starts listening for new connections More... | |
virtual void | after_stopping (void) |
called after the TCP server has stopped listening for new connections More... | |
Protected Member Functions inherited from pion::http::server | |
virtual void | handle_connection (const tcp::connection_ptr &tcp_conn) |
virtual void | handle_request (const http::request_ptr &http_request_ptr, const tcp::connection_ptr &tcp_conn, const boost::system::error_code &ec) |
virtual bool | find_request_handler (const std::string &resource, request_handler_t &request_handler) const |
Protected Member Functions inherited from pion::tcp::server | |
server (const unsigned int tcp_port) | |
server (const boost::asio::ip::tcp::endpoint &endpoint) | |
server (scheduler &sched, const unsigned int tcp_port=0) | |
server (scheduler &sched, const boost::asio::ip::tcp::endpoint &endpoint) | |
boost::asio::io_service & | get_io_service (void) |
returns an async I/O service used to schedule work More... | |
Additional Inherited Members | |
Public Types inherited from pion::http::server | |
typedef boost::function2< void, const http::request_ptr &, const tcp::connection_ptr & > | request_handler_t |
type of function that is used to handle requests More... | |
typedef boost::function3< void, const http::request_ptr &, const tcp::connection_ptr &, const std::string & > | error_handler_t |
handler for requests that result in "500 Server Error" More... | |
Static Public Member Functions inherited from pion::http::server | |
static std::string | strip_trailing_slash (const std::string &str) |
static void | handle_bad_request (const http::request_ptr &http_request_ptr, const tcp::connection_ptr &tcp_conn) |
static void | handle_not_found_request (const http::request_ptr &http_request_ptr, const tcp::connection_ptr &tcp_conn) |
static void | handle_server_error (const http::request_ptr &http_request_ptr, const tcp::connection_ptr &tcp_conn, const std::string &error_msg) |
static void | handle_forbidden_request (const http::request_ptr &http_request_ptr, const tcp::connection_ptr &tcp_conn, const std::string &error_msg) |
static void | handle_method_not_allowed (const http::request_ptr &http_request_ptr, const tcp::connection_ptr &tcp_conn, const std::string &allowed_methods="") |
Protected Attributes inherited from pion::tcp::server | |
logger | m_logger |
primary logging interface used by this class More... | |
plugin_server: a server that handles HTTP connections using http::plugin_service plug-ins
|
inlinevirtual |
default destructor
|
inlineexplicit |
creates a new plugin_server object
tcp_port | port number used to listen for new connections (IPv4) |
References PION_GET_LOGGER.
|
inlineexplicit |
creates a new plugin_server object
endpoint | TCP endpoint used to listen for new connections (see ASIO docs) |
References PION_GET_LOGGER.
|
inlineexplicit |
creates a new plugin_server object
sched | the scheduler that will be used to manage worker threads |
tcp_port | port number used to listen for new connections (IPv4) |
References PION_GET_LOGGER.
|
inline |
creates a new plugin_server object
sched | the scheduler that will be used to manage worker threads |
endpoint | TCP endpoint used to listen for new connections (see ASIO docs) |
References PION_GET_LOGGER.
void pion::http::plugin_server::add_service | ( | const std::string & | resource, |
http::plugin_service * | 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 |
References pion::plugin_manager< PluginType >::add(), pion::http::server::add_resource(), pion::tcp::server::m_logger, PION_LOG_INFO, pion::http::plugin_service::set_resource(), and pion::http::server::strip_trailing_slash().
|
inlineprotectedvirtual |
called after the TCP server has stopped listening for new connections
Reimplemented from pion::tcp::server.
References pion::http::plugin_service::stop().
|
inlineprotectedvirtual |
called before the TCP server starts listening for new connections
Reimplemented from pion::tcp::server.
References pion::http::plugin_service::start().
|
inlinevirtual |
clears all the web services that are currently configured
Reimplemented from pion::http::server.
References pion::http::server::clear().
void pion::http::plugin_server::load_service | ( | 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) |
References pion::http::server::add_resource(), pion::plugin_manager< PluginType >::load(), pion::tcp::server::m_logger, PION_LOG_INFO, pion::http::plugin_service::set_resource(), and pion::http::server::strip_trailing_slash().
Referenced by load_service_config().
void pion::http::plugin_server::load_service_config | ( | 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 |
References pion::plugin::add_plugin_directory(), pion::diagnostic_information(), pion::plugin::find_config_file(), load_service(), pion::tcp::server::m_logger, PION_LOG_WARN, pion::http::server::set_authentication(), and set_service_option().
void pion::http::plugin_server::set_service_option | ( | 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 |
References pion::tcp::server::m_logger, PION_LOG_INFO, pion::plugin_manager< PluginType >::run(), pion::http::plugin_service::set_option(), and pion::http::server::strip_trailing_slash().
Referenced by load_service_config().