summaryrefslogtreecommitdiffstats
path: root/source/cWebPlugin.cpp
diff options
context:
space:
mode:
authorfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-08-22 16:22:21 +0200
committerfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-08-22 16:22:21 +0200
commit7c84349990f21f783f4b24c113fb372a3c00164b (patch)
tree41cb29e214b98fc5b9c105bdf722a5c236c2318e /source/cWebPlugin.cpp
parentFixed cWebPlugin_Lua being not thread safe. And I don't know why, but it still crashes in Lua sometimes o_O (diff)
downloadcuberite-7c84349990f21f783f4b24c113fb372a3c00164b.tar
cuberite-7c84349990f21f783f4b24c113fb372a3c00164b.tar.gz
cuberite-7c84349990f21f783f4b24c113fb372a3c00164b.tar.bz2
cuberite-7c84349990f21f783f4b24c113fb372a3c00164b.tar.lz
cuberite-7c84349990f21f783f4b24c113fb372a3c00164b.tar.xz
cuberite-7c84349990f21f783f4b24c113fb372a3c00164b.tar.zst
cuberite-7c84349990f21f783f4b24c113fb372a3c00164b.zip
Diffstat (limited to 'source/cWebPlugin.cpp')
-rw-r--r--source/cWebPlugin.cpp87
1 files changed, 85 insertions, 2 deletions
diff --git a/source/cWebPlugin.cpp b/source/cWebPlugin.cpp
index 186662ba8..d0f0c9a9c 100644
--- a/source/cWebPlugin.cpp
+++ b/source/cWebPlugin.cpp
@@ -10,17 +10,100 @@
-cWebPlugin::cWebPlugin( lua_State* L )
+cWebPlugin::cWebPlugin()
{
LOG("cWebPlugin::cWebPlugin()");
- m_LuaState = L;
cWebAdmin* WebAdmin = cRoot::Get()->GetWebAdmin();
if( WebAdmin ) WebAdmin->AddPlugin( this );
}
+
+
+
+
cWebPlugin::~cWebPlugin()
{
LOG("~cWebPlugin::cWebPlugin()");
cWebAdmin* WebAdmin = cRoot::Get()->GetWebAdmin();
if( WebAdmin ) WebAdmin->RemovePlugin( this );
+
+ for( TabList::iterator itr = m_Tabs.begin(); itr != m_Tabs.end(); ++itr )
+ {
+ delete *itr;
+ }
+ m_Tabs.clear();
+}
+
+
+
+
+
+std::list< std::pair<std::string, std::string> > cWebPlugin::GetTabNames()
+{
+ std::list< std::pair< std::string, std::string > > NameList;
+ for( TabList::iterator itr = GetTabs().begin(); itr != GetTabs().end(); ++itr )
+ {
+ std::pair< std::string, std::string > StringPair;
+ StringPair.first = (*itr)->Title;
+ StringPair.second = (*itr)->SafeTitle;
+ NameList.push_back( StringPair );
+ }
+ return NameList;
+}
+
+
+
+
+
+std::pair< std::string, std::string > cWebPlugin::GetTabNameForRequest( HTTPRequest* a_Request )
+{
+ std::pair< std::string, std::string > Names;
+ AStringVector Split = StringSplit(a_Request->Path, "/");
+
+ if( Split.size() > 1 )
+ {
+ sWebPluginTab* Tab = 0;
+ if( Split.size() > 2 ) // If we got the tab name, show that page
+ {
+ for( TabList::iterator itr = GetTabs().begin(); itr != GetTabs().end(); ++itr )
+ {
+ if( (*itr)->SafeTitle.compare( Split[2] ) == 0 ) // This is the one! Rawr
+ {
+ Tab = *itr;
+ break;
+ }
+ }
+ }
+ else // Otherwise show the first tab
+ {
+ if( GetTabs().size() > 0 )
+ Tab = *GetTabs().begin();
+ }
+
+ if( Tab )
+ {
+ Names.first = Tab->Title;
+ Names.second = Tab->SafeTitle;
+ }
+ }
+
+ return Names;
+}
+
+
+
+
+AString cWebPlugin::SafeString( const AString & a_String )
+{
+ std::string RetVal;
+ for( unsigned int i = 0; i < a_String.size(); ++i )
+ {
+ char c = a_String[i];
+ if( c == ' ' )
+ {
+ c = '_';
+ }
+ RetVal.push_back( c );
+ }
+ return RetVal;
} \ No newline at end of file