8 #include "src/SocketClient.h"
9 #include "src/buffer.h"
11 #include "libicq2000/exceptions.h"
13 using namespace ICQ2000
;
15 class HTTPRequestEvent
: public MessageEvent
{
16 friend class HTTPClient
;
31 string m_content
, m_url
, m_httpresp
, m_user
, m_pass
;
32 vector
<pair
<string
, string
> > params
;
33 map
<string
, string
> authparams
;
34 int authTries
, connectTries
;
37 AuthMethod authmethod
;
40 HTTPRequestEvent(const string
&url
, RequestMethod rt
= GET
)
41 : MessageEvent(ContactRef()), m_url(url
),
42 authTries(0), connectTries(0), method(rt
) { }
44 string
getContent() const { return m_content
; }
45 string
getURL() const { return m_url
; }
46 string
getHTTPResp() const { return m_httpresp
; }
48 MessageType
getType() const { return Normal
; }
49 RequestMethod
getMethod() const { return method
; }
51 void setContent(const string
&content
) { m_content
= content
; }
52 void setHTTPResp(const string
&resp
) { m_httpresp
= resp
; }
54 void setAuth(AuthMethod am
, const string
&user
, const string
&pass
)
55 { authmethod
= am
; m_user
= user
; m_pass
= pass
; }
57 void addParam(const string pname
, const string pval
)
58 { params
.push_back(make_pair(mime(pname
), mime(pval
))); }
60 vector
<pair
<string
, string
> >::const_iterator
pbegin() const { return params
.begin(); }
61 vector
<pair
<string
, string
> >::const_iterator
pend() const { return params
.end(); }
63 bool operator == (HTTPRequestEvent
&ev
) const
64 { return m_url
== ev
.m_url
&& params
== ev
.params
&& method
== ev
.method
; }
66 bool operator != (HTTPRequestEvent
&ev
) const
67 { return !(*this == ev
); }
70 class HTTPClient
: public SocketClient
{
81 list
<HTTPRequestEvent
*> m_queue
;
86 string m_hostname
, m_proxy_hostname
;
87 string m_proxy_user
, m_proxy_passwd
;
88 string m_resource
, m_content
, m_redirect
;
89 unsigned short m_port
, m_proxy_port
;
90 unsigned long m_length
;
91 time_t m_last_operation
, m_timeout
;
101 void check_timeout();
102 string
strMethod(HTTPRequestEvent::RequestMethod m
);
109 void FinishNonBlockingConnect();
112 void setTimeout(time_t t
);
113 time_t getTimeout() const;
115 void clearoutMessagesPoll();
116 void SendEvent(MessageEvent
* ev
);
118 void socket_cb(int fd
, SocketEvent::Mode m
);
120 void setProxyServerHost(const string
& host
) { m_proxy_hostname
= host
; }
121 string
getProxyServerHost() const { return m_proxy_hostname
; }
123 void setProxyServerPort(const unsigned short& port
) { m_proxy_port
= port
; }
124 unsigned short getProxyServerPort() const { return m_proxy_port
; }
126 void setProxyServerUser(const string
& user
) { m_proxy_user
= user
; }
127 string
getProxyServerUser() const { return m_proxy_user
; }
129 void setProxyServerPasswd(const string
& passwd
) { m_proxy_passwd
= passwd
; }
130 string
getProxyServerPasswd() const { return m_proxy_passwd
; }
133 class HTTPException
: public exception
{
139 HTTPException(const string
& text
): m_errortext(text
) {};
140 ~HTTPException() throw() {}
142 const char* what() const throw() { return m_errortext
.c_str(); }