00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef __PION_WEBSERVICE_HEADER__
00011 #define __PION_WEBSERVICE_HEADER__
00012
00013 #include <boost/noncopyable.hpp>
00014 #include <pion/PionConfig.hpp>
00015 #include <pion/PionException.hpp>
00016 #include <pion/net/HTTPRequest.hpp>
00017 #include <pion/net/TCPConnection.hpp>
00018 #include <string>
00019
00020
00021 namespace pion {
00022 namespace net {
00023
00027 class WebService :
00028 private boost::noncopyable
00029 {
00030 public:
00031
00033 class UnknownOptionException : public PionException {
00034 public:
00035 UnknownOptionException(const std::string& name)
00036 : PionException("Option not recognized by web service: ", name) {}
00037 };
00038
00040 WebService(void) {}
00041
00043 virtual ~WebService() {}
00044
00051 virtual void operator()(HTTPRequestPtr& request, TCPConnectionPtr& tcp_conn) = 0;
00052
00059 virtual void setOption(const std::string& name, const std::string& value) {
00060 throw UnknownOptionException(name);
00061 }
00062
00064 virtual void start(void) {}
00065
00067 virtual void stop(void) {}
00068
00070 inline void setResource(const std::string& str) { m_resource = str; }
00071
00073 inline const std::string& getResource(void) const { return m_resource; }
00074
00076 inline std::string getRelativeResource(const std::string& resource_requested) const {
00077 if (resource_requested.size() <= getResource().size()) {
00078
00079
00080 return std::string();
00081 }
00082
00083 return HTTPTypes::url_decode(resource_requested.substr(getResource().size() + 1));
00084 }
00085
00086
00087 private:
00088
00090 std::string m_resource;
00091 };
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 }
00119 }
00120
00121 #endif