]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: 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 | ||
21 | WX_DECLARE_STRING_HASH_MAP_WITH_DECL( wxString, wxStringToStringHashMap, | |
22 | class WXDLLIMPEXP_NET ); | |
23 | ||
24 | class WXDLLIMPEXP_NET wxHTTP : public wxProtocol | |
25 | { | |
26 | public: | |
27 | wxHTTP(); | |
28 | ~wxHTTP(); | |
29 | ||
30 | virtual bool Connect(const wxString& host, unsigned short port); | |
31 | virtual bool Connect(const wxString& host) { return Connect(host, 0); } | |
32 | virtual bool Connect(wxSockAddress& addr, bool wait); | |
33 | bool Abort(); | |
34 | wxInputStream *GetInputStream(const wxString& path); | |
35 | inline wxProtocolError GetError() { return m_perr; } | |
36 | wxString GetContentType(); | |
37 | ||
38 | void SetHeader(const wxString& header, const wxString& h_data); | |
39 | wxString GetHeader(const wxString& header) const; | |
40 | void SetPostBuffer(const wxString& post_buf); | |
41 | ||
42 | void SetProxyMode(bool on); | |
43 | ||
44 | int GetResponse() { return m_http_response; } | |
45 | ||
46 | virtual void SetUser(const wxString& user) { m_username = user; } | |
47 | virtual void SetPassword(const wxString& passwd ) { m_password = passwd; } | |
48 | ||
49 | protected: | |
50 | enum wxHTTP_Req | |
51 | { | |
52 | wxHTTP_GET, | |
53 | wxHTTP_POST, | |
54 | wxHTTP_HEAD | |
55 | }; | |
56 | ||
57 | typedef wxStringToStringHashMap::iterator wxHeaderIterator; | |
58 | typedef wxStringToStringHashMap::const_iterator wxHeaderConstIterator; | |
59 | ||
60 | bool BuildRequest(const wxString& path, wxHTTP_Req req); | |
61 | void SendHeaders(); | |
62 | bool ParseHeaders(); | |
63 | ||
64 | wxString GenerateAuthString(const wxString& user, const wxString& pass) const; | |
65 | ||
66 | // find the header in m_headers | |
67 | wxHeaderIterator FindHeader(const wxString& header); | |
68 | wxHeaderConstIterator FindHeader(const wxString& header) const; | |
69 | ||
70 | // deletes the header value strings | |
71 | void ClearHeaders(); | |
72 | ||
73 | wxProtocolError m_perr; | |
74 | wxStringToStringHashMap m_headers; | |
75 | bool m_read, | |
76 | m_proxy_mode; | |
77 | wxSockAddress *m_addr; | |
78 | wxString m_post_buf; | |
79 | int m_http_response; | |
80 | wxString m_username; | |
81 | wxString m_password; | |
82 | ||
83 | DECLARE_DYNAMIC_CLASS(wxHTTP) | |
84 | DECLARE_PROTOCOL(wxHTTP) | |
85 | DECLARE_NO_COPY_CLASS(wxHTTP) | |
86 | }; | |
87 | ||
88 | #endif // wxUSE_PROTOCOL_HTTP | |
89 | ||
90 | #endif // _WX_HTTP_H | |
91 |