diff --git a/LICENSE b/LICENSE index 8c3cfe5..5bd3478 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ -LuaSocket 2.0.2 license -Copyright © 2004-2007 Diego Nehab +LuaSocket 2.1 license +Copyright © 2004-2012 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 --git a/README b/README index 6941026..e9dc323 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -This is the LuaSocket 2.1.1. It has been tested on --[[WinXP--]], Mac OS X, +This is the LuaSocket 2.1. It has been tested on --[[WinXP--]], Mac OS X, and --[[Linux--]]. Please use the Lua mailing list to report any bugs (or "features") you encounter. diff --git a/TODO b/TODO index fbd5865..a6d5372 100644 --- a/TODO +++ b/TODO @@ -1,39 +1,40 @@ -- merge luaL_typeerror into auxiliar to avoid using luaL prefix? - getsockname should also support IPv6, no? -- remove RCSID from files? - shouldn't we instead make the code compatible to Lua 5.2 without any compat stuff, and use a compatibility layer to make it work on 5.1? -- why 2.1.1 rather than 2.1? - add what's new to manual - should there be an equivalent to tohostname for IPv6? -- should we add service name resolution as well to - getaddrinfo? +- should we add service name resolution as well to getaddrinfo? - document bind and connect behavior based on address? -- add functionality to query if object is ipv4 or 6? -- update copyright date everywhere? -- what to do about author? - add http POST sample to manual people keep asking stupid questions - documentation of dirty/getfd/setfd is problematic because of portability same for unix and serial. what to do about this? add a stronger disclaimer? -- remove references to Lua 5.0 from documentation, add 5.2? -- update lua and luasocket version in samples in documentation -- document headers.lua? - fix makefile with decent defaults? Done: +- document headers.lua? +- update copyright date everywhere? +- remove RCSID from files? +- move version to 2.1 rather than 2.1.1? +- fixed url package to support ipv6 hosts +- changed domain to family +- implement getfamily methods. + +- remove references to Lua 5.0 from documentation, add 5.2? +- update lua and luasocket version in samples in documentation - document ipv5_v6only default option being set? - document tcp6 and udp6 - document dns.getaddrinfo -- document zero-sized send on udp vs. tcp? +- documented zero-sized datagram change? no. - document unix socket and serial socket? add raw support? no. - document getoption +- merge luaL_typeerror into auxiliar to avoid using luaL prefix? diff --git a/doc/http.html b/doc/http.html index 9f3f087..cd41c0d 100644 --- a/doc/http.html +++ b/doc/http.html @@ -95,8 +95,9 @@ headers = {

-Field names are case insensitive (as specified by the standard) and all -functions work with lowercase field names. +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.

@@ -117,6 +118,7 @@ the HTTP module:
  • USERAGENT: default user agent reported to server. +

    diff --git a/doc/index.html b/doc/index.html index 9da0f3c..833c9a8 100644 --- a/doc/index.html +++ b/doc/index.html @@ -87,7 +87,7 @@ Author: Diego Nehab

    Download

    -LuaSocket version 2.1.1-rc1 is now available for download! +LuaSocket version 2.1-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. @@ -125,7 +125,7 @@ has helped bring this library back to life.

    What's New

    -Main changes for LuaSocket 2.1.1-rc1 are IPv6 support +Main changes for LuaSocket 2.1-rc1 are IPv6 support and Lua 5.2 compatibility.

    @@ -135,6 +135,7 @@ and Lua 5.2 compatibility. diff --git a/doc/installation.html b/doc/installation.html index 00b2db0..37c309b 100644 --- a/doc/installation.html +++ b/doc/installation.html @@ -39,7 +39,7 @@ Installation">

    Installation

    -

    LuaSocket 2.1.1-rc still uses Lua 5.1's package +

    LuaSocket 2.1-rc still uses Lua 5.1's package system. Users that have already made the switch to Lua 5.2 should leave the default LUA_COMPAT_MODULE defined when compiling their Lua @@ -95,7 +95,7 @@ it should be easy to use LuaSocket. Just fire the interpreter and use the Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio > socket = require("socket") > print(socket._VERSION) ---> LuaSocket 2.1.1-rc1 +--> LuaSocket 2.1-rc1

    Each module loads their dependencies automatically, so you only need to diff --git a/doc/reference.html b/doc/reference.html index d1043d4..f069d47 100644 --- a/doc/reference.html +++ b/doc/reference.html @@ -148,6 +148,7 @@ Support, Manual"> _DEBUG, dns, gettime, +headers.canonic, newtry, protect, select, diff --git a/doc/smtp.html b/doc/smtp.html index 2ef673a..bbbff80 100644 --- a/doc/smtp.html +++ b/doc/smtp.html @@ -90,8 +90,9 @@ headers = {

    -Field names are case insensitive (as specified by the standard) and all -functions work with lowercase field names. +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.

    diff --git a/doc/socket.html b/doc/socket.html index 2267b4a..dcf8b61 100644 --- a/doc/socket.html +++ b/doc/socket.html @@ -112,6 +112,29 @@ t = socket.gettime() print(socket.gettime() - t .. " seconds elapsed") + + +

    +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")
    +
    +

    diff --git a/etc/b64.lua b/etc/b64.lua index f75c423..11eeb2d 100644 --- a/etc/b64.lua +++ b/etc/b64.lua @@ -2,7 +2,6 @@ -- Little program to convert to and from Base64 -- LuaSocket sample files -- Author: Diego Nehab --- RCS ID: $Id: b64.lua,v 1.8 2004/06/16 04:28:21 diego Exp $ ----------------------------------------------------------------------------- local ltn12 = require("ltn12") local mime = require("mime") diff --git a/etc/check-links.lua b/etc/check-links.lua index a989f8c..d2e4266 100644 --- a/etc/check-links.lua +++ b/etc/check-links.lua @@ -3,7 +3,6 @@ -- non-blocking I/O via the dispatcher module. -- LuaSocket sample files -- Author: Diego Nehab --- RCS ID: $$ ----------------------------------------------------------------------------- local url = require("socket.url") local dispatch = require("dispatch") diff --git a/etc/dict.lua b/etc/dict.lua index e375d23..8c5b711 100644 --- a/etc/dict.lua +++ b/etc/dict.lua @@ -2,7 +2,6 @@ -- Little program to download DICT word definitions -- LuaSocket sample files -- Author: Diego Nehab --- RCS ID: $Id: dict.lua,v 1.22 2005/11/22 08:33:29 diego Exp $ ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- diff --git a/etc/dispatch.lua b/etc/dispatch.lua index 5236f3d..cc8cb23 100644 --- a/etc/dispatch.lua +++ b/etc/dispatch.lua @@ -2,7 +2,6 @@ -- A hacked dispatcher module -- LuaSocket sample files -- Author: Diego Nehab --- RCS ID: $$ ----------------------------------------------------------------------------- local base = _G local table = require("table") diff --git a/etc/eol.lua b/etc/eol.lua index b90be79..eeaf0ce 100644 --- a/etc/eol.lua +++ b/etc/eol.lua @@ -2,7 +2,6 @@ -- Little program to adjust end of line markers. -- LuaSocket sample files -- Author: Diego Nehab --- RCS ID: $Id: eol.lua,v 1.8 2005/11/22 08:33:29 diego Exp $ ----------------------------------------------------------------------------- local mime = require("mime") local ltn12 = require("ltn12") diff --git a/etc/get.lua b/etc/get.lua index 4c344e2..4196f00 100644 --- a/etc/get.lua +++ b/etc/get.lua @@ -2,7 +2,6 @@ -- Little program to download files from URLs -- LuaSocket sample files -- Author: Diego Nehab --- RCS ID: $Id: get.lua,v 1.25 2007/03/12 04:08:40 diego Exp $ ----------------------------------------------------------------------------- local socket = require("socket") local http = require("socket.http") diff --git a/etc/lp.lua b/etc/lp.lua index d57c928..25f0b95 100644 --- a/etc/lp.lua +++ b/etc/lp.lua @@ -3,7 +3,6 @@ -- LuaSocket toolkit. -- Author: David Burgess -- Modified by Diego Nehab, but David is in charge --- RCS ID: $Id: lp.lua,v 1.14 2005/11/21 07:04:44 diego Exp $ ----------------------------------------------------------------------------- --[[ if you have any questions: RFC 1179 diff --git a/etc/qp.lua b/etc/qp.lua index a4c0cad..523238b 100644 --- a/etc/qp.lua +++ b/etc/qp.lua @@ -2,7 +2,6 @@ -- Little program to convert to and from Quoted-Printable -- LuaSocket sample files -- Author: Diego Nehab --- RCS ID: $Id: qp.lua,v 1.5 2004/06/17 21:46:22 diego Exp $ ----------------------------------------------------------------------------- local ltn12 = require("ltn12") local mime = require("mime") diff --git a/etc/tftp.lua b/etc/tftp.lua index 7f51c6f..ed99cd1 100644 --- a/etc/tftp.lua +++ b/etc/tftp.lua @@ -2,7 +2,6 @@ -- TFTP support for the Lua language -- LuaSocket toolkit. -- Author: Diego Nehab --- RCS ID: $Id: tftp.lua,v 1.16 2005/11/22 08:33:29 diego Exp $ ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- diff --git a/makefile.dist b/makefile.dist index fbd6681..2c6137b 100644 --- a/makefile.dist +++ b/makefile.dist @@ -1,7 +1,7 @@ #-------------------------------------------------------------------------- # Distribution makefile #-------------------------------------------------------------------------- -DIST = luasocket-2.1.1-rc1 +DIST = luasocket-2.1-rc1 TEST = \ test/README \ diff --git a/samples/daytimeclnt.lua b/samples/daytimeclnt.lua index 90ab39e..f81e37c 100644 --- a/samples/daytimeclnt.lua +++ b/samples/daytimeclnt.lua @@ -2,7 +2,6 @@ -- UDP sample: daytime protocol client -- LuaSocket sample files -- Author: Diego Nehab --- RCS ID: $Id: daytimeclnt.lua,v 1.11 2004/06/21 06:07:57 diego Exp $ ----------------------------------------------------------------------------- local socket = require"socket" host = host or "127.0.0.1" diff --git a/samples/echoclnt.lua b/samples/echoclnt.lua index 038be4c..bb22557 100644 --- a/samples/echoclnt.lua +++ b/samples/echoclnt.lua @@ -2,7 +2,6 @@ -- UDP sample: echo protocol client -- LuaSocket sample files -- Author: Diego Nehab --- RCS ID: $Id: echoclnt.lua,v 1.10 2005/01/02 22:44:00 diego Exp $ ----------------------------------------------------------------------------- local socket = require("socket") host = host or "localhost" diff --git a/samples/echosrvr.lua b/samples/echosrvr.lua index 2697ca4..ea564e2 100644 --- a/samples/echosrvr.lua +++ b/samples/echosrvr.lua @@ -2,7 +2,6 @@ -- UDP sample: echo protocol server -- LuaSocket sample files -- Author: Diego Nehab --- RCS ID: $Id: echosrvr.lua,v 1.12 2005/11/22 08:33:29 diego Exp $ ----------------------------------------------------------------------------- local socket = require("socket") host = host or "127.0.0.1" diff --git a/samples/listener.lua b/samples/listener.lua index 9260fbb..77db2d5 100644 --- a/samples/listener.lua +++ b/samples/listener.lua @@ -2,7 +2,6 @@ -- TCP sample: Little program to dump lines received at a given port -- LuaSocket sample files -- Author: Diego Nehab --- RCS ID: $Id: listener.lua,v 1.11 2005/01/02 22:44:00 diego Exp $ ----------------------------------------------------------------------------- local socket = require("socket") host = host or "*" diff --git a/samples/talker.lua b/samples/talker.lua index 607ff31..d5a36cb 100644 --- a/samples/talker.lua +++ b/samples/talker.lua @@ -2,7 +2,6 @@ -- TCP sample: Little program to send text lines to a given host/port -- LuaSocket sample files -- Author: Diego Nehab --- RCS ID: $Id: talker.lua,v 1.9 2005/01/02 22:44:00 diego Exp $ ----------------------------------------------------------------------------- local socket = require("socket") host = host or "localhost" diff --git a/samples/tinyirc.lua b/samples/tinyirc.lua index f474302..e75851f 100644 --- a/samples/tinyirc.lua +++ b/samples/tinyirc.lua @@ -2,7 +2,6 @@ -- Select sample: simple text line server -- LuaSocket sample files. -- Author: Diego Nehab --- RCS ID: $Id: tinyirc.lua,v 1.14 2005/11/22 08:33:29 diego Exp $ ----------------------------------------------------------------------------- local socket = require("socket") host = host or "*" 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 diff --git a/test/urltest.lua b/test/urltest.lua index d46cb03..71e4428 100644 --- a/test/urltest.lua +++ b/test/urltest.lua @@ -8,7 +8,7 @@ local check_build_url = function(parsed) print("built is different from expected") print(built) print(expected) - exit() + os.exit() end end @@ -17,7 +17,7 @@ local check_protect = function(parsed, path, unsafe) if built ~= path then print(built, path) print("path composition failed.") - exit() + os.exit() end end @@ -28,7 +28,7 @@ local check_invert = function(url) if rebuilt ~= url then print(url, rebuilt) print("original and rebuilt are different") - exit() + os.exit() end end @@ -37,24 +37,24 @@ local check_parse_path = function(path, expect) for i = 1, math.max(table.getn(parsed), table.getn(expect)) do if parsed[i] ~= expect[i] then print(path) - exit() + os.exit() end end if expect.is_directory ~= parsed.is_directory then print(path) print("is_directory mismatch") - exit() + os.exit() end if expect.is_absolute ~= parsed.is_absolute then print(path) print("is_absolute mismatch") - exit() + os.exit() end local built = socket.url.build_path(expect) if built ~= path then print(built, path) print("path composition failed.") - exit() + os.exit() end end @@ -63,7 +63,7 @@ local check_absolute_url = function(base, relative, absolute) if res ~= absolute then io.write("absolute: In test for '", relative, "' expected '", absolute, "' but got '", res, "'\n") - exit() + os.exit() end end @@ -76,7 +76,7 @@ local check_parse_url = function(gaba) 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 - exit() + os.exit() end end for i, v in pairs(parsed) do @@ -84,7 +84,7 @@ local check_parse_url = function(gaba) 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 - exit() + os.exit() end end end @@ -304,6 +304,92 @@ check_parse_url{ path = "path", } +-- IPv6 tests + +check_parse_url{ + url = "http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html", + scheme = "http", + host = "FEDC:BA98:7654:3210:FEDC:BA98:7654:3210", + authority = "[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80", + port = "80", + path = "/index.html" +} + +check_parse_url{ + url = "http://[1080:0:0:0:8:800:200C:417A]/index.html", + scheme = "http", + host = "1080:0:0:0:8:800:200C:417A", + authority = "[1080:0:0:0:8:800:200C:417A]", + path = "/index.html" +} + +check_parse_url{ + url = "http://[3ffe:2a00:100:7031::1]", + scheme = "http", + host = "3ffe:2a00:100:7031::1", + authority = "[3ffe:2a00:100:7031::1]", +} + +check_parse_url{ + url = "http://[1080::8:800:200C:417A]/foo", + scheme = "http", + host = "1080::8:800:200C:417A", + authority = "[1080::8:800:200C:417A]", + path = "/foo" +} + +check_parse_url{ + url = "http://[::192.9.5.5]/ipng", + scheme = "http", + host = "::192.9.5.5", + authority = "[::192.9.5.5]", + path = "/ipng" +} + +check_parse_url{ + url = "http://[::FFFF:129.144.52.38]:80/index.html", + scheme = "http", + host = "::FFFF:129.144.52.38", + port = "80", + authority = "[::FFFF:129.144.52.38]:80", + path = "/index.html" +} + +check_parse_url{ + url = "http://[2010:836B:4179::836B:4179]", + scheme = "http", + host = "2010:836B:4179::836B:4179", + authority = "[2010:836B:4179::836B:4179]", +} + +check_parse_url{ + url = "//userinfo@[::FFFF:129.144.52.38]:port/path;params?query#fragment", + authority = "userinfo@[::FFFF:129.144.52.38]:port", + host = "::FFFF:129.144.52.38", + port = "port", + userinfo = "userinfo", + user = "userinfo", + path = "/path", + params = "params", + query = "query", + fragment = "fragment" +} + +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", + host = "::192.9.5.5", + port = "port", + userinfo = "user:password", + user = "user", + password = "password", + path = "/path", + params = "params", + query = "query", + fragment = "fragment" +} + print("testing URL building") check_build_url { url = "scheme://user:password@host:port/path;params?query#fragment", @@ -318,6 +404,30 @@ check_build_url { fragment = "fragment" } +check_build_url{ + url = "//userinfo@[::FFFF:129.144.52.38]:port/path;params?query#fragment", + host = "::FFFF:129.144.52.38", + port = "port", + user = "userinfo", + path = "/path", + params = "params", + query = "query", + fragment = "fragment" +} + +check_build_url{ + url = "scheme://user:password@[::192.9.5.5]:port/path;params?query#fragment", + scheme = "scheme", + host = "::192.9.5.5", + port = "port", + user = "user", + password = "password", + path = "/path", + params = "params", + query = "query", + fragment = "fragment" +} + check_build_url { url = "scheme://user:password@host/path;params?query#fragment", scheme = "scheme", @@ -520,5 +630,6 @@ check_invert("/b/c/d;param#fragment") check_invert("/b/c/d;param?query#fragment") check_invert("/b/c/d?query") check_invert("/b/c/d;param?query") +check_invert("http://he:man@[::192.168.1.1]/a/b/c/i.html;type=moo?this=that#mark") print("the library passed all tests")