summaryrefslogtreecommitdiffstats
path: root/source/cWebPlugin_Lua.cpp
diff options
context:
space:
mode:
authorfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-01 01:02:48 +0100
committerfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-01 01:02:48 +0100
commit28bc14e267daff85d66efc9467f40ce87bfcb858 (patch)
treea2ab38d5f8805c64294905a4b65b694d6dfeacf7 /source/cWebPlugin_Lua.cpp
parentChanged how Lua handles the (Post)Params in the HTTPRequest of a WebPlugin (diff)
downloadcuberite-28bc14e267daff85d66efc9467f40ce87bfcb858.tar
cuberite-28bc14e267daff85d66efc9467f40ce87bfcb858.tar.gz
cuberite-28bc14e267daff85d66efc9467f40ce87bfcb858.tar.bz2
cuberite-28bc14e267daff85d66efc9467f40ce87bfcb858.tar.lz
cuberite-28bc14e267daff85d66efc9467f40ce87bfcb858.tar.xz
cuberite-28bc14e267daff85d66efc9467f40ce87bfcb858.tar.zst
cuberite-28bc14e267daff85d66efc9467f40ce87bfcb858.zip
Diffstat (limited to '')
-rw-r--r--source/cWebPlugin_Lua.cpp41
1 files changed, 30 insertions, 11 deletions
diff --git a/source/cWebPlugin_Lua.cpp b/source/cWebPlugin_Lua.cpp
index d1446ba24..bb3f79226 100644
--- a/source/cWebPlugin_Lua.cpp
+++ b/source/cWebPlugin_Lua.cpp
@@ -8,7 +8,20 @@
#include "cWebAdmin.h"
-
+static std::string SafeString( const std::string& 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;
+}
extern bool report_errors(lua_State* lua, int status);
@@ -47,7 +60,7 @@ bool cWebPlugin_Lua::AddTab( const char* a_Title, lua_State * a_LuaState, int a_
}
sWebPluginTab* Tab = new sWebPluginTab();
Tab->Title = a_Title;
- Tab->SafeTitle = a_Title; // TODO - Convert all non alphabet/digit letters to underscores
+ Tab->SafeTitle = SafeString( a_Title );
Tab->Reference = a_FunctionReference;
@@ -60,14 +73,15 @@ std::string cWebPlugin_Lua::HandleRequest( HTTPRequest* a_Request )
lua_State* LuaState = m_Plugin->GetLuaState();
std::string RetVal = "";
- std::string TabName = GetTabNameForRequest(a_Request);
- if( TabName.empty() )
+ std::pair< std::string, std::string > TabName = GetTabNameForRequest(a_Request);
+ std::string SafeTabName = TabName.second;
+ if( SafeTabName.empty() )
return "";
sWebPluginTab* Tab = 0;
for( TabList::iterator itr = m_Tabs.begin(); itr != m_Tabs.end(); ++itr )
{
- if( (*itr)->Title.compare( TabName ) == 0 ) // This is the one! Rawr
+ if( (*itr)->SafeTitle.compare( SafeTabName ) == 0 ) // This is the one! Rawr
{
Tab = *itr;
break;
@@ -113,8 +127,9 @@ void cWebPlugin_Lua::Initialize()
{
}
-std::string cWebPlugin_Lua::GetTabNameForRequest( HTTPRequest* a_Request )
+std::pair< std::string, std::string > cWebPlugin_Lua::GetTabNameForRequest( HTTPRequest* a_Request )
{
+ std::pair< std::string, std::string > Names;
std::vector<std::string> Split = StringSplit( a_Request->Path, "/" );
if( Split.size() > 1 )
@@ -139,19 +154,23 @@ std::string cWebPlugin_Lua::GetTabNameForRequest( HTTPRequest* a_Request )
if( Tab )
{
- return Tab->Title;
+ Names.first = Tab->Title;
+ Names.second = Tab->SafeTitle;
}
}
- return "";
+ return Names;
}
-std::list< std::string > cWebPlugin_Lua::GetTabNames()
+std::list< std::pair<std::string, std::string> > cWebPlugin_Lua::GetTabNames()
{
- std::list< std::string > NameList;
+ std::list< std::pair< std::string, std::string > > NameList;
for( TabList::iterator itr = m_Tabs.begin(); itr != m_Tabs.end(); ++itr )
{
- NameList.push_back( (*itr)->Title );
+ std::pair< std::string, std::string > StringPair;
+ StringPair.first = (*itr)->Title;
+ StringPair.second = (*itr)->SafeTitle;
+ NameList.push_back( StringPair );
}
return NameList;
} \ No newline at end of file