diff -Nru luasocket-3.0~rc1+git+ac3201d/CHANGELOG.md luasocket-3.1.0/CHANGELOG.md --- luasocket-3.0~rc1+git+ac3201d/CHANGELOG.md 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/CHANGELOG.md 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,65 @@ +# Changelog + +## [v3.1.0](https://github.com/lunarmodules/luasocket/releases/v3.1.0) — 2022-07-27 + +* Add support for TCP Defer Accept – @Zash +* Add support for TCP Fast Open – @Zash +* Fix Windows (mingw32) builds – @goldenstein64 +* Avoid build warnings on 64-bit Windows – @rpatters1 + +## [v3.0.0](https://github.com/lunarmodules/luasocket/releases/v3.0.0) — 2022-03-25 + +The last time LuaSocket had a stable release tag was 14 years ago when 2.0.2 was tagged. +A v3 release candidate was tagged 9 years ago. +Since then it has been downloaded over 3 million times. +Additionally the Git repository regularly gets several hundred clones a day. +But 9 years is a long time and even the release candidate has grown a bit long in the tooth. +Many Linux distros have packaged the current Git HEAD or some specific tested point as dated or otherwise labeled releases. +256 commits later and having been migrated to the @lunarmodules org namespace on GitHub, please welcome v3. + +This release is a "safe-harbor" tag that represents a minimal amount of changes to get a release tagged. +Beyond some CI tooling, very little code has changed since migration to @lunarmodules ([5b18e47..e47d98f](https://github.com/lunarmodules/luasocket/compare/5b18e47..e47d98f?w=1)): + +* Lua 5.4.3+ support – @pkulchenko, @Zash +* Cleanup minor issues to get a code linter to pass – @Tieske, @jyoui, @alerque +* Update Visual Studio build rules for Lua 5.1 – @ewestbrook +* Set http transfer-encoding even without content-length – @tokenrove + +Prior to migration to @lunarmodules ([v3.0-rc1..5b18e47](https://github.com/lunarmodules/luasocket/compare/v3.0-rc1..5b18e47?w=1)) many things happened of which the author of this changelog is not fully apprised. +Your best bet if it affects your project somehow is to read the commit log & diffs yourself. + +## [v3.0-rc1](https://github.com/lunarmodules/luasocket/releases/v3.0-rc1) — 2013-06-14 + +Main changes for LuaSocket 3.0-rc1 are IPv6 support and Lua 5.2 compatibility. + +* Added: Compatible with Lua 5.2 + - Note that unless you define LUA_COMPAT_MODULE, package tables will not be exported as globals! +* Added: IPv6 support; + - Socket.connect and socket.bind support IPv6 addresses; + - Getpeername and getsockname support IPv6 addresses, and return the socket family as a third value; + - URL module updated to support IPv6 host names; + - New socket.tcp6 and socket.udp6 functions; + - New socket.dns.getaddrinfo and socket.dns.getnameinfo functions; +* Added: getoption method; +* Fixed: url.unescape was returning additional values; +* Fixed: mime.qp, mime.unqp, mime.b64, and mime.unb64 could mistaking their own stack slots for functions arguments; +* Fixed: Receiving zero-length datagram is now possible; +* Improved: Hidden all internal library symbols; +* Improved: Better error messages; +* Improved: Better documentation of socket options. +* Fixed: manual sample of HTTP authentication now uses correct "authorization" header (Alexandre Ittner); +* Fixed: failure on bind() was destroying the socket (Sam Roberts); +* Fixed: receive() returns immediatelly if prefix can satisfy bytes requested (M Joonas Pihlaja); +* Fixed: multicast didn't work on Windows, or anywhere else for that matter (Herbert Leuwer, Adrian Sietsma); +* Fixed: select() now reports an error when called with more sockets than FD_SETSIZE (Lorenzo Leonini); +* Fixed: manual links to home.html changed to index.html (Robert Hahn); +* Fixed: mime.unb64() would return an empty string on results that started with a null character (Robert Raschke); +* Fixed: HTTP now automatically redirects on 303 and 307 (Jonathan Gray); +* Fixed: calling sleep() with negative numbers could block forever, wasting CPU. Now it returns immediately (MPB); +* Improved: FTP commands are now sent in upper case to help buggy servers (Anders Eurenius); +* Improved: known headers now sent in canonic capitalization to help buggy servers (Joseph Stewart); +* Improved: Clarified tcp:receive() in the manual (MPB); +* Improved: Decent makefiles (LHF). +* Fixed: RFC links in documentation now point to IETF (Cosmin Apreutesei). + +## [v2.0.2](https://github.com/lunarmodules/luasocket/releases/v2.0.2) — 2007-09-11 diff -Nru luasocket-3.0~rc1+git+ac3201d/debian/changelog luasocket-3.1.0/debian/changelog --- luasocket-3.0~rc1+git+ac3201d/debian/changelog 2021-12-21 13:25:56.000000000 +0000 +++ luasocket-3.1.0/debian/changelog 2022-09-19 10:18:25.000000000 +0000 @@ -1,3 +1,16 @@ +luasocket (3.1.0-1) unstable; urgency=medium + + * upstream metadata from janitor + * update homepage + * New upstream version 3.1.0 + * project moved to https://github.com/lunarmodules/luasocket + * remove patch already merged + * replace LUASOCKET patch with version from #346 + * unix.tcp and unix.udp were renamed + * documentation is now in docs dir + + -- Victor Seva Mon, 19 Sep 2022 12:18:25 +0200 + luasocket (3.0~rc1+git+ac3201d-6) unstable; urgency=medium * Lua team as maintainer, me as uploader (Closes: #995536) diff -Nru luasocket-3.0~rc1+git+ac3201d/debian/control luasocket-3.1.0/debian/control --- luasocket-3.0~rc1+git+ac3201d/debian/control 2021-12-21 13:25:56.000000000 +0000 +++ luasocket-3.1.0/debian/control 2022-09-19 10:18:25.000000000 +0000 @@ -12,7 +12,7 @@ Standards-Version: 4.6.0.1 Vcs-Git: https://salsa.debian.org/lua-team/luasocket.git Vcs-Browser: https://salsa.debian.org/lua-team/luasocket -Homepage: http://w3.impa.br/~diego/software/luasocket/ +Homepage: https://lunarmodules.github.io/luasocket/ Package: lua-socket Architecture: any diff -Nru luasocket-3.0~rc1+git+ac3201d/debian/copyright luasocket-3.1.0/debian/copyright --- luasocket-3.0~rc1+git+ac3201d/debian/copyright 2021-12-21 13:25:56.000000000 +0000 +++ luasocket-3.1.0/debian/copyright 2022-09-19 10:18:25.000000000 +0000 @@ -1,7 +1,7 @@ Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: luasocket Upstream-Contact: Diego Nehab https://w3.impa.br/~diego/ -Source: https://github.com/diegonehab/luasocket +Source: https://github.com/lunarmodules/luasocket Files: * Copyright: 2004-2006 Diego Nehab diff -Nru luasocket-3.0~rc1+git+ac3201d/debian/lua5.1.02-unix.dh-lua.conf luasocket-3.1.0/debian/lua5.1.02-unix.dh-lua.conf --- luasocket-3.0~rc1+git+ac3201d/debian/lua5.1.02-unix.dh-lua.conf 2021-12-21 13:25:56.000000000 +0000 +++ luasocket-3.1.0/debian/lua5.1.02-unix.dh-lua.conf 2022-09-19 10:18:25.000000000 +0000 @@ -1,7 +1,7 @@ PKG_NAME=socket.unix CLIB_CFLAGS=-I src/ -I src/ -DLUASOCKET_NODEBUG -DLUA_NOCOMPAT_MODULE -DLUASOCKET_API='__attribute__((visibility("default")))' -DUNIX_API='__attribute__((visibility("default")))' -DMIME_API='__attribute__((visibility("default")))' -pedantic -Wall -Wshadow -Wextra -Wimplicit -fvisibility=hidden CLIB_OBJS=src/buffer.lo src/auxiliar.lo src/options.lo \ - src/timeout.lo src/io.lo src/usocket.lo src/unixtcp.lo src/unixudp.lo src/unix.lo src/compat.lo + src/timeout.lo src/io.lo src/usocket.lo src/unixstream.lo src/unixdgram.lo src/unix.lo src/compat.lo LUA_HEADER=src/unix.h LUA_MODNAME=socket.unix LUA_MODNAME_CPART=socket.unix diff -Nru luasocket-3.0~rc1+git+ac3201d/debian/lua5.2.02-unix.dh-lua.conf luasocket-3.1.0/debian/lua5.2.02-unix.dh-lua.conf --- luasocket-3.0~rc1+git+ac3201d/debian/lua5.2.02-unix.dh-lua.conf 2021-12-21 13:25:56.000000000 +0000 +++ luasocket-3.1.0/debian/lua5.2.02-unix.dh-lua.conf 2022-09-19 10:18:25.000000000 +0000 @@ -1,7 +1,7 @@ PKG_NAME=socket.unix CLIB_CFLAGS=-I src/ -I src/ -DLUASOCKET_NODEBUG -DLUA_NOCOMPAT_MODULE -DLUASOCKET_API='__attribute__((visibility("default")))' -DUNIX_API='__attribute__((visibility("default")))' -DMIME_API='__attribute__((visibility("default")))' -pedantic -Wall -Wshadow -Wextra -Wimplicit -fvisibility=hidden CLIB_OBJS=src/buffer.lo src/auxiliar.lo src/options.lo \ - src/timeout.lo src/io.lo src/usocket.lo src/unixtcp.lo src/unixudp.lo src/unix.lo src/compat.lo + src/timeout.lo src/io.lo src/usocket.lo src/unixstream.lo src/unixdgram.lo src/unix.lo src/compat.lo LUA_HEADER=src/unix.h LUA_MODNAME=socket.unix LUA_MODNAME_CPART=socket.unix diff -Nru luasocket-3.0~rc1+git+ac3201d/debian/lua5.3.02-unix.dh-lua.conf luasocket-3.1.0/debian/lua5.3.02-unix.dh-lua.conf --- luasocket-3.0~rc1+git+ac3201d/debian/lua5.3.02-unix.dh-lua.conf 2021-12-21 13:25:56.000000000 +0000 +++ luasocket-3.1.0/debian/lua5.3.02-unix.dh-lua.conf 2022-09-19 10:18:25.000000000 +0000 @@ -1,7 +1,7 @@ PKG_NAME=socket.unix CLIB_CFLAGS=-I src/ -I src/ -DLUASOCKET_NODEBUG -DLUA_NOCOMPAT_MODULE -DLUASOCKET_API='__attribute__((visibility("default")))' -DUNIX_API='__attribute__((visibility("default")))' -DMIME_API='__attribute__((visibility("default")))' -pedantic -Wall -Wshadow -Wextra -Wimplicit -fvisibility=hidden CLIB_OBJS=src/buffer.lo src/auxiliar.lo src/options.lo \ - src/timeout.lo src/io.lo src/usocket.lo src/unixtcp.lo src/unixudp.lo src/unix.lo src/compat.lo + src/timeout.lo src/io.lo src/usocket.lo src/unixstream.lo src/unixdgram.lo src/unix.lo src/compat.lo LUA_HEADER=src/unix.h LUA_MODNAME=socket.unix LUA_MODNAME_CPART=socket.unix diff -Nru luasocket-3.0~rc1+git+ac3201d/debian/lua5.4.02-unix.dh-lua.conf luasocket-3.1.0/debian/lua5.4.02-unix.dh-lua.conf --- luasocket-3.0~rc1+git+ac3201d/debian/lua5.4.02-unix.dh-lua.conf 2021-12-21 13:25:56.000000000 +0000 +++ luasocket-3.1.0/debian/lua5.4.02-unix.dh-lua.conf 2022-09-19 10:18:25.000000000 +0000 @@ -1,7 +1,7 @@ PKG_NAME=socket.unix CLIB_CFLAGS=-I src/ -I src/ -DLUASOCKET_NODEBUG -DLUA_NOCOMPAT_MODULE -DLUASOCKET_API='__attribute__((visibility("default")))' -DUNIX_API='__attribute__((visibility("default")))' -DMIME_API='__attribute__((visibility("default")))' -pedantic -Wall -Wshadow -Wextra -Wimplicit -fvisibility=hidden CLIB_OBJS=src/buffer.lo src/auxiliar.lo src/options.lo \ - src/timeout.lo src/io.lo src/usocket.lo src/unixtcp.lo src/unixudp.lo src/unix.lo src/compat.lo + src/timeout.lo src/io.lo src/usocket.lo src/unixstream.lo src/unixdgram.lo src/unix.lo src/compat.lo LUA_HEADER=src/unix.h LUA_MODNAME=socket.unix LUA_MODNAME_CPART=socket.unix diff -Nru luasocket-3.0~rc1+git+ac3201d/debian/lua-socket-dev.docs luasocket-3.1.0/debian/lua-socket-dev.docs --- luasocket-3.0~rc1+git+ac3201d/debian/lua-socket-dev.docs 2021-12-21 13:25:56.000000000 +0000 +++ luasocket-3.1.0/debian/lua-socket-dev.docs 2022-09-19 10:18:25.000000000 +0000 @@ -1,2 +1,2 @@ -doc/ +docs/ samples/ diff -Nru luasocket-3.0~rc1+git+ac3201d/debian/patches/0001-add-LUASOCKET_API.patch luasocket-3.1.0/debian/patches/0001-add-LUASOCKET_API.patch --- luasocket-3.0~rc1+git+ac3201d/debian/patches/0001-add-LUASOCKET_API.patch 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/debian/patches/0001-add-LUASOCKET_API.patch 2022-09-19 10:18:25.000000000 +0000 @@ -0,0 +1,291 @@ +From 26fd89be8425acfbe0d0e6eb348ab1b5227444d0 Mon Sep 17 00:00:00 2001 +From: Jonas Wielicki +Date: Wed, 31 Jul 2013 14:25:23 +0200 +Subject: [PATCH] Make the API more accessible by publishing constants + +--- + src/buffer.h | 15 ++++++++------- + src/common.h | 16 ++++++++++++++++ + src/io.h | 7 ++++--- + src/socket.h | 51 ++++++++++++++++++++++++++------------------------- + src/timeout.h | 19 ++++++++++--------- + src/usocket.c | 6 ------ + src/usocket.h | 16 ++++++++++++++++ + src/wsocket.c | 4 ---- + src/wsocket.h | 5 +++++ + 9 files changed, 85 insertions(+), 54 deletions(-) + create mode 100644 src/common.h + +diff --git a/src/buffer.h b/src/buffer.h +index a0901fcc..66acf090 100644 +--- a/src/buffer.h ++++ b/src/buffer.h +@@ -18,6 +18,7 @@ + #include "luasocket.h" + #include "io.h" + #include "timeout.h" ++#include "common.h" + + /* buffer size in bytes */ + #define BUF_SIZE 8192 +@@ -37,13 +38,13 @@ typedef t_buffer *p_buffer; + #pragma GCC visibility push(hidden) + #endif + +-int buffer_open(lua_State *L); +-void buffer_init(p_buffer buf, p_io io, p_timeout tm); +-int buffer_meth_getstats(lua_State *L, p_buffer buf); +-int buffer_meth_setstats(lua_State *L, p_buffer buf); +-int buffer_meth_send(lua_State *L, p_buffer buf); +-int buffer_meth_receive(lua_State *L, p_buffer buf); +-int buffer_isempty(p_buffer buf); ++LUASOCKET_API int buffer_open(lua_State *L); ++LUASOCKET_API void buffer_init(p_buffer buf, p_io io, p_timeout tm); ++LUASOCKET_API int buffer_meth_getstats(lua_State *L, p_buffer buf); ++LUASOCKET_API int buffer_meth_setstats(lua_State *L, p_buffer buf); ++LUASOCKET_API int buffer_meth_send(lua_State *L, p_buffer buf); ++LUASOCKET_API int buffer_meth_receive(lua_State *L, p_buffer buf); ++LUASOCKET_API int buffer_isempty(p_buffer buf); + + #ifndef _WIN32 + #pragma GCC visibility pop +diff --git a/src/common.h b/src/common.h +new file mode 100644 +index 00000000..9bb06660 +--- /dev/null ++++ b/src/common.h +@@ -0,0 +1,16 @@ ++#ifndef LUASOCKET_COMMON_H ++#define LUASOCKET_COMMON_H ++ ++#ifndef LUASOCKET_API ++#define LUASOCKET_API extern ++#endif ++ ++#ifndef UNIX_API ++#define UNIX_API extern ++#endif ++ ++#ifndef MIME_API ++#define MIME_API extern ++#endif ++ ++#endif +diff --git a/src/io.h b/src/io.h +index b8a54df6..6e399fb3 100644 +--- a/src/io.h ++++ b/src/io.h +@@ -14,13 +14,14 @@ + \*=========================================================================*/ + #include "luasocket.h" + #include "timeout.h" ++#include "common.h" + + /* IO error codes */ + enum { + IO_DONE = 0, /* operation completed successfully */ + IO_TIMEOUT = -1, /* operation timed out */ + IO_CLOSED = -2, /* the connection has been closed */ +- IO_UNKNOWN = -3 ++ IO_UNKNOWN = -3 + }; + + /* interface to error message function */ +@@ -60,8 +61,8 @@ typedef t_io *p_io; + #pragma GCC visibility push(hidden) + #endif + +-void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx); +-const char *io_strerror(int err); ++LUASOCKET_API void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx); ++LUASOCKET_API const char *io_strerror(int err); + + #ifndef _WIN32 + #pragma GCC visibility pop +diff --git a/src/socket.h b/src/socket.h +index e541f27d..e0b64324 100644 +--- a/src/socket.h ++++ b/src/socket.h +@@ -10,6 +10,7 @@ + * creates a interface compatible with the io.h module. + \*=========================================================================*/ + #include "io.h" ++#include "common.h" + + /*=========================================================================*\ + * Platform specific compatibilization +@@ -40,31 +41,31 @@ typedef struct sockaddr SA; + #pragma GCC visibility push(hidden) + #endif + +-int socket_waitfd(p_socket ps, int sw, p_timeout tm); +-int socket_open(void); +-int socket_close(void); +-void socket_destroy(p_socket ps); +-int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds, p_timeout tm); +-int socket_create(p_socket ps, int domain, int type, int protocol); +-int socket_bind(p_socket ps, SA *addr, socklen_t addr_len); +-int socket_listen(p_socket ps, int backlog); +-void socket_shutdown(p_socket ps, int how); +-int socket_connect(p_socket ps, SA *addr, socklen_t addr_len, p_timeout tm); +-int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *addr_len, p_timeout tm); +-int socket_send(p_socket ps, const char *data, size_t count, size_t *sent, p_timeout tm); +-int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent, SA *addr, socklen_t addr_len, p_timeout tm); +-int socket_recv(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm); +-int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got, SA *addr, socklen_t *addr_len, p_timeout tm); +-int socket_write(p_socket ps, const char *data, size_t count, size_t *sent, p_timeout tm); +-int socket_read(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm); +-void socket_setblocking(p_socket ps); +-void socket_setnonblocking(p_socket ps); +-int socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp); +-int socket_gethostbyname(const char *addr, struct hostent **hp); +-const char *socket_hoststrerror(int err); +-const char *socket_strerror(int err); +-const char *socket_ioerror(p_socket ps, int err); +-const char *socket_gaistrerror(int err); ++LUASOCKET_API int socket_waitfd(p_socket ps, int sw, p_timeout tm); ++LUASOCKET_API int socket_open(void); ++LUASOCKET_API int socket_close(void); ++LUASOCKET_API void socket_destroy(p_socket ps); ++LUASOCKET_API int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds, p_timeout tm); ++LUASOCKET_API int socket_create(p_socket ps, int domain, int type, int protocol); ++LUASOCKET_API int socket_bind(p_socket ps, SA *addr, socklen_t addr_len); ++LUASOCKET_API int socket_listen(p_socket ps, int backlog); ++LUASOCKET_API void socket_shutdown(p_socket ps, int how); ++LUASOCKET_API int socket_connect(p_socket ps, SA *addr, socklen_t addr_len, p_timeout tm); ++LUASOCKET_API int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *addr_len, p_timeout tm); ++LUASOCKET_API int socket_send(p_socket ps, const char *data, size_t count, size_t *sent, p_timeout tm); ++LUASOCKET_API int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent, SA *addr, socklen_t addr_len, p_timeout tm); ++LUASOCKET_API int socket_recv(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm); ++LUASOCKET_API int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got, SA *addr, socklen_t *addr_len, p_timeout tm); ++LUASOCKET_API int socket_write(p_socket ps, const char *data, size_t count, size_t *sent, p_timeout tm); ++LUASOCKET_API int socket_read(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm); ++LUASOCKET_API void socket_setblocking(p_socket ps); ++LUASOCKET_API void socket_setnonblocking(p_socket ps); ++LUASOCKET_API int socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp); ++LUASOCKET_API int socket_gethostbyname(const char *addr, struct hostent **hp); ++LUASOCKET_API const char *socket_hoststrerror(int err); ++LUASOCKET_API const char *socket_strerror(int err); ++LUASOCKET_API const char *socket_ioerror(p_socket ps, int err); ++LUASOCKET_API const char *socket_gaistrerror(int err); + + #ifndef _WIN32 + #pragma GCC visibility pop +diff --git a/src/timeout.h b/src/timeout.h +index 9e5250d3..b36bd588 100644 +--- a/src/timeout.h ++++ b/src/timeout.h +@@ -5,6 +5,7 @@ + * LuaSocket toolkit + \*=========================================================================*/ + #include "luasocket.h" ++#include "common.h" + + /* timeout control structure */ + typedef struct t_timeout_ { +@@ -18,18 +19,18 @@ typedef t_timeout *p_timeout; + #pragma GCC visibility push(hidden) + #endif + +-void timeout_init(p_timeout tm, double block, double total); +-double timeout_get(p_timeout tm); +-double timeout_getstart(p_timeout tm); +-double timeout_getretry(p_timeout tm); +-p_timeout timeout_markstart(p_timeout tm); ++LUASOCKET_API void timeout_init(p_timeout tm, double block, double total); ++LUASOCKET_API double timeout_get(p_timeout tm); ++LUASOCKET_API double timeout_getstart(p_timeout tm); ++LUASOCKET_API double timeout_getretry(p_timeout tm); ++LUASOCKET_API p_timeout timeout_markstart(p_timeout tm); + +-double timeout_gettime(void); ++LUASOCKET_API double timeout_gettime(void); + +-int timeout_open(lua_State *L); ++LUASOCKET_API int timeout_open(lua_State *L); + +-int timeout_meth_settimeout(lua_State *L, p_timeout tm); +-int timeout_meth_gettimeout(lua_State *L, p_timeout tm); ++LUASOCKET_API int timeout_meth_settimeout(lua_State *L, p_timeout tm); ++LUASOCKET_API int timeout_meth_gettimeout(lua_State *L, p_timeout tm); + + #ifndef _WIN32 + #pragma GCC visibility pop +diff --git a/src/usocket.c b/src/usocket.c +index acfe186c..7490df56 100644 +--- a/src/usocket.c ++++ b/src/usocket.c +@@ -20,9 +20,6 @@ + #ifndef SOCKET_SELECT + #include + +-#define WAITFD_R POLLIN +-#define WAITFD_W POLLOUT +-#define WAITFD_C (POLLIN|POLLOUT) + int socket_waitfd(p_socket ps, int sw, p_timeout tm) { + int ret; + struct pollfd pfd; +@@ -41,9 +38,6 @@ int socket_waitfd(p_socket ps, int sw, p_timeout tm) { + } + #else + +-#define WAITFD_R 1 +-#define WAITFD_W 2 +-#define WAITFD_C (WAITFD_R|WAITFD_W) + + int socket_waitfd(p_socket ps, int sw, p_timeout tm) { + int ret; +diff --git a/src/usocket.h b/src/usocket.h +index 45f2f99f..ca67c95c 100644 +--- a/src/usocket.h ++++ b/src/usocket.h +@@ -56,4 +56,20 @@ typedef struct sockaddr_storage t_sockaddr_storage; + + #define SOCKET_INVALID (-1) + ++#ifndef SOCKET_SELECT ++#include ++ ++#define WAITFD_R POLLIN ++#define WAITFD_W POLLOUT ++#define WAITFD_C (POLLIN|POLLOUT) ++ ++#else ++ ++#define WAITFD_R 1 ++#define WAITFD_W 2 ++#define WAITFD_C (WAITFD_R|WAITFD_W) ++ ++#endif ++ ++ + #endif /* USOCKET_H */ +diff --git a/src/wsocket.c b/src/wsocket.c +index 7cd41159..0bb1833f 100755 +--- a/src/wsocket.c ++++ b/src/wsocket.c +@@ -42,10 +42,6 @@ int socket_close(void) { + /*-------------------------------------------------------------------------*\ + * Wait for readable/writable/connected socket with timeout + \*-------------------------------------------------------------------------*/ +-#define WAITFD_R 1 +-#define WAITFD_W 2 +-#define WAITFD_E 4 +-#define WAITFD_C (WAITFD_E|WAITFD_W) + + int socket_waitfd(p_socket ps, int sw, p_timeout tm) { + int ret; +diff --git a/src/wsocket.h b/src/wsocket.h +index 39866402..55ab0a93 100644 +--- a/src/wsocket.h ++++ b/src/wsocket.h +@@ -30,4 +30,9 @@ typedef t_socket *p_socket; + #define AI_NUMERICSERV (0) + #endif + ++#define WAITFD_R 1 ++#define WAITFD_W 2 ++#define WAITFD_E 4 ++#define WAITFD_C (WAITFD_E|WAITFD_W) ++ + #endif /* WSOCKET_H */ diff -Nru luasocket-3.0~rc1+git+ac3201d/debian/patches/0001-add-LUASOCKET_API-to-timeout_markstart-init-for-lua-.patch luasocket-3.1.0/debian/patches/0001-add-LUASOCKET_API-to-timeout_markstart-init-for-lua-.patch --- luasocket-3.0~rc1+git+ac3201d/debian/patches/0001-add-LUASOCKET_API-to-timeout_markstart-init-for-lua-.patch 2021-12-21 13:25:56.000000000 +0000 +++ luasocket-3.1.0/debian/patches/0001-add-LUASOCKET_API-to-timeout_markstart-init-for-lua-.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,171 +0,0 @@ -From: Enrico Tassi -Date: Fri, 9 Aug 2013 16:48:11 +0200 -Subject: add LUASOCKET_API to timeout_markstart/init (for lua-sec) - ---- - src/buffer.c | 12 ++++++------ - src/io.c | 2 +- - src/timeout.c | 6 +++--- - src/usocket.c | 12 ++++++------ - 4 files changed, 16 insertions(+), 16 deletions(-) - -diff --git a/src/buffer.c b/src/buffer.c -index fff1634..94e6580 100644 ---- a/src/buffer.c -+++ b/src/buffer.c -@@ -40,7 +40,7 @@ int buffer_open(lua_State *L) { - /*-------------------------------------------------------------------------*\ - * Initializes C structure - \*-------------------------------------------------------------------------*/ --void buffer_init(p_buffer buf, p_io io, p_timeout tm) { -+LUASOCKET_API void buffer_init(p_buffer buf, p_io io, p_timeout tm) { - buf->first = buf->last = 0; - buf->io = io; - buf->tm = tm; -@@ -51,7 +51,7 @@ void buffer_init(p_buffer buf, p_io io, p_timeout tm) { - /*-------------------------------------------------------------------------*\ - * object:getstats() interface - \*-------------------------------------------------------------------------*/ --int buffer_meth_getstats(lua_State *L, p_buffer buf) { -+LUASOCKET_API int buffer_meth_getstats(lua_State *L, p_buffer buf) { - lua_pushnumber(L, (lua_Number) buf->received); - lua_pushnumber(L, (lua_Number) buf->sent); - lua_pushnumber(L, timeout_gettime() - buf->birthday); -@@ -61,7 +61,7 @@ int buffer_meth_getstats(lua_State *L, p_buffer buf) { - /*-------------------------------------------------------------------------*\ - * object:setstats() interface - \*-------------------------------------------------------------------------*/ --int buffer_meth_setstats(lua_State *L, p_buffer buf) { -+LUASOCKET_API int buffer_meth_setstats(lua_State *L, p_buffer buf) { - buf->received = (long) luaL_optnumber(L, 2, (lua_Number) buf->received); - buf->sent = (long) luaL_optnumber(L, 3, (lua_Number) buf->sent); - if (lua_isnumber(L, 4)) buf->birthday = timeout_gettime() - lua_tonumber(L, 4); -@@ -72,7 +72,7 @@ int buffer_meth_setstats(lua_State *L, p_buffer buf) { - /*-------------------------------------------------------------------------*\ - * object:send() interface - \*-------------------------------------------------------------------------*/ --int buffer_meth_send(lua_State *L, p_buffer buf) { -+LUASOCKET_API int buffer_meth_send(lua_State *L, p_buffer buf) { - int top = lua_gettop(L); - int err = IO_DONE; - size_t size = 0, sent = 0; -@@ -105,7 +105,7 @@ int buffer_meth_send(lua_State *L, p_buffer buf) { - /*-------------------------------------------------------------------------*\ - * object:receive() interface - \*-------------------------------------------------------------------------*/ --int buffer_meth_receive(lua_State *L, p_buffer buf) { -+LUASOCKET_API int buffer_meth_receive(lua_State *L, p_buffer buf) { - int err = IO_DONE, top = lua_gettop(L); - luaL_Buffer b; - size_t size; -@@ -154,7 +154,7 @@ int buffer_meth_receive(lua_State *L, p_buffer buf) { - /*-------------------------------------------------------------------------*\ - * Determines if there is any data in the read buffer - \*-------------------------------------------------------------------------*/ --int buffer_isempty(p_buffer buf) { -+LUASOCKET_API int buffer_isempty(p_buffer buf) { - return buf->first >= buf->last; - } - -diff --git a/src/io.c b/src/io.c -index a4230ce..cd28b41 100644 ---- a/src/io.c -+++ b/src/io.c -@@ -10,7 +10,7 @@ - /*-------------------------------------------------------------------------*\ - * Initializes C structure - \*-------------------------------------------------------------------------*/ --void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx) { -+LUASOCKET_API void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx) { - io->send = send; - io->recv = recv; - io->error = error; -diff --git a/src/timeout.c b/src/timeout.c -index 5a601d5..742f7c8 100644 ---- a/src/timeout.c -+++ b/src/timeout.c -@@ -46,7 +46,7 @@ static luaL_Reg func[] = { - /*-------------------------------------------------------------------------*\ - * Initialize structure - \*-------------------------------------------------------------------------*/ --void timeout_init(p_timeout tm, double block, double total) { -+LUASOCKET_API void timeout_init(p_timeout tm, double block, double total) { - tm->block = block; - tm->total = total; - } -@@ -112,7 +112,7 @@ double timeout_getretry(p_timeout tm) { - * Input - * tm: timeout control structure - \*-------------------------------------------------------------------------*/ --p_timeout timeout_markstart(p_timeout tm) { -+LUASOCKET_API p_timeout timeout_markstart(p_timeout tm) { - tm->start = timeout_gettime(); - return tm; - } -@@ -155,7 +155,7 @@ int timeout_open(lua_State *L) { - * time: time out value in seconds - * mode: "b" for block timeout, "t" for total timeout. (default: b) - \*-------------------------------------------------------------------------*/ --int timeout_meth_settimeout(lua_State *L, p_timeout tm) { -+LUASOCKET_API int timeout_meth_settimeout(lua_State *L, p_timeout tm) { - double t = luaL_optnumber(L, 2, -1); - const char *mode = luaL_optstring(L, 3, "b"); - switch (*mode) { -diff --git a/src/usocket.c b/src/usocket.c -index 8adc573..fce2400 100644 ---- a/src/usocket.c -+++ b/src/usocket.c -@@ -21,7 +21,7 @@ - #define WAITFD_R POLLIN - #define WAITFD_W POLLOUT - #define WAITFD_C (POLLIN|POLLOUT) --int socket_waitfd(p_socket ps, int sw, p_timeout tm) { -+LUASOCKET_API int socket_waitfd(p_socket ps, int sw, p_timeout tm) { - int ret; - struct pollfd pfd; - pfd.fd = *ps; -@@ -75,7 +75,7 @@ int socket_waitfd(p_socket ps, int sw, p_timeout tm) { - /*-------------------------------------------------------------------------*\ - * Initializes module - \*-------------------------------------------------------------------------*/ --int socket_open(void) { -+LUASOCKET_API int socket_open(void) { - /* instals a handler to ignore sigpipe or it will crash us */ - signal(SIGPIPE, SIG_IGN); - return 1; -@@ -91,7 +91,7 @@ int socket_close(void) { - /*-------------------------------------------------------------------------*\ - * Close and inutilize socket - \*-------------------------------------------------------------------------*/ --void socket_destroy(p_socket ps) { -+LUASOCKET_API void socket_destroy(p_socket ps) { - if (*ps != SOCKET_INVALID) { - close(*ps); - *ps = SOCKET_INVALID; -@@ -359,7 +359,7 @@ int socket_read(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm - /*-------------------------------------------------------------------------*\ - * Put socket into blocking mode - \*-------------------------------------------------------------------------*/ --void socket_setblocking(p_socket ps) { -+LUASOCKET_API void socket_setblocking(p_socket ps) { - int flags = fcntl(*ps, F_GETFL, 0); - flags &= (~(O_NONBLOCK)); - fcntl(*ps, F_SETFL, flags); -@@ -368,7 +368,7 @@ void socket_setblocking(p_socket ps) { - /*-------------------------------------------------------------------------*\ - * Put socket into non-blocking mode - \*-------------------------------------------------------------------------*/ --void socket_setnonblocking(p_socket ps) { -+LUASOCKET_API void socket_setnonblocking(p_socket ps) { - int flags = fcntl(*ps, F_GETFL, 0); - flags |= O_NONBLOCK; - fcntl(*ps, F_SETFL, flags); -@@ -405,7 +405,7 @@ const char *socket_hoststrerror(int err) { - } - } - --const char *socket_strerror(int err) { -+LUASOCKET_API const char *socket_strerror(int err) { - if (err <= 0) return io_strerror(err); - switch (err) { - case EADDRINUSE: return PIE_ADDRINUSE; diff -Nru luasocket-3.0~rc1+git+ac3201d/debian/patches/0002-Add-backwards-compatibility-wrappers-for-socket.unix.patch luasocket-3.1.0/debian/patches/0002-Add-backwards-compatibility-wrappers-for-socket.unix.patch --- luasocket-3.0~rc1+git+ac3201d/debian/patches/0002-Add-backwards-compatibility-wrappers-for-socket.unix.patch 2021-12-21 13:25:56.000000000 +0000 +++ luasocket-3.1.0/debian/patches/0002-Add-backwards-compatibility-wrappers-for-socket.unix.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,135 +0,0 @@ -From: Courtney Bane -Date: Wed, 25 Jan 2017 18:04:35 -0600 -Subject: Add backwards compatibility wrappers for socket.unix - -Add backwards compatibility aliases "tcp" and "udp" for the recently renamed -"stream" and "dgram" functions, as well as a wrapper function and metatable -setup so that socket.unix() calls socket.unix.stream(). - -(cherry picked from commit ea0064625b2a4cf279977477fe2ca627afbd5ad0) ---- - src/unix.c | 50 +++++++++++++++++++++++++++++++++++++++++++++----- - 1 file changed, 45 insertions(+), 5 deletions(-) - -diff --git a/src/unix.c b/src/unix.c -index 2009c19..d362a3b 100644 ---- a/src/unix.c -+++ b/src/unix.c -@@ -17,14 +17,54 @@ static const luaL_Reg mod[] = { - {NULL, NULL} - }; - -+static void add_alias(lua_State *L, int index, const char *name, const char *target) -+{ -+ lua_getfield(L, index, target); -+ lua_setfield(L, index, name); -+} -+ -+static int compat_socket_unix_call(lua_State *L) -+{ -+ /* Look up socket.unix.stream in the socket.unix table (which is the first -+ * argument). */ -+ lua_getfield(L, 1, "stream"); -+ -+ /* Replace the stack entry for the socket.unix table with the -+ * socket.unix.stream function. */ -+ lua_replace(L, 1); -+ -+ /* Call socket.unix.stream, passing along any arguments. */ -+ int n = lua_gettop(L); -+ lua_call(L, n-1, LUA_MULTRET); -+ -+ /* Pass along the return values from socket.unix.stream. */ -+ n = lua_gettop(L); -+ return n; -+} -+ - /*-------------------------------------------------------------------------*\ - * Initializes module - \*-------------------------------------------------------------------------*/ - int luaopen_socket_unix(lua_State *L) - { -- int i; -- lua_newtable(L); -- for (i = 0; mod[i].name; i++) mod[i].func(L); -- return 1; --} -+ int i; -+ lua_newtable(L); -+ int socket_unix_table = lua_gettop(L); -+ -+ for (i = 0; mod[i].name; i++) -+ mod[i].func(L); - -+ /* Add backwards compatibility aliases "tcp" and "udp" for the "stream" and -+ * "dgram" functions. */ -+ add_alias(L, socket_unix_table, "tcp", "stream"); -+ add_alias(L, socket_unix_table, "udp", "dgram"); -+ -+ /* Add a backwards compatibility function and a metatable setup to call it -+ * for the old socket.unix() interface. */ -+ lua_pushcfunction(L, compat_socket_unix_call); -+ lua_setfield(L, socket_unix_table, "__call"); -+ lua_pushvalue(L, socket_unix_table); -+ lua_setmetatable(L, socket_unix_table); -+ -+ return 1; -+} --- -2.11.0 - -From: Mathieu Parent -Date: Thu, 26 Jan 2017 08:04:52 +0100 -Subject: Change backward compat by forward compat - ---- - src/unix.c | 18 +++++++++--------- - 1 file changed, 9 insertions(+), 9 deletions(-) - -diff --git a/src/unix.c b/src/unix.c -index d362a3b..74c5392 100644 ---- a/src/unix.c -+++ b/src/unix.c -@@ -25,19 +25,19 @@ static void add_alias(lua_State *L, int index, const char *name, const char *tar - - static int compat_socket_unix_call(lua_State *L) - { -- /* Look up socket.unix.stream in the socket.unix table (which is the first -+ /* Look up socket.unix.tcp in the socket.unix table (which is the first - * argument). */ -- lua_getfield(L, 1, "stream"); -+ lua_getfield(L, 1, "tcp"); - - /* Replace the stack entry for the socket.unix table with the -- * socket.unix.stream function. */ -+ * socket.unix.tcp function. */ - lua_replace(L, 1); - -- /* Call socket.unix.stream, passing along any arguments. */ -+ /* Call socket.unix.tcp, passing along any arguments. */ - int n = lua_gettop(L); - lua_call(L, n-1, LUA_MULTRET); - -- /* Pass along the return values from socket.unix.stream. */ -+ /* Pass along the return values from socket.unix.tcp. */ - n = lua_gettop(L); - return n; - } -@@ -54,10 +54,10 @@ int luaopen_socket_unix(lua_State *L) - for (i = 0; mod[i].name; i++) - mod[i].func(L); - -- /* Add backwards compatibility aliases "tcp" and "udp" for the "stream" and -- * "dgram" functions. */ -- add_alias(L, socket_unix_table, "tcp", "stream"); -- add_alias(L, socket_unix_table, "udp", "dgram"); -+ /* Add forward compatibility aliases "stream" and "dgram" for the "tcp" and -+ * "udp" functions. */ -+ add_alias(L, socket_unix_table, "stream", "tcp"); -+ add_alias(L, socket_unix_table, "dgram", "udp"); - - /* Add a backwards compatibility function and a metatable setup to call it - * for the old socket.unix() interface. */ --- -2.11.0 - diff -Nru luasocket-3.0~rc1+git+ac3201d/debian/patches/series luasocket-3.1.0/debian/patches/series --- luasocket-3.0~rc1+git+ac3201d/debian/patches/series 2021-12-21 13:25:56.000000000 +0000 +++ luasocket-3.1.0/debian/patches/series 2022-09-19 10:18:25.000000000 +0000 @@ -1,2 +1 @@ -0001-add-LUASOCKET_API-to-timeout_markstart-init-for-lua-.patch -0002-Add-backwards-compatibility-wrappers-for-socket.unix.patch +0001-add-LUASOCKET_API.patch diff -Nru luasocket-3.0~rc1+git+ac3201d/debian/rules luasocket-3.1.0/debian/rules --- luasocket-3.0~rc1+git+ac3201d/debian/rules 2021-12-21 13:25:56.000000000 +0000 +++ luasocket-3.1.0/debian/rules 2022-09-19 10:18:25.000000000 +0000 @@ -4,4 +4,4 @@ dh $@ --buildsystem=lua --with lua override_dh_installdocs: - dh_installdocs -Xdoc/lua05.ppt + dh_installdocs -Xdocs/lua05.ppt diff -Nru luasocket-3.0~rc1+git+ac3201d/debian/upstream/metadata luasocket-3.1.0/debian/upstream/metadata --- luasocket-3.0~rc1+git+ac3201d/debian/upstream/metadata 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/debian/upstream/metadata 2022-09-19 10:18:25.000000000 +0000 @@ -0,0 +1,2 @@ +Bug-Database: https://github.com/diegonehab/luasocket/issues +Bug-Submit: https://github.com/diegonehab/luasocket/issues/new diff -Nru luasocket-3.0~rc1+git+ac3201d/debian/watch luasocket-3.1.0/debian/watch --- luasocket-3.0~rc1+git+ac3201d/debian/watch 2021-12-21 13:25:56.000000000 +0000 +++ luasocket-3.1.0/debian/watch 2022-09-19 10:18:25.000000000 +0000 @@ -3,4 +3,4 @@ # version=4 opts=filenamemangle=s/.+\/v?(\d\S+)\.tar\.gz/luasocket-$1\.tar\.gz/ \ - https://github.com/diegonehab/luasocket/tags .*/v?(\d\S+)\.tar\.gz + https://github.com/lunarmodules/luasocket/tags .*/v?(\d\S+)\.tar\.gz diff -Nru luasocket-3.0~rc1+git+ac3201d/doc/dns.html luasocket-3.1.0/doc/dns.html --- luasocket-3.0~rc1+git+ac3201d/doc/dns.html 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/doc/dns.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,183 +0,0 @@ - - - - - - -LuaSocket: DNS support - - - - - - - -
-
-
- - - -
-LuaSocket -
Network support for the Lua language -
-

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

-
-
-
- - - -

DNS

- -

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

- -
-resolved4 = {
-  name = canonic-name,
-  alias = alias-list,
-  ip = ip-address-list
-} -
- -

-Note that the alias list can be empty. -

- -

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

- -
-resolved6 = {
-  [1] = {
-    family = family-name-1,
-    addr = address-1
-  },
-  ...
-  [n] = {
-    family = family-name-n,
-    addr = address-n
-  }
-} -
- -

-Here, family contains the string "inet" for IPv4 -addresses, and "inet6" for IPv6 addresses. -

- - - -

-socket.dns.getaddrinfo(address) -

- -

-Converts from host name to address. -

- -

-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. -

- - - -

-socket.dns.gethostname() -

- -

-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. -

- -

-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. -

- - - -

-socket.dns.toip(address) -

- -

-Converts from host name to IPv4 address. -

- -

-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. -

- - - - - - - diff -Nru luasocket-3.0~rc1+git+ac3201d/doc/ftp.html luasocket-3.1.0/doc/ftp.html --- luasocket-3.0~rc1+git+ac3201d/doc/ftp.html 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/doc/ftp.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,288 +0,0 @@ - - - - - - -LuaSocket: FTP support - - - - - - - -
-
-
- - - -
-LuaSocket -
Network support for the Lua language -
-

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

-
-
-
- - - -

FTP

- -

-FTP (File Transfer Protocol) is a protocol used to transfer files -between hosts. The ftp namespace offers thorough support -to FTP, under a simple interface. The implementation conforms to -RFC 959. -

- -

-High level functions are provided supporting the most common operations. -These high level functions are implemented on top of a lower level -interface. Using the low-level interface, users can easily create their -own functions to access any operation supported by the FTP -protocol. For that, check the implementation. -

- -

-To really benefit from this module, a good understanding of - -LTN012, Filters sources and sinks is necessary. -

- -

-To obtain the ftp namespace, run: -

- -
--- loads the FTP module and any libraries it requires
-local ftp = require("socket.ftp")
-
- -

-URLs MUST conform to -RFC 1738, -that is, an URL is a string in the form: -

- -
- -[ftp://][<user>[:<password>]@]<host>[:<port>][/<path>][type=a|i] -
- -

-The following constants in the namespace can be set to control the default behavior of -the FTP module: -

- -
    -
  • PASSWORD: default anonymous password. -
  • TIMEOUT: sets the timeout for all I/O operations; -
  • USER: default anonymous user; -
- - - - -

-ftp.get(url)
-ftp.get{
-  host = string,
-  sink = LTN12 sink,
-  argument or path = string,
-  [user = string,]
-  [password = string]
-  [command = string,]
-  [port = number,]
-  [type = string,]
-  [step = LTN12 pump step,]
-  [create = function]
-} -

- -

-The get function has two forms. The simple form has fixed -functionality: it downloads the contents of a URL and returns it as a -string. The generic form allows a lot more control, as explained -below. -

- -

-If the argument of the get function is a table, the function -expects at least the fields host, sink, and one of -argument or path (argument takes -precedence). Host is the server to connect to. Sink is -the simple -LTN12 -sink that will receive the downloaded data. Argument or -path give the target path to the resource in the server. The -optional arguments are the following: -

-
    -
  • user, password: User name and password used for -authentication. Defaults to "ftp:anonymous@anonymous.org"; -
  • command: The FTP command used to obtain data. Defaults to -"retr", but see example below; -
  • port: The port to used for the control connection. Defaults to 21; -
  • type: The transfer mode. Can take values "i" or -"a". Defaults to whatever is the server default; -
  • step: -LTN12 -pump step function used to pass data from the -server to the sink. Defaults to the LTN12 pump.step function; -
  • create: An optional function to be used instead of -socket.tcp when the communications socket is created. -
- -

-If successful, the simple version returns the URL contents as a -string, and the generic function returns 1. In case of error, both -functions return nil and an error message describing the -error. -

- -
--- load the ftp support
-local ftp = require("socket.ftp")
-
--- Log as user "anonymous" on server "ftp.tecgraf.puc-rio.br",
--- and get file "lua.tar.gz" from directory "pub/lua" as binary.
-f, e = ftp.get("ftp://ftp.tecgraf.puc-rio.br/pub/lua/lua.tar.gz;type=i")
-
- -
--- load needed modules
-local ftp = require("socket.ftp")
-local ltn12 = require("ltn12")
-local url = require("socket.url")
-
--- a function that returns a directory listing
-function nlst(u)
-    local t = {}
-    local p = url.parse(u)
-    p.command = "nlst"
-    p.sink = ltn12.sink.table(t)
-    local r, e = ftp.get(p)
-    return r and table.concat(t), e
-end
-
- - - -

-ftp.put(url, content)
-ftp.put{
-  host = string,
-  source = LTN12 sink,
-  argument or path = string,
-  [user = string,]
-  [password = string]
-  [command = string,]
-  [port = number,]
-  [type = string,]
-  [step = LTN12 pump step,]
-  [create = function]
-} -

- -

-The put function has two forms. The simple form has fixed -functionality: it uploads a string of content into a URL. The generic form -allows a lot more control, as explained below. -

- -

-If the argument of the put function is a table, the function -expects at least the fields host, source, and one of -argument or path (argument takes -precedence). Host is the server to connect to. Source is -the simple -LTN12 -source that will provide the contents to be uploaded. -Argument or -path give the target path to the resource in the server. The -optional arguments are the following: -

-
    -
  • user, password: User name and password used for -authentication. Defaults to "ftp:anonymous@anonymous.org"; -
  • command: The FTP command used to send data. Defaults to -"stor", but see example below; -
  • port: The port to used for the control connection. Defaults to 21; -
  • type: The transfer mode. Can take values "i" or -"a". Defaults to whatever is the server default; -
  • step: -LTN12 -pump step function used to pass data from the -server to the sink. Defaults to the LTN12 pump.step function; -
  • create: An optional function to be used instead of -socket.tcp when the communications socket is created. -
- -

-Both functions return 1 if successful, or nil and an error -message describing the reason for failure. -

- -
--- load the ftp support
-local ftp = require("socket.ftp")
-
--- Log as user "fulano" on server "ftp.example.com",
--- using password "silva", and store a file "README" with contents 
--- "wrong password, of course"
-f, e = ftp.put("ftp://fulano:silva@ftp.example.com/README", 
-    "wrong password, of course")
-
- -
--- load the ftp support
-local ftp = require("socket.ftp")
-local ltn12 = require("ltn12")
-
--- Log as user "fulano" on server "ftp.example.com",
--- using password "silva", and append to the remote file "LOG", sending the
--- contents of the local file "LOCAL-LOG"
-f, e = ftp.put{
-  host = "ftp.example.com", 
-  user = "fulano",
-  password = "silva",
-  command = "appe",
-  argument = "LOG",
-  source = ltn12.source.file(io.open("LOCAL-LOG", "r"))
-}
-
- - - - - - - - diff -Nru luasocket-3.0~rc1+git+ac3201d/doc/http.html luasocket-3.1.0/doc/http.html --- luasocket-3.0~rc1+git+ac3201d/doc/http.html 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/doc/http.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,335 +0,0 @@ - - - - - - -LuaSocket: HTTP support - - - - - - - -
-
-
- - - -
-LuaSocket -
Network support for the Lua language -
-

-home · -download · -introduction · -introduction · -reference -

-
-
-
- - - -

HTTP

- -

-HTTP (Hyper Text Transfer Protocol) is the protocol used to exchange -information between web-browsers and servers. The http -namespace offers full support for the client side of the HTTP -protocol (i.e., -the facilities that would be used by a web-browser implementation). The -implementation conforms to the HTTP/1.1 standard, -RFC 2616. -

- -

-The module exports functions that provide HTTP functionality in different -levels of abstraction. From the simple -string oriented requests, through generic -LTN12 based, down to even lower-level if you bother to look through the source code. -

- -

-To obtain the http namespace, run: -

- -
--- loads the HTTP module and any libraries it requires
-local http = require("socket.http")
-
- -

-URLs must conform to -RFC 1738, -that is, an URL is a string in the form: -

- -
-
-[http://][<user>[:<password>]@]<host>[:<port>][/<path>] 
-
-
- -

-MIME headers are represented as a Lua table in the form: -

- -
- - -
-headers = {
-  field-1-name = field-1-value,
-  field-2-name = field-2-value,
-  field-3-name = field-3-value,
-  ...
-  field-n-name = field-n-value
-} -
-
- -

-Field names are case insensitive (as specified by the standard) and all -functions work with lowercase field names (but see -socket.headers.canonic). -Field values are left unmodified. -

- -

-Note: MIME headers are independent of order. Therefore, there is no problem -in representing them in a Lua table. -

- -

-The following constants can be set to control the default behavior of -the HTTP module: -

- -
    -
  • PROXY: default proxy used for connections; -
  • TIMEOUT: sets the timeout for all I/O operations; -
  • USERAGENT: default user agent reported to server. -
- -

-Note: These constants are global. Changing them will also -change the behavior other code that might be using LuaSocket. -

- - - -

-http.request(url [, body])
-http.request{
-  url = string,
-  [sink = LTN12 sink,]
-  [method = string,]
-  [headers = header-table,]
-  [source = LTN12 source],
-  [step = LTN12 pump step,]
-  [proxy = string,]
-  [redirect = boolean,]
-  [create = function]
-} -

- -

-The request function has two forms. The simple form downloads -a URL using the GET or POST method and is based -on strings. The generic form performs any HTTP method and is -LTN12 based. -

- -

-If the first argument of the request function is a string, it -should be an url. In that case, if a body -is provided as a string, the function will perform a POST method -in the url. Otherwise, it performs a GET in the -url -

- -

-If the first argument is instead a table, the most important fields are -the url and the simple -LTN12 -sink that will receive the downloaded content. -Any part of the url can be overridden by including -the appropriate field in the request table. -If authentication information is provided, the function -uses the Basic Authentication Scheme (see note) -to retrieve the document. If sink is nil, the -function discards the downloaded data. The optional parameters are the -following: -

-
    -
  • method: The HTTP request method. Defaults to "GET"; -
  • headers: Any additional HTTP headers to send with the request; -
  • source: simple -LTN12 -source to provide the request body. If there -is a body, you need to provide an appropriate "content-length" -request header field, or the function will attempt to send the body as -"chunked" (something few servers support). Defaults to the empty source; -
  • step: -LTN12 -pump step function used to move data. -Defaults to the LTN12 pump.step function. -
  • proxy: The URL of a proxy server to use. Defaults to no proxy; -
  • redirect: Set to false to prevent the -function from automatically following 301 or 302 server redirect messages; -
  • create: An optional function to be used instead of -socket.tcp when the communications socket is created. -
- -

-In case of failure, the function returns nil followed by an -error message. If successful, the simple form returns the response -body as a string, followed by the response status code, the response -headers and the response status line. The generic function returns the same -information, except the first return value is just the number 1 (the body -goes to the sink). -

- -

-Even when the server fails to provide the contents of the requested URL (URL not found, for example), -it usually returns a message body (a web page informing the -URL was not found or some other useless page). To make sure the -operation was successful, check the returned status code. For -a list of the possible values and their meanings, refer to RFC 2616. -

- -

-Here are a few examples with the simple interface: -

- -
--- load the http module
-local io = require("io")
-local http = require("socket.http")
-local ltn12 = require("ltn12")
-
--- connect to server "www.cs.princeton.edu" and retrieves this manual
--- file from "~diego/professional/luasocket/http.html" and print it to stdout
-http.request{ 
-    url = "http://www.cs.princeton.edu/~diego/professional/luasocket/http.html", 
-    sink = ltn12.sink.file(io.stdout)
-}
-
--- connect to server "www.example.com" and tries to retrieve
--- "/private/index.html". Fails because authentication is needed.
-b, c, h = http.request("http://www.example.com/private/index.html")
--- b returns some useless page telling about the denied access, 
--- h returns authentication information
--- and c returns with value 401 (Authentication Required)
-
--- tries to connect to server "wrong.host" to retrieve "/"
--- and fails because the host does not exist.
-r, e = http.request("http://wrong.host/")
--- r is nil, and e returns with value "host not found"
-
- -

-And here is an example using the generic interface: -

- -
--- load the http module
-http = require("socket.http")
-
--- Requests information about a document, without downloading it.
--- Useful, for example, if you want to display a download gauge and need
--- to know the size of the document in advance
-r, c, h = http.request {
-  method = "HEAD",
-  url = "http://www.tecgraf.puc-rio.br/~diego"
-}
--- r is 1, c is 200, and h would return the following headers:
--- h = {
---   date = "Tue, 18 Sep 2001 20:42:21 GMT",
---   server = "Apache/1.3.12 (Unix)  (Red Hat/Linux)",
---   ["last-modified"] = "Wed, 05 Sep 2001 06:11:20 GMT",
---   ["content-length"] = 15652,
---   ["connection"] = "close",
---   ["content-Type"] = "text/html"
--- }
-
- -

-Note: When sending a POST request, simple interface adds a -"Content-type: application/x-www-form-urlencoded" -header to the request. This is the type used by -HTML forms. If you need another type, use the generic -interface. -

- -

-Note: Some URLs are protected by their -servers from anonymous download. For those URLs, the server must receive -some sort of authentication along with the request or it will deny -download and return status "401 Authentication Required". -

- -

-The HTTP/1.1 standard defines two authentication methods: the Basic -Authentication Scheme and the Digest Authentication Scheme, both -explained in detail in -RFC 2068. -

- -

The Basic Authentication Scheme sends -<user> and -<password> unencrypted to the server and is therefore -considered unsafe. Unfortunately, by the time of this implementation, -the wide majority of servers and browsers support the Basic Scheme only. -Therefore, this is the method used by the toolkit whenever -authentication is required. -

- -
--- load required modules
-http = require("socket.http")
-mime = require("mime")
-
--- Connect to server "www.example.com" and tries to retrieve
--- "/private/index.html", using the provided name and password to
--- authenticate the request
-b, c, h = http.request("http://fulano:silva@www.example.com/private/index.html")
-
--- Alternatively, one could fill the appropriate header and authenticate
--- the request directly.
-r, c = http.request {
-  url = "http://www.example.com/private/index.html",
-  headers = { authorization = "Basic " .. (mime.b64("fulano:silva")) }
-}
-
- - - - - - - diff -Nru luasocket-3.0~rc1+git+ac3201d/doc/index.html luasocket-3.1.0/doc/index.html --- luasocket-3.0~rc1+git+ac3201d/doc/index.html 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/doc/index.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,215 +0,0 @@ - - - - - - -LuaSocket: Network support for the Lua language - - - - - - - -
-
-
- - - -
-LuaSocket -
Network support for the Lua language -
-

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

-
-
-
- - - -

What is LuaSocket?

- -

-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. -

- -

-The core support has been implemented so that it is both efficient and -simple to use. It is available to any Lua application once it has been -properly initialized by the interpreter in use. The code has been tested -and runs well on several Windows and UNIX platforms.

- -

-Among the support modules, the most commonly used implement the -SMTP -(sending e-mails), -HTTP -(WWW access) and -FTP -(uploading and downloading files) client -protocols. These provide a very natural and generic interface to the -functionality defined by each protocol. -In addition, you will find that the -MIME (common encodings), -URL -(anything you could possible want to do with one) and -LTN12 -(filters, sinks, sources and pumps) modules can be very handy. -

- -

-The library is available under the same - -terms and conditions as the Lua language, the MIT license. The idea is -that if you can use Lua in a project, you should also be able to use -LuaSocket. -

- -

-Copyright © 1999-2013 Diego Nehab. All rights reserved.
-Author: Diego Nehab -

- - - -

Download

- -

-LuaSocket version 3.0-rc1 is now available for download! -It is compatible with Lua 5.1 and 5.2, and has -been tested on Windows XP, Linux, and Mac OS X. Chances -are it works well on most UNIX distributions and Windows flavors. -

- -

-The current version of the library can be found at -the LuaSocket -project page on GitHub. Besides the full C and Lua source code -for the library, the distribution contains several examples, -this user's manual and basic test procedures. -

- -

Take a look at the installation section of the -manual to find out how to properly install the library. -

- - - -

Special thanks

- -

-This marks the first release of LuaSocket that -wholeheartedly embraces the open-source development -philosophy. After a long hiatus, Matthew Wild finally -convinced me it was time for a release including IPv6 and -Lua 5.2 support. It was more work than we anticipated. -Special thanks to Sam Roberts, Florian Zeitz, and Paul -Aurich, Liam Devine, Alexey Melnichuk, and everybody else -that has helped bring this library back to life. -

- - - -

What's New

- -

-Main changes for LuaSocket 3.0-rc1 are IPv6 support -and Lua 5.2 compatibility. -

- -
    -
  • Added: Compatible with Lua 5.2 -
      -
    • Note that unless you define LUA_COMPAT_MODULE, -package tables will not be exported as globals! -
    -
  • Added: IPv6 support; -
      -
    • Socket.connect and socket.bind support IPv6 addresses; -
    • Getpeername and getsockname support -IPv6 addresses, and return the socket family as a third value; -
    • URL module updated to support IPv6 host names; -
    • New socket.tcp6 and socket.udp6 functions; -
    • New socket.dns.getaddrinfo and - socket.dns.getnameinfo functions; -
    -
  • Added: getoption method; -
  • Fixed: url.unescape was returning additional values; -
  • Fixed: mime.qp, mime.unqp, - mime.b64, and mime.unb64 could - mistaking their own stack slots for functions arguments; -
  • Fixed: Receiving zero-length datagram is now possible; -
  • Improved: Hidden all internal library symbols; -
  • Improved: Better error messages; -
  • Improved: Better documentation of socket options. -
  • Fixed: manual sample of HTTP authentication now uses correct - "authorization" header (Alexandre Ittner); -
  • Fixed: failure on bind() was destroying the socket (Sam Roberts); -
  • Fixed: receive() returns immediatelly if prefix can satisfy - bytes requested (M Joonas Pihlaja); -
  • Fixed: multicast didn't work on Windows, or anywhere - else for that matter (Herbert Leuwer, Adrian Sietsma); -
  • Fixed: select() now reports an error when called with more - sockets than FD_SETSIZE (Lorenzo Leonini); -
  • Fixed: manual links to home.html changed to index.html -(Robert Hahn); -
  • Fixed: mime.unb64() would return an empty string on results that started - with a null character (Robert Raschke); -
  • Fixed: HTTP now automatically redirects on 303 and 307 (Jonathan Gray); -
  • Fixed: calling sleep() with negative numbers could - block forever, wasting CPU. Now it returns immediately (MPB); -
  • Improved: FTP commands are now sent in upper case to - help buggy servers (Anders Eurenius); -
  • Improved: known headers now sent in canonic - capitalization to help buggy servers (Joseph Stewart); -
  • Improved: Clarified tcp:receive() in the manual (MPB); -
  • Improved: Decent makefiles (LHF). -
  • Fixed: RFC links in documentation now point to IETF (Cosmin Apreutesei). -
- - - -

Old Versions

- -

-All previous versions of the LuaSocket library can be downloaded -here. Although these versions are no longer supported, they are -still available for those that have compatibility issues. -

- - - - - - - diff -Nru luasocket-3.0~rc1+git+ac3201d/doc/installation.html luasocket-3.1.0/doc/installation.html --- luasocket-3.0~rc1+git+ac3201d/doc/installation.html 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/doc/installation.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,127 +0,0 @@ - - - - - - -LuaSocket: Installation - - - - - - - -
-
-
- - - -
-LuaSocket -
Network support for the Lua language -
-

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

-
-
-
- - - -

Installation

- -

Here we describe the standard distribution. If the -standard doesn't meet your needs, we refer you to the Lua -discussion list, where any question about the package scheme -will likely already have been answered.

- -

Directory structure

- -

On Unix systems, the standard distribution uses two base -directories, one for system dependent files, and another for system -independent files. Let's call these directories <CDIR> -and <LDIR>, respectively. -For example, in my laptp, Lua 5.1 is configured to -use '/usr/local/lib/lua/5.1' for -<CDIR> and '/usr/local/share/lua/5.1' for -<LDIR>. On Windows, <CDIR> -usually points to the directory where the Lua executable is -found, and <LDIR> points to a -lua/ directory inside <CDIR>. (These -settings can be overridden by environment variables -LUA_PATH and LUA_CPATH. See the Lua -documentation for details.) Here is the standard LuaSocket -distribution directory structure:

- -
-<LDIR>/ltn12.lua
-<LDIR>/socket.lua
-<CDIR>/socket/core.dll
-<LDIR>/socket/http.lua
-<LDIR>/socket/tp.lua
-<LDIR>/socket/ftp.lua
-<LDIR>/socket/smtp.lua
-<LDIR>/socket/url.lua
-<LDIR>/mime.lua
-<CDIR>/mime/core.dll
-
- -

Naturally, on Unix systems, core.dll -would be replaced by core.so. -

- -

Using LuaSocket

- -

With the above setup, and an interpreter with shared library support, -it should be easy to use LuaSocket. Just fire the interpreter and use the -require function to gain access to whatever module you need:

- -
-Lua 5.2.2  Copyright (C) 1994-2013 Lua.org, PUC-Rio
-> socket = require("socket")
-> print(socket._VERSION)
---> LuaSocket 3.0-rc1
-
- -

Each module loads their dependencies automatically, so you only need to -load the modules you directly depend upon:

- -
-Lua 5.2.2  Copyright (C) 1994-2013 Lua.org, PUC-Rio
-> http = require("socket.http")
-> print(http.request("http://www.impa.br/~diego/software/luasocket"))
---> homepage gets dumped to terminal
-
- - - - - - - diff -Nru luasocket-3.0~rc1+git+ac3201d/doc/introduction.html luasocket-3.1.0/doc/introduction.html --- luasocket-3.0~rc1+git+ac3201d/doc/introduction.html 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/doc/introduction.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,333 +0,0 @@ - - - - - - -LuaSocket: Introduction to the core - - - - - - - -
-
-
- - - -
-LuaSocket -
Network support for the Lua language -
-

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

-
-
-
- - - -

Introduction

- -

-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 -the SMTP (sending e-mails), HTTP (WWW access) and FTP (uploading and -downloading files) protocols and other functionality commonly needed by -applications that deal with the Internet. This introduction is about the C -core. -

- -

-Communication in LuaSocket is performed via I/O objects. These can -represent different network domains. Currently, support is provided for TCP -and UDP, but nothing prevents other developers from implementing SSL, Local -Domain, Pipes, File Descriptors etc. I/O objects provide a standard -interface to I/O across different domains and operating systems. -

- -

-The API design had two goals in mind. First, users -experienced with the C API to sockets should feel comfortable using LuaSocket. -Second, the simplicity and the feel of the Lua language should be -preserved. To achieve these goals, the LuaSocket API keeps the function names and semantics the C API whenever possible, but their usage in Lua has been greatly simplified. -

- - -

-One of the simplifications is the receive pattern capability. -Applications can read data from stream domains (such as TCP) -line by line, block by block, or until the connection is closed. -All I/O reads are buffered and the performance differences between -different receive patterns are negligible. -

- -

-Another advantage is the flexible timeout control -mechanism. As in C, all I/O operations are blocking by default. For -example, the send, -receive and -accept methods -of the TCP domain will block the caller application until -the operation is completed (if ever!). However, with a call to the -settimeout -method, an application can specify upper limits on -the time it can be blocked by LuaSocket (the "total" timeout), on -the time LuaSocket can internally be blocked by any OS call (the -"block" timeout) or a combination of the two. Each LuaSocket -call might perform several OS calls, so that the two timeout values are -not equivalent. -

- -

-Finally, the host name resolution is transparent, meaning that most -functions and methods accept both IP addresses and host names. In case a -host name is given, the library queries the system's resolver and -tries the main IP address returned. Note that direct use of IP addresses -is more efficient, of course. The -toip -and tohostname -functions from the DNS module are provided to convert between host names and IP addresses. -

- -

-Together, these changes make network programming in LuaSocket much simpler -than it is in C, as the following sections will show. -

- - - -

TCP

- -

-TCP (Transfer Control Protocol) is reliable stream protocol. In other -words, applications communicating through TCP can send and receive data as -an error free stream of bytes. Data is split in one end and -reassembled transparently on the other end. There are no boundaries in -the data transfers. The library allows users to read data from the -sockets in several different granularities: patterns are available for -lines, arbitrary sized blocks or "read up to connection closed", all with -good performance. -

- -

-The library distinguishes three types of TCP sockets: master, -client and server sockets. -

- -

-Master sockets are newly created TCP sockets returned by the function -socket.tcp. A master socket is -transformed into a server socket -after it is associated with a local address by a call to the -bind method followed by a call to the -listen. Conversely, a master socket -can be changed into a client socket with the method -connect, -which associates it with a remote address. -

- -

-On server sockets, applications can use the -accept method -to wait for a client connection. Once a connection is established, a -client socket object is returned representing this connection. The -other methods available for server socket objects are -getsockname, -setoption, -settimeout, and -close. -

- -

-Client sockets are used to exchange data between two applications over -the Internet. Applications can call the methods -send and -receive -to send and receive data. The other methods -available for client socket objects are -getsockname, -getpeername, -setoption, -settimeout, -shutdown, and -close. -

- -

-Example: -

-
-

-A simple echo server, using LuaSocket. The program binds to an ephemeral -port (one that is chosen by the operating system) on the local host and -awaits client connections on that port. When a connection is established, -the program reads a line from the remote end and sends it back, closing -the connection immediately. You can test it using the telnet -program. -

- -
--- load namespace
-local socket = require("socket")
--- create a TCP socket and bind it to the local host, at any port
-local server = assert(socket.bind("*", 0))
--- find out which port the OS chose for us
-local ip, port = server:getsockname()
--- print a message informing what's up
-print("Please telnet to localhost on port " .. port)
-print("After connecting, you have 10s to enter a line to be echoed")
--- loop forever waiting for clients
-while 1 do
-  -- wait for a connection from any client
-  local client = server:accept()
-  -- make sure we don't block waiting for this client's line
-  client:settimeout(10)
-  -- receive the line
-  local line, err = client:receive()
-  -- if there was no error, send it back to the client
-  if not err then client:send(line .. "\n") end
-  -- done with client, close the object
-  client:close()
-end
-
-
- - - -

UDP

- -

-UDP (User Datagram Protocol) is a non-reliable datagram protocol. In -other words, applications communicating through UDP send and receive -data as independent blocks, which are not guaranteed to reach the other -end. Even when they do reach the other end, they are not guaranteed to be -error free. Data transfers are atomic, one datagram at a time. Reading -only part of a datagram discards the rest, so that the following read -operation will act on the next datagram. The advantages are in -simplicity (no connection setup) and performance (no error checking or -error correction). -

- -

-Note that although no guarantees are made, these days -networks are so good that, under normal circumstances, few errors -happen in practice. -

- -

-An UDP socket object is created by the -socket.udp function. UDP -sockets do not need to be connected before use. The method -sendto -can be used immediately after creation to -send a datagram to IP address and port. Host names are not allowed -because performing name resolution for each packet would be forbiddingly -slow. Methods -receive and -receivefrom -can be used to retrieve datagrams, the latter returning the IP and port of -the sender as extra return values (thus being slightly less -efficient). -

- -

-When communication is performed repeatedly with a single peer, an -application should call the -setpeername method to specify a -permanent partner. Methods -sendto and -receivefrom -can no longer be used, but the method -send can be used to send data -directly to the peer, and the method -receive -will only return datagrams originating -from that peer. There is about 30% performance gain due to this practice. -

- -

-To associate an UDP socket with a local address, an application calls the -setsockname -method before sending any datagrams. Otherwise, the socket is -automatically bound to an ephemeral address before the first data -transmission and once bound the local address cannot be changed. -The other methods available for UDP sockets are -getpeername, -getsockname, -settimeout, -setoption and -close. -

- -

-Example: -

-
-

-A simple daytime client, using LuaSocket. The program connects to a remote -server and tries to retrieve the daytime, printing the answer it got or an -error message. -

- -
--- change here to the host an port you want to contact
-local host, port = "localhost", 13
--- load namespace
-local socket = require("socket")
--- convert host name to ip address
-local ip = assert(socket.dns.toip(host))
--- create a new UDP object
-local udp = assert(socket.udp())
--- contact daytime host
-assert(udp:sendto("anything", ip, port))
--- retrieve the answer and print results
-io.write(assert(udp:receive()))
-
-
- - - -

Support modules

- -

Although not covered in the introduction, LuaSocket offers -much more than TCP and UDP functionality. As the library -evolved, support for HTTP, FTP, -and SMTP were built on top of these. These modules -and many others are covered by the reference manual. -

- - - - - - - diff -Nru luasocket-3.0~rc1+git+ac3201d/doc/ltn12.html luasocket-3.1.0/doc/ltn12.html --- luasocket-3.0~rc1+git+ac3201d/doc/ltn12.html 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/doc/ltn12.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,430 +0,0 @@ - - - - - - -LuaSocket: LTN12 module - - - - - - - -
-
-
- - - -
-LuaSocket -
Network support for the Lua language -
-

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

-
-
-
- - - -

LTN12

- -

The ltn12 namespace implements the ideas described in - -LTN012, Filters sources and sinks. This manual simply describes the -functions. Please refer to the LTN for a deeper explanation of the -functionality provided by this module. -

- -

-To obtain the ltn12 namespace, run: -

- -
--- loads the LTN21 module
-local ltn12 = require("ltn12")
-
- - - -

Filters

- - - -

-ltn12.filter.chain(filter1, filter2 -[, ... filterN]) -

- -

-Returns a filter that passes all data it receives through each of a -series of given filters. -

- -

-Filter1 to filterN are simple -filters. -

- -

-The function returns the chained filter. -

- -

-The nesting of filters can be arbitrary. For instance, the useless filter -below doesn't do anything but return the data that was passed to it, -unaltered. -

- -
--- load required modules
-local ltn12 = require("ltn12")
-local mime = require("mime")
-
--- create a silly identity filter
-id = ltn12.filter.chain(
-  mime.encode("quoted-printable"),
-  mime.encode("base64"),
-  mime.decode("base64"),
-  mime.decode("quoted-printable")
-)
-
- - - -

-ltn12.filter.cycle(low [, ctx, extra]) -

- -

-Returns a high-level filter that cycles though a low-level filter by -passing it each chunk and updating a context between calls. -

- -

-Low is the low-level filter to be cycled, -ctx is the initial context and extra is any extra -argument the low-level filter might take. -

- -

-The function returns the high-level filter. -

- -
--- load the ltn12 module
-local ltn12 = require("ltn12")
-
--- the base64 mime filter factory
-encodet['base64'] = function()
-    return ltn12.filter.cycle(b64, "")
-end
-
- - - -

Pumps

- - - -

-ltn12.pump.all(source, sink) -

- -

-Pumps all data from a source to a sink. -

- -

-If successful, the function returns a value that evaluates to -true. In case -of error, the function returns a false value, followed by an error message. -

- - - -

-ltn12.pump.step(source, sink) -

- -

-Pumps one chunk of data from a source to a sink. -

- -

-If successful, the function returns a value that evaluates to -true. In case -of error, the function returns a false value, followed by an error message. -

- - - -

Sinks

- - - -

-ltn12.sink.chain(filter, sink) -

- -

-Creates and returns a new sink that passes data through a filter before sending it to a given sink. -

- - - -

-ltn12.sink.error(message) -

- -

-Creates and returns a sink that aborts transmission with the error -message. -

- - - -

-ltn12.sink.file(handle, message) -

- -

-Creates a sink that sends data to a file. -

- -

-Handle is a file handle. If handle is nil, -message should give the reason for failure. -

- -

-The function returns a sink that sends all data to the given handle -and closes the file when done, or a sink that aborts the transmission with -the error message -

- -

-In the following example, notice how the prototype is designed to -fit nicely with the io.open function. -

- -
--- load the ltn12 module
-local ltn12 = require("ltn12")
-
--- copy a file
-ltn12.pump.all(
-  ltn12.source.file(io.open("original.png", "rb")),
-  ltn12.sink.file(io.open("copy.png", "wb"))
-)
-
- - - -

-ltn12.sink.null() -

- -

-Returns a sink that ignores all data it receives. -

- - - -

-ltn12.sink.simplify(sink) -

- -

-Creates and returns a simple sink given a fancy sink. -

- - - -

-ltn12.sink.table([table]) -

- -

-Creates a sink that stores all chunks in a table. The chunks can later be -efficiently concatenated into a single string. -

- -

-Table is used to hold the chunks. If -nil, the function creates its own table. -

- -

-The function returns the sink and the table used to store the chunks. -

- -
--- load needed modules
-local http = require("socket.http")
-local ltn12 = require("ltn12")
-
--- a simplified http.get function
-function http.get(u)
-  local t = {}
-  local respt = request{
-    url = u,
-    sink = ltn12.sink.table(t)
-  }
-  return table.concat(t), respt.headers, respt.code
-end
-
- - - -

Sources

- - - -

-ltn12.source.cat(source1 [, source2, ..., -sourceN]) -

- -

-Creates a new source that produces the concatenation of the data produced -by a number of sources. -

- -

-Source1 to sourceN are the original -sources. -

- -

-The function returns the new source. -

- - - -

-ltn12.source.chain(source, filter) -

- -

-Creates a new source that passes data through a filter -before returning it. -

- -

-The function returns the new source. -

- - - -

-ltn12.source.empty() -

- -

-Creates and returns an empty source. -

- - - -

-ltn12.source.error(message) -

- -

-Creates and returns a source that aborts transmission with the error -message. -

- - - -

-ltn12.source.file(handle, message) -

- -

-Creates a source that produces the contents of a file. -

- -

-Handle is a file handle. If handle is nil, -message should give the reason for failure. -

- -

-The function returns a source that reads chunks of data from -given handle and returns it to the user, -closing the file when done, or a source that aborts the transmission with -the error message -

- -

-In the following example, notice how the prototype is designed to -fit nicely with the io.open function. -

- -
--- load the ltn12 module
-local ltn12 = require("ltn12")
-
--- copy a file
-ltn12.pump.all(
-  ltn12.source.file(io.open("original.png", "rb")),
-  ltn12.sink.file(io.open("copy.png", "wb"))
-)
-
- - - -

-ltn12.source.simplify(source) -

- -

-Creates and returns a simple source given a fancy source. -

- - - -

-ltn12.source.string(string) -

- -

-Creates and returns a source that produces the contents of a -string, chunk by chunk. -

- - - - - - - Binary files /tmp/tmpsljgbcll/D2IclVS3PF/luasocket-3.0~rc1+git+ac3201d/doc/lua05.ppt and /tmp/tmpsljgbcll/P9aFpSgj8o/luasocket-3.1.0/doc/lua05.ppt differ Binary files /tmp/tmpsljgbcll/D2IclVS3PF/luasocket-3.0~rc1+git+ac3201d/doc/luasocket.png and /tmp/tmpsljgbcll/P9aFpSgj8o/luasocket-3.1.0/doc/luasocket.png differ diff -Nru luasocket-3.0~rc1+git+ac3201d/doc/mime.html luasocket-3.1.0/doc/mime.html --- luasocket-3.0~rc1+git+ac3201d/doc/mime.html 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/doc/mime.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,477 +0,0 @@ - - - - - - -LuaSocket: MIME module - - - - - - - -
-
-
- - - -
-LuaSocket -
Network support for the Lua language -
-

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

-
-
-
- - - -

MIME

- -

-The mime namespace offers filters that apply and remove common -content transfer encodings, such as Base64 and Quoted-Printable. -It also provides functions to break text into lines and change -the end-of-line convention. -MIME is described mainly in -RFC 2045, -2046, -2047, -2048, and -2049. -

- -

-All functionality provided by the MIME module -follows the ideas presented in - -LTN012, Filters sources and sinks. -

- -

-To obtain the mime namespace, run: -

- -
--- loads the MIME module and everything it requires
-local mime = require("mime")
-
- - - - -

High-level filters

- - - - -

-mime.decode("base64")
-mime.decode("quoted-printable") -

- -

-Returns a filter that decodes data from a given transfer content -encoding. -

- - - -

-mime.encode("base64")
-mime.encode("quoted-printable" [, mode]) -

- -

-Returns a filter that encodes data according to a given transfer content -encoding. -

- -

-In the Quoted-Printable case, the user can specify whether the data is -textual or binary, by passing the mode strings "text" or -"binary". Mode defaults to "text". -

- -

-Although both transfer content encodings specify a limit for the line -length, the encoding filters do not break text into lines (for -added flexibility). -Below is a filter that converts binary data to the Base64 transfer content -encoding and breaks it into lines of the correct size. -

- -
-base64 = ltn12.filter.chain(
-  mime.encode("base64"),
-  mime.wrap("base64")
-)
-
- -

-Note: Text data has to be converted to canonic form -before being encoded. -

- -
-base64 = ltn12.filter.chain(
-  mime.normalize(),
-  mime.encode("base64"),
-  mime.wrap("base64")
-)
-
- - - -

-mime.normalize([marker]) -

- -

-Converts most common end-of-line markers to a specific given marker. -

- -

-Marker is the new marker. It defaults to CRLF, the canonic -end-of-line marker defined by the MIME standard. -

- -

-The function returns a filter that performs the conversion. -

- -

-Note: There is no perfect solution to this problem. Different end-of-line -markers are an evil that will probably plague developers forever. -This function, however, will work perfectly for text created with any of -the most common end-of-line markers, i.e. the Mac OS (CR), the Unix (LF), -or the DOS (CRLF) conventions. Even if the data has mixed end-of-line -markers, the function will still work well, although it doesn't -guarantee that the number of empty lines will be correct. -

- - - -

-mime.stuff()
-

- -

-Creates and returns a filter that performs stuffing of SMTP messages. -

- -

-Note: The smtp.send function -uses this filter automatically. You don't need to chain it with your -source, or apply it to your message body. -

- - - -

-mime.wrap("text" [, length])
-mime.wrap("base64")
-mime.wrap("quoted-printable") -

- -

-Returns a filter that breaks data into lines. -

- -

-The "text" line-wrap filter simply breaks text into lines by -inserting CRLF end-of-line markers at appropriate positions. -Length defaults 76. -The "base64" line-wrap filter works just like the default -"text" line-wrap filter with default length. -The function can also wrap "quoted-printable" lines, taking care -not to break lines in the middle of an escaped character. In that case, the -line length is fixed at 76. -

- -

-For example, to create an encoding filter for the Quoted-Printable transfer content encoding of text data, do the following: -

- -
-qp = ltn12.filter.chain(
-  mime.normalize(),
-  mime.encode("quoted-printable"),
-  mime.wrap("quoted-printable")
-)
-
- -

-Note: To break into lines with a different end-of-line convention, apply -a normalization filter after the line break filter. -

- - - -

Low-level filters

- - - -

-A, B = mime.b64(C [, D]) -

- -

-Low-level filter to perform Base64 encoding. -

- -

-A is the encoded version of the largest prefix of -C..D -that can be encoded unambiguously. B has the remaining bytes of -C..D, before encoding. -If D is nil, A is padded with -the encoding of the remaining bytes of C. -

- -

-Note: The simplest use of this function is to encode a string into it's -Base64 transfer content encoding. Notice the extra parenthesis around the -call to mime.b64, to discard the second return value. -

- -
-print((mime.b64("diego:password")))
---> ZGllZ286cGFzc3dvcmQ=
-
- - -

-A, n = mime.dot(m [, B]) -

- -

-Low-level filter to perform SMTP stuffing and enable transmission of -messages containing the sequence "CRLF.CRLF". -

- -

-A is the stuffed version of B. 'n' gives the -number of characters from the sequence CRLF seen in the end of B. -'m' should tell the same, but for the previous chunk. -

- -

Note: The message body is defined to begin with -an implicit CRLF. Therefore, to stuff a message correctly, the -first m should have the value 2. -

- -
-print((string.gsub(mime.dot(2, ".\r\nStuffing the message.\r\n.\r\n."), "\r\n", "\\n")))
---> ..\nStuffing the message.\n..\n..
-
- -

-Note: The smtp.send function -uses this filter automatically. You don't need to -apply it again. -

- - - -

-A, B = mime.eol(C [, D, marker]) -

- -

-Low-level filter to perform end-of-line marker translation. -For each chunk, the function needs to know if the last character of the -previous chunk could be part of an end-of-line marker or not. This is the -context the function receives besides the chunk. An updated version of -the context is returned after each new chunk. -

- -

-A is the translated version of D. C is the -ASCII value of the last character of the previous chunk, if it was a -candidate for line break, or 0 otherwise. -B is the same as C, but for the current -chunk. Marker gives the new end-of-line marker and defaults to CRLF. -

- -
--- translates the end-of-line marker to UNIX
-unix = mime.eol(0, dos, "\n") 
-
- - - -

-A, B = mime.qp(C [, D, marker]) -

- -

-Low-level filter to perform Quoted-Printable encoding. -

- -

-A is the encoded version of the largest prefix of -C..D -that can be encoded unambiguously. B has the remaining bytes of -C..D, before encoding. -If D is nil, A is padded with -the encoding of the remaining bytes of C. -Throughout encoding, occurrences of CRLF are replaced by the -marker, which itself defaults to CRLF. -

- -

-Note: The simplest use of this function is to encode a string into it's -Quoted-Printable transfer content encoding. -Notice the extra parenthesis around the call to mime.qp, to discard the second return value. -

- -
-print((mime.qp("maçã")))
---> ma=E7=E3=
-
- - - -

-A, m = mime.qpwrp(n [, B, length]) -

- -

-Low-level filter to break Quoted-Printable text into lines. -

- -

-A is a copy of B, broken into lines of at most -length bytes (defaults to 76). -'n' should tell how many bytes are left for the first -line of B and 'm' returns the number of bytes -left in the last line of A. -

- -

-Note: Besides breaking text into lines, this function makes sure the line -breaks don't fall in the middle of an escaped character combination. Also, -this function only breaks lines that are bigger than length bytes. -

- - - -

-A, B = mime.unb64(C [, D]) -

- -

-Low-level filter to perform Base64 decoding. -

- -

-A is the decoded version of the largest prefix of -C..D -that can be decoded unambiguously. B has the remaining bytes of -C..D, before decoding. -If D is nil, A is the empty string -and B returns whatever couldn't be decoded. -

- -

-Note: The simplest use of this function is to decode a string from it's -Base64 transfer content encoding. -Notice the extra parenthesis around the call to mime.unqp, to discard the second return value. -

- -
-print((mime.unb64("ZGllZ286cGFzc3dvcmQ=")))
---> diego:password
-
- - - -

-A, B = mime.unqp(C [, D]) -

- -

-Low-level filter to remove the Quoted-Printable transfer content encoding -from data. -

- -

-A is the decoded version of the largest prefix of -C..D -that can be decoded unambiguously. B has the remaining bytes of -C..D, before decoding. -If D is nil, A is augmented with -the encoding of the remaining bytes of C. -

- -

-Note: The simplest use of this function is to decode a string from it's -Quoted-Printable transfer content encoding. -Notice the extra parenthesis around the call to mime.unqp, to discard the second return value. -

- -
-print((mime.qp("ma=E7=E3=")))
---> maçã
-
- - - -

-A, m = mime.wrp(n [, B, length]) -

- -

-Low-level filter to break text into lines with CRLF marker. -Text is assumed to be in the normalize form. -

- -

-A is a copy of B, broken into lines of at most -length bytes (defaults to 76). -'n' should tell how many bytes are left for the first -line of B and 'm' returns the number of bytes -left in the last line of A. -

- -

-Note: This function only breaks lines that are bigger than -length bytes. The resulting line length does not include the CRLF -marker. -

- - - - - - - - diff -Nru luasocket-3.0~rc1+git+ac3201d/doc/reference.css luasocket-3.1.0/doc/reference.css --- luasocket-3.0~rc1+git+ac3201d/doc/reference.css 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/doc/reference.css 1970-01-01 00:00:00.000000000 +0000 @@ -1,55 +0,0 @@ -body { - margin-left: 1em; - margin-right: 1em; - font-family: "Verdana", sans-serif; - background: #ffffff; -} - -tt { - font-family: "Andale Mono", monospace; -} - -h1, h2, h3, h4 { margin-left: 0em; } - - -h3 { padding-top: 1em; } - -p { margin-left: 1em; } - -p.name { - font-family: "Andale Mono", monospace; - padding-top: 1em; - margin-left: 0em; -} - -a[href] { color: #00007f; } - -blockquote { margin-left: 3em; } - -pre.example { - background: #ccc; - padding: 1em; - margin-left: 1em; - font-family: "Andale Mono", monospace; - font-size: small; -} - -hr { - margin-left: 0em; - background: #00007f; - border: 0px; - height: 1px; -} - -ul { list-style-type: disc; } - -table.index { border: 1px #00007f; } -table.index td { text-align: left; vertical-align: top; } -table.index ul { padding-top: 0em; margin-top: 0em; } - -h1:first-letter, -h2:first-letter, -h2:first-letter, -h3:first-letter { color: #00007f; } - -div.header, div.footer { margin-left: 0em; } diff -Nru luasocket-3.0~rc1+git+ac3201d/doc/reference.html luasocket-3.1.0/doc/reference.html --- luasocket-3.0~rc1+git+ac3201d/doc/reference.html 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/doc/reference.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,260 +0,0 @@ - - - - - - -LuaSocket: Index to reference manual - - - - - - - -
-
-
- - - -
-LuaSocket -
Network support for the Lua language -
-

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

-
-
-
- - - -

Reference

- -
-DNS (in socket) -
-getaddrinfo, -gethostname, -tohostname, -toip. -
-
- - - -
-FTP -
-get, -put. -
-
- - - -
-HTTP -
-request. -
-
- - - -
-LTN12 -
-filter: -chain, -cycle. -
-
-pump: -all, -step. -
-
-sink: -chain, -error, -file, -null, -simplify, -table. -
-
-source: -cat, -chain, -empty, -error, -file, -simplify, -string. -
-
- - - -
-MIME -
-high-level: -decode, -encode, -normalize, -stuff, -wrap. -
-
-low-level: -b64, -dot, -eol, -qp, -qpwrp, -unb64, -unqp, -wrp. -
-
- - - -
-SMTP -
-message, -send. -
-
- - - -
-Socket -
-bind, -connect, -connect4, -connect6, -_DATAGRAMSIZE, -_DEBUG, -dns, -gettime, -headers.canonic, -newtry, -protect, -select, -sink, -skip, -sleep, -_SETSIZE, -_SOCKETINVALID, -source, -tcp, -tcp4, -tcp6, -try, -udp, -udp4, -udp6, -_VERSION. -
-
- - - -
-TCP (in socket) -
-accept, -bind, -close, -connect, -dirty, -getfd, -getoption, -getpeername, -getsockname, -getstats, -gettimeout, -listen, -receive, -send, -setfd, -setoption, -setstats, -settimeout, -shutdown. -
-
- - - -
-UDP (in socket) -
-close, -getoption, -getpeername, -getsockname, -gettimeout, -receive, -receivefrom, -send, -sendto, -setpeername, -setsockname, -setoption, -settimeout. -
-
- - - -
-URL -
-absolute, -build, -build_path, -escape, -parse, -parse_path, -unescape. -
-
- - - - - - - diff -Nru luasocket-3.0~rc1+git+ac3201d/doc/smtp.html luasocket-3.1.0/doc/smtp.html --- luasocket-3.0~rc1+git+ac3201d/doc/smtp.html 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/doc/smtp.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,418 +0,0 @@ - - - - - - -LuaSocket: SMTP support - - - - - - - -
-
-
- - - -
-LuaSocket -
Network support for the Lua language -
-

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

-
-
-
- - - -

SMTP

- -

The smtp namespace provides functionality to send e-mail -messages. The high-level API consists of two functions: one to -define an e-mail message, and another to actually send the message. -Although almost all users will find that these functions provide more than -enough functionality, the underlying implementation allows for even more -control (if you bother to read the code). -

- -

The implementation conforms to the Simple Mail Transfer Protocol, -RFC 2821. -Another RFC of interest is RFC 2822, -which governs the Internet Message Format. -Multipart messages (those that contain attachments) are part -of the MIME standard, but described mainly -in RFC 2046 - -

In the description below, good understanding of LTN012, Filters -sources and sinks and the MIME module is -assumed. In fact, the SMTP module was the main reason for their -creation.

- -

-To obtain the smtp namespace, run: -

- -
--- loads the SMTP module and everything it requires
-local smtp = require("socket.smtp")
-
- -

-MIME headers are represented as a Lua table in the form: -

- -
- - -
-headers = {
-  field-1-name = field-1-value,
-  field-2-name = field-2-value,
-  field-3-name = field-3-value,
-  ...
-  field-n-name = field-n-value
-} -
-
- -

-Field names are case insensitive (as specified by the standard) and all -functions work with lowercase field names (but see -socket.headers.canonic). -Field values are left unmodified. -

- -

-Note: MIME headers are independent of order. Therefore, there is no problem -in representing them in a Lua table. -

- -

-The following constants can be set to control the default behavior of -the SMTP module: -

- -
    -
  • DOMAIN: domain used to greet the server; -
  • PORT: default port used for the connection; -
  • SERVER: default server used for the connection; -
  • TIMEOUT: default timeout for all I/O operations; -
  • ZONE: default time zone. -
- - - -

-smtp.message(mesgt) -

- -

-Returns a simple -LTN12 source that sends an SMTP message body, possibly multipart (arbitrarily deep). -

- -

-The only parameter of the function is a table describing the message. -Mesgt has the following form (notice the recursive structure): -

- -
- - -
-mesgt = {
-  headers = header-table,
-  body = LTN12 source or string or -multipart-mesgt
-}

-multipart-mesgt = {
-  [preamble = string,]
-  [1] = mesgt,
-  [2] = mesgt,
-  ...
-  [n] = mesgt,
-  [epilogue = string,]
-}
-
-
- -

-For a simple message, all that is needed is a set of headers -and the body. The message body can be given as a string -or as a simple -LTN12 -source. For multipart messages, the body is a table that -recursively defines each part as an independent message, plus an optional -preamble and epilogue. -

- -

-The function returns a simple -LTN12 -source that produces the -message contents as defined by mesgt, chunk by chunk. -Hopefully, the following -example will make things clear. When in doubt, refer to the appropriate RFC -as listed in the introduction.

- -
--- load the smtp support and its friends
-local smtp = require("socket.smtp")
-local mime = require("mime")
-local ltn12 = require("ltn12")
-
--- 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. 
-     from = "Sicrano de Oliveira <sicrano@example.com>",
-     to = "Fulano da Silva <fulano@example.com>",
-     subject = "Here is a message with attachments"
-  },
-  body = {
-    preamble = "If your client doesn't understand attachments, \r\n" ..
-               "it will still display the preamble and the epilogue.\r\n" ..
-               "Preamble will probably appear 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] = { 
-      body = mime.eol(0, [[
-        Lines in a message body should always end with CRLF. 
-        The smtp module will *NOT* perform translation. However, the 
-        send function *DOES* perform SMTP stuffing, whereas the message
-        function does *NOT*.
-      ]])
-    },
-    -- second part: headers describe content to be a png image, 
-    -- sent under the base64 transfer content encoding.
-    -- notice that nothing happens until the message is actually sent. 
-    -- small chunks are loaded into memory right before transmission and 
-    -- translation happens on the fly.
-    [2] = { 
-      headers = {
-        ["content-type"] = 'image/png; name="image.png"',
-        ["content-disposition"] = 'attachment; filename="image.png"',
-        ["content-description"] = 'a beautiful image',
-        ["content-transfer-encoding"] = "BASE64"
-      },
-      body = ltn12.source.chain(
-        ltn12.source.file(io.open("image.png", "rb")),
-        ltn12.filter.chain(
-          mime.encode("base64"),
-          mime.wrap()
-        )
-      )
-    },
-    epilogue = "This might also show up, but after the attachments"
-  }
-}
-
--- finally send it
-r, e = smtp.send{
-    from = "<sicrano@example.com>",
-    rcpt = "<fulano@example.com>",
-    source = source,
-}
-
- - - - -

-smtp.send{
-  from = string,
-  rcpt = string or string-table,
-  source = LTN12 source,
-  [user = string,]
-  [password = string,]
-  [server = string,]
-  [port = number,]
-  [domain = string,]
-  [step = LTN12 pump step,]
-  [create = function]
-} -

- -

-Sends a message to a recipient list. Since sending messages is not as -simple as downloading an URL from a FTP or HTTP server, this function -doesn't have a simple interface. However, see the -message source factory for -a very powerful way to define the message contents. -

- - -

-The sender is given by the e-mail address in the from field. -Rcpt is a Lua table with one entry for each recipient e-mail -address, or a string -in case there is just one recipient. -The contents of the message are given by a simple -LTN12 -source. Several arguments are optional: -

-
    -
  • user, password: User and password for -authentication. The function will attempt LOGIN and PLAIN authentication -methods if supported by the server (both are unsafe); -
  • server: Server to connect to. Defaults to "localhost"; -
  • port: Port to connect to. Defaults to 25; -
  • domain: Domain name used to greet the server; Defaults to the -local machine host name; -
  • step: -LTN12 -pump step function used to pass data from the -source to the server. Defaults to the LTN12 pump.step function; -
  • create: An optional function to be used instead of -socket.tcp when the communications socket is created. -
- -

-If successful, the function returns 1. Otherwise, the function returns -nil followed by an error message. -

- -

-Note: SMTP servers can be very picky with the format of e-mail -addresses. To be safe, use only addresses of the form -"<fulano@example.com>" in the from and -rcpt arguments to the send function. In headers, e-mail -addresses can take whatever form you like.

- -

-Big note: There is a good deal of misconception with the use of the -destination address field headers, i.e., the 'To', 'Cc', -and, more importantly, the 'Bcc' headers. Do not add a -'Bcc' header to your messages because it will probably do the -exact opposite of what you expect. -

- -

-Only recipients specified in the rcpt list will receive a copy of the -message. Each recipient of an SMTP mail message receives a copy of the -message body along with the headers, and nothing more. The headers -are part of the message and should be produced by the -LTN12 -source function. The rcpt list is not -part of the message and will not be sent to anyone. -

- -

-RFC 2822 -has two important and short sections, "3.6.3. Destination address -fields" and "5. Security considerations", explaining the proper -use of these headers. Here is a summary of what it says: -

- -
    -
  • To: contains the address(es) of the primary recipient(s) -of the message; -
  • Cc: (where the "Cc" means "Carbon Copy" in the sense of -making a copy on a typewriter using carbon paper) contains the -addresses of others who are to receive the message, though the -content of the message may not be directed at them; -
  • Bcc: (where the "Bcc" means "Blind Carbon -Copy") contains addresses of recipients of the message whose addresses are not to be revealed to other recipients of the message. -
- -

-The LuaSocket send function does not care or interpret the -headers you send, but it gives you full control over what is sent and -to whom it is sent: -

-
    -
  • If someone is to receive the message, the e-mail address has -to be in the recipient list. This is the only parameter that controls who -gets a copy of the message; -
  • If there are multiple recipients, none of them will automatically -know that someone else got that message. That is, the default behavior is -similar to the Bcc field of popular e-mail clients; -
  • It is up to you to add the To header with the list of primary -recipients so that other recipients can see it; -
  • It is also up to you to add the Cc header with the -list of additional recipients so that everyone else sees it; -
  • Adding a header Bcc is nonsense, unless it is -empty. Otherwise, everyone receiving the message will see it and that is -exactly what you don't want to happen! -
- -

-I hope this clarifies the issue. Otherwise, please refer to -RFC 2821 -and -RFC 2822. -

- -
--- load the smtp support
-local smtp = require("socket.smtp")
-
--- Connects to server "localhost" and sends a message to users
--- "fulano@example.com",  "beltrano@example.com", 
--- and "sicrano@example.com".
--- Note that "fulano" is the primary recipient, "beltrano" receives a
--- carbon copy and neither of them knows that "sicrano" received a blind
--- carbon copy of the message.
-from = "<luasocket@example.com>"
-
-rcpt = {
-  "<fulano@example.com>",
-  "<beltrano@example.com>",
-  "<sicrano@example.com>"
-}
-
-mesgt = {
-  headers = {
-    to = "Fulano da Silva <fulano@example.com>",
-    cc = '"Beltrano F. Nunes" <beltrano@example.com>',
-    subject = "My first message"
-  },
-  body = "I hope this works. If it does, I can send you another 1000 copies."
-}
-
-r, e = smtp.send{
-  from = from,
-  rcpt = rcpt, 
-  source = smtp.message(mesgt)
-}
-
- - - - - - - diff -Nru luasocket-3.0~rc1+git+ac3201d/doc/socket.html luasocket-3.1.0/doc/socket.html --- luasocket-3.0~rc1+git+ac3201d/doc/socket.html 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/doc/socket.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,479 +0,0 @@ - - - - - - -LuaSocket: The socket namespace - - - - - - - -
-
-
- - - -
-LuaSocket -
Network support for the Lua language -
-

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

-
-
-
- - - -

The socket namespace

- -

-The socket namespace contains the core functionality of LuaSocket. -

- -

-To obtain the socket namespace, run: -

- -
--- loads the socket module 
-local socket = require("socket")
-
- - - -

-socket.headers.canonic

- -

The socket.headers.canonic table -is used by the HTTP and SMTP modules to translate from -lowercase field names back into their canonic -capitalization. When a lowercase field name exists as a key -in this table, the associated value is substituted in -whenever the field name is sent out. -

- -

-You can obtain the headers namespace if case run-time -modifications are required by running: -

- -
--- loads the headers module 
-local headers = require("headers")
-
- - - - -

-socket.bind(address, port [, backlog]) -

- -

-This function is a shortcut that creates and returns a TCP server object -bound to a local address and port, ready to -accept client connections. Optionally, -user can also specify the backlog argument to the -listen method (defaults to 32). -

- -

-Note: The server object returned will have the option "reuseaddr" -set to true. -

- - - -

-socket.connect[46](address, port [, locaddr] [, locport] [, family]) -

- -

-This function is a shortcut that creates and returns a TCP client object -connected to a remote address at a given port. Optionally, -the user can also specify the local address and port to bind -(locaddr and locport), or restrict the socket family -to "inet" or "inet6". -Without specifying family to connect, whether a tcp or tcp6 -connection is created depends on your system configuration. Two variations -of connect are defined as simple helper functions that restrict the -family, socket.connect4 and socket.connect6. -

- - - -

-socket._DEBUG -

- -

-This constant is set to true if the library was compiled -with debug support. -

- - - -

-socket._DATAGRAMSIZE -

- -

-Default datagram size used by calls to -receive and -receivefrom. -(Unless changed in compile time, the value is 8192.) -

- - - -

-socket.gettime() -

- -

-Returns the UNIX time in seconds. You should subtract the values returned by this function -to get meaningful values. -

- -
-t = socket.gettime()
--- do stuff
-print(socket.gettime() - t .. " seconds elapsed")
-
- - - -

-socket.newtry(finalizer) -

- -

-Creates and returns a clean -try -function that allows for cleanup before the exception -is raised. -

- -

-Finalizer is a function that will be called before -try throws the exception. -

- -

-The function returns your customized try function. -

- -

-Note: This idea saved a lot of work with the -implementation of protocols in LuaSocket: -

- -
-foo = socket.protect(function()
-    -- connect somewhere
-    local c = socket.try(socket.connect("somewhere", 42))
-    -- create a try function that closes 'c' on error
-    local try = socket.newtry(function() c:close() end)
-    -- do everything reassured c will be closed 
-    try(c:send("hello there?\r\n"))
-    local answer = try(c:receive())
-    ...
-    try(c:send("good bye\r\n"))
-    c:close()
-end)
-
- - - - -

-socket.protect(func) -

- -

-Converts a function that throws exceptions into a safe function. This -function only catches exceptions thrown by the try -and newtry functions. It does not catch normal -Lua errors. -

- -

-Func is a function that calls -try (or assert, or error) -to throw exceptions. -

- -

-Returns an equivalent function that instead of throwing exceptions in case of -a failed try call, returns nil -followed by an error message. -

- - - -

-socket.select(recvt, sendt [, timeout]) -

- -

-Waits for a number of sockets to change status. -

- -

-Recvt is an array with the sockets to test for characters -available for reading. Sockets in the sendt array are watched to -see if it is OK to immediately write on them. Timeout is the -maximum amount of time (in seconds) to wait for a change in status. A -nil, negative or omitted timeout value allows the -function to block indefinitely. Recvt and sendt can also -be empty tables or nil. Non-socket values (or values with -non-numeric indices) in the arrays will be silently ignored. -

- -

The function returns a list with the sockets ready for -reading, a list with the sockets ready for writing and an error message. -The error message is "timeout" if a timeout -condition was met, "select failed" if the call -to select failed, and -nil otherwise. The returned tables are -doubly keyed both by integers and also by the sockets -themselves, to simplify the test if a specific socket has -changed status. -

- -

-Note: select can monitor a limited number -of sockets, as defined by the constant socket._SETSIZE. This -number may be as high as 1024 or as low as 64 by default, -depending on the system. It is usually possible to change this -at compile time. Invoking select with a larger -number of sockets will raise an error. -

- -

-Important note: a known bug in WinSock causes select to fail -on non-blocking TCP sockets. The function may return a socket as -writable even though the socket is not ready for sending. -

- -

-Another important note: calling select with a server socket in the receive parameter before a call to accept does not guarantee -accept will return immediately. -Use the settimeout -method or accept might block forever. -

- -

-Yet another note: If you close a socket and pass -it to select, it will be ignored. -

- -

-Using select with non-socket objects: Any object that implements getfd and dirty can be used with select, allowing objects from other libraries to be used within a socket.select driven loop. -

- - - -

-socket._SETSIZE -

- -

-The maximum number of sockets that the select function can handle. -

- - - - -

-socket.sink(mode, socket) -

- -

-Creates an -LTN12 -sink from a stream socket object. -

- -

-Mode defines the behavior of the sink. The following -options are available: -

-
    -
  • "http-chunked": sends data through socket after applying the -chunked transfer coding, closing the socket when done; -
  • "close-when-done": sends all received data through the -socket, closing the socket when done; -
  • "keep-open": sends all received data through the -socket, leaving it open when done. -
-

-Socket is the stream socket object used to send the data. -

- -

-The function returns a sink with the appropriate behavior. -

- - - -

-socket.skip(d [, ret1, ret2 ... retN]) -

- -

-Drops a number of arguments and returns the remaining. -

- -

-D is the number of arguments to drop. Ret1 to -retN are the arguments. -

- -

-The function returns retd+1 to retN. -

- -

-Note: This function is useful to avoid creation of dummy variables: -

- -
--- get the status code and separator from SMTP server reply 
-local code, sep = socket.skip(2, string.find(line, "^(%d%d%d)(.?)"))
-
- - - -

-socket.sleep(time) -

- -

-Freezes the program execution during a given amount of time. -

- -

-Time is the number of seconds to sleep for. If -time is negative, the function returns immediately. -

- - - -

-socket.source(mode, socket [, length]) -

- -

-Creates an -LTN12 -source from a stream socket object. -

- -

-Mode defines the behavior of the source. The following -options are available: -

-
    -
  • "http-chunked": receives data from socket and removes the -chunked transfer coding before returning the data; -
  • "by-length": receives a fixed number of bytes from the -socket. This mode requires the extra argument length; -
  • "until-closed": receives data from a socket until the other -side closes the connection. -
-

-Socket is the stream socket object used to receive the data. -

- -

-The function returns a source with the appropriate behavior. -

- - - -

-socket._SOCKETINVALID -

- -

-The OS value for an invalid socket. -

- - - -

-socket.try(ret1 [, ret2 ... retN]) -

- -

-Throws an exception in case ret1 is falsy, using -ret2 as the error message. The exception is supposed to be caught -by a protected function only. -

- -

-Ret1 to retN can be arbitrary -arguments, but are usually the return values of a function call -nested with try. -

- -

-The function returns ret1 to retN if -ret1 is not nil or false. -Otherwise, it calls error passing ret2 wrapped -in a table with metatable used by protect to -distinguish exceptions from runtime errors. -

- -
--- connects or throws an exception with the appropriate error message
-c = socket.try(socket.connect("localhost", 80))
-
- - - -

-socket._VERSION -

- -

-This constant has a string describing the current LuaSocket version. -

- - - - - - - diff -Nru luasocket-3.0~rc1+git+ac3201d/doc/tcp.html luasocket-3.1.0/doc/tcp.html --- luasocket-3.0~rc1+git+ac3201d/doc/tcp.html 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/doc/tcp.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,721 +0,0 @@ - - - - - - -LuaSocket: TCP/IP support - - - - - - - -
-
-
- - - -
-LuaSocket -
Network support for the Lua language -
-

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

-
-
-
- - - -

TCP

- - - -

-server:accept() -

- -

-Waits for a remote connection on the server -object and returns a client object representing that connection. -

- -

-If a connection is successfully initiated, a client object is returned. -If a timeout condition is met, the method returns nil -followed by the error string 'timeout'. Other errors are -reported by nil followed by a message describing the error. -

- -

-Note: calling socket.select -with a server object in -the recvt parameter before a call to accept does -not guarantee accept will return immediately. Use the settimeout method or accept -might block until another client shows up. -

- - - -

-master:bind(address, port) -

- -

-Binds a master object to address and port on the -local host. - -

-Address can be an IP address or a host name. -Port must be an integer number in the range [0..64K). -If address -is '*', the system binds to all local interfaces -using the INADDR_ANY constant or -IN6ADDR_ANY_INIT, according to the family. -If port is 0, the system automatically -chooses an ephemeral port. -

- -

-In case of success, the method returns 1. In case of error, the -method returns nil followed by an error message. -

- -

-Note: The function socket.bind -is available and is a shortcut for the creation of server sockets. -

- - - -

-master:close()
-client:close()
-server:close() -

- -

-Closes a TCP object. The internal socket used by the object is closed -and the local address to which the object was -bound is made available to other applications. No further operations -(except for further calls to the close method) are allowed on -a closed socket. -

- -

-Note: It is important to close all used sockets once they are not -needed, since, in many systems, each socket uses a file descriptor, -which are limited system resources. Garbage-collected objects are -automatically closed before destruction, though. -

- - - -

-master:connect(address, port) -

- -

-Attempts to connect a master object to a remote host, transforming it into a -client object. -Client objects support methods -send, -receive, -getsockname, -getpeername, -settimeout, -and close. -

- -

-Address can be an IP address or a host name. -Port must be an integer number in the range [1..64K). -

- -

-In case of error, the method returns nil followed by a string -describing the error. In case of success, the method returns 1. -

- -

-Note: The function socket.connect -is available and is a shortcut for the creation of client sockets. -

- -

-Note: Starting with LuaSocket 2.0, -the settimeout -method affects the behavior of connect, causing it to return -with an error in case of a timeout. If that happens, you can still call socket.select with the socket in the -sendt table. The socket will be writable when the connection is -established. -

- -

-Note: Starting with LuaSocket 3.0, the host name resolution -depends on whether the socket was created by -socket.tcp, -socket.tcp4 or -socket.tcp6. Addresses from -the appropriate family (or both) are tried in the order -returned by the resolver until the -first success or until the last failure. If the timeout was -set to zero, only the first address is tried. -

- - - -

-master:dirty()
-client:dirty()
-server:dirty() -

- -

-Check the read buffer status. -

- -

-Returns true if there is any data in the read buffer, false otherwise. -

- -

-Note: This is an internal method, use at your own risk. -

- - - - -

-master:getfd()
-client:getfd()
-server:getfd() -

- -

-Returns the underling socket descriptor or handle associated to the object. -

- -

-The descriptor or handle. In case the object has been closed, the return will be -1. -

- -

-Note: This is an internal method. Unlikely to be -portable. Use at your own risk. -

- - - - -

-client:getoption(option)
-server:getoption(option) -

- -

-Gets options for the TCP object. -See setoption for description of the -option names and values. -

- -

-Option is a string with the option name. -

    - -
  • 'keepalive' -
  • 'linger' -
  • 'reuseaddr' -
  • 'tcp-nodelay' -
- -

-The method returns the option value in case of success, or -nil followed by an error message otherwise. -

- - - - -

-client:getpeername() -

- -

-Returns information about the remote side of a connected client object. -

- -

-Returns a string with the IP address of the peer, the -port number that peer is using for the connection, -and a string with the family ("inet" or "inet6"). -In case of error, the method returns nil. -

- -

-Note: It makes no sense to call this method on server objects. -

- - - -

-master:getsockname()
-client:getsockname()
-server:getsockname() -

- -

-Returns the local address information associated to the object. -

- -

-The method returns a string with local IP address, a number with -the local port, -and a string with the family ("inet" or "inet6"). -In case of error, the method returns nil. -

- - - -

-master:getstats()
-client:getstats()
-server:getstats()
-

- -

-Returns accounting information on the socket, useful for throttling -of bandwidth. -

- -

-The method returns the number of bytes received, the number of bytes sent, -and the age of the socket object in seconds. -

- - - -

-master:gettimeout()
-client:gettimeout()
-server:gettimeout() -

- -

-Returns the current block timeout followed by the curent -total timeout. -

- - - - -

-master:listen(backlog) -

- -

-Specifies the socket is willing to receive connections, transforming the -object into a server object. Server objects support the -accept, -getsockname, -setoption, -settimeout, -and close methods. -

- -

-The parameter backlog specifies the number of client -connections that can -be queued waiting for service. If the queue is full and another client -attempts connection, the connection is refused. -

- -

-In case of success, the method returns 1. In case of error, the -method returns nil followed by an error message. -

- - - -

-client:receive([pattern [, prefix]]) -

- -

-Reads data from a client object, according to the specified read -pattern. Patterns follow the Lua file I/O format, and the difference in performance between all patterns is negligible. -

- -

-Pattern can be any of the following: -

- -
    -
  • '*a': reads from the socket until the connection is -closed. No end-of-line translation is performed; -
  • '*l': reads a line of text from the socket. The line is -terminated by a LF character (ASCII 10), optionally preceded by a -CR character (ASCII 13). The CR and LF characters are not included in -the returned line. In fact, all CR characters are -ignored by the pattern. This is the default pattern; -
  • number: causes the method to read a specified number -of bytes from the socket. -
- -

-Prefix is an optional string to be concatenated to the beginning -of any received data before return. -

- -

-If successful, the method returns the received pattern. In case of error, -the method returns nil followed by an error -message, followed by a (possibly empty) string containing -the partial that was received. The error message can be -the string 'closed' in case the connection was -closed before the transmission was completed or the string -'timeout' in case there was a timeout during the operation. -

- -

-Important note: This function was changed severely. It used -to support multiple patterns (but I have never seen this feature used) and -now it doesn't anymore. Partial results used to be returned in the same -way as successful results. This last feature violated the idea that all -functions should return nil on error. Thus it was changed -too. -

- - - -

-client:send(data [, i [, j]]) -

- -

-Sends data through client object. -

- -

-Data is the string to be sent. The optional arguments -i and j work exactly like the standard -string.sub Lua function to allow the selection of a -substring to be sent. -

- -

-If successful, the method returns the index of the last byte -within [i, j] that has been sent. Notice that, if -i is 1 or absent, this is effectively the total -number of bytes sent. In case of error, the method returns -nil, followed by an error message, followed -by the index of the last byte within [i, j] that -has been sent. You might want to try again from the byte -following that. The error message can be 'closed' -in case the connection was closed before the transmission -was completed or the string 'timeout' in case -there was a timeout during the operation. -

- -

-Note: Output is not buffered. For small strings, -it is always better to concatenate them in Lua -(with the '..' operator) and send the result in one call -instead of calling the method several times. -

- - - -

-client:setoption(option [, value])
-server:setoption(option [, value]) -

- -

-Sets options for the TCP object. Options are only needed by low-level or -time-critical applications. You should only modify an option if you -are sure you need it. -

- -

-Option is a string with the option name, and value -depends on the option being set: - -

    - -
  • 'keepalive': Setting this option to true enables -the periodic transmission of messages on a connected socket. Should the -connected party fail to respond to these messages, the connection is -considered broken and processes using the socket are notified; - -
  • 'linger': Controls the action taken when unsent data are -queued on a socket and a close is performed. The value is a table with a -boolean entry 'on' and a numeric entry for the time interval -'timeout' in seconds. If the 'on' field is set to -true, the system will block the process on the close attempt until -it is able to transmit the data or until 'timeout' has passed. If -'on' is false and a close is issued, the system will -process the close in a manner that allows the process to continue as -quickly as possible. I do not advise you to set this to anything other than -zero; - -
  • 'reuseaddr': Setting this option indicates that the rules -used in validating addresses supplied in a call to -bind should allow reuse of local addresses; - -
  • 'tcp-nodelay': Setting this option to true -disables the Nagle's algorithm for the connection; - -
  • 'ipv6-v6only': -Setting this option to true restricts an inet6 socket to -sending and receiving only IPv6 packets. -
- -

-The method returns 1 in case of success, or nil -followed by an error message otherwise. -

- -

-Note: The descriptions above come from the man pages. -

- - - -

-master:setstats(received, sent, age)
-client:setstats(received, sent, age)
-server:setstats(received, sent, age)
-

- -

-Resets accounting information on the socket, useful for throttling -of bandwidth. -

- -

-Received is a number with the new number of bytes received. -Sent is a number with the new number of bytes sent. -Age is the new age in seconds. -

- -

-The method returns 1 in case of success and nil otherwise. -

- - - -

-master:settimeout(value [, mode])
-client:settimeout(value [, mode])
-server:settimeout(value [, mode]) -

- -

-Changes the timeout values for the object. By default, -all I/O operations are blocking. That is, any call to the methods -send, -receive, and -accept -will block indefinitely, until the operation completes. The -settimeout method defines a limit on the amount of time the -I/O methods can block. When a timeout is set and the specified amount of -time has elapsed, the affected methods give up and fail with an error code. -

- -

-The amount of time to wait is specified as the -value parameter, in seconds. There are two timeout modes and -both can be used together for fine tuning: -

- -
    -
  • 'b': block timeout. Specifies the upper limit on -the amount of time LuaSocket can be blocked by the operating system -while waiting for completion of any single I/O operation. This is the -default mode;
  • - -
  • 't': total timeout. Specifies the upper limit on -the amount of time LuaSocket can block a Lua script before returning from -a call.
  • -
- -

-The nil timeout value allows operations to block -indefinitely. Negative timeout values have the same effect. -

- -

-Note: although timeout values have millisecond precision in LuaSocket, -large blocks can cause I/O functions not to respect timeout values due -to the time the library takes to transfer blocks to and from the OS -and to and from the Lua interpreter. Also, function that accept host names -and perform automatic name resolution might be blocked by the resolver for -longer than the specified timeout value. -

- -

-Note: The old timeout method is deprecated. The name has been -changed for sake of uniformity, since all other method names already -contained verbs making their imperative nature obvious. -

- - - -

-client:shutdown(mode)
-

- -

-Shuts down part of a full-duplex connection. -

- -

-Mode tells which way of the connection should be shut down and can -take the value: -

    -
  • "both": disallow further sends and receives on the object. -This is the default mode; -
  • "send": disallow further sends on the object; -
  • "receive": disallow further receives on the object. -
- -

-This function returns 1. -

- - - -

-master:setfd(fd)
-client:setfd(fd)
-server:setfd(fd) -

- -

-Sets the underling socket descriptor or handle associated to the object. The current one is simply replaced, not closed, and no other change to the object state is made. -

- -

-No return value. -

- -

-Note: This is an internal method. Unlikely to be -portable. Use at your own risk. -

- - - -

-socket.tcp() -

- -

-Creates and returns an TCP master object. A master object can -be transformed into a server object with the method -listen (after a call to bind) or into a client object with -the method connect. The only other -method supported by a master object is the -close method.

- -

-In case of success, a new master object is returned. In case of error, -nil is returned, followed by an error message. -

- -

-Note: The choice between IPv4 and IPv6 happens during a call to -bind or connect, depending on the address -family obtained from the resolver. -

- -

-Note: Before the choice between IPv4 and IPv6 happens, -the internal socket object is invalid and therefore setoption will fail. -

- - - -

-socket.tcp4() -

- -

-Creates and returns an IPv4 TCP master object. A master object can -be transformed into a server object with the method -listen (after a call to bind) or into a client object with -the method connect. The only other -method supported by a master object is the -close method.

- -

-In case of success, a new master object is returned. In case of error, -nil is returned, followed by an error message. -

- - - -

-socket.tcp6() -

- -

-Creates and returns an IPv6 TCP master object. A master object can -be transformed into a server object with the method -listen (after a call to bind) or into a client object with -the method connect. The only other -method supported by a master object is the -close method.

- -

-In case of success, a new master object is returned. In case of error, -nil is returned, followed by an error message. -

- -

-Note: The TCP object returned will have the option -"ipv6-v6only" set to true. -

- - - - - - - - - diff -Nru luasocket-3.0~rc1+git+ac3201d/doc/udp.html luasocket-3.1.0/doc/udp.html --- luasocket-3.0~rc1+git+ac3201d/doc/udp.html 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/doc/udp.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,596 +0,0 @@ - - - - - - -LuaSocket: UDP support - - - - - - - -
-
-
- - - -
-LuaSocket -
Network support for the Lua language -
-

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

-
-
-
- - - - -

UDP

- - - -

-connected:close()
-unconnected:close() -

- -

-Closes a UDP object. The internal socket -used by the object is closed and the local address to which the -object was bound is made available to other applications. No -further operations (except for further calls to the close -method) are allowed on a closed socket. -

- -

-Note: It is important to close all used sockets -once they are not needed, since, in many systems, each socket uses -a file descriptor, which are limited system resources. -Garbage-collected objects are automatically closed before -destruction, though. -

- - - -

-connected:getoption()
-unconnected:getoption() -

- -

-Gets an option value from the UDP object. -See setoption for -description of the option names and values. -

- -

Option is a string with the option name. -

    -
  • 'dontroute' -
  • 'broadcast' -
  • 'reuseaddr' -
  • 'reuseport' -
  • 'ip-multicast-loop' -
  • 'ipv6-v6only' -
  • 'ip-multicast-if' -
  • 'ip-multicast-ttl' -
  • 'ip-add-membership' -
  • 'ip-drop-membership' -
-

- -

-The method returns the option value in case of -success, or -nil followed by an error message otherwise. -

- - - -

-connected:getpeername() -

- -

-Retrieves information about the peer -associated with a connected UDP object. -

- - -

-Returns a string with the IP address of the peer, the -port number that peer is using for the connection, -and a string with the family ("inet" or "inet6"). -In case of error, the method returns nil. -

- -

-Note: It makes no sense to call this method on unconnected objects. -

- - - -

-connected:getsockname()
-unconnected:getsockname() -

- -

-Returns the local address information associated to the object. -

- - -

-The method returns a string with local IP address, a number with -the local port, -and a string with the family ("inet" or "inet6"). -In case of error, the method returns nil. -

- -

-Note: UDP sockets are not bound to any address -until the setsockname or the -sendto method is called for the -first time (in which case it is bound to an ephemeral port and the -wild-card address). -

- - - -

-connected:settimeout(value)
-unconnected:settimeout(value) -

- -

-Returns the current timeout value. -

- - - - -

-connected:receive([size])
-unconnected:receive([size]) -

- -

-Receives a datagram from the UDP object. If -the UDP object is connected, only datagrams coming from the peer -are accepted. Otherwise, the returned datagram can come from any -host. -

- -

-The optional size parameter -specifies the maximum size of the datagram to be retrieved. If -there are more than size bytes available in the datagram, -the excess bytes are discarded. If there are less then -size bytes available in the current datagram, the -available bytes are returned. -If size is omitted, the -compile-time constant socket._DATAGRAMSIZE is used -(it defaults to 8192 bytes). Larger sizes will cause a -temporary buffer to be allocated for the operation. -

- -

-In case of success, the method returns the -received datagram. In case of timeout, the method returns -nil followed by the string 'timeout'. -

- - - -

-unconnected:receivefrom([size]) -

- -

-Works exactly as the receive -method, except it returns the IP -address and port as extra return values (and is therefore slightly less -efficient). -

- - - -

-connected:send(datagram) -

- -

-Sends a datagram to the UDP peer of a connected object. -

- -

-Datagram is a string with the datagram contents. -The maximum datagram size for UDP is 64K minus IP layer overhead. -However datagrams larger than the link layer packet size will be -fragmented, which may deteriorate performance and/or reliability. -

- -

-If successful, the method returns 1. In case of -error, the method returns nil followed by an error message. -

- -

-Note: In UDP, the send method never blocks -and the only way it can fail is if the underlying transport layer -refuses to send a message to the specified address (i.e. no -interface accepts the address). -

- - - -

-unconnected:sendto(datagram, ip, port) -

- -

-Sends a datagram to the specified IP address and port number. -

- -

-Datagram is a string with the -datagram contents. -The maximum datagram size for UDP is 64K minus IP layer overhead. -However datagrams larger than the link layer packet size will be -fragmented, which may deteriorate performance and/or reliability. -Ip is the IP address of the recipient. -Host names are not allowed for performance reasons. - -Port is the port number at the recipient. -

- -

-If successful, the method returns 1. In case of -error, the method returns nil followed by an error message. -

- -

-Note: In UDP, the send method never blocks -and the only way it can fail is if the underlying transport layer -refuses to send a message to the specified address (i.e. no -interface accepts the address). -

- - - -

-connected:setoption(option [, value])
-unconnected:setoption(option [, value]) -

- -

-Sets options for the UDP object. Options are -only needed by low-level or time-critical applications. You should -only modify an option if you are sure you need it.

-

Option is a string with the option -name, and value depends on the option being set: -

- -
    -
  • 'dontroute': Indicates that outgoing -messages should bypass the standard routing facilities. -Receives a boolean value; -
  • 'broadcast': Requests permission to send -broadcast datagrams on the socket. -Receives a boolean value; -
  • 'reuseaddr': Indicates that the rules used in -validating addresses supplied in a bind() call -should allow reuse of local addresses. -Receives a boolean value; -
  • 'reuseport': Allows completely duplicate -bindings by multiple processes if they all set -'reuseport' before binding the port. -Receives a boolean value; -
  • 'ip-multicast-loop': -Specifies whether or not a copy of an outgoing multicast -datagram is delivered to the sending host as long as it is a -member of the multicast group. -Receives a boolean value; -
  • 'ipv6-v6only': -Specifies whether to restrict inet6 sockets to -sending and receiving only IPv6 packets. -Receive a boolean value; -
  • 'ip-multicast-if': -Sets the interface over which outgoing multicast datagrams -are sent. -Receives an IP address; -
  • 'ip-multicast-ttl': -Sets the Time To Live in the IP header for outgoing -multicast datagrams. -Receives a number; -
  • 'ip-add-membership': -Joins the multicast group specified. -Receives a table with fields -multiaddr and interface, each containing an -IP address; -
  • 'ip-drop-membership': Leaves the multicast -group specified. -Receives a table with fields -multiaddr and interface, each containing an -IP address. -
- -

-The method returns 1 in case of success, or -nil followed by an error message otherwise. -

- -

-Note: The descriptions above come from the man pages. -

- - - - -

-connected:setpeername('*')
-unconnected:setpeername(address, port) -

- -

-Changes the peer of a UDP object. This -method turns an unconnected UDP object into a connected UDP -object or vice versa. -

- -

-For connected objects, outgoing datagrams -will be sent to the specified peer, and datagrams received from -other peers will be discarded by the OS. Connected UDP objects must -use the send and -receive methods instead of -sendto and -receivefrom. -

- -

-Address can be an IP address or a -host name. Port is the port number. If address is -'*' and the object is connected, the peer association is -removed and the object becomes an unconnected object again. In that -case, the port argument is ignored. -

- -

-In case of error the method returns -nil followed by an error message. In case of success, the -method returns 1. -

- -

-Note: Since the address of the peer does not have -to be passed to and from the OS, the use of connected UDP objects -is recommended when the same peer is used for several transmissions -and can result in up to 30% performance gains. -

- -

-Note: Starting with LuaSocket 3.0, the host name resolution -depends on whether the socket was created by socket.udp or socket.udp6. Addresses from -the appropriate family are tried in succession until the -first success or until the last failure. -

- - - -

-unconnected:setsockname(address, port) -

- -

-Binds the UDP object to a local address. -

- -

-Address can be an IP address or a -host name. If address is '*' the system binds to -all local interfaces using the constant INADDR_ANY. If -port is 0, the system chooses an ephemeral port. -

- -

-If successful, the method returns 1. In case of -error, the method returns nil followed by an error -message. -

- -

-Note: This method can only be called before any -datagram is sent through the UDP object, and only once. Otherwise, -the system automatically binds the object to all local interfaces -and chooses an ephemeral port as soon as the first datagram is -sent. After the local address is set, either automatically by the -system or explicitly by setsockname, it cannot be -changed. -

- - - -

-connected:settimeout(value)
-unconnected:settimeout(value) -

- -

-Changes the timeout values for the object. By default, the -receive and -receivefrom -operations are blocking. That is, any call to the methods will block -indefinitely, until data arrives. The settimeout function defines -a limit on the amount of time the functions can block. When a timeout is -set and the specified amount of time has elapsed, the affected methods -give up and fail with an error code. -

- -

-The amount of time to wait is specified as -the value parameter, in seconds. The nil timeout -value allows operations to block indefinitely. Negative -timeout values have the same effect. -

- -

-Note: In UDP, the send -and sendto methods never block (the -datagram is just passed to the OS and the call returns -immediately). Therefore, the settimeout method has no -effect on them. -

- -

-Note: The old timeout method is -deprecated. The name has been changed for sake of uniformity, since -all other method names already contained verbs making their -imperative nature obvious. -

- - - -

-socket.udp() -

- -

-Creates and returns an unconnected UDP object. -Unconnected objects support the -sendto, -receive, -receivefrom, -getoption, -getsockname, -setoption, -settimeout, -setpeername, -setsockname, and -close. -The setpeername -is used to connect the object. -

- -

-In case of success, a new unconnected UDP object -returned. In case of error, nil is returned, followed by -an error message. -

- -

-Note: The choice between IPv4 and IPv6 happens during a call to -sendto, setpeername, or sockname, depending on the address -family obtained from the resolver. -

- -

-Note: Before the choice between IPv4 and IPv6 happens, -the internal socket object is invalid and therefore setoption will fail. -

- - - -

-socket.udp4() -

- -

-Creates and returns an unconnected IPv4 UDP object. -Unconnected objects support the -sendto, -receive, -receivefrom, -getoption, -getsockname, -setoption, -settimeout, -setpeername, -setsockname, and -close. -The setpeername -is used to connect the object. -

- -

-In case of success, a new unconnected UDP object -returned. In case of error, nil is returned, followed by -an error message. -

- - - -

-socket.udp6() -

- -

-Creates and returns an unconnected IPv6 UDP object. -Unconnected objects support the -sendto, -receive, -receivefrom, -getoption, -getsockname, -setoption, -settimeout, -setpeername, -setsockname, and -close. -The setpeername -is used to connect the object. -

- -

-In case of success, a new unconnected UDP object -returned. In case of error, nil is returned, followed by -an error message. -

- -

-Note: The TCP object returned will have the option -"ipv6-v6only" set to true. -

- - - - - - - - - diff -Nru luasocket-3.0~rc1+git+ac3201d/doc/url.html luasocket-3.1.0/doc/url.html --- luasocket-3.0~rc1+git+ac3201d/doc/url.html 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/doc/url.html 1970-01-01 00:00:00.000000000 +0000 @@ -1,328 +0,0 @@ - - - - - - -LuaSocket: URL support - - - - - - - -
-
-
- - - -
-LuaSocket -
Network support for the Lua language -
-

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

-
-
-
- - - -

URL

- -

-The url namespace provides functions to parse, protect, -and build URLs, as well as functions to compose absolute URLs -from base and relative URLs, according to -RFC 2396. -

- -

-To obtain the url namespace, run: -

- -
--- loads the URL module 
-local url = require("socket.url")
-
- -

-An URL is defined by the following grammar: -

- -
- -<url> ::= [<scheme>:][//<authority>][/<path>][;<params>][?<query>][#<fragment>]
-<authority> ::= [<userinfo>@]<host>[:<port>]
-<userinfo> ::= <user>[:<password>]
-<path> ::= {<segment>/}<segment>
-
-
- - - -

-url.absolute(base, relative) -

- -

-Builds an absolute URL from a base URL and a relative URL. -

- -

-Base is a string with the base URL or -a parsed URL table. Relative is a -string with the relative URL. -

- -

-The function returns a string with the absolute URL. -

- -

-Note: The rules that -govern the composition are fairly complex, and are described in detail in -RFC 2396. -The example bellow should give an idea of what the rules are. -

- -
-http://a/b/c/d;p?q
-
-+
-
-g:h      =  g:h
-g        =  http://a/b/c/g
-./g      =  http://a/b/c/g
-g/       =  http://a/b/c/g/
-/g       =  http://a/g
-//g      =  http://g
-?y       =  http://a/b/c/?y
-g?y      =  http://a/b/c/g?y
-#s       =  http://a/b/c/d;p?q#s
-g#s      =  http://a/b/c/g#s
-g?y#s    =  http://a/b/c/g?y#s
-;x       =  http://a/b/c/;x
-g;x      =  http://a/b/c/g;x
-g;x?y#s  =  http://a/b/c/g;x?y#s
-.        =  http://a/b/c/
-./       =  http://a/b/c/
-..       =  http://a/b/
-../      =  http://a/b/
-../g     =  http://a/b/g
-../..    =  http://a/
-../../   =  http://a/
-../../g  =  http://a/g
-
- - - -

-url.build(parsed_url) -

- -

-Rebuilds an URL from its parts. -

- -

-Parsed_url is a table with same components returned by -parse. -Lower level components, if specified, -take precedence over high level components of the URL grammar. -

- -

-The function returns a string with the built URL. -

- - - -

-url.build_path(segments, unsafe) -

- -

-Builds a <path> component from a list of -<segment> parts. -Before composition, any reserved characters found in a segment are escaped into -their protected form, so that the resulting path is a valid URL path -component. -

- -

-Segments is a list of strings with the <segment> -parts. If unsafe is anything but nil, reserved -characters are left untouched. -

- -

-The function returns a string with the -built <path> component. -

- - - -

-url.escape(content) -

- -

-Applies the URL escaping content coding to a string -Each byte is encoded as a percent character followed -by the two byte hexadecimal representation of its integer -value. -

- -

-Content is the string to be encoded. -

- -

-The function returns the encoded string. -

- -
--- load url module
-url = require("socket.url")
-
-code = url.escape("/#?;")
--- code = "%2f%23%3f%3b"
-
- - - -

-url.parse(url, default) -

- -

-Parses an URL given as a string into a Lua table with its components. -

- -

-Url is the URL to be parsed. If the default table is -present, it is used to store the parsed fields. Only fields present in the -URL are overwritten. Therefore, this table can be used to pass default -values for each field. -

- -

-The function returns a table with all the URL components: -

- -
-parsed_url = {
-  url = string,
-  scheme = string,
-  authority = string,
-  path = string,
-  params = string,
-  query = string,
-  fragment = string,
-  userinfo = string,
-  host = string,
-  port = string,
-  user = string,
-  password = string
-} -
- -
--- load url module
-url = require("socket.url")
-
-parsed_url = url.parse("http://www.example.com/cgilua/index.lua?a=2#there")
--- parsed_url = {
---   scheme = "http",
---   authority = "www.example.com",
---   path = "/cgilua/index.lua"
---   query = "a=2",
---   fragment = "there",
---   host = "www.puc-rio.br",
--- }
-
-parsed_url = url.parse("ftp://root:passwd@unsafe.org/pub/virus.exe;type=i")
--- parsed_url = {
---   scheme = "ftp",
---   authority = "root:passwd@unsafe.org",
---   path = "/pub/virus.exe",
---   params = "type=i",
---   userinfo = "root:passwd",
---   host = "unsafe.org",
---   user = "root",
---   password = "passwd",
--- }
-
- - - -

-url.parse_path(path) -

- -

-Breaks a <path> URL component into all its -<segment> parts. -

- -

-Path is a string with the path to be parsed. -

- -

-Since some characters are reserved in URLs, they must be escaped -whenever present in a <path> component. Therefore, before -returning a list with all the parsed segments, the function removes -escaping from all of them. -

- - - -

-url.unescape(content) -

- -

-Removes the URL escaping content coding from a string. -

- -

-Content is the string to be decoded. -

- -

-The function returns the decoded string. -

- - - - - - - diff -Nru luasocket-3.0~rc1+git+ac3201d/docs/dns.html luasocket-3.1.0/docs/dns.html --- luasocket-3.0~rc1+git+ac3201d/docs/dns.html 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/docs/dns.html 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,183 @@ + + + + + + +LuaSocket: DNS support + + + + + + + +
+
+
+ + + +
+LuaSocket +
Network support for the Lua language +
+

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

+
+
+
+ + + +

DNS

+ +

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

+ +
+resolved4 = {
+  name = canonic-name,
+  alias = alias-list,
+  ip = ip-address-list
+} +
+ +

+Note that the alias list can be empty. +

+ +

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

+ +
+resolved6 = {
+  [1] = {
+    family = family-name-1,
+    addr = address-1
+  },
+  ...
+  [n] = {
+    family = family-name-n,
+    addr = address-n
+  }
+} +
+ +

+Here, family contains the string "inet" for IPv4 +addresses, and "inet6" for IPv6 addresses. +

+ + + +

+socket.dns.getaddrinfo(address) +

+ +

+Converts from host name to address. +

+ +

+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. +

+ + + +

+socket.dns.gethostname() +

+ +

+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. +

+ +

+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. +

+ + + +

+socket.dns.toip(address) +

+ +

+Converts from host name to IPv4 address. +

+ +

+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. +

+ + + + + + + diff -Nru luasocket-3.0~rc1+git+ac3201d/docs/ftp.html luasocket-3.1.0/docs/ftp.html --- luasocket-3.0~rc1+git+ac3201d/docs/ftp.html 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/docs/ftp.html 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,288 @@ + + + + + + +LuaSocket: FTP support + + + + + + + +
+
+
+ + + +
+LuaSocket +
Network support for the Lua language +
+

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

+
+
+
+ + + +

FTP

+ +

+FTP (File Transfer Protocol) is a protocol used to transfer files +between hosts. The ftp namespace offers thorough support +to FTP, under a simple interface. The implementation conforms to +RFC 959. +

+ +

+High level functions are provided supporting the most common operations. +These high level functions are implemented on top of a lower level +interface. Using the low-level interface, users can easily create their +own functions to access any operation supported by the FTP +protocol. For that, check the implementation. +

+ +

+To really benefit from this module, a good understanding of + +LTN012, Filters sources and sinks is necessary. +

+ +

+To obtain the ftp namespace, run: +

+ +
+-- loads the FTP module and any libraries it requires
+local ftp = require("socket.ftp")
+
+ +

+URLs MUST conform to +RFC 1738, +that is, an URL is a string in the form: +

+ +
+ +[ftp://][<user>[:<password>]@]<host>[:<port>][/<path>][type=a|i] +
+ +

+The following constants in the namespace can be set to control the default behavior of +the FTP module: +

+ +
    +
  • PASSWORD: default anonymous password.
  • +
  • TIMEOUT: sets the timeout for all I/O operations;
  • +
  • USER: default anonymous user;
  • +
+ + + + +

+ftp.get(url)
+ftp.get{
+  host = string,
+  sink = LTN12 sink,
+  argument or path = string,
+  [user = string,]
+  [password = string]
+  [command = string,]
+  [port = number,]
+  [type = string,]
+  [step = LTN12 pump step,]
+  [create = function]
+} +

+ +

+The get function has two forms. The simple form has fixed +functionality: it downloads the contents of a URL and returns it as a +string. The generic form allows a lot more control, as explained +below. +

+ +

+If the argument of the get function is a table, the function +expects at least the fields host, sink, and one of +argument or path (argument takes +precedence). Host is the server to connect to. Sink is +the simple +LTN12 +sink that will receive the downloaded data. Argument or +path give the target path to the resource in the server. The +optional arguments are the following: +

+
    +
  • user, password: User name and password used for +authentication. Defaults to "ftp:anonymous@anonymous.org";
  • +
  • command: The FTP command used to obtain data. Defaults to +"retr", but see example below;
  • +
  • port: The port to used for the control connection. Defaults to 21;
  • +
  • type: The transfer mode. Can take values "i" or +"a". Defaults to whatever is the server default;
  • +
  • step: +LTN12 +pump step function used to pass data from the +server to the sink. Defaults to the LTN12 pump.step function;
  • +
  • create: An optional function to be used instead of +socket.tcp when the communications socket is created.
  • +
+ +

+If successful, the simple version returns the URL contents as a +string, and the generic function returns 1. In case of error, both +functions return nil and an error message describing the +error. +

+ +
+-- load the ftp support
+local ftp = require("socket.ftp")
+
+-- Log as user "anonymous" on server "ftp.tecgraf.puc-rio.br",
+-- and get file "lua.tar.gz" from directory "pub/lua" as binary.
+f, e = ftp.get("ftp://ftp.tecgraf.puc-rio.br/pub/lua/lua.tar.gz;type=i")
+
+ +
+-- load needed modules
+local ftp = require("socket.ftp")
+local ltn12 = require("ltn12")
+local url = require("socket.url")
+
+-- a function that returns a directory listing
+function nlst(u)
+    local t = {}
+    local p = url.parse(u)
+    p.command = "nlst"
+    p.sink = ltn12.sink.table(t)
+    local r, e = ftp.get(p)
+    return r and table.concat(t), e
+end
+
+ + + +

+ftp.put(url, content)
+ftp.put{
+  host = string,
+  source = LTN12 sink,
+  argument or path = string,
+  [user = string,]
+  [password = string]
+  [command = string,]
+  [port = number,]
+  [type = string,]
+  [step = LTN12 pump step,]
+  [create = function]
+} +

+ +

+The put function has two forms. The simple form has fixed +functionality: it uploads a string of content into a URL. The generic form +allows a lot more control, as explained below. +

+ +

+If the argument of the put function is a table, the function +expects at least the fields host, source, and one of +argument or path (argument takes +precedence). Host is the server to connect to. Source is +the simple +LTN12 +source that will provide the contents to be uploaded. +Argument or +path give the target path to the resource in the server. The +optional arguments are the following: +

+
    +
  • user, password: User name and password used for +authentication. Defaults to "ftp:anonymous@anonymous.org";
  • +
  • command: The FTP command used to send data. Defaults to +"stor", but see example below;
  • +
  • port: The port to used for the control connection. Defaults to 21;
  • +
  • type: The transfer mode. Can take values "i" or +"a". Defaults to whatever is the server default;
  • +
  • step: +LTN12 +pump step function used to pass data from the +server to the sink. Defaults to the LTN12 pump.step function;
  • +
  • create: An optional function to be used instead of +socket.tcp when the communications socket is created.
  • +
+ +

+Both functions return 1 if successful, or nil and an error +message describing the reason for failure. +

+ +
+-- load the ftp support
+local ftp = require("socket.ftp")
+
+-- Log as user "fulano" on server "ftp.example.com",
+-- using password "silva", and store a file "README" with contents
+-- "wrong password, of course"
+f, e = ftp.put("ftp://fulano:silva@ftp.example.com/README",
+    "wrong password, of course")
+
+ +
+-- load the ftp support
+local ftp = require("socket.ftp")
+local ltn12 = require("ltn12")
+
+-- Log as user "fulano" on server "ftp.example.com",
+-- using password "silva", and append to the remote file "LOG", sending the
+-- contents of the local file "LOCAL-LOG"
+f, e = ftp.put{
+  host = "ftp.example.com",
+  user = "fulano",
+  password = "silva",
+  command = "appe",
+  argument = "LOG",
+  source = ltn12.source.file(io.open("LOCAL-LOG", "r"))
+}
+
+ + + + + + + + diff -Nru luasocket-3.0~rc1+git+ac3201d/docs/http.html luasocket-3.1.0/docs/http.html --- luasocket-3.0~rc1+git+ac3201d/docs/http.html 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/docs/http.html 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,339 @@ + + + + + + +LuaSocket: HTTP support + + + + + + + +
+
+
+ + + +
+LuaSocket +
Network support for the Lua language +
+

+home · +download · +introduction · +introduction · +reference +

+
+
+
+ + + +

HTTP

+ +

+HTTP (Hyper Text Transfer Protocol) is the protocol used to exchange +information between web-browsers and servers. The http +namespace offers full support for the client side of the HTTP +protocol (i.e., +the facilities that would be used by a web-browser implementation). The +implementation conforms to the HTTP/1.1 standard, +RFC 2616. +

+ +

+The module exports functions that provide HTTP functionality in different +levels of abstraction. From the simple +string oriented requests, through generic +LTN12 based, down to even lower-level if you bother to look through the source code. +

+ +

+To obtain the http namespace, run: +

+ +
+-- loads the HTTP module and any libraries it requires
+local http = require("socket.http")
+
+ +

+URLs must conform to +RFC 1738, +that is, an URL is a string in the form: +

+ +
+
+[http://][<user>[:<password>]@]<host>[:<port>][/<path>]
+
+
+ +

+MIME headers are represented as a Lua table in the form: +

+ +
+ + +
+headers = {
+  field-1-name = field-1-value,
+  field-2-name = field-2-value,
+  field-3-name = field-3-value,
+  ...
+  field-n-name = field-n-value
+} +
+
+ +

+Field names are case insensitive (as specified by the standard) and all +functions work with lowercase field names (but see +socket.headers.canonic). +Field values are left unmodified. +

+ +

+Note: MIME headers are independent of order. Therefore, there is no problem +in representing them in a Lua table. +

+ +

+The following constants can be set to control the default behavior of +the HTTP module: +

+ +
    +
  • PROXY: default proxy used for connections;
  • +
  • TIMEOUT: sets the timeout for all I/O operations;
  • +
  • USERAGENT: default user agent reported to server.
  • +
+ +

+Note: These constants are global. Changing them will also +change the behavior other code that might be using LuaSocket. +

+ + + +

+http.request(url [, body])
+http.request{
+  url = string,
+  [sink = LTN12 sink,]
+  [method = string,]
+  [headers = header-table,]
+  [source = LTN12 source],
+  [step = LTN12 pump step,]
+  [proxy = string,]
+  [redirect = boolean,]
+  [create = function,]
+  [maxredirects = number]
+} +

+ +

+The request function has two forms. The simple form downloads +a URL using the GET or POST method and is based +on strings. The generic form performs any HTTP method and is +LTN12 based. +

+ +

+If the first argument of the request function is a string, it +should be an url. In that case, if a body +is provided as a string, the function will perform a POST method +in the url. Otherwise, it performs a GET in the +url +

+ +

+If the first argument is instead a table, the most important fields are +the url and the simple +LTN12 +sink that will receive the downloaded content. +Any part of the url can be overridden by including +the appropriate field in the request table. +If authentication information is provided, the function +uses the Basic Authentication Scheme (see note) +to retrieve the document. If sink is nil, the +function discards the downloaded data. The optional parameters are the +following: +

+
    +
  • method: The HTTP request method. Defaults to "GET";
  • +
  • headers: Any additional HTTP headers to send with the request;
  • +
  • source: simple +LTN12 +source to provide the request body. If there +is a body, you need to provide an appropriate "content-length" +request header field, or the function will attempt to send the body as +"chunked" (something few servers support). Defaults to the empty source;
  • +
  • step: +LTN12 +pump step function used to move data. +Defaults to the LTN12 pump.step function.
  • +
  • proxy: The URL of a proxy server to use. Defaults to no proxy;
  • +
  • redirect: Set to false to prevent the +function from automatically following 301 or 302 server redirect messages;
  • +
  • create: An optional function to be used instead of +socket.tcp when the communications socket is created.
  • +
  • maxredirects: An optional number specifying the maximum number of + redirects to follow. Defaults to 5 if not specified. A boolean + false value means no maximum (unlimited).
  • +
+ +

+In case of failure, the function returns nil followed by an +error message. If successful, the simple form returns the response +body as a string, followed by the response status code, the response +headers and the response status line. The generic function returns the same +information, except the first return value is just the number 1 (the body +goes to the sink). +

+ +

+Even when the server fails to provide the contents of the requested URL (URL not found, for example), +it usually returns a message body (a web page informing the +URL was not found or some other useless page). To make sure the +operation was successful, check the returned status code. For +a list of the possible values and their meanings, refer to RFC 2616. +

+ +

+Here are a few examples with the simple interface: +

+ +
+-- load the http module
+local io = require("io")
+local http = require("socket.http")
+local ltn12 = require("ltn12")
+
+-- connect to server "www.cs.princeton.edu" and retrieves this manual
+-- file from "~diego/professional/luasocket/http.html" and print it to stdout
+http.request{
+    url = "http://www.cs.princeton.edu/~diego/professional/luasocket/http.html",
+    sink = ltn12.sink.file(io.stdout)
+}
+
+-- connect to server "www.example.com" and tries to retrieve
+-- "/private/index.html". Fails because authentication is needed.
+b, c, h = http.request("http://www.example.com/private/index.html")
+-- b returns some useless page telling about the denied access,
+-- h returns authentication information
+-- and c returns with value 401 (Authentication Required)
+
+-- tries to connect to server "wrong.host" to retrieve "/"
+-- and fails because the host does not exist.
+r, e = http.request("http://wrong.host/")
+-- r is nil, and e returns with value "host not found"
+
+ +

+And here is an example using the generic interface: +

+ +
+-- load the http module
+http = require("socket.http")
+
+-- Requests information about a document, without downloading it.
+-- Useful, for example, if you want to display a download gauge and need
+-- to know the size of the document in advance
+r, c, h = http.request {
+  method = "HEAD",
+  url = "http://www.tecgraf.puc-rio.br/~diego"
+}
+-- r is 1, c is 200, and h would return the following headers:
+-- h = {
+--   date = "Tue, 18 Sep 2001 20:42:21 GMT",
+--   server = "Apache/1.3.12 (Unix)  (Red Hat/Linux)",
+--   ["last-modified"] = "Wed, 05 Sep 2001 06:11:20 GMT",
+--   ["content-length"] = 15652,
+--   ["connection"] = "close",
+--   ["content-Type"] = "text/html"
+-- }
+
+ +

+Note: When sending a POST request, simple interface adds a +"Content-type: application/x-www-form-urlencoded" +header to the request. This is the type used by +HTML forms. If you need another type, use the generic +interface. +

+ +

+Note: Some URLs are protected by their +servers from anonymous download. For those URLs, the server must receive +some sort of authentication along with the request or it will deny +download and return status "401 Authentication Required". +

+ +

+The HTTP/1.1 standard defines two authentication methods: the Basic +Authentication Scheme and the Digest Authentication Scheme, both +explained in detail in +RFC 2068. +

+ +

The Basic Authentication Scheme sends +<user> and +<password> unencrypted to the server and is therefore +considered unsafe. Unfortunately, by the time of this implementation, +the wide majority of servers and browsers support the Basic Scheme only. +Therefore, this is the method used by the toolkit whenever +authentication is required. +

+ +
+-- load required modules
+http = require("socket.http")
+mime = require("mime")
+
+-- Connect to server "www.example.com" and tries to retrieve
+-- "/private/index.html", using the provided name and password to
+-- authenticate the request
+b, c, h = http.request("http://fulano:silva@www.example.com/private/index.html")
+
+-- Alternatively, one could fill the appropriate header and authenticate
+-- the request directly.
+r, c = http.request {
+  url = "http://www.example.com/private/index.html",
+  headers = { authorization = "Basic " .. (mime.b64("fulano:silva")) }
+}
+
+ + + + + + + diff -Nru luasocket-3.0~rc1+git+ac3201d/docs/index.html luasocket-3.1.0/docs/index.html --- luasocket-3.0~rc1+git+ac3201d/docs/index.html 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/docs/index.html 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,138 @@ + + + + + + +LuaSocket: Network support for the Lua language + + + + + + + +
+
+
+ + + +
+LuaSocket +
Network support for the Lua language +
+

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

+
+
+
+ + + +

What is LuaSocket?

+ +

+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. +

+ +

+The core support has been implemented so that it is both efficient and +simple to use. It is available to any Lua application once it has been +properly initialized by the interpreter in use. The code has been tested +and runs well on several Windows and UNIX platforms.

+ +

+Among the support modules, the most commonly used implement the +SMTP +(sending e-mails), +HTTP +(WWW access) and +FTP +(uploading and downloading files) client +protocols. These provide a very natural and generic interface to the +functionality defined by each protocol. +In addition, you will find that the +MIME (common encodings), +URL +(anything you could possible want to do with one) and +LTN12 +(filters, sinks, sources and pumps) modules can be very handy. +

+ +

+The library is available under the same + +terms and conditions as the Lua language, the MIT license. The idea is +that if you can use Lua in a project, you should also be able to use +LuaSocket. +

+ +

+Copyright © 1999-2013 Diego Nehab. All rights reserved.
+Author: Diego Nehab +

+ + + +

Download

+ +

+LuaSocket version 3.1.0 is now available for download! +It is compatible with Lua 5.1 through 5.4. +Chances are it works well on most UNIX distributions and Windows flavors. +

+ +

+The current version of the library can be found at +the LuaSocket +project page on GitHub. Besides the full C and Lua source code +for the library, the distribution contains several examples, +this user's manual and basic test procedures. +

+ +

Take a look at the installation section of the +manual to find out how to properly install the library. +

+ + + +

Special thanks

+ +

+This marks the first release of LuaSocket that +wholeheartedly embraces the open-source development +philosophy. After a long hiatus, Matthew Wild finally +convinced me it was time for a release including IPv6 and +Lua 5.2 support. It was more work than we anticipated. +Special thanks to Sam Roberts, Florian Zeitz, and Paul +Aurich, Liam Devine, Alexey Melnichuk, and everybody else +that has helped bring this library back to life. +

+ + + + + + + diff -Nru luasocket-3.0~rc1+git+ac3201d/docs/installation.html luasocket-3.1.0/docs/installation.html --- luasocket-3.0~rc1+git+ac3201d/docs/installation.html 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/docs/installation.html 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,127 @@ + + + + + + +LuaSocket: Installation + + + + + + + +
+
+
+ + + +
+LuaSocket +
Network support for the Lua language +
+

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

+
+
+
+ + + +

Installation

+ +

Here we describe the standard distribution. If the +standard doesn't meet your needs, we refer you to the Lua +discussion list, where any question about the package scheme +will likely already have been answered.

+ +

Directory structure

+ +

On Unix systems, the standard distribution uses two base +directories, one for system dependent files, and another for system +independent files. Let's call these directories <CDIR> +and <LDIR>, respectively. +For example, in my laptp, Lua 5.1 is configured to +use '/usr/local/lib/lua/5.1' for +<CDIR> and '/usr/local/share/lua/5.1' for +<LDIR>. On Windows, <CDIR> +usually points to the directory where the Lua executable is +found, and <LDIR> points to a +lua/ directory inside <CDIR>. (These +settings can be overridden by environment variables +LUA_PATH and LUA_CPATH. See the Lua +documentation for details.) Here is the standard LuaSocket +distribution directory structure:

+ +
+<LDIR>/ltn12.lua
+<LDIR>/socket.lua
+<CDIR>/socket/core.dll
+<LDIR>/socket/http.lua
+<LDIR>/socket/tp.lua
+<LDIR>/socket/ftp.lua
+<LDIR>/socket/smtp.lua
+<LDIR>/socket/url.lua
+<LDIR>/mime.lua
+<CDIR>/mime/core.dll
+
+ +

Naturally, on Unix systems, core.dll +would be replaced by core.so. +

+ +

Using LuaSocket

+ +

With the above setup, and an interpreter with shared library support, +it should be easy to use LuaSocket. Just fire the interpreter and use the +require function to gain access to whatever module you need:

+ +
+Lua 5.2.2  Copyright (C) 1994-2013 Lua.org, PUC-Rio
+> socket = require("socket")
+> print(socket._VERSION)
+--> LuaSocket 3.0.0
+
+ +

Each module loads their dependencies automatically, so you only need to +load the modules you directly depend upon:

+ +
+Lua 5.2.2  Copyright (C) 1994-2013 Lua.org, PUC-Rio
+> http = require("socket.http")
+> print(http.request("http://www.impa.br/~diego/software/luasocket"))
+--> homepage gets dumped to terminal
+
+ + + + + + + diff -Nru luasocket-3.0~rc1+git+ac3201d/docs/introduction.html luasocket-3.1.0/docs/introduction.html --- luasocket-3.0~rc1+git+ac3201d/docs/introduction.html 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/docs/introduction.html 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,333 @@ + + + + + + +LuaSocket: Introduction to the core + + + + + + + +
+
+
+ + + +
+LuaSocket +
Network support for the Lua language +
+

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

+
+
+
+ + + +

Introduction

+ +

+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 +the SMTP (sending e-mails), HTTP (WWW access) and FTP (uploading and +downloading files) protocols and other functionality commonly needed by +applications that deal with the Internet. This introduction is about the C +core. +

+ +

+Communication in LuaSocket is performed via I/O objects. These can +represent different network domains. Currently, support is provided for TCP +and UDP, but nothing prevents other developers from implementing SSL, Local +Domain, Pipes, File Descriptors etc. I/O objects provide a standard +interface to I/O across different domains and operating systems. +

+ +

+The API design had two goals in mind. First, users +experienced with the C API to sockets should feel comfortable using LuaSocket. +Second, the simplicity and the feel of the Lua language should be +preserved. To achieve these goals, the LuaSocket API keeps the function names and semantics the C API whenever possible, but their usage in Lua has been greatly simplified. +

+ + +

+One of the simplifications is the receive pattern capability. +Applications can read data from stream domains (such as TCP) +line by line, block by block, or until the connection is closed. +All I/O reads are buffered and the performance differences between +different receive patterns are negligible. +

+ +

+Another advantage is the flexible timeout control +mechanism. As in C, all I/O operations are blocking by default. For +example, the send, +receive and +accept methods +of the TCP domain will block the caller application until +the operation is completed (if ever!). However, with a call to the +settimeout +method, an application can specify upper limits on +the time it can be blocked by LuaSocket (the "total" timeout), on +the time LuaSocket can internally be blocked by any OS call (the +"block" timeout) or a combination of the two. Each LuaSocket +call might perform several OS calls, so that the two timeout values are +not equivalent. +

+ +

+Finally, the host name resolution is transparent, meaning that most +functions and methods accept both IP addresses and host names. In case a +host name is given, the library queries the system's resolver and +tries the main IP address returned. Note that direct use of IP addresses +is more efficient, of course. The +toip +and tohostname +functions from the DNS module are provided to convert between host names and IP addresses. +

+ +

+Together, these changes make network programming in LuaSocket much simpler +than it is in C, as the following sections will show. +

+ + + +

TCP

+ +

+TCP (Transfer Control Protocol) is reliable stream protocol. In other +words, applications communicating through TCP can send and receive data as +an error free stream of bytes. Data is split in one end and +reassembled transparently on the other end. There are no boundaries in +the data transfers. The library allows users to read data from the +sockets in several different granularities: patterns are available for +lines, arbitrary sized blocks or "read up to connection closed", all with +good performance. +

+ +

+The library distinguishes three types of TCP sockets: master, +client and server sockets. +

+ +

+Master sockets are newly created TCP sockets returned by the function +socket.tcp. A master socket is +transformed into a server socket +after it is associated with a local address by a call to the +bind method followed by a call to the +listen. Conversely, a master socket +can be changed into a client socket with the method +connect, +which associates it with a remote address. +

+ +

+On server sockets, applications can use the +accept method +to wait for a client connection. Once a connection is established, a +client socket object is returned representing this connection. The +other methods available for server socket objects are +getsockname, +setoption, +settimeout, and +close. +

+ +

+Client sockets are used to exchange data between two applications over +the Internet. Applications can call the methods +send and +receive +to send and receive data. The other methods +available for client socket objects are +getsockname, +getpeername, +setoption, +settimeout, +shutdown, and +close. +

+ +

+Example: +

+
+

+A simple echo server, using LuaSocket. The program binds to an ephemeral +port (one that is chosen by the operating system) on the local host and +awaits client connections on that port. When a connection is established, +the program reads a line from the remote end and sends it back, closing +the connection immediately. You can test it using the telnet +program. +

+ +
+-- load namespace
+local socket = require("socket")
+-- create a TCP socket and bind it to the local host, at any port
+local server = assert(socket.bind("*", 0))
+-- find out which port the OS chose for us
+local ip, port = server:getsockname()
+-- print a message informing what's up
+print("Please telnet to localhost on port " .. port)
+print("After connecting, you have 10s to enter a line to be echoed")
+-- loop forever waiting for clients
+while 1 do
+  -- wait for a connection from any client
+  local client = server:accept()
+  -- make sure we don't block waiting for this client's line
+  client:settimeout(10)
+  -- receive the line
+  local line, err = client:receive()
+  -- if there was no error, send it back to the client
+  if not err then client:send(line .. "\n") end
+  -- done with client, close the object
+  client:close()
+end
+
+
+ + + +

UDP

+ +

+UDP (User Datagram Protocol) is a non-reliable datagram protocol. In +other words, applications communicating through UDP send and receive +data as independent blocks, which are not guaranteed to reach the other +end. Even when they do reach the other end, they are not guaranteed to be +error free. Data transfers are atomic, one datagram at a time. Reading +only part of a datagram discards the rest, so that the following read +operation will act on the next datagram. The advantages are in +simplicity (no connection setup) and performance (no error checking or +error correction). +

+ +

+Note that although no guarantees are made, these days +networks are so good that, under normal circumstances, few errors +happen in practice. +

+ +

+An UDP socket object is created by the +socket.udp function. UDP +sockets do not need to be connected before use. The method +sendto +can be used immediately after creation to +send a datagram to IP address and port. Host names are not allowed +because performing name resolution for each packet would be forbiddingly +slow. Methods +receive and +receivefrom +can be used to retrieve datagrams, the latter returning the IP and port of +the sender as extra return values (thus being slightly less +efficient). +

+ +

+When communication is performed repeatedly with a single peer, an +application should call the +setpeername method to specify a +permanent partner. Methods +sendto and +receivefrom +can no longer be used, but the method +send can be used to send data +directly to the peer, and the method +receive +will only return datagrams originating +from that peer. There is about 30% performance gain due to this practice. +

+ +

+To associate an UDP socket with a local address, an application calls the +setsockname +method before sending any datagrams. Otherwise, the socket is +automatically bound to an ephemeral address before the first data +transmission and once bound the local address cannot be changed. +The other methods available for UDP sockets are +getpeername, +getsockname, +settimeout, +setoption and +close. +

+ +

+Example: +

+
+

+A simple daytime client, using LuaSocket. The program connects to a remote +server and tries to retrieve the daytime, printing the answer it got or an +error message. +

+ +
+-- change here to the host an port you want to contact
+local host, port = "localhost", 13
+-- load namespace
+local socket = require("socket")
+-- convert host name to ip address
+local ip = assert(socket.dns.toip(host))
+-- create a new UDP object
+local udp = assert(socket.udp())
+-- contact daytime host
+assert(udp:sendto("anything", ip, port))
+-- retrieve the answer and print results
+io.write(assert(udp:receive()))
+
+
+ + + +

Support modules

+ +

Although not covered in the introduction, LuaSocket offers +much more than TCP and UDP functionality. As the library +evolved, support for HTTP, FTP, +and SMTP were built on top of these. These modules +and many others are covered by the reference manual. +

+ + + + + + + diff -Nru luasocket-3.0~rc1+git+ac3201d/docs/ltn12.html luasocket-3.1.0/docs/ltn12.html --- luasocket-3.0~rc1+git+ac3201d/docs/ltn12.html 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/docs/ltn12.html 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,440 @@ + + + + + + +LuaSocket: LTN12 module + + + + + + + +
+
+
+ + + +
+LuaSocket +
Network support for the Lua language +
+

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

+
+
+
+ + + +

LTN12

+ +

The ltn12 namespace implements the ideas described in + +LTN012, Filters sources and sinks. This manual simply describes the +functions. Please refer to the LTN for a deeper explanation of the +functionality provided by this module. +

+ +

+To obtain the ltn12 namespace, run: +

+ +
+-- loads the LTN21 module
+local ltn12 = require("ltn12")
+
+ + + +

Filters

+ + + +

+ltn12.filter.chain(filter1, filter2 +[, ... filterN]) +

+ +

+Returns a filter that passes all data it receives through each of a +series of given filters. +

+ +

+Filter1 to filterN are simple +filters. +

+ +

+The function returns the chained filter. +

+ +

+The nesting of filters can be arbitrary. For instance, the useless filter +below doesn't do anything but return the data that was passed to it, +unaltered. +

+ +
+-- load required modules
+local ltn12 = require("ltn12")
+local mime = require("mime")
+
+-- create a silly identity filter
+id = ltn12.filter.chain(
+  mime.encode("quoted-printable"),
+  mime.encode("base64"),
+  mime.decode("base64"),
+  mime.decode("quoted-printable")
+)
+
+ + + +

+ltn12.filter.cycle(low [, ctx, extra]) +

+ +

+Returns a high-level filter that cycles though a low-level filter by +passing it each chunk and updating a context between calls. +

+ +

+Low is the low-level filter to be cycled, +ctx is the initial context and extra is any extra +argument the low-level filter might take. +

+ +

+The function returns the high-level filter. +

+ +
+-- load the ltn12 module
+local ltn12 = require("ltn12")
+
+-- the base64 mime filter factory
+encodet['base64'] = function()
+    return ltn12.filter.cycle(b64, "")
+end
+
+ + + +

Pumps

+ + + +

+ltn12.pump.all(source, sink) +

+ +

+Pumps all data from a source to a sink. +

+ +

+If successful, the function returns a value that evaluates to +true. In case +of error, the function returns a false value, followed by an error message. +

+ + + +

+ltn12.pump.step(source, sink) +

+ +

+Pumps one chunk of data from a source to a sink. +

+ +

+If successful, the function returns a value that evaluates to +true. In case +of error, the function returns a false value, followed by an error message. +

+ + + +

Sinks

+ + + +

+ltn12.sink.chain(filter, sink) +

+ +

+Creates and returns a new sink that passes data through a filter before sending it to a given sink. +

+ + + +

+ltn12.sink.error(message) +

+ +

+Creates and returns a sink that aborts transmission with the error +message. +

+ + + +

+ltn12.sink.file(handle, message) +

+ +

+Creates a sink that sends data to a file. +

+ +

+Handle is a file handle. If handle is nil, +message should give the reason for failure. +

+ +

+The function returns a sink that sends all data to the given handle +and closes the file when done, or a sink that aborts the transmission with +the error message +

+ +

+In the following example, notice how the prototype is designed to +fit nicely with the io.open function. +

+ +
+-- load the ltn12 module
+local ltn12 = require("ltn12")
+
+-- copy a file
+ltn12.pump.all(
+  ltn12.source.file(io.open("original.png", "rb")),
+  ltn12.sink.file(io.open("copy.png", "wb"))
+)
+
+ + + +

+ltn12.sink.null() +

+ +

+Returns a sink that ignores all data it receives. +

+ + + +

+ltn12.sink.simplify(sink) +

+ +

+Creates and returns a simple sink given a fancy sink. +

+ + + +

+ltn12.sink.table([table]) +

+ +

+Creates a sink that stores all chunks in a table. The chunks can later be +efficiently concatenated into a single string. +

+ +

+Table is used to hold the chunks. If +nil, the function creates its own table. +

+ +

+The function returns the sink and the table used to store the chunks. +

+ +
+-- load needed modules
+local http = require("socket.http")
+local ltn12 = require("ltn12")
+
+-- a simplified http.get function
+function http.get(u)
+  local t = {}
+  local respt = request{
+    url = u,
+    sink = ltn12.sink.table(t)
+  }
+  return table.concat(t), respt.headers, respt.code
+end
+
+ + + +

Sources

+ + + +

+ltn12.source.cat(source1 [, source2, ..., +sourceN]) +

+ +

+Creates a new source that produces the concatenation of the data produced +by a number of sources. +

+ +

+Source1 to sourceN are the original +sources. +

+ +

+The function returns the new source. +

+ + + +

+ltn12.source.chain(source, filter) +

+ +

+Creates a new source that passes data through a filter +before returning it. +

+ +

+The function returns the new source. +

+ + + +

+ltn12.source.empty() +

+ +

+Creates and returns an empty source. +

+ + + +

+ltn12.source.error(message) +

+ +

+Creates and returns a source that aborts transmission with the error +message. +

+ + + +

+ltn12.source.file(handle, message) +

+ +

+Creates a source that produces the contents of a file. +

+ +

+Handle is a file handle. If handle is nil, +message should give the reason for failure. +

+ +

+The function returns a source that reads chunks of data from +given handle and returns it to the user, +closing the file when done, or a source that aborts the transmission with +the error message +

+ +

+In the following example, notice how the prototype is designed to +fit nicely with the io.open function. +

+ +
+-- load the ltn12 module
+local ltn12 = require("ltn12")
+
+-- copy a file
+ltn12.pump.all(
+  ltn12.source.file(io.open("original.png", "rb")),
+  ltn12.sink.file(io.open("copy.png", "wb"))
+)
+
+ + + +

+ltn12.source.simplify(source) +

+ +

+Creates and returns a simple source given a fancy source. +

+ + + +

+ltn12.source.string(string) +

+ +

+Creates and returns a source that produces the contents of a +string, chunk by chunk. +

+ + + +

+ltn12.source.table(table) +

+ +

+Creates and returns a source that produces the numerically-indexed values of a table successively beginning at 1. The source returns nil (end-of-stream) whenever a nil value is produced by the current index, which proceeds forward regardless. +

+ + + + + + + Binary files /tmp/tmpsljgbcll/D2IclVS3PF/luasocket-3.0~rc1+git+ac3201d/docs/lua05.ppt and /tmp/tmpsljgbcll/P9aFpSgj8o/luasocket-3.1.0/docs/lua05.ppt differ Binary files /tmp/tmpsljgbcll/D2IclVS3PF/luasocket-3.0~rc1+git+ac3201d/docs/luasocket.png and /tmp/tmpsljgbcll/P9aFpSgj8o/luasocket-3.1.0/docs/luasocket.png differ diff -Nru luasocket-3.0~rc1+git+ac3201d/docs/mime.html luasocket-3.1.0/docs/mime.html --- luasocket-3.0~rc1+git+ac3201d/docs/mime.html 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/docs/mime.html 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,477 @@ + + + + + + +LuaSocket: MIME module + + + + + + + +
+
+
+ + + +
+LuaSocket +
Network support for the Lua language +
+

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

+
+
+
+ + + +

MIME

+ +

+The mime namespace offers filters that apply and remove common +content transfer encodings, such as Base64 and Quoted-Printable. +It also provides functions to break text into lines and change +the end-of-line convention. +MIME is described mainly in +RFC 2045, +2046, +2047, +2048, and +2049. +

+ +

+All functionality provided by the MIME module +follows the ideas presented in + +LTN012, Filters sources and sinks. +

+ +

+To obtain the mime namespace, run: +

+ +
+-- loads the MIME module and everything it requires
+local mime = require("mime")
+
+ + + + +

High-level filters

+ + + + +

+mime.decode("base64")
+mime.decode("quoted-printable") +

+ +

+Returns a filter that decodes data from a given transfer content +encoding. +

+ + + +

+mime.encode("base64")
+mime.encode("quoted-printable" [, mode]) +

+ +

+Returns a filter that encodes data according to a given transfer content +encoding. +

+ +

+In the Quoted-Printable case, the user can specify whether the data is +textual or binary, by passing the mode strings "text" or +"binary". Mode defaults to "text". +

+ +

+Although both transfer content encodings specify a limit for the line +length, the encoding filters do not break text into lines (for +added flexibility). +Below is a filter that converts binary data to the Base64 transfer content +encoding and breaks it into lines of the correct size. +

+ +
+base64 = ltn12.filter.chain(
+  mime.encode("base64"),
+  mime.wrap("base64")
+)
+
+ +

+Note: Text data has to be converted to canonic form +before being encoded. +

+ +
+base64 = ltn12.filter.chain(
+  mime.normalize(),
+  mime.encode("base64"),
+  mime.wrap("base64")
+)
+
+ + + +

+mime.normalize([marker]) +

+ +

+Converts most common end-of-line markers to a specific given marker. +

+ +

+Marker is the new marker. It defaults to CRLF, the canonic +end-of-line marker defined by the MIME standard. +

+ +

+The function returns a filter that performs the conversion. +

+ +

+Note: There is no perfect solution to this problem. Different end-of-line +markers are an evil that will probably plague developers forever. +This function, however, will work perfectly for text created with any of +the most common end-of-line markers, i.e. the Mac OS (CR), the Unix (LF), +or the DOS (CRLF) conventions. Even if the data has mixed end-of-line +markers, the function will still work well, although it doesn't +guarantee that the number of empty lines will be correct. +

+ + + +

+mime.stuff()
+

+ +

+Creates and returns a filter that performs stuffing of SMTP messages. +

+ +

+Note: The smtp.send function +uses this filter automatically. You don't need to chain it with your +source, or apply it to your message body. +

+ + + +

+mime.wrap("text" [, length])
+mime.wrap("base64")
+mime.wrap("quoted-printable") +

+ +

+Returns a filter that breaks data into lines. +

+ +

+The "text" line-wrap filter simply breaks text into lines by +inserting CRLF end-of-line markers at appropriate positions. +Length defaults 76. +The "base64" line-wrap filter works just like the default +"text" line-wrap filter with default length. +The function can also wrap "quoted-printable" lines, taking care +not to break lines in the middle of an escaped character. In that case, the +line length is fixed at 76. +

+ +

+For example, to create an encoding filter for the Quoted-Printable transfer content encoding of text data, do the following: +

+ +
+qp = ltn12.filter.chain(
+  mime.normalize(),
+  mime.encode("quoted-printable"),
+  mime.wrap("quoted-printable")
+)
+
+ +

+Note: To break into lines with a different end-of-line convention, apply +a normalization filter after the line break filter. +

+ + + +

Low-level filters

+ + + +

+A, B = mime.b64(C [, D]) +

+ +

+Low-level filter to perform Base64 encoding. +

+ +

+A is the encoded version of the largest prefix of +C..D +that can be encoded unambiguously. B has the remaining bytes of +C..D, before encoding. +If D is nil, A is padded with +the encoding of the remaining bytes of C. +

+ +

+Note: The simplest use of this function is to encode a string into it's +Base64 transfer content encoding. Notice the extra parenthesis around the +call to mime.b64, to discard the second return value. +

+ +
+print((mime.b64("diego:password")))
+--> ZGllZ286cGFzc3dvcmQ=
+
+ + +

+A, n = mime.dot(m [, B]) +

+ +

+Low-level filter to perform SMTP stuffing and enable transmission of +messages containing the sequence "CRLF.CRLF". +

+ +

+A is the stuffed version of B. 'n' gives the +number of characters from the sequence CRLF seen in the end of B. +'m' should tell the same, but for the previous chunk. +

+ +

Note: The message body is defined to begin with +an implicit CRLF. Therefore, to stuff a message correctly, the +first m should have the value 2. +

+ +
+print((string.gsub(mime.dot(2, ".\r\nStuffing the message.\r\n.\r\n."), "\r\n", "\\n")))
+--> ..\nStuffing the message.\n..\n..
+
+ +

+Note: The smtp.send function +uses this filter automatically. You don't need to +apply it again. +

+ + + +

+A, B = mime.eol(C [, D, marker]) +

+ +

+Low-level filter to perform end-of-line marker translation. +For each chunk, the function needs to know if the last character of the +previous chunk could be part of an end-of-line marker or not. This is the +context the function receives besides the chunk. An updated version of +the context is returned after each new chunk. +

+ +

+A is the translated version of D. C is the +ASCII value of the last character of the previous chunk, if it was a +candidate for line break, or 0 otherwise. +B is the same as C, but for the current +chunk. Marker gives the new end-of-line marker and defaults to CRLF. +

+ +
+-- translates the end-of-line marker to UNIX
+unix = mime.eol(0, dos, "\n")
+
+ + + +

+A, B = mime.qp(C [, D, marker]) +

+ +

+Low-level filter to perform Quoted-Printable encoding. +

+ +

+A is the encoded version of the largest prefix of +C..D +that can be encoded unambiguously. B has the remaining bytes of +C..D, before encoding. +If D is nil, A is padded with +the encoding of the remaining bytes of C. +Throughout encoding, occurrences of CRLF are replaced by the +marker, which itself defaults to CRLF. +

+ +

+Note: The simplest use of this function is to encode a string into it's +Quoted-Printable transfer content encoding. +Notice the extra parenthesis around the call to mime.qp, to discard the second return value. +

+ +
+print((mime.qp("ma��")))
+--> ma=E7=E3=
+
+ + + +

+A, m = mime.qpwrp(n [, B, length]) +

+ +

+Low-level filter to break Quoted-Printable text into lines. +

+ +

+A is a copy of B, broken into lines of at most +length bytes (defaults to 76). +'n' should tell how many bytes are left for the first +line of B and 'm' returns the number of bytes +left in the last line of A. +

+ +

+Note: Besides breaking text into lines, this function makes sure the line +breaks don't fall in the middle of an escaped character combination. Also, +this function only breaks lines that are bigger than length bytes. +

+ + + +

+A, B = mime.unb64(C [, D]) +

+ +

+Low-level filter to perform Base64 decoding. +

+ +

+A is the decoded version of the largest prefix of +C..D +that can be decoded unambiguously. B has the remaining bytes of +C..D, before decoding. +If D is nil, A is the empty string +and B returns whatever couldn't be decoded. +

+ +

+Note: The simplest use of this function is to decode a string from it's +Base64 transfer content encoding. +Notice the extra parenthesis around the call to mime.unqp, to discard the second return value. +

+ +
+print((mime.unb64("ZGllZ286cGFzc3dvcmQ=")))
+--> diego:password
+
+ + + +

+A, B = mime.unqp(C [, D]) +

+ +

+Low-level filter to remove the Quoted-Printable transfer content encoding +from data. +

+ +

+A is the decoded version of the largest prefix of +C..D +that can be decoded unambiguously. B has the remaining bytes of +C..D, before decoding. +If D is nil, A is augmented with +the encoding of the remaining bytes of C. +

+ +

+Note: The simplest use of this function is to decode a string from it's +Quoted-Printable transfer content encoding. +Notice the extra parenthesis around the call to mime.unqp, to discard the second return value. +

+ +
+print((mime.qp("ma=E7=E3=")))
+--> ma��
+
+ + + +

+A, m = mime.wrp(n [, B, length]) +

+ +

+Low-level filter to break text into lines with CRLF marker. +Text is assumed to be in the normalize form. +

+ +

+A is a copy of B, broken into lines of at most +length bytes (defaults to 76). +'n' should tell how many bytes are left for the first +line of B and 'm' returns the number of bytes +left in the last line of A. +

+ +

+Note: This function only breaks lines that are bigger than +length bytes. The resulting line length does not include the CRLF +marker. +

+ + + + + + + + diff -Nru luasocket-3.0~rc1+git+ac3201d/docs/reference.css luasocket-3.1.0/docs/reference.css --- luasocket-3.0~rc1+git+ac3201d/docs/reference.css 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/docs/reference.css 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,55 @@ +body { + margin-left: 1em; + margin-right: 1em; + font-family: "Verdana", sans-serif; + background: #ffffff; +} + +tt { + font-family: "Andale Mono", monospace; +} + +h1, h2, h3, h4 { margin-left: 0em; } + + +h3 { padding-top: 1em; } + +p { margin-left: 1em; } + +p.name { + font-family: "Andale Mono", monospace; + padding-top: 1em; + margin-left: 0em; +} + +a[href] { color: #00007f; } + +blockquote { margin-left: 3em; } + +pre.example { + background: #ccc; + padding: 1em; + margin-left: 1em; + font-family: "Andale Mono", monospace; + font-size: small; +} + +hr { + margin-left: 0em; + background: #00007f; + border: 0px; + height: 1px; +} + +ul { list-style-type: disc; } + +table.index { border: 1px #00007f; } +table.index td { text-align: left; vertical-align: top; } +table.index ul { padding-top: 0em; margin-top: 0em; } + +h1:first-letter, +h2:first-letter, +h2:first-letter, +h3:first-letter { color: #00007f; } + +div.header, div.footer { margin-left: 0em; } diff -Nru luasocket-3.0~rc1+git+ac3201d/docs/reference.html luasocket-3.1.0/docs/reference.html --- luasocket-3.0~rc1+git+ac3201d/docs/reference.html 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/docs/reference.html 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,261 @@ + + + + + + +LuaSocket: Index to reference manual + + + + + + + +
+
+
+ + + +
+LuaSocket +
Network support for the Lua language +
+

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

+
+
+
+ + + +

Reference

+ +
+DNS (in socket) +
+getaddrinfo, +gethostname, +tohostname, +toip. +
+
+ + + +
+FTP +
+get, +put. +
+
+ + + +
+HTTP +
+request. +
+
+ + + +
+LTN12 +
+filter: +chain, +cycle. +
+
+pump: +all, +step. +
+
+sink: +chain, +error, +file, +null, +simplify, +table. +
+
+source: +cat, +chain, +empty, +error, +file, +simplify, +string, +table. +
+
+ + + +
+MIME +
+high-level: +decode, +encode, +normalize, +stuff, +wrap. +
+
+low-level: +b64, +dot, +eol, +qp, +qpwrp, +unb64, +unqp, +wrp. +
+
+ + + +
+SMTP +
+message, +send. +
+
+ + + +
+Socket +
+bind, +connect, +connect4, +connect6, +_DATAGRAMSIZE, +_DEBUG, +dns, +gettime, +headers.canonic, +newtry, +protect, +select, +sink, +skip, +sleep, +_SETSIZE, +_SOCKETINVALID, +source, +tcp, +tcp4, +tcp6, +try, +udp, +udp4, +udp6, +_VERSION. +
+
+ + + +
+TCP (in socket) +
+accept, +bind, +close, +connect, +dirty, +getfd, +getoption, +getpeername, +getsockname, +getstats, +gettimeout, +listen, +receive, +send, +setfd, +setoption, +setstats, +settimeout, +shutdown. +
+
+ + + +
+UDP (in socket) +
+close, +getoption, +getpeername, +getsockname, +gettimeout, +receive, +receivefrom, +send, +sendto, +setpeername, +setsockname, +setoption, +settimeout. +
+
+ + + +
+URL +
+absolute, +build, +build_path, +escape, +parse, +parse_path, +unescape. +
+
+ + + + + + + diff -Nru luasocket-3.0~rc1+git+ac3201d/docs/smtp.html luasocket-3.1.0/docs/smtp.html --- luasocket-3.0~rc1+git+ac3201d/docs/smtp.html 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/docs/smtp.html 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,419 @@ + + + + + + +LuaSocket: SMTP support + + + + + + + +
+
+
+ + + +
+LuaSocket +
Network support for the Lua language +
+

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

+
+
+
+ + + +

SMTP

+ +

The smtp namespace provides functionality to send e-mail +messages. The high-level API consists of two functions: one to +define an e-mail message, and another to actually send the message. +Although almost all users will find that these functions provide more than +enough functionality, the underlying implementation allows for even more +control (if you bother to read the code). +

+ +

The implementation conforms to the Simple Mail Transfer Protocol, +RFC 2821. +Another RFC of interest is RFC 2822, +which governs the Internet Message Format. +Multipart messages (those that contain attachments) are part +of the MIME standard, but described mainly +in RFC 2046.

+ +

In the description below, good understanding of LTN012, Filters +sources and sinks and the MIME module is +assumed. In fact, the SMTP module was the main reason for their +creation.

+ +

+To obtain the smtp namespace, run: +

+ +
+-- loads the SMTP module and everything it requires
+local smtp = require("socket.smtp")
+
+ +

+MIME headers are represented as a Lua table in the form: +

+ +
+ + +
+headers = {
+  field-1-name = field-1-value,
+  field-2-name = field-2-value,
+  field-3-name = field-3-value,
+  ...
+  field-n-name = field-n-value
+} +
+
+ +

+Field names are case insensitive (as specified by the standard) and all +functions work with lowercase field names (but see +socket.headers.canonic). +Field values are left unmodified. +

+ +

+Note: MIME headers are independent of order. Therefore, there is no problem +in representing them in a Lua table. +

+ +

+The following constants can be set to control the default behavior of +the SMTP module: +

+ +
    +
  • DOMAIN: domain used to greet the server;
  • +
  • PORT: default port used for the connection;
  • +
  • SERVER: default server used for the connection;
  • +
  • TIMEOUT: default timeout for all I/O operations;
  • +
  • ZONE: default time zone.
  • +
+ + + +

+smtp.message(mesgt) +

+ +

+Returns a simple +LTN12 source that sends an SMTP message body, possibly multipart (arbitrarily deep). +

+ +

+The only parameter of the function is a table describing the message. +Mesgt has the following form (notice the recursive structure): +

+ +
+ + +
+mesgt = {
+  headers = header-table,
+  body = LTN12 source or string or +multipart-mesgt
+}

+multipart-mesgt = {
+  [preamble = string,]
+  [1] = mesgt,
+  [2] = mesgt,
+  ...
+  [n] = mesgt,
+  [epilogue = string,]
+}
+
+
+ +

+For a simple message, all that is needed is a set of headers +and the body. The message body can be given as a string +or as a simple +LTN12 +source. For multipart messages, the body is a table that +recursively defines each part as an independent message, plus an optional +preamble and epilogue. +

+ +

+The function returns a simple +LTN12 +source that produces the +message contents as defined by mesgt, chunk by chunk. +Hopefully, the following +example will make things clear. When in doubt, refer to the appropriate RFC +as listed in the introduction.

+ +
+-- load the smtp support and its friends
+local smtp = require("socket.smtp")
+local mime = require("mime")
+local ltn12 = require("ltn12")
+
+-- 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.
+     from = "Sicrano de Oliveira <sicrano@example.com>",
+     to = "Fulano da Silva <fulano@example.com>",
+     subject = "Here is a message with attachments"
+  },
+  body = {
+    preamble = "If your client doesn't understand attachments, \r\n" ..
+               "it will still display the preamble and the epilogue.\r\n" ..
+               "Preamble will probably appear 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] = {
+      body = mime.eol(0, [[
+        Lines in a message body should always end with CRLF.
+        The smtp module will *NOT* perform translation. However, the
+        send function *DOES* perform SMTP stuffing, whereas the message
+        function does *NOT*.
+      ]])
+    },
+    -- second part: headers describe content to be a png image,
+    -- sent under the base64 transfer content encoding.
+    -- notice that nothing happens until the message is actually sent.
+    -- small chunks are loaded into memory right before transmission and
+    -- translation happens on the fly.
+    [2] = {
+      headers = {
+        ["content-type"] = 'image/png; name="image.png"',
+        ["content-disposition"] = 'attachment; filename="image.png"',
+        ["content-description"] = 'a beautiful image',
+        ["content-transfer-encoding"] = "BASE64"
+      },
+      body = ltn12.source.chain(
+        ltn12.source.file(io.open("image.png", "rb")),
+        ltn12.filter.chain(
+          mime.encode("base64"),
+          mime.wrap()
+        )
+      )
+    },
+    epilogue = "This might also show up, but after the attachments"
+  }
+}
+
+-- finally send it
+r, e = smtp.send{
+    from = "<sicrano@example.com>",
+    rcpt = "<fulano@example.com>",
+    source = source,
+}
+
+ + + + +

+smtp.send{
+  from = string,
+  rcpt = string or string-table,
+  source = LTN12 source,
+  [user = string,]
+  [password = string,]
+  [server = string,]
+  [port = number,]
+  [domain = string,]
+  [step = LTN12 pump step,]
+  [create = function]
+} +

+ +

+Sends a message to a recipient list. Since sending messages is not as +simple as downloading an URL from a FTP or HTTP server, this function +doesn't have a simple interface. However, see the +message source factory for +a very powerful way to define the message contents. +

+ + +

+The sender is given by the e-mail address in the from field. +Rcpt is a Lua table with one entry for each recipient e-mail +address, or a string +in case there is just one recipient. +The contents of the message are given by a simple +LTN12 +source. Several arguments are optional: +

+
    +
  • user, password: User and password for +authentication. The function will attempt LOGIN and PLAIN authentication +methods if supported by the server (both are unsafe);
  • +
  • server: Server to connect to. Defaults to "localhost";
  • +
  • port: Port to connect to. Defaults to 25;
  • +
  • domain: Domain name used to greet the server; Defaults to the +local machine host name;
  • +
  • step: +LTN12 +pump step function used to pass data from the +source to the server. Defaults to the LTN12 pump.step function;
  • +
  • create: An optional function to be used instead of +socket.tcp when the communications socket is created.
  • +
+ +

+If successful, the function returns 1. Otherwise, the function returns +nil followed by an error message. +

+ +

+Note: SMTP servers can be very picky with the format of e-mail +addresses. To be safe, use only addresses of the form +"<fulano@example.com>" in the from and +rcpt arguments to the send function. In headers, e-mail +addresses can take whatever form you like.

+ +

+Big note: There is a good deal of misconception with the use of the +destination address field headers, i.e., the 'To', 'Cc', +and, more importantly, the 'Bcc' headers. Do not add a +'Bcc' header to your messages because it will probably do the +exact opposite of what you expect. +

+ +

+Only recipients specified in the rcpt list will receive a copy of the +message. Each recipient of an SMTP mail message receives a copy of the +message body along with the headers, and nothing more. The headers +are part of the message and should be produced by the +LTN12 +source function. The rcpt list is not +part of the message and will not be sent to anyone. +

+ +

+RFC 2822 +has two important and short sections, "3.6.3. Destination address +fields" and "5. Security considerations", explaining the proper +use of these headers. Here is a summary of what it says: +

+ +
    +
  • To: contains the address(es) of the primary recipient(s) +of the message;
  • +
  • Cc: (where the "Cc" means "Carbon Copy" in the sense of +making a copy on a typewriter using carbon paper) contains the +addresses of others who are to receive the message, though the +content of the message may not be directed at them;
  • +
  • Bcc: (where the "Bcc" means "Blind Carbon +Copy") contains addresses of recipients of the message whose addresses are not +to be revealed to other recipients of the message.
  • +
+ +

+The LuaSocket send function does not care or interpret the +headers you send, but it gives you full control over what is sent and +to whom it is sent: +

+
    +
  • If someone is to receive the message, the e-mail address has +to be in the recipient list. This is the only parameter that controls who +gets a copy of the message;
  • +
  • If there are multiple recipients, none of them will automatically +know that someone else got that message. That is, the default behavior is +similar to the Bcc field of popular e-mail clients;
  • +
  • It is up to you to add the To header with the list of primary +recipients so that other recipients can see it;
  • +
  • It is also up to you to add the Cc header with the +list of additional recipients so that everyone else sees it;
  • +
  • Adding a header Bcc is nonsense, unless it is +empty. Otherwise, everyone receiving the message will see it and that is +exactly what you don't want to happen!
  • +
+ +

+I hope this clarifies the issue. Otherwise, please refer to +RFC 2821 +and +RFC 2822. +

+ +
+-- load the smtp support
+local smtp = require("socket.smtp")
+
+-- Connects to server "localhost" and sends a message to users
+-- "fulano@example.com",  "beltrano@example.com",
+-- and "sicrano@example.com".
+-- Note that "fulano" is the primary recipient, "beltrano" receives a
+-- carbon copy and neither of them knows that "sicrano" received a blind
+-- carbon copy of the message.
+from = "<luasocket@example.com>"
+
+rcpt = {
+  "<fulano@example.com>",
+  "<beltrano@example.com>",
+  "<sicrano@example.com>"
+}
+
+mesgt = {
+  headers = {
+    to = "Fulano da Silva <fulano@example.com>",
+    cc = '"Beltrano F. Nunes" <beltrano@example.com>',
+    subject = "My first message"
+  },
+  body = "I hope this works. If it does, I can send you another 1000 copies."
+}
+
+r, e = smtp.send{
+  from = from,
+  rcpt = rcpt,
+  source = smtp.message(mesgt)
+}
+
+ + + + + + + diff -Nru luasocket-3.0~rc1+git+ac3201d/docs/socket.html luasocket-3.1.0/docs/socket.html --- luasocket-3.0~rc1+git+ac3201d/docs/socket.html 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/docs/socket.html 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,481 @@ + + + + + + +LuaSocket: The socket namespace + + + + + + + +
+
+
+ + + +
+LuaSocket +
Network support for the Lua language +
+

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

+
+
+
+ + + +

The socket namespace

+ +

+The socket namespace contains the core functionality of LuaSocket. +

+ +

+To obtain the socket namespace, run: +

+ +
+-- loads the socket module
+local socket = require("socket")
+
+ + + +

+socket.headers.canonic

+ +

The socket.headers.canonic table +is used by the HTTP and SMTP modules to translate from +lowercase field names back into their canonic +capitalization. When a lowercase field name exists as a key +in this table, the associated value is substituted in +whenever the field name is sent out. +

+ +

+You can obtain the headers namespace if case run-time +modifications are required by running: +

+ +
+-- loads the headers module
+local headers = require("headers")
+
+ + + + +

+socket.bind(address, port [, backlog]) +

+ +

+This function is a shortcut that creates and returns a TCP server object +bound to a local address and port, ready to +accept client connections. Optionally, +user can also specify the backlog argument to the +listen method (defaults to 32). +

+ +

+Note: The server object returned will have the option "reuseaddr" +set to true. +

+ + + +

+socket.connect[46](address, port [, locaddr] [, locport] [, family]) +

+ +

+This function is a shortcut that creates and returns a TCP client object +connected to a remote address at a given port. Optionally, +the user can also specify the local address and port to bind +(locaddr and locport), or restrict the socket family +to "inet" or "inet6". +Without specifying family to connect, whether a tcp or tcp6 +connection is created depends on your system configuration. Two variations +of connect are defined as simple helper functions that restrict the +family, socket.connect4 and socket.connect6. +

+ + + +

+socket._DEBUG +

+ +

+This constant is set to true if the library was compiled +with debug support. +

+ + + +

+socket._DATAGRAMSIZE +

+ +

+Default datagram size used by calls to +receive and +receivefrom. +(Unless changed in compile time, the value is 8192.) +

+ + + +

+socket.gettime() +

+ +

+Returns the UNIX time in seconds. You should subtract the values returned by this function +to get meaningful values. +

+ +
+t = socket.gettime()
+-- do stuff
+print(socket.gettime() - t .. " seconds elapsed")
+
+ + + +

+socket.newtry(finalizer) +

+ +

+Creates and returns a clean +try +function that allows for cleanup before the exception +is raised. +

+ +

+Finalizer is a function that will be called before +try throws the exception. +

+ +

+The function returns your customized try function. +

+ +

+Note: This idea saved a lot of work with the +implementation of protocols in LuaSocket: +

+ +
+foo = socket.protect(function()
+    -- connect somewhere
+    local c = socket.try(socket.connect("somewhere", 42))
+    -- create a try function that closes 'c' on error
+    local try = socket.newtry(function() c:close() end)
+    -- do everything reassured c will be closed
+    try(c:send("hello there?\r\n"))
+    local answer = try(c:receive())
+    ...
+    try(c:send("good bye\r\n"))
+    c:close()
+end)
+
+ + + + +

+socket.protect(func) +

+ +

+Converts a function that throws exceptions into a safe function. This +function only catches exceptions thrown by the try +and newtry functions. It does not catch normal +Lua errors. +

+ +

+Func is a function that calls +try (or assert, or error) +to throw exceptions. +

+ +

+Returns an equivalent function that instead of throwing exceptions in case of +a failed try call, returns nil +followed by an error message. +

+ + + +

+socket.select(recvt, sendt [, timeout]) +

+ +

+Waits for a number of sockets to change status. +

+ +

+Recvt is an array with the sockets to test for characters +available for reading. Sockets in the sendt array are watched to +see if it is OK to immediately write on them. Timeout is the +maximum amount of time (in seconds) to wait for a change in status. A +nil, negative or omitted timeout value allows the +function to block indefinitely. Recvt and sendt can also +be empty tables or nil. Non-socket values (or values with +non-numeric indices) in the arrays will be silently ignored. +

+ +

The function returns a list with the sockets ready for +reading, a list with the sockets ready for writing and an error message. +The error message is "timeout" if a timeout +condition was met, "select failed" if the call +to select failed, and +nil otherwise. The returned tables are +doubly keyed both by integers and also by the sockets +themselves, to simplify the test if a specific socket has +changed status. +

+ +

+Note: select can monitor a limited number +of sockets, as defined by the constant +socket._SETSIZE. This +number may be as high as 1024 or as low as 64 by default, +depending on the system. It is usually possible to change this +at compile time. Invoking select with a larger +number of sockets will raise an error. +

+ +

+Important note: a known bug in WinSock causes select to fail +on non-blocking TCP sockets. The function may return a socket as +writable even though the socket is not ready for sending. +

+ +

+Another important note: calling select with a server socket in the receive parameter before a call to accept does not guarantee +accept will return immediately. +Use the settimeout +method or accept might block forever. +

+ +

+Yet another note: If you close a socket and pass +it to select, it will be ignored. +

+ +

+Using select with non-socket objects: Any object that implements getfd and dirty can be used with select, allowing objects from other libraries to be used within a socket.select driven loop. +

+ + + +

+socket._SETSIZE +

+ +

+The maximum number of sockets that the select function can handle. +

+ + + + +

+socket.sink(mode, socket) +

+ +

+Creates an +LTN12 +sink from a stream socket object. +

+ +

+Mode defines the behavior of the sink. The following +options are available: +

+
    +
  • "http-chunked": sends data through socket after applying the +chunked transfer coding, closing the socket when done;
  • +
  • "close-when-done": sends all received data through the +socket, closing the socket when done;
  • +
  • "keep-open": sends all received data through the +socket, leaving it open when done.
  • +
+

+Socket is the stream socket object used to send the data. +

+ +

+The function returns a sink with the appropriate behavior. +

+ + + +

+socket.skip(d [, ret1, ret2 ... retN]) +

+ +

+Drops a number of arguments and returns the remaining. +

+ +

+D is the number of arguments to drop. Ret1 to +retN are the arguments. +

+ +

+The function returns retd+1 to retN. +

+ +

+Note: This function is useful to avoid creation of dummy variables: +

+ +
+-- get the status code and separator from SMTP server reply
+local code, sep = socket.skip(2, string.find(line, "^(%d%d%d)(.?)"))
+
+ + + +

+socket.sleep(time) +

+ +

+Freezes the program execution during a given amount of time. +

+ +

+Time is the number of seconds to sleep for. If +time is negative, the function returns immediately. +

+ + + +

+socket.source(mode, socket [, length]) +

+ +

+Creates an +LTN12 +source from a stream socket object. +

+ +

+Mode defines the behavior of the source. The following +options are available: +

+
    +
  • "http-chunked": receives data from socket and removes the +chunked transfer coding before returning the data;
  • +
  • "by-length": receives a fixed number of bytes from the +socket. This mode requires the extra argument length;
  • +
  • "until-closed": receives data from a socket until the other +side closes the connection.
  • +
+

+Socket is the stream socket object used to receive the data. +

+ +

+The function returns a source with the appropriate behavior. +

+ + + +

+socket._SOCKETINVALID +

+ +

+The OS value for an invalid socket. This can be used with +tcp:getfd and tcp:setfd methods. +

+ + + +

+socket.try(ret1 [, ret2 ... retN]) +

+ +

+Throws an exception in case ret1 is falsy, using +ret2 as the error message. The exception is supposed to be caught +by a protected function only. +

+ +

+Ret1 to retN can be arbitrary +arguments, but are usually the return values of a function call +nested with try. +

+ +

+The function returns ret1 to retN if +ret1 is not nil or false. +Otherwise, it calls error passing ret2 wrapped +in a table with metatable used by protect to +distinguish exceptions from runtime errors. +

+ +
+-- connects or throws an exception with the appropriate error message
+c = socket.try(socket.connect("localhost", 80))
+
+ + + +

+socket._VERSION +

+ +

+This constant has a string describing the current LuaSocket version. +

+ + + + + + + diff -Nru luasocket-3.0~rc1+git+ac3201d/docs/tcp.html luasocket-3.1.0/docs/tcp.html --- luasocket-3.0~rc1+git+ac3201d/docs/tcp.html 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/docs/tcp.html 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,738 @@ + + + + + + +LuaSocket: TCP/IP support + + + + + + + +
+
+
+ + + +
+LuaSocket +
Network support for the Lua language +
+

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

+
+
+
+ + + +

TCP

+ + + +

+server:accept() +

+ +

+Waits for a remote connection on the server +object and returns a client object representing that connection. +

+ +

+If a connection is successfully initiated, a client object is returned. +If a timeout condition is met, the method returns nil +followed by the error string 'timeout'. Other errors are +reported by nil followed by a message describing the error. +

+ +

+Note: calling socket.select +with a server object in +the recvt parameter before a call to accept does +not guarantee accept will return immediately. Use the settimeout method or accept +might block until another client shows up. +

+ + + +

+master:bind(address, port) +

+ +

+Binds a master object to address and port on the +local host. +

+ +

+Address can be an IP address or a host name. +Port must be an integer number in the range [0..64K). +If address +is '*', the system binds to all local interfaces +using the INADDR_ANY constant or +IN6ADDR_ANY_INIT, according to the family. +If port is 0, the system automatically +chooses an ephemeral port. +

+ +

+In case of success, the method returns 1. In case of error, the +method returns nil followed by an error message. +

+ +

+Note: The function socket.bind +is available and is a shortcut for the creation of server sockets. +

+ + + +

+master:close()
+client:close()
+server:close() +

+ +

+Closes a TCP object. The internal socket used by the object is closed +and the local address to which the object was +bound is made available to other applications. No further operations +(except for further calls to the close method) are allowed on +a closed socket. +

+ +

+Note: It is important to close all used sockets once they are not +needed, since, in many systems, each socket uses a file descriptor, +which are limited system resources. Garbage-collected objects are +automatically closed before destruction, though. +

+ + + +

+master:connect(address, port) +

+ +

+Attempts to connect a master object to a remote host, transforming it into a +client object. +Client objects support methods +send, +receive, +getsockname, +getpeername, +settimeout, +and close. +

+ +

+Address can be an IP address or a host name. +Port must be an integer number in the range [1..64K). +

+ +

+In case of error, the method returns nil followed by a string +describing the error. In case of success, the method returns 1. +

+ +

+Note: The function socket.connect +is available and is a shortcut for the creation of client sockets. +

+ +

+Note: Starting with LuaSocket 2.0, +the settimeout +method affects the behavior of connect, causing it to return +with an error in case of a timeout. If that happens, you can still call socket.select with the socket in the +sendt table. The socket will be writable when the connection is +established. +

+ +

+Note: Starting with LuaSocket 3.0, the host name resolution +depends on whether the socket was created by +socket.tcp, +socket.tcp4 or +socket.tcp6. Addresses from +the appropriate family (or both) are tried in the order +returned by the resolver until the +first success or until the last failure. If the timeout was +set to zero, only the first address is tried. +

+ + + +

+master:dirty()
+client:dirty()
+server:dirty() +

+ +

+Check the read buffer status. +

+ +

+Returns true if there is any data in the read buffer, false otherwise. +

+ +

+Note: This is an internal method, use at your own risk. +

+ + + + +

+master:getfd()
+client:getfd()
+server:getfd() +

+ +

+Returns the underling socket descriptor or handle associated to the object. +

+ +

+The descriptor or handle. In case the object has been closed, the return value +will be -1. For an invalid socket it will be +_SOCKETINVALID. +

+ +

+Note: This is an internal method. Unlikely to be +portable. Use at your own risk. +

+ + + + +

+client:getoption(option)
+server:getoption(option) +

+ +

+Gets options for the TCP object. +See setoption for description of the +option names and values. +

+ +

+Option is a string with the option name.

+
    +
  • 'keepalive'
  • +
  • 'linger'
  • +
  • 'reuseaddr'
  • +
  • 'tcp-nodelay'
  • +
+ +

+The method returns the option value in case of success, or +nil followed by an error message otherwise. +

+ + + + +

+client:getpeername() +

+ +

+Returns information about the remote side of a connected client object. +

+ +

+Returns a string with the IP address of the peer, the +port number that peer is using for the connection, +and a string with the family ("inet" or "inet6"). +In case of error, the method returns nil. +

+ +

+Note: It makes no sense to call this method on server objects. +

+ + + +

+master:getsockname()
+client:getsockname()
+server:getsockname() +

+ +

+Returns the local address information associated to the object. +

+ +

+The method returns a string with local IP address, a number with +the local port, +and a string with the family ("inet" or "inet6"). +In case of error, the method returns nil. +

+ + + +

+master:getstats()
+client:getstats()
+server:getstats()
+

+ +

+Returns accounting information on the socket, useful for throttling +of bandwidth. +

+ +

+The method returns the number of bytes received, the number of bytes sent, +and the age of the socket object in seconds. +

+ + + +

+master:gettimeout()
+client:gettimeout()
+server:gettimeout() +

+ +

+Returns the current block timeout followed by the curent +total timeout. +

+ + + + +

+master:listen(backlog) +

+ +

+Specifies the socket is willing to receive connections, transforming the +object into a server object. Server objects support the +accept, +getsockname, +setoption, +settimeout, +and close methods. +

+ +

+The parameter backlog specifies the number of client +connections that can +be queued waiting for service. If the queue is full and another client +attempts connection, the connection is refused. +

+ +

+In case of success, the method returns 1. In case of error, the +method returns nil followed by an error message. +

+ + + +

+client:receive([pattern [, prefix]]) +

+ +

+Reads data from a client object, according to the specified read +pattern. Patterns follow the Lua file I/O format, and the difference in performance between all patterns is negligible. +

+ +

+Pattern can be any of the following: +

+ +
    +
  • '*a': reads from the socket until the connection is +closed. No end-of-line translation is performed;
  • +
  • '*l': reads a line of text from the socket. The line is +terminated by a LF character (ASCII 10), optionally preceded by a +CR character (ASCII 13). The CR and LF characters are not included in +the returned line. In fact, all CR characters are +ignored by the pattern. This is the default pattern;
  • +
  • number: causes the method to read a specified number +of bytes from the socket.
  • +
+ +

+Prefix is an optional string to be concatenated to the beginning +of any received data before return. +

+ +

+If successful, the method returns the received pattern. In case of error, +the method returns nil followed by an error +message, followed by a (possibly empty) string containing +the partial that was received. The error message can be +the string 'closed' in case the connection was +closed before the transmission was completed or the string +'timeout' in case there was a timeout during the operation. +

+ +

+Important note: This function was changed severely. It used +to support multiple patterns (but I have never seen this feature used) and +now it doesn't anymore. Partial results used to be returned in the same +way as successful results. This last feature violated the idea that all +functions should return nil on error. Thus it was changed +too. +

+ + + +

+client:send(data [, i [, j]]) +

+ +

+Sends data through client object. +

+ +

+Data is the string to be sent. The optional arguments +i and j work exactly like the standard +string.sub Lua function to allow the selection of a +substring to be sent. +

+ +

+If successful, the method returns the index of the last byte +within [i, j] that has been sent. Notice that, if +i is 1 or absent, this is effectively the total +number of bytes sent. In case of error, the method returns +nil, followed by an error message, followed +by the index of the last byte within [i, j] that +has been sent. You might want to try again from the byte +following that. The error message can be 'closed' +in case the connection was closed before the transmission +was completed or the string 'timeout' in case +there was a timeout during the operation. +

+ +

+Note: Output is not buffered. For small strings, +it is always better to concatenate them in Lua +(with the '..' operator) and send the result in one call +instead of calling the method several times. +

+ + + +

+client:setoption(option [, value])
+server:setoption(option [, value]) +

+ +

+Sets options for the TCP object. Options are only needed by low-level or +time-critical applications. You should only modify an option if you +are sure you need it. +

+ +

+Option is a string with the option name, and value +depends on the option being set:

+ +
    + +
  • 'keepalive': Setting this option to true enables +the periodic transmission of messages on a connected socket. Should the +connected party fail to respond to these messages, the connection is +considered broken and processes using the socket are notified;
  • + +
  • 'linger': Controls the action taken when unsent data are +queued on a socket and a close is performed. The value is a table with a +boolean entry 'on' and a numeric entry for the time interval +'timeout' in seconds. If the 'on' field is set to +true, the system will block the process on the close attempt until +it is able to transmit the data or until 'timeout' has passed. If +'on' is false and a close is issued, the system will +process the close in a manner that allows the process to continue as +quickly as possible. I do not advise you to set this to anything other than +zero;
  • + +
  • 'reuseaddr': Setting this option indicates that the rules +used in validating addresses supplied in a call to +bind should allow reuse of local addresses;
  • + +
  • 'tcp-nodelay': Setting this option to true +disables the Nagle's algorithm for the connection;
  • + +
  • 'tcp-keepidle': value in seconds for TCP_KEEPIDLE Linux only!!
  • + +
  • 'tcp-keepcnt': value for TCP_KEEPCNT Linux only!!
  • + +
  • 'tcp-keepintvl': value for TCP_KEEPINTVL Linux only!!
  • + +
  • 'tcp-defer-accept': value for TCP_DEFER_ACCEPT Linux only!!
  • + +
  • 'tcp-fastopen': value for TCP_FASTOPEN Linux only!!
  • + +
  • 'tcp-fastopen-connect': value for TCP_FASTOPEN_CONNECT Linux only!!
  • + +
  • 'ipv6-v6only': +Setting this option to true restricts an inet6 socket to +sending and receiving only IPv6 packets.
  • +
+ +

+The method returns 1 in case of success, or nil +followed by an error message otherwise. +

+ +

+Note: The descriptions above come from the man pages. +

+ + + +

+master:setstats(received, sent, age)
+client:setstats(received, sent, age)
+server:setstats(received, sent, age)
+

+ +

+Resets accounting information on the socket, useful for throttling +of bandwidth. +

+ +

+Received is a number with the new number of bytes received. +Sent is a number with the new number of bytes sent. +Age is the new age in seconds. +

+ +

+The method returns 1 in case of success and nil otherwise. +

+ + + +

+master:settimeout(value [, mode])
+client:settimeout(value [, mode])
+server:settimeout(value [, mode]) +

+ +

+Changes the timeout values for the object. By default, +all I/O operations are blocking. That is, any call to the methods +send, +receive, and +accept +will block indefinitely, until the operation completes. The +settimeout method defines a limit on the amount of time the +I/O methods can block. When a timeout is set and the specified amount of +time has elapsed, the affected methods give up and fail with an error code. +

+ +

+The amount of time to wait is specified as the +value parameter, in seconds. There are two timeout modes and +both can be used together for fine tuning: +

+ +
    +
  • 'b': block timeout. Specifies the upper limit on +the amount of time LuaSocket can be blocked by the operating system +while waiting for completion of any single I/O operation. This is the +default mode;
  • + +
  • 't': total timeout. Specifies the upper limit on +the amount of time LuaSocket can block a Lua script before returning from +a call.
  • +
+ +

+The nil timeout value allows operations to block +indefinitely. Negative timeout values have the same effect. +

+ +

+Note: although timeout values have millisecond precision in LuaSocket, +large blocks can cause I/O functions not to respect timeout values due +to the time the library takes to transfer blocks to and from the OS +and to and from the Lua interpreter. Also, function that accept host names +and perform automatic name resolution might be blocked by the resolver for +longer than the specified timeout value. +

+ +

+Note: The old timeout method is deprecated. The name has been +changed for sake of uniformity, since all other method names already +contained verbs making their imperative nature obvious. +

+ + + +

+client:shutdown(mode)
+

+ +

+Shuts down part of a full-duplex connection. +

+ +

+Mode tells which way of the connection should be shut down and can +take the value: +

    +
  • "both": disallow further sends and receives on the object. +This is the default mode;
  • +
  • "send": disallow further sends on the object;
  • +
  • "receive": disallow further receives on the object.
  • +
+

+ +

+This function returns 1. +

+ + + +

+master:setfd(fd)
+client:setfd(fd)
+server:setfd(fd) +

+ +

+Sets the underling socket descriptor or handle associated to the object. The current one +is simply replaced, not closed, and no other change to the object state is made. +To set it as invalid use _SOCKETINVALID. +

+ +

+No return value. +

+ +

+Note: This is an internal method. Unlikely to be +portable. Use at your own risk. +

+ + + +

+socket.tcp() +

+ +

+Creates and returns an TCP master object. A master object can +be transformed into a server object with the method +listen (after a call to bind) or into a client object with +the method connect. The only other +method supported by a master object is the +close method.

+ +

+In case of success, a new master object is returned. In case of error, +nil is returned, followed by an error message. +

+ +

+Note: The choice between IPv4 and IPv6 happens during a call to +bind or connect, depending on the address +family obtained from the resolver. +

+ +

+Note: Before the choice between IPv4 and IPv6 happens, +the internal socket object is invalid and therefore setoption will fail. +

+ + + +

+socket.tcp4() +

+ +

+Creates and returns an IPv4 TCP master object. A master object can +be transformed into a server object with the method +listen (after a call to bind) or into a client object with +the method connect. The only other +method supported by a master object is the +close method.

+ +

+In case of success, a new master object is returned. In case of error, +nil is returned, followed by an error message. +

+ + + +

+socket.tcp6() +

+ +

+Creates and returns an IPv6 TCP master object. A master object can +be transformed into a server object with the method +listen (after a call to bind) or into a client object with +the method connect. The only other +method supported by a master object is the +close method.

+ +

+In case of success, a new master object is returned. In case of error, +nil is returned, followed by an error message. +

+ +

+Note: The TCP object returned will have the option +"ipv6-v6only" set to true. +

+ + + + + + + + + diff -Nru luasocket-3.0~rc1+git+ac3201d/docs/udp.html luasocket-3.1.0/docs/udp.html --- luasocket-3.0~rc1+git+ac3201d/docs/udp.html 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/docs/udp.html 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,596 @@ + + + + + + +LuaSocket: UDP support + + + + + + + +
+
+
+ + + +
+LuaSocket +
Network support for the Lua language +
+

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

+
+
+
+ + + + +

UDP

+ + + +

+connected:close()
+unconnected:close() +

+ +

+Closes a UDP object. The internal socket +used by the object is closed and the local address to which the +object was bound is made available to other applications. No +further operations (except for further calls to the close +method) are allowed on a closed socket. +

+ +

+Note: It is important to close all used sockets +once they are not needed, since, in many systems, each socket uses +a file descriptor, which are limited system resources. +Garbage-collected objects are automatically closed before +destruction, though. +

+ + + +

+connected:getoption()
+unconnected:getoption() +

+ +

+Gets an option value from the UDP object. +See setoption for +description of the option names and values. +

+ +

Option is a string with the option name. +

    +
  • 'dontroute'
  • +
  • 'broadcast'
  • +
  • 'reuseaddr'
  • +
  • 'reuseport'
  • +
  • 'ip-multicast-loop'
  • +
  • 'ipv6-v6only'
  • +
  • 'ip-multicast-if'
  • +
  • 'ip-multicast-ttl'
  • +
  • 'ip-add-membership'
  • +
  • 'ip-drop-membership'
  • +
+

+ +

+The method returns the option value in case of +success, or +nil followed by an error message otherwise. +

+ + + +

+connected:getpeername() +

+ +

+Retrieves information about the peer +associated with a connected UDP object. +

+ + +

+Returns a string with the IP address of the peer, the +port number that peer is using for the connection, +and a string with the family ("inet" or "inet6"). +In case of error, the method returns nil. +

+ +

+Note: It makes no sense to call this method on unconnected objects. +

+ + + +

+connected:getsockname()
+unconnected:getsockname() +

+ +

+Returns the local address information associated to the object. +

+ + +

+The method returns a string with local IP address, a number with +the local port, +and a string with the family ("inet" or "inet6"). +In case of error, the method returns nil. +

+ +

+Note: UDP sockets are not bound to any address +until the setsockname or the +sendto method is called for the +first time (in which case it is bound to an ephemeral port and the +wild-card address). +

+ + + +

+connected:settimeout(value)
+unconnected:settimeout(value) +

+ +

+Returns the current timeout value. +

+ + + + +

+connected:receive([size])
+unconnected:receive([size]) +

+ +

+Receives a datagram from the UDP object. If +the UDP object is connected, only datagrams coming from the peer +are accepted. Otherwise, the returned datagram can come from any +host. +

+ +

+The optional size parameter +specifies the maximum size of the datagram to be retrieved. If +there are more than size bytes available in the datagram, +the excess bytes are discarded. If there are less then +size bytes available in the current datagram, the +available bytes are returned. +If size is omitted, the +compile-time constant +socket._DATAGRAMSIZE is used +(it defaults to 8192 bytes). Larger sizes will cause a +temporary buffer to be allocated for the operation. +

+ +

+In case of success, the method returns the +received datagram. In case of timeout, the method returns +nil followed by the string 'timeout'. +

+ + + +

+unconnected:receivefrom([size]) +

+ +

+Works exactly as the receive +method, except it returns the IP +address and port as extra return values (and is therefore slightly less +efficient). +

+ + + +

+connected:send(datagram) +

+ +

+Sends a datagram to the UDP peer of a connected object. +

+ +

+Datagram is a string with the datagram contents. +The maximum datagram size for UDP is 64K minus IP layer overhead. +However datagrams larger than the link layer packet size will be +fragmented, which may deteriorate performance and/or reliability. +

+ +

+If successful, the method returns 1. In case of +error, the method returns nil followed by an error message. +

+ +

+Note: In UDP, the send method never blocks +and the only way it can fail is if the underlying transport layer +refuses to send a message to the specified address (i.e. no +interface accepts the address). +

+ + + +

+unconnected:sendto(datagram, ip, port) +

+ +

+Sends a datagram to the specified IP address and port number. +

+ +

+Datagram is a string with the +datagram contents. +The maximum datagram size for UDP is 64K minus IP layer overhead. +However datagrams larger than the link layer packet size will be +fragmented, which may deteriorate performance and/or reliability. +Ip is the IP address of the recipient. +Host names are not allowed for performance reasons. + +Port is the port number at the recipient. +

+ +

+If successful, the method returns 1. In case of +error, the method returns nil followed by an error message. +

+ +

+Note: In UDP, the send method never blocks +and the only way it can fail is if the underlying transport layer +refuses to send a message to the specified address (i.e. no +interface accepts the address). +

+ + + +

+connected:setoption(option [, value])
+unconnected:setoption(option [, value]) +

+ +

+Sets options for the UDP object. Options are +only needed by low-level or time-critical applications. You should +only modify an option if you are sure you need it.

+

Option is a string with the option +name, and value depends on the option being set: +

+ +
    +
  • 'dontroute': Indicates that outgoing +messages should bypass the standard routing facilities. +Receives a boolean value;
  • +
  • 'broadcast': Requests permission to send +broadcast datagrams on the socket. +Receives a boolean value;
  • +
  • 'reuseaddr': Indicates that the rules used in +validating addresses supplied in a bind() call +should allow reuse of local addresses. +Receives a boolean value;
  • +
  • 'reuseport': Allows completely duplicate +bindings by multiple processes if they all set +'reuseport' before binding the port. +Receives a boolean value;
  • +
  • 'ip-multicast-loop': +Specifies whether or not a copy of an outgoing multicast +datagram is delivered to the sending host as long as it is a +member of the multicast group. +Receives a boolean value;
  • +
  • 'ipv6-v6only': +Specifies whether to restrict inet6 sockets to +sending and receiving only IPv6 packets. +Receive a boolean value;
  • +
  • 'ip-multicast-if': +Sets the interface over which outgoing multicast datagrams +are sent. +Receives an IP address;
  • +
  • 'ip-multicast-ttl': +Sets the Time To Live in the IP header for outgoing +multicast datagrams. +Receives a number;
  • +
  • 'ip-add-membership': +Joins the multicast group specified. +Receives a table with fields +multiaddr and interface, each containing an +IP address;
  • +
  • 'ip-drop-membership': Leaves the multicast +group specified. +Receives a table with fields +multiaddr and interface, each containing an +IP address.
  • +
+ +

+The method returns 1 in case of success, or +nil followed by an error message otherwise. +

+ +

+Note: The descriptions above come from the man pages. +

+ + + + +

+connected:setpeername('*')
+unconnected:setpeername(address, port) +

+ +

+Changes the peer of a UDP object. This +method turns an unconnected UDP object into a connected UDP +object or vice versa. +

+ +

+For connected objects, outgoing datagrams +will be sent to the specified peer, and datagrams received from +other peers will be discarded by the OS. Connected UDP objects must +use the send and +receive methods instead of +sendto and +receivefrom. +

+ +

+Address can be an IP address or a +host name. Port is the port number. If address is +'*' and the object is connected, the peer association is +removed and the object becomes an unconnected object again. In that +case, the port argument is ignored. +

+ +

+In case of error the method returns +nil followed by an error message. In case of success, the +method returns 1. +

+ +

+Note: Since the address of the peer does not have +to be passed to and from the OS, the use of connected UDP objects +is recommended when the same peer is used for several transmissions +and can result in up to 30% performance gains. +

+ +

+Note: Starting with LuaSocket 3.0, the host name resolution +depends on whether the socket was created by socket.udp or socket.udp6. Addresses from +the appropriate family are tried in succession until the +first success or until the last failure. +

+ + + +

+unconnected:setsockname(address, port) +

+ +

+Binds the UDP object to a local address. +

+ +

+Address can be an IP address or a +host name. If address is '*' the system binds to +all local interfaces using the constant INADDR_ANY. If +port is 0, the system chooses an ephemeral port. +

+ +

+If successful, the method returns 1. In case of +error, the method returns nil followed by an error +message. +

+ +

+Note: This method can only be called before any +datagram is sent through the UDP object, and only once. Otherwise, +the system automatically binds the object to all local interfaces +and chooses an ephemeral port as soon as the first datagram is +sent. After the local address is set, either automatically by the +system or explicitly by setsockname, it cannot be +changed. +

+ + + +

+connected:settimeout(value)
+unconnected:settimeout(value) +

+ +

+Changes the timeout values for the object. By default, the +receive and +receivefrom +operations are blocking. That is, any call to the methods will block +indefinitely, until data arrives. The settimeout function defines +a limit on the amount of time the functions can block. When a timeout is +set and the specified amount of time has elapsed, the affected methods +give up and fail with an error code. +

+ +

+The amount of time to wait is specified as +the value parameter, in seconds. The nil timeout +value allows operations to block indefinitely. Negative +timeout values have the same effect. +

+ +

+Note: In UDP, the send +and sendto methods never block (the +datagram is just passed to the OS and the call returns +immediately). Therefore, the settimeout method has no +effect on them. +

+ +

+Note: The old timeout method is +deprecated. The name has been changed for sake of uniformity, since +all other method names already contained verbs making their +imperative nature obvious. +

+ + + +

+socket.udp() +

+ +

+Creates and returns an unconnected UDP object. +Unconnected objects support the +sendto, +receive, +receivefrom, +getoption, +getsockname, +setoption, +settimeout, +setpeername, +setsockname, and +close. +The setpeername +is used to connect the object. +

+ +

+In case of success, a new unconnected UDP object +returned. In case of error, nil is returned, followed by +an error message. +

+ +

+Note: The choice between IPv4 and IPv6 happens during a call to +sendto, setpeername, or sockname, depending on the address +family obtained from the resolver. +

+ +

+Note: Before the choice between IPv4 and IPv6 happens, +the internal socket object is invalid and therefore setoption will fail. +

+ + + +

+socket.udp4() +

+ +

+Creates and returns an unconnected IPv4 UDP object. +Unconnected objects support the +sendto, +receive, +receivefrom, +getoption, +getsockname, +setoption, +settimeout, +setpeername, +setsockname, and +close. +The setpeername +is used to connect the object. +

+ +

+In case of success, a new unconnected UDP object +returned. In case of error, nil is returned, followed by +an error message. +

+ + + +

+socket.udp6() +

+ +

+Creates and returns an unconnected IPv6 UDP object. +Unconnected objects support the +sendto, +receive, +receivefrom, +getoption, +getsockname, +setoption, +settimeout, +setpeername, +setsockname, and +close. +The setpeername +is used to connect the object. +

+ +

+In case of success, a new unconnected UDP object +returned. In case of error, nil is returned, followed by +an error message. +

+ +

+Note: The TCP object returned will have the option +"ipv6-v6only" set to true. +

+ + + + + + + + + diff -Nru luasocket-3.0~rc1+git+ac3201d/docs/url.html luasocket-3.1.0/docs/url.html --- luasocket-3.0~rc1+git+ac3201d/docs/url.html 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/docs/url.html 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,328 @@ + + + + + + +LuaSocket: URL support + + + + + + + +
+
+
+ + + +
+LuaSocket +
Network support for the Lua language +
+

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

+
+
+
+ + + +

URL

+ +

+The url namespace provides functions to parse, protect, +and build URLs, as well as functions to compose absolute URLs +from base and relative URLs, according to +RFC 2396. +

+ +

+To obtain the url namespace, run: +

+ +
+-- loads the URL module 
+local url = require("socket.url")
+
+ +

+An URL is defined by the following grammar: +

+ +
+ +<url> ::= [<scheme>:][//<authority>][/<path>][;<params>][?<query>][#<fragment>]
+<authority> ::= [<userinfo>@]<host>[:<port>]
+<userinfo> ::= <user>[:<password>]
+<path> ::= {<segment>/}<segment>
+
+
+ + + +

+url.absolute(base, relative) +

+ +

+Builds an absolute URL from a base URL and a relative URL. +

+ +

+Base is a string with the base URL or +a parsed URL table. Relative is a +string with the relative URL. +

+ +

+The function returns a string with the absolute URL. +

+ +

+Note: The rules that +govern the composition are fairly complex, and are described in detail in +RFC 2396. +The example bellow should give an idea of what the rules are. +

+ +
+http://a/b/c/d;p?q
+
++
+
+g:h      =  g:h
+g        =  http://a/b/c/g
+./g      =  http://a/b/c/g
+g/       =  http://a/b/c/g/
+/g       =  http://a/g
+//g      =  http://g
+?y       =  http://a/b/c/?y
+g?y      =  http://a/b/c/g?y
+#s       =  http://a/b/c/d;p?q#s
+g#s      =  http://a/b/c/g#s
+g?y#s    =  http://a/b/c/g?y#s
+;x       =  http://a/b/c/;x
+g;x      =  http://a/b/c/g;x
+g;x?y#s  =  http://a/b/c/g;x?y#s
+.        =  http://a/b/c/
+./       =  http://a/b/c/
+..       =  http://a/b/
+../      =  http://a/b/
+../g     =  http://a/b/g
+../..    =  http://a/
+../../   =  http://a/
+../../g  =  http://a/g
+
+ + + +

+url.build(parsed_url) +

+ +

+Rebuilds an URL from its parts. +

+ +

+Parsed_url is a table with same components returned by +parse. +Lower level components, if specified, +take precedence over high level components of the URL grammar. +

+ +

+The function returns a string with the built URL. +

+ + + +

+url.build_path(segments, unsafe) +

+ +

+Builds a <path> component from a list of +<segment> parts. +Before composition, any reserved characters found in a segment are escaped into +their protected form, so that the resulting path is a valid URL path +component. +

+ +

+Segments is a list of strings with the <segment> +parts. If unsafe is anything but nil, reserved +characters are left untouched. +

+ +

+The function returns a string with the +built <path> component. +

+ + + +

+url.escape(content) +

+ +

+Applies the URL escaping content coding to a string +Each byte is encoded as a percent character followed +by the two byte hexadecimal representation of its integer +value. +

+ +

+Content is the string to be encoded. +

+ +

+The function returns the encoded string. +

+ +
+-- load url module
+url = require("socket.url")
+
+code = url.escape("/#?;")
+-- code = "%2f%23%3f%3b"
+
+ + + +

+url.parse(url, default) +

+ +

+Parses an URL given as a string into a Lua table with its components. +

+ +

+Url is the URL to be parsed. If the default table is +present, it is used to store the parsed fields. Only fields present in the +URL are overwritten. Therefore, this table can be used to pass default +values for each field. +

+ +

+The function returns a table with all the URL components: +

+ +
+parsed_url = {
+  url = string,
+  scheme = string,
+  authority = string,
+  path = string,
+  params = string,
+  query = string,
+  fragment = string,
+  userinfo = string,
+  host = string,
+  port = string,
+  user = string,
+  password = string
+} +
+ +
+-- load url module
+url = require("socket.url")
+
+parsed_url = url.parse("http://www.example.com/cgilua/index.lua?a=2#there")
+-- parsed_url = {
+--   scheme = "http",
+--   authority = "www.example.com",
+--   path = "/cgilua/index.lua"
+--   query = "a=2",
+--   fragment = "there",
+--   host = "www.puc-rio.br",
+-- }
+
+parsed_url = url.parse("ftp://root:passwd@unsafe.org/pub/virus.exe;type=i")
+-- parsed_url = {
+--   scheme = "ftp",
+--   authority = "root:passwd@unsafe.org",
+--   path = "/pub/virus.exe",
+--   params = "type=i",
+--   userinfo = "root:passwd",
+--   host = "unsafe.org",
+--   user = "root",
+--   password = "passwd",
+-- }
+
+ + + +

+url.parse_path(path) +

+ +

+Breaks a <path> URL component into all its +<segment> parts. +

+ +

+Path is a string with the path to be parsed. +

+ +

+Since some characters are reserved in URLs, they must be escaped +whenever present in a <path> component. Therefore, before +returning a list with all the parsed segments, the function removes +escaping from all of them. +

+ + + +

+url.unescape(content) +

+ +

+Removes the URL escaping content coding from a string. +

+ +

+Content is the string to be decoded. +

+ +

+The function returns the decoded string. +

+ + + + + + + diff -Nru luasocket-3.0~rc1+git+ac3201d/.editorconfig luasocket-3.1.0/.editorconfig --- luasocket-3.0~rc1+git+ac3201d/.editorconfig 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/.editorconfig 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,23 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +charset = utf-8 + +[{*.lua,*.rockspec,.luacheckrc}] +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 diff -Nru luasocket-3.0~rc1+git+ac3201d/etc/cookie.lua luasocket-3.1.0/etc/cookie.lua --- luasocket-3.0~rc1+git+ac3201d/etc/cookie.lua 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/etc/cookie.lua 2022-08-11 13:08:58.000000000 +0000 @@ -5,7 +5,7 @@ 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 @@ 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 @@ -- 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 @@ 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 @@ end if i < #cookies then s = s .. ", " end end - return s + return s end diff -Nru luasocket-3.0~rc1+git+ac3201d/etc/get.lua luasocket-3.1.0/etc/get.lua --- luasocket-3.0~rc1+git+ac3201d/etc/get.lua 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/etc/get.lua 2022-08-11 13:08:58.000000000 +0000 @@ -71,7 +71,7 @@ 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 -Nru luasocket-3.0~rc1+git+ac3201d/gem/ex11.lua luasocket-3.1.0/gem/ex11.lua --- luasocket-3.0~rc1+git+ac3201d/gem/ex11.lua 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/gem/ex11.lua 2022-08-11 13:08:58.000000000 +0000 @@ -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 -Nru luasocket-3.0~rc1+git+ac3201d/gem/ex3.lua luasocket-3.1.0/gem/ex3.lua --- luasocket-3.0~rc1+git+ac3201d/gem/ex3.lua 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/gem/ex3.lua 2022-08-11 13:08:58.000000000 +0000 @@ -7,7 +7,7 @@ end function filter.chain(...) - local f = select(1, ...) + local f = select(1, ...) for i = 2, select('#', ...) do f = chainpair(f, select(i, ...)) end diff -Nru luasocket-3.0~rc1+git+ac3201d/gem/ex4.lua luasocket-3.1.0/gem/ex4.lua --- luasocket-3.0~rc1+git+ac3201d/gem/ex4.lua 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/gem/ex4.lua 2022-08-11 13:08:58.000000000 +0000 @@ -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 -Nru luasocket-3.0~rc1+git+ac3201d/.github/workflows/build.yml luasocket-3.1.0/.github/workflows/build.yml --- luasocket-3.0~rc1+git+ac3201d/.github/workflows/build.yml 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/.github/workflows/build.yml 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,45 @@ +name: Build + +on: + push: + branches: + - master + pull_request: + +jobs: + build: + name: Test build on ${{ matrix.platform }} + strategy: + fail-fast: false + matrix: + luaVersion: [ "5.4", "5.3", "5.2", "5.1", "luajit", "luajit-openresty" ] + platform: [ "ubuntu-20.04", "macos-11" ] # "windows-2022" not supported by gh-actions-lua + runs-on: ${{ matrix.platform }} + 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 and install + run: | + export DEBUG=DEBUG + luarocks make -- luasocket-scm-3.rockspec + - name: Run regression tests + run: | + 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 diff -Nru luasocket-3.0~rc1+git+ac3201d/.github/workflows/deploy.yml luasocket-3.1.0/.github/workflows/deploy.yml --- luasocket-3.0~rc1+git+ac3201d/.github/workflows/deploy.yml 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/.github/workflows/deploy.yml 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,34 @@ +name: Deploy + +on: [ push, workflow_dispatch ] + +jobs: + + affected: + uses: lunarmodules/.github/.github/workflows/list_affected_rockspecs.yml@main + + build: + needs: affected + if: ${{ needs.affected.outputs.rockspecs }} + uses: lunarmodules/.github/.github/workflows/test_build_rock.yml@main + with: + rockspecs: ${{ needs.affected.outputs.rockspecs }} + + upload: + needs: [ affected, build ] + # Only run upload if: + # 1. We are on the canonical repository (no uploads from forks) + # 2. The current commit is either tagged or on the default branch (the workflow will upload dev/scm rockspecs any + # time they are touched, tagged ones whenever the edited rockspec and tag match) + # 3. Some rockspecs were changed — this implies the commit changing the rockspec is the same one that gets tagged + if: >- + ${{ + github.repository == 'lunarmodules/luasocket' && + ( github.ref_name == 'master' || startsWith(github.ref, 'refs/tags/') ) && + needs.affected.outputs.rockspecs + }} + uses: lunarmodules/.github/.github/workflows/upload_to_luarocks.yml@main + with: + rockspecs: ${{ needs.affected.outputs.rockspecs }} + secrets: + apikey: ${{ secrets.LUAROCKS_APIKEY }} diff -Nru luasocket-3.0~rc1+git+ac3201d/.github/workflows/luacheck.yml luasocket-3.1.0/.github/workflows/luacheck.yml --- luasocket-3.0~rc1+git+ac3201d/.github/workflows/luacheck.yml 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/.github/workflows/luacheck.yml 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,13 @@ +name: Luacheck + +on: [push, pull_request] + +jobs: + + luacheck: + runs-on: ubuntu-20.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Luacheck + uses: lunarmodules/luacheck@v0 diff -Nru luasocket-3.0~rc1+git+ac3201d/.gitignore luasocket-3.1.0/.gitignore --- luasocket-3.0~rc1+git+ac3201d/.gitignore 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/.gitignore 2022-08-11 13:08:58.000000000 +0000 @@ -6,7 +6,6 @@ *.dll* *.user *.sdf -Lua.props Debug Release *.manifest diff -Nru luasocket-3.0~rc1+git+ac3201d/LICENSE luasocket-3.1.0/LICENSE --- luasocket-3.0~rc1+git+ac3201d/LICENSE 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/LICENSE 2022-08-11 13:08:58.000000000 +0000 @@ -1,5 +1,4 @@ -LuaSocket 3.0 license -Copyright © 2004-2013 Diego Nehab +Copyright (C) 2004-2022 Diego Nehab Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), diff -Nru luasocket-3.0~rc1+git+ac3201d/Lua51.props luasocket-3.1.0/Lua51.props --- luasocket-3.0~rc1+git+ac3201d/Lua51.props 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/Lua51.props 1970-01-01 00:00:00.000000000 +0000 @@ -1,28 +0,0 @@ - - - - - ..\build\vc12\bin\lua\5.1\ - ..\build\vc12\bin\lua\5.1\ - ..\build\vc12\include\lua\5.1\ - lua51.lib - - - <_PropertySheetDisplayName>Lua51 - - - - - $(LUALIB_PATH) - - - $(LUABIN_PATH) - - - $(LUAINC_PATH) - - - $(LUALIB) - - - diff -Nru luasocket-3.0~rc1+git+ac3201d/Lua52.props luasocket-3.1.0/Lua52.props --- luasocket-3.0~rc1+git+ac3201d/Lua52.props 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/Lua52.props 1970-01-01 00:00:00.000000000 +0000 @@ -1,28 +0,0 @@ - - - - - ..\build\vc12\bin\lua\5.2\ - ..\build\vc12\bin\lua\5.2\ - ..\build\vc12\include\lua\5.2\ - lua52.lib - - - <_PropertySheetDisplayName>Lua52 - - - - - $(LUALIB_PATH) - - - $(LUABIN_PATH) - - - $(LUAINC_PATH) - - - $(LUALIB) - - - diff -Nru luasocket-3.0~rc1+git+ac3201d/.luacheckrc luasocket-3.1.0/.luacheckrc --- luasocket-3.0~rc1+git+ac3201d/.luacheckrc 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/.luacheckrc 2022-08-11 13:08:58.000000000 +0000 @@ -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", +} + diff -Nru luasocket-3.0~rc1+git+ac3201d/Lua.props luasocket-3.1.0/Lua.props --- luasocket-3.0~rc1+git+ac3201d/Lua.props 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/Lua.props 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,49 @@ + + + + + $(Platform)/$(Configuration) + + + $(Configuration) + + + 5.3 + z:\data\build\vc14\ + $(LUAPREFIX)\lib\lua\$(LUAV)\$(LUAPLAT) + $(LUAPREFIX)\bin\lua\$(LUAV)\$(LUAPLAT) + $(LUAPREFIX)\bin\lua\$(LUAV)\$(LUAPLAT)\lua + $(LUAPREFIX)\include\lua\$(LUAV);$(LUAPREFIX)\include\lua$(LUAV) + lua$(LUAV.Replace('.', '')).lib + + + <_PropertySheetDisplayName>Lua + + + + + $(LUAPLAT) + + + $(LUAPREFIX) + + + $(LUAV) + + + $(LUALIB) + + + $(LUAINC) + + + $(LUACDIR) + + + $(LUALDIR) + + + $(LUALIBNAME) + + + diff -Nru luasocket-3.0~rc1+git+ac3201d/luasocket-scm-0.rockspec luasocket-3.1.0/luasocket-scm-0.rockspec --- luasocket-3.0~rc1+git+ac3201d/luasocket-scm-0.rockspec 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/luasocket-scm-0.rockspec 1970-01-01 00:00:00.000000000 +0000 @@ -1,105 +0,0 @@ -package = "LuaSocket" -version = "scm-0" -source = { - url = "https://github.com/diegonehab/luasocket/archive/master.zip", - dir = "luasocket-master", -} -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", - "LUASOCKET_API=__attribute__((visibility(\"default\")))", - "UNIX_API=__attribute__((visibility(\"default\")))", - "MIME_API=__attribute__((visibility(\"default\")))" - }, - macosx = { - "LUASOCKET_DEBUG", - "UNIX_HAS_SUN_LEN", - "LUASOCKET_API=__attribute__((visibility(\"default\")))", - "UNIX_API=__attribute__((visibility(\"default\")))", - "MIME_API=__attribute__((visibility(\"default\")))" - }, - win32 = { - "LUASOCKET_DEBUG", - "NDEBUG", - "LUASOCKET_API=__declspec(dllexport)", - "MIME_API=__declspec(dllexport)" - }, - mingw32 = { - "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", "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/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"), - haiku = make_plat("haiku"), - win32 = make_plat("win32"), - mingw32 = make_plat("mingw32") - }, - copy_directories = { "doc", "samples", "etc", "test" } -} diff -Nru luasocket-3.0~rc1+git+ac3201d/luasocket-scm-3.rockspec luasocket-3.1.0/luasocket-scm-3.rockspec --- luasocket-3.0~rc1+git+ac3201d/luasocket-scm-3.rockspec 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/luasocket-scm-3.rockspec 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,135 @@ +package = "LuaSocket" +version = "scm-3" +source = { + url = "git+https://github.com/lunarmodules/luasocket.git", + branch = "master" +} +description = { + summary = "Network support for the Lua language", + detailed = [[ + LuaSocket is a Lua extension library composed of two parts: a set of C + modules that provide support for the TCP and UDP transport layers, and a + set of Lua modules that provide functions commonly needed by applications + that deal with the Internet. + ]], + homepage = "https://github.com/lunarmodules/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" } + modules["socket.core"].libdirs = {} + 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 = { + "docs" + , "samples" + , "etc" + , "test" } +} diff -Nru luasocket-3.0~rc1+git+ac3201d/macosx.cmd luasocket-3.1.0/macosx.cmd --- luasocket-3.0~rc1+git+ac3201d/macosx.cmd 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/macosx.cmd 2022-08-11 13:08:58.000000000 +0000 @@ -1 +1 @@ -make DEBUG=DEBUG PLAT=macosx LUAINC_macosx_base=/Users/diego/build/macosx/include LUAPREFIX_macosx=/Users/diego/build/macosx install-both +make DEBUG=DEBUG PLAT=macosx LUAINC_macosx_base=/Users/$USER/build/macosx/include LUAPREFIX_macosx=/Users/$USER/build/macosx install-both diff -Nru luasocket-3.0~rc1+git+ac3201d/makefile luasocket-3.1.0/makefile --- luasocket-3.0~rc1+git+ac3201d/makefile 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/makefile 2022-08-11 13:08:58.000000000 +0000 @@ -10,7 +10,7 @@ # print print the build settings PLAT?= linux -PLATS= macosx linux win32 mingw freebsd solaris +PLATS= macosx linux win32 win64 mingw freebsd solaris all: $(PLAT) @@ -33,6 +33,9 @@ $(MAKE) clean @cd src; $(MAKE) $(PLAT) LUAV=5.3 @cd src; $(MAKE) install LUAV=5.3 + $(MAKE) clean + @cd src; $(MAKE) $(PLAT) LUAV=5.4 + @cd src; $(MAKE) install LUAV=5.4 install-both-unix: $(MAKE) clean @@ -44,6 +47,9 @@ $(MAKE) clean @cd src; $(MAKE) $(PLAT) LUAV=5.3 @cd src; $(MAKE) install-unix LUAV=5.3 + $(MAKE) clean + @cd src; $(MAKE) $(PLAT) LUAV=5.4 + @cd src; $(MAKE) install-unix LUAV=5.4 .PHONY: test diff -Nru luasocket-3.0~rc1+git+ac3201d/makefile.dist luasocket-3.1.0/makefile.dist --- luasocket-3.0~rc1+git+ac3201d/makefile.dist 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/makefile.dist 2022-08-11 13:08:58.000000000 +0000 @@ -1,7 +1,7 @@ #-------------------------------------------------------------------------- # Distribution makefile #-------------------------------------------------------------------------- -DIST = luasocket-3.0-rc1 +DIST = luasocket-3.0.0 TEST = \ test/README \ @@ -92,29 +92,29 @@ socket.vcxproj \ mime.vcxproj -DOC = \ - doc/dns.html \ - doc/ftp.html \ - doc/index.html \ - doc/http.html \ - doc/installation.html \ - doc/introduction.html \ - doc/ltn12.html \ - doc/luasocket.png \ - doc/mime.html \ - doc/reference.css \ - doc/reference.html \ - doc/smtp.html \ - doc/socket.html \ - doc/tcp.html \ - doc/udp.html \ - doc/url.html +DOCS = \ + docs/dns.html \ + docs/ftp.html \ + docs/index.html \ + docs/http.html \ + docs/installation.html \ + docs/introduction.html \ + docs/ltn12.html \ + docs/luasocket.png \ + docs/mime.html \ + docs/reference.css \ + docs/reference.html \ + docs/smtp.html \ + docs/socket.html \ + docs/tcp.html \ + docs/udp.html \ + docs/url.html dist: mkdir -p $(DIST) - cp -vf NEW $(DIST) + cp -vf CHANGELOG.md $(DIST) cp -vf LICENSE $(DIST) - cp -vf README $(DIST) + cp -vf README.md $(DIST) cp -vf $(MAKE) $(DIST) mkdir -p $(DIST)/etc @@ -123,8 +123,8 @@ mkdir -p $(DIST)/src cp -vf $(SRC) $(DIST)/src - mkdir -p $(DIST)/doc - cp -vf $(DOC) $(DIST)/doc + mkdir -p $(DIST)/docs + cp -vf $(DOCS) $(DIST)/docs mkdir -p $(DIST)/samples cp -vf $(SAMPLES) $(DIST)/samples diff -Nru luasocket-3.0~rc1+git+ac3201d/mime.vcxproj luasocket-3.1.0/mime.vcxproj --- luasocket-3.0~rc1+git+ac3201d/mime.vcxproj 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/mime.vcxproj 2022-08-11 13:08:58.000000000 +0000 @@ -1,5 +1,5 @@  - + Debug @@ -20,19 +20,7 @@ - - - - Document - copy %(FullPath) $(LUABIN_PATH)$(Configuration) - $(LUABIN_PATH)$(Configuration)\%(Filename)%(Extension) - copy %(FullPath) $(LUABIN_PATH)$(Configuration) - $(LUABIN_PATH)$(Configuration)\%(Filename)%(Extension) - copy %(FullPath) $(LUALIB_PATH)$(Platform)\$(Configuration) - copy %(FullPath) $(LUALIB_PATH)$(Platform)\$(Configuration) - $(LUABIN_PATH)$(Platform)\$(Configuration)\%(Filename)%(Extension) - $(LUABIN_PATH)$(Platform)\$(Configuration)\%(Filename)%(Extension) - + {128E8BD0-174A-48F0-8771-92B1E8D18713} @@ -41,22 +29,22 @@ DynamicLibrary - v110 + v141 MultiByte DynamicLibrary - v110 + v141 MultiByte DynamicLibrary - v110 + v141 MultiByte DynamicLibrary - v110 + v141 MultiByte @@ -87,7 +75,7 @@ <_ProjectFileVersion>11.0.50727.1 - $(LUABIN_PATH)$(Configuration)\mime\ + $(Configuration)\mime\ $(Configuration)\ true core @@ -95,23 +83,23 @@ true core - $(LUABIN_PATH)$(Platform)\$(Configuration)\mime\ + $(Platform)\$(Configuration)\mime\ - $(LUABIN_PATH)$(Configuration)\mime\ + $(Configuration)\mime\ $(Configuration)\ false core false - $(LUABIN_PATH)$(Platform)\$(Configuration)\mime\ + $(Platform)\$(Configuration)\mime\ core Disabled - $(LUAINC_PATH);%(AdditionalIncludeDirectories) + $(LUAINC);%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;_USRDLL;MIME_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true EnableFastChecks @@ -122,9 +110,9 @@ $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - $(LUALIB);%(AdditionalDependencies) + $(LUALIBNAME);%(AdditionalDependencies) $(OutDir)$(TargetName).dll - $(LUALIB_PATH)$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB);%(AdditionalLibraryDirectories) true $(OutDir)mime.pdb Windows @@ -138,7 +126,7 @@ Disabled - $(LUAINC_PATH);%(AdditionalIncludeDirectories) + $(LUAINC);%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;_USRDLL;MIME_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebugDLL @@ -149,9 +137,9 @@ $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - $(LUALIB);%(AdditionalDependencies) + $(LUALIBNAME);%(AdditionalDependencies) $(OutDir)$(TargetName).dll - $(LUALIB_PATH)$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB);%(AdditionalLibraryDirectories) true $(OutDir)mime.pdb Windows @@ -163,7 +151,7 @@ - $(LUAINC_PATH);%(AdditionalIncludeDirectories) + $(LUAINC);%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_USRDLL;MIME_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreadedDLL @@ -172,9 +160,9 @@ $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - $(LUALIB);%(AdditionalDependencies) + $(LUALIBNAME);%(AdditionalDependencies) $(OutDir)$(TargetName).dll - $(LUALIB_PATH)$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB);%(AdditionalLibraryDirectories) true Windows true @@ -187,7 +175,7 @@ - $(LUAINC_PATH);%(AdditionalIncludeDirectories) + $(LUAINC);%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_USRDLL;MIME_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreadedDLL @@ -198,9 +186,9 @@ $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - $(LUALIB);%(AdditionalDependencies) + $(LUALIBNAME);%(AdditionalDependencies) $(OutDir)$(TargetName).dll - $(LUALIB_PATH)$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB);%(AdditionalLibraryDirectories) true Windows true diff -Nru luasocket-3.0~rc1+git+ac3201d/mime.vcxproj.filters luasocket-3.1.0/mime.vcxproj.filters --- luasocket-3.0~rc1+git+ac3201d/mime.vcxproj.filters 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/mime.vcxproj.filters 1970-01-01 00:00:00.000000000 +0000 @@ -1,16 +0,0 @@ - - - - - - - - {fad87a86-297c-4881-a114-73b967bb3c92} - - - - - cdir - - - \ No newline at end of file diff -Nru luasocket-3.0~rc1+git+ac3201d/NEW luasocket-3.1.0/NEW --- luasocket-3.0~rc1+git+ac3201d/NEW 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/NEW 1970-01-01 00:00:00.000000000 +0000 @@ -1,44 +0,0 @@ -What's New - -Main changes for LuaSocket 3.0-rc1 are IPv6 support and Lua 5.2 compatibility. - - * Added: Compatible with Lua 5.2 - - Note that unless you define LUA_COMPAT_MODULE, package - tables will not be exported as globals! - * Added: IPv6 support; - - Socket.connect and socket.bind support IPv6 addresses; - - Getpeername and getsockname support IPv6 addresses, and - return the socket family as a third value; - - URL module updated to support IPv6 host names; - - New socket.tcp6 and socket.udp6 functions; - - New socket.dns.getaddrinfo and socket.dns.getnameinfo functions; - * Added: getoption method; - * Fixed: url.unescape was returning additional values; - * Fixed: mime.qp, mime.unqp, mime.b64, and mime.unb64 could - mistaking their own stack slots for functions arguments; - * Fixed: Receiving zero-length datagram is now possible; - * Improved: Hidden all internal library symbols; - * Improved: Better error messages; - * Improved: Better documentation of socket options. - * Fixed: manual sample of HTTP authentication now uses correct - "authorization" header (Alexandre Ittner); - * Fixed: failure on bind() was destroying the socket (Sam Roberts); - * Fixed: receive() returns immediatelly if prefix can satisfy - bytes requested (M Joonas Pihlaja); - * Fixed: multicast didn't work on Windows, or anywhere - else for that matter (Herbert Leuwer, Adrian Sietsma); - * Fixed: select() now reports an error when called with more - sockets than FD_SETSIZE (Lorenzo Leonini); - * Fixed: manual links to home.html changed to index.html (Robert Hahn); - * Fixed: mime.unb64() would return an empty string on results that started - with a null character (Robert Raschke); - * Fixed: HTTP now automatically redirects on 303 and 307 (Jonathan Gray); - * Fixed: calling sleep() with negative numbers could - block forever, wasting CPU. Now it returns immediately (MPB); - * Improved: FTP commands are now sent in upper case to - help buggy servers (Anders Eurenius); - * Improved: known headers now sent in canonic - capitalization to help buggy servers (Joseph Stewart); - * Improved: Clarified tcp:receive() in the manual (MPB); - * Improved: Decent makefiles (LHF). - * Fixed: RFC links in documentation now point to IETF (Cosmin Apreutesei). diff -Nru luasocket-3.0~rc1+git+ac3201d/README luasocket-3.1.0/README --- luasocket-3.0~rc1+git+ac3201d/README 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/README 1970-01-01 00:00:00.000000000 +0000 @@ -1,11 +0,0 @@ -This is the LuaSocket 3.0-rc1. It has been tested on Windows 7, Mac OS X, -and Linux. - -Please use the project page at GitHub - - https://github.com/diegonehab/luasocket - -to file bug reports or propose changes. - -Have fun, -Diego Nehab. diff -Nru luasocket-3.0~rc1+git+ac3201d/README.md luasocket-3.1.0/README.md --- luasocket-3.0~rc1+git+ac3201d/README.md 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/README.md 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,12 @@ +# LuaSocket + + +[![Build](https://img.shields.io/github/workflow/status/lunarmodules/luasocket/Build?label=Build=Lua)](https://github.com/lunarmodules/luasocket/actions?workflow=Build) +[![Luacheck](https://img.shields.io/github/workflow/status/lunarmodules/luasocket/Luacheck?label=Luacheck&logo=Lua)](https://github.com/lunarmodules/luasocket/actions?workflow=Luacheck) +[![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/lunarmodules/luasocket?label=Tag&logo=GitHub)](https://github.com/lunarmodules/luasocket/releases) +[![Luarocks](https://img.shields.io/luarocks/v/lunarmodules/luasocket?label=Luarocks&logo=Lua)](https://luarocks.org/modules/lunarmodules/luasocket) + +LuaSocket is a Lua extension library composed of two parts: + +1. a set of C modules that provide support for the TCP and UDP transport layers, and +2. a set of Lua modules that provide functions commonly needed by applications that deal with the Internet. diff -Nru luasocket-3.0~rc1+git+ac3201d/rockspec/luasocket-3.0rc2-1.rockspec luasocket-3.1.0/rockspec/luasocket-3.0rc2-1.rockspec --- luasocket-3.0~rc1+git+ac3201d/rockspec/luasocket-3.0rc2-1.rockspec 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/rockspec/luasocket-3.0rc2-1.rockspec 1970-01-01 00:00:00.000000000 +0000 @@ -1,105 +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", - "LUASOCKET_API=__attribute__((visibility(\"default\")))", - "UNIX_API=__attribute__((visibility(\"default\")))", - "MIME_API=__attribute__((visibility(\"default\")))" - }, - macosx = { - "LUASOCKET_DEBUG", - "UNIX_HAS_SUN_LEN", - "LUASOCKET_API=__attribute__((visibility(\"default\")))", - "UNIX_API=__attribute__((visibility(\"default\")))", - "MIME_API=__attribute__((visibility(\"default\")))" - }, - win32 = { - "LUASOCKET_DEBUG", - "NDEBUG", - "LUASOCKET_API=__declspec(dllexport)", - "MIME_API=__declspec(dllexport)" - }, - mingw32 = { - "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", "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/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"), - haiku = make_plat("haiku"), - win32 = make_plat("win32"), - mingw32 = make_plat("mingw32") - }, - copy_directories = { "doc", "samples", "etc", "test" } -} diff -Nru luasocket-3.0~rc1+git+ac3201d/rockspecs/luasocket-3.0.0-1.rockspec luasocket-3.1.0/rockspecs/luasocket-3.0.0-1.rockspec --- luasocket-3.0~rc1+git+ac3201d/rockspecs/luasocket-3.0.0-1.rockspec 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/rockspecs/luasocket-3.0.0-1.rockspec 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,134 @@ +package = "LuaSocket" +version = "3.0.0-1" +source = { + url = "git+https://github.com/lunarmodules/luasocket.git", + tag = "v3.0.0" +} +description = { + summary = "Network support for the Lua language", + detailed = [[ + LuaSocket is a Lua extension library composed of two parts: a set of C + modules that provide support for the TCP and UDP transport layers, and a + set of Lua modules that provide functions commonly needed by applications + that deal with the Internet. + ]], + homepage = "https://github.com/lunarmodules/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 = { + "docs" + , "samples" + , "etc" + , "test" } +} diff -Nru luasocket-3.0~rc1+git+ac3201d/rockspecs/luasocket-3.0rc1-2.rockspec luasocket-3.1.0/rockspecs/luasocket-3.0rc1-2.rockspec --- luasocket-3.0~rc1+git+ac3201d/rockspecs/luasocket-3.0rc1-2.rockspec 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/rockspecs/luasocket-3.0rc1-2.rockspec 2022-08-11 13:08:58.000000000 +0000 @@ -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" } +} diff -Nru luasocket-3.0~rc1+git+ac3201d/rockspecs/luasocket-3.1.0-1.rockspec luasocket-3.1.0/rockspecs/luasocket-3.1.0-1.rockspec --- luasocket-3.0~rc1+git+ac3201d/rockspecs/luasocket-3.1.0-1.rockspec 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/rockspecs/luasocket-3.1.0-1.rockspec 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,135 @@ +package = "LuaSocket" +version = "3.1.0-1" +source = { + url = "git+https://github.com/lunarmodules/luasocket.git", + tag = "v3.1.0" +} +description = { + summary = "Network support for the Lua language", + detailed = [[ + LuaSocket is a Lua extension library composed of two parts: a set of C + modules that provide support for the TCP and UDP transport layers, and a + set of Lua modules that provide functions commonly needed by applications + that deal with the Internet. + ]], + homepage = "https://github.com/lunarmodules/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" } + modules["socket.core"].libdirs = {} + 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 = { + "docs" + , "samples" + , "etc" + , "test" } +} diff -Nru luasocket-3.0~rc1+git+ac3201d/samples/cddb.lua luasocket-3.1.0/samples/cddb.lua --- luasocket-3.0~rc1+git+ac3201d/samples/cddb.lua 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/samples/cddb.lua 2022-08-11 13:08:58.000000000 +0000 @@ -26,7 +26,7 @@ data[key] = value end end - return data, code, message + return data, code, message end local host = socket.dns.gethostname() diff -Nru luasocket-3.0~rc1+git+ac3201d/socket.vcxproj luasocket-3.1.0/socket.vcxproj --- luasocket-3.0~rc1+git+ac3201d/socket.vcxproj 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/socket.vcxproj 2022-08-11 13:08:58.000000000 +0000 @@ -1,5 +1,5 @@  - + Debug @@ -21,6 +21,7 @@ + @@ -32,98 +33,6 @@ - - - Document - copy %(FullPath) $(LUABIN_PATH)$(Configuration) - copy %(FullPath) $(LUABIN_PATH)$(Configuration) - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration) - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration) - $(LUABIN_PATH)$(Configuration)\%(Filename)%(Extension) - $(LUABIN_PATH)$(Configuration)\%(Filename)%(Extension) - $(LUABIN_PATH)$(Platform)\$(Configuration)\%(Filename)%(Extension) - $(LUABIN_PATH)$(Platform)\$(Configuration)\%(Filename)%(Extension) - - - Document - copy %(FullPath) $(LUABIN_PATH)$(Configuration) - copy %(FullPath) $(LUABIN_PATH)$(Configuration) - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration) - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration) - $(LUABIN_PATH)$(Configuration)\%(Filename)%(Extension) - $(LUABIN_PATH)$(Configuration)\%(Filename)%(Extension) - $(LUABIN_PATH)$(Platform)\$(Configuration)\%(Filename)%(Extension) - $(LUABIN_PATH)$(Platform)\$(Configuration)\%(Filename)%(Extension) - - - - - Document - $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket - - - Document - $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket - - - Document - $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket - - - Document - $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket - - - Document - $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket - - - Document - $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) - $(LUABIN_PATH)$(Configuration)\socket\%(Filename)%(Extension) - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Platform)\$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket - copy %(FullPath) $(LUABIN_PATH)$(Configuration)\socket - - {66E3CE14-884D-4AEA-9F20-15A0BEAF8C5A} Win32Proj @@ -131,22 +40,22 @@ DynamicLibrary - v110 + v141 MultiByte DynamicLibrary - v110 + v141 MultiByte DynamicLibrary - v110 + v141 MultiByte DynamicLibrary - v110 + v141 MultiByte @@ -177,7 +86,7 @@ <_ProjectFileVersion>11.0.50727.1 - $(LUALIB_PATH)$(Configuration)\socket\ + $(Configuration)\socket\ $(Configuration)\ true core @@ -185,23 +94,23 @@ true core - $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\ + $(Platform)\$(Configuration)\socket\ - $(LUALIB_PATH)$(Configuration)\socket\ + $(Configuration)\socket\ $(Configuration)\ false core false - $(LUABIN_PATH)$(Platform)\$(Configuration)\socket\ + $(Platform)\$(Configuration)\socket\ core Disabled - $(LUAINC_PATH);%(AdditionalIncludeDirectories) + $(LUAINC);%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;_USRDLL;LUASOCKET_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;LUASOCKET_DEBUG;%(PreprocessorDefinitions) true EnableFastChecks @@ -212,9 +121,9 @@ $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - $(LUALIB);ws2_32.lib;%(AdditionalDependencies) + $(LUALIBNAME);ws2_32.lib;%(AdditionalDependencies) $(OutDir)$(TargetName).dll - $(LUALIB_PATH)$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB);%(AdditionalLibraryDirectories) true $(OutDir)mime.pdb Windows @@ -228,7 +137,7 @@ Disabled - $(LUAINC_PATH);%(AdditionalIncludeDirectories) + $(LUAINC);%(AdditionalIncludeDirectories) WIN32;_DEBUG;_WINDOWS;_USRDLL;LUASOCKET_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;LUASOCKET_DEBUG;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebugDLL @@ -239,9 +148,9 @@ $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - $(LUALIB);ws2_32.lib;%(AdditionalDependencies) + $(LUALIBNAME);ws2_32.lib;%(AdditionalDependencies) $(OutDir)$(TargetName).dll - $(LUALIB_PATH)$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB);%(AdditionalLibraryDirectories) true $(OutDir)mime.pdb Windows @@ -253,7 +162,7 @@ - $(LUAINC_PATH);%(AdditionalIncludeDirectories) + $(LUAINC);%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_USRDLL;LUASOCKET_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreadedDLL @@ -262,9 +171,9 @@ $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - $(LUALIB);ws2_32.lib;%(AdditionalDependencies) + $(LUALIBNAME);ws2_32.lib;%(AdditionalDependencies) $(OutDir)$(TargetName).dll - $(LUALIB_PATH)$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB);%(AdditionalLibraryDirectories) true Windows true @@ -277,7 +186,7 @@ - $(LUAINC_PATH);%(AdditionalIncludeDirectories) + $(LUAINC);%(AdditionalIncludeDirectories) WIN32;NDEBUG;_WINDOWS;_USRDLL;LUASOCKET_API=__declspec(dllexport);_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) MultiThreadedDLL @@ -288,9 +197,9 @@ $(IntDir)$(TargetName)$(PlatformToolsetVersion).pdb - $(LUALIB);ws2_32.lib;%(AdditionalDependencies) + $(LUALIBNAME);ws2_32.lib;%(AdditionalDependencies) $(OutDir)$(TargetName).dll - $(LUALIB_PATH)$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + $(LUALIB);%(AdditionalLibraryDirectories) true Windows true diff -Nru luasocket-3.0~rc1+git+ac3201d/socket.vcxproj.filters luasocket-3.1.0/socket.vcxproj.filters --- luasocket-3.0~rc1+git+ac3201d/socket.vcxproj.filters 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/socket.vcxproj.filters 1970-01-01 00:00:00.000000000 +0000 @@ -1,51 +0,0 @@ - - - - - - - - - - - - - - - - - - - cdir - - - cdir - - - ldir - - - ldir - - - ldir - - - ldir - - - ldir - - - ldir - - - - - {b053460d-5439-4e3a-a2eb-c31a95b5691f} - - - {b301b82c-37cb-4e05-9333-194e92ed7a62} - - - \ No newline at end of file diff -Nru luasocket-3.0~rc1+git+ac3201d/src/auxiliar.c luasocket-3.1.0/src/auxiliar.c --- luasocket-3.0~rc1+git+ac3201d/src/auxiliar.c 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/auxiliar.c 2022-08-11 13:08:58.000000000 +0000 @@ -2,14 +2,11 @@ * Auxiliar routines for class hierarchy manipulation * LuaSocket toolkit \*=========================================================================*/ +#include "luasocket.h" +#include "auxiliar.h" #include #include -#include "auxiliar.h" - -/*=========================================================================*\ -* Exported functions -\*=========================================================================*/ /*-------------------------------------------------------------------------*\ * Initializes the module \*-------------------------------------------------------------------------*/ @@ -143,7 +140,7 @@ * otherwise \*-------------------------------------------------------------------------*/ void *auxiliar_getclassudata(lua_State *L, const char *classname, int objidx) { - return luaL_checkudata(L, objidx, classname); + return luaL_testudata(L, objidx, classname); } /*-------------------------------------------------------------------------*\ @@ -155,4 +152,3 @@ luaL_typename(L, narg)); return luaL_argerror(L, narg, msg); } - diff -Nru luasocket-3.0~rc1+git+ac3201d/src/auxiliar.h luasocket-3.1.0/src/auxiliar.h --- luasocket-3.0~rc1+git+ac3201d/src/auxiliar.h 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/auxiliar.h 2022-08-11 13:08:58.000000000 +0000 @@ -29,20 +29,26 @@ * reverse mapping are done using lauxlib. \*=========================================================================*/ -#include "lua.h" -#include "lauxlib.h" -#include "compat.h" +#include "luasocket.h" + +#ifndef _WIN32 +#pragma GCC visibility push(hidden) +#endif int auxiliar_open(lua_State *L); void auxiliar_newclass(lua_State *L, const char *classname, luaL_Reg *func); +int auxiliar_tostring(lua_State *L); void auxiliar_add2group(lua_State *L, const char *classname, const char *group); -void auxiliar_setclass(lua_State *L, const char *classname, int objidx); +int auxiliar_checkboolean(lua_State *L, int objidx); void *auxiliar_checkclass(lua_State *L, const char *classname, int objidx); void *auxiliar_checkgroup(lua_State *L, const char *groupname, int objidx); -void *auxiliar_getclassudata(lua_State *L, const char *groupname, int objidx); +void auxiliar_setclass(lua_State *L, const char *classname, int objidx); void *auxiliar_getgroupudata(lua_State *L, const char *groupname, int objidx); -int auxiliar_checkboolean(lua_State *L, int objidx); -int auxiliar_tostring(lua_State *L); +void *auxiliar_getclassudata(lua_State *L, const char *groupname, int objidx); int auxiliar_typeerror(lua_State *L, int narg, const char *tname); +#ifndef _WIN32 +#pragma GCC visibility pop +#endif + #endif /* AUXILIAR_H */ diff -Nru luasocket-3.0~rc1+git+ac3201d/src/buffer.c luasocket-3.1.0/src/buffer.c --- luasocket-3.0~rc1+git+ac3201d/src/buffer.c 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/buffer.c 2022-08-11 13:08:58.000000000 +0000 @@ -2,10 +2,7 @@ * Input/Output interface for Lua programs * LuaSocket toolkit \*=========================================================================*/ -#include "lua.h" -#include "lauxlib.h" -#include "compat.h" - +#include "luasocket.h" #include "buffer.h" /*=========================================================================*\ @@ -106,11 +103,14 @@ * 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); diff -Nru luasocket-3.0~rc1+git+ac3201d/src/buffer.h luasocket-3.1.0/src/buffer.h --- luasocket-3.0~rc1+git+ac3201d/src/buffer.h 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/buffer.h 2022-08-11 13:08:58.000000000 +0000 @@ -15,8 +15,7 @@ * The module is built on top of the I/O abstraction defined in io.h and the * timeout management is done with the timeout.h interface. \*=========================================================================*/ -#include "lua.h" - +#include "luasocket.h" #include "io.h" #include "timeout.h" @@ -34,12 +33,20 @@ } t_buffer; typedef t_buffer *p_buffer; +#ifndef _WIN32 +#pragma GCC visibility push(hidden) +#endif + int buffer_open(lua_State *L); void buffer_init(p_buffer buf, p_io io, p_timeout tm); -int buffer_meth_send(lua_State *L, p_buffer buf); -int buffer_meth_receive(lua_State *L, p_buffer buf); int buffer_meth_getstats(lua_State *L, p_buffer buf); int buffer_meth_setstats(lua_State *L, p_buffer buf); +int buffer_meth_send(lua_State *L, p_buffer buf); +int buffer_meth_receive(lua_State *L, p_buffer buf); int buffer_isempty(p_buffer buf); +#ifndef _WIN32 +#pragma GCC visibility pop +#endif + #endif /* BUF_H */ diff -Nru luasocket-3.0~rc1+git+ac3201d/src/compat.c luasocket-3.1.0/src/compat.c --- luasocket-3.0~rc1+git+ac3201d/src/compat.c 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/compat.c 2022-08-11 13:08:58.000000000 +0000 @@ -1,10 +1,12 @@ +#include "luasocket.h" #include "compat.h" #if LUA_VERSION_NUM==501 + /* ** Adapted from Lua 5.2 */ -void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { +void luasocket_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { luaL_checkstack(L, nup+1, "too many upvalues"); for (; l->name != NULL; l++) { /* fill the table with given functions */ int i; @@ -16,4 +18,22 @@ } lua_pop(L, nup); /* remove upvalues */ } + +/* +** Duplicated from Lua 5.2 +*/ +void *luasocket_testudata (lua_State *L, int ud, const char *tname) { + void *p = lua_touserdata(L, ud); + if (p != NULL) { /* value is a userdata? */ + if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ + luaL_getmetatable(L, tname); /* get correct metatable */ + if (!lua_rawequal(L, -1, -2)) /* not the same? */ + p = NULL; /* value is a userdata with wrong metatable */ + lua_pop(L, 2); /* remove both metatables */ + return p; + } + } + return NULL; /* value is not a userdata with a metatable */ +} + #endif diff -Nru luasocket-3.0~rc1+git+ac3201d/src/compat.h luasocket-3.1.0/src/compat.h --- luasocket-3.0~rc1+git+ac3201d/src/compat.h 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/compat.h 2022-08-11 13:08:58.000000000 +0000 @@ -1,11 +1,22 @@ #ifndef COMPAT_H #define COMPAT_H -#include "lua.h" -#include "lauxlib.h" - #if LUA_VERSION_NUM==501 -void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup); + +#ifndef _WIN32 +#pragma GCC visibility push(hidden) +#endif + +void luasocket_setfuncs (lua_State *L, const luaL_Reg *l, int nup); +void *luasocket_testudata ( lua_State *L, int arg, const char *tname); + +#ifndef _WIN32 +#pragma GCC visibility pop +#endif + +#define luaL_setfuncs luasocket_setfuncs +#define luaL_testudata luasocket_testudata + #endif #endif diff -Nru luasocket-3.0~rc1+git+ac3201d/src/except.c luasocket-3.1.0/src/except.c --- luasocket-3.0~rc1+git+ac3201d/src/except.c 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/except.c 2022-08-11 13:08:58.000000000 +0000 @@ -2,13 +2,9 @@ * Simple exception support * LuaSocket toolkit \*=========================================================================*/ -#include - -#include "lua.h" -#include "lauxlib.h" -#include "compat.h" - +#include "luasocket.h" #include "except.h" +#include #if LUA_VERSION_NUM < 502 #define lua_pcallk(L, na, nr, err, ctx, cont) \ diff -Nru luasocket-3.0~rc1+git+ac3201d/src/except.h luasocket-3.1.0/src/except.h --- luasocket-3.0~rc1+git+ac3201d/src/except.h 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/except.h 2022-08-11 13:08:58.000000000 +0000 @@ -31,8 +31,16 @@ * exceptions on error, but that don't interrupt the user script. \*=========================================================================*/ -#include "lua.h" +#include "luasocket.h" + +#ifndef _WIN32 +#pragma GCC visibility push(hidden) +#endif int except_open(lua_State *L); +#ifndef _WIN32 +#pragma GCC visibility pop +#endif + #endif diff -Nru luasocket-3.0~rc1+git+ac3201d/src/ftp.lua luasocket-3.1.0/src/ftp.lua --- luasocket-3.0~rc1+git+ac3201d/src/ftp.lua 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/ftp.lua 2022-08-11 13:08:58.000000000 +0000 @@ -56,7 +56,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 -Nru luasocket-3.0~rc1+git+ac3201d/src/http.lua luasocket-3.1.0/src/http.lua --- luasocket-3.0~rc1+git+ac3201d/src/http.lua 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/http.lua 2022-08-11 13:08:58.000000000 +0000 @@ -26,10 +26,20 @@ -- user agent field sent in request _M.USERAGENT = socket._VERSION --- supported schemes -local SCHEMES = { ["http"] = true } --- default port for document retrieval -local PORT = 80 +-- supported schemes and their particulars +local SCHEMES = { + http = { + port = 80 + , create = function(t) + return socket.tcp end } + , https = { + port = 443 + , create = function(t) + local https = assert( + require("ssl.https"), 'LuaSocket: LuaSec not found') + local tcp = assert( + https.tcp, 'LuaSocket: Function tcp() not available from LuaSec') + return tcp(t) end }} ----------------------------------------------------------------------------- -- Reads MIME headers from a connection, unfolding where needed @@ -79,7 +89,7 @@ -- 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 @@ -111,13 +121,13 @@ function _M.open(host, port, create) -- create socket with user connect function, or with default - local c = socket.try((create or socket.tcp)()) + local c = socket.try(create()) local h = base.setmetatable({ c = c }, metat) -- create finalized try h.try = socket.newtry(function() h:close() end) -- set timeout before connecting h.try(c:settimeout(_M.TIMEOUT)) - h.try(c:connect(host, port or PORT)) + h.try(c:connect(host, port)) -- here everything worked return h end @@ -147,10 +157,15 @@ end function metat.__index:receivestatusline() - local status = self.try(self.c:receive(5)) + local status,ec = self.try(self.c:receive(5)) -- identify HTTP/0.9 responses, which do not contain a status line -- this is just a heuristic, but is what the RFC recommends - if status ~= "HTTP/" then return nil, status end + if status ~= "HTTP/" then + if ec == "timeout" then + return 408 + end + return nil, status + end -- otherwise proceed reading a status line status = self.try(self.c:receive("*l", status)) local code = socket.skip(2, string.find(status, "HTTP/%d*%.%d* (%d%d%d)")) @@ -212,7 +227,10 @@ local function adjustheaders(reqt) -- default headers - local host = string.gsub(reqt.authority, "^.-@", "") + local host = reqt.host + local port = tostring(reqt.port) + if port ~= tostring(SCHEMES[reqt.scheme].port) then + host = host .. ':' .. port end local lower = { ["user-agent"] = _M.USERAGENT, ["host"] = host, @@ -243,10 +261,8 @@ -- default url parts local default = { - host = "", - port = PORT, - path ="/", - scheme = "http" + path ="/" + , scheme = "http" } local function adjustrequest(reqt) @@ -254,14 +270,26 @@ local nreqt = reqt.url and url.parse(reqt.url, default) or {} -- explicit components override url for i,v in base.pairs(reqt) do nreqt[i] = v end - if nreqt.port == "" then nreqt.port = PORT end - if not (nreqt.host and nreqt.host ~= "") then + -- default to scheme particulars + local schemedefs, host, port, method + = SCHEMES[nreqt.scheme], nreqt.host, nreqt.port, nreqt.method + if not nreqt.create then nreqt.create = schemedefs.create(nreqt) end + if not (port and port ~= '') then nreqt.port = schemedefs.port end + if not (method and method ~= '') then nreqt.method = 'GET' end + if not (host and host ~= "") then socket.try(nil, "invalid host '" .. base.tostring(nreqt.host) .. "'") end -- compute uri if user hasn't overriden 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 @@ -272,12 +300,16 @@ if not location then return false end location = string.gsub(location, "%s", "") if location == "" then return false end - local scheme = string.match(location, "^([%w][%w%+%-%.]*)%:") - if scheme and not SCHEMES[scheme] then return false end + local scheme = url.parse(location).scheme + if scheme and (not SCHEMES[scheme]) then return false end + -- avoid https downgrades + if ('https' == reqt.scheme) and ('https' ~= scheme) then return false end return (reqt.redirect ~= false) and (code == 301 or code == 302 or code == 303 or code == 307) and (not reqt.method or reqt.method == "GET" or reqt.method == "HEAD") - and (not reqt.nredirects or reqt.nredirects < 5) + and ((false == reqt.maxredirects) + or ((reqt.nredirects or 0) + < (reqt.maxredirects or 5))) end local function shouldreceivebody(reqt, code) @@ -291,14 +323,21 @@ local trequest, tredirect --[[local]] function tredirect(reqt, location) + -- the RFC says the redirect URL has to be absolute, but some + -- servers do not respect that + local newurl = url.absolute(reqt.url, location) + -- if switching schemes, reset port and create function + if url.parse(newurl).scheme ~= reqt.scheme then + reqt.port = nil + reqt.create = nil end + -- make new request local result, code, headers, status = trequest { - -- the RFC says the redirect URL has to be absolute, but some - -- servers do not respect that - url = url.absolute(reqt.url, location), + url = newurl, source = reqt.source, sink = reqt.sink, headers = reqt.headers, proxy = reqt.proxy, + maxredirects = reqt.maxredirects, nredirects = (reqt.nredirects or 0) + 1, create = reqt.create } @@ -325,11 +364,13 @@ if not code then h:receive09body(status, nreqt.sink, nreqt.step) return 1, 200 + elseif code == 408 then + return 1, code 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() @@ -379,4 +420,5 @@ else return trequest(reqt) end end) +_M.schemes = SCHEMES return _M diff -Nru luasocket-3.0~rc1+git+ac3201d/src/inet.c luasocket-3.1.0/src/inet.c --- luasocket-3.0~rc1+git+ac3201d/src/inet.c 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/inet.c 2022-08-11 13:08:58.000000000 +0000 @@ -2,16 +2,13 @@ * Internet domain functions * LuaSocket toolkit \*=========================================================================*/ +#include "luasocket.h" +#include "inet.h" + #include #include #include -#include "lua.h" -#include "lauxlib.h" -#include "compat.h" - -#include "inet.h" - /*=========================================================================*\ * Internal function prototypes. \*=========================================================================*/ @@ -32,9 +29,6 @@ { NULL, NULL} }; -/*=========================================================================*\ -* Exported functions -\*=========================================================================*/ /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ @@ -259,7 +253,7 @@ port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV); if (err) { lua_pushnil(L); - lua_pushstring(L, gai_strerror(err)); + lua_pushstring(L, LUA_GAI_STRERROR(err)); return 2; } lua_pushstring(L, name); @@ -292,7 +286,7 @@ name, INET6_ADDRSTRLEN, port, 6, NI_NUMERICHOST | NI_NUMERICSERV); if (err) { lua_pushnil(L); - lua_pushstring(L, gai_strerror(err)); + lua_pushstring(L, LUA_GAI_STRERROR(err)); return 2; } lua_pushstring(L, name); diff -Nru luasocket-3.0~rc1+git+ac3201d/src/inet.h luasocket-3.1.0/src/inet.h --- luasocket-3.0~rc1+git+ac3201d/src/inet.h 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/inet.h 2022-08-11 13:08:58.000000000 +0000 @@ -14,7 +14,7 @@ * * The Lua functions toip and tohostname are also implemented here. \*=========================================================================*/ -#include "lua.h" +#include "luasocket.h" #include "socket.h" #include "timeout.h" @@ -22,21 +22,23 @@ #define LUASOCKET_INET_ATON #endif +#ifndef _WIN32 +#pragma GCC visibility push(hidden) +#endif + int inet_open(lua_State *L); -const char *inet_trycreate(p_socket ps, int family, int type, int protocol); -const char *inet_tryconnect(p_socket ps, int *family, const char *address, - const char *serv, p_timeout tm, struct addrinfo *connecthints); -const char *inet_trybind(p_socket ps, int *family, const char *address, - const char *serv, struct addrinfo *bindhints); -const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm); -const char *inet_tryaccept(p_socket server, int family, p_socket client, p_timeout tm); +int inet_optfamily(lua_State* L, int narg, const char* def); +int inet_optsocktype(lua_State* L, int narg, const char* def); int inet_meth_getpeername(lua_State *L, p_socket ps, int family); int inet_meth_getsockname(lua_State *L, p_socket ps, int family); -int inet_optfamily(lua_State* L, int narg, const char* def); -int inet_optsocktype(lua_State* L, int narg, const char* def); +const char *inet_trycreate(p_socket ps, int family, int type, int protocol); +const char *inet_trydisconnect(p_socket ps, int family, p_timeout tm); +const char *inet_tryconnect(p_socket ps, int *family, const char *address, const char *serv, p_timeout tm, struct addrinfo *connecthints); +const char *inet_tryaccept(p_socket server, int family, p_socket client, p_timeout tm); +const char *inet_trybind(p_socket ps, int *family, const char *address, const char *serv, struct addrinfo *bindhints); #ifdef LUASOCKET_INET_ATON int inet_aton(const char *cp, struct in_addr *inp); @@ -47,4 +49,8 @@ int inet_pton(int af, const char *src, void *dst); #endif +#ifndef _WIN32 +#pragma GCC visibility pop +#endif + #endif /* INET_H */ diff -Nru luasocket-3.0~rc1+git+ac3201d/src/io.c luasocket-3.1.0/src/io.c --- luasocket-3.0~rc1+git+ac3201d/src/io.c 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/io.c 2022-08-11 13:08:58.000000000 +0000 @@ -2,11 +2,9 @@ * Input/Output abstraction * LuaSocket toolkit \*=========================================================================*/ +#include "luasocket.h" #include "io.h" -/*=========================================================================*\ -* Exported functions -\*=========================================================================*/ /*-------------------------------------------------------------------------*\ * Initializes C structure \*-------------------------------------------------------------------------*/ diff -Nru luasocket-3.0~rc1+git+ac3201d/src/io.h luasocket-3.1.0/src/io.h --- luasocket-3.0~rc1+git+ac3201d/src/io.h 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/io.h 2022-08-11 13:08:58.000000000 +0000 @@ -12,9 +12,7 @@ * The module socket.h implements this interface, and thus the module tcp.h * is very simple. \*=========================================================================*/ -#include -#include "lua.h" - +#include "luasocket.h" #include "timeout.h" /* IO error codes */ @@ -58,8 +56,15 @@ } t_io; typedef t_io *p_io; +#ifndef _WIN32 +#pragma GCC visibility push(hidden) +#endif + void io_init(p_io io, p_send send, p_recv recv, p_error error, void *ctx); const char *io_strerror(int err); -#endif /* IO_H */ +#ifndef _WIN32 +#pragma GCC visibility pop +#endif +#endif /* IO_H */ diff -Nru luasocket-3.0~rc1+git+ac3201d/src/ltn12.lua luasocket-3.1.0/src/ltn12.lua --- luasocket-3.0~rc1+git+ac3201d/src/ltn12.lua 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/ltn12.lua 2022-08-11 13:08:58.000000000 +0000 @@ -11,9 +11,11 @@ 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 + ltn12 = _M -- luacheck: ignore end local filter,source,sink,pump = {},{},{},{} @@ -22,9 +24,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 _M._VERSION = "LTN12 1.0.3" @@ -46,7 +45,7 @@ -- (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) @@ -128,6 +127,16 @@ else return source.empty() end end +-- creates table source +function source.table(t) + base.assert('table' == type(t)) + local i = 0 + return function() + i = i + 1 + return t[i] + end +end + -- creates rewindable source function source.rewind(src) base.assert(src) diff -Nru luasocket-3.0~rc1+git+ac3201d/src/luasocket.c luasocket-3.1.0/src/luasocket.c --- luasocket-3.0~rc1+git+ac3201d/src/luasocket.c 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/luasocket.c 2022-08-11 13:08:58.000000000 +0000 @@ -12,16 +12,6 @@ * standard Lua read and write functions. \*=========================================================================*/ -/*=========================================================================*\ -* Standard include files -\*=========================================================================*/ -#include "lua.h" -#include "lauxlib.h" -#include "compat.h" - -/*=========================================================================*\ -* LuaSocket includes -\*=========================================================================*/ #include "luasocket.h" #include "auxiliar.h" #include "except.h" @@ -64,7 +54,7 @@ * Skip a few arguments \*-------------------------------------------------------------------------*/ static int global_skip(lua_State *L) { - int amount = luaL_checkinteger(L, 1); + int amount = (int) luaL_checkinteger(L, 1); int ret = lua_gettop(L) - amount - 1; return ret >= 0 ? ret : 0; } diff -Nru luasocket-3.0~rc1+git+ac3201d/src/luasocket.h luasocket-3.1.0/src/luasocket.h --- luasocket-3.0~rc1+git+ac3201d/src/luasocket.h 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/luasocket.h 2022-08-11 13:08:58.000000000 +0000 @@ -6,21 +6,28 @@ * Diego Nehab * 9/11/1999 \*=========================================================================*/ -#include "lua.h" -/*-------------------------------------------------------------------------*\ +/*-------------------------------------------------------------------------* \ * Current socket library version \*-------------------------------------------------------------------------*/ -#define LUASOCKET_VERSION "LuaSocket 3.0-rc1" +#define LUASOCKET_VERSION "LuaSocket 3.0.0" #define LUASOCKET_COPYRIGHT "Copyright (C) 1999-2013 Diego Nehab" /*-------------------------------------------------------------------------*\ * This macro prefixes all exported API functions \*-------------------------------------------------------------------------*/ #ifndef LUASOCKET_API -#define LUASOCKET_API extern +#ifdef _WIN32 +#define LUASOCKET_API __declspec(dllexport) +#else +#define LUASOCKET_API __attribute__ ((visibility ("default"))) +#endif #endif +#include "lua.h" +#include "lauxlib.h" +#include "compat.h" + /*-------------------------------------------------------------------------*\ * Initializes the library. \*-------------------------------------------------------------------------*/ diff -Nru luasocket-3.0~rc1+git+ac3201d/src/makefile luasocket-3.1.0/src/makefile --- luasocket-3.0~rc1+git+ac3201d/src/makefile 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/makefile 2022-08-11 13:08:58.000000000 +0000 @@ -12,11 +12,11 @@ # # make PLAT=linux DEBUG=DEBUG LUAV=5.2 prefix=/sw -# PLAT: linux macosx win32 mingw +# PLAT: linux macosx win32 win64 mingw # platform to build for PLAT?=linux -# LUAV: 5.1 5.2 +# LUAV: 5.1 5.2 5.3 5.4 # lua version to build against LUAV?=5.1 @@ -35,7 +35,8 @@ # LUAINC_macosx: # /opt/local/include LUAINC_macosx_base?=/opt/local/include -LUAINC_macosx?=$(LUAINC_macosx_base)/lua/$(LUAV) +LUAINC_macosx?=$(LUAINC_macosx_base)/lua/$(LUAV) $(LUAINC_macosx_base)/lua$(LUAV) $(LUAINC_macosx_base)/lua-$(LUAV) + # FIXME default should this default to fink or to macports? # What happens when more than one Lua version is installed? LUAPREFIX_macosx?=/opt/local @@ -48,7 +49,7 @@ # /usr/local/include/lua$(LUAV) # where lua headers are found for linux builds LUAINC_linux_base?=/usr/include -LUAINC_linux?=$(LUAINC_linux_base)/lua/$(LUAV) +LUAINC_linux?=$(LUAINC_linux_base)/lua/$(LUAV) $(LUAINC_linux_base)/lua$(LUAV) LUAPREFIX_linux?=/usr/local CDIR_linux?=lib/lua/$(LUAV) LDIR_linux?=share/lua/$(LUAV) @@ -57,7 +58,7 @@ # /usr/local/include/lua$(LUAV) # where lua headers are found for freebsd builds LUAINC_freebsd_base?=/usr/local/include/ -LUAINC_freebsd?=$(LUAINC_freebsd_base)/lua$(LUAV) +LUAINC_freebsd?=$(LUAINC_freebsd_base)/lua/$(LUAV) $(LUAINC_freebsd_base)/lua$(LUAV) LUAPREFIX_freebsd?=/usr/local/ CDIR_freebsd?=lib/lua/$(LUAV) LDIR_freebsd?=share/lua/$(LUAV) @@ -66,7 +67,7 @@ # LUAINC_mingw: # /opt/local/include LUAINC_mingw_base?=/usr/include -LUAINC_mingw?=$(LUAINC_mingw_base)/lua/$(LUAV) +LUAINC_mingw?=$(LUAINC_mingw_base)/lua/$(LUAV) $(LUAINC_mingw_base)/lua$(LUAV) LUALIB_mingw_base?=/usr/bin LUALIB_mingw?=$(LUALIB_mingw_base)/lua/$(LUAV)/lua$(subst .,,$(LUAV)).dll LUAPREFIX_mingw?=/usr @@ -78,17 +79,28 @@ # LUALIB_win32: # where lua headers and libraries are found for win32 builds LUAPREFIX_win32?= -LUAINC_win32?=$(LUAPREFIX_win32)/include/lua/$(LUAV) +LUAINC_win32?=$(LUAPREFIX_win32)/include/lua/$(LUAV) $(LUAPREFIX_win32)/include/lua$(LUAV) PLATFORM_win32?=Release CDIR_win32?=bin/lua/$(LUAV)/$(PLATFORM_win32) LDIR_win32?=bin/lua/$(LUAV)/$(PLATFORM_win32)/lua LUALIB_win32?=$(LUAPREFIX_win32)/lib/lua/$(LUAV)/$(PLATFORM_win32) -LUALIBNAME_win32?=lua$(subst .,,$(LUAV)).lib +LUALIBNAME_win32?=lua$(subst .,,$(LUAV)).lib + +# LUAINC_win64: +# LUALIB_win64: +# where lua headers and libraries are found for win64 builds +LUAPREFIX_win64?= +LUAINC_win64?=$(LUAPREFIX_win64)/include/lua/$(LUAV) $(LUAPREFIX_win64)/include/lua$(LUAV) +PLATFORM_win64?=x64/Release +CDIR_win64?=bin/lua/$(LUAV)/$(PLATFORM_win64) +LDIR_win64?=bin/lua/$(LUAV)/$(PLATFORM_win64)/lua +LUALIB_win64?=$(LUAPREFIX_win64)/lib/lua/$(LUAV)/$(PLATFORM_win64) +LUALIBNAME_win64?=lua$(subst .,,$(LUAV)).lib # LUAINC_solaris: LUAINC_solaris_base?=/usr/include -LUAINC_solaris?=$(LUAINC_solaris_base)/lua/$(LUAV) +LUAINC_solaris?=$(LUAINC_solaris_base)/lua/$(LUAV) $(LUAINC_solaris_base)/lua$(LUAV) LUAPREFIX_solaris?=/usr/local CDIR_solaris?=lib/lua/$(LUAV) LDIR_solaris?=share/lua/$(LUAV) @@ -141,7 +153,7 @@ #------ # Supported platforms # -PLATS= macosx linux win32 mingw solaris +PLATS= macosx linux win32 win64 mingw solaris #------ # Compiler and linker settings @@ -149,14 +161,10 @@ SO_macosx=so O_macosx=o CC_macosx=gcc -DEF_macosx= -DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN \ - -DLUASOCKET_API='__attribute__((visibility("default")))' \ - -DUNIX_API='__attribute__((visibility("default")))' \ - -DMIME_API='__attribute__((visibility("default")))' -CFLAGS_macosx= -I$(LUAINC) $(DEF) -Wall -O2 -fno-common \ - -fvisibility=hidden -LDFLAGS_macosx= -bundle -undefined dynamic_lookup -o -LD_macosx= export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc +DEF_macosx= -DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN +CFLAGS_macosx=$(LUAINC:%=-I%) $(DEF) -Wall -O2 -fno-common +LDFLAGS_macosx= -bundle -undefined dynamic_lookup -o +LD_macosx=gcc SOCKET_macosx=usocket.o #------ @@ -165,13 +173,10 @@ SO_linux=so O_linux=o CC_linux=gcc -DEF_linux=-DLUASOCKET_$(DEBUG) \ - -DLUASOCKET_API='__attribute__((visibility("default")))' \ - -DUNIX_API='__attribute__((visibility("default")))' \ - -DMIME_API='__attribute__((visibility("default")))' -CFLAGS_linux= -I$(LUAINC) $(DEF) -Wall -Wshadow -Wextra \ - -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden -LDFLAGS_linux=-O -shared -fpic -o +DEF_linux=-DLUASOCKET_$(DEBUG) +CFLAGS_linux=$(LUAINC:%=-I%) $(DEF) -Wall -Wshadow -Wextra \ + -Wimplicit -O2 -ggdb3 -fpic +LDFLAGS_linux=-O -shared -fpic -o LD_linux=gcc SOCKET_linux=usocket.o @@ -181,13 +186,10 @@ SO_freebsd=so O_freebsd=o CC_freebsd=gcc -DEF_freebsd=-DLUASOCKET_$(DEBUG) \ - -DLUASOCKET_API='__attribute__((visibility("default")))' \ - -DUNIX_API='__attribute__((visibility("default")))' \ - -DMIME_API='__attribute__((visibility("default")))' -CFLAGS_freebsd= -I$(LUAINC) $(DEF) -Wall -Wshadow -Wextra \ - -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden -LDFLAGS_freebsd=-O -shared -fpic -o +DEF_freebsd=-DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN +CFLAGS_freebsd=$(LUAINC:%=-I%) $(DEF) -Wall -Wshadow -Wextra \ + -Wimplicit -O2 -ggdb3 -fpic +LDFLAGS_freebsd=-O -shared -fpic -o LD_freebsd=gcc SOCKET_freebsd=usocket.o @@ -197,13 +199,10 @@ SO_solaris=so O_solaris=o CC_solaris=gcc -DEF_solaris=-DLUASOCKET_$(DEBUG) \ - -DLUASOCKET_API='__attribute__((visibility("default")))' \ - -DUNIX_API='__attribute__((visibility("default")))' \ - -DMIME_API='__attribute__((visibility("default")))' -CFLAGS_solaris=-I$(LUAINC) $(DEF) -Wall -Wshadow -Wextra \ - -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden -LDFLAGS_solaris=-lnsl -lsocket -lresolv -O -shared -fpic -o +DEF_solaris=-DLUASOCKET_$(DEBUG) +CFLAGS_solaris=$(LUAINC:%=-I%) $(DEF) -Wall -Wshadow -Wextra \ + -Wimplicit -O2 -ggdb3 -fpic +LDFLAGS_solaris=-lnsl -lsocket -lresolv -O -shared -fpic -o LD_solaris=gcc SOCKET_solaris=usocket.o @@ -213,12 +212,10 @@ SO_mingw=dll O_mingw=o CC_mingw=gcc -DEF_mingw= -DLUASOCKET_INET_PTON -DLUASOCKET_$(DEBUG) \ - -DWINVER=0x0501 -DLUASOCKET_API='__declspec(dllexport)' \ - -DMIME_API='__declspec(dllexport)' -CFLAGS_mingw= -I$(LUAINC) $(DEF) -Wall -O2 -fno-common \ - -fvisibility=hidden -LDFLAGS_mingw= $(LUALIB) -shared -Wl,-s -lws2_32 -o +DEF_mingw= -DLUASOCKET_$(DEBUG) \ + -DWINVER=0x0501 +CFLAGS_mingw=$(LUAINC:%=-I%) $(DEF) -Wall -O2 -fno-common +LDFLAGS_mingw= $(LUALIB) -shared -Wl,-s -lws2_32 -o LD_mingw=gcc SOCKET_mingw=wsocket.o @@ -230,19 +227,41 @@ O_win32=obj CC_win32=cl DEF_win32= //D "WIN32" //D "NDEBUG" //D "_WINDOWS" //D "_USRDLL" \ - //D "LUASOCKET_API=__declspec(dllexport)" //D "_CRT_SECURE_NO_WARNINGS" \ - //D "_WINDLL" //D "MIME_API=__declspec(dllexport)" \ - //D "LUASOCKET_$(DEBUG)" -CFLAGS_win32=//I "$(LUAINC)" $(DEF) //O2 //Ot //MD //W3 //nologo + //D "_CRT_SECURE_NO_WARNINGS" \ + //D "_WINDLL" \ + //D "LUASOCKET_$(DEBUG)" +CFLAGS_win32=$(LUAINC:%=//I "%") $(DEF) //O2 //Ot //MD //W3 //nologo LDFLAGS_win32= //nologo //link //NOLOGO //DLL //INCREMENTAL:NO \ //MANIFEST //MANIFESTFILE:"intermediate.manifest" \ - //MANIFESTUAC:"level='asInvoker' uiAccess='false'" \ + /MANIFESTUAC:"level='asInvoker' uiAccess='false'" \ //SUBSYSTEM:WINDOWS //OPT:REF //OPT:ICF //DYNAMICBASE:NO \ - //MACHINE:X86 /LIBPATH:"$(shell cmd //c echo $(LUALIB))" \ + //MACHINE:X86 /LIBPATH:"$(LUALIB)" \ $(LUALIBNAME_win32) ws2_32.lib //OUT: + LD_win32=cl SOCKET_win32=wsocket.obj +#------ +# Compiler and linker settings +# for Win64 +SO_win64=dll +O_win64=obj +CC_win64=cl +DEF_win64= //D "WIN32" //D "NDEBUG" //D "_WINDOWS" //D "_USRDLL" \ + //D "_CRT_SECURE_NO_WARNINGS" \ + //D "_WINDLL" \ + //D "LUASOCKET_$(DEBUG)" +CFLAGS_win64=$(LUAINC:%=//I "%") $(DEF) //O2 //Ot //MD //W3 //nologo +LDFLAGS_win64= //nologo //link //NOLOGO //DLL //INCREMENTAL:NO \ + //MANIFEST //MANIFESTFILE:"intermediate.manifest" \ + /MANIFESTUAC:"level='asInvoker' uiAccess='false'" \ + //SUBSYSTEM:WINDOWS //OPT:REF //OPT:ICF //DYNAMICBASE:NO \ + /LIBPATH:"$(LUALIB)" \ + $(LUALIBNAME_win64) ws2_32.lib //OUT: + +LD_win64=cl +SOCKET_win64=wsocket.obj + .SUFFIXES: .obj .c.obj: @@ -253,7 +272,7 @@ # SO=$(SO_$(PLAT)) O=$(O_$(PLAT)) -SOCKET_V=3.0-rc1 +SOCKET_V=3.0.0 MIME_V=1.0.3 SOCKET_SO=socket-$(SOCKET_V).$(SO) MIME_SO=mime-$(MIME_V).$(SO) @@ -307,8 +326,8 @@ timeout.$(O) \ io.$(O) \ usocket.$(O) \ - unixtcp.$(O) \ - unixudp.$(O) \ + unixstream.$(O) \ + unixdgram.$(O) \ compat.$(O) \ unix.$(O) @@ -317,6 +336,7 @@ # SERIAL_OBJS=\ buffer.$(O) \ + compat.$(O) \ auxiliar.$(O) \ options.$(O) \ timeout.$(O) \ @@ -355,12 +375,15 @@ win32: $(MAKE) all PLAT=win32 +win64: + $(MAKE) all PLAT=win64 + linux: $(MAKE) all-unix PLAT=linux mingw: $(MAKE) all PLAT=mingw - + solaris: $(MAKE) all-unix PLAT=solaris @@ -386,7 +409,7 @@ $(SERIAL_SO): $(SERIAL_OBJS) $(LD) $(SERIAL_OBJS) $(LDFLAGS)$@ -install: +install: $(INSTALL_DIR) $(INSTALL_TOP_LDIR) $(INSTALL_DATA) $(TO_TOP_LDIR) $(INSTALL_TOP_LDIR) $(INSTALL_DIR) $(INSTALL_SOCKET_LDIR) diff -Nru luasocket-3.0~rc1+git+ac3201d/src/mbox.lua luasocket-3.1.0/src/mbox.lua --- luasocket-3.0~rc1+git+ac3201d/src/mbox.lua 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/mbox.lua 2022-08-11 13:08:58.000000000 +0000 @@ -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 @@ 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 @@ 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 @@ 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 -Nru luasocket-3.0~rc1+git+ac3201d/src/mime.c luasocket-3.1.0/src/mime.c --- luasocket-3.0~rc1+git+ac3201d/src/mime.c 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/mime.c 2022-08-11 13:08:58.000000000 +0000 @@ -2,13 +2,10 @@ * MIME support functions * LuaSocket toolkit \*=========================================================================*/ -#include - -#include "lua.h" -#include "lauxlib.h" -#include "compat.h" - +#include "luasocket.h" #include "mime.h" +#include +#include /*=========================================================================*\ * Don't want to trust escape character constants @@ -30,12 +27,12 @@ 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, @@ -58,17 +55,111 @@ /*-------------------------------------------------------------------------*\ * Quoted-printable globals \*-------------------------------------------------------------------------*/ -static UC qpclass[256]; -static UC qpbase[] = "0123456789ABCDEF"; -static UC qpunbase[256]; enum {QP_PLAIN, QP_QUOTED, QP_CR, QP_IF_LAST}; +static const UC qpclass[] = { + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_IF_LAST, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_CR, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_IF_LAST, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_QUOTED, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, QP_PLAIN, + QP_PLAIN, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED, + QP_QUOTED, QP_QUOTED, QP_QUOTED, QP_QUOTED +}; + +static const UC qpbase[] = "0123456789ABCDEF"; + +static const UC qpunbase[] = { + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 255, + 255, 255, 255, 255, 255, 255, 10, 11, 12, 13, 14, 15, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 10, 11, 12, 13, 14, 15, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255 +}; + /*-------------------------------------------------------------------------*\ * Base64 globals \*-------------------------------------------------------------------------*/ static const UC b64base[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -static UC b64unbase[256]; + +static const UC b64unbase[] = { + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 62, 255, 255, 255, 63, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255, 255, 0, + 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, + 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 255, 255, + 255, 255, 255, 255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, + 51, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255 +}; /*=========================================================================*\ * Exported functions @@ -76,7 +167,7 @@ /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -MIME_API int luaopen_mime_core(lua_State *L) +LUASOCKET_API int luaopen_mime_core(lua_State *L) { lua_newtable(L); luaL_setfuncs(L, func, 0); @@ -85,8 +176,8 @@ lua_pushstring(L, MIME_VERSION); lua_rawset(L, -3); /* initialize lookup tables */ - qpsetup(qpclass, qpunbase); - b64setup(b64unbase); + /*qpsetup(qpclass, qpunbase);*/ + /*b64setup(b64unbase);*/ return 1; } @@ -142,6 +233,7 @@ return 2; } +#if 0 /*-------------------------------------------------------------------------*\ * Fill base64 decode map. \*-------------------------------------------------------------------------*/ @@ -151,7 +243,14 @@ for (i = 0; i <= 255; i++) unbase[i] = (UC) 255; for (i = 0; i < 64; i++) unbase[b64base[i]] = (UC) i; unbase['='] = 0; + + printf("static const UC b64unbase[] = {\n"); + for (int i = 0; i < 256; i++) { + printf("%d, ", unbase[i]); + } + printf("\n}\n;"); } +#endif /*-------------------------------------------------------------------------*\ * Acumulates bytes in input buffer until 3 bytes are available. @@ -345,12 +444,14 @@ * To encode one byte, we need to see the next two. * Worst case is when we see a space, and wonder if a CRLF is comming \*-------------------------------------------------------------------------*/ +#if 0 /*-------------------------------------------------------------------------*\ * Split quoted-printable characters into classes * Precompute reverse map for encoding \*-------------------------------------------------------------------------*/ static void qpsetup(UC *cl, UC *unbase) { + int i; for (i = 0; i < 256; i++) cl[i] = QP_QUOTED; for (i = 33; i <= 60; i++) cl[i] = QP_PLAIN; @@ -367,7 +468,37 @@ unbase['c'] = 12; unbase['D'] = 13; unbase['d'] = 13; unbase['E'] = 14; unbase['e'] = 14; unbase['F'] = 15; unbase['f'] = 15; + +printf("static UC qpclass[] = {"); + for (int i = 0; i < 256; i++) { + if (i % 6 == 0) { + printf("\n "); + } + switch(cl[i]) { + case QP_QUOTED: + printf("QP_QUOTED, "); + break; + case QP_PLAIN: + printf("QP_PLAIN, "); + break; + case QP_CR: + printf("QP_CR, "); + break; + case QP_IF_LAST: + printf("QP_IF_LAST, "); + break; + } + } +printf("\n};\n"); + +printf("static const UC qpunbase[] = {"); + for (int i = 0; i < 256; i++) { + int c = qpunbase[i]; + printf("%d, ", c); + } +printf("\";\n"); } +#endif /*-------------------------------------------------------------------------*\ * Output one character in form =XX @@ -447,7 +578,6 @@ \*-------------------------------------------------------------------------*/ static int mime_global_qp(lua_State *L) { - size_t asize = 0, isize = 0; UC atom[3]; const UC *input = (const UC *) luaL_optlstring(L, 1, NULL, &isize); @@ -654,7 +784,7 @@ \*-------------------------------------------------------------------------*/ static int mime_global_eol(lua_State *L) { - int ctx = luaL_checkinteger(L, 1); + int ctx = (int) luaL_checkinteger(L, 1); size_t isize = 0; const char *input = luaL_optlstring(L, 2, NULL, &isize); const char *last = input + isize; @@ -689,6 +819,7 @@ case '.': if (state == 2) luaL_addchar(buffer, '.'); + /* Falls through. */ default: return 0; } diff -Nru luasocket-3.0~rc1+git+ac3201d/src/mime.h luasocket-3.1.0/src/mime.h --- luasocket-3.0~rc1+git+ac3201d/src/mime.h 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/mime.h 2022-08-11 13:08:58.000000000 +0000 @@ -8,7 +8,7 @@ * and formatting conforming to RFC 2045. It is used by mime.lua, which * provide a higher level interface to this functionality. \*=========================================================================*/ -#include "lua.h" +#include "luasocket.h" /*-------------------------------------------------------------------------*\ * Current MIME library version @@ -17,13 +17,6 @@ #define MIME_COPYRIGHT "Copyright (C) 2004-2013 Diego Nehab" #define MIME_AUTHORS "Diego Nehab" -/*-------------------------------------------------------------------------*\ -* This macro prefixes all exported API functions -\*-------------------------------------------------------------------------*/ -#ifndef MIME_API -#define MIME_API extern -#endif - -MIME_API int luaopen_mime_core(lua_State *L); +LUASOCKET_API int luaopen_mime_core(lua_State *L); #endif /* MIME_H */ diff -Nru luasocket-3.0~rc1+git+ac3201d/src/mime.lua luasocket-3.1.0/src/mime.lua --- luasocket-3.0~rc1+git+ac3201d/src/mime.lua 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/mime.lua 2022-08-11 13:08:58.000000000 +0000 @@ -10,8 +10,6 @@ local base = _G local ltn12 = require("ltn12") local mime = require("mime.core") -local io = require("io") -local string = require("string") local _M = mime -- encode, decode and wrap algorithm tables @@ -19,7 +17,7 @@ _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) @@ -28,7 +26,7 @@ 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 @@ -53,13 +51,6 @@ 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 @@ -87,4 +78,4 @@ return ltn12.filter.cycle(_M.dot, 2) end -return _M \ No newline at end of file +return _M diff -Nru luasocket-3.0~rc1+git+ac3201d/src/options.c luasocket-3.1.0/src/options.c --- luasocket-3.0~rc1+git+ac3201d/src/options.c 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/options.c 2022-08-11 13:08:58.000000000 +0000 @@ -2,14 +2,11 @@ * Common option interface * LuaSocket toolkit \*=========================================================================*/ -#include - -#include "lauxlib.h" - +#include "luasocket.h" #include "auxiliar.h" #include "options.h" #include "inet.h" - +#include /*=========================================================================*\ * Internal functions prototypes @@ -37,7 +34,7 @@ while (opt->name && strcmp(name, opt->name)) opt++; if (!opt->func) { - char msg[45]; + char msg[57]; sprintf(msg, "unsupported option `%.35s'", name); luaL_argerror(L, 2, msg); } @@ -50,13 +47,14 @@ while (opt->name && strcmp(name, opt->name)) opt++; if (!opt->func) { - char msg[45]; + char msg[57]; sprintf(msg, "unsupported option `%.35s'", name); luaL_argerror(L, 2, msg); } return opt->func(L, ps); } +/*------------------------------------------------------*/ /* enables reuse of local address */ int opt_set_reuseaddr(lua_State *L, p_socket ps) { @@ -68,6 +66,7 @@ return opt_getboolean(L, ps, SOL_SOCKET, SO_REUSEADDR); } +/*------------------------------------------------------*/ /* enables reuse of local port */ int opt_set_reuseport(lua_State *L, p_socket ps) { @@ -79,7 +78,8 @@ return opt_getboolean(L, ps, SOL_SOCKET, SO_REUSEPORT); } -/* disables the Naggle algorithm */ +/*------------------------------------------------------*/ +/* disables the Nagle algorithm */ int opt_set_tcp_nodelay(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, IPPROTO_TCP, TCP_NODELAY); @@ -90,6 +90,52 @@ return opt_getboolean(L, ps, IPPROTO_TCP, TCP_NODELAY); } +/*------------------------------------------------------*/ +#ifdef TCP_KEEPIDLE + +int opt_get_tcp_keepidle(lua_State *L, p_socket ps) +{ + return opt_getint(L, ps, IPPROTO_TCP, TCP_KEEPIDLE); +} + +int opt_set_tcp_keepidle(lua_State *L, p_socket ps) +{ + return opt_setint(L, ps, IPPROTO_TCP, TCP_KEEPIDLE); +} + +#endif + +/*------------------------------------------------------*/ +#ifdef TCP_KEEPCNT + +int opt_get_tcp_keepcnt(lua_State *L, p_socket ps) +{ + return opt_getint(L, ps, IPPROTO_TCP, TCP_KEEPCNT); +} + +int opt_set_tcp_keepcnt(lua_State *L, p_socket ps) +{ + return opt_setint(L, ps, IPPROTO_TCP, TCP_KEEPCNT); +} + +#endif + +/*------------------------------------------------------*/ +#ifdef TCP_KEEPINTVL + +int opt_get_tcp_keepintvl(lua_State *L, p_socket ps) +{ + return opt_getint(L, ps, IPPROTO_TCP, TCP_KEEPINTVL); +} + +int opt_set_tcp_keepintvl(lua_State *L, p_socket ps) +{ + return opt_setint(L, ps, IPPROTO_TCP, TCP_KEEPINTVL); +} + +#endif + +/*------------------------------------------------------*/ int opt_set_keepalive(lua_State *L, p_socket ps) { return opt_setboolean(L, ps, SOL_SOCKET, SO_KEEPALIVE); @@ -100,6 +146,7 @@ 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); @@ -110,6 +157,7 @@ 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); @@ -120,6 +168,54 @@ 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); +} + +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); +} + +int opt_set_send_buf_size(lua_State *L, p_socket ps) +{ + return opt_setint(L, ps, SOL_SOCKET, SO_SNDBUF); +} + +// /*------------------------------------------------------*/ + +#ifdef TCP_FASTOPEN +int opt_set_tcp_fastopen(lua_State *L, p_socket ps) +{ + return opt_setint(L, ps, IPPROTO_TCP, TCP_FASTOPEN); +} +#endif + +#ifdef TCP_FASTOPEN_CONNECT +int opt_set_tcp_fastopen_connect(lua_State *L, p_socket ps) +{ + return opt_setint(L, ps, IPPROTO_TCP, TCP_FASTOPEN_CONNECT); +} +#endif + +/*------------------------------------------------------*/ + +#ifdef TCP_DEFER_ACCEPT +int opt_set_tcp_defer_accept(lua_State *L, p_socket ps) +{ + return opt_setint(L, ps, IPPROTO_TCP, TCP_DEFER_ACCEPT); +} +#endif + +/*------------------------------------------------------*/ int opt_set_ip6_unicast_hops(lua_State *L, p_socket ps) { return opt_setint(L, ps, IPPROTO_IPV6, IPV6_UNICAST_HOPS); @@ -130,6 +226,7 @@ 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); @@ -140,6 +237,7 @@ 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); @@ -150,6 +248,7 @@ 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); @@ -160,6 +259,7 @@ 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 */ @@ -192,11 +292,13 @@ 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 */ @@ -221,6 +323,7 @@ return 1; } +/*------------------------------------------------------*/ int opt_set_ip_add_membership(lua_State *L, p_socket ps) { return opt_setmembership(L, ps, IPPROTO_IP, IP_ADD_MEMBERSHIP); @@ -231,6 +334,7 @@ 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); @@ -241,6 +345,7 @@ 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); @@ -251,6 +356,20 @@ return opt_setboolean(L, ps, IPPROTO_IPV6, IPV6_V6ONLY); } +/*------------------------------------------------------*/ +int opt_get_error(lua_State *L, p_socket ps) +{ + int val = 0; + socklen_t len = sizeof(val); + if (getsockopt(*ps, SOL_SOCKET, SO_ERROR, (char *) &val, &len) < 0) { + lua_pushnil(L); + lua_pushstring(L, "getsockopt failed"); + return 2; + } + lua_pushstring(L, socket_strerror(val)); + return 1; +} + /*=========================================================================*\ * Auxiliar functions \*=========================================================================*/ @@ -337,19 +456,6 @@ return 1; } -int opt_get_error(lua_State *L, p_socket ps) -{ - int val = 0; - socklen_t len = sizeof(val); - if (getsockopt(*ps, SOL_SOCKET, SO_ERROR, (char *) &val, &len) < 0) { - lua_pushnil(L); - lua_pushstring(L, "getsockopt failed"); - return 2; - } - lua_pushstring(L, socket_strerror(val)); - return 1; -} - static int opt_setboolean(lua_State *L, p_socket ps, int level, int name) { int val = auxiliar_checkboolean(L, 3); /* obj, name, bool */ diff -Nru luasocket-3.0~rc1+git+ac3201d/src/options.h luasocket-3.1.0/src/options.h --- luasocket-3.0~rc1+git+ac3201d/src/options.h 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/options.h 2022-08-11 13:08:58.000000000 +0000 @@ -8,7 +8,7 @@ * modules UDP and TCP. \*=========================================================================*/ -#include "lua.h" +#include "luasocket.h" #include "socket.h" /* option registry */ @@ -18,45 +18,96 @@ } t_opt; typedef t_opt *p_opt; -/* supported options for setoption */ -int opt_set_dontroute(lua_State *L, p_socket ps); -int opt_set_broadcast(lua_State *L, p_socket ps); +#ifndef _WIN32 +#pragma GCC visibility push(hidden) +#endif + +int opt_meth_setoption(lua_State *L, p_opt opt, p_socket ps); +int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps); + +int opt_set_reuseaddr(lua_State *L, p_socket ps); +int opt_get_reuseaddr(lua_State *L, p_socket ps); + +int opt_set_reuseport(lua_State *L, p_socket ps); +int opt_get_reuseport(lua_State *L, p_socket ps); + int opt_set_tcp_nodelay(lua_State *L, p_socket ps); +int opt_get_tcp_nodelay(lua_State *L, p_socket ps); + +#ifdef TCP_KEEPIDLE +int opt_set_tcp_keepidle(lua_State *L, p_socket ps); +int opt_get_tcp_keepidle(lua_State *L, p_socket ps); +#endif + +#ifdef TCP_KEEPCNT +int opt_set_tcp_keepcnt(lua_State *L, p_socket ps); +int opt_get_tcp_keepcnt(lua_State *L, p_socket ps); +#endif + +#ifdef TCP_KEEPINTVL +int opt_set_tcp_keepintvl(lua_State *L, p_socket ps); +int opt_get_tcp_keepintvl(lua_State *L, p_socket ps); +#endif + +#ifdef TCP_DEFER_ACCEPT +int opt_set_tcp_defer_accept(lua_State *L, p_socket ps); +#endif + int opt_set_keepalive(lua_State *L, p_socket ps); +int opt_get_keepalive(lua_State *L, p_socket ps); + +int opt_set_dontroute(lua_State *L, p_socket ps); +int opt_get_dontroute(lua_State *L, p_socket ps); + +int opt_set_broadcast(lua_State *L, p_socket ps); +int opt_get_broadcast(lua_State *L, p_socket ps); + +int opt_set_recv_buf_size(lua_State *L, p_socket ps); +int opt_get_recv_buf_size(lua_State *L, p_socket ps); + +int opt_set_send_buf_size(lua_State *L, p_socket ps); +int opt_get_send_buf_size(lua_State *L, p_socket ps); + +#ifdef TCP_FASTOPEN +int opt_set_tcp_fastopen(lua_State *L, p_socket ps); +#endif +#ifdef TCP_FASTOPEN_CONNECT +int opt_set_tcp_fastopen_connect(lua_State *L, p_socket ps); +#endif + +int opt_set_ip6_unicast_hops(lua_State *L, p_socket ps); +int opt_get_ip6_unicast_hops(lua_State *L, p_socket ps); + +int opt_set_ip6_multicast_hops(lua_State *L, p_socket ps); +int opt_get_ip6_multicast_hops(lua_State *L, p_socket ps); + +int opt_set_ip_multicast_loop(lua_State *L, p_socket ps); +int opt_get_ip_multicast_loop(lua_State *L, p_socket ps); + +int opt_set_ip6_multicast_loop(lua_State *L, p_socket ps); +int opt_get_ip6_multicast_loop(lua_State *L, p_socket ps); + int opt_set_linger(lua_State *L, p_socket ps); -int opt_set_reuseaddr(lua_State *L, p_socket ps); -int opt_set_reuseport(lua_State *L, p_socket ps); -int opt_set_ip_multicast_if(lua_State *L, p_socket ps); +int opt_get_linger(lua_State *L, p_socket ps); + int opt_set_ip_multicast_ttl(lua_State *L, p_socket ps); -int opt_set_ip_multicast_loop(lua_State *L, p_socket ps); + +int opt_set_ip_multicast_if(lua_State *L, p_socket ps); +int opt_get_ip_multicast_if(lua_State *L, p_socket ps); + int opt_set_ip_add_membership(lua_State *L, p_socket ps); int opt_set_ip_drop_membersip(lua_State *L, p_socket ps); -int opt_set_ip6_unicast_hops(lua_State *L, p_socket ps); -int opt_set_ip6_multicast_hops(lua_State *L, p_socket ps); -int opt_set_ip6_multicast_loop(lua_State *L, p_socket ps); + int opt_set_ip6_add_membership(lua_State *L, p_socket ps); int opt_set_ip6_drop_membersip(lua_State *L, p_socket ps); + int opt_set_ip6_v6only(lua_State *L, p_socket ps); +int opt_get_ip6_v6only(lua_State *L, p_socket ps); -/* supported options for getoption */ -int opt_get_dontroute(lua_State *L, p_socket ps); -int opt_get_broadcast(lua_State *L, p_socket ps); -int opt_get_reuseaddr(lua_State *L, p_socket ps); -int opt_get_reuseport(lua_State *L, p_socket ps); -int opt_get_tcp_nodelay(lua_State *L, p_socket ps); -int opt_get_keepalive(lua_State *L, p_socket ps); -int opt_get_linger(lua_State *L, p_socket ps); -int opt_get_ip_multicast_loop(lua_State *L, p_socket ps); -int opt_get_ip_multicast_if(lua_State *L, p_socket ps); int opt_get_error(lua_State *L, p_socket ps); -int opt_get_ip6_multicast_loop(lua_State *L, p_socket ps); -int opt_get_ip6_multicast_hops(lua_State *L, p_socket ps); -int opt_get_ip6_unicast_hops(lua_State *L, p_socket ps); -int opt_get_ip6_v6only(lua_State *L, p_socket ps); -int opt_get_reuseport(lua_State *L, p_socket ps); -/* invokes the appropriate option handler */ -int opt_meth_setoption(lua_State *L, p_opt opt, p_socket ps); -int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps); +#ifndef _WIN32 +#pragma GCC visibility pop +#endif #endif diff -Nru luasocket-3.0~rc1+git+ac3201d/src/select.c luasocket-3.1.0/src/select.c --- luasocket-3.0~rc1+git+ac3201d/src/select.c 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/select.c 2022-08-11 13:08:58.000000000 +0000 @@ -2,16 +2,14 @@ * Select implementation * LuaSocket toolkit \*=========================================================================*/ -#include - -#include "lua.h" -#include "lauxlib.h" -#include "compat.h" +#include "luasocket.h" #include "socket.h" #include "timeout.h" #include "select.h" +#include + /*=========================================================================*\ * Internal function prototypes. \*=========================================================================*/ @@ -31,9 +29,6 @@ {NULL, NULL} }; -/*=========================================================================*\ -* Exported functions -\*=========================================================================*/ /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ @@ -217,4 +212,3 @@ i = i+1; } } - diff -Nru luasocket-3.0~rc1+git+ac3201d/src/select.h luasocket-3.1.0/src/select.h --- luasocket-3.0~rc1+git+ac3201d/src/select.h 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/select.h 2022-08-11 13:08:58.000000000 +0000 @@ -10,6 +10,14 @@ * true if there is data ready for reading (required for buffered input). \*=========================================================================*/ +#ifndef _WIN32 +#pragma GCC visibility push(hidden) +#endif + int select_open(lua_State *L); +#ifndef _WIN32 +#pragma GCC visibility pop +#endif + #endif /* SELECT_H */ diff -Nru luasocket-3.0~rc1+git+ac3201d/src/serial.c luasocket-3.1.0/src/serial.c --- luasocket-3.0~rc1+git+ac3201d/src/serial.c 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/serial.c 2022-08-11 13:08:58.000000000 +0000 @@ -2,15 +2,14 @@ * Serial stream * LuaSocket toolkit \*=========================================================================*/ -#include - -#include "lua.h" -#include "lauxlib.h" +#include "luasocket.h" #include "auxiliar.h" #include "socket.h" #include "options.h" #include "unix.h" + +#include #include /* diff -Nru luasocket-3.0~rc1+git+ac3201d/src/socket.h luasocket-3.1.0/src/socket.h --- luasocket-3.0~rc1+git+ac3201d/src/socket.h 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/socket.h 2022-08-11 13:08:58.000000000 +0000 @@ -16,8 +16,10 @@ \*=========================================================================*/ #ifdef _WIN32 #include "wsocket.h" +#define LUA_GAI_STRERROR gai_strerrorA #else #include "usocket.h" +#define LUA_GAI_STRERROR gai_strerror #endif /*=========================================================================*\ @@ -28,51 +30,46 @@ \*=========================================================================*/ #include "timeout.h" -/* we are lazy... */ +/* convenient shorthand */ typedef struct sockaddr SA; /*=========================================================================*\ * Functions bellow implement a comfortable platform independent * interface to sockets \*=========================================================================*/ -int socket_open(void); -int socket_close(void); -void socket_destroy(p_socket ps); -void socket_shutdown(p_socket ps, int how); -int socket_sendto(p_socket ps, const char *data, size_t count, - size_t *sent, SA *addr, socklen_t addr_len, p_timeout tm); -int socket_recvfrom(p_socket ps, char *data, size_t count, - size_t *got, SA *addr, socklen_t *addr_len, p_timeout tm); -void socket_setnonblocking(p_socket ps); -void socket_setblocking(p_socket ps); +#ifndef _WIN32 +#pragma GCC visibility push(hidden) +#endif int socket_waitfd(p_socket ps, int sw, p_timeout tm); -int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds, - p_timeout tm); - -int socket_connect(p_socket ps, SA *addr, socklen_t addr_len, p_timeout tm); +int socket_open(void); +int socket_close(void); +void socket_destroy(p_socket ps); +int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds, p_timeout tm); int socket_create(p_socket ps, int domain, int type, int protocol); int socket_bind(p_socket ps, SA *addr, socklen_t addr_len); int socket_listen(p_socket ps, int backlog); -int socket_accept(p_socket ps, p_socket pa, SA *addr, - socklen_t *addr_len, p_timeout tm); - -const char *socket_hoststrerror(int err); -const char *socket_gaistrerror(int err); -const char *socket_strerror(int err); - -/* these are perfect to use with the io abstraction module - and the buffered input module */ -int socket_send(p_socket ps, const char *data, size_t count, - size_t *sent, p_timeout tm); +void socket_shutdown(p_socket ps, int how); +int socket_connect(p_socket ps, SA *addr, socklen_t addr_len, p_timeout tm); +int socket_accept(p_socket ps, p_socket pa, SA *addr, socklen_t *addr_len, p_timeout tm); +int socket_send(p_socket ps, const char *data, size_t count, size_t *sent, p_timeout tm); +int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent, SA *addr, socklen_t addr_len, p_timeout tm); int socket_recv(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm); -int socket_write(p_socket ps, const char *data, size_t count, - size_t *sent, p_timeout tm); +int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got, SA *addr, socklen_t *addr_len, p_timeout tm); +int socket_write(p_socket ps, const char *data, size_t count, size_t *sent, p_timeout tm); int socket_read(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm); -const char *socket_ioerror(p_socket ps, int err); - +void socket_setblocking(p_socket ps); +void socket_setnonblocking(p_socket ps); int socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp); int socket_gethostbyname(const char *addr, struct hostent **hp); +const char *socket_hoststrerror(int err); +const char *socket_strerror(int err); +const char *socket_ioerror(p_socket ps, int err); +const char *socket_gaistrerror(int err); + +#ifndef _WIN32 +#pragma GCC visibility pop +#endif #endif /* SOCKET_H */ diff -Nru luasocket-3.0~rc1+git+ac3201d/src/tcp.c luasocket-3.1.0/src/tcp.c --- luasocket-3.0~rc1+git+ac3201d/src/tcp.c 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/tcp.c 2022-08-11 13:08:58.000000000 +0000 @@ -2,11 +2,7 @@ * TCP object * LuaSocket toolkit \*=========================================================================*/ -#include - -#include "lua.h" -#include "lauxlib.h" -#include "compat.h" +#include "luasocket.h" #include "auxiliar.h" #include "socket.h" @@ -14,6 +10,8 @@ #include "options.h" #include "tcp.h" +#include + /*=========================================================================*\ * Internal function prototypes \*=========================================================================*/ @@ -77,8 +75,19 @@ {"reuseaddr", opt_get_reuseaddr}, {"reuseport", opt_get_reuseport}, {"tcp-nodelay", opt_get_tcp_nodelay}, +#ifdef TCP_KEEPIDLE + {"tcp-keepidle", opt_get_tcp_keepidle}, +#endif +#ifdef TCP_KEEPCNT + {"tcp-keepcnt", opt_get_tcp_keepcnt}, +#endif +#ifdef TCP_KEEPINTVL + {"tcp-keepintvl", opt_get_tcp_keepintvl}, +#endif {"linger", opt_get_linger}, {"error", opt_get_error}, + {"recv-buffer-size", opt_get_recv_buf_size}, + {"send-buffer-size", opt_get_send_buf_size}, {NULL, NULL} }; @@ -87,8 +96,28 @@ {"reuseaddr", opt_set_reuseaddr}, {"reuseport", opt_set_reuseport}, {"tcp-nodelay", opt_set_tcp_nodelay}, +#ifdef TCP_KEEPIDLE + {"tcp-keepidle", opt_set_tcp_keepidle}, +#endif +#ifdef TCP_KEEPCNT + {"tcp-keepcnt", opt_set_tcp_keepcnt}, +#endif +#ifdef TCP_KEEPINTVL + {"tcp-keepintvl", opt_set_tcp_keepintvl}, +#endif {"ipv6-v6only", opt_set_ip6_v6only}, {"linger", opt_set_linger}, + {"recv-buffer-size", opt_set_recv_buf_size}, + {"send-buffer-size", opt_set_send_buf_size}, +#ifdef TCP_DEFER_ACCEPT + {"tcp-defer-accept", opt_set_tcp_defer_accept}, +#endif +#ifdef TCP_FASTOPEN + {"tcp-fastopen", opt_set_tcp_fastopen}, +#endif +#ifdef TCP_FASTOPEN_CONNECT + {"tcp-fastopen-connect", opt_set_tcp_fastopen_connect}, +#endif {NULL, NULL} }; diff -Nru luasocket-3.0~rc1+git+ac3201d/src/tcp.h luasocket-3.1.0/src/tcp.h --- luasocket-3.0~rc1+git+ac3201d/src/tcp.h 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/tcp.h 2022-08-11 13:08:58.000000000 +0000 @@ -14,7 +14,7 @@ * tcp objects either connected to some address or returned by the accept * method of a server object. \*=========================================================================*/ -#include "lua.h" +#include "luasocket.h" #include "buffer.h" #include "timeout.h" @@ -30,6 +30,14 @@ typedef t_tcp *p_tcp; +#ifndef _WIN32 +#pragma GCC visibility push(hidden) +#endif + int tcp_open(lua_State *L); +#ifndef _WIN32 +#pragma GCC visibility pop +#endif + #endif /* TCP_H */ diff -Nru luasocket-3.0~rc1+git+ac3201d/src/timeout.c luasocket-3.1.0/src/timeout.c --- luasocket-3.0~rc1+git+ac3201d/src/timeout.c 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/timeout.c 2022-08-11 13:08:58.000000000 +0000 @@ -2,17 +2,15 @@ * Timeout management functions * LuaSocket toolkit \*=========================================================================*/ -#include -#include -#include - -#include "lua.h" -#include "lauxlib.h" -#include "compat.h" +#include "luasocket.h" #include "auxiliar.h" #include "timeout.h" +#include +#include +#include + #ifdef _WIN32 #include #else diff -Nru luasocket-3.0~rc1+git+ac3201d/src/timeout.h luasocket-3.1.0/src/timeout.h --- luasocket-3.0~rc1+git+ac3201d/src/timeout.h 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/timeout.h 2022-08-11 13:08:58.000000000 +0000 @@ -4,7 +4,7 @@ * Timeout management functions * LuaSocket toolkit \*=========================================================================*/ -#include "lua.h" +#include "luasocket.h" /* timeout control structure */ typedef struct t_timeout_ { @@ -14,16 +14,27 @@ } t_timeout; typedef t_timeout *p_timeout; -int timeout_open(lua_State *L); +#ifndef _WIN32 +#pragma GCC visibility push(hidden) +#endif + void timeout_init(p_timeout tm, double block, double total); double timeout_get(p_timeout tm); +double timeout_getstart(p_timeout tm); double timeout_getretry(p_timeout tm); p_timeout timeout_markstart(p_timeout tm); -double timeout_getstart(p_timeout tm); + double timeout_gettime(void); + +int timeout_open(lua_State *L); + int timeout_meth_settimeout(lua_State *L, p_timeout tm); int timeout_meth_gettimeout(lua_State *L, p_timeout tm); +#ifndef _WIN32 +#pragma GCC visibility pop +#endif + #define timeout_iszero(tm) ((tm)->block == 0.0) #endif /* TIMEOUT_H */ diff -Nru luasocket-3.0~rc1+git+ac3201d/src/udp.c luasocket-3.1.0/src/udp.c --- luasocket-3.0~rc1+git+ac3201d/src/udp.c 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/udp.c 2022-08-11 13:08:58.000000000 +0000 @@ -2,12 +2,7 @@ * UDP object * LuaSocket toolkit \*=========================================================================*/ -#include -#include - -#include "lua.h" -#include "lauxlib.h" -#include "compat.h" +#include "luasocket.h" #include "auxiliar.h" #include "socket.h" @@ -15,6 +10,9 @@ #include "options.h" #include "udp.h" +#include +#include + /* min and max macros */ #ifndef MIN #define MIN(x, y) ((x) < (y) ? x : y) @@ -88,6 +86,8 @@ {"ipv6-add-membership", opt_set_ip6_add_membership}, {"ipv6-drop-membership", opt_set_ip6_drop_membersip}, {"ipv6-v6only", opt_set_ip6_v6only}, + {"recv-buffer-size", opt_set_recv_buf_size}, + {"send-buffer-size", opt_set_send_buf_size}, {NULL, NULL} }; @@ -104,6 +104,8 @@ {"ipv6-multicast-hops", opt_get_ip6_unicast_hops}, {"ipv6-multicast-loop", opt_get_ip6_multicast_loop}, {"ipv6-v6only", opt_get_ip6_v6only}, + {"recv-buffer-size", opt_get_recv_buf_size}, + {"send-buffer-size", opt_get_send_buf_size}, {NULL, NULL} }; @@ -182,13 +184,37 @@ memset(&aihint, 0, sizeof(aihint)); aihint.ai_family = udp->family; aihint.ai_socktype = SOCK_DGRAM; - aihint.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV; + aihint.ai_flags = AI_NUMERICHOST; +#ifdef AI_NUMERICSERV + aihint.ai_flags |= AI_NUMERICSERV; +#endif err = getaddrinfo(ip, port, &aihint, &ai); if (err) { lua_pushnil(L); - lua_pushstring(L, gai_strerror(err)); + lua_pushstring(L, LUA_GAI_STRERROR(err)); return 2; } + + /* create socket if on first sendto if AF_UNSPEC was set */ + if (udp->family == AF_UNSPEC && udp->sock == SOCKET_INVALID) { + struct addrinfo *ap; + const char *errstr = NULL; + for (ap = ai; ap != NULL; ap = ap->ai_next) { + errstr = inet_trycreate(&udp->sock, ap->ai_family, SOCK_DGRAM, 0); + if (errstr == NULL) { + socket_setnonblocking(&udp->sock); + udp->family = ap->ai_family; + break; + } + } + if (errstr != NULL) { + lua_pushnil(L); + lua_pushstring(L, errstr); + freeaddrinfo(ai); + return 2; + } + } + timeout_markstart(tm); err = socket_sendto(&udp->sock, data, count, &sent, ai->ai_addr, (socklen_t) ai->ai_addrlen, tm); @@ -264,7 +290,7 @@ INET6_ADDRSTRLEN, portstr, 6, NI_NUMERICHOST | NI_NUMERICSERV); if (err) { lua_pushnil(L); - lua_pushstring(L, gai_strerror(err)); + lua_pushstring(L, LUA_GAI_STRERROR(err)); if (wanted > sizeof(buf)) free(dgram); return 2; } diff -Nru luasocket-3.0~rc1+git+ac3201d/src/udp.h luasocket-3.1.0/src/udp.h --- luasocket-3.0~rc1+git+ac3201d/src/udp.h 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/udp.h 2022-08-11 13:08:58.000000000 +0000 @@ -12,7 +12,7 @@ * with a call to the setpeername function. The same function can be used to * break the connection. \*=========================================================================*/ -#include "lua.h" +#include "luasocket.h" #include "timeout.h" #include "socket.h" @@ -26,6 +26,14 @@ } t_udp; typedef t_udp *p_udp; +#ifndef _WIN32 +#pragma GCC visibility push(hidden) +#endif + int udp_open(lua_State *L); +#ifndef _WIN32 +#pragma GCC visibility pop +#endif + #endif /* UDP_H */ diff -Nru luasocket-3.0~rc1+git+ac3201d/src/unix.c luasocket-3.1.0/src/unix.c --- luasocket-3.0~rc1+git+ac3201d/src/unix.c 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/unix.c 2022-08-11 13:08:58.000000000 +0000 @@ -2,29 +2,68 @@ * Unix domain socket * LuaSocket toolkit \*=========================================================================*/ -#include "lua.h" -#include "lauxlib.h" +#include "luasocket.h" -#include "unixtcp.h" -#include "unixudp.h" +#include "unixstream.h" +#include "unixdgram.h" /*-------------------------------------------------------------------------*\ * Modules and functions \*-------------------------------------------------------------------------*/ static const luaL_Reg mod[] = { - {"tcp", unixtcp_open}, - {"udp", unixudp_open}, + {"stream", unixstream_open}, + {"dgram", unixdgram_open}, {NULL, NULL} }; +static void add_alias(lua_State *L, int index, const char *name, const char *target) +{ + lua_getfield(L, index, target); + lua_setfield(L, index, name); +} + +static int compat_socket_unix_call(lua_State *L) +{ + /* Look up socket.unix.stream in the socket.unix table (which is the first + * argument). */ + lua_getfield(L, 1, "stream"); + + /* Replace the stack entry for the socket.unix table with the + * socket.unix.stream function. */ + lua_replace(L, 1); + + /* Call socket.unix.stream, passing along any arguments. */ + int n = lua_gettop(L); + lua_call(L, n-1, LUA_MULTRET); + + /* Pass along the return values from socket.unix.stream. */ + n = lua_gettop(L); + return n; +} + /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -int luaopen_socket_unix(lua_State *L) +LUASOCKET_API int luaopen_socket_unix(lua_State *L) { - int i; - lua_newtable(L); - for (i = 0; mod[i].name; i++) mod[i].func(L); - return 1; -} + int i; + lua_newtable(L); + int socket_unix_table = lua_gettop(L); + + for (i = 0; mod[i].name; i++) + mod[i].func(L); + /* Add backwards compatibility aliases "tcp" and "udp" for the "stream" and + * "dgram" functions. */ + add_alias(L, socket_unix_table, "tcp", "stream"); + add_alias(L, socket_unix_table, "udp", "dgram"); + + /* Add a backwards compatibility function and a metatable setup to call it + * for the old socket.unix() interface. */ + lua_pushcfunction(L, compat_socket_unix_call); + lua_setfield(L, socket_unix_table, "__call"); + lua_pushvalue(L, socket_unix_table); + lua_setmetatable(L, socket_unix_table); + + return 1; +} diff -Nru luasocket-3.0~rc1+git+ac3201d/src/unixdgram.c luasocket-3.1.0/src/unixdgram.c --- luasocket-3.0~rc1+git+ac3201d/src/unixdgram.c 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/src/unixdgram.c 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,405 @@ +/*=========================================================================*\ +* Unix domain socket dgram submodule +* LuaSocket toolkit +\*=========================================================================*/ +#include "luasocket.h" + +#include "auxiliar.h" +#include "socket.h" +#include "options.h" +#include "unix.h" + +#include +#include + +#include + +#define UNIXDGRAM_DATAGRAMSIZE 8192 + +/* 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) \ + + strlen ((ptr)->sun_path)) +#endif + +/*=========================================================================*\ +* Internal function prototypes +\*=========================================================================*/ +static int global_create(lua_State *L); +static int meth_connect(lua_State *L); +static int meth_bind(lua_State *L); +static int meth_send(lua_State *L); +static int meth_receive(lua_State *L); +static int meth_close(lua_State *L); +static int meth_setoption(lua_State *L); +static int meth_settimeout(lua_State *L); +static int meth_gettimeout(lua_State *L); +static int meth_getfd(lua_State *L); +static int meth_setfd(lua_State *L); +static int meth_dirty(lua_State *L); +static int meth_receivefrom(lua_State *L); +static int meth_sendto(lua_State *L); +static int meth_getsockname(lua_State *L); + +static const char *unixdgram_tryconnect(p_unix un, const char *path); +static const char *unixdgram_trybind(p_unix un, const char *path); + +/* unixdgram object methods */ +static luaL_Reg unixdgram_methods[] = { + {"__gc", meth_close}, + {"__tostring", auxiliar_tostring}, + {"bind", meth_bind}, + {"close", meth_close}, + {"connect", meth_connect}, + {"dirty", meth_dirty}, + {"getfd", meth_getfd}, + {"send", meth_send}, + {"sendto", meth_sendto}, + {"receive", meth_receive}, + {"receivefrom", meth_receivefrom}, + {"setfd", meth_setfd}, + {"setoption", meth_setoption}, + {"setpeername", meth_connect}, + {"setsockname", meth_bind}, + {"getsockname", meth_getsockname}, + {"settimeout", meth_settimeout}, + {"gettimeout", meth_gettimeout}, + {NULL, NULL} +}; + +/* socket option handlers */ +static t_opt optset[] = { + {"reuseaddr", opt_set_reuseaddr}, + {NULL, NULL} +}; + +/* functions in library namespace */ +static luaL_Reg func[] = { + {"dgram", global_create}, + {NULL, NULL} +}; + +/*-------------------------------------------------------------------------*\ +* Initializes module +\*-------------------------------------------------------------------------*/ +int unixdgram_open(lua_State *L) +{ + /* create classes */ + auxiliar_newclass(L, "unixdgram{connected}", unixdgram_methods); + auxiliar_newclass(L, "unixdgram{unconnected}", unixdgram_methods); + /* create class groups */ + auxiliar_add2group(L, "unixdgram{connected}", "unixdgram{any}"); + auxiliar_add2group(L, "unixdgram{unconnected}", "unixdgram{any}"); + auxiliar_add2group(L, "unixdgram{connected}", "select{able}"); + auxiliar_add2group(L, "unixdgram{unconnected}", "select{able}"); + + luaL_setfuncs(L, func, 0); + return 0; +} + +/*=========================================================================*\ +* Lua methods +\*=========================================================================*/ +static const char *unixdgram_strerror(int err) +{ + /* a 'closed' error on an unconnected means the target address was not + * accepted by the transport layer */ + if (err == IO_CLOSED) return "refused"; + else return socket_strerror(err); +} + +static int meth_send(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkclass(L, "unixdgram{connected}", 1); + p_timeout tm = &un->tm; + size_t count, sent = 0; + int err; + const char *data = luaL_checklstring(L, 2, &count); + timeout_markstart(tm); + err = socket_send(&un->sock, data, count, &sent, tm); + if (err != IO_DONE) { + lua_pushnil(L); + lua_pushstring(L, unixdgram_strerror(err)); + return 2; + } + lua_pushnumber(L, (lua_Number) sent); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Send data through unconnected unixdgram socket +\*-------------------------------------------------------------------------*/ +static int meth_sendto(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkclass(L, "unixdgram{unconnected}", 1); + size_t count, sent = 0; + const char *data = luaL_checklstring(L, 2, &count); + const char *path = luaL_checkstring(L, 3); + p_timeout tm = &un->tm; + int err; + struct sockaddr_un remote; + size_t len = strlen(path); + + if (len >= sizeof(remote.sun_path)) { + lua_pushnil(L); + lua_pushstring(L, "path too long"); + return 2; + } + + memset(&remote, 0, sizeof(remote)); + strcpy(remote.sun_path, path); + remote.sun_family = AF_UNIX; + timeout_markstart(tm); +#ifdef UNIX_HAS_SUN_LEN + remote.sun_len = sizeof(remote.sun_family) + sizeof(remote.sun_len) + + len + 1; + err = socket_sendto(&un->sock, data, count, &sent, (SA *) &remote, remote.sun_len, tm); +#else + err = socket_sendto(&un->sock, data, count, &sent, (SA *) &remote, + sizeof(remote.sun_family) + len, tm); +#endif + if (err != IO_DONE) { + lua_pushnil(L); + lua_pushstring(L, unixdgram_strerror(err)); + return 2; + } + lua_pushnumber(L, (lua_Number) sent); + return 1; +} + +static int meth_receive(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); + char buf[UNIXDGRAM_DATAGRAMSIZE]; + size_t got, wanted = (size_t) luaL_optnumber(L, 2, sizeof(buf)); + char *dgram = wanted > sizeof(buf)? (char *) malloc(wanted): buf; + int err; + p_timeout tm = &un->tm; + timeout_markstart(tm); + if (!dgram) { + lua_pushnil(L); + lua_pushliteral(L, "out of memory"); + return 2; + } + err = socket_recv(&un->sock, dgram, wanted, &got, tm); + /* Unlike STREAM, recv() of zero is not closed, but a zero-length packet. */ + if (err != IO_DONE && err != IO_CLOSED) { + lua_pushnil(L); + lua_pushstring(L, unixdgram_strerror(err)); + if (wanted > sizeof(buf)) free(dgram); + return 2; + } + lua_pushlstring(L, dgram, got); + if (wanted > sizeof(buf)) free(dgram); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Receives data and sender from a DGRAM socket +\*-------------------------------------------------------------------------*/ +static int meth_receivefrom(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkclass(L, "unixdgram{unconnected}", 1); + char buf[UNIXDGRAM_DATAGRAMSIZE]; + size_t got, wanted = (size_t) luaL_optnumber(L, 2, sizeof(buf)); + char *dgram = wanted > sizeof(buf)? (char *) malloc(wanted): buf; + struct sockaddr_un addr; + socklen_t addr_len = sizeof(addr); + int err; + p_timeout tm = &un->tm; + timeout_markstart(tm); + if (!dgram) { + lua_pushnil(L); + lua_pushliteral(L, "out of memory"); + return 2; + } + addr.sun_path[0] = '\0'; + err = socket_recvfrom(&un->sock, dgram, wanted, &got, (SA *) &addr, + &addr_len, tm); + /* Unlike STREAM, recv() of zero is not closed, but a zero-length packet. */ + if (err != IO_DONE && err != IO_CLOSED) { + lua_pushnil(L); + lua_pushstring(L, unixdgram_strerror(err)); + if (wanted > sizeof(buf)) free(dgram); + return 2; + } + + lua_pushlstring(L, dgram, got); + /* the path may be empty, when client send without bind */ + lua_pushstring(L, addr.sun_path); + if (wanted > sizeof(buf)) free(dgram); + return 2; +} + +/*-------------------------------------------------------------------------*\ +* Just call option handler +\*-------------------------------------------------------------------------*/ +static int meth_setoption(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); + return opt_meth_setoption(L, optset, &un->sock); +} + +/*-------------------------------------------------------------------------*\ +* Select support methods +\*-------------------------------------------------------------------------*/ +static int meth_getfd(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); + lua_pushnumber(L, (int) un->sock); + return 1; +} + +/* this is very dangerous, but can be handy for those that are brave enough */ +static int meth_setfd(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); + un->sock = (t_socket) luaL_checknumber(L, 2); + return 0; +} + +static int meth_dirty(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); + (void) un; + lua_pushboolean(L, 0); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Binds an object to an address +\*-------------------------------------------------------------------------*/ +static const char *unixdgram_trybind(p_unix un, const char *path) { + struct sockaddr_un local; + size_t len = strlen(path); + if (len >= sizeof(local.sun_path)) return "path too long"; + memset(&local, 0, sizeof(local)); + strcpy(local.sun_path, path); + local.sun_family = AF_UNIX; + size_t addrlen = SUN_LEN(&local); +#ifdef UNIX_HAS_SUN_LEN + local.sun_len = addrlen + 1; +#endif + int err = socket_bind(&un->sock, (SA *) &local, addrlen); + if (err != IO_DONE) socket_destroy(&un->sock); + return socket_strerror(err); +} + +static int meth_bind(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkclass(L, "unixdgram{unconnected}", 1); + const char *path = luaL_checkstring(L, 2); + const char *err = unixdgram_trybind(un, path); + if (err) { + lua_pushnil(L); + lua_pushstring(L, err); + return 2; + } + lua_pushnumber(L, 1); + return 1; +} + +static int meth_getsockname(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); + struct sockaddr_un peer = {0}; + socklen_t peer_len = sizeof(peer); + + if (getsockname(un->sock, (SA *) &peer, &peer_len) < 0) { + lua_pushnil(L); + lua_pushstring(L, socket_strerror(errno)); + return 2; + } + + lua_pushstring(L, peer.sun_path); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Turns a master unixdgram object into a client object. +\*-------------------------------------------------------------------------*/ +static const char *unixdgram_tryconnect(p_unix un, const char *path) +{ + struct sockaddr_un remote; + size_t len = strlen(path); + if (len >= sizeof(remote.sun_path)) return "path too long"; + memset(&remote, 0, sizeof(remote)); + strcpy(remote.sun_path, path); + remote.sun_family = AF_UNIX; + timeout_markstart(&un->tm); + size_t addrlen = SUN_LEN(&remote); +#ifdef UNIX_HAS_SUN_LEN + remote.sun_len = addrlen + 1; +#endif + int err = socket_connect(&un->sock, (SA *) &remote, addrlen, &un->tm); + if (err != IO_DONE) socket_destroy(&un->sock); + return socket_strerror(err); +} + +static int meth_connect(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); + const char *path = luaL_checkstring(L, 2); + const char *err = unixdgram_tryconnect(un, path); + if (err) { + lua_pushnil(L); + lua_pushstring(L, err); + return 2; + } + /* turn unconnected object into a connected object */ + auxiliar_setclass(L, "unixdgram{connected}", 1); + lua_pushnumber(L, 1); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Closes socket used by object +\*-------------------------------------------------------------------------*/ +static int meth_close(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); + socket_destroy(&un->sock); + lua_pushnumber(L, 1); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Just call tm methods +\*-------------------------------------------------------------------------*/ +static int meth_settimeout(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); + return timeout_meth_settimeout(L, &un->tm); +} + +static int meth_gettimeout(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); + return timeout_meth_gettimeout(L, &un->tm); +} + +/*=========================================================================*\ +* Library functions +\*=========================================================================*/ +/*-------------------------------------------------------------------------*\ +* Creates a master unixdgram object +\*-------------------------------------------------------------------------*/ +static int global_create(lua_State *L) +{ + t_socket sock; + int err = socket_create(&sock, AF_UNIX, SOCK_DGRAM, 0); + /* try to allocate a system socket */ + if (err == IO_DONE) { + /* allocate unixdgram object */ + p_unix un = (p_unix) lua_newuserdata(L, sizeof(t_unix)); + /* set its type as master object */ + auxiliar_setclass(L, "unixdgram{unconnected}", -1); + /* initialize remaining structure fields */ + socket_setnonblocking(&sock); + un->sock = sock; + io_init(&un->io, (p_send) socket_send, (p_recv) socket_recv, + (p_error) socket_ioerror, &un->sock); + timeout_init(&un->tm, -1, -1); + buffer_init(&un->buf, &un->io, &un->tm); + return 1; + } else { + lua_pushnil(L); + lua_pushstring(L, socket_strerror(err)); + return 2; + } +} diff -Nru luasocket-3.0~rc1+git+ac3201d/src/unixdgram.h luasocket-3.1.0/src/unixdgram.h --- luasocket-3.0~rc1+git+ac3201d/src/unixdgram.h 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/src/unixdgram.h 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,28 @@ +#ifndef UNIXDGRAM_H +#define UNIXDGRAM_H +/*=========================================================================*\ +* DGRAM object +* LuaSocket toolkit +* +* The dgram.h module provides LuaSocket with support for DGRAM protocol +* (AF_INET, SOCK_DGRAM). +* +* Two classes are defined: connected and unconnected. DGRAM objects are +* originally unconnected. They can be "connected" to a given address +* with a call to the setpeername function. The same function can be used to +* break the connection. +\*=========================================================================*/ + +#include "unix.h" + +#ifndef _WIN32 +#pragma GCC visibility push(hidden) +#endif + +int unixdgram_open(lua_State *L); + +#ifndef _WIN32 +#pragma GCC visibility pop +#endif + +#endif /* UNIXDGRAM_H */ diff -Nru luasocket-3.0~rc1+git+ac3201d/src/unix.h luasocket-3.1.0/src/unix.h --- luasocket-3.0~rc1+git+ac3201d/src/unix.h 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/unix.h 2022-08-11 13:08:58.000000000 +0000 @@ -7,16 +7,12 @@ * This module is just an example of how to extend LuaSocket with a new * domain. \*=========================================================================*/ -#include "lua.h" +#include "luasocket.h" #include "buffer.h" #include "timeout.h" #include "socket.h" -#ifndef UNIX_API -#define UNIX_API extern -#endif - typedef struct t_unix_ { t_socket sock; t_io io; @@ -25,6 +21,6 @@ } t_unix; typedef t_unix *p_unix; -UNIX_API int luaopen_socket_unix(lua_State *L); +LUASOCKET_API int luaopen_socket_unix(lua_State *L); #endif /* UNIX_H */ diff -Nru luasocket-3.0~rc1+git+ac3201d/src/unixstream.c luasocket-3.1.0/src/unixstream.c --- luasocket-3.0~rc1+git+ac3201d/src/unixstream.c 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/src/unixstream.c 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,355 @@ +/*=========================================================================*\ +* Unix domain socket stream sub module +* LuaSocket toolkit +\*=========================================================================*/ +#include "luasocket.h" + +#include "auxiliar.h" +#include "socket.h" +#include "options.h" +#include "unixstream.h" + +#include +#include + +/*=========================================================================*\ +* Internal function prototypes +\*=========================================================================*/ +static int global_create(lua_State *L); +static int meth_connect(lua_State *L); +static int meth_listen(lua_State *L); +static int meth_bind(lua_State *L); +static int meth_send(lua_State *L); +static int meth_shutdown(lua_State *L); +static int meth_receive(lua_State *L); +static int meth_accept(lua_State *L); +static int meth_close(lua_State *L); +static int meth_setoption(lua_State *L); +static int meth_settimeout(lua_State *L); +static int meth_getfd(lua_State *L); +static int meth_setfd(lua_State *L); +static int meth_dirty(lua_State *L); +static int meth_getstats(lua_State *L); +static int meth_setstats(lua_State *L); +static int meth_getsockname(lua_State *L); + +static const char *unixstream_tryconnect(p_unix un, const char *path); +static const char *unixstream_trybind(p_unix un, const char *path); + +/* unixstream object methods */ +static luaL_Reg unixstream_methods[] = { + {"__gc", meth_close}, + {"__tostring", auxiliar_tostring}, + {"accept", meth_accept}, + {"bind", meth_bind}, + {"close", meth_close}, + {"connect", meth_connect}, + {"dirty", meth_dirty}, + {"getfd", meth_getfd}, + {"getstats", meth_getstats}, + {"setstats", meth_setstats}, + {"listen", meth_listen}, + {"receive", meth_receive}, + {"send", meth_send}, + {"setfd", meth_setfd}, + {"setoption", meth_setoption}, + {"setpeername", meth_connect}, + {"setsockname", meth_bind}, + {"getsockname", meth_getsockname}, + {"settimeout", meth_settimeout}, + {"shutdown", meth_shutdown}, + {NULL, NULL} +}; + +/* socket option handlers */ +static t_opt optset[] = { + {"keepalive", opt_set_keepalive}, + {"reuseaddr", opt_set_reuseaddr}, + {"linger", opt_set_linger}, + {NULL, NULL} +}; + +/* functions in library namespace */ +static luaL_Reg func[] = { + {"stream", global_create}, + {NULL, NULL} +}; + +/*-------------------------------------------------------------------------*\ +* Initializes module +\*-------------------------------------------------------------------------*/ +int unixstream_open(lua_State *L) +{ + /* create classes */ + auxiliar_newclass(L, "unixstream{master}", unixstream_methods); + auxiliar_newclass(L, "unixstream{client}", unixstream_methods); + auxiliar_newclass(L, "unixstream{server}", unixstream_methods); + + /* create class groups */ + auxiliar_add2group(L, "unixstream{master}", "unixstream{any}"); + auxiliar_add2group(L, "unixstream{client}", "unixstream{any}"); + auxiliar_add2group(L, "unixstream{server}", "unixstream{any}"); + + luaL_setfuncs(L, func, 0); + return 0; +} + +/*=========================================================================*\ +* Lua methods +\*=========================================================================*/ +/*-------------------------------------------------------------------------*\ +* Just call buffered IO methods +\*-------------------------------------------------------------------------*/ +static int meth_send(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{client}", 1); + return buffer_meth_send(L, &un->buf); +} + +static int meth_receive(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{client}", 1); + return buffer_meth_receive(L, &un->buf); +} + +static int meth_getstats(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{client}", 1); + return buffer_meth_getstats(L, &un->buf); +} + +static int meth_setstats(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{client}", 1); + return buffer_meth_setstats(L, &un->buf); +} + +/*-------------------------------------------------------------------------*\ +* Just call option handler +\*-------------------------------------------------------------------------*/ +static int meth_setoption(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixstream{any}", 1); + return opt_meth_setoption(L, optset, &un->sock); +} + +/*-------------------------------------------------------------------------*\ +* Select support methods +\*-------------------------------------------------------------------------*/ +static int meth_getfd(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixstream{any}", 1); + lua_pushnumber(L, (int) un->sock); + return 1; +} + +/* this is very dangerous, but can be handy for those that are brave enough */ +static int meth_setfd(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixstream{any}", 1); + un->sock = (t_socket) luaL_checknumber(L, 2); + return 0; +} + +static int meth_dirty(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixstream{any}", 1); + lua_pushboolean(L, !buffer_isempty(&un->buf)); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Waits for and returns a client object attempting connection to the +* server object +\*-------------------------------------------------------------------------*/ +static int meth_accept(lua_State *L) { + p_unix server = (p_unix) auxiliar_checkclass(L, "unixstream{server}", 1); + p_timeout tm = timeout_markstart(&server->tm); + t_socket sock; + int err = socket_accept(&server->sock, &sock, NULL, NULL, tm); + /* if successful, push client socket */ + if (err == IO_DONE) { + p_unix clnt = (p_unix) lua_newuserdata(L, sizeof(t_unix)); + auxiliar_setclass(L, "unixstream{client}", -1); + /* initialize structure fields */ + socket_setnonblocking(&sock); + clnt->sock = sock; + io_init(&clnt->io, (p_send)socket_send, (p_recv)socket_recv, + (p_error) socket_ioerror, &clnt->sock); + timeout_init(&clnt->tm, -1, -1); + buffer_init(&clnt->buf, &clnt->io, &clnt->tm); + return 1; + } else { + lua_pushnil(L); + lua_pushstring(L, socket_strerror(err)); + return 2; + } +} + +/*-------------------------------------------------------------------------*\ +* Binds an object to an address +\*-------------------------------------------------------------------------*/ +static const char *unixstream_trybind(p_unix un, const char *path) { + struct sockaddr_un local; + size_t len = strlen(path); + int err; + if (len >= sizeof(local.sun_path)) return "path too long"; + memset(&local, 0, sizeof(local)); + strcpy(local.sun_path, path); + local.sun_family = AF_UNIX; +#ifdef UNIX_HAS_SUN_LEN + local.sun_len = sizeof(local.sun_family) + sizeof(local.sun_len) + + len + 1; + err = socket_bind(&un->sock, (SA *) &local, local.sun_len); + +#else + err = socket_bind(&un->sock, (SA *) &local, + sizeof(local.sun_family) + len); +#endif + if (err != IO_DONE) socket_destroy(&un->sock); + return socket_strerror(err); +} + +static int meth_bind(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{master}", 1); + const char *path = luaL_checkstring(L, 2); + const char *err = unixstream_trybind(un, path); + if (err) { + lua_pushnil(L); + lua_pushstring(L, err); + return 2; + } + lua_pushnumber(L, 1); + return 1; +} + +static int meth_getsockname(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixstream{any}", 1); + struct sockaddr_un peer = {0}; + socklen_t peer_len = sizeof(peer); + + if (getsockname(un->sock, (SA *) &peer, &peer_len) < 0) { + lua_pushnil(L); + lua_pushstring(L, socket_strerror(errno)); + return 2; + } + + lua_pushstring(L, peer.sun_path); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Turns a master unixstream object into a client object. +\*-------------------------------------------------------------------------*/ +static const char *unixstream_tryconnect(p_unix un, const char *path) +{ + struct sockaddr_un remote; + int err; + size_t len = strlen(path); + if (len >= sizeof(remote.sun_path)) return "path too long"; + memset(&remote, 0, sizeof(remote)); + strcpy(remote.sun_path, path); + remote.sun_family = AF_UNIX; + timeout_markstart(&un->tm); +#ifdef UNIX_HAS_SUN_LEN + remote.sun_len = sizeof(remote.sun_family) + sizeof(remote.sun_len) + + len + 1; + err = socket_connect(&un->sock, (SA *) &remote, remote.sun_len, &un->tm); +#else + err = socket_connect(&un->sock, (SA *) &remote, + sizeof(remote.sun_family) + len, &un->tm); +#endif + if (err != IO_DONE) socket_destroy(&un->sock); + return socket_strerror(err); +} + +static int meth_connect(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{master}", 1); + const char *path = luaL_checkstring(L, 2); + const char *err = unixstream_tryconnect(un, path); + if (err) { + lua_pushnil(L); + lua_pushstring(L, err); + return 2; + } + /* turn master object into a client object */ + auxiliar_setclass(L, "unixstream{client}", 1); + lua_pushnumber(L, 1); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Closes socket used by object +\*-------------------------------------------------------------------------*/ +static int meth_close(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixstream{any}", 1); + socket_destroy(&un->sock); + lua_pushnumber(L, 1); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Puts the sockt in listen mode +\*-------------------------------------------------------------------------*/ +static int meth_listen(lua_State *L) +{ + p_unix un = (p_unix) auxiliar_checkclass(L, "unixstream{master}", 1); + int backlog = (int) luaL_optnumber(L, 2, 32); + int err = socket_listen(&un->sock, backlog); + if (err != IO_DONE) { + lua_pushnil(L); + lua_pushstring(L, socket_strerror(err)); + return 2; + } + /* turn master object into a server object */ + auxiliar_setclass(L, "unixstream{server}", 1); + lua_pushnumber(L, 1); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Shuts the connection down partially +\*-------------------------------------------------------------------------*/ +static int meth_shutdown(lua_State *L) +{ + /* SHUT_RD, SHUT_WR, SHUT_RDWR have the value 0, 1, 2, so we can use method index directly */ + static const char* methods[] = { "receive", "send", "both", NULL }; + p_unix stream = (p_unix) auxiliar_checkclass(L, "unixstream{client}", 1); + int how = luaL_checkoption(L, 2, "both", methods); + socket_shutdown(&stream->sock, how); + lua_pushnumber(L, 1); + return 1; +} + +/*-------------------------------------------------------------------------*\ +* Just call tm methods +\*-------------------------------------------------------------------------*/ +static int meth_settimeout(lua_State *L) { + p_unix un = (p_unix) auxiliar_checkgroup(L, "unixstream{any}", 1); + return timeout_meth_settimeout(L, &un->tm); +} + +/*=========================================================================*\ +* Library functions +\*=========================================================================*/ +/*-------------------------------------------------------------------------*\ +* Creates a master unixstream object +\*-------------------------------------------------------------------------*/ +static int global_create(lua_State *L) { + t_socket sock; + int err = socket_create(&sock, AF_UNIX, SOCK_STREAM, 0); + /* try to allocate a system socket */ + if (err == IO_DONE) { + /* allocate unixstream object */ + p_unix un = (p_unix) lua_newuserdata(L, sizeof(t_unix)); + /* set its type as master object */ + auxiliar_setclass(L, "unixstream{master}", -1); + /* initialize remaining structure fields */ + socket_setnonblocking(&sock); + un->sock = sock; + io_init(&un->io, (p_send) socket_send, (p_recv) socket_recv, + (p_error) socket_ioerror, &un->sock); + timeout_init(&un->tm, -1, -1); + buffer_init(&un->buf, &un->io, &un->tm); + return 1; + } else { + lua_pushnil(L); + lua_pushstring(L, socket_strerror(err)); + return 2; + } +} diff -Nru luasocket-3.0~rc1+git+ac3201d/src/unixstream.h luasocket-3.1.0/src/unixstream.h --- luasocket-3.0~rc1+git+ac3201d/src/unixstream.h 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/src/unixstream.h 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,29 @@ +#ifndef UNIXSTREAM_H +#define UNIXSTREAM_H +/*=========================================================================*\ +* UNIX STREAM object +* LuaSocket toolkit +* +* The unixstream.h module is basicly a glue that puts together modules buffer.h, +* timeout.h socket.h and inet.h to provide the LuaSocket UNIX STREAM (AF_UNIX, +* SOCK_STREAM) support. +* +* Three classes are defined: master, client and server. The master class is +* a newly created unixstream object, that has not been bound or connected. Server +* objects are unixstream objects bound to some local address. Client objects are +* unixstream objects either connected to some address or returned by the accept +* method of a server object. +\*=========================================================================*/ +#include "unix.h" + +#ifndef _WIN32 +#pragma GCC visibility push(hidden) +#endif + +int unixstream_open(lua_State *L); + +#ifndef _WIN32 +#pragma GCC visibility pop +#endif + +#endif /* UNIXSTREAM_H */ diff -Nru luasocket-3.0~rc1+git+ac3201d/src/unixtcp.c luasocket-3.1.0/src/unixtcp.c --- luasocket-3.0~rc1+git+ac3201d/src/unixtcp.c 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/unixtcp.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,357 +0,0 @@ -/*=========================================================================*\ -* Unix domain socket tcp sub module -* LuaSocket toolkit -\*=========================================================================*/ -#include - -#include "lua.h" -#include "lauxlib.h" -#include "compat.h" - -#include "auxiliar.h" -#include "socket.h" -#include "options.h" -#include "unixtcp.h" -#include - -/*=========================================================================*\ -* Internal function prototypes -\*=========================================================================*/ -static int global_create(lua_State *L); -static int meth_connect(lua_State *L); -static int meth_listen(lua_State *L); -static int meth_bind(lua_State *L); -static int meth_send(lua_State *L); -static int meth_shutdown(lua_State *L); -static int meth_receive(lua_State *L); -static int meth_accept(lua_State *L); -static int meth_close(lua_State *L); -static int meth_setoption(lua_State *L); -static int meth_settimeout(lua_State *L); -static int meth_getfd(lua_State *L); -static int meth_setfd(lua_State *L); -static int meth_dirty(lua_State *L); -static int meth_getstats(lua_State *L); -static int meth_setstats(lua_State *L); -static int meth_getsockname(lua_State *L); - -static const char *unixtcp_tryconnect(p_unix un, const char *path); -static const char *unixtcp_trybind(p_unix un, const char *path); - -/* unixtcp object methods */ -static luaL_Reg unixtcp_methods[] = { - {"__gc", meth_close}, - {"__tostring", auxiliar_tostring}, - {"accept", meth_accept}, - {"bind", meth_bind}, - {"close", meth_close}, - {"connect", meth_connect}, - {"dirty", meth_dirty}, - {"getfd", meth_getfd}, - {"getstats", meth_getstats}, - {"setstats", meth_setstats}, - {"listen", meth_listen}, - {"receive", meth_receive}, - {"send", meth_send}, - {"setfd", meth_setfd}, - {"setoption", meth_setoption}, - {"setpeername", meth_connect}, - {"setsockname", meth_bind}, - {"getsockname", meth_getsockname}, - {"settimeout", meth_settimeout}, - {"shutdown", meth_shutdown}, - {NULL, NULL} -}; - -/* socket option handlers */ -static t_opt optset[] = { - {"keepalive", opt_set_keepalive}, - {"reuseaddr", opt_set_reuseaddr}, - {"linger", opt_set_linger}, - {NULL, NULL} -}; - -/* functions in library namespace */ -static luaL_Reg func[] = { - {"tcp", global_create}, - {NULL, NULL} -}; - -/*-------------------------------------------------------------------------*\ -* Initializes module -\*-------------------------------------------------------------------------*/ -int unixtcp_open(lua_State *L) -{ - /* create classes */ - auxiliar_newclass(L, "unixtcp{master}", unixtcp_methods); - auxiliar_newclass(L, "unixtcp{client}", unixtcp_methods); - auxiliar_newclass(L, "unixtcp{server}", unixtcp_methods); - - /* create class groups */ - auxiliar_add2group(L, "unixtcp{master}", "unixtcp{any}"); - auxiliar_add2group(L, "unixtcp{client}", "unixtcp{any}"); - auxiliar_add2group(L, "unixtcp{server}", "unixtcp{any}"); - - luaL_setfuncs(L, func, 0); - return 0; -} - -/*=========================================================================*\ -* Lua methods -\*=========================================================================*/ -/*-------------------------------------------------------------------------*\ -* Just call buffered IO methods -\*-------------------------------------------------------------------------*/ -static int meth_send(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkclass(L, "unixtcp{client}", 1); - return buffer_meth_send(L, &un->buf); -} - -static int meth_receive(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkclass(L, "unixtcp{client}", 1); - return buffer_meth_receive(L, &un->buf); -} - -static int meth_getstats(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkclass(L, "unixtcp{client}", 1); - return buffer_meth_getstats(L, &un->buf); -} - -static int meth_setstats(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkclass(L, "unixtcp{client}", 1); - return buffer_meth_setstats(L, &un->buf); -} - -/*-------------------------------------------------------------------------*\ -* Just call option handler -\*-------------------------------------------------------------------------*/ -static int meth_setoption(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixtcp{any}", 1); - return opt_meth_setoption(L, optset, &un->sock); -} - -/*-------------------------------------------------------------------------*\ -* Select support methods -\*-------------------------------------------------------------------------*/ -static int meth_getfd(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixtcp{any}", 1); - lua_pushnumber(L, (int) un->sock); - return 1; -} - -/* this is very dangerous, but can be handy for those that are brave enough */ -static int meth_setfd(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixtcp{any}", 1); - un->sock = (t_socket) luaL_checknumber(L, 2); - return 0; -} - -static int meth_dirty(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixtcp{any}", 1); - lua_pushboolean(L, !buffer_isempty(&un->buf)); - return 1; -} - -/*-------------------------------------------------------------------------*\ -* Waits for and returns a client object attempting connection to the -* server object -\*-------------------------------------------------------------------------*/ -static int meth_accept(lua_State *L) { - p_unix server = (p_unix) auxiliar_checkclass(L, "unixtcp{server}", 1); - p_timeout tm = timeout_markstart(&server->tm); - t_socket sock; - int err = socket_accept(&server->sock, &sock, NULL, NULL, tm); - /* if successful, push client socket */ - if (err == IO_DONE) { - p_unix clnt = (p_unix) lua_newuserdata(L, sizeof(t_unix)); - auxiliar_setclass(L, "unixtcp{client}", -1); - /* initialize structure fields */ - socket_setnonblocking(&sock); - clnt->sock = sock; - io_init(&clnt->io, (p_send)socket_send, (p_recv)socket_recv, - (p_error) socket_ioerror, &clnt->sock); - timeout_init(&clnt->tm, -1, -1); - buffer_init(&clnt->buf, &clnt->io, &clnt->tm); - return 1; - } else { - lua_pushnil(L); - lua_pushstring(L, socket_strerror(err)); - return 2; - } -} - -/*-------------------------------------------------------------------------*\ -* Binds an object to an address -\*-------------------------------------------------------------------------*/ -static const char *unixtcp_trybind(p_unix un, const char *path) { - struct sockaddr_un local; - size_t len = strlen(path); - int err; - if (len >= sizeof(local.sun_path)) return "path too long"; - memset(&local, 0, sizeof(local)); - strcpy(local.sun_path, path); - local.sun_family = AF_UNIX; -#ifdef UNIX_HAS_SUN_LEN - local.sun_len = sizeof(local.sun_family) + sizeof(local.sun_len) - + len + 1; - err = socket_bind(&un->sock, (SA *) &local, local.sun_len); - -#else - err = socket_bind(&un->sock, (SA *) &local, - sizeof(local.sun_family) + len); -#endif - if (err != IO_DONE) socket_destroy(&un->sock); - return socket_strerror(err); -} - -static int meth_bind(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkclass(L, "unixtcp{master}", 1); - const char *path = luaL_checkstring(L, 2); - const char *err = unixtcp_trybind(un, path); - if (err) { - lua_pushnil(L); - lua_pushstring(L, err); - return 2; - } - lua_pushnumber(L, 1); - return 1; -} - -static int meth_getsockname(lua_State *L) -{ - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixtcp{any}", 1); - struct sockaddr_un peer = {0}; - socklen_t peer_len = sizeof(peer); - - if (getsockname(un->sock, (SA *) &peer, &peer_len) < 0) { - lua_pushnil(L); - lua_pushstring(L, socket_strerror(errno)); - return 2; - } - - lua_pushstring(L, peer.sun_path); - return 1; -} - -/*-------------------------------------------------------------------------*\ -* Turns a master unixtcp object into a client object. -\*-------------------------------------------------------------------------*/ -static const char *unixtcp_tryconnect(p_unix un, const char *path) -{ - struct sockaddr_un remote; - int err; - size_t len = strlen(path); - if (len >= sizeof(remote.sun_path)) return "path too long"; - memset(&remote, 0, sizeof(remote)); - strcpy(remote.sun_path, path); - remote.sun_family = AF_UNIX; - timeout_markstart(&un->tm); -#ifdef UNIX_HAS_SUN_LEN - remote.sun_len = sizeof(remote.sun_family) + sizeof(remote.sun_len) - + len + 1; - err = socket_connect(&un->sock, (SA *) &remote, remote.sun_len, &un->tm); -#else - err = socket_connect(&un->sock, (SA *) &remote, - sizeof(remote.sun_family) + len, &un->tm); -#endif - if (err != IO_DONE) socket_destroy(&un->sock); - return socket_strerror(err); -} - -static int meth_connect(lua_State *L) -{ - p_unix un = (p_unix) auxiliar_checkclass(L, "unixtcp{master}", 1); - const char *path = luaL_checkstring(L, 2); - const char *err = unixtcp_tryconnect(un, path); - if (err) { - lua_pushnil(L); - lua_pushstring(L, err); - return 2; - } - /* turn master object into a client object */ - auxiliar_setclass(L, "unixtcp{client}", 1); - lua_pushnumber(L, 1); - return 1; -} - -/*-------------------------------------------------------------------------*\ -* Closes socket used by object -\*-------------------------------------------------------------------------*/ -static int meth_close(lua_State *L) -{ - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixtcp{any}", 1); - socket_destroy(&un->sock); - lua_pushnumber(L, 1); - return 1; -} - -/*-------------------------------------------------------------------------*\ -* Puts the sockt in listen mode -\*-------------------------------------------------------------------------*/ -static int meth_listen(lua_State *L) -{ - p_unix un = (p_unix) auxiliar_checkclass(L, "unixtcp{master}", 1); - int backlog = (int) luaL_optnumber(L, 2, 32); - int err = socket_listen(&un->sock, backlog); - if (err != IO_DONE) { - lua_pushnil(L); - lua_pushstring(L, socket_strerror(err)); - return 2; - } - /* turn master object into a server object */ - auxiliar_setclass(L, "unixtcp{server}", 1); - lua_pushnumber(L, 1); - return 1; -} - -/*-------------------------------------------------------------------------*\ -* Shuts the connection down partially -\*-------------------------------------------------------------------------*/ -static int meth_shutdown(lua_State *L) -{ - /* SHUT_RD, SHUT_WR, SHUT_RDWR have the value 0, 1, 2, so we can use method index directly */ - static const char* methods[] = { "receive", "send", "both", NULL }; - p_unix tcp = (p_unix) auxiliar_checkclass(L, "unixtcp{client}", 1); - int how = luaL_checkoption(L, 2, "both", methods); - socket_shutdown(&tcp->sock, how); - lua_pushnumber(L, 1); - return 1; -} - -/*-------------------------------------------------------------------------*\ -* Just call tm methods -\*-------------------------------------------------------------------------*/ -static int meth_settimeout(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixtcp{any}", 1); - return timeout_meth_settimeout(L, &un->tm); -} - -/*=========================================================================*\ -* Library functions -\*=========================================================================*/ -/*-------------------------------------------------------------------------*\ -* Creates a master unixtcp object -\*-------------------------------------------------------------------------*/ -static int global_create(lua_State *L) { - t_socket sock; - int err = socket_create(&sock, AF_UNIX, SOCK_STREAM, 0); - /* try to allocate a system socket */ - if (err == IO_DONE) { - /* allocate unixtcp object */ - p_unix un = (p_unix) lua_newuserdata(L, sizeof(t_unix)); - /* set its type as master object */ - auxiliar_setclass(L, "unixtcp{master}", -1); - /* initialize remaining structure fields */ - socket_setnonblocking(&sock); - un->sock = sock; - io_init(&un->io, (p_send) socket_send, (p_recv) socket_recv, - (p_error) socket_ioerror, &un->sock); - timeout_init(&un->tm, -1, -1); - buffer_init(&un->buf, &un->io, &un->tm); - return 1; - } else { - lua_pushnil(L); - lua_pushstring(L, socket_strerror(err)); - return 2; - } -} diff -Nru luasocket-3.0~rc1+git+ac3201d/src/unixtcp.h luasocket-3.1.0/src/unixtcp.h --- luasocket-3.0~rc1+git+ac3201d/src/unixtcp.h 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/unixtcp.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,21 +0,0 @@ -#ifndef UNIXTCP_H -#define UNIXTCP_H -/*=========================================================================*\ -* UNIX TCP object -* LuaSocket toolkit -* -* The unixtcp.h module is basicly a glue that puts together modules buffer.h, -* timeout.h socket.h and inet.h to provide the LuaSocket UNIX TCP (AF_UNIX, -* SOCK_STREAM) support. -* -* Three classes are defined: master, client and server. The master class is -* a newly created unixtcp object, that has not been bound or connected. Server -* objects are unixtcp objects bound to some local address. Client objects are -* unixtcp objects either connected to some address or returned by the accept -* method of a server object. -\*=========================================================================*/ -#include "unix.h" - -int unixtcp_open(lua_State *L); - -#endif /* UNIXTCP_H */ diff -Nru luasocket-3.0~rc1+git+ac3201d/src/unixudp.c luasocket-3.1.0/src/unixudp.c --- luasocket-3.0~rc1+git+ac3201d/src/unixudp.c 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/unixudp.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,407 +0,0 @@ -/*=========================================================================*\ -* Unix domain socket udp submodule -* LuaSocket toolkit -\*=========================================================================*/ -#include -#include - -#include "lua.h" -#include "lauxlib.h" -#include "compat.h" - -#include "auxiliar.h" -#include "socket.h" -#include "options.h" -#include "unix.h" -#include - -#define UNIXUDP_DATAGRAMSIZE 8192 - -/*=========================================================================*\ -* Internal function prototypes -\*=========================================================================*/ -static int global_create(lua_State *L); -static int meth_connect(lua_State *L); -static int meth_bind(lua_State *L); -static int meth_send(lua_State *L); -static int meth_receive(lua_State *L); -static int meth_close(lua_State *L); -static int meth_setoption(lua_State *L); -static int meth_settimeout(lua_State *L); -static int meth_gettimeout(lua_State *L); -static int meth_getfd(lua_State *L); -static int meth_setfd(lua_State *L); -static int meth_dirty(lua_State *L); -static int meth_receivefrom(lua_State *L); -static int meth_sendto(lua_State *L); -static int meth_getsockname(lua_State *L); - -static const char *unixudp_tryconnect(p_unix un, const char *path); -static const char *unixudp_trybind(p_unix un, const char *path); - -/* unixudp object methods */ -static luaL_Reg unixudp_methods[] = { - {"__gc", meth_close}, - {"__tostring", auxiliar_tostring}, - {"bind", meth_bind}, - {"close", meth_close}, - {"connect", meth_connect}, - {"dirty", meth_dirty}, - {"getfd", meth_getfd}, - {"send", meth_send}, - {"sendto", meth_sendto}, - {"receive", meth_receive}, - {"receivefrom", meth_receivefrom}, - {"setfd", meth_setfd}, - {"setoption", meth_setoption}, - {"setpeername", meth_connect}, - {"setsockname", meth_bind}, - {"getsockname", meth_getsockname}, - {"settimeout", meth_settimeout}, - {"gettimeout", meth_gettimeout}, - {NULL, NULL} -}; - -/* socket option handlers */ -static t_opt optset[] = { - {"reuseaddr", opt_set_reuseaddr}, - {NULL, NULL} -}; - -/* functions in library namespace */ -static luaL_Reg func[] = { - {"udp", global_create}, - {NULL, NULL} -}; - -/*-------------------------------------------------------------------------*\ -* Initializes module -\*-------------------------------------------------------------------------*/ -int unixudp_open(lua_State *L) -{ - /* create classes */ - auxiliar_newclass(L, "unixudp{connected}", unixudp_methods); - auxiliar_newclass(L, "unixudp{unconnected}", unixudp_methods); - /* create class groups */ - auxiliar_add2group(L, "unixudp{connected}", "unixudp{any}"); - auxiliar_add2group(L, "unixudp{unconnected}", "unixudp{any}"); - auxiliar_add2group(L, "unixudp{connected}", "select{able}"); - auxiliar_add2group(L, "unixudp{unconnected}", "select{able}"); - - luaL_setfuncs(L, func, 0); - return 0; -} - -/*=========================================================================*\ -* Lua methods -\*=========================================================================*/ -static const char *unixudp_strerror(int err) -{ - /* a 'closed' error on an unconnected means the target address was not - * accepted by the transport layer */ - if (err == IO_CLOSED) return "refused"; - else return socket_strerror(err); -} - -static int meth_send(lua_State *L) -{ - p_unix un = (p_unix) auxiliar_checkclass(L, "unixudp{connected}", 1); - p_timeout tm = &un->tm; - size_t count, sent = 0; - int err; - const char *data = luaL_checklstring(L, 2, &count); - timeout_markstart(tm); - err = socket_send(&un->sock, data, count, &sent, tm); - if (err != IO_DONE) { - lua_pushnil(L); - lua_pushstring(L, unixudp_strerror(err)); - return 2; - } - lua_pushnumber(L, (lua_Number) sent); - return 1; -} - -/*-------------------------------------------------------------------------*\ -* Send data through unconnected unixudp socket -\*-------------------------------------------------------------------------*/ -static int meth_sendto(lua_State *L) -{ - p_unix un = (p_unix) auxiliar_checkclass(L, "unixudp{unconnected}", 1); - size_t count, sent = 0; - const char *data = luaL_checklstring(L, 2, &count); - const char *path = luaL_checkstring(L, 3); - p_timeout tm = &un->tm; - int err; - struct sockaddr_un remote; - size_t len = strlen(path); - - if (len >= sizeof(remote.sun_path)) { - lua_pushnil(L); - lua_pushstring(L, "path too long"); - return 2; - } - - memset(&remote, 0, sizeof(remote)); - strcpy(remote.sun_path, path); - remote.sun_family = AF_UNIX; - timeout_markstart(tm); -#ifdef UNIX_HAS_SUN_LEN - remote.sun_len = sizeof(remote.sun_family) + sizeof(remote.sun_len) - + len + 1; - err = socket_sendto(&un->sock, data, count, &sent, (SA *) &remote, remote.sun_len, tm); -#else - err = socket_sendto(&un->sock, data, count, &sent, (SA *) &remote, - sizeof(remote.sun_family) + len, tm); -#endif - if (err != IO_DONE) { - lua_pushnil(L); - lua_pushstring(L, unixudp_strerror(err)); - return 2; - } - lua_pushnumber(L, (lua_Number) sent); - return 1; -} - -static int meth_receive(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); - char buf[UNIXUDP_DATAGRAMSIZE]; - size_t got, wanted = (size_t) luaL_optnumber(L, 2, sizeof(buf)); - char *dgram = wanted > sizeof(buf)? (char *) malloc(wanted): buf; - int err; - p_timeout tm = &un->tm; - timeout_markstart(tm); - if (!dgram) { - lua_pushnil(L); - lua_pushliteral(L, "out of memory"); - return 2; - } - err = socket_recv(&un->sock, dgram, wanted, &got, tm); - /* Unlike TCP, recv() of zero is not closed, but a zero-length packet. */ - if (err != IO_DONE && err != IO_CLOSED) { - lua_pushnil(L); - lua_pushstring(L, unixudp_strerror(err)); - if (wanted > sizeof(buf)) free(dgram); - return 2; - } - lua_pushlstring(L, dgram, got); - if (wanted > sizeof(buf)) free(dgram); - return 1; -} - -/*-------------------------------------------------------------------------*\ -* Receives data and sender from a UDP socket -\*-------------------------------------------------------------------------*/ -static int meth_receivefrom(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkclass(L, "unixudp{unconnected}", 1); - char buf[UNIXUDP_DATAGRAMSIZE]; - size_t got, wanted = (size_t) luaL_optnumber(L, 2, sizeof(buf)); - char *dgram = wanted > sizeof(buf)? (char *) malloc(wanted): buf; - struct sockaddr_un addr; - socklen_t addr_len = sizeof(addr); - int err; - p_timeout tm = &un->tm; - timeout_markstart(tm); - if (!dgram) { - lua_pushnil(L); - lua_pushliteral(L, "out of memory"); - return 2; - } - err = socket_recvfrom(&un->sock, dgram, wanted, &got, (SA *) &addr, - &addr_len, tm); - /* Unlike TCP, recv() of zero is not closed, but a zero-length packet. */ - if (err != IO_DONE && err != IO_CLOSED) { - lua_pushnil(L); - lua_pushstring(L, unixudp_strerror(err)); - if (wanted > sizeof(buf)) free(dgram); - return 2; - } - - lua_pushlstring(L, dgram, got); - /* the path may be empty, when client send without bind */ - lua_pushstring(L, addr.sun_path); - if (wanted > sizeof(buf)) free(dgram); - return 2; -} - -/*-------------------------------------------------------------------------*\ -* Just call option handler -\*-------------------------------------------------------------------------*/ -static int meth_setoption(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); - return opt_meth_setoption(L, optset, &un->sock); -} - -/*-------------------------------------------------------------------------*\ -* Select support methods -\*-------------------------------------------------------------------------*/ -static int meth_getfd(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); - lua_pushnumber(L, (int) un->sock); - return 1; -} - -/* this is very dangerous, but can be handy for those that are brave enough */ -static int meth_setfd(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); - un->sock = (t_socket) luaL_checknumber(L, 2); - return 0; -} - -static int meth_dirty(lua_State *L) { - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); - (void) un; - lua_pushboolean(L, 0); - return 1; -} - -/*-------------------------------------------------------------------------*\ -* Binds an object to an address -\*-------------------------------------------------------------------------*/ -static const char *unixudp_trybind(p_unix un, const char *path) { - struct sockaddr_un local; - size_t len = strlen(path); - int err; - if (len >= sizeof(local.sun_path)) return "path too long"; - memset(&local, 0, sizeof(local)); - strcpy(local.sun_path, path); - local.sun_family = AF_UNIX; -#ifdef UNIX_HAS_SUN_LEN - local.sun_len = sizeof(local.sun_family) + sizeof(local.sun_len) - + len + 1; - err = socket_bind(&un->sock, (SA *) &local, local.sun_len); - -#else - err = socket_bind(&un->sock, (SA *) &local, - sizeof(local.sun_family) + len); -#endif - if (err != IO_DONE) socket_destroy(&un->sock); - return socket_strerror(err); -} - -static int meth_bind(lua_State *L) -{ - p_unix un = (p_unix) auxiliar_checkclass(L, "unixudp{unconnected}", 1); - const char *path = luaL_checkstring(L, 2); - const char *err = unixudp_trybind(un, path); - if (err) { - lua_pushnil(L); - lua_pushstring(L, err); - return 2; - } - lua_pushnumber(L, 1); - return 1; -} - -static int meth_getsockname(lua_State *L) -{ - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); - struct sockaddr_un peer = {0}; - socklen_t peer_len = sizeof(peer); - - if (getsockname(un->sock, (SA *) &peer, &peer_len) < 0) { - lua_pushnil(L); - lua_pushstring(L, socket_strerror(errno)); - return 2; - } - - lua_pushstring(L, peer.sun_path); - return 1; -} - -/*-------------------------------------------------------------------------*\ -* Turns a master unixudp object into a client object. -\*-------------------------------------------------------------------------*/ -static const char *unixudp_tryconnect(p_unix un, const char *path) -{ - struct sockaddr_un remote; - int err; - size_t len = strlen(path); - if (len >= sizeof(remote.sun_path)) return "path too long"; - memset(&remote, 0, sizeof(remote)); - strcpy(remote.sun_path, path); - remote.sun_family = AF_UNIX; - timeout_markstart(&un->tm); -#ifdef UNIX_HAS_SUN_LEN - remote.sun_len = sizeof(remote.sun_family) + sizeof(remote.sun_len) - + len + 1; - err = socket_connect(&un->sock, (SA *) &remote, remote.sun_len, &un->tm); -#else - err = socket_connect(&un->sock, (SA *) &remote, - sizeof(remote.sun_family) + len, &un->tm); -#endif - if (err != IO_DONE) socket_destroy(&un->sock); - return socket_strerror(err); -} - -static int meth_connect(lua_State *L) -{ - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); - const char *path = luaL_checkstring(L, 2); - const char *err = unixudp_tryconnect(un, path); - if (err) { - lua_pushnil(L); - lua_pushstring(L, err); - return 2; - } - /* turn unconnected object into a connected object */ - auxiliar_setclass(L, "unixudp{connected}", 1); - lua_pushnumber(L, 1); - return 1; -} - -/*-------------------------------------------------------------------------*\ -* Closes socket used by object -\*-------------------------------------------------------------------------*/ -static int meth_close(lua_State *L) -{ - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); - socket_destroy(&un->sock); - lua_pushnumber(L, 1); - return 1; -} - -/*-------------------------------------------------------------------------*\ -* Just call tm methods -\*-------------------------------------------------------------------------*/ -static int meth_settimeout(lua_State *L) -{ - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); - return timeout_meth_settimeout(L, &un->tm); -} - -static int meth_gettimeout(lua_State *L) -{ - p_unix un = (p_unix) auxiliar_checkgroup(L, "unixudp{any}", 1); - return timeout_meth_gettimeout(L, &un->tm); -} - -/*=========================================================================*\ -* Library functions -\*=========================================================================*/ -/*-------------------------------------------------------------------------*\ -* Creates a master unixudp object -\*-------------------------------------------------------------------------*/ -static int global_create(lua_State *L) -{ - t_socket sock; - int err = socket_create(&sock, AF_UNIX, SOCK_DGRAM, 0); - /* try to allocate a system socket */ - if (err == IO_DONE) { - /* allocate unixudp object */ - p_unix un = (p_unix) lua_newuserdata(L, sizeof(t_unix)); - /* set its type as master object */ - auxiliar_setclass(L, "unixudp{unconnected}", -1); - /* initialize remaining structure fields */ - socket_setnonblocking(&sock); - un->sock = sock; - io_init(&un->io, (p_send) socket_send, (p_recv) socket_recv, - (p_error) socket_ioerror, &un->sock); - timeout_init(&un->tm, -1, -1); - buffer_init(&un->buf, &un->io, &un->tm); - return 1; - } else { - lua_pushnil(L); - lua_pushstring(L, socket_strerror(err)); - return 2; - } -} diff -Nru luasocket-3.0~rc1+git+ac3201d/src/unixudp.h luasocket-3.1.0/src/unixudp.h --- luasocket-3.0~rc1+git+ac3201d/src/unixudp.h 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/unixudp.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,20 +0,0 @@ -#ifndef UNIXUDP_H -#define UNIXUDP_H -/*=========================================================================*\ -* UDP object -* LuaSocket toolkit -* -* The udp.h module provides LuaSocket with support for UDP protocol -* (AF_INET, SOCK_DGRAM). -* -* Two classes are defined: connected and unconnected. UDP objects are -* originally unconnected. They can be "connected" to a given address -* with a call to the setpeername function. The same function can be used to -* break the connection. -\*=========================================================================*/ - -#include "unix.h" - -int unixudp_open(lua_State *L); - -#endif /* UNIXUDP_H */ diff -Nru luasocket-3.0~rc1+git+ac3201d/src/url.lua luasocket-3.1.0/src/url.lua --- luasocket-3.0~rc1+git+ac3201d/src/url.lua 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/url.lua 2022-08-11 13:08:58.000000000 +0000 @@ -49,7 +49,7 @@ return s end --- these are allowed withing a path segment, along with alphanum +-- these are allowed within a path segment, along with alphanum -- other characters must be escaped local segment_set = make_set { "-", "_", ".", "!", "~", "*", "'", "(", @@ -59,7 +59,7 @@ local function protect_segment(s) return string.gsub(s, "([^A-Za-z0-9_])", function (c) if segment_set[c] then return c - else return string.format("%%%02x", string.byte(c)) end + else return string.format("%%%02X", string.byte(c)) end end) end @@ -77,6 +77,34 @@ end ----------------------------------------------------------------------------- +-- Removes '..' and '.' components appropriately from a path. +-- Input +-- path +-- Returns +-- dot-normalized path +local function remove_dot_components(path) + local marker = string.char(1) + repeat + local was = path + path = path:gsub('//', '/'..marker..'/', 1) + until path == was + repeat + local was = path + path = path:gsub('/%./', '/', 1) + until path == was + repeat + local was = path + path = path:gsub('[^/]+/%.%./([^/]+)', '%1', 1) + until path == was + path = path:gsub('[^/]+/%.%./*$', '') + path = path:gsub('/%.%.$', '/') + path = path:gsub('/%.$', '/') + path = path:gsub('^/%.%./', '/') + path = path:gsub(marker, '') + return path +end + +----------------------------------------------------------------------------- -- Builds a path from a base path and a relative path -- Input -- base_path @@ -85,23 +113,12 @@ -- corresponding absolute path ----------------------------------------------------------------------------- local function absolute_path(base_path, relative_path) - if string.sub(relative_path, 1, 1) == "/" then return relative_path end - local path = string.gsub(base_path, "[^/]*$", "") - path = path .. relative_path - path = string.gsub(path, "([^/]*%./)", function (s) - if s ~= "./" then return s else return "" end - end) - path = string.gsub(path, "/%.$", "/") - local reduced - while reduced ~= path do - reduced = path - path = string.gsub(reduced, "([^/]*/%.%./)", function (s) - if s ~= "../../" then return "" else return s end - end) - end - path = string.gsub(reduced, "([^/]*/%.%.)$", function (s) - if s ~= "../.." then return "" else return s end - end) + if string.sub(relative_path, 1, 1) == "/" then + return remove_dot_components(relative_path) end + base_path = base_path:gsub("[^/]*$", "") + if not base_path:find'/$' then base_path = base_path .. '/' end + local path = base_path .. relative_path + path = remove_dot_components(path) return path end @@ -131,11 +148,6 @@ if not url or url == "" then return nil, "invalid url" end -- remove whitespace -- url = string.gsub(url, "%s", "") - -- get fragment - url = string.gsub(url, "#(.*)$", function(f) - parsed.fragment = f - return "" - end) -- get scheme url = string.gsub(url, "^([%w][%w%+%-%.]*)%:", function(s) parsed.scheme = s; return "" end) @@ -144,6 +156,11 @@ parsed.authority = n return "" end) + -- get fragment + url = string.gsub(url, "#(.*)$", function(f) + parsed.fragment = f + return "" + end) -- get query string url = string.gsub(url, "%?(.*)", function(q) parsed.query = q @@ -162,9 +179,9 @@ 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 @@ -183,8 +200,9 @@ -- a stringing with the corresponding URL ----------------------------------------------------------------------------- function _M.build(parsed) - local ppath = _M.parse_path(parsed.path or "") - local url = _M.build_path(ppath) + --local ppath = _M.parse_path(parsed.path or "") + --local url = _M.build_path(ppath) + local url = parsed.path or "" if parsed.params then url = url .. ";" .. parsed.params end if parsed.query then url = url .. "?" .. parsed.query end local authority = parsed.authority @@ -193,7 +211,7 @@ if string.find(authority, ":") then -- IPv6? authority = "[" .. authority .. "]" end - if parsed.port then authority = authority .. ":" .. parsed.port end + if parsed.port then authority = authority .. ":" .. base.tostring(parsed.port) end local userinfo = parsed.userinfo if parsed.user then userinfo = parsed.user @@ -226,10 +244,14 @@ else base_parsed = _M.parse(base_url) end + local result local relative_parsed = _M.parse(relative_url) - if not base_parsed then return relative_url - elseif not relative_parsed then return base_url - elseif relative_parsed.scheme then return relative_url + if not base_parsed then + result = relative_url + elseif not relative_parsed then + result = base_url + elseif relative_parsed.scheme then + result = relative_url else relative_parsed.scheme = base_parsed.scheme if not relative_parsed.authority then @@ -242,13 +264,14 @@ relative_parsed.query = base_parsed.query end end - else + else relative_parsed.path = absolute_path(base_parsed.path or "", relative_parsed.path) end end - return _M.build(relative_parsed) + result = _M.build(relative_parsed) end + return remove_dot_components(result) end ----------------------------------------------------------------------------- diff -Nru luasocket-3.0~rc1+git+ac3201d/src/usocket.c luasocket-3.1.0/src/usocket.c --- luasocket-3.0~rc1+git+ac3201d/src/usocket.c 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/usocket.c 2022-08-11 13:08:58.000000000 +0000 @@ -6,12 +6,14 @@ * The penalty of calling select to avoid busy-wait is only paid when * the I/O call fail in the first place. \*=========================================================================*/ -#include -#include +#include "luasocket.h" #include "socket.h" #include "pierror.h" +#include +#include + /*-------------------------------------------------------------------------*\ * Wait for readable/writable/connected socket with timeout \*-------------------------------------------------------------------------*/ @@ -76,7 +78,7 @@ * Initializes module \*-------------------------------------------------------------------------*/ int socket_open(void) { - /* instals a handler to ignore sigpipe or it will crash us */ + /* installs a handler to ignore sigpipe or it will crash us */ signal(SIGPIPE, SIG_IGN); return 1; } @@ -438,14 +440,15 @@ case EAI_FAMILY: return PIE_FAMILY; case EAI_MEMORY: return PIE_MEMORY; case EAI_NONAME: return PIE_NONAME; +#ifdef EAI_OVERFLOW case EAI_OVERFLOW: return PIE_OVERFLOW; +#endif #ifdef EAI_PROTOCOL case EAI_PROTOCOL: return PIE_PROTOCOL; #endif case EAI_SERVICE: return PIE_SERVICE; case EAI_SOCKTYPE: return PIE_SOCKTYPE; case EAI_SYSTEM: return strerror(errno); - default: return gai_strerror(err); + default: return LUA_GAI_STRERROR(err); } } - diff -Nru luasocket-3.0~rc1+git+ac3201d/src/wsocket.c luasocket-3.1.0/src/wsocket.c --- luasocket-3.0~rc1+git+ac3201d/src/wsocket.c 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/src/wsocket.c 2022-08-11 13:08:58.000000000 +0000 @@ -5,6 +5,8 @@ * The penalty of calling select to avoid busy-wait is only paid when * the I/O call fail in the first place. \*=========================================================================*/ +#include "luasocket.h" + #include #include "socket.h" @@ -131,11 +133,11 @@ /* we wait until something happens */ err = socket_waitfd(ps, WAITFD_C, tm); if (err == IO_CLOSED) { - int len = sizeof(err); + int elen = sizeof(err); /* give windows time to set the error (yes, disgusting) */ Sleep(10); /* find out why we failed */ - getsockopt(*ps, SOL_SOCKET, SO_ERROR, (char *)&err, &len); + getsockopt(*ps, SOL_SOCKET, SO_ERROR, (char *)&err, &elen); /* we KNOW there was an error. if 'why' is 0, we will return * "unknown error", but it's not really our fault */ return err > 0? err: IO_UNKNOWN; @@ -358,7 +360,7 @@ 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"; @@ -371,23 +373,23 @@ 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"; @@ -396,9 +398,9 @@ 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"; } @@ -427,7 +429,6 @@ #ifdef EAI_SYSTEM case EAI_SYSTEM: return strerror(errno); #endif - default: return gai_strerror(err); + default: return LUA_GAI_STRERROR(err); } } - diff -Nru luasocket-3.0~rc1+git+ac3201d/test/auth/.htaccess luasocket-3.1.0/test/auth/.htaccess --- luasocket-3.0~rc1+git+ac3201d/test/auth/.htaccess 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/test/auth/.htaccess 2022-08-11 13:08:58.000000000 +0000 @@ -1,4 +1,4 @@ AuthName "test-auth" AuthType Basic - AuthUserFile /Users/diego/impa/luasocket/test/auth/.htpasswd + AuthUserFile /home/diego/impa/luasocket/test/auth/.htpasswd Require valid-user diff -Nru luasocket-3.0~rc1+git+ac3201d/test/find-connect-limit luasocket-3.1.0/test/find-connect-limit --- luasocket-3.0~rc1+git+ac3201d/test/find-connect-limit 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/test/find-connect-limit 2022-08-11 13:08:58.000000000 +0000 @@ -10,7 +10,7 @@ You'll probably need to be root to do this. ]] -require "socket" +socket = require "socket" host = arg[1] or "google.com" port = arg[2] or 80 diff -Nru luasocket-3.0~rc1+git+ac3201d/test/ltn12test.lua luasocket-3.1.0/test/ltn12test.lua --- luasocket-3.0~rc1+git+ac3201d/test/ltn12test.lua 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/test/ltn12test.lua 2022-08-11 13:08:58.000000000 +0000 @@ -38,7 +38,7 @@ end -------------------------------- -local function split(size) +local function split(size) local buffer = "" local last_out = "" local last_in = "" @@ -50,12 +50,12 @@ 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 @@ 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 @@ end -------------------------------- -local function merge(size) +local function merge(size) local buffer = "" local last_out = "" local last_in = "" @@ -102,12 +102,12 @@ 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 @@ 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) @@ -181,6 +181,15 @@ print("ok") -------------------------------- +io.write("testing source.table: ") +local inp = {'a','b','c','d','e'} +local source = ltn12.source.table(inp) +sink, t = ltn12.sink.table() +assert(ltn12.pump.all(source, sink), "returned error") +for i = 1, #inp do assert(t[i] == inp[i], "mismatch") end +print("ok") + +-------------------------------- io.write("testing source.chain (with split): ") source = ltn12.source.string(s) filter = split(5) diff -Nru luasocket-3.0~rc1+git+ac3201d/test/mimetest.lua luasocket-3.1.0/test/mimetest.lua --- luasocket-3.0~rc1+git+ac3201d/test/mimetest.lua 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/test/mimetest.lua 2022-08-11 13:08:58.000000000 +0000 @@ -15,27 +15,27 @@ 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 @@ 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 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 @@ f:write(' ',string.char(32)) end f:write("\r\n") - + f:close() end @@ -157,7 +157,7 @@ os.remove(dqptest) end --- create test file +-- create test file local function create_b64test() local f = assert(io.open(b64test, "wb")) local t = {} diff -Nru luasocket-3.0~rc1+git+ac3201d/test/smtptest.lua luasocket-3.1.0/test/smtptest.lua --- luasocket-3.0~rc1+git+ac3201d/test/smtptest.lua 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/test/smtptest.lua 2022-08-11 13:08:58.000000000 +0000 @@ -27,8 +27,8 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 -Nru luasocket-3.0~rc1+git+ac3201d/test/tcp-getoptions luasocket-3.1.0/test/tcp-getoptions --- luasocket-3.0~rc1+git+ac3201d/test/tcp-getoptions 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/test/tcp-getoptions 2022-08-11 13:08:58.000000000 +0000 @@ -1,19 +1,35 @@ #!/usr/bin/env lua -require"socket" +local socket = require"socket" port = 8765 +function pcalltest(msg, o, opt) + local a = { pcall(o.getoption, o, opt) } + if a[1] then + print(msg, opt, unpack(a)) + else + print(msg, opt, 'fail: ' .. a[2]) + end +end + function options(o) print("options for", o) - for _, opt in ipairs{"keepalive", "reuseaddr", "tcp-nodelay"} do - print("getoption", opt, o:getoption(opt)) + for _, opt in ipairs{ + "keepalive", "reuseaddr", + "tcp-nodelay", "tcp-keepidle", "tcp-keepcnt", "tcp-keepintvl"} do + pcalltest("getoption", o, opt) end - print("getoption", "linger", - "on", o:getoption("linger").on, - "timeout", o:getoption("linger").timeout) + r = o:getoption'linger' + if r then + print("getoption", "linger", + "on", r.on, + "timeout", r.timeout) + else + print("getoption", "linger", "no result") + end end local m = socket.tcp() diff -Nru luasocket-3.0~rc1+git+ac3201d/test/testmesg.lua luasocket-3.1.0/test/testmesg.lua --- luasocket-3.0~rc1+git+ac3201d/test/testmesg.lua 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/test/testmesg.lua 2022-08-11 13:08:58.000000000 +0000 @@ -34,11 +34,11 @@ 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 @@ "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 -Nru luasocket-3.0~rc1+git+ac3201d/test/test_socket_error.lua luasocket-3.1.0/test/test_socket_error.lua --- luasocket-3.0~rc1+git+ac3201d/test/test_socket_error.lua 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/test/test_socket_error.lua 2022-08-11 13:08:58.000000000 +0000 @@ -19,7 +19,7 @@ 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 -Nru luasocket-3.0~rc1+git+ac3201d/test/testsupport.lua luasocket-3.1.0/test/testsupport.lua --- luasocket-3.0~rc1+git+ac3201d/test/testsupport.lua 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/test/testsupport.lua 2022-08-11 13:08:58.000000000 +0000 @@ -7,7 +7,7 @@ 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 -Nru luasocket-3.0~rc1+git+ac3201d/test/udp-zero-length-send luasocket-3.1.0/test/udp-zero-length-send --- luasocket-3.0~rc1+git+ac3201d/test/udp-zero-length-send 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/test/udp-zero-length-send 2022-08-11 13:08:58.000000000 +0000 @@ -1,4 +1,4 @@ -#!/usr/bin/lua +#!/usr/bin/env lua --[[ Show that luasocket returns an error message on zero-length UDP sends, @@ -12,7 +12,7 @@ ]] -require"socket" +socket = require"socket" s = assert(socket.udp()) r = assert(socket.udp()) diff -Nru luasocket-3.0~rc1+git+ac3201d/test/udp-zero-length-send-recv luasocket-3.1.0/test/udp-zero-length-send-recv --- luasocket-3.0~rc1+git+ac3201d/test/udp-zero-length-send-recv 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/test/udp-zero-length-send-recv 2022-08-11 13:08:58.000000000 +0000 @@ -1,4 +1,4 @@ -#!/usr/bin/lua +#!/usr/bin/env lua --[[ Show that luasocket returns an error message on zero-length UDP sends, @@ -12,7 +12,7 @@ ]] -require"socket" +socket = require"socket" s = assert(socket.udp()) r = assert(socket.udp()) diff -Nru luasocket-3.0~rc1+git+ac3201d/test/unixdgramclnt.lua luasocket-3.1.0/test/unixdgramclnt.lua --- luasocket-3.0~rc1+git+ac3201d/test/unixdgramclnt.lua 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/test/unixdgramclnt.lua 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,9 @@ +socket = require"socket" +socket.unix = require"socket.unix" +c = assert(socket.unix.dgram()) +print(c:bind("/tmp/bar")) +while 1 do + local l = io.read("*l") + assert(c:sendto(l, "/tmp/foo")) + print(assert(c:receivefrom())) +end diff -Nru luasocket-3.0~rc1+git+ac3201d/test/unixdgramsrvr.lua luasocket-3.1.0/test/unixdgramsrvr.lua --- luasocket-3.0~rc1+git+ac3201d/test/unixdgramsrvr.lua 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/test/unixdgramsrvr.lua 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,9 @@ + socket = require"socket" + socket.unix = require"socket.unix" + u = assert(socket.unix.dgram()) + assert(u:bind("/tmp/foo")) + while 1 do + x, r = assert(u:receivefrom()) + print(x, r) + assert(u:sendto(">" .. x, r)) + end diff -Nru luasocket-3.0~rc1+git+ac3201d/test/unixstreamclnt.lua luasocket-3.1.0/test/unixstreamclnt.lua --- luasocket-3.0~rc1+git+ac3201d/test/unixstreamclnt.lua 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/test/unixstreamclnt.lua 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,8 @@ +socket = require"socket" +socket.unix = require"socket.unix" +c = assert(socket.unix.stream()) +assert(c:connect("/tmp/foo")) +while 1 do + local l = io.read() + assert(c:send(l .. "\n")) +end diff -Nru luasocket-3.0~rc1+git+ac3201d/test/unixstreamsrvr.lua luasocket-3.1.0/test/unixstreamsrvr.lua --- luasocket-3.0~rc1+git+ac3201d/test/unixstreamsrvr.lua 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/test/unixstreamsrvr.lua 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,9 @@ + socket = require"socket" + socket.unix = require"socket.unix" + u = assert(socket.unix.stream()) + assert(u:bind("/tmp/foo")) + assert(u:listen()) + c = assert(u:accept()) + while 1 do + print(assert(c:receive())) + end diff -Nru luasocket-3.0~rc1+git+ac3201d/test/unixtcpclnt.lua luasocket-3.1.0/test/unixtcpclnt.lua --- luasocket-3.0~rc1+git+ac3201d/test/unixtcpclnt.lua 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/test/unixtcpclnt.lua 1970-01-01 00:00:00.000000000 +0000 @@ -1,8 +0,0 @@ -socket = require"socket" -socket.unix = require"socket.unix" -c = assert(socket.unix.tcp()) -assert(c:connect("/tmp/foo")) -while 1 do - local l = io.read() - assert(c:send(l .. "\n")) -end diff -Nru luasocket-3.0~rc1+git+ac3201d/test/unixtcpsrvr.lua luasocket-3.1.0/test/unixtcpsrvr.lua --- luasocket-3.0~rc1+git+ac3201d/test/unixtcpsrvr.lua 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/test/unixtcpsrvr.lua 1970-01-01 00:00:00.000000000 +0000 @@ -1,9 +0,0 @@ - socket = require"socket" - socket.unix = require"socket.unix" - u = assert(socket.unix.tcp()) - assert(u:bind("/tmp/foo")) - assert(u:listen()) - c = assert(u:accept()) - while 1 do - print(assert(c:receive())) - end diff -Nru luasocket-3.0~rc1+git+ac3201d/test/unixudpclnt.lua luasocket-3.1.0/test/unixudpclnt.lua --- luasocket-3.0~rc1+git+ac3201d/test/unixudpclnt.lua 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/test/unixudpclnt.lua 1970-01-01 00:00:00.000000000 +0000 @@ -1,9 +0,0 @@ -socket = require"socket" -socket.unix = require"socket.unix" -c = assert(socket.unix.udp()) -c:bind("/tmp/bar") -while 1 do - local l = io.read("*l") - assert(c:sendto(l, "/tmp/foo")) - print(assert(c:receivefrom())) -end diff -Nru luasocket-3.0~rc1+git+ac3201d/test/unixudpsrvr.lua luasocket-3.1.0/test/unixudpsrvr.lua --- luasocket-3.0~rc1+git+ac3201d/test/unixudpsrvr.lua 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/test/unixudpsrvr.lua 1970-01-01 00:00:00.000000000 +0000 @@ -1,9 +0,0 @@ - socket = require"socket" - socket.unix = require"socket.unix" - u = assert(socket.unix.udp()) - assert(u:bind("/tmp/foo")) - while 1 do - x, r = assert(u:receivefrom()) - print(x, r) - assert(u:sendto(">" .. x, r)) - end diff -Nru luasocket-3.0~rc1+git+ac3201d/test/urltest.lua luasocket-3.1.0/test/urltest.lua --- luasocket-3.0~rc1+git+ac3201d/test/urltest.lua 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/test/urltest.lua 2022-08-11 13:08:58.000000000 +0000 @@ -60,8 +60,8 @@ 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 '", 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 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 @@ 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() @@ -91,9 +91,78 @@ 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", + host = "host", + port = "port", + userinfo = "user:pass$%?#wd", + password = "pass$%?#wd", + user = "user", + path = "/path", + params = "params", + query = "query", + fragment = "fragment" +} +check_parse_url{ + url = "scheme://user:pass?#wd@host:port/path;params?query#fragment", + scheme = "scheme", + authority = "user:pass?#wd@host:port", + host = "host", + port = "port", + userinfo = "user:pass?#wd", + password = "pass?#wd", + user = "user", + path = "/path", + params = "params", + query = "query", + fragment = "fragment" +} +check_parse_url{ + url = "scheme://user:pass-wd@host:port/path;params?query#fragment", + scheme = "scheme", + authority = "user:pass-wd@host:port", + host = "host", + port = "port", + userinfo = "user:pass-wd", + password = "pass-wd", + user = "user", + path = "/path", + params = "params", + query = "query", + fragment = "fragment" +} +check_parse_url{ + url = "scheme://user:pass#wd@host:port/path;params?query#fragment", + scheme = "scheme", + authority = "user:pass#wd@host:port", + host = "host", + port = "port", + userinfo = "user:pass#wd", + password = "pass#wd", + user = "user", + path = "/path", + params = "params", + query = "query", + fragment = "fragment" +} +check_parse_url{ + url = "scheme://user:pass#wd@host:port/path;params?query", + scheme = "scheme", + authority = "user:pass#wd@host:port", + host = "host", + port = "port", + userinfo = "user:pass#wd", + password = "pass#wd", + user = "user", + path = "/path", + params = "params", + query = "query", +} +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", @@ -106,8 +175,8 @@ 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", @@ -121,8 +190,8 @@ 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", @@ -135,8 +204,8 @@ 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", @@ -149,8 +218,8 @@ 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", @@ -162,8 +231,8 @@ 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", @@ -176,8 +245,8 @@ 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", @@ -189,8 +258,8 @@ 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", @@ -203,8 +272,8 @@ 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", @@ -213,7 +282,7 @@ 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", @@ -226,7 +295,7 @@ check_parse_url{ url = "//userinfo@host:port/path", - authority = "userinfo@host:port", + authority = "userinfo@host:port", host = "host", port = "port", userinfo = "userinfo", @@ -236,7 +305,7 @@ check_parse_url{ url = "//userinfo@host/path", - authority = "userinfo@host", + authority = "userinfo@host", host = "host", userinfo = "userinfo", user = "userinfo", @@ -245,7 +314,7 @@ check_parse_url{ url = "//user:password@host/path", - authority = "user:password@host", + authority = "user:password@host", host = "host", userinfo = "user:password", password = "password", @@ -255,7 +324,7 @@ check_parse_url{ url = "//user:@host/path", - authority = "user:@host", + authority = "user:@host", host = "host", userinfo = "user:", password = "", @@ -265,7 +334,7 @@ check_parse_url{ url = "//user@host:port/path", - authority = "user@host:port", + authority = "user@host:port", host = "host", userinfo = "user", user = "user", @@ -275,7 +344,7 @@ check_parse_url{ url = "//host:port/path", - authority = "host:port", + authority = "host:port", port = "port", host = "host", path = "/path", @@ -283,14 +352,14 @@ 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", } @@ -364,7 +433,7 @@ 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", @@ -378,7 +447,7 @@ 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", @@ -393,7 +462,7 @@ 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", @@ -430,7 +499,7 @@ check_build_url { url = "scheme://user:password@host/path;params?query#fragment", - scheme = "scheme", + scheme = "scheme", host = "host", user = "user", password = "password", @@ -442,7 +511,7 @@ check_build_url { url = "scheme://user@host/path;params?query#fragment", - scheme = "scheme", + scheme = "scheme", host = "host", user = "user", path = "/path", @@ -453,7 +522,7 @@ check_build_url { url = "scheme://host/path;params?query#fragment", - scheme = "scheme", + scheme = "scheme", host = "host", path = "/path", params = "params", @@ -463,7 +532,7 @@ check_build_url { url = "scheme://host/path;params#fragment", - scheme = "scheme", + scheme = "scheme", host = "host", path = "/path", params = "params", @@ -472,7 +541,7 @@ check_build_url { url = "scheme://host/path#fragment", - scheme = "scheme", + scheme = "scheme", host = "host", path = "/path", fragment = "fragment" @@ -480,7 +549,7 @@ check_build_url { url = "scheme://host/path", - scheme = "scheme", + scheme = "scheme", host = "host", path = "/path", } @@ -498,7 +567,7 @@ check_build_url { url = "scheme://user:password@host:port/path;params?query#fragment", - scheme = "scheme", + scheme = "scheme", host = "host", port = "port", user = "user", @@ -512,7 +581,7 @@ check_build_url { url = "scheme://user:password@host:port/path;params?query#fragment", - scheme = "scheme", + scheme = "scheme", host = "host", port = "port", user = "user", @@ -527,7 +596,7 @@ check_build_url { url = "scheme://user:password@host:port/path;params?query#fragment", - scheme = "scheme", + scheme = "scheme", host = "host", port = "port", userinfo = "user:password", @@ -540,7 +609,7 @@ 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", @@ -558,25 +627,37 @@ check_absolute_url("http://a/b/c/d;p?q#f", "//g", "http://g") check_absolute_url("http://a/b/c/d;p?q#f", "?y", "http://a/b/c/d;p?y") check_absolute_url("http://a/b/c/d;p?q#f", "g?y", "http://a/b/c/g?y") -check_absolute_url("http://a/b/c/d;p?q#f", "g?y/./x", "http://a/b/c/g?y/./x") +check_absolute_url("http://a/b/c/d;p?q#f", "g?y/./x", "http://a/b/c/g?y/x") check_absolute_url("http://a/b/c/d;p?q#f", "#s", "http://a/b/c/d;p?q#s") check_absolute_url("http://a/b/c/d;p?q#f", "g#s", "http://a/b/c/g#s") -check_absolute_url("http://a/b/c/d;p?q#f", "g#s/./x", "http://a/b/c/g#s/./x") +check_absolute_url("http://a/b/c/d;p?q#f", "g#s/./x", "http://a/b/c/g#s/x") check_absolute_url("http://a/b/c/d;p?q#f", "g?y#s", "http://a/b/c/g?y#s") check_absolute_url("http://a/b/c/d;p?q#f", ";x", "http://a/b/c/d;x") check_absolute_url("http://a/b/c/d;p?q#f", "g;x", "http://a/b/c/g;x") check_absolute_url("http://a/b/c/d;p?q#f", "g;x?y#s", "http://a/b/c/g;x?y#s") check_absolute_url("http://a/b/c/d;p?q#f", ".", "http://a/b/c/") check_absolute_url("http://a/b/c/d;p?q#f", "./", "http://a/b/c/") +check_absolute_url("http://a/b/c/d;p?q#f", "./g", "http://a/b/c/g") +check_absolute_url("http://a/b/c/d;p?q#f", "./g/", "http://a/b/c/g/") +check_absolute_url("http://a/b/c/d;p?q#f", "././g", "http://a/b/c/g") +check_absolute_url("http://a/b/c/d;p?q#f", "././g/", "http://a/b/c/g/") +check_absolute_url("http://a/b/c/d;p?q#f", "g/.", "http://a/b/c/g/") +check_absolute_url("http://a/b/c/d;p?q#f", "g/./", "http://a/b/c/g/") +check_absolute_url("http://a/b/c/d;p?q#f", "g/./.", "http://a/b/c/g/") +check_absolute_url("http://a/b/c/d;p?q#f", "g/././", "http://a/b/c/g/") +check_absolute_url("http://a/b/c/d;p?q#f", "./.", "http://a/b/c/") +check_absolute_url("http://a/b/c/d;p?q#f", "././.", "http://a/b/c/") +check_absolute_url("http://a/b/c/d;p?q#f", "././g/./.", "http://a/b/c/g/") check_absolute_url("http://a/b/c/d;p?q#f", "..", "http://a/b/") check_absolute_url("http://a/b/c/d;p?q#f", "../", "http://a/b/") check_absolute_url("http://a/b/c/d;p?q#f", "../g", "http://a/b/g") check_absolute_url("http://a/b/c/d;p?q#f", "../..", "http://a/") check_absolute_url("http://a/b/c/d;p?q#f", "../../", "http://a/") check_absolute_url("http://a/b/c/d;p?q#f", "../../g", "http://a/g") +check_absolute_url("http://a/b/c/d;p?q#f", "../../../g", "http://a/g") check_absolute_url("http://a/b/c/d;p?q#f", "", "http://a/b/c/d;p?q#f") -check_absolute_url("http://a/b/c/d;p?q#f", "/./g", "http://a/./g") -check_absolute_url("http://a/b/c/d;p?q#f", "/../g", "http://a/../g") +check_absolute_url("http://a/b/c/d;p?q#f", "/./g", "http://a/g") +check_absolute_url("http://a/b/c/d;p?q#f", "/../g", "http://a/g") check_absolute_url("http://a/b/c/d;p?q#f", "g.", "http://a/b/c/g.") check_absolute_url("http://a/b/c/d;p?q#f", ".g", "http://a/b/c/.g") check_absolute_url("http://a/b/c/d;p?q#f", "g..", "http://a/b/c/g..") @@ -586,31 +667,53 @@ check_absolute_url("http://a/b/c/d;p?q#f", "g/./h", "http://a/b/c/g/h") check_absolute_url("http://a/b/c/d;p?q#f", "g/../h", "http://a/b/c/h") +check_absolute_url("http://a/b/c/d:p?q#f/", "../g/", "http://a/b/g/") +check_absolute_url("http://a/b/c/d:p?q#f/", "../g", "http://a/b/g") +check_absolute_url("http://a/b/c/d:p?q#f/", "../.g/", "http://a/b/.g/") +check_absolute_url("http://a/b/c/d:p?q#f/", "../.g", "http://a/b/.g") +check_absolute_url("http://a/b/c/d:p?q#f/", "../.g.h/", "http://a/b/.g.h/") +check_absolute_url("http://a/b/c/d:p?q#f/", "../.g.h", "http://a/b/.g.h") + +check_absolute_url("http://a/b/c/d:p?q#f/", "g.h/", "http://a/b/c/g.h/") +check_absolute_url("http://a/b/c/d:p?q#f/", "../g.h/", "http://a/b/g.h/") +check_absolute_url("http://a/", "../g.h/", "http://a/g.h/") + -- extra tests 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/") +check_absolute_url("http://example.com/a/b/c/d/", "../q", "http://example.com/a/b/c/q") +check_absolute_url("http://example.com/a/b/c/d/", "../../q", "http://example.com/a/b/q") +check_absolute_url("http://example.com/a/b/c/d/", "../../../q", "http://example.com/a/q") +check_absolute_url("http://example.com", ".badhost.com", "http://example.com/.badhost.com") +check_absolute_url("http://example.com/a/b/c/d/", "..//../../../q", "http://example.com/a/q") +check_absolute_url("http://example.com/a/b/c/d/", "..//a/../../../../q", "http://example.com/a/q") +check_absolute_url("http://example.com/a/b/c/d/", "..//a/..//../../../q", "http://example.com/a/b/q") +check_absolute_url("http://example.com/a/b/c/d/", "..//a/..///../../../../q", "http://example.com/a/b/q") +check_absolute_url("http://example.com/a/b/c/d/", "../x/a/../y/z/../../../../q", "http://example.com/a/b/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" }) print("testing path protection") check_protect({ "eu", "-_.!~*'():@&=+$,", "tu" }, "eu/-_.!~*'():@&=+$,/tu") check_protect({ "eu ", "~diego" }, "eu%20/~diego") -check_protect({ "/eu>", "", "", "/ 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 @@ 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 @@ ------------------------------------------------------------------------ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ ]], 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ ------------------------------------------------------------------------ -function test_nonblocking(size) +function test_nonblocking(size) reconnect() print("Testing " .. 2*size .. " bytes") remote(string.format([[ diff -Nru luasocket-3.0~rc1+git+ac3201d/test/utestsrvr.lua luasocket-3.1.0/test/utestsrvr.lua --- luasocket-3.0~rc1+git+ac3201d/test/utestsrvr.lua 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/test/utestsrvr.lua 2022-08-11 13:08:58.000000000 +0000 @@ -9,7 +9,7 @@ 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))(); diff -Nru luasocket-3.0~rc1+git+ac3201d/.travis.yml luasocket-3.1.0/.travis.yml --- luasocket-3.0~rc1+git+ac3201d/.travis.yml 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/.travis.yml 1970-01-01 00:00:00.000000000 +0000 @@ -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 diff -Nru luasocket-3.0~rc1+git+ac3201d/vc32.bat luasocket-3.1.0/vc32.bat --- luasocket-3.0~rc1+git+ac3201d/vc32.bat 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/vc32.bat 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,3 @@ +call "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\vcvars32.bat" +cls +"c:\Program Files\Git\git-bash.exe" --cd-to-home diff -Nru luasocket-3.0~rc1+git+ac3201d/vc64.bat luasocket-3.1.0/vc64.bat --- luasocket-3.0~rc1+git+ac3201d/vc64.bat 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/vc64.bat 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1,3 @@ +call "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\vcvars64.bat" +cls +"c:\Program Files\Git\git-bash.exe" --cd-to-home diff -Nru luasocket-3.0~rc1+git+ac3201d/win32.cmd luasocket-3.1.0/win32.cmd --- luasocket-3.0~rc1+git+ac3201d/win32.cmd 2016-12-18 21:18:47.000000000 +0000 +++ luasocket-3.1.0/win32.cmd 2022-08-11 13:08:58.000000000 +0000 @@ -1 +1 @@ -make LUAPREFIX_win32='c:\cygwin\home\diego\vc12' LUAV=5.1 PLAT=win32 LUALIBNAME_win32=lualib.lib PLATFORM_win32=Debug install-both +LUAV=5.3 PLAT=win32 LUAPREFIX_win32=/z/data/build/vc14 make diff -Nru luasocket-3.0~rc1+git+ac3201d/win64.cmd luasocket-3.1.0/win64.cmd --- luasocket-3.0~rc1+git+ac3201d/win64.cmd 1970-01-01 00:00:00.000000000 +0000 +++ luasocket-3.1.0/win64.cmd 2022-08-11 13:08:58.000000000 +0000 @@ -0,0 +1 @@ +LUAV=5.3 PLAT=win64 LUAPREFIX_win64=/z/data/build/vc14 make