blob: 7b710bd3b610ffda5ed49c173c656519be644fc9 (
plain) (
blame)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
#pragma once
#include "../WebServer/WebServer.h"
#include "OSSupport/Socket.h"
#include "LuaState.h"
// fwd:
class cStringMap;
class cEvent;
class cIniFile;
class cWebPlugin;
// tolua_begin
struct HTTPFormData
{
std::string Name;
std::string Value;
std::string Type;
} ;
// tolua_end
// tolua_begin
struct HTTPRequest
{
typedef std::map< std::string, std::string > StringStringMap;
typedef std::map< std::string, HTTPFormData > FormDataMap;
AString Method;
AString Path;
AString Username;
// tolua_end
StringStringMap Params; // >> EXPORTED IN MANUALBINDINGS <<
StringStringMap PostParams; // >> EXPORTED IN MANUALBINDINGS <<
FormDataMap FormData; // >> EXPORTED IN MANUALBINDINGS <<
} ; // tolua_export
// tolua_begin
struct HTTPTemplateRequest
{
HTTPRequest Request;
} ;
// tolua_end
// tolua_begin
struct sWebAdminPage
{
AString Content;
AString PluginName;
AString TabName;
};
// tolua_end
// tolua_begin
class cWebAdmin
{
public:
// tolua_end
typedef std::list< cWebPlugin* > PluginList;
cWebAdmin( int a_Port = 8080 );
~cWebAdmin();
bool Init( int a_Port );
void AddPlugin( cWebPlugin* a_Plugin );
void RemovePlugin( cWebPlugin* a_Plugin );
// TODO: Convert this to the auto-locking callback mechanism used for looping players in worlds and such
PluginList GetPlugins() const { return m_Plugins; } // >> EXPORTED IN MANUALBINDINGS <<
static void Request_Handler(webserver::http_request* r);
// tolua_begin
/// Returns the amount of currently used memory, in KiB, or -1 if it cannot be queried
static int GetMemoryUsage(void);
int GetPort() { return m_Port; }
sWebAdminPage GetPage(const HTTPRequest& a_Request);
AString GetBaseURL(const AString& a_URL);
// tolua_end
AString GetBaseURL(const AStringVector& a_URLSplit);
private:
int m_Port;
bool m_bConnected;
cSocket m_ListenSocket;
cIniFile * m_IniFile;
PluginList m_Plugins;
cEvent * m_Event;
webserver * m_WebServer;
/// The Lua template script to provide templates:
cLuaState m_TemplateScript;
#ifdef _WIN32
static DWORD WINAPI ListenThread(LPVOID lpParam);
#else
static void * ListenThread(void * lpParam);
#endif
AString GetTemplate();
} ; // tolua_export
|