From c3a1a6c7e4e2f4d34d37a350aa12514fea77ad4c Mon Sep 17 00:00:00 2001 From: sumneko Date: Mon, 20 May 2019 11:42:37 +0800 Subject: =?UTF-8?q?#37=20=E4=BD=BF=E7=94=A8uri=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/3rd/lua-uri/uri/ftp.lua | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 server/src/3rd/lua-uri/uri/ftp.lua (limited to 'server/src/3rd/lua-uri/uri/ftp.lua') 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 -- cgit v1.2.3