pion::http::plugin_server Class Reference

`#include <plugin_server.hpp>`

Inherits pion::http::server.

## Public Member Functions

virtual | ~plugin_server ()
| default destructor
| 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
Public Member Functions inherited from pion::http::server
virtual | ~server ()
| default destructor
| 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
void | set_not_found_handler (request_handler_t h)
| sets the function that handles requests which match no other web services
void | set_error_handler (error_handler_t h)
| sets the function that handles requests which match no other web services
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
Public Member Functions inherited from pion::tcp::server
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 | set_ssl_key_file (const std::string &pem_key_file)
std::size_t | get_connections (void) const
| returns the number of active tcp connections
unsigned int | get_port (void) const
| returns tcp port number that the server listens for connections on
void | set_port (unsigned int p)
| sets tcp port number that the server listens for connections on
boost::asio::ip::address | get_address (void) const
| returns IP address that the server listens for connections on
void | set_address (const boost::asio::ip::address &addr)
| sets IP address that the server listens for connections on
const boost::asio::ip::tcp::endpoint & | get_endpoint (void) const
| returns tcp endpoint that the server listens for connections on
void | set_endpoint (const boost::asio::ip::tcp::endpoint &ep)
| sets tcp endpoint that the server listens for connections on
bool | get_ssl_flag (void) const
| returns true if the server uses SSL to encrypt connections
void | set_ssl_flag (bool b=true)
| sets value of SSL flag (true if the server uses SSL to encrypt connections)
connection::ssl_context_type & | get_ssl_context_type (void)
| returns the SSL context for configuration
bool | is_listening (void) const
| returns true if the server is listening for connections
void | set_logger (logger log_ptr)
| sets the logger to be used
logger | get_logger (void)
| returns the logger currently in use
boost::asio::ip::tcp::acceptor & | get_acceptor (void)
| returns mutable reference to the TCP connection acceptor
const boost::asio::ip::tcp::acceptor & | get_acceptor (void) const
| returns const reference to the TCP connection acceptor

## Protected Member Functions

virtual void | before_starting (void)
| called before the TCP server starts listening for new connections
virtual void | after_stopping (void)
| called after the TCP server has stopped listening for new connections
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

## 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
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"
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

## Detailed Description

plugin_server: a server that handles HTTP connections using http::plugin_service plug-ins

Definition at line 31 of file plugin_server.hpp.

## Constructor & Destructor Documentation

## plugin_server() [1/4]

pion::http::plugin_server::plugin_server | ( | const unsigned int | tcp_port = `0` | ) |

inline explicit

creates a new plugin_server object

Parameters

  tcp_port | port number used to listen for new connections (IPv4)

Definition at line 45 of file plugin_server.hpp.

## plugin_server() [2/4]

pion::http::plugin_server::plugin_server | ( | const boost::asio::ip::tcp::endpoint & | endpoint | ) |

inline explicit

creates a new plugin_server object

Parameters

  endpoint | TCP endpoint used to listen for new connections (see ASIO docs)

Definition at line 56 of file plugin_server.hpp.

## plugin_server() [3/4]

pion::http::plugin_server::plugin_server | ( | scheduler & | sched,
|  | const unsigned int | tcp_port = `0`
| ) |  |

inline explicit

creates a new plugin_server object

Parameters

  sched | the scheduler that will be used to manage worker threads
  tcp_port | port number used to listen for new connections (IPv4)

Definition at line 68 of file plugin_server.hpp.

## plugin_server() [4/4]

pion::http::plugin_server::plugin_server | ( | scheduler & | sched,
|  | const boost::asio::ip::tcp::endpoint & | endpoint
| ) |  |

inline

creates a new plugin_server object

Parameters

  sched | the scheduler that will be used to manage worker threads
  endpoint | TCP endpoint used to listen for new connections (see ASIO docs)

Definition at line 80 of file plugin_server.hpp.

## Member Function Documentation

## add_service()

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

Parameters

  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 http_plugin_server.cpp.

References pion::plugin_manager< PluginType >::add(), pion::http::server::add_resource(), pion::tcp::server::m_logger, pion::http::plugin_service::set_resource(), and pion::http::server::strip_trailing_slash().

## load_service()

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

Parameters

  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 35 of file http_plugin_server.cpp.

References pion::http::server::add_resource(), pion::plugin_manager< PluginType >::load(), pion::tcp::server::m_logger, pion::http::plugin_service::set_resource(), and pion::http::server::strip_trailing_slash().

Referenced by load_service_config().

## 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.

Parameters

  config_name | the name of the config file to parse

Definition at line 54 of file http_plugin_server.cpp.

References pion::plugin::add_plugin_directory(), pion::plugin::find_config_file(), load_service(), pion::tcp::server::m_logger, pion::http::server::set_authentication(), and set_service_option().

## 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

Parameters

  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 45 of file http_plugin_server.cpp.

References pion::tcp::server::m_logger, pion::plugin_manager< PluginType >::run(), pion::http::plugin_service::set_option(), and pion::http::server::strip_trailing_slash().

Referenced by load_service_config().

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

- include/pion/http/plugin_server.hpp
- src/http_plugin_server.cpp