00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef _SOCKETS_HTTPSocket_H
00031 #define _SOCKETS_HTTPSocket_H
00032
00033 #include "sockets-config.h"
00034 #include <map>
00035 #include "TcpSocket.h"
00036
00037 #ifdef SOCKETS_NAMESPACE
00038 namespace SOCKETS_NAMESPACE {
00039 #endif
00040
00044 class HTTPSocket : public TcpSocket
00045 {
00047 typedef std::map<std::string,std::string> string_m;
00048 public:
00049 HTTPSocket(ISocketHandler& );
00050 ~HTTPSocket();
00051
00052
00054
00055 void OnRawData(const char *buf,size_t len);
00056 void OnLine(const std::string& line);
00057
00060 virtual void OnFirst() = 0;
00064 virtual void OnHeader(const std::string& key,const std::string& value) = 0;
00066 virtual void OnHeaderComplete() = 0;
00068 virtual void OnData(const char *,size_t) = 0;
00069
00071 const std::string& GetMethod();
00073 void SetMethod(const std::string& x);
00075 const std::string& GetUrl();
00077 void SetUrl(const std::string& x);
00079 const std::string& GetUri();
00081 void SetUri(const std::string& x);
00083 const std::string& GetQueryString();
00085 const std::string& GetHttpVersion();
00087 const std::string& GetStatus();
00089 const std::string& GetStatusText();
00091 bool IsRequest();
00093 bool IsResponse();
00095 void SetHttpVersion(const std::string& x);
00097 void SetStatus(const std::string& x);
00099 void SetStatusText(const std::string& x);
00101 void AddResponseHeader(const std::string& x,const std::string& y);
00103 void AddResponseHeader(const std::string& x,const char *format, ...);
00106 void SendResponse();
00109 void SendRequest();
00110
00112 virtual std::string MyUseragent();
00113
00115 void url_this(const std::string& url_in,std::string& protocol,std::string& host,port_t& port,std::string& url,std::string& file);
00116
00117 protected:
00118 HTTPSocket(const HTTPSocket& s) : TcpSocket(s) {}
00120 virtual void Reset();
00121
00122 private:
00123 HTTPSocket& operator=(const HTTPSocket& ) { return *this; }
00124 bool m_first;
00125 bool m_header;
00126 std::string m_line;
00127 std::string m_method;
00128 std::string m_url;
00129 std::string m_uri;
00130 std::string m_query_string;
00131 std::string m_http_version;
00132 std::string m_status;
00133 std::string m_status_text;
00134 bool m_request;
00135 bool m_response;
00136 string_m m_response_header;
00137 };
00138
00139
00140
00141
00142 #ifdef SOCKETS_NAMESPACE
00143 }
00144 #endif
00145
00146 #endif // _SOCKETS_HTTPSocket_H