Files
cuberite-2a/source/WebAdmin.h
T

139 lines
2.2 KiB
C++
Raw Normal View History

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