2012-06-14 09:06:06 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../WebServer/WebServer.h"
|
2012-09-23 17:23:33 -04:00
|
|
|
#include "OSSupport/Socket.h"
|
2013-08-08 10:30:02 -04:00
|
|
|
#include "LuaState.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-08-08 10:30:02 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// fwd:
|
2012-06-14 09:06:06 -04:00
|
|
|
class cStringMap;
|
2013-08-08 10:30:02 -04:00
|
|
|
class cEvent;
|
|
|
|
class cIniFile;
|
|
|
|
class cWebPlugin;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// tolua_begin
|
|
|
|
struct HTTPFormData
|
|
|
|
{
|
|
|
|
std::string Name;
|
|
|
|
std::string Value;
|
|
|
|
std::string Type;
|
|
|
|
} ;
|
|
|
|
// tolua_end
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
|
2013-08-08 10:30:02 -04:00
|
|
|
|
|
|
|
// tolua_begin
|
|
|
|
struct HTTPRequest
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
typedef std::map< std::string, std::string > StringStringMap;
|
|
|
|
typedef std::map< std::string, HTTPFormData > FormDataMap;
|
2013-08-08 10:30:02 -04:00
|
|
|
|
|
|
|
AString Method;
|
|
|
|
AString Path;
|
|
|
|
AString Username;
|
|
|
|
// tolua_end
|
2013-07-28 20:37:59 -04:00
|
|
|
StringStringMap Params; // >> EXPORTED IN MANUALBINDINGS <<
|
|
|
|
StringStringMap PostParams; // >> EXPORTED IN MANUALBINDINGS <<
|
|
|
|
FormDataMap FormData; // >> EXPORTED IN MANUALBINDINGS <<
|
2013-08-08 10:30:02 -04:00
|
|
|
} ; // tolua_export
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// tolua_begin
|
|
|
|
struct HTTPTemplateRequest
|
|
|
|
{
|
|
|
|
HTTPRequest Request;
|
|
|
|
} ;
|
|
|
|
// tolua_end
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-07-28 20:37:59 -04:00
|
|
|
|
|
|
|
|
|
|
|
// tolua_begin
|
|
|
|
struct sWebAdminPage
|
|
|
|
{
|
|
|
|
AString Content;
|
|
|
|
AString PluginName;
|
|
|
|
AString TabName;
|
|
|
|
};
|
|
|
|
// tolua_end
|
|
|
|
|
|
|
|
|
2013-08-08 10:30:02 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// tolua_begin
|
|
|
|
class cWebAdmin
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// tolua_end
|
|
|
|
|
|
|
|
typedef std::list< cWebPlugin* > PluginList;
|
|
|
|
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
cWebAdmin( int a_Port = 8080 );
|
|
|
|
~cWebAdmin();
|
|
|
|
|
2013-07-28 20:37:59 -04:00
|
|
|
bool Init( int a_Port );
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-07-28 20:37:59 -04:00
|
|
|
void AddPlugin( cWebPlugin* a_Plugin );
|
|
|
|
void RemovePlugin( cWebPlugin* a_Plugin );
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-07-28 20:37:59 -04:00
|
|
|
// 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);
|
|
|
|
|
2013-08-08 10:30:02 -04:00
|
|
|
// tolua_begin
|
|
|
|
static AString GetMemoryUsage(void);
|
|
|
|
|
|
|
|
int GetPort() { return m_Port; }
|
|
|
|
|
|
|
|
sWebAdminPage GetPage(const HTTPRequest& a_Request);
|
|
|
|
AString GetBaseURL(const AString& a_URL);
|
|
|
|
|
|
|
|
// tolua_end
|
2012-09-30 12:37:44 -04:00
|
|
|
|
2013-07-28 20:37:59 -04:00
|
|
|
AString GetBaseURL(const AStringVector& a_URLSplit);
|
|
|
|
|
2013-08-08 10:30:02 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
private:
|
2013-08-08 10:30:02 -04:00
|
|
|
int m_Port;
|
|
|
|
|
|
|
|
bool m_bConnected;
|
|
|
|
cSocket m_ListenSocket;
|
|
|
|
|
|
|
|
cIniFile * m_IniFile;
|
|
|
|
PluginList m_Plugins;
|
|
|
|
|
|
|
|
cEvent * m_Event;
|
|
|
|
|
|
|
|
webserver * m_WebServer;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-08-08 10:30:02 -04:00
|
|
|
/// The Lua template script to provide templates:
|
|
|
|
cLuaState m_TemplateScript;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-07-28 20:37:59 -04:00
|
|
|
|
2013-08-08 10:30:02 -04:00
|
|
|
#ifdef _WIN32
|
|
|
|
static DWORD WINAPI ListenThread(LPVOID lpParam);
|
|
|
|
#else
|
|
|
|
static void * ListenThread(void * lpParam);
|
|
|
|
#endif
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-08-08 10:30:02 -04:00
|
|
|
AString GetTemplate();
|
|
|
|
} ; // tolua_export
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|