From d9cc531e3bc62cfe7965c8cb3df7b1d510f3f4a2 Mon Sep 17 00:00:00 2001 From: Paul Kulchenko Date: Fri, 18 Mar 2022 02:23:09 -0700 Subject: [PATCH 01/62] Fixe an issue with aux buffer init overwriting optional parameters in receive() (#334) Fixes use on Lua >= 5.4.3 --- src/buffer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/buffer.c b/src/buffer.c index ac5c531..7148be3 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -103,11 +103,14 @@ int buffer_meth_send(lua_State *L, p_buffer buf) { * object:receive() interface \*-------------------------------------------------------------------------*/ int buffer_meth_receive(lua_State *L, p_buffer buf) { - int err = IO_DONE, top = lua_gettop(L); + int err = IO_DONE, top; luaL_Buffer b; size_t size; const char *part = luaL_optlstring(L, 3, "", &size); timeout_markstart(buf->tm); + /* make sure we don't confuse buffer stuff with arguments */ + lua_settop(L, 3); + top = lua_gettop(L); /* initialize buffer with optional extra prefix * (useful for concatenating previous partial results) */ luaL_buffinit(L, &b); From 6952262e6a1315b14935ddd0ea511c202c0154ba Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Fri, 18 Mar 2022 17:54:11 +0300 Subject: [PATCH 02/62] style: Use C-style comment syntax throughout (#309) Co-authored-by: Denise Cullassnekuff <19711487+BlackCutpoint@users.noreply.github.com> --- src/mime.c | 8 ++++---- src/options.c | 45 +++++++++++++++++++++++---------------------- src/unixdgram.c | 2 +- src/wsocket.c | 20 ++++++++++---------- 4 files changed, 38 insertions(+), 37 deletions(-) diff --git a/src/mime.c b/src/mime.c index 6c210e4..05602f5 100755 --- a/src/mime.c +++ b/src/mime.c @@ -27,12 +27,12 @@ static int mime_global_eol(lua_State *L); static int mime_global_dot(lua_State *L); static size_t dot(int c, size_t state, luaL_Buffer *buffer); -//static void b64setup(UC *base); +/*static void b64setup(UC *base);*/ static size_t b64encode(UC c, UC *input, size_t size, luaL_Buffer *buffer); static size_t b64pad(const UC *input, size_t size, luaL_Buffer *buffer); static size_t b64decode(UC c, UC *input, size_t size, luaL_Buffer *buffer); -//static void qpsetup(UC *class, UC *unbase); +/*static void qpsetup(UC *class, UC *unbase);*/ static void qpquote(UC c, luaL_Buffer *buffer); static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer); static size_t qpencode(UC c, UC *input, size_t size, @@ -176,8 +176,8 @@ LUASOCKET_API int luaopen_mime_core(lua_State *L) lua_pushstring(L, MIME_VERSION); lua_rawset(L, -3); /* initialize lookup tables */ - // qpsetup(qpclass, qpunbase); - // b64setup(b64unbase); + /*qpsetup(qpclass, qpunbase);*/ + /*b64setup(b64unbase);*/ return 1; } diff --git a/src/options.c b/src/options.c index 06ab58d..2b53c67 100644 --- a/src/options.c +++ b/src/options.c @@ -54,7 +54,7 @@ int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps) return opt->func(L, ps); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ /* enables reuse of local address */ int opt_set_reuseaddr(lua_State *L, p_socket ps) { @@ -66,7 +66,7 @@ int opt_get_reuseaddr(lua_State *L, p_socket ps) return opt_getboolean(L, ps, SOL_SOCKET, SO_REUSEADDR); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ /* enables reuse of local port */ int opt_set_reuseport(lua_State *L, p_socket ps) { @@ -78,7 +78,7 @@ int opt_get_reuseport(lua_State *L, p_socket ps) return opt_getboolean(L, ps, SOL_SOCKET, SO_REUSEPORT); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ /* disables the Nagle algorithm */ int opt_set_tcp_nodelay(lua_State *L, p_socket ps) { @@ -90,7 +90,7 @@ int opt_get_tcp_nodelay(lua_State *L, p_socket ps) return opt_getboolean(L, ps, IPPROTO_TCP, TCP_NODELAY); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ #ifdef TCP_KEEPIDLE int opt_get_tcp_keepidle(lua_State *L, p_socket ps) @@ -105,7 +105,7 @@ int opt_set_tcp_keepidle(lua_State *L, p_socket ps) #endif -// ------------------------------------------------------- +/*------------------------------------------------------*/ #ifdef TCP_KEEPCNT int opt_get_tcp_keepcnt(lua_State *L, p_socket ps) @@ -120,7 +120,7 @@ int opt_set_tcp_keepcnt(lua_State *L, p_socket ps) #endif -// ------------------------------------------------------- +/*------------------------------------------------------*/ #ifdef TCP_KEEPINTVL int opt_get_tcp_keepintvl(lua_State *L, p_socket ps) @@ -135,7 +135,7 @@ int opt_set_tcp_keepintvl(lua_State *L, p_socket ps) #endif -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_set_keepalive(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, SOL_SOCKET, SO_KEEPALIVE); @@ -146,7 +146,7 @@ int opt_get_keepalive(lua_State *L, p_socket ps) return opt_getboolean(L, ps, SOL_SOCKET, SO_KEEPALIVE); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_set_dontroute(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, SOL_SOCKET, SO_DONTROUTE); @@ -157,7 +157,7 @@ int opt_get_dontroute(lua_State *L, p_socket ps) return opt_getboolean(L, ps, SOL_SOCKET, SO_DONTROUTE); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_set_broadcast(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, SOL_SOCKET, SO_BROADCAST); @@ -168,7 +168,7 @@ int opt_get_broadcast(lua_State *L, p_socket ps) return opt_getboolean(L, ps, SOL_SOCKET, SO_BROADCAST); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_set_recv_buf_size(lua_State *L, p_socket ps) { return opt_setint(L, ps, SOL_SOCKET, SO_RCVBUF); @@ -179,7 +179,7 @@ int opt_get_recv_buf_size(lua_State *L, p_socket ps) return opt_getint(L, ps, SOL_SOCKET, SO_RCVBUF); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_get_send_buf_size(lua_State *L, p_socket ps) { return opt_getint(L, ps, SOL_SOCKET, SO_SNDBUF); @@ -190,7 +190,7 @@ int opt_set_send_buf_size(lua_State *L, p_socket ps) return opt_setint(L, ps, SOL_SOCKET, SO_SNDBUF); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_set_ip6_unicast_hops(lua_State *L, p_socket ps) { return opt_setint(L, ps, IPPROTO_IPV6, IPV6_UNICAST_HOPS); @@ -201,7 +201,7 @@ int opt_get_ip6_unicast_hops(lua_State *L, p_socket ps) return opt_getint(L, ps, IPPROTO_IPV6, IPV6_UNICAST_HOPS); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_set_ip6_multicast_hops(lua_State *L, p_socket ps) { return opt_setint(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_HOPS); @@ -212,7 +212,7 @@ int opt_get_ip6_multicast_hops(lua_State *L, p_socket ps) return opt_getint(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_HOPS); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_set_ip_multicast_loop(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, IPPROTO_IP, IP_MULTICAST_LOOP); @@ -223,7 +223,7 @@ int opt_get_ip_multicast_loop(lua_State *L, p_socket ps) return opt_getboolean(L, ps, IPPROTO_IP, IP_MULTICAST_LOOP); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_set_ip6_multicast_loop(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_LOOP); @@ -234,7 +234,7 @@ int opt_get_ip6_multicast_loop(lua_State *L, p_socket ps) return opt_getboolean(L, ps, IPPROTO_IPV6, IPV6_MULTICAST_LOOP); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_set_linger(lua_State *L, p_socket ps) { struct linger li; /* obj, name, table */ @@ -267,13 +267,13 @@ int opt_get_linger(lua_State *L, p_socket ps) return 1; } -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_set_ip_multicast_ttl(lua_State *L, p_socket ps) { return opt_setint(L, ps, IPPROTO_IP, IP_MULTICAST_TTL); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_set_ip_multicast_if(lua_State *L, p_socket ps) { const char *address = luaL_checkstring(L, 3); /* obj, name, ip */ @@ -298,7 +298,7 @@ int opt_get_ip_multicast_if(lua_State *L, p_socket ps) return 1; } -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_set_ip_add_membership(lua_State *L, p_socket ps) { return opt_setmembership(L, ps, IPPROTO_IP, IP_ADD_MEMBERSHIP); @@ -309,7 +309,7 @@ int opt_set_ip_drop_membersip(lua_State *L, p_socket ps) return opt_setmembership(L, ps, IPPROTO_IP, IP_DROP_MEMBERSHIP); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_set_ip6_add_membership(lua_State *L, p_socket ps) { return opt_ip6_setmembership(L, ps, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP); @@ -319,7 +319,8 @@ int opt_set_ip6_drop_membersip(lua_State *L, p_socket ps) { return opt_ip6_setmembership(L, ps, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP); } -// ------------------------------------------------------- + +/*------------------------------------------------------*/ int opt_get_ip6_v6only(lua_State *L, p_socket ps) { return opt_getboolean(L, ps, IPPROTO_IPV6, IPV6_V6ONLY); @@ -330,7 +331,7 @@ int opt_set_ip6_v6only(lua_State *L, p_socket ps) return opt_setboolean(L, ps, IPPROTO_IPV6, IPV6_V6ONLY); } -// ------------------------------------------------------- +/*------------------------------------------------------*/ int opt_get_error(lua_State *L, p_socket ps) { int val = 0; diff --git a/src/unixdgram.c b/src/unixdgram.c index 3ac3c5e..69093d7 100644 --- a/src/unixdgram.c +++ b/src/unixdgram.c @@ -16,7 +16,7 @@ #define UNIXDGRAM_DATAGRAMSIZE 8192 -// provide a SUN_LEN macro if sys/un.h doesn't (e.g. Android) +/* provide a SUN_LEN macro if sys/un.h doesn't (e.g. Android) */ #ifndef SUN_LEN #define SUN_LEN(ptr) \ ((size_t) (((struct sockaddr_un *) 0)->sun_path) \ diff --git a/src/wsocket.c b/src/wsocket.c index 20da330..7cd4115 100755 --- a/src/wsocket.c +++ b/src/wsocket.c @@ -360,7 +360,7 @@ const char *socket_ioerror(p_socket ps, int err) { static const char *wstrerror(int err) { switch (err) { case WSAEINTR: return "Interrupted function call"; - case WSAEACCES: return PIE_ACCESS; // "Permission denied"; + case WSAEACCES: return PIE_ACCESS; /* "Permission denied"; */ case WSAEFAULT: return "Bad address"; case WSAEINVAL: return "Invalid argument"; case WSAEMFILE: return "Too many open files"; @@ -373,23 +373,23 @@ static const char *wstrerror(int err) { case WSAEPROTOTYPE: return "Protocol wrong type for socket"; case WSAENOPROTOOPT: return "Bad protocol option"; case WSAEPROTONOSUPPORT: return "Protocol not supported"; - case WSAESOCKTNOSUPPORT: return PIE_SOCKTYPE; // "Socket type not supported"; + case WSAESOCKTNOSUPPORT: return PIE_SOCKTYPE; /* "Socket type not supported"; */ case WSAEOPNOTSUPP: return "Operation not supported"; case WSAEPFNOSUPPORT: return "Protocol family not supported"; - case WSAEAFNOSUPPORT: return PIE_FAMILY; // "Address family not supported by protocol family"; - case WSAEADDRINUSE: return PIE_ADDRINUSE; // "Address already in use"; + case WSAEAFNOSUPPORT: return PIE_FAMILY; /* "Address family not supported by protocol family"; */ + case WSAEADDRINUSE: return PIE_ADDRINUSE; /* "Address already in use"; */ case WSAEADDRNOTAVAIL: return "Cannot assign requested address"; case WSAENETDOWN: return "Network is down"; case WSAENETUNREACH: return "Network is unreachable"; case WSAENETRESET: return "Network dropped connection on reset"; case WSAECONNABORTED: return "Software caused connection abort"; - case WSAECONNRESET: return PIE_CONNRESET; // "Connection reset by peer"; + case WSAECONNRESET: return PIE_CONNRESET; /* "Connection reset by peer"; */ case WSAENOBUFS: return "No buffer space available"; - case WSAEISCONN: return PIE_ISCONN; // "Socket is already connected"; + case WSAEISCONN: return PIE_ISCONN; /* "Socket is already connected"; */ case WSAENOTCONN: return "Socket is not connected"; case WSAESHUTDOWN: return "Cannot send after socket shutdown"; - case WSAETIMEDOUT: return PIE_TIMEDOUT; // "Connection timed out"; - case WSAECONNREFUSED: return PIE_CONNREFUSED; // "Connection refused"; + case WSAETIMEDOUT: return PIE_TIMEDOUT; /* "Connection timed out"; */ + case WSAECONNREFUSED: return PIE_CONNREFUSED; /* "Connection refused"; */ case WSAEHOSTDOWN: return "Host is down"; case WSAEHOSTUNREACH: return "No route to host"; case WSAEPROCLIM: return "Too many processes"; @@ -398,9 +398,9 @@ static const char *wstrerror(int err) { case WSANOTINITIALISED: return "Successful WSAStartup not yet performed"; case WSAEDISCON: return "Graceful shutdown in progress"; - case WSAHOST_NOT_FOUND: return PIE_HOST_NOT_FOUND; // "Host not found"; + case WSAHOST_NOT_FOUND: return PIE_HOST_NOT_FOUND; /* "Host not found"; */ case WSATRY_AGAIN: return "Nonauthoritative host not found"; - case WSANO_RECOVERY: return PIE_FAIL; // "Nonrecoverable name lookup error"; + case WSANO_RECOVERY: return PIE_FAIL; /* "Nonrecoverable name lookup error"; */ case WSANO_DATA: return "Valid name, no data record of requested type"; default: return "Unknown error"; } From 52b22da7e3361b6927ef7516851239808d54c673 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Fri, 18 Mar 2022 12:12:39 +0100 Subject: [PATCH 03/62] chore: Add editorconfig setup file --- .editorconfig | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..edf8aa1 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,23 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +charset = utf-8 + +[*.{lua,rockspec}] +indent_style = space +indent_size = 4 + +[Makefile] +indent_style = tab +indent_size = 4 + +[*.html] +indent_style = space +indent_size = 4 + +[*.{c,h}] +indent_style = space +indent_size = 4 From f6509d4fd5dfc0363aada9b1653934356e9abd3f Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Fri, 18 Mar 2022 12:12:39 +0100 Subject: [PATCH 04/62] chore: Add luacheck linter project configuration --- .luacheckrc | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .luacheckrc diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..fcec7d5 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,31 @@ +unused_args = false +redefined = false +max_line_length = false + +not_globals = { + "string.len", + "table.getn", +} + +include_files = { + "**/*.lua", + "**/*.rockspec", + ".busted", + ".luacheckrc", +} + +exclude_files = { + "etc/*.lua", + "etc/**/*.lua", + "test/*.lua", + "test/**/*.lua", + "samples/*.lua", + "samples/**/*.lua", + "gem/*.lua", + "gem/**/*.lua", + -- GH Actions Lua Environment + ".lua", + ".luarocks", + ".install", +} + From 480c05257211b3e566f33fdf8cf051233e2dab30 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Fri, 18 Mar 2022 12:12:39 +0100 Subject: [PATCH 05/62] ci: Add workflow to run luacheck linter --- .github/workflows/luacheck.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/luacheck.yml diff --git a/.github/workflows/luacheck.yml b/.github/workflows/luacheck.yml new file mode 100644 index 0000000..13993cc --- /dev/null +++ b/.github/workflows/luacheck.yml @@ -0,0 +1,26 @@ +name: Luacheck + +on: [push, pull_request] + +jobs: + luacheck: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup Lua + uses: leafo/gh-actions-lua@v8 + with: + luaVersion: 5.4 + + - name: Setup Lua Rocks + uses: leafo/gh-actions-luarocks@v4 + + - name: Setup dependencies + run: luarocks install luacheck + + - name: Run Code Linter + run: | + luacheck . From 601ad8d59f11d7180015d0ecfb9d0a8d67f6f5c1 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Fri, 18 Mar 2022 12:12:39 +0100 Subject: [PATCH 06/62] refactor: Address issues raised by linter --- etc/cookie.lua | 22 +++---- etc/get.lua | 2 +- gem/ex11.lua | 4 +- gem/ex3.lua | 2 +- gem/ex4.lua | 2 +- samples/cddb.lua | 2 +- src/ftp.lua | 14 ++--- src/http.lua | 11 ++-- src/ltn12.lua | 3 +- src/mbox.lua | 13 +++-- src/mime.lua | 12 +--- src/url.lua | 6 +- test/ltn12test.lua | 24 ++++---- test/mimetest.lua | 46 +++++++-------- test/smtptest.lua | 20 +++---- test/test_socket_error.lua | 2 +- test/testmesg.lua | 14 ++--- test/testsupport.lua | 2 +- test/urltest.lua | 114 ++++++++++++++++++------------------- test/utestclnt.lua | 68 +++++++++++----------- test/utestsrvr.lua | 2 +- 21 files changed, 187 insertions(+), 198 deletions(-) diff --git a/etc/cookie.lua b/etc/cookie.lua index 4adb403..fec10a1 100644 --- a/etc/cookie.lua +++ b/etc/cookie.lua @@ -5,7 +5,7 @@ local ltn12 = require"ltn12" local token_class = '[^%c%s%(%)%<%>%@%,%;%:%\\%"%/%[%]%?%=%{%}]' -local function unquote(t, quoted) +local function unquote(t, quoted) local n = string.match(t, "%$(%d+)$") if n then n = tonumber(n) end if quoted[n] then return quoted[n] @@ -14,19 +14,19 @@ end local function parse_set_cookie(c, quoted, cookie_table) c = c .. ";$last=last;" - local _, __, n, v, i = string.find(c, "(" .. token_class .. + local _, _, n, v, i = string.find(c, "(" .. token_class .. "+)%s*=%s*(.-)%s*;%s*()") local cookie = { - name = n, - value = unquote(v, quoted), + name = n, + value = unquote(v, quoted), attributes = {} } while 1 do - _, __, n, v, i = string.find(c, "(" .. token_class .. + _, _, n, v, i = string.find(c, "(" .. token_class .. "+)%s*=?%s*(.-)%s*;%s*()", i) if not n or n == "$last" then break end cookie.attributes[#cookie.attributes+1] = { - name = n, + name = n, value = unquote(v, quoted) } end @@ -46,8 +46,8 @@ local function split_set_cookie(s, cookie_table) -- split into individual cookies i = 1 while 1 do - local _, __, cookie, next_token - _, __, cookie, i, next_token = string.find(s, "(.-)%s*%,%s*()(" .. + local _, _, cookie, next_token + _, _, cookie, i, next_token = string.find(s, "(.-)%s*%,%s*()(" .. token_class .. "+)%s*=", i) if not next_token then break end parse_set_cookie(cookie, quoted, cookie_table) @@ -62,12 +62,12 @@ local function quote(s) end local _empty = {} -local function build_cookies(cookies) +local function build_cookies(cookies) s = "" for i,v in ipairs(cookies or _empty) do if v.name then s = s .. v.name - if v.value and v.value ~= "" then + if v.value and v.value ~= "" then s = s .. '=' .. quote(v.value) end end @@ -83,6 +83,6 @@ local function build_cookies(cookies) end if i < #cookies then s = s .. ", " end end - return s + return s end diff --git a/etc/get.lua b/etc/get.lua index 9edc235..d53c465 100644 --- a/etc/get.lua +++ b/etc/get.lua @@ -71,7 +71,7 @@ function stats(size) local current = socket.gettime() if chunk then -- total bytes received - got = got + string.len(chunk) + got = got + string.len(chunk) -- not enough time for estimate if current - last > 1 then io.stderr:write("\r", gauge(got, current - start, size)) diff --git a/gem/ex11.lua b/gem/ex11.lua index 1cbf01f..79c99af 100644 --- a/gem/ex11.lua +++ b/gem/ex11.lua @@ -1,7 +1,7 @@ local input = source.chain( - source.file(io.open("input.bin", "rb")), + source.file(io.open("input.bin", "rb")), encode("base64")) local output = sink.chain( - wrap(76), + wrap(76), sink.file(io.open("output.b64", "w"))) pump.all(input, output) diff --git a/gem/ex3.lua b/gem/ex3.lua index a43fefa..60b4423 100644 --- a/gem/ex3.lua +++ b/gem/ex3.lua @@ -7,7 +7,7 @@ local function chainpair(f1, f2) end function filter.chain(...) - local f = select(1, ...) + local f = select(1, ...) for i = 2, select('#', ...) do f = chainpair(f, select(i, ...)) end diff --git a/gem/ex4.lua b/gem/ex4.lua index c670e0e..c48b77e 100644 --- a/gem/ex4.lua +++ b/gem/ex4.lua @@ -1,4 +1,4 @@ -local qp = filter.chain(normalize(CRLF), encode("quoted-printable"), +local qp = filter.chain(normalize(CRLF), encode("quoted-printable"), wrap("quoted-printable")) local input = source.chain(source.file(io.stdin), qp) local output = sink.file(io.stdout) diff --git a/samples/cddb.lua b/samples/cddb.lua index 49a1871..59d5a44 100644 --- a/samples/cddb.lua +++ b/samples/cddb.lua @@ -26,7 +26,7 @@ function parse(body) data[key] = value end end - return data, code, message + return data, code, message end local host = socket.dns.gethostname() diff --git a/src/ftp.lua b/src/ftp.lua index bd528ca..0ebc508 100644 --- a/src/ftp.lua +++ b/src/ftp.lua @@ -56,7 +56,7 @@ end function metat.__index:login(user, password) self.try(self.tp:command("user", user or _M.USER)) - local code, reply = self.try(self.tp:check{"2..", 331}) + local code, _ = self.try(self.tp:check{"2..", 331}) if code == 331 then self.try(self.tp:command("pass", password or _M.PASSWORD)) self.try(self.tp:check("2..")) @@ -66,7 +66,7 @@ end function metat.__index:pasv() self.try(self.tp:command("pasv")) - local code, reply = self.try(self.tp:check("2..")) + local _, reply = self.try(self.tp:check("2..")) local pattern = "(%d+)%D(%d+)%D(%d+)%D(%d+)%D(%d+)%D(%d+)" local a, b, c, d, p1, p2 = socket.skip(2, string.find(reply, pattern)) self.try(a and b and c and d and p1 and p2, reply) @@ -83,9 +83,9 @@ end function metat.__index:epsv() self.try(self.tp:command("epsv")) - local code, reply = self.try(self.tp:check("229")) + local _, reply = self.try(self.tp:check("229")) local pattern = "%((.)(.-)%1(.-)%1(.-)%1%)" - local d, prt, address, port = string.match(reply, pattern) + local _, _, _, port = string.match(reply, pattern) self.try(port, "invalid epsv response") self.pasvt = { address = self.tp:getpeername(), @@ -102,7 +102,7 @@ end function metat.__index:port(address, port) self.pasvt = nil if not address then - address, port = self.try(self.tp:getsockname()) + address = self.try(self.tp:getsockname()) self.server = self.try(socket.bind(address, 0)) address, port = self.try(self.server:getsockname()) self.try(self.server:settimeout(_M.TIMEOUT)) @@ -118,7 +118,7 @@ end function metat.__index:eprt(family, address, port) self.pasvt = nil if not address then - address, port = self.try(self.tp:getsockname()) + address = self.try(self.tp:getsockname()) self.server = self.try(socket.bind(address, 0)) address, port = self.try(self.server:getsockname()) self.try(self.server:settimeout(_M.TIMEOUT)) @@ -142,7 +142,7 @@ function metat.__index:send(sendt) local command = sendt.command or "stor" -- send the transfer command and check the reply self.try(self.tp:command(command, argument)) - local code, reply = self.try(self.tp:check{"2..", "1.."}) + local code, _ = self.try(self.tp:check{"2..", "1.."}) -- if there is not a pasvt table, then there is a server -- and we already sent a PORT command if not self.pasvt then self:portconnect() end diff --git a/src/http.lua b/src/http.lua index 6a3416e..e3a1742 100644 --- a/src/http.lua +++ b/src/http.lua @@ -41,9 +41,6 @@ local SCHEMES = { https.tcp, 'LuaSocket: Function tcp() not available from LuaSec') return tcp(t) end }} --- default scheme and port for document retrieval -local SCHEME = 'http' -local PORT = SCHEMES[SCHEME].port ----------------------------------------------------------------------------- -- Reads MIME headers from a connection, unfolding where needed ----------------------------------------------------------------------------- @@ -92,7 +89,7 @@ socket.sourcet["http-chunked"] = function(sock, headers) -- was it the last chunk? if size > 0 then -- if not, get chunk and skip terminating CRLF - local chunk, err, part = sock:receive(size) + local chunk, err, _ = sock:receive(size) if chunk then sock:receive() end return chunk, err else @@ -166,8 +163,8 @@ function metat.__index:receivestatusline() if status ~= "HTTP/" then if ec == "timeout" then return 408 - end - return nil, status + end + return nil, status end -- otherwise proceed reading a status line status = self.try(self.c:receive("*l", status)) @@ -366,7 +363,7 @@ end local headers -- ignore any 100-continue messages while code == 100 do - headers = h:receiveheaders() + h:receiveheaders() code, status = h:receivestatusline() end headers = h:receiveheaders() diff --git a/src/ltn12.lua b/src/ltn12.lua index afa735d..f1e05e1 100644 --- a/src/ltn12.lua +++ b/src/ltn12.lua @@ -13,7 +13,7 @@ local unpack = unpack or table.unpack local base = _G local _M = {} if module then -- heuristic for exporting a global package table - ltn12 = _M + ltn12 = _M -- luacheck: ignore end local filter,source,sink,pump = {},{},{},{} @@ -23,7 +23,6 @@ _M.sink = sink _M.pump = pump local unpack = unpack or table.unpack -local select = base.select -- 2048 seems to be better in windows... _M.BLOCKSIZE = 2048 diff --git a/src/mbox.lua b/src/mbox.lua index ed9e781..12823b0 100644 --- a/src/mbox.lua +++ b/src/mbox.lua @@ -1,8 +1,8 @@ local _M = {} if module then - mbox = _M -end + mbox = _M -- luacheck: ignore +end function _M.split_message(message_s) local message = {} @@ -29,7 +29,7 @@ end function _M.parse_header(header_s) header_s = string.gsub(header_s, "\n[ ]+", " ") header_s = string.gsub(header_s, "\n+", "") - local _, __, name, value = string.find(header_s, "([^%s:]-):%s*(.*)") + local _, _, name, value = string.find(header_s, "([^%s:]-):%s*(.*)") return name, value end @@ -49,9 +49,9 @@ function _M.parse_headers(headers_s) end function _M.parse_from(from) - local _, __, name, address = string.find(from, "^%s*(.-)%s*%<(.-)%>") + local _, _, name, address = string.find(from, "^%s*(.-)%s*%<(.-)%>") if not address then - _, __, address = string.find(from, "%s*(.+)%s*") + _, _, address = string.find(from, "%s*(.+)%s*") end name = name or "" address = address or "" @@ -63,7 +63,8 @@ end function _M.split_mbox(mbox_s) local mbox = {} mbox_s = string.gsub(mbox_s, "\r\n", "\n") .."\n\nFrom \n" - local nj, i, j = 1, 1, 1 + local nj, i + local j = 1 while 1 do i, nj = string.find(mbox_s, "\n\nFrom .-\n", j) if not i then break end diff --git a/src/mime.lua b/src/mime.lua index d3abac5..93539de 100644 --- a/src/mime.lua +++ b/src/mime.lua @@ -10,7 +10,6 @@ local base = _G local ltn12 = require("ltn12") local mime = require("mime.core") -local string = require("string") local _M = mime -- encode, decode and wrap algorithm tables @@ -18,7 +17,7 @@ local encodet, decodet, wrapt = {},{},{} _M.encodet = encodet _M.decodet = decodet -_M.wrapt = wrapt +_M.wrapt = wrapt -- creates a function that chooses a filter by name from a given table local function choose(table) @@ -27,7 +26,7 @@ local function choose(table) name, opt1, opt2 = "default", name, opt1 end local f = table[name or "nil"] - if not f then + if not f then base.error("unknown key (" .. base.tostring(name) .. ")", 3) else return f(opt1, opt2) end end @@ -52,13 +51,6 @@ decodet['quoted-printable'] = function() return ltn12.filter.cycle(_M.unqp, "") end -local function format(chunk) - if chunk then - if chunk == "" then return "''" - else return string.len(chunk) end - else return "nil" end -end - -- define the line-wrap filters wrapt['text'] = function(length) length = length or 76 diff --git a/src/url.lua b/src/url.lua index 0a3a80a..8e0dc5c 100644 --- a/src/url.lua +++ b/src/url.lua @@ -179,9 +179,9 @@ function _M.parse(url, default) function(u) parsed.userinfo = u; return "" end) authority = string.gsub(authority, ":([^:%]]*)$", function(p) parsed.port = p; return "" end) - if authority ~= "" then + if authority ~= "" then -- IPv6? - parsed.host = string.match(authority, "^%[(.+)%]$") or authority + parsed.host = string.match(authority, "^%[(.+)%]$") or authority end local userinfo = parsed.userinfo if not userinfo then return parsed end @@ -264,7 +264,7 @@ function _M.absolute(base_url, relative_url) relative_parsed.query = base_parsed.query end end - else + else relative_parsed.path = absolute_path(base_parsed.path or "", relative_parsed.path) end diff --git a/test/ltn12test.lua b/test/ltn12test.lua index e7d368d..0cafbc9 100644 --- a/test/ltn12test.lua +++ b/test/ltn12test.lua @@ -38,7 +38,7 @@ local function named(f, name) end -------------------------------- -local function split(size) +local function split(size) local buffer = "" local last_out = "" local last_in = "" @@ -50,12 +50,12 @@ local function split(size) return last_out end return function(chunk, done) - if done then - return not last_in and not last_out + if done then + return not last_in and not last_out end -- check if argument is consistent with state if not chunk then - if last_in and last_in ~= "" and last_out ~= "" then + if last_in and last_in ~= "" and last_out ~= "" then error("nil chunk following data chunk", 2) end if not last_out then error("extra nil chunk", 2) end @@ -67,8 +67,8 @@ local function split(size) return output(chunk) else if not last_in then error("data chunk following nil chunk", 2) end - if last_in ~= "" and last_out ~= "" then - error("data chunk following data chunk", 2) + if last_in ~= "" and last_out ~= "" then + error("data chunk following data chunk", 2) end buffer = chunk return output(chunk) @@ -85,7 +85,7 @@ local function format(chunk) end -------------------------------- -local function merge(size) +local function merge(size) local buffer = "" local last_out = "" local last_in = "" @@ -102,12 +102,12 @@ local function merge(size) return last_out end return function(chunk, done) - if done then - return not last_in and not last_out + if done then + return not last_in and not last_out end -- check if argument is consistent with state if not chunk then - if last_in and last_in ~= "" and last_out ~= "" then + if last_in and last_in ~= "" and last_out ~= "" then error("nil chunk following data chunk", 2) end if not last_out then error("extra nil chunk", 2) end @@ -119,8 +119,8 @@ local function merge(size) return output(chunk) else if not last_in then error("data chunk following nil chunk", 2) end - if last_in ~= "" and last_out ~= "" then - error("data chunk following data chunk", 2) + if last_in ~= "" and last_out ~= "" then + error("data chunk following data chunk", 2) end buffer = buffer .. chunk return output(chunk) diff --git a/test/mimetest.lua b/test/mimetest.lua index f5b3747..a3c89ac 100644 --- a/test/mimetest.lua +++ b/test/mimetest.lua @@ -15,27 +15,27 @@ local eb64test = "b64test.bin2" local db64test = "b64test.bin3" --- from Machado de Assis, "A Mão e a Rosa" +-- from Machado de Assis, "A M�o e a Rosa" local mao = [[ - Cursavam estes dois moços a academia de S. Paulo, estando - Luís Alves no quarto ano e Estêvão no terceiro. - Conheceram-se na academia, e ficaram amigos íntimos, tanto - quanto podiam sê-lo dois espíritos diferentes, ou talvez por - isso mesmo que o eram. Estêvão, dotado de extrema - sensibilidade, e não menor fraqueza de ânimo, afetuoso e - bom, não daquela bondade varonil, que é apanágio de uma alma - forte, mas dessa outra bondade mole e de cera, que vai à - mercê de todas as circunstâncias, tinha, além de tudo isso, - o infortúnio de trazer ainda sobre o nariz os óculos - cor-de-rosa de suas virginais ilusões. Luís Alves via bem - com os olhos da cara. Não era mau rapaz, mas tinha o seu - grão de egoísmo, e se não era incapaz de afeições, sabia - regê-las, moderá-las, e sobretudo guiá-las ao seu próprio + Cursavam estes dois mo�os a academia de S. Paulo, estando + Lu�s Alves no quarto ano e Est�v�o no terceiro. + Conheceram-se na academia, e ficaram amigos �ntimos, tanto + quanto podiam s�-lo dois esp�ritos diferentes, ou talvez por + isso mesmo que o eram. Est�v�o, dotado de extrema + sensibilidade, e n�o menor fraqueza de �nimo, afetuoso e + bom, n�o daquela bondade varonil, que � apan�gio de uma alma + forte, mas dessa outra bondade mole e de cera, que vai � + merc� de todas as circunst�ncias, tinha, al�m de tudo isso, + o infort�nio de trazer ainda sobre o nariz os �culos + cor-de-rosa de suas virginais ilus�es. Lu�s Alves via bem + com os olhos da cara. N�o era mau rapaz, mas tinha o seu + gr�o de ego�smo, e se n�o era incapaz de afei��es, sabia + reg�-las, moder�-las, e sobretudo gui�-las ao seu pr�prio interesse. Entre estes dois homens travara-se amizade - íntima, nascida para um na simpatia, para outro no costume. + �ntima, nascida para um na simpatia, para outro no costume. Eram eles os naturais confidentes um do outro, com a - diferença que Luís Alves dava menos do que recebia, e, ainda - assim, nem tudo o que dava exprimia grande confiança. + diferen�a que Lu�s Alves dava menos do que recebia, e, ainda + assim, nem tudo o que dava exprimia grande confian�a. ]] local function random(handle, io_err) @@ -44,8 +44,8 @@ local function random(handle, io_err) if not handle then error("source is empty!", 2) end local len = math.random(0, 1024) local chunk = handle:read(len) - if not chunk then - handle:close() + if not chunk then + handle:close() handle = nil end return chunk @@ -62,7 +62,7 @@ local what = nil local function transform(input, output, filter) local source = random(io.open(input, "rb")) local sink = ltn12.sink.file(io.open(output, "wb")) - if what then + if what then sink = ltn12.sink.chain(filter, sink) else source = ltn12.source.chain(source, filter) @@ -147,7 +147,7 @@ local function create_qptest() f:write(' ',string.char(32)) end f:write("\r\n") - + f:close() end @@ -157,7 +157,7 @@ local function cleanup_qptest() os.remove(dqptest) end --- create test file +-- create test file local function create_b64test() local f = assert(io.open(b64test, "wb")) local t = {} diff --git a/test/smtptest.lua b/test/smtptest.lua index b5380ff..9d06054 100644 --- a/test/smtptest.lua +++ b/test/smtptest.lua @@ -27,8 +27,8 @@ local total = function() end local similar = function(s1, s2) - return - string.lower(string.gsub(s1, "%s", "")) == + return + string.lower(string.gsub(s1, "%s", "")) == string.lower(string.gsub(s2, "%s", "")) end @@ -40,9 +40,9 @@ end local readfile = function(name) local f = io.open(name, "r") - if not f then + if not f then fail("unable to open file!") - return nil + return nil end local s = f:read("*a") f:close() @@ -52,7 +52,7 @@ end local empty = function() for i,v in ipairs(files) do local f = io.open(v, "w") - if not f then + if not f then fail("unable to open file!") end f:close() @@ -116,8 +116,8 @@ local wait = function(sentinel, n) while 1 do local mbox = parse(get()) if n == #mbox then break end - if socket.time() - sentinel.time > 50 then - to = 1 + if socket.time() - sentinel.time > 50 then + to = 1 break end socket.sleep(1) @@ -132,7 +132,7 @@ local stuffed_body = [[ This message body needs to be stuffed because it has a dot . -by itself on a line. +by itself on a line. Otherwise the mailer would think that the dot . @@ -219,7 +219,7 @@ else print("ok") end io.write("testing invalid from: ") local ret, err = socket.smtp.mail{ - from = ' " " (( _ * ', + from = ' " " (( _ * ', rcpt = rcpt, } if ret or not err then fail("wrong error message") @@ -227,7 +227,7 @@ else print(err) end io.write("testing no rcpt: ") local ret, err = socket.smtp.mail{ - from = from, + from = from, } if ret or not err then fail("wrong error message") else print(err) end diff --git a/test/test_socket_error.lua b/test/test_socket_error.lua index bda6408..1b4b601 100644 --- a/test/test_socket_error.lua +++ b/test/test_socket_error.lua @@ -19,7 +19,7 @@ for i = 1, 10 do assert(ss == sock) else assert('timeout' == err, 'unexpected error :' .. tostring(err)) - end + end err = sock:getoption("error") -- i get 'connection refused' on WinXP if err then print("Passed! Error is '" .. err .. "'.") diff --git a/test/testmesg.lua b/test/testmesg.lua index 135a008..8c086d5 100644 --- a/test/testmesg.lua +++ b/test/testmesg.lua @@ -34,11 +34,11 @@ r, e = smtp.send{ print(r, e) --- creates a source to send a message with two parts. The first part is +-- creates a source to send a message with two parts. The first part is -- plain text, the second part is a PNG image, encoded as base64. source = smtp.message{ headers = { - -- Remember that headers are *ignored* by smtp.send. + -- Remember that headers are *ignored* by smtp.send. from = "Sicrano ", to = "Fulano ", subject = "Here is a message with attachments" @@ -49,18 +49,18 @@ source = smtp.message{ "Preamble might show up even in a MIME enabled client.", -- first part: No headers means plain text, us-ascii. -- The mime.eol low-level filter normalizes end-of-line markers. - [1] = { + [1] = { body = mime.eol(0, [[ - Lines in a message body should always end with CRLF. + Lines in a message body should always end with CRLF. The smtp module will *NOT* perform translation. It will perform necessary stuffing, though. ]]) }, - -- second part: Headers describe content the to be an image, + -- second part: Headers describe content the to be an image, -- sent under the base64 transfer content encoding. - -- Notice that nothing happens until the message is sent. Small + -- Notice that nothing happens until the message is sent. Small -- chunks are loaded into memory and translation happens on the fly. - [2] = { + [2] = { headers = { ["ConTenT-tYpE"] = 'image/png; name="luasocket.png"', ["content-disposition"] = 'attachment; filename="luasocket.png"', diff --git a/test/testsupport.lua b/test/testsupport.lua index b986088..4360b6b 100644 --- a/test/testsupport.lua +++ b/test/testsupport.lua @@ -7,7 +7,7 @@ function readfile(name) end function similar(s1, s2) - return string.lower(string.gsub(s1 or "", "%s", "")) == + return string.lower(string.gsub(s1 or "", "%s", "")) == string.lower(string.gsub(s2 or "", "%s", "")) end diff --git a/test/urltest.lua b/test/urltest.lua index ae8ba75..9a3c470 100644 --- a/test/urltest.lua +++ b/test/urltest.lua @@ -60,8 +60,8 @@ end local check_absolute_url = function(base, relative, absolute) local res = socket.url.absolute(base, relative) - if res ~= absolute then - io.write("absolute: In test for base='", base, "', rel='", relative, "' expected '", + if res ~= absolute then + io.write("absolute: In test for base='", base, "', rel='", relative, "' expected '", absolute, "' but got '", res, "'\n") os.exit() end @@ -73,7 +73,7 @@ local check_parse_url = function(gaba) local parsed = socket.url.parse(url) for i, v in pairs(gaba) do if v ~= parsed[i] then - io.write("parse: In test for '", url, "' expected ", i, " = '", + io.write("parse: In test for '", url, "' expected ", i, " = '", v, "' but got '", tostring(parsed[i]), "'\n") for i,v in pairs(parsed) do print(i,v) end os.exit() @@ -81,7 +81,7 @@ local check_parse_url = function(gaba) end for i, v in pairs(parsed) do if v ~= gaba[i] then - io.write("parse: In test for '", url, "' expected ", i, " = '", + io.write("parse: In test for '", url, "' expected ", i, " = '", tostring(gaba[i]), "' but got '", v, "'\n") for i,v in pairs(parsed) do print(i,v) end os.exit() @@ -92,8 +92,8 @@ end print("testing URL parsing") check_parse_url{ url = "scheme://user:pass$%?#wd@host:port/path;params?query#fragment", - scheme = "scheme", - authority = "user:pass$%?#wd@host:port", + scheme = "scheme", + authority = "user:pass$%?#wd@host:port", host = "host", port = "port", userinfo = "user:pass$%?#wd", @@ -106,8 +106,8 @@ check_parse_url{ } check_parse_url{ url = "scheme://user:pass?#wd@host:port/path;params?query#fragment", - scheme = "scheme", - authority = "user:pass?#wd@host:port", + scheme = "scheme", + authority = "user:pass?#wd@host:port", host = "host", port = "port", userinfo = "user:pass?#wd", @@ -120,8 +120,8 @@ check_parse_url{ } check_parse_url{ url = "scheme://user:pass-wd@host:port/path;params?query#fragment", - scheme = "scheme", - authority = "user:pass-wd@host:port", + scheme = "scheme", + authority = "user:pass-wd@host:port", host = "host", port = "port", userinfo = "user:pass-wd", @@ -134,8 +134,8 @@ check_parse_url{ } check_parse_url{ url = "scheme://user:pass#wd@host:port/path;params?query#fragment", - scheme = "scheme", - authority = "user:pass#wd@host:port", + scheme = "scheme", + authority = "user:pass#wd@host:port", host = "host", port = "port", userinfo = "user:pass#wd", @@ -148,8 +148,8 @@ check_parse_url{ } check_parse_url{ url = "scheme://user:pass#wd@host:port/path;params?query", - scheme = "scheme", - authority = "user:pass#wd@host:port", + scheme = "scheme", + authority = "user:pass#wd@host:port", host = "host", port = "port", userinfo = "user:pass#wd", @@ -161,8 +161,8 @@ check_parse_url{ } check_parse_url{ url = "scheme://userinfo@host:port/path;params?query#fragment", - scheme = "scheme", - authority = "userinfo@host:port", + scheme = "scheme", + authority = "userinfo@host:port", host = "host", port = "port", userinfo = "userinfo", @@ -175,8 +175,8 @@ check_parse_url{ check_parse_url{ url = "scheme://user:password@host:port/path;params?query#fragment", - scheme = "scheme", - authority = "user:password@host:port", + scheme = "scheme", + authority = "user:password@host:port", host = "host", port = "port", userinfo = "user:password", @@ -190,8 +190,8 @@ check_parse_url{ check_parse_url{ url = "scheme://userinfo@host:port/path;params?query#", - scheme = "scheme", - authority = "userinfo@host:port", + scheme = "scheme", + authority = "userinfo@host:port", host = "host", port = "port", userinfo = "userinfo", @@ -204,8 +204,8 @@ check_parse_url{ check_parse_url{ url = "scheme://userinfo@host:port/path;params?#fragment", - scheme = "scheme", - authority = "userinfo@host:port", + scheme = "scheme", + authority = "userinfo@host:port", host = "host", port = "port", userinfo = "userinfo", @@ -218,8 +218,8 @@ check_parse_url{ check_parse_url{ url = "scheme://userinfo@host:port/path;params#fragment", - scheme = "scheme", - authority = "userinfo@host:port", + scheme = "scheme", + authority = "userinfo@host:port", host = "host", port = "port", userinfo = "userinfo", @@ -231,8 +231,8 @@ check_parse_url{ check_parse_url{ url = "scheme://userinfo@host:port/path;?query#fragment", - scheme = "scheme", - authority = "userinfo@host:port", + scheme = "scheme", + authority = "userinfo@host:port", host = "host", port = "port", userinfo = "userinfo", @@ -245,8 +245,8 @@ check_parse_url{ check_parse_url{ url = "scheme://userinfo@host:port/path?query#fragment", - scheme = "scheme", - authority = "userinfo@host:port", + scheme = "scheme", + authority = "userinfo@host:port", host = "host", port = "port", userinfo = "userinfo", @@ -258,8 +258,8 @@ check_parse_url{ check_parse_url{ url = "scheme://userinfo@host:port/;params?query#fragment", - scheme = "scheme", - authority = "userinfo@host:port", + scheme = "scheme", + authority = "userinfo@host:port", host = "host", port = "port", userinfo = "userinfo", @@ -272,8 +272,8 @@ check_parse_url{ check_parse_url{ url = "scheme://userinfo@host:port", - scheme = "scheme", - authority = "userinfo@host:port", + scheme = "scheme", + authority = "userinfo@host:port", host = "host", port = "port", userinfo = "userinfo", @@ -282,7 +282,7 @@ check_parse_url{ check_parse_url{ url = "//userinfo@host:port/path;params?query#fragment", - authority = "userinfo@host:port", + authority = "userinfo@host:port", host = "host", port = "port", userinfo = "userinfo", @@ -295,7 +295,7 @@ check_parse_url{ check_parse_url{ url = "//userinfo@host:port/path", - authority = "userinfo@host:port", + authority = "userinfo@host:port", host = "host", port = "port", userinfo = "userinfo", @@ -305,7 +305,7 @@ check_parse_url{ check_parse_url{ url = "//userinfo@host/path", - authority = "userinfo@host", + authority = "userinfo@host", host = "host", userinfo = "userinfo", user = "userinfo", @@ -314,7 +314,7 @@ check_parse_url{ check_parse_url{ url = "//user:password@host/path", - authority = "user:password@host", + authority = "user:password@host", host = "host", userinfo = "user:password", password = "password", @@ -324,7 +324,7 @@ check_parse_url{ check_parse_url{ url = "//user:@host/path", - authority = "user:@host", + authority = "user:@host", host = "host", userinfo = "user:", password = "", @@ -334,7 +334,7 @@ check_parse_url{ check_parse_url{ url = "//user@host:port/path", - authority = "user@host:port", + authority = "user@host:port", host = "host", userinfo = "user", user = "user", @@ -344,7 +344,7 @@ check_parse_url{ check_parse_url{ url = "//host:port/path", - authority = "host:port", + authority = "host:port", port = "port", host = "host", path = "/path", @@ -352,14 +352,14 @@ check_parse_url{ check_parse_url{ url = "//host/path", - authority = "host", + authority = "host", host = "host", path = "/path", } check_parse_url{ url = "//host", - authority = "host", + authority = "host", host = "host", } @@ -433,7 +433,7 @@ check_parse_url{ check_parse_url{ url = "//userinfo@[::FFFF:129.144.52.38]:port/path;params?query#fragment", - authority = "userinfo@[::FFFF:129.144.52.38]:port", + authority = "userinfo@[::FFFF:129.144.52.38]:port", host = "::FFFF:129.144.52.38", port = "port", userinfo = "userinfo", @@ -447,7 +447,7 @@ check_parse_url{ check_parse_url{ url = "scheme://user:password@[::192.9.5.5]:port/path;params?query#fragment", scheme = "scheme", - authority = "user:password@[::192.9.5.5]:port", + authority = "user:password@[::192.9.5.5]:port", host = "::192.9.5.5", port = "port", userinfo = "user:password", @@ -462,7 +462,7 @@ check_parse_url{ print("testing URL building") check_build_url { url = "scheme://user:password@host:port/path;params?query#fragment", - scheme = "scheme", + scheme = "scheme", host = "host", port = "port", user = "user", @@ -499,7 +499,7 @@ check_build_url{ check_build_url { url = "scheme://user:password@host/path;params?query#fragment", - scheme = "scheme", + scheme = "scheme", host = "host", user = "user", password = "password", @@ -511,7 +511,7 @@ check_build_url { check_build_url { url = "scheme://user@host/path;params?query#fragment", - scheme = "scheme", + scheme = "scheme", host = "host", user = "user", path = "/path", @@ -522,7 +522,7 @@ check_build_url { check_build_url { url = "scheme://host/path;params?query#fragment", - scheme = "scheme", + scheme = "scheme", host = "host", path = "/path", params = "params", @@ -532,7 +532,7 @@ check_build_url { check_build_url { url = "scheme://host/path;params#fragment", - scheme = "scheme", + scheme = "scheme", host = "host", path = "/path", params = "params", @@ -541,7 +541,7 @@ check_build_url { check_build_url { url = "scheme://host/path#fragment", - scheme = "scheme", + scheme = "scheme", host = "host", path = "/path", fragment = "fragment" @@ -549,7 +549,7 @@ check_build_url { check_build_url { url = "scheme://host/path", - scheme = "scheme", + scheme = "scheme", host = "host", path = "/path", } @@ -567,7 +567,7 @@ check_build_url { check_build_url { url = "scheme://user:password@host:port/path;params?query#fragment", - scheme = "scheme", + scheme = "scheme", host = "host", port = "port", user = "user", @@ -581,7 +581,7 @@ check_build_url { check_build_url { url = "scheme://user:password@host:port/path;params?query#fragment", - scheme = "scheme", + scheme = "scheme", host = "host", port = "port", user = "user", @@ -596,7 +596,7 @@ check_build_url { check_build_url { url = "scheme://user:password@host:port/path;params?query#fragment", - scheme = "scheme", + scheme = "scheme", host = "host", port = "port", userinfo = "user:password", @@ -609,7 +609,7 @@ check_build_url { check_build_url { url = "scheme://user:password@host:port/path;params?query#fragment", - scheme = "scheme", + scheme = "scheme", authority = "user:password@host:port", path = "/path", params = "params", @@ -683,7 +683,7 @@ check_absolute_url("//a/b/c/d;p?q#f", "d/e/f", "//a/b/c/d/e/f") check_absolute_url("/a/b/c/d;p?q#f", "d/e/f", "/a/b/c/d/e/f") check_absolute_url("a/b/c/d", "d/e/f", "a/b/c/d/e/f") check_absolute_url("a/b/c/d/../", "d/e/f", "a/b/c/d/e/f") -check_absolute_url("http://velox.telemar.com.br", "/dashboard/index.html", +check_absolute_url("http://velox.telemar.com.br", "/dashboard/index.html", "http://velox.telemar.com.br/dashboard/index.html") check_absolute_url("http://example.com/", "../.badhost.com/", "http://example.com/.badhost.com/") check_absolute_url("http://example.com/", "...badhost.com/", "http://example.com/...badhost.com/") @@ -700,11 +700,11 @@ check_absolute_url("http://example.com/a/b/c/d/", "../x/a/../y/z/../../../../q", print("testing path parsing and composition") check_parse_path("/eu/tu/ele", { "eu", "tu", "ele"; is_absolute = 1 }) check_parse_path("/eu/", { "eu"; is_absolute = 1, is_directory = 1 }) -check_parse_path("eu/tu/ele/nos/vos/eles/", +check_parse_path("eu/tu/ele/nos/vos/eles/", { "eu", "tu", "ele", "nos", "vos", "eles"; is_directory = 1}) check_parse_path("/", { is_absolute = 1, is_directory = 1}) check_parse_path("", { }) -check_parse_path("eu%01/%02tu/e%03l%04e/nos/vos%05/e%12les/", +check_parse_path("eu%01/%02tu/e%03l%04e/nos/vos%05/e%12les/", { "eu\1", "\2tu", "e\3l\4e", "nos", "vos\5", "e\18les"; is_directory = 1}) check_parse_path("eu/tu", { "eu", "tu" }) diff --git a/test/utestclnt.lua b/test/utestclnt.lua index 34a0718..7f10643 100644 --- a/test/utestclnt.lua +++ b/test/utestclnt.lua @@ -54,30 +54,30 @@ function check_timeout(tm, sl, elapsed, err, opp, mode, alldone) if not err then warn("must be buffered") elseif err == "timeout" then pass("proper timeout") else fail("unexpected error '%s'", err) end - else - if err ~= "timeout" then fail("should have timed out") + else + if err ~= "timeout" then fail("should have timed out") else pass("proper timeout") end end else if mode == "total" then - if elapsed > tm then + if elapsed > tm then if err ~= "timeout" then fail("should have timed out") else pass("proper timeout") end elseif elapsed < tm then - if err then fail(err) + if err then fail(err) else pass("ok") end - else - if alldone then - if err then fail("unexpected error '%s'", err) + else + if alldone then + if err then fail("unexpected error '%s'", err) else pass("ok") end else - if err ~= "timeout" then fail(err) + if err ~= "timeout" then fail(err) else pass("proper timeoutk") end end end - else - if err then fail(err) - else pass("ok") end + else + if err then fail(err) + else pass("ok") end end end end @@ -104,7 +104,7 @@ function reconnect() print("done " .. i) ]] data, err = uconnect(host, port) - if not data then fail(err) + if not data then fail(err) else pass("connected!") end end @@ -116,8 +116,8 @@ else pass("connected!") end ------------------------------------------------------------------------ function test_methods(sock, methods) for _, v in pairs(methods) do - if type(sock[v]) ~= "function" then - fail(sock.class .. " method '" .. v .. "' not registered") + if type(sock[v]) ~= "function" then + fail(sock.class .. " method '" .. v .. "' not registered") end end pass(sock.class .. " methods are ok") @@ -132,7 +132,7 @@ function test_mixed(len) local p3 = "raw " .. string.rep("z", inter) .. "bytes" local p4 = "end" .. string.rep("w", inter) .. "bytes" local bp1, bp2, bp3, bp4 -remote (string.format("str = data:receive(%d)", +remote (string.format("str = data:receive(%d)", string.len(p1)+string.len(p2)+string.len(p3)+string.len(p4))) sent, err = data:send(p1..p2..p3..p4) if err then fail(err) end @@ -172,7 +172,7 @@ function test_rawline(len) reconnect() local str, str10, back, err str = string.rep(string.char(47), math.mod(len, 10)) - str10 = string.rep(string.char(120,21,77,4,5,0,7,36,44,100), + str10 = string.rep(string.char(120,21,77,4,5,0,7,36,44,100), math.floor(len/10)) str = str .. str10 remote "str = data:receive()" @@ -221,7 +221,7 @@ function test_totaltimeoutreceive(len, tm, sl) data:settimeout(tm, "total") local t = socket.gettime() str, err, partial, elapsed = data:receive(2*len) - check_timeout(tm, sl, elapsed, err, "receive", "total", + check_timeout(tm, sl, elapsed, err, "receive", "total", string.len(str or partial) == 2*len) end @@ -241,7 +241,7 @@ function test_totaltimeoutsend(len, tm, sl) data:settimeout(tm, "total") str = string.rep("a", 2*len) total, err, partial, elapsed = data:send(str) - check_timeout(tm, sl, elapsed, err, "send", "total", + check_timeout(tm, sl, elapsed, err, "send", "total", total == 2*len) end @@ -261,7 +261,7 @@ function test_blockingtimeoutreceive(len, tm, sl) ]], 2*tm, len, sl, sl)) data:settimeout(tm) str, err, partial, elapsed = data:receive(2*len) - check_timeout(tm, sl, elapsed, err, "receive", "blocking", + check_timeout(tm, sl, elapsed, err, "receive", "blocking", string.len(str or partial) == 2*len) end @@ -294,10 +294,10 @@ function empty_connect() data = server:accept() ]] data, err = socket.connect("", port) - if not data then + if not data then pass("ok") data = socket.connect(host, port) - else + else pass("gethostbyname returns localhost on empty string...") end end @@ -331,7 +331,7 @@ function test_closed() data:close() data = nil ]], str)) - -- try to get a line + -- try to get a line back, err, partial = data:receive() if not err then fail("should have gotten 'closed'.") elseif err ~= "closed" then fail("got '"..err.."' instead of 'closed'.") @@ -344,25 +344,25 @@ function test_closed() data = nil ]] total, err, partial = data:send(string.rep("ugauga", 100000)) - if not err then + if not err then pass("failed: output buffer is at least %d bytes long!", total) - elseif err ~= "closed" then + elseif err ~= "closed" then fail("got '"..err.."' instead of 'closed'.") - else - pass("graceful 'closed' received after %d bytes were sent", partial) + else + pass("graceful 'closed' received after %d bytes were sent", partial) end end ------------------------------------------------------------------------ function test_selectbugs() local r, s, e = socket.select(nil, nil, 0.1) - assert(type(r) == "table" and type(s) == "table" and + assert(type(r) == "table" and type(s) == "table" and (e == "timeout" or e == "error")) pass("both nil: ok") local udp = socket.udp() udp:close() r, s, e = socket.select({ udp }, { udp }, 0.1) - assert(type(r) == "table" and type(s) == "table" and + assert(type(r) == "table" and type(s) == "table" and (e == "timeout" or e == "error")) pass("closed sockets: ok") e = pcall(socket.select, "wrong", 1, 0.1) @@ -380,7 +380,7 @@ function accept_timeout() local t = socket.gettime() s:settimeout(1) local c, e = s:accept() - assert(not c, "should not accept") + assert(not c, "should not accept") assert(e == "timeout", string.format("wrong error message (%s)", e)) t = socket.gettime() - t assert(t < 2, string.format("took to long to give up (%gs)", t)) @@ -398,9 +398,9 @@ function connect_timeout() local t = socket.gettime() local r, e = c:connect("127.0.0.2", 80) assert(not r, "should not connect") - assert(socket.gettime() - t < 2, "took too long to give up.") + assert(socket.gettime() - t < 2, "took too long to give up.") c:close() - print("ok") + print("ok") end ------------------------------------------------------------------------ @@ -463,9 +463,9 @@ function getstats_test() data:receive(c) t = t + c local r, s, a = data:getstats() - assert(r == t, "received count failed" .. tostring(r) + assert(r == t, "received count failed" .. tostring(r) .. "/" .. tostring(t)) - assert(s == t, "sent count failed" .. tostring(s) + assert(s == t, "sent count failed" .. tostring(s) .. "/" .. tostring(t)) end print("ok") @@ -473,7 +473,7 @@ end ------------------------------------------------------------------------ -function test_nonblocking(size) +function test_nonblocking(size) reconnect() print("Testing " .. 2*size .. " bytes") remote(string.format([[ diff --git a/test/utestsrvr.lua b/test/utestsrvr.lua index a96b570..b6e4246 100644 --- a/test/utestsrvr.lua +++ b/test/utestsrvr.lua @@ -9,7 +9,7 @@ ack = "\n"; while 1 do print("server: waiting for client connection..."); control = assert(server:accept()); - while 1 do + while 1 do command = assert(control:receive()); assert(control:send(ack)); ((loadstring or load)(command))(); From 989a5b11310c1c6da900c2f997712405a7986d09 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 19 Mar 2022 17:28:25 +0300 Subject: [PATCH 07/62] chore: Include luacheck config in editorconfig setup --- .editorconfig | 2 +- .luacheckrc | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.editorconfig b/.editorconfig index edf8aa1..56ad87d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,7 +6,7 @@ insert_final_newline = true trim_trailing_whitespace = true charset = utf-8 -[*.{lua,rockspec}] +[{*.lua,*.rockspec,.luacheckrc}] indent_style = space indent_size = 4 diff --git a/.luacheckrc b/.luacheckrc index fcec7d5..8b25dd7 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -8,10 +8,10 @@ not_globals = { } include_files = { - "**/*.lua", - "**/*.rockspec", - ".busted", - ".luacheckrc", + "**/*.lua", + "**/*.rockspec", + ".busted", + ".luacheckrc", } exclude_files = { From 8390d07774a1ba1a597d809a1a2562d88ecce19d Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 19 Mar 2022 17:34:28 +0300 Subject: [PATCH 08/62] chore: Bump Lua version used in linter --- .github/workflows/luacheck.yml | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/.github/workflows/luacheck.yml b/.github/workflows/luacheck.yml index 13993cc..597cd64 100644 --- a/.github/workflows/luacheck.yml +++ b/.github/workflows/luacheck.yml @@ -3,24 +3,17 @@ name: Luacheck on: [push, pull_request] jobs: - luacheck: - runs-on: ubuntu-latest + luacheck: + runs-on: ubuntu-20.04 steps: - name: Checkout - uses: actions/checkout@v2 - - - name: Setup Lua - uses: leafo/gh-actions-lua@v8 - with: - luaVersion: 5.4 - - - name: Setup Lua Rocks + uses: actions/checkout@v3 + - name: Setup ‘lua’ + uses: leafo/gh-actions-lua@v9 + - name: Setup ‘luarocks’ uses: leafo/gh-actions-luarocks@v4 - - - name: Setup dependencies + - name: Setup ‘luacheck’ run: luarocks install luacheck - - - name: Run Code Linter - run: | - luacheck . + - name: Run ‘luacheck’ linter + run: luacheck . From d0f2d132bf4b02ff342b3d87479ec0cf46f7c059 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 19 Mar 2022 17:55:12 +0300 Subject: [PATCH 09/62] chore: Move SCM rockspec to root and bump rockrel to 3 --- .../luasocket-scm-2.rockspec => luasocket-scm-3.rockspec | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename rockspec/luasocket-scm-2.rockspec => luasocket-scm-3.rockspec (95%) diff --git a/rockspec/luasocket-scm-2.rockspec b/luasocket-scm-3.rockspec similarity index 95% rename from rockspec/luasocket-scm-2.rockspec rename to luasocket-scm-3.rockspec index 9a71b07..4e1669c 100644 --- a/rockspec/luasocket-scm-2.rockspec +++ b/luasocket-scm-3.rockspec @@ -1,8 +1,8 @@ package = "LuaSocket" -version = "scm-2" +version = "scm-3" source = { - url = "git://github.com/diegonehab/luasocket.git" - , branch="master" + url = "git+https://github.com/lunarmodules/luasocket.git", + branch = "master" } description = { summary = "Network support for the Lua language", @@ -12,7 +12,7 @@ description = { modules that add support for functionality commonly needed by applications that deal with the Internet. ]], - homepage = "http://luaforge.net/projects/luasocket/", + homepage = "https://github.com/lunarmodules/luasocket", license = "MIT" } dependencies = { From 36428e07cd164c83f71469d1bb84992bd026cbb3 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 19 Mar 2022 17:55:12 +0300 Subject: [PATCH 10/62] chore: Rename rockspec dir to be plural --- {rockspec => rockspecs}/luasocket-3.0rc2-1.rockspec | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {rockspec => rockspecs}/luasocket-3.0rc2-1.rockspec (100%) diff --git a/rockspec/luasocket-3.0rc2-1.rockspec b/rockspecs/luasocket-3.0rc2-1.rockspec similarity index 100% rename from rockspec/luasocket-3.0rc2-1.rockspec rename to rockspecs/luasocket-3.0rc2-1.rockspec From 335f647075fb5e0423039e9a335bbf032e8a8334 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 19 Mar 2022 18:20:05 +0300 Subject: [PATCH 11/62] chore: Add current most recent rockspec as published --- rockspecs/luasocket-3.0rc1-2.rockspec | 108 ++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 rockspecs/luasocket-3.0rc1-2.rockspec diff --git a/rockspecs/luasocket-3.0rc1-2.rockspec b/rockspecs/luasocket-3.0rc1-2.rockspec new file mode 100644 index 0000000..3cb6524 --- /dev/null +++ b/rockspecs/luasocket-3.0rc1-2.rockspec @@ -0,0 +1,108 @@ +package = "LuaSocket" +version = "3.0rc1-2" +source = { + url = "https://github.com/diegonehab/luasocket/archive/v3.0-rc1.zip", + dir = "luasocket-3.0-rc1", +} +description = { + summary = "Network support for the Lua language", + detailed = [[ + LuaSocket is a Lua extension library that is composed by two parts: a C core + that provides support for the TCP and UDP transport layers, and a set of Lua + modules that add support for functionality commonly needed by applications + that deal with the Internet. + ]], + homepage = "http://luaforge.net/projects/luasocket/", + license = "MIT" +} +dependencies = { + "lua >= 5.1" +} + +local function make_plat(plat) + local defines = { + unix = { + "LUA_COMPAT_APIINTCASTS", + "LUASOCKET_DEBUG", + "LUASOCKET_API=__attribute__((visibility(\"default\")))", + "UNIX_API=__attribute__((visibility(\"default\")))", + "MIME_API=__attribute__((visibility(\"default\")))" + }, + macosx = { + "LUA_COMPAT_APIINTCASTS", + "LUASOCKET_DEBUG", + "UNIX_HAS_SUN_LEN", + "LUASOCKET_API=__attribute__((visibility(\"default\")))", + "UNIX_API=__attribute__((visibility(\"default\")))", + "MIME_API=__attribute__((visibility(\"default\")))" + }, + win32 = { + "LUA_COMPAT_APIINTCASTS", + "LUASOCKET_DEBUG", + "NDEBUG", + "LUASOCKET_API=__declspec(dllexport)", + "MIME_API=__declspec(dllexport)" + }, + mingw32 = { + "LUA_COMPAT_APIINTCASTS", + "LUASOCKET_DEBUG", + "LUASOCKET_INET_PTON", + "WINVER=0x0501", + "LUASOCKET_API=__declspec(dllexport)", + "MIME_API=__declspec(dllexport)" + } + } + local modules = { + ["socket.core"] = { + sources = { "src/luasocket.c", "src/timeout.c", "src/buffer.c", "src/io.c", "src/auxiliar.c", + "src/options.c", "src/inet.c", "src/except.c", "src/select.c", "src/tcp.c", "src/udp.c" }, + defines = defines[plat], + incdir = "src" + }, + ["mime.core"] = { + sources = { "src/mime.c" }, + defines = defines[plat], + incdir = "src" + }, + ["socket.http"] = "src/http.lua", + ["socket.url"] = "src/url.lua", + ["socket.tp"] = "src/tp.lua", + ["socket.ftp"] = "src/ftp.lua", + ["socket.headers"] = "src/headers.lua", + ["socket.smtp"] = "src/smtp.lua", + ltn12 = "src/ltn12.lua", + socket = "src/socket.lua", + mime = "src/mime.lua" + } + if plat == "unix" or plat == "macosx" then + modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/usocket.c" + modules["socket.unix"] = { + sources = { "src/buffer.c", "src/auxiliar.c", "src/options.c", "src/timeout.c", "src/io.c", + "src/usocket.c", "src/unix.c" }, + defines = defines[plat], + incdir = "/src" + } + modules["socket.serial"] = { + sources = { "src/buffer.c", "src/auxiliar.c", "src/options.c", "src/timeout.c", + "src/io.c", "src/usocket.c", "src/serial.c" }, + defines = defines[plat], + incdir = "/src" + } + end + if plat == "win32" or plat == "mingw32" then + modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/wsocket.c" + modules["socket.core"].libraries = { "ws2_32" } + end + return { modules = modules } +end + +build = { + type = "builtin", + platforms = { + unix = make_plat("unix"), + macosx = make_plat("macosx"), + win32 = make_plat("win32"), + mingw32 = make_plat("mingw32") + }, + copy_directories = { "doc", "samples", "etc", "test" } +} From 91aa6522a0a4d5e24af86524fa68350de40a2667 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 19 Mar 2022 18:20:52 +0300 Subject: [PATCH 12/62] chore: Drop rockspec for never-published RC2 release --- rockspecs/luasocket-3.0rc2-1.rockspec | 134 -------------------------- 1 file changed, 134 deletions(-) delete mode 100644 rockspecs/luasocket-3.0rc2-1.rockspec diff --git a/rockspecs/luasocket-3.0rc2-1.rockspec b/rockspecs/luasocket-3.0rc2-1.rockspec deleted file mode 100644 index dfe5275..0000000 --- a/rockspecs/luasocket-3.0rc2-1.rockspec +++ /dev/null @@ -1,134 +0,0 @@ -package = "LuaSocket" -version = "3.0rc2-1" -source = { - url = "git://github.com/diegonehab/luasocket.git", - tag = "v3.0-rc2", -} -description = { - summary = "Network support for the Lua language", - detailed = [[ - LuaSocket is a Lua extension library that is composed by two parts: a C core - that provides support for the TCP and UDP transport layers, and a set of Lua - modules that add support for functionality commonly needed by applications - that deal with the Internet. - ]], - homepage = "http://luaforge.net/projects/luasocket/", - license = "MIT" -} -dependencies = { - "lua >= 5.1" -} - -local function make_plat(plat) - local defines = { - unix = { - "LUASOCKET_DEBUG" - }, - macosx = { - "LUASOCKET_DEBUG", - "UNIX_HAS_SUN_LEN" - }, - win32 = { - "LUASOCKET_DEBUG", - "NDEBUG" - }, - mingw32 = { - "LUASOCKET_DEBUG", - "LUASOCKET_INET_PTON", - "WINVER=0x0501" - } - } - local modules = { - ["socket.core"] = { - sources = { - "src/luasocket.c" - , "src/timeout.c" - , "src/buffer.c" - , "src/io.c" - , "src/auxiliar.c" - , "src/options.c" - , "src/inet.c" - , "src/except.c" - , "src/select.c" - , "src/tcp.c" - , "src/udp.c" - , "src/compat.c" }, - defines = defines[plat], - incdir = "/src" - }, - ["mime.core"] = { - sources = { "src/mime.c", "src/compat.c" }, - defines = defines[plat], - incdir = "/src" - }, - ["socket.http"] = "src/http.lua", - ["socket.url"] = "src/url.lua", - ["socket.tp"] = "src/tp.lua", - ["socket.ftp"] = "src/ftp.lua", - ["socket.headers"] = "src/headers.lua", - ["socket.smtp"] = "src/smtp.lua", - ltn12 = "src/ltn12.lua", - socket = "src/socket.lua", - mime = "src/mime.lua" - } - if plat == "unix" - or plat == "macosx" - or plat == "haiku" - then - modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/usocket.c" - if plat == "haiku" then - modules["socket.core"].libraries = {"network"} - end - modules["socket.unix"] = { - sources = { - "src/buffer.c" - , "src/compat.c" - , "src/auxiliar.c" - , "src/options.c" - , "src/timeout.c" - , "src/io.c" - , "src/usocket.c" - , "src/unix.c" - , "src/unixdgram.c" - , "src/unixstream.c" }, - defines = defines[plat], - incdir = "/src" - } - modules["socket.serial"] = { - sources = { - "src/buffer.c" - , "src/compat.c" - , "src/auxiliar.c" - , "src/options.c" - , "src/timeout.c" - , "src/io.c" - , "src/usocket.c" - , "src/serial.c" }, - defines = defines[plat], - incdir = "/src" - } - end - if plat == "win32" - or plat == "mingw32" - then - modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/wsocket.c" - modules["socket.core"].libraries = { "ws2_32" } - end - return { modules = modules } -end - -build = { - type = "builtin", - platforms = { - unix = make_plat("unix"), - macosx = make_plat("macosx"), - haiku = make_plat("haiku"), - win32 = make_plat("win32"), - mingw32 = make_plat("mingw32") - }, - copy_directories = { - "doc" - , "samples" - , "etc" - , "test" } -} From 844165ff89c0ec7bb50ac65ce010200dba1c8d89 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 19 Mar 2022 18:11:43 +0300 Subject: [PATCH 13/62] ci: Drop obsolete Travis configs --- .travis.yml | 54 ----------------------------------------------------- 1 file changed, 54 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index fce8a96..0000000 --- a/.travis.yml +++ /dev/null @@ -1,54 +0,0 @@ -language: erlang - -env: - global: - - LUAROCKS_BASE=luarocks-2.0.13 - matrix: - - LUA=lua5.1 LUA_DEV=liblua5.1-dev LUA_VER=5.1 LUA_SFX=5.1 LUA_INCDIR=/usr/include/lua5.1 - - LUA=lua5.2 LUA_DEV=liblua5.2-dev LUA_VER=5.2 LUA_SFX=5.2 LUA_INCDIR=/usr/include/lua5.2 - - LUA=luajit LUA_DEV=libluajit-5.1-dev LUA_VER=5.1 LUA_SFX=jit LUA_INCDIR=/usr/include/luajit-2.0 - -branches: - only: - - master - -before_install: - - if [ $LUA = "luajit" ]; then - sudo add-apt-repository ppa:mwild1/ppa -y && sudo apt-get update -y; - fi - - sudo apt-get install $LUA - - sudo apt-get install $LUA_DEV - - lua$LUA_SFX -v - # Install a recent luarocks release - - wget http://luarocks.org/releases/$LUAROCKS_BASE.tar.gz - - tar zxvpf $LUAROCKS_BASE.tar.gz - - cd $LUAROCKS_BASE - - ./configure - --lua-version=$LUA_VER --lua-suffix=$LUA_SFX --with-lua-include="$LUA_INCDIR" - - sudo make - - sudo make install - - cd $TRAVIS_BUILD_DIR - - -install: - - export DEBUG=DEBUG - - sudo -E luarocks make luasocket-scm-0.rockspec - -script: - - cd test - - lua$LUA_SFX hello.lua - - lua$LUA_SFX testsrvr.lua > /dev/null & - - lua$LUA_SFX testclnt.lua - - lua$LUA_SFX stufftest.lua - - lua$LUA_SFX excepttest.lua - - lua$LUA_SFX test_bind.lua - - lua$LUA_SFX test_getaddrinfo.lua - - lua$LUA_SFX ltn12test.lua - - lua$LUA_SFX mimetest.lua - - lua$LUA_SFX urltest.lua - - lua$LUA_SFX test_socket_error.lua - -notifications: - email: - on_success: change - on_failure: always From 2cc6f8a55c45ec9b5ad165c150259060d4d70a82 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 19 Mar 2022 20:55:11 +0300 Subject: [PATCH 14/62] ci: Add workflow to confirm build completes --- .github/workflows/build.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..8265bb1 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,24 @@ +name: Check build + +on: [ push, pull_request ] + +jobs: + build: + name: Check build + strategy: + fail-fast: false + matrix: + luaVersion: [ "5.4", "5.3", "5.2", "5.1", "luajit", "luajit-openresty"] + runs-on: ubuntu-20.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup ‘lua’ + uses: leafo/gh-actions-lua@v9 + with: + luaVersion: ${{ matrix.luaVersion }} + - name: Setup ‘luarocks’ + uses: leafo/gh-actions-luarocks@v4 + - name: Make with Luarocks + run: | + luarocks make --pack-binary-rock -- luasocket-scm-3.rockspec From 46ecb7e2dc3dd92931c6d9d99fdc9260e83077ff Mon Sep 17 00:00:00 2001 From: david <57832272+jyoui@users.noreply.github.com> Date: Tue, 1 Feb 2022 15:40:35 +0900 Subject: [PATCH 15/62] src/ltn12.lua: remove duplicated codes --- src/ltn12.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ltn12.lua b/src/ltn12.lua index f1e05e1..4cb17f5 100644 --- a/src/ltn12.lua +++ b/src/ltn12.lua @@ -11,6 +11,8 @@ local string = require("string") local table = require("table") local unpack = unpack or table.unpack local base = _G +local select = select + local _M = {} if module then -- heuristic for exporting a global package table ltn12 = _M -- luacheck: ignore @@ -22,8 +24,6 @@ _M.source = source _M.sink = sink _M.pump = pump -local unpack = unpack or table.unpack - -- 2048 seems to be better in windows... _M.BLOCKSIZE = 2048 _M._VERSION = "LTN12 1.0.3" @@ -45,7 +45,7 @@ end -- (thanks to Wim Couwenberg) function filter.chain(...) local arg = {...} - local n = base.select('#',...) + local n = select('#',...) local top, index = 1, 1 local retry = "" return function(chunk) From e3c17b002ae4747c033c374d39538d4e242dbb22 Mon Sep 17 00:00:00 2001 From: "E. Westbrook" Date: Mon, 11 Mar 2019 02:07:45 -0600 Subject: [PATCH 16/62] Add src\compat.c to mime.vcxproj and socket.vcxproj --- mime.vcxproj | 1 + socket.vcxproj | 1 + 2 files changed, 2 insertions(+) diff --git a/mime.vcxproj b/mime.vcxproj index 43acee9..575f985 100755 --- a/mime.vcxproj +++ b/mime.vcxproj @@ -20,6 +20,7 @@ + {128E8BD0-174A-48F0-8771-92B1E8D18713} diff --git a/socket.vcxproj b/socket.vcxproj index 305c094..51ebc68 100755 --- a/socket.vcxproj +++ b/socket.vcxproj @@ -21,6 +21,7 @@ + From 2a76cb906cb955a83ed76b8e47cc76c77ce8e15f Mon Sep 17 00:00:00 2001 From: Julian Squires Date: Fri, 16 Oct 2020 12:18:46 -0230 Subject: [PATCH 17/62] http.lua: set transfer-encoding if source and no content-length If a source is specified without a content-length header, LuaSocket sends the data in the chunked transfer coding; however, it doesn't set the transfer-encoding header. While I recognize that the user can set this manually, this is a gotcha that has caught me multiple times. RFC7230, section 3.3.3 (https://tools.ietf.org/html/rfc7230#section-3.3.3) is clear about this; if neither content-length nor transfer-encoding chunked are specified, the request message body length is zero. While some servers may ignore this, I have encountered several that follow the RFC in this regard, most recently golang's net/http. --- src/http.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/http.lua b/src/http.lua index e3a1742..1330355 100644 --- a/src/http.lua +++ b/src/http.lua @@ -283,6 +283,13 @@ local function adjustrequest(reqt) nreqt.uri = reqt.uri or adjusturi(nreqt) -- adjust headers in request nreqt.headers = adjustheaders(nreqt) + if nreqt.source + and not nreqt.headers["content-length"] + and not nreqt.headers["transfer-encoding"] + then + nreqt.headers["transfer-encoding"] = "chunked" + end + -- ajust host and port if there is a proxy nreqt.host, nreqt.port = adjustproxy(nreqt) return nreqt From fdd741da5cd0515e69572e564f2d57f336d2466b Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 19 Mar 2022 20:58:52 +0300 Subject: [PATCH 18/62] Ci: Run regression tests after successful build --- .github/workflows/build.yml | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8265bb1..64393cc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,10 +1,10 @@ -name: Check build +name: Test build on: [ push, pull_request ] jobs: build: - name: Check build + name: Test build on Linux strategy: fail-fast: false matrix: @@ -19,6 +19,23 @@ jobs: luaVersion: ${{ matrix.luaVersion }} - name: Setup ‘luarocks’ uses: leafo/gh-actions-luarocks@v4 - - name: Make with Luarocks + - name: Make and install locally run: | - luarocks make --pack-binary-rock -- luasocket-scm-3.rockspec + export DEBUG=DEBUG + luarocks --local make -- luasocket-scm-3.rockspec + - name: Run regression tests + run: | + eval $(luarocks --local path) + cd test + lua hello.lua + lua testsrvr.lua > /dev/null & + lua testclnt.lua + lua stufftest.lua + lua excepttest.lua + lua test_bind.lua + lua test_getaddrinfo.lua + lua ltn12test.lua + lua mimetest.lua + lua urltest.lua + lua test_socket_error.lua + kill %1 From 9787c17e589dc1b12c1f96e6bb391a7ff3dd5065 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 19 Mar 2022 21:18:54 +0300 Subject: [PATCH 19/62] ci: Expand test matrix to cover Windows and macOS --- .github/workflows/build.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 64393cc..518de63 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,7 +9,8 @@ jobs: fail-fast: false matrix: luaVersion: [ "5.4", "5.3", "5.2", "5.1", "luajit", "luajit-openresty"] - runs-on: ubuntu-20.04 + platform: [ "ubuntu-20.04", "windows-2022", "macos-11" ] + runs-on: ${{ matrix.platform }} steps: - name: Checkout uses: actions/checkout@v3 From 52c72694c2989c38fc9df915dcb34995d1e37404 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 19 Mar 2022 21:23:58 +0300 Subject: [PATCH 20/62] ci: Disable unsupported Windows and avoid duplicate runs --- .github/workflows/build.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 518de63..d22e67f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,10 @@ name: Test build -on: [ push, pull_request ] +on: + push: + branches: + - master + pull_request: jobs: build: @@ -9,7 +13,7 @@ jobs: fail-fast: false matrix: luaVersion: [ "5.4", "5.3", "5.2", "5.1", "luajit", "luajit-openresty"] - platform: [ "ubuntu-20.04", "windows-2022", "macos-11" ] + platform: [ "ubuntu-20.04", "macos-11" ] # "windows-2022" not supported by gh-actions-lua runs-on: ${{ matrix.platform }} steps: - name: Checkout From f9e1d03f3c6c9fc59dd3b91716debc23aebf947f Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 19 Mar 2022 22:42:25 +0300 Subject: [PATCH 21/62] ci: Don't bother doing user-local install in ephemeral runner --- .github/workflows/build.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d22e67f..17cad49 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,13 +24,12 @@ jobs: luaVersion: ${{ matrix.luaVersion }} - name: Setup ‘luarocks’ uses: leafo/gh-actions-luarocks@v4 - - name: Make and install locally + - name: Make and install run: | export DEBUG=DEBUG - luarocks --local make -- luasocket-scm-3.rockspec + luarocks make -- luasocket-scm-3.rockspec - name: Run regression tests run: | - eval $(luarocks --local path) cd test lua hello.lua lua testsrvr.lua > /dev/null & From f97dc8489d58aef2d038288f9a8bc69f907e17bb Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Tue, 22 Mar 2022 19:21:58 +0100 Subject: [PATCH 22/62] fix(docs) fix html linter issues in the docs (#358) --- doc/dns.html | 78 +++++------ doc/ftp.html | 122 ++++++++--------- doc/http.html | 142 ++++++++++---------- doc/index.html | 140 +++++++++---------- doc/ltn12.html | 200 ++++++++++++++-------------- doc/mime.html | 302 ++++++++++++++++++++--------------------- doc/reference.html | 22 +-- doc/smtp.html | 191 +++++++++++++------------- doc/socket.html | 256 +++++++++++++++++------------------ doc/tcp.html | 325 +++++++++++++++++++++++---------------------- doc/udp.html | 94 ++++++------- 11 files changed, 938 insertions(+), 934 deletions(-) diff --git a/doc/dns.html b/doc/dns.html index c4a0472..56ce3ba 100644 --- a/doc/dns.html +++ b/doc/dns.html @@ -1,4 +1,4 @@ - @@ -13,22 +13,22 @@ -
+

- -
-LuaSocket +
+LuaSocket
Network support for the Lua language +
Network support for the Lua language
-

+

home · download · installation · introduction · -reference +reference


@@ -36,14 +36,14 @@ -

DNS

+

DNS

-IPv4 name resolution functions -dns.toip +IPv4 name resolution functions +dns.toip and -dns.tohostname -return all information obtained from +dns.tohostname +return all information obtained from the resolver in a table of the form:

@@ -60,10 +60,10 @@ Note that the alias list can be empty.

-The more general name resolution function -dns.getaddrinfo, which +The more general name resolution function +dns.getaddrinfo, which supports both IPv6 and IPv4, -returns all information obtained from +returns all information obtained from the resolver in a table of the form:

@@ -88,82 +88,82 @@ addresses, and "inet6" for IPv6 addresses. -

+

socket.dns.getaddrinfo(address)

-

-Converts from host name to address. +

+Converts from host name to address.

-

-Address can be an IPv4 or IPv6 address or host name. +

+Address can be an IPv4 or IPv6 address or host name.

-

+

The function returns a table with all information returned by the resolver. In case of error, the function returns nil -followed by an error message. +followed by an error message.

-

+

socket.dns.gethostname()

-

-Returns the standard host name for the machine as a string. +

+Returns the standard host name for the machine as a string.

-

+

socket.dns.tohostname(address)

-

+

Converts from IPv4 address to host name.

-

-Address can be an IP address or host name. +

+Address can be an IP address or host name.

-

+

The function returns a string with the canonic host name of the given address, followed by a table with all information returned by the resolver. In case of error, the function returns nil -followed by an error message. +followed by an error message.

-

+

socket.dns.toip(address)

-

+

Converts from host name to IPv4 address.

-

-Address can be an IP address or host name. +

+Address can be an IP address or host name.

-

+

Returns a string with the first IP address found for address, followed by a table with all information returned by the resolver. In case of error, the function returns nil followed by an error -message. +message.

-