pion
5.0.6
|
00001 // --------------------------------------------------------------------- 00002 // pion: a Boost C++ framework for building lightweight HTTP interfaces 00003 // --------------------------------------------------------------------- 00004 // Copyright (C) 2007-2014 Splunk Inc. (https://github.com/splunk/pion) 00005 // 00006 // Distributed under the Boost Software License, Version 1.0. 00007 // See http://www.boost.org/LICENSE_1_0.txt 00008 // 00009 00010 #ifndef __PION_PLUGIN_SERVICE_HEADER__ 00011 #define __PION_PLUGIN_SERVICE_HEADER__ 00012 00013 #include <string> 00014 #include <boost/noncopyable.hpp> 00015 #include <pion/config.hpp> 00016 #include <pion/error.hpp> 00017 #include <pion/algorithm.hpp> 00018 #include <pion/http/request.hpp> 00019 #include <pion/tcp/connection.hpp> 00020 00021 00022 namespace pion { // begin namespace pion 00023 namespace http { // begin namespace http 00024 00025 00029 class plugin_service : 00030 private boost::noncopyable 00031 { 00032 public: 00033 00035 plugin_service(void) {} 00036 00038 virtual ~plugin_service() {} 00039 00046 virtual void operator()(http::request_ptr& http_request_ptr, tcp::connection_ptr& tcp_conn) = 0; 00047 00054 virtual void set_option(const std::string& name, const std::string& value) { 00055 BOOST_THROW_EXCEPTION( error::bad_arg() << error::errinfo_arg_name(name) ); 00056 } 00057 00059 virtual void start(void) {} 00060 00062 virtual void stop(void) {} 00063 00065 inline void set_resource(const std::string& str) { m_resource = str; } 00066 00068 inline const std::string& get_resource(void) const { return m_resource; } 00069 00071 inline std::string get_relative_resource(const std::string& resource_requested) const { 00072 if (resource_requested.size() <= get_resource().size()) { 00073 // either the request matches the web service's resource path (a directory) 00074 // or the request does not match (should never happen) 00075 return std::string(); 00076 } 00077 // strip the web service's resource path plus the slash after it 00078 return algorithm::url_decode(resource_requested.substr(get_resource().size() + 1)); 00079 } 00080 00081 00082 private: 00083 00085 std::string m_resource; 00086 }; 00087 00088 00089 // 00090 // The following symbols must be defined for any web service that you would 00091 // like to be able to load dynamically using the http::server::load_service() 00092 // function. These are not required for any services that you only want to link 00093 // directly into your programs. 00094 // 00095 // Make sure that you replace "MyPluginName" with the name of your derived class. 00096 // This name must also match the name of the object file (excluding the 00097 // extension). These symbols must be linked into your service's object file, 00098 // not included in any headers that it may use (declarations are OK in headers 00099 // but not the definitions). 00100 // 00101 // The "pion_create" function is used to create new instances of your service. 00102 // The "pion_destroy" function is used to destroy instances of your service. 00103 // 00104 // extern "C" MyPluginName *pion_create_MyPluginName(void) { 00105 // return new MyPluginName; 00106 // } 00107 // 00108 // extern "C" void pion_destroy_MyPluginName(MyPluginName *service_ptr) { 00109 // delete service_ptr; 00110 // } 00111 // 00112 00113 00114 } // end namespace http 00115 } // end namespace pion 00116 00117 #endif