1 | #ifndef __EXTERNALIPRESOLVER_H__ |
---|
2 | #define __EXTERNALIPRESOLVER_H__ |
---|
3 | |
---|
4 | #include "socket.h" |
---|
5 | |
---|
6 | struct external_ip_resolve_event_type; |
---|
7 | typedef CEvent<external_ip_resolve_event_type> CExternalIPResolveEvent; |
---|
8 | |
---|
9 | class CExternalIPResolver final : public CEventHandler |
---|
10 | { |
---|
11 | public: |
---|
12 | CExternalIPResolver(CEventHandler & handler); |
---|
13 | virtual ~CExternalIPResolver(); |
---|
14 | |
---|
15 | CExternalIPResolver(CExternalIPResolver const&) = delete; |
---|
16 | CExternalIPResolver& operator=(CExternalIPResolver const&) = delete; |
---|
17 | |
---|
18 | bool Done() const { return m_done; } |
---|
19 | bool Successful() const; |
---|
20 | wxString GetIP() const; |
---|
21 | |
---|
22 | void GetExternalIP(const wxString& address, CSocket::address_family protocol, bool force = false); |
---|
23 | |
---|
24 | protected: |
---|
25 | |
---|
26 | void Close(bool successful); |
---|
27 | |
---|
28 | wxString m_address; |
---|
29 | CSocket::address_family m_protocol{}; |
---|
30 | unsigned long m_port{80}; |
---|
31 | CEventHandler * m_handler{}; |
---|
32 | |
---|
33 | bool m_done{}; |
---|
34 | |
---|
35 | wxString m_data; |
---|
36 | |
---|
37 | CSocket *m_pSocket{}; |
---|
38 | |
---|
39 | virtual void operator()(CEventBase const& ev); |
---|
40 | void OnSocketEvent(CSocketEventSource* source, SocketEventType t, int error); |
---|
41 | |
---|
42 | void OnConnect(int error); |
---|
43 | void OnClose(); |
---|
44 | void OnReceive(); |
---|
45 | void OnHeader(); |
---|
46 | void OnData(char* buffer, unsigned int len); |
---|
47 | void OnChunkedData(); |
---|
48 | void OnSend(); |
---|
49 | |
---|
50 | char* m_pSendBuffer{}; |
---|
51 | unsigned int m_sendBufferPos{}; |
---|
52 | |
---|
53 | char* m_pRecvBuffer{}; |
---|
54 | unsigned int m_recvBufferPos{}; |
---|
55 | |
---|
56 | static const unsigned int m_recvBufferLen = 4096; |
---|
57 | |
---|
58 | // HTTP data |
---|
59 | void ResetHttpData(bool resetRedirectCount); |
---|
60 | bool m_gotHeader{}; |
---|
61 | int m_responseCode{}; |
---|
62 | wxString m_responseString; |
---|
63 | wxString m_location; |
---|
64 | int m_redirectCount{}; |
---|
65 | |
---|
66 | enum transferEncodings |
---|
67 | { |
---|
68 | identity, |
---|
69 | chunked, |
---|
70 | unknown |
---|
71 | }; |
---|
72 | |
---|
73 | transferEncodings m_transferEncoding; |
---|
74 | |
---|
75 | struct t_chunkData |
---|
76 | { |
---|
77 | bool getTrailer{}; |
---|
78 | bool terminateChunk{}; |
---|
79 | int64_t size{}; |
---|
80 | } m_chunkData; |
---|
81 | |
---|
82 | bool m_finished{}; |
---|
83 | }; |
---|
84 | |
---|
85 | #endif //__EXTERNALIPRESOLVER_H__ |
---|