summaryrefslogtreecommitdiffstats
path: root/Server
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 /Server
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 'Server')
-rw-r--r--Server/Plugins/APIDump/APIDesc.lua45
-rw-r--r--Server/Plugins/Debuggers/Debuggers.lua41
-rw-r--r--Server/Plugins/Debuggers/Info.lua6
3 files changed, 91 insertions, 1 deletions
diff --git a/Server/Plugins/APIDump/APIDesc.lua b/Server/Plugins/APIDump/APIDesc.lua
index 6be3795a8..ad7cf6403 100644
--- a/Server/Plugins/APIDump/APIDesc.lua
+++ b/Server/Plugins/APIDump/APIDesc.lua
@@ -2286,7 +2286,50 @@ local CompressedString = cStringCompression.CompressStringGZIP("DataToCompress")
SetFuseTicks = { Return = "number", Notes = "Set the fuse ticks until the tnt will explode." },
},
Inherits = "cEntity",
- },
+ }, -- cTNTEntity
+
+ cUrlParser =
+ {
+ Desc = [[
+ Provides a parser for generic URLs that returns the individual components of the URL.</p>
+ <p>
+ Note that all functions are static. Call them by using "cUrlParser:Parse(...)" etc.
+ ]],
+ Functions =
+ {
+ GetDefaultPort = { Params = "Scheme", Return = "number", Notes = "(STATIC) Returns the default port that should be used for the given scheme (protocol). Returns zero if the scheme is not known." },
+ IsKnownScheme = { Params = "Scheme", Return = "bool", Notes = "(STATIC) Returns true if the scheme (protocol) is recognized by the parser." },
+ Parse = { Params = "URL", Return = "Scheme, Username, Password, Host, Port, Path, Query, Fragment", Notes = "(STATIC) Returns the individual parts of the URL. Parts that are not explicitly specified in the URL are empty, the default port for the scheme is used. If parsing fails, the function returns nil and an error message." },
+ ParseAuthorityPart = { Params = "AuthPart", Return = "Username, Password, Host, Port", Notes = "(STATIC) Parses the Authority part of the URL. Parts that are not explicitly specified in the AuthPart are returned empty, the port is returned zero. If parsing fails, the function returns nil and an error message." },
+ },
+ AdditionalInfo =
+ {
+ {
+ Header = "Code example",
+ Contents = [==[
+ The following code fragment uses the cUrlParser to parse an URL string into its components, and
+ prints those components out:
+<pre class="prettyprint lang-lua">
+local Scheme, Username, Password, Host, Port, Path, Query, Fragment = cUrlParser:Parse(
+ "http://anonymous:user@example.com@ftp.cuberite.org:9921/releases/2015/?sort=date#files"
+)
+if not(Scheme) then
+ LOG(" Error: " .. (username or "<nil>"))
+else
+ LOG(" Scheme = " .. Scheme) -- "http"
+ LOG(" Username = " .. Username) -- "anonymous"
+ LOG(" Password = " .. Password) -- "user@example.com"
+ LOG(" Host = " .. Host) -- "ftp.cuberite.org"
+ LOG(" Port = " .. Port) -- 9921
+ LOG(" Path = " .. Path) -- "releases/2015/"
+ LOG(" Query = " .. Query) -- "sort=date"
+ LOG(" Fragment = " .. Fragment) -- "files"
+end
+</pre>
+ ]==],
+ },
+ },
+ }, -- cUrlParser
cWebPlugin =
{
diff --git a/Server/Plugins/Debuggers/Debuggers.lua b/Server/Plugins/Debuggers/Debuggers.lua
index 0559a4ef8..7058a5025 100644
--- a/Server/Plugins/Debuggers/Debuggers.lua
+++ b/Server/Plugins/Debuggers/Debuggers.lua
@@ -2030,6 +2030,47 @@ end
+function HandleConsoleTestUrlParser(a_Split, a_EntireCmd)
+ LOG("Testing cUrlParser...")
+ local UrlsToTest =
+ {
+ "invalid URL",
+ "https://github.com",
+ "ftp://anonymous:user@example.com@ftp.cuberite.org:9921/releases/2015/2015-12-25.zip",
+ "ftp://anonymous:user:name:with:colons@example.com@ftp.cuberite.org:9921",
+ "http://google.com/",
+ "http://google.com/?q=cuberite",
+ "http://google.com/search?q=cuberite",
+ "http://google.com/some/search?q=cuberite#results",
+ "http://google.com/?q=cuberite#results",
+ "http://google.com/#results",
+ "ftp://cuberite.org:9921/releases/2015/2015-12-25.zip",
+ "mailto:support@cuberite.org",
+ }
+ for _, u in ipairs(UrlsToTest) do
+ LOG("URL: " .. u)
+ local scheme, username, password, host, port, path, query, fragment = cUrlParser:Parse(u)
+ if not(scheme) then
+ LOG(" Error: " .. (username or "<nil>"))
+ else
+ LOG(" Scheme = " .. scheme)
+ LOG(" Username = " .. username)
+ LOG(" Password = " .. password)
+ LOG(" Host = " .. host)
+ LOG(" Port = " .. port)
+ LOG(" Path = " .. path)
+ LOG(" Query = " .. query)
+ LOG(" Fragment = " .. fragment)
+ end
+ end
+ LOG("cUrlParser test complete")
+ return true
+end
+
+
+
+
+
function HandleConsoleBBox(a_Split)
local bbox = cBoundingBox(0, 10, 0, 10, 0, 10)
local v1 = Vector3d(1, 1, 1)
diff --git a/Server/Plugins/Debuggers/Info.lua b/Server/Plugins/Debuggers/Info.lua
index f71ee5509..486cfd0d9 100644
--- a/Server/Plugins/Debuggers/Info.lua
+++ b/Server/Plugins/Debuggers/Info.lua
@@ -253,6 +253,12 @@ g_PluginInfo =
Handler = HandleConsoleTestTracer,
HelpString = "Tests the cLineBlockTracer",
},
+
+ ["testurlparser"] =
+ {
+ Handler = HandleConsoleTestUrlParser,
+ HelpString = "Tests the cUrlParser",
+ },
}, -- ConsoleCommands
} -- g_PluginInfo