summaryrefslogtreecommitdiffstats
path: root/src/Bindings
diff options
context:
space:
mode:
authorworktycho <work.tycho@gmail.com>2015-12-26 20:01:37 +0100
committerworktycho <work.tycho@gmail.com>2015-12-26 20:01:37 +0100
commitb99b60720a3bb5c19032c330028b91f5faf7f4c2 (patch)
treeccbcdc4e3771a5ca4415438e8b631a6dfbdd0944 /src/Bindings
parentMerge pull request #2789 from cuberite/apidump-analytics (diff)
parentAdded the cUrlParser class, exported to Lua API. (diff)
downloadcuberite-b99b60720a3bb5c19032c330028b91f5faf7f4c2.tar
cuberite-b99b60720a3bb5c19032c330028b91f5faf7f4c2.tar.gz
cuberite-b99b60720a3bb5c19032c330028b91f5faf7f4c2.tar.bz2
cuberite-b99b60720a3bb5c19032c330028b91f5faf7f4c2.tar.lz
cuberite-b99b60720a3bb5c19032c330028b91f5faf7f4c2.tar.xz
cuberite-b99b60720a3bb5c19032c330028b91f5faf7f4c2.tar.zst
cuberite-b99b60720a3bb5c19032c330028b91f5faf7f4c2.zip
Diffstat (limited to 'src/Bindings')
-rw-r--r--src/Bindings/CMakeLists.txt2
-rw-r--r--src/Bindings/ManualBindings.cpp159
2 files changed, 160 insertions, 1 deletions
diff --git a/src/Bindings/CMakeLists.txt b/src/Bindings/CMakeLists.txt
index a53e82581..702d38365 100644
--- a/src/Bindings/CMakeLists.txt
+++ b/src/Bindings/CMakeLists.txt
@@ -154,5 +154,5 @@ endif()
if(NOT MSVC)
add_library(Bindings ${SRCS} ${HDRS})
- target_link_libraries(Bindings lua sqlite tolualib mbedtls)
+ target_link_libraries(Bindings lua sqlite tolualib mbedtls HTTPServer)
endif()
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp
index 3a595c1d2..42e7e9bd2 100644
--- a/src/Bindings/ManualBindings.cpp
+++ b/src/Bindings/ManualBindings.cpp
@@ -36,6 +36,7 @@
#include "../StringCompression.h"
#include "../CommandOutput.h"
#include "../BuildInfo.h"
+#include "../HTTPServer/UrlParser.h"
@@ -1956,6 +1957,155 @@ static int tolua_get_HTTPRequest_FormData(lua_State* tolua_S)
+static int tolua_cUrlParser_GetDefaultPort(lua_State * a_LuaState)
+{
+ // API function signature:
+ // cUrlParser:GetDefaultPort("scheme") -> number
+
+ // Check params:
+ cLuaState L(a_LuaState);
+ if (
+ !L.CheckParamUserTable(1, "cUrlParser") ||
+ !L.CheckParamString(2) ||
+ !L.CheckParamEnd(3)
+ )
+ {
+ return 0;
+ }
+
+ // Read params from Lua:
+ AString scheme;
+ L.GetStackValue(2, scheme);
+
+ // Execute and push result:
+ L.Push(cUrlParser::GetDefaultPort(scheme));
+ return 1;
+}
+
+
+
+
+
+static int tolua_cUrlParser_IsKnownScheme(lua_State * a_LuaState)
+{
+ // API function signature:
+ // cUrlParser:IsKnownScheme("scheme") -> bool
+
+ // Check params:
+ cLuaState L(a_LuaState);
+ if (
+ !L.CheckParamUserTable(1, "cUrlParser") ||
+ !L.CheckParamString(2) ||
+ !L.CheckParamEnd(3)
+ )
+ {
+ return 0;
+ }
+
+ // Read params from Lua:
+ AString scheme;
+ L.GetStackValue(2, scheme);
+
+ // Execute and push result:
+ L.Push(cUrlParser::IsKnownScheme(scheme));
+ return 1;
+}
+
+
+
+
+
+static int tolua_cUrlParser_Parse(lua_State * a_LuaState)
+{
+ // API function signature:
+ // cUrlParser:Parse("url") -> "scheme", "user", "password", "host", portnum, "path", "query", "fragment"
+ // On error, returns nil and error message
+
+ // Check params:
+ cLuaState L(a_LuaState);
+ if (
+ !L.CheckParamUserTable(1, "cUrlParser") ||
+ !L.CheckParamString(2) ||
+ !L.CheckParamEnd(3)
+ )
+ {
+ return 0;
+ }
+
+ // Read params from Lua:
+ AString url;
+ L.GetStackValue(2, url);
+
+ // Execute and push result:
+ AString scheme, username, password, host, path, query, fragment;
+ UInt16 port;
+ auto res = cUrlParser::Parse(url, scheme, username, password, host, port, path, query, fragment);
+ if (!res.first)
+ {
+ // Error, return nil and error msg:
+ L.PushNil();
+ L.Push(res.second);
+ return 2;
+ }
+ L.Push(scheme);
+ L.Push(username);
+ L.Push(password);
+ L.Push(host);
+ L.Push(port);
+ L.Push(path);
+ L.Push(query);
+ L.Push(fragment);
+ return 8;
+}
+
+
+
+
+
+static int tolua_cUrlParser_ParseAuthorityPart(lua_State * a_LuaState)
+{
+ // API function signature:
+ // cUrlParser:ParseAuthorityPart("authority") -> "user", "password", "host", portnum
+ // On error, returns nil and error message
+ // Parts not specified in the "authority" are left empty / zero
+
+ // Check params:
+ cLuaState L(a_LuaState);
+ if (
+ !L.CheckParamUserTable(1, "cUrlParser") ||
+ !L.CheckParamString(2) ||
+ !L.CheckParamEnd(3)
+ )
+ {
+ return 0;
+ }
+
+ // Read params from Lua:
+ AString authPart;
+ L.GetStackValue(2, authPart);
+
+ // Execute and push result:
+ AString username, password, host;
+ UInt16 port;
+ auto res = cUrlParser::ParseAuthorityPart(authPart, username, password, host, port);
+ if (!res.first)
+ {
+ // Error, return nil and error msg:
+ L.PushNil();
+ L.Push(res.second);
+ return 2;
+ }
+ L.Push(username);
+ L.Push(password);
+ L.Push(host);
+ L.Push(port);
+ return 4;
+}
+
+
+
+
+
static int tolua_cWebAdmin_GetPlugins(lua_State * tolua_S)
{
cWebAdmin * self = reinterpret_cast<cWebAdmin *>(tolua_tousertype(tolua_S, 1, nullptr));
@@ -3224,9 +3374,11 @@ void cManualBindings::Bind(lua_State * tolua_S)
tolua_usertype(tolua_S, "cCryptoHash");
tolua_usertype(tolua_S, "cLineBlockTracer");
tolua_usertype(tolua_S, "cStringCompression");
+ tolua_usertype(tolua_S, "cUrlParser");
tolua_cclass(tolua_S, "cCryptoHash", "cCryptoHash", "", nullptr);
tolua_cclass(tolua_S, "cLineBlockTracer", "cLineBlockTracer", "", nullptr);
tolua_cclass(tolua_S, "cStringCompression", "cStringCompression", "", nullptr);
+ tolua_cclass(tolua_S, "cUrlParser", "cUrlParser", "", nullptr);
// Globals:
tolua_function(tolua_S, "Clamp", tolua_Clamp);
@@ -3390,6 +3542,13 @@ void cManualBindings::Bind(lua_State * tolua_S)
tolua_function(tolua_S, "InflateString", tolua_InflateString);
tolua_endmodule(tolua_S);
+ tolua_beginmodule(tolua_S, "cUrlParser");
+ tolua_function(tolua_S, "GetDefaultPort", tolua_cUrlParser_GetDefaultPort);
+ tolua_function(tolua_S, "IsKnownScheme", tolua_cUrlParser_IsKnownScheme);
+ tolua_function(tolua_S, "Parse", tolua_cUrlParser_Parse);
+ tolua_function(tolua_S, "ParseAuthorityPart", tolua_cUrlParser_ParseAuthorityPart);
+ tolua_endmodule(tolua_S);
+
tolua_beginmodule(tolua_S, "cWebAdmin");
tolua_function(tolua_S, "GetHTMLEscapedString", tolua_AllToLua_cWebAdmin_GetHTMLEscapedString);
tolua_function(tolua_S, "GetPlugins", tolua_cWebAdmin_GetPlugins);