/
wxWebServer.h
74 lines (59 loc) · 1.93 KB
/
wxWebServer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* (c) 2006 by Magnus Manske
* Released under the terms of the GNU public license (GPL)
* Based on sources in wxMusic
*/
#ifndef WXWEBSERVER_H
#define WXWEBSERVER_H
#include <wx/socket.h>
inline const wxCharBuffer ConvToUTF8( const wxString &s )
{
#if wxUSE_UNICODE
return wxConvUTF8.cWC2MB(s);
#else
return wxConvUTF8.cWC2WX(wxConvCurrent->cMB2WC(s));
#endif
}
class wxWebServer : public wxEvtHandler
{
public:
wxWebServer () ;
virtual ~wxWebServer () ;
virtual void Start(int port);
virtual void Stop();
virtual bool IsRunning();
virtual int GetPort();
virtual wxString GetValue ( wxString key , wxString def = _T("") ) ;
virtual wxString Unescape ( wxString s ) ;
virtual char *spc_decode_url(const char *url, size_t *nbytes) ;
class HttpResponse // Response class
{
public:
HttpResponse();
void Send(wxSocketBase*pSocket);
void SetRC(const wxString & rc);
void AddDataLine(const wxString & data);
void AddHeader(const wxString & Header);
void SetBinaryData(char *data, unsigned long len);
bool Ok(){return !m_sRC.IsEmpty();}
private:
wxString m_sRC;
wxString m_sHeaders;
wxString m_sData;
char *m_sBinaryData ;
unsigned long m_sBinaryDataLength ;
};
DECLARE_EVENT_TABLE()
private:
bool m_running;
int m_port;
wxSocketServer *socket_server;
wxArrayString keys , values ;
virtual void OnServerEvent(wxSocketEvent& event);
virtual void OnSocketEvent(wxSocketEvent& event);
virtual void ProcessRequest(const wxString &reqstr,HttpResponse &hr);
virtual int ReadLine(wxSocketBase*pSocket,wxString& outstr);
virtual void WriteLine(wxSocketBase*pSocket,const wxString &str);
virtual void HandleSimpleGetRequest(const wxString &page,HttpResponse &hr);
} ;
#endif