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/PionAlgorithms.hpp>
00017 #include <pion/net/HTTPRequest.hpp>
00018 #include <pion/net/TCPConnection.hpp>
00019 #include <string>
00020
00021
00022 namespace pion {
00023 namespace net {
00024
00028 class WebService :
00029 private boost::noncopyable
00030 {
00031 public:
00032
00034 class UnknownOptionException : public PionException {
00035 public:
00036 UnknownOptionException(const std::string& name)
00037 : PionException("Option not recognized by web service: ", name) {}
00038 };
00039
00041 WebService(void) {}
00042
00044 virtual ~WebService() {}
00045
00052 virtual void operator()(HTTPRequestPtr& request, TCPConnectionPtr& tcp_conn) = 0;
00053
00060 virtual void setOption(const std::string& name, const std::string& value) {
00061 throw UnknownOptionException(name);
00062 }
00063
00065 virtual void start(void) {}
00066
00068 virtual void stop(void) {}
00069
00071 inline void setResource(const std::string& str) { m_resource = str; }
00072
00074 inline const std::string& getResource(void) const { return m_resource; }
00075
00077 inline std::string getRelativeResource(const std::string& resource_requested) const {
00078 if (resource_requested.size() <= getResource().size()) {
00079
00080
00081 return std::string();
00082 }
00083
00084 return algo::url_decode(resource_requested.substr(getResource().size() + 1));
00085 }
00086
00087
00088 private:
00089
00091 std::string m_resource;
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
00122 #endif