From f960b3872a668ed1b53bd50c5b6a708367332f3c Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Mon, 23 Apr 2012 00:18:45 +0800 Subject: Making progress toward a release Documented headers.lua Update copyright date everywhere Remove RCSID from files Move version back to 2.1 rather than 2.1.1 Fixed url package to support ipv6 hosts Changed "domain" to "family" in tcp and udp structures Implemented getfamily methods --- src/auxiliar.c | 2 -- src/buffer.c | 2 -- src/except.c | 2 -- src/ftp.lua | 1 - src/headers.lua | 1 - src/http.lua | 1 - src/inet.c | 6 ++---- src/io.c | 2 -- src/ltn12.lua | 1 - src/luasocket.h | 2 +- src/makefile | 2 +- src/mime.c | 2 -- src/mime.lua | 1 - src/options.c | 2 -- src/select.c | 2 -- src/smtp.lua | 1 - src/socket.lua | 1 - src/tcp.c | 31 +++++++++++++++++++++++-------- src/tcp.h | 2 +- src/timeout.c | 2 -- src/tp.lua | 1 - src/udp.c | 31 +++++++++++++++++++++++-------- src/udp.h | 2 +- src/unix.c | 2 -- src/url.lua | 15 ++++++++++----- src/usocket.c | 2 -- src/wsocket.c | 2 -- 27 files changed, 62 insertions(+), 59 deletions(-) (limited to 'src') diff --git a/src/auxiliar.c b/src/auxiliar.c index c4e5260..de625e9 100644 --- a/src/auxiliar.c +++ b/src/auxiliar.c @@ -1,8 +1,6 @@ /*=========================================================================*\ * Auxiliar routines for class hierarchy manipulation * LuaSocket toolkit -* -* RCS ID: $Id: auxiliar.c,v 1.14 2005/10/07 04:40:59 diego Exp $ \*=========================================================================*/ #include #include diff --git a/src/buffer.c b/src/buffer.c index 452a579..d8facd2 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1,8 +1,6 @@ /*=========================================================================*\ * Input/Output interface for Lua programs * LuaSocket toolkit -* -* RCS ID: $Id: buffer.c,v 1.29 2009/05/27 09:31:35 diego Exp $ \*=========================================================================*/ #include "lua.h" #include "lauxlib.h" diff --git a/src/except.c b/src/except.c index 97c00a3..1d1ade0 100644 --- a/src/except.c +++ b/src/except.c @@ -1,8 +1,6 @@ /*=========================================================================*\ * Simple exception support * LuaSocket toolkit -* -* RCS ID: $Id: except.c,v 1.8 2005/09/29 06:11:41 diego Exp $ \*=========================================================================*/ #include diff --git a/src/ftp.lua b/src/ftp.lua index 1d5ff77..5aa646b 100644 --- a/src/ftp.lua +++ b/src/ftp.lua @@ -2,7 +2,6 @@ -- FTP support for the Lua language -- LuaSocket toolkit. -- Author: Diego Nehab --- RCS ID: $Id: ftp.lua,v 1.45 2007/07/11 19:25:47 diego Exp $ ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- diff --git a/src/headers.lua b/src/headers.lua index f92ee7a..41794ba 100644 --- a/src/headers.lua +++ b/src/headers.lua @@ -2,7 +2,6 @@ -- Canonic header field capitalization -- LuaSocket toolkit. -- Author: Diego Nehab --- RCS ID: $Id$ ----------------------------------------------------------------------------- module("socket.headers") diff --git a/src/http.lua b/src/http.lua index 029a367..4c7e7d8 100644 --- a/src/http.lua +++ b/src/http.lua @@ -2,7 +2,6 @@ -- HTTP/1.1 client support for the Lua language. -- LuaSocket toolkit. -- Author: Diego Nehab --- RCS ID: $Id: http.lua,v 1.72 2009/05/27 09:31:35 diego Exp $ ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- diff --git a/src/inet.c b/src/inet.c index 839fe5f..fd16506 100644 --- a/src/inet.c +++ b/src/inet.c @@ -1,8 +1,6 @@ /*=========================================================================*\ * Internet domain functions * LuaSocket toolkit -* -* RCS ID: $Id: inet.c,v 1.28 2005/10/07 04:40:59 diego Exp $ \*=========================================================================*/ #include #include @@ -270,8 +268,8 @@ static void inet_pushresolved(lua_State *L, struct hostent *hp) /*-------------------------------------------------------------------------*\ * Tries to create a new inet socket \*-------------------------------------------------------------------------*/ -const char *inet_trycreate(p_socket ps, int domain, int type) { - return socket_strerror(socket_create(ps, domain, type, 0)); +const char *inet_trycreate(p_socket ps, int family, int type) { + return socket_strerror(socket_create(ps, family, type, 0)); } /*-------------------------------------------------------------------------*\ diff --git a/src/io.c b/src/io.c index 06dc50e..35f46f7 100644 --- a/src/io.c +++ b/src/io.c @@ -1,8 +1,6 @@ /*=========================================================================*\ * Input/Output abstraction * LuaSocket toolkit -* -* RCS ID: $Id: io.c,v 1.6 2005/09/29 06:11:41 diego Exp $ \*=========================================================================*/ #include "io.h" diff --git a/src/ltn12.lua b/src/ltn12.lua index b42689a..b7f9a21 100644 --- a/src/ltn12.lua +++ b/src/ltn12.lua @@ -2,7 +2,6 @@ -- LTN12 - Filters, sources, sinks and pumps. -- LuaSocket toolkit. -- Author: Diego Nehab --- RCS ID: $Id: ltn12.lua,v 1.31 2006/04/03 04:45:42 diego Exp $ ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- diff --git a/src/luasocket.h b/src/luasocket.h index 09e758d..f2ca3c1 100644 --- a/src/luasocket.h +++ b/src/luasocket.h @@ -11,7 +11,7 @@ /*-------------------------------------------------------------------------*\ * Current socket library version \*-------------------------------------------------------------------------*/ -#define LUASOCKET_VERSION "LuaSocket 2.1.1-rc1" +#define LUASOCKET_VERSION "LuaSocket 2.1-rc1" #define LUASOCKET_COPYRIGHT "Copyright (C) 1999-2012 Diego Nehab" #define LUASOCKET_AUTHORS "Diego Nehab" diff --git a/src/makefile b/src/makefile index 0665c14..6225ce4 100644 --- a/src/makefile +++ b/src/makefile @@ -98,7 +98,7 @@ SOCKET_win32=wsocket.obj # SO=$(SO_$(PLAT)) O=$(O_$(PLAT)) -SOCKET_V=2.1.1 +SOCKET_V=2.1 MIME_V=1.0.3 SOCKET_SO=socket.$(SO).$(SOCKET_V) MIME_SO=mime.$(SO).$(MIME_V) diff --git a/src/mime.c b/src/mime.c index 023559f..a1aaae9 100644 --- a/src/mime.c +++ b/src/mime.c @@ -1,8 +1,6 @@ /*=========================================================================*\ * MIME support functions * LuaSocket toolkit -* -* RCS ID: $Id: mime.c,v 1.29 2009/05/27 09:31:35 diego Exp $ \*=========================================================================*/ #include diff --git a/src/mime.lua b/src/mime.lua index 218b38a..4aaccc8 100644 --- a/src/mime.lua +++ b/src/mime.lua @@ -2,7 +2,6 @@ -- MIME support for the Lua language. -- Author: Diego Nehab -- Conforming to RFCs 2045-2049 --- RCS ID: $Id: mime.lua,v 1.29 2007/06/11 23:44:54 diego Exp $ ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- diff --git a/src/options.c b/src/options.c index c122ead..6cae7ee 100644 --- a/src/options.c +++ b/src/options.c @@ -1,8 +1,6 @@ /*=========================================================================*\ * Common option interface * LuaSocket toolkit -* -* RCS ID: $Id: options.c,v 1.7 2009/05/27 09:31:35 diego Exp $ \*=========================================================================*/ #include diff --git a/src/select.c b/src/select.c index 87b5dc2..b870545 100644 --- a/src/select.c +++ b/src/select.c @@ -1,8 +1,6 @@ /*=========================================================================*\ * Select implementation * LuaSocket toolkit -* -* RCS ID: $Id: select.c,v 1.23 2009/05/27 09:31:35 diego Exp $ \*=========================================================================*/ #include diff --git a/src/smtp.lua b/src/smtp.lua index e258d62..26808f5 100644 --- a/src/smtp.lua +++ b/src/smtp.lua @@ -2,7 +2,6 @@ -- SMTP client support for the Lua language. -- LuaSocket toolkit. -- Author: Diego Nehab --- RCS ID: $Id: smtp.lua,v 1.47 2009/05/27 09:31:35 diego Exp $ ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- diff --git a/src/socket.lua b/src/socket.lua index 734da3c..a9219b0 100644 --- a/src/socket.lua +++ b/src/socket.lua @@ -1,7 +1,6 @@ ----------------------------------------------------------------------------- -- LuaSocket helper module -- Author: Diego Nehab --- RCS ID: $Id: socket.lua,v 1.22 2005/11/22 08:33:29 diego Exp $ ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- diff --git a/src/tcp.c b/src/tcp.c index 3146467..872b1c6 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -1,8 +1,6 @@ /*=========================================================================*\ * TCP object * LuaSocket toolkit -* -* RCS ID: $Id: tcp.c,v 1.42 2009/05/27 09:31:35 diego Exp $ \*=========================================================================*/ #include @@ -23,6 +21,7 @@ static int global_create6(lua_State *L); static int global_connect6(lua_State *L); static int meth_connect(lua_State *L); static int meth_listen(lua_State *L); +static int meth_getfamily(lua_State *L); static int meth_bind(lua_State *L); static int meth_send(lua_State *L); static int meth_getstats(lua_State *L); @@ -49,6 +48,7 @@ static luaL_Reg tcp_methods[] = { {"close", meth_close}, {"connect", meth_connect}, {"dirty", meth_dirty}, + {"getfamily", meth_getfamily}, {"getfd", meth_getfd}, {"getoption", meth_getoption}, {"getpeername", meth_getpeername}, @@ -218,7 +218,7 @@ static int meth_bind(lua_State *L) struct addrinfo bindhints; memset(&bindhints, 0, sizeof(bindhints)); bindhints.ai_socktype = SOCK_STREAM; - bindhints.ai_family = tcp->domain; + bindhints.ai_family = tcp->family; bindhints.ai_flags = AI_PASSIVE; err = inet_trybind(&tcp->sock, address, port, &bindhints); if (err) { @@ -243,7 +243,7 @@ static int meth_connect(lua_State *L) memset(&connecthints, 0, sizeof(connecthints)); connecthints.ai_socktype = SOCK_STREAM; /* make sure we try to connect only to the same family */ - connecthints.ai_family = tcp->domain; + connecthints.ai_family = tcp->family; timeout_markstart(&tcp->tm); err = inet_tryconnect(&tcp->sock, address, port, &tcp->tm, &connecthints); @@ -269,6 +269,21 @@ static int meth_close(lua_State *L) return 1; } +/*-------------------------------------------------------------------------*\ +* Returns family as string +\*-------------------------------------------------------------------------*/ +static int meth_getfamily(lua_State *L) +{ + p_tcp tcp = (p_tcp) auxiliar_checkgroup(L, "tcp{any}", 1); + if (tcp->family == PF_INET6) { + lua_pushliteral(L, "inet6"); + return 1; + } else { + lua_pushliteral(L, "inet4"); + return 1; + } +} + /*-------------------------------------------------------------------------*\ * Puts the sockt in listen mode \*-------------------------------------------------------------------------*/ @@ -346,9 +361,9 @@ static int meth_settimeout(lua_State *L) /*-------------------------------------------------------------------------*\ * Creates a master tcp object \*-------------------------------------------------------------------------*/ -static int tcp_create(lua_State *L, int domain) { +static int tcp_create(lua_State *L, int family) { t_socket sock; - const char *err = inet_trycreate(&sock, domain, SOCK_STREAM); + const char *err = inet_trycreate(&sock, family, SOCK_STREAM); /* try to allocate a system socket */ if (!err) { /* allocate tcp object */ @@ -357,7 +372,7 @@ static int tcp_create(lua_State *L, int domain) { auxiliar_setclass(L, "tcp{master}", -1); /* initialize remaining structure fields */ socket_setnonblocking(&sock); - if (domain == PF_INET6) { + if (family == PF_INET6) { int yes = 1; setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&yes, sizeof(yes)); @@ -367,7 +382,7 @@ static int tcp_create(lua_State *L, int domain) { (p_error) socket_ioerror, &tcp->sock); timeout_init(&tcp->tm, -1, -1); buffer_init(&tcp->buf, &tcp->io, &tcp->tm); - tcp->domain = domain; + tcp->family = family; return 1; } else { lua_pushnil(L); diff --git a/src/tcp.h b/src/tcp.h index 4dc9c4a..eded620 100644 --- a/src/tcp.h +++ b/src/tcp.h @@ -25,7 +25,7 @@ typedef struct t_tcp_ { t_io io; t_buffer buf; t_timeout tm; - int domain; + int family; } t_tcp; typedef t_tcp *p_tcp; diff --git a/src/timeout.c b/src/timeout.c index a3f1318..c7354b5 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -1,8 +1,6 @@ /*=========================================================================*\ * Timeout management functions * LuaSocket toolkit -* -* RCS ID: $Id: timeout.c,v 1.31 2009/05/27 09:31:35 diego Exp $ \*=========================================================================*/ #include #include diff --git a/src/tp.lua b/src/tp.lua index adeb4b0..2ffe9a4 100644 --- a/src/tp.lua +++ b/src/tp.lua @@ -2,7 +2,6 @@ -- Unified SMTP/FTP subsystem -- LuaSocket toolkit. -- Author: Diego Nehab --- RCS ID: $Id: tp.lua,v 1.23 2009/05/27 09:31:35 diego Exp $ ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- diff --git a/src/udp.c b/src/udp.c index 386051a..bfa934f 100644 --- a/src/udp.c +++ b/src/udp.c @@ -1,8 +1,6 @@ /*=========================================================================*\ * UDP object * LuaSocket toolkit -* -* RCS ID: $Id: udp.c,v 1.30 2009/05/27 09:31:35 diego Exp $ \*=========================================================================*/ #include @@ -32,6 +30,7 @@ static int meth_send(lua_State *L); static int meth_sendto(lua_State *L); static int meth_receive(lua_State *L); static int meth_receivefrom(lua_State *L); +static int meth_getfamily(lua_State *L); static int meth_getsockname(lua_State *L); static int meth_getpeername(lua_State *L); static int meth_setsockname(lua_State *L); @@ -50,6 +49,7 @@ static luaL_Reg udp_methods[] = { {"__tostring", auxiliar_tostring}, {"close", meth_close}, {"dirty", meth_dirty}, + {"getfamily", meth_getfamily}, {"getfd", meth_getfd}, {"getpeername", meth_getpeername}, {"getsockname", meth_getsockname}, @@ -226,6 +226,21 @@ static int meth_receivefrom(lua_State *L) { } } +/*-------------------------------------------------------------------------*\ +* Returns family as string +\*-------------------------------------------------------------------------*/ +static int meth_getfamily(lua_State *L) +{ + p_udp udp = (p_udp) auxiliar_checkgroup(L, "udp{any}", 1); + if (udp->family == PF_INET6) { + lua_pushliteral(L, "inet6"); + return 1; + } else { + lua_pushliteral(L, "inet4"); + return 1; + } +} + /*-------------------------------------------------------------------------*\ * Select support methods \*-------------------------------------------------------------------------*/ @@ -302,7 +317,7 @@ static int meth_setpeername(lua_State *L) { memset(&connecthints, 0, sizeof(connecthints)); connecthints.ai_socktype = SOCK_DGRAM; /* make sure we try to connect only to the same family */ - connecthints.ai_family = udp->domain; + connecthints.ai_family = udp->family; err = inet_tryconnect(&udp->sock, address, port, tm, &connecthints); if (err) { @@ -338,7 +353,7 @@ static int meth_setsockname(lua_State *L) { struct addrinfo bindhints; memset(&bindhints, 0, sizeof(bindhints)); bindhints.ai_socktype = SOCK_DGRAM; - bindhints.ai_family = udp->domain; + bindhints.ai_family = udp->family; bindhints.ai_flags = AI_PASSIVE; err = inet_trybind(&udp->sock, address, port, &bindhints); if (err) { @@ -356,9 +371,9 @@ static int meth_setsockname(lua_State *L) { /*-------------------------------------------------------------------------*\ * Creates a master udp object \*-------------------------------------------------------------------------*/ -static int udp_create(lua_State *L, int domain) { +static int udp_create(lua_State *L, int family) { t_socket sock; - const char *err = inet_trycreate(&sock, domain, SOCK_DGRAM); + const char *err = inet_trycreate(&sock, family, SOCK_DGRAM); /* try to allocate a system socket */ if (!err) { /* allocate udp object */ @@ -366,14 +381,14 @@ static int udp_create(lua_State *L, int domain) { auxiliar_setclass(L, "udp{unconnected}", -1); /* initialize remaining structure fields */ socket_setnonblocking(&sock); - if (domain == PF_INET6) { + if (family == PF_INET6) { int yes = 1; setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&yes, sizeof(yes)); } udp->sock = sock; timeout_init(&udp->tm, -1, -1); - udp->domain = domain; + udp->family = family; return 1; } else { lua_pushnil(L); diff --git a/src/udp.h b/src/udp.h index c5b8688..2b831a5 100644 --- a/src/udp.h +++ b/src/udp.h @@ -23,7 +23,7 @@ typedef struct t_udp_ { t_socket sock; t_timeout tm; - int domain; + int family; } t_udp; typedef t_udp *p_udp; diff --git a/src/unix.c b/src/unix.c index 935d4c3..f972738 100644 --- a/src/unix.c +++ b/src/unix.c @@ -1,8 +1,6 @@ /*=========================================================================*\ * Unix domain socket * LuaSocket toolkit -* -* RCS ID: $Id: unix.c,v 1.14 2009/05/27 09:31:35 diego Exp $ \*=========================================================================*/ #include diff --git a/src/url.lua b/src/url.lua index 1e59771..1bfecad 100644 --- a/src/url.lua +++ b/src/url.lua @@ -2,7 +2,6 @@ -- URI parsing, composition and relative URL resolution -- LuaSocket toolkit. -- Author: Diego Nehab --- RCS ID: $Id: url.lua,v 1.38 2006/04/03 04:45:42 diego Exp $ ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- @@ -16,7 +15,7 @@ module("socket.url") ----------------------------------------------------------------------------- -- Module version ----------------------------------------------------------------------------- -_VERSION = "URL 1.0.1" +_VERSION = "URL 1.0.2" ----------------------------------------------------------------------------- -- Encodes a string into its escaped hexadecimal representation @@ -142,7 +141,7 @@ function parse(url, default) parsed.authority = n return "" end) - -- get query stringing + -- get query string url = string.gsub(url, "%?(.*)", function(q) parsed.query = q return "" @@ -158,9 +157,12 @@ function parse(url, default) if not authority then return parsed end authority = string.gsub(authority,"^([^@]*)@", function(u) parsed.userinfo = u; return "" end) - authority = string.gsub(authority, ":([^:]*)$", + authority = string.gsub(authority, ":([^:%]]*)$", function(p) parsed.port = p; return "" end) - if authority ~= "" then parsed.host = authority end + if authority ~= "" then + -- IPv6? + parsed.host = string.match(authority, "^%[(.+)%]$") or authority + end local userinfo = parsed.userinfo if not userinfo then return parsed end userinfo = string.gsub(userinfo, ":([^:]*)$", @@ -185,6 +187,9 @@ function build(parsed) local authority = parsed.authority if parsed.host then authority = parsed.host + if string.find(authority, ":") then -- IPv6? + authority = "[" .. authority .. "]" + end if parsed.port then authority = authority .. ":" .. parsed.port end local userinfo = parsed.userinfo if parsed.user then diff --git a/src/usocket.c b/src/usocket.c index bf2d19c..80d4d70 100644 --- a/src/usocket.c +++ b/src/usocket.c @@ -5,8 +5,6 @@ * The code is now interrupt-safe. * The penalty of calling select to avoid busy-wait is only paid when * the I/O call fail in the first place. -* -* RCS ID: $Id: usocket.c,v 1.38 2007/10/13 23:55:20 diego Exp $ \*=========================================================================*/ #include #include diff --git a/src/wsocket.c b/src/wsocket.c index c82882a..12e6352 100644 --- a/src/wsocket.c +++ b/src/wsocket.c @@ -4,8 +4,6 @@ * * The penalty of calling select to avoid busy-wait is only paid when * the I/O call fail in the first place. -* -* RCS ID: $Id: wsocket.c,v 1.36 2007/06/11 23:44:54 diego Exp $ \*=========================================================================*/ #include -- cgit v1.2.3-55-g6feb