plugin_service.hpp
// ---------------------------------------------------------------------
// pion: a Boost C++ framework for building lightweight HTTP interfaces
// ---------------------------------------------------------------------
// Copyright (C) 2007-2014 Splunk Inc. (https://github.com/splunk/pion)
//
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
//
#ifndef __PION_PLUGIN_SERVICE_HEADER__
#define __PION_PLUGIN_SERVICE_HEADER__
#include <string>
#include <boost/noncopyable.hpp>
#include <pion/config.hpp>
#include <pion/error.hpp>
#include <pion/algorithm.hpp>
#include <pion/http/request.hpp>
#include <pion/tcp/connection.hpp>
namespace pion { // begin namespace pion
namespace http { // begin namespace http
class plugin_service :
private boost::noncopyable
{
public:
plugin_service(void) {}
virtual ~plugin_service() {}
virtual void operator()(const http::request_ptr& http_request_ptr, const tcp::connection_ptr& tcp_conn) = 0;
virtual void set_option(const std::string& name, const std::string& value) {
BOOST_THROW_EXCEPTION( error::bad_arg() << error::errinfo_arg_name(name) );
}
virtual void start(void) {}
virtual void stop(void) {}
inline void set_resource(const std::string& str) { m_resource = str; }
inline const std::string& get_resource(void) const { return m_resource; }
inline std::string get_relative_resource(const std::string& resource_requested) const {
if (resource_requested.size() <= get_resource().size()) {
// either the request matches the web service's resource path (a directory)
// or the request does not match (should never happen)
return std::string();
}
// strip the web service's resource path plus the slash after it
return algorithm::url_decode(resource_requested.substr(get_resource().size() + 1));
}
private:
std::string m_resource;
};
//
// The following symbols must be defined for any web service that you would
// like to be able to load dynamically using the http::server::load_service()
// function. These are not required for any services that you only want to link
// directly into your programs.
//
// Make sure that you replace "MyPluginName" with the name of your derived class.
// This name must also match the name of the object file (excluding the
// extension). These symbols must be linked into your service's object file,
// not included in any headers that it may use (declarations are OK in headers
// but not the definitions).
//
// The "pion_create" function is used to create new instances of your service.
// The "pion_destroy" function is used to destroy instances of your service.
//
// extern "C" MyPluginName *pion_create_MyPluginName(void) {
// return new MyPluginName;
// }
//
// extern "C" void pion_destroy_MyPluginName(MyPluginName *service_ptr) {
// delete service_ptr;
// }
//
} // end namespace http
} // end namespace pion
#endif
pion::http::plugin_service
Definition: plugin_service.hpp:29
pion::http::plugin_service::~plugin_service
virtual ~plugin_service()
virtual destructor
Definition: plugin_service.hpp:38
pion::http::plugin_service::set_resource
void set_resource(const std::string &str)
sets the URI stem or resource that is bound to the web service
Definition: plugin_service.hpp:65
pion::http::plugin_service::set_option
virtual void set_option(const std::string &name, const std::string &value)
Definition: plugin_service.hpp:54
pion::http::plugin_service::stop
virtual void stop(void)
called when the web service&#39;s server is stopping
Definition: plugin_service.hpp:62
pion::algorithm::url_decode
static std::string url_decode(const std::string &str)
escapes URL-encoded strings (a%20value+with%20spaces)
Definition: algorithm.cpp:153
pion::http::plugin_service::plugin_service
plugin_service(void)
default constructor
Definition: plugin_service.hpp:35
pion::http::plugin_service::operator()
virtual void operator()(const http::request_ptr &http_request_ptr, const tcp::connection_ptr &tcp_conn)=0
pion
Definition: admin_rights.hpp:19
pion::http::plugin_service::get_resource
const std::string & get_resource(void) const
returns the URI stem or resource that is bound to the web service
Definition: plugin_service.hpp:68
pion::error::bad_arg
exception thrown for an invalid configuration argument or option
Definition: error.hpp:132
pion::http::plugin_service::get_relative_resource
std::string get_relative_resource(const std::string &resource_requested) const
returns the path to the resource requested, relative to the web service&#39;s location ...
Definition: plugin_service.hpp:71
pion::http::plugin_service::start
virtual void start(void)
called when the web service&#39;s server is starting
Definition: plugin_service.hpp:59