summaryrefslogtreecommitdiff
path: root/server/src/3rd/lua-uri/uri/ftp.lua
diff options
context:
space:
mode:
authorsumneko <sumneko@hotmail.com>2019-05-20 11:42:37 +0800
committersumneko <sumneko@hotmail.com>2019-05-20 11:42:37 +0800
commitc3a1a6c7e4e2f4d34d37a350aa12514fea77ad4c (patch)
tree0e70dfdfd6429a76a27ad858cb81431d2d389fee /server/src/3rd/lua-uri/uri/ftp.lua
parent6014825d9b1afe0af05f61c5ece7cf2b6f6b8013 (diff)
downloadlua-language-server-c3a1a6c7e4e2f4d34d37a350aa12514fea77ad4c.zip
#37 使用uri库
Diffstat (limited to 'server/src/3rd/lua-uri/uri/ftp.lua')
-rw-r--r--server/src/3rd/lua-uri/uri/ftp.lua53
1 files changed, 53 insertions, 0 deletions
diff --git a/server/src/3rd/lua-uri/uri/ftp.lua b/server/src/3rd/lua-uri/uri/ftp.lua
new file mode 100644
index 00000000..2d9e3f6c
--- /dev/null
+++ b/server/src/3rd/lua-uri/uri/ftp.lua
@@ -0,0 +1,53 @@
+local M = { _NAME = "uri.ftp" }
+local Util = require "uri._util"
+local LoginURI = require "uri._login"
+Util.subclass_of(M, LoginURI)
+
+function M.default_port () return 21 end
+
+function M.init (self)
+ self, err = M._SUPER.init_base(self)
+ if not self then return nil, err end
+
+ local host = self:host()
+ if not host or host == "" then
+ return nil, "FTP URIs must have a hostname"
+ end
+
+ -- I don't think there's any distinction in FTP URIs between empty path
+ -- and the root directory, so probably best to normalize as we do for HTTP.
+ if self:path() == "" then self:path("/") end
+
+ return self
+end
+
+function M.path (self, ...)
+ local old = M._SUPER.path(self)
+
+ if select("#", ...) > 0 then
+ local new = ...
+ if not new or new == "" then new = "/" end
+ M._SUPER.path(self, new)
+ end
+
+ return old
+end
+
+function M.ftp_typecode (self, ...)
+ local path = M._SUPER.path(self)
+ local _, _, withouttype, old = path:find("^(.*);type=(.*)$")
+ if not withouttype then withouttype = path end
+ if old == "" then old = nil end
+
+ if select("#", ...) > 0 then
+ local new = ...
+ if not new then new = "" end
+ if new ~= "" then new = ";type=" .. new end
+ M._SUPER.path(self, withouttype .. new)
+ end
+
+ return old
+end
+
+return M
+-- vi:ts=4 sw=4 expandtab