]> git.saurik.com Git - wxWidgets.git/blob - include/wx/protocol/http.h
Implement wxNotificationMessage using libnotify in wxGTK.
[wxWidgets.git] / include / wx / protocol / http.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/protocol/http.h
3 // Purpose: HTTP protocol
4 // Author: Guilhem Lavaux
5 // Modified by: Simo Virokannas (authentication, Dec 2005)
6 // Created: August 1997
7 // RCS-ID: $Id$
8 // Copyright: (c) 1997, 1998 Guilhem Lavaux
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_HTTP_H
12 #define _WX_HTTP_H
13
14 #include "wx/defs.h"
15
16 #if wxUSE_PROTOCOL_HTTP
17
18 #include "wx/hashmap.h"
19 #include "wx/protocol/protocol.h"
20 #include "wx/buffer.h"
21
22 class WXDLLIMPEXP_NET wxHTTP : public wxProtocol
23 {
24 public:
25 wxHTTP();
26 virtual ~wxHTTP();
27
28 virtual bool Connect(const wxString& host, unsigned short port);
29 virtual bool Connect(const wxString& host) { return Connect(host, 0); }
30 virtual bool Connect(const wxSockAddress& addr, bool wait);
31 bool Abort();
32
33 wxInputStream *GetInputStream(const wxString& path);
34
35 wxString GetContentType() const;
36 wxString GetHeader(const wxString& header) const;
37 int GetResponse() const { return m_http_response; }
38
39 void SetHeader(const wxString& header, const wxString& h_data);
40 bool SetPostText(const wxString& contentType,
41 const wxString& data,
42 const wxMBConv& conv = wxConvUTF8);
43 bool SetPostBuffer(const wxString& contentType, const wxMemoryBuffer& data);
44 void SetProxyMode(bool on);
45
46 /* Cookies */
47 wxString GetCookie(const wxString& cookie) const;
48 bool HasCookies() const { return m_cookies.size() > 0; }
49
50 // Use the other SetPostBuffer() overload or SetPostText() instead.
51 wxDEPRECATED(void SetPostBuffer(const wxString& post_buf));
52
53 protected:
54 enum wxHTTP_Req
55 {
56 wxHTTP_GET,
57 wxHTTP_POST,
58 wxHTTP_HEAD
59 };
60
61 typedef wxStringToStringHashMap::iterator wxHeaderIterator;
62 typedef wxStringToStringHashMap::const_iterator wxHeaderConstIterator;
63 typedef wxStringToStringHashMap::iterator wxCookieIterator;
64 typedef wxStringToStringHashMap::const_iterator wxCookieConstIterator;
65
66 bool BuildRequest(const wxString& path, wxHTTP_Req req);
67 void SendHeaders();
68 bool ParseHeaders();
69
70 wxString GenerateAuthString(const wxString& user, const wxString& pass) const;
71
72 // find the header in m_headers
73 wxHeaderIterator FindHeader(const wxString& header);
74 wxHeaderConstIterator FindHeader(const wxString& header) const;
75 wxCookieIterator FindCookie(const wxString& cookie);
76 wxCookieConstIterator FindCookie(const wxString& cookie) const;
77
78 // deletes the header value strings
79 void ClearHeaders();
80 void ClearCookies();
81
82 // internal variables:
83
84 wxStringToStringHashMap m_cookies;
85
86 wxStringToStringHashMap m_headers;
87 bool m_read,
88 m_proxy_mode;
89 wxSockAddress *m_addr;
90 wxMemoryBuffer m_postBuffer;
91 wxString m_contentType;
92 int m_http_response;
93
94 DECLARE_DYNAMIC_CLASS(wxHTTP)
95 DECLARE_PROTOCOL(wxHTTP)
96 wxDECLARE_NO_COPY_CLASS(wxHTTP);
97 };
98
99 #endif // wxUSE_PROTOCOL_HTTP
100
101 #endif // _WX_HTTP_H
102