mirror of
https://github.com/lunarmodules/luasocket.git
synced 2025-07-13 22:24:28 +02:00
Compare commits
14 Commits
hjelmeland
...
9aa01250a7
Author | SHA1 | Date | |
---|---|---|---|
9aa01250a7 | |||
98be8d9fc1 | |||
fa69770e52 | |||
13f2b3c663 | |||
453a5207ed | |||
de359ea408 | |||
c93f9154e1 | |||
8a5368b659 | |||
22b8202d70 | |||
3a817a56eb | |||
7eaf648056 | |||
bef62aeb50 | |||
b0470f4a0e | |||
c27c23074c |
@ -89,7 +89,7 @@ it should be easy to use LuaSocket. Just fire the interpreter and use the
|
|||||||
Lua 5.2.2 Copyright (C) 1994-2013 Lua.org, PUC-Rio
|
Lua 5.2.2 Copyright (C) 1994-2013 Lua.org, PUC-Rio
|
||||||
> socket = require("socket")
|
> socket = require("socket")
|
||||||
> print(socket._VERSION)
|
> print(socket._VERSION)
|
||||||
--> LuaSocket 3.0.0
|
--> LuaSocket 3.1.0
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
<p> Each module loads their dependencies automatically, so you only need to
|
<p> Each module loads their dependencies automatically, so you only need to
|
||||||
|
@ -69,6 +69,7 @@ local function make_plat(plat)
|
|||||||
["socket.smtp"] = "src/smtp.lua",
|
["socket.smtp"] = "src/smtp.lua",
|
||||||
ltn12 = "src/ltn12.lua",
|
ltn12 = "src/ltn12.lua",
|
||||||
socket = "src/socket.lua",
|
socket = "src/socket.lua",
|
||||||
|
mbox = "src/mbox.lua",
|
||||||
mime = "src/mime.lua"
|
mime = "src/mime.lua"
|
||||||
}
|
}
|
||||||
if plat == "unix"
|
if plat == "unix"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#--------------------------------------------------------------------------
|
#--------------------------------------------------------------------------
|
||||||
# Distribution makefile
|
# Distribution makefile
|
||||||
#--------------------------------------------------------------------------
|
#--------------------------------------------------------------------------
|
||||||
DIST = luasocket-3.0.0
|
DIST = luasocket-3.1.0
|
||||||
|
|
||||||
TEST = \
|
TEST = \
|
||||||
test/README \
|
test/README \
|
||||||
|
25
src/buffer.c
25
src/buffer.c
@ -9,7 +9,7 @@
|
|||||||
* Internal function prototypes
|
* Internal function prototypes
|
||||||
\*=========================================================================*/
|
\*=========================================================================*/
|
||||||
static int recvraw(p_buffer buf, size_t wanted, luaL_Buffer *b);
|
static int recvraw(p_buffer buf, size_t wanted, luaL_Buffer *b);
|
||||||
static int recvline(p_buffer buf, luaL_Buffer *b);
|
static int recvline(p_buffer buf, luaL_Buffer *b, int chop);
|
||||||
static int recvall(p_buffer buf, luaL_Buffer *b);
|
static int recvall(p_buffer buf, luaL_Buffer *b);
|
||||||
static int buffer_get(p_buffer buf, const char **data, size_t *count);
|
static int buffer_get(p_buffer buf, const char **data, size_t *count);
|
||||||
static void buffer_skip(p_buffer buf, size_t count);
|
static void buffer_skip(p_buffer buf, size_t count);
|
||||||
@ -117,10 +117,21 @@ int buffer_meth_receive(lua_State *L, p_buffer buf) {
|
|||||||
luaL_addlstring(&b, part, size);
|
luaL_addlstring(&b, part, size);
|
||||||
/* receive new patterns */
|
/* receive new patterns */
|
||||||
if (!lua_isnumber(L, 2)) {
|
if (!lua_isnumber(L, 2)) {
|
||||||
const char *p= luaL_optstring(L, 2, "*l");
|
const char *p = luaL_optstring(L, 2, "l");
|
||||||
if (p[0] == '*' && p[1] == 'l') err = recvline(buf, &b);
|
if (*p == '*') p++; /* skip optional '*' (for compatibility) */
|
||||||
else if (p[0] == '*' && p[1] == 'a') err = recvall(buf, &b);
|
switch (*p) {
|
||||||
else luaL_argcheck(L, 0, 2, "invalid receive pattern");
|
case 'l': /* line */
|
||||||
|
err = recvline(buf, &b, 1);
|
||||||
|
break;
|
||||||
|
case 'L': /* line with \n */
|
||||||
|
err = recvline(buf, &b, 0);
|
||||||
|
break;
|
||||||
|
case 'a': /* all */
|
||||||
|
err = recvall(buf, &b);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
luaL_argcheck(L, 0, 2, "invalid receive pattern");
|
||||||
|
}
|
||||||
/* get a fixed number of bytes (minus what was already partially
|
/* get a fixed number of bytes (minus what was already partially
|
||||||
* received) */
|
* received) */
|
||||||
} else {
|
} else {
|
||||||
@ -222,7 +233,7 @@ static int recvall(p_buffer buf, luaL_Buffer *b) {
|
|||||||
* Reads a line terminated by a CR LF pair or just by a LF. The CR and LF
|
* Reads a line terminated by a CR LF pair or just by a LF. The CR and LF
|
||||||
* are not returned by the function and are discarded from the buffer
|
* are not returned by the function and are discarded from the buffer
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
static int recvline(p_buffer buf, luaL_Buffer *b) {
|
static int recvline(p_buffer buf, luaL_Buffer *b, int chop) {
|
||||||
int err = IO_DONE;
|
int err = IO_DONE;
|
||||||
while (err == IO_DONE) {
|
while (err == IO_DONE) {
|
||||||
size_t count, pos; const char *data;
|
size_t count, pos; const char *data;
|
||||||
@ -234,6 +245,8 @@ static int recvline(p_buffer buf, luaL_Buffer *b) {
|
|||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
if (pos < count) { /* found '\n' */
|
if (pos < count) { /* found '\n' */
|
||||||
|
if (!chop)
|
||||||
|
luaL_addchar(b, '\n');
|
||||||
buffer_skip(buf, pos+1); /* skip '\n' too */
|
buffer_skip(buf, pos+1); /* skip '\n' too */
|
||||||
break; /* we are done */
|
break; /* we are done */
|
||||||
} else /* reached the end of the buffer */
|
} else /* reached the end of the buffer */
|
||||||
|
19
src/http.lua
19
src/http.lua
@ -54,7 +54,7 @@ local function receiveheaders(sock, headers)
|
|||||||
while line ~= "" do
|
while line ~= "" do
|
||||||
-- get field-name and value
|
-- get field-name and value
|
||||||
name, value = socket.skip(2, string.find(line, "^(.-):%s*(.*)"))
|
name, value = socket.skip(2, string.find(line, "^(.-):%s*(.*)"))
|
||||||
if not (name and value) then return nil, "malformed reponse headers" end
|
if not (name and value) then return nil, "malformed response headers" end
|
||||||
name = string.lower(name)
|
name = string.lower(name)
|
||||||
-- get next line (value might be folded)
|
-- get next line (value might be folded)
|
||||||
line, err = sock:receive()
|
line, err = sock:receive()
|
||||||
@ -62,7 +62,7 @@ local function receiveheaders(sock, headers)
|
|||||||
-- unfold any folded values
|
-- unfold any folded values
|
||||||
while string.find(line, "^%s") do
|
while string.find(line, "^%s") do
|
||||||
value = value .. line
|
value = value .. line
|
||||||
line = sock:receive()
|
line, err = sock:receive()
|
||||||
if err then return nil, err end
|
if err then return nil, err end
|
||||||
end
|
end
|
||||||
-- save pair in table
|
-- save pair in table
|
||||||
@ -81,7 +81,7 @@ socket.sourcet["http-chunked"] = function(sock, headers)
|
|||||||
dirty = function() return sock:dirty() end
|
dirty = function() return sock:dirty() end
|
||||||
}, {
|
}, {
|
||||||
__call = function()
|
__call = function()
|
||||||
-- get chunk size, skip extention
|
-- get chunk size, skip extension
|
||||||
local line, err = sock:receive()
|
local line, err = sock:receive()
|
||||||
if err then return nil, err end
|
if err then return nil, err end
|
||||||
local size = base.tonumber(string.gsub(line, ";.*", ""), 16)
|
local size = base.tonumber(string.gsub(line, ";.*", ""), 16)
|
||||||
@ -219,9 +219,11 @@ local function adjustproxy(reqt)
|
|||||||
local proxy = reqt.proxy or _M.PROXY
|
local proxy = reqt.proxy or _M.PROXY
|
||||||
if proxy then
|
if proxy then
|
||||||
proxy = url.parse(proxy)
|
proxy = url.parse(proxy)
|
||||||
return proxy.host, proxy.port or 3128
|
proxy.port = proxy.port or 3128
|
||||||
|
proxy.create = SCHEMES[proxy.scheme].create(reqt)
|
||||||
|
return proxy.host, proxy.port, proxy.create
|
||||||
else
|
else
|
||||||
return reqt.host, reqt.port
|
return reqt.host, reqt.port, reqt.create
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -279,7 +281,7 @@ local function adjustrequest(reqt)
|
|||||||
if not (host and host ~= "") then
|
if not (host and host ~= "") then
|
||||||
socket.try(nil, "invalid host '" .. base.tostring(nreqt.host) .. "'")
|
socket.try(nil, "invalid host '" .. base.tostring(nreqt.host) .. "'")
|
||||||
end
|
end
|
||||||
-- compute uri if user hasn't overriden
|
-- compute uri if user hasn't overridden
|
||||||
nreqt.uri = reqt.uri or adjusturi(nreqt)
|
nreqt.uri = reqt.uri or adjusturi(nreqt)
|
||||||
-- adjust headers in request
|
-- adjust headers in request
|
||||||
nreqt.headers = adjustheaders(nreqt)
|
nreqt.headers = adjustheaders(nreqt)
|
||||||
@ -291,7 +293,10 @@ local function adjustrequest(reqt)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- ajust host and port if there is a proxy
|
-- ajust host and port if there is a proxy
|
||||||
nreqt.host, nreqt.port = adjustproxy(nreqt)
|
local proxy_create
|
||||||
|
nreqt.host, nreqt.port, proxy_create = adjustproxy(nreqt)
|
||||||
|
if not reqt.create then nreqt.create = proxy_create end
|
||||||
|
|
||||||
return nreqt
|
return nreqt
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -290,7 +290,7 @@ int inet_meth_getsockname(lua_State *L, p_socket ps, int family)
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
lua_pushstring(L, name);
|
lua_pushstring(L, name);
|
||||||
lua_pushstring(L, port);
|
lua_pushinteger(L, (int) strtol(port, (char **) NULL, 10));
|
||||||
switch (family) {
|
switch (family) {
|
||||||
case AF_INET: lua_pushliteral(L, "inet"); break;
|
case AF_INET: lua_pushliteral(L, "inet"); break;
|
||||||
case AF_INET6: lua_pushliteral(L, "inet6"); break;
|
case AF_INET6: lua_pushliteral(L, "inet6"); break;
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
/*-------------------------------------------------------------------------* \
|
/*-------------------------------------------------------------------------* \
|
||||||
* Current socket library version
|
* Current socket library version
|
||||||
\*-------------------------------------------------------------------------*/
|
\*-------------------------------------------------------------------------*/
|
||||||
#define LUASOCKET_VERSION "LuaSocket 3.0.0"
|
#define LUASOCKET_VERSION "LuaSocket 3.1.0"
|
||||||
#define LUASOCKET_COPYRIGHT "Copyright (C) 1999-2013 Diego Nehab"
|
#define LUASOCKET_COPYRIGHT "Copyright (C) 1999-2013 Diego Nehab"
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*\
|
/*-------------------------------------------------------------------------*\
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# luasocket src/makefile
|
# luasocket src/makefile
|
||||||
#
|
#
|
||||||
# Definitions in this section can be overriden on the command line or in the
|
# Definitions in this section can be overridden on the command line or in the
|
||||||
# environment.
|
# environment.
|
||||||
#
|
#
|
||||||
# These are equivalent:
|
# These are equivalent:
|
||||||
@ -272,7 +272,7 @@ SOCKET_win64=wsocket.obj
|
|||||||
#
|
#
|
||||||
SO=$(SO_$(PLAT))
|
SO=$(SO_$(PLAT))
|
||||||
O=$(O_$(PLAT))
|
O=$(O_$(PLAT))
|
||||||
SOCKET_V=3.0.0
|
SOCKET_V=3.1.0
|
||||||
MIME_V=1.0.3
|
MIME_V=1.0.3
|
||||||
SOCKET_SO=socket-$(SOCKET_V).$(SO)
|
SOCKET_SO=socket-$(SOCKET_V).$(SO)
|
||||||
MIME_SO=mime-$(MIME_V).$(SO)
|
MIME_SO=mime-$(MIME_V).$(SO)
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
#define PIE_CONNREFUSED "connection refused"
|
#define PIE_CONNREFUSED "connection refused"
|
||||||
#define PIE_CONNABORTED "closed"
|
#define PIE_CONNABORTED "closed"
|
||||||
#define PIE_CONNRESET "closed"
|
#define PIE_CONNRESET "closed"
|
||||||
#define PIE_TIMEDOUT "connection timeout"
|
#define PIE_TIMEDOUT "timeout"
|
||||||
#define PIE_AGAIN "temporary failure in name resolution"
|
#define PIE_AGAIN "temporary failure in name resolution"
|
||||||
#define PIE_BADFLAGS "invalid value for ai_flags"
|
#define PIE_BADFLAGS "invalid value for ai_flags"
|
||||||
#define PIE_BADHINTS "invalid value for hints"
|
#define PIE_BADHINTS "invalid value for hints"
|
||||||
|
@ -225,7 +225,7 @@ local function adjust_headers(mesgt)
|
|||||||
lower["date"] = lower["date"] or
|
lower["date"] = lower["date"] or
|
||||||
os.date("!%a, %d %b %Y %H:%M:%S ") .. (mesgt.zone or _M.ZONE)
|
os.date("!%a, %d %b %Y %H:%M:%S ") .. (mesgt.zone or _M.ZONE)
|
||||||
lower["x-mailer"] = lower["x-mailer"] or socket._VERSION
|
lower["x-mailer"] = lower["x-mailer"] or socket._VERSION
|
||||||
-- this can't be overriden
|
-- this can't be overridden
|
||||||
lower["mime-version"] = "1.0"
|
lower["mime-version"] = "1.0"
|
||||||
return lower
|
return lower
|
||||||
end
|
end
|
||||||
|
@ -152,7 +152,7 @@ function _M.parse(url, default)
|
|||||||
url = string.gsub(url, "^([%w][%w%+%-%.]*)%:",
|
url = string.gsub(url, "^([%w][%w%+%-%.]*)%:",
|
||||||
function(s) parsed.scheme = s; return "" end)
|
function(s) parsed.scheme = s; return "" end)
|
||||||
-- get authority
|
-- get authority
|
||||||
url = string.gsub(url, "^//([^/]*)", function(n)
|
url = string.gsub(url, "^//([^/%?#]*)", function(n)
|
||||||
parsed.authority = n
|
parsed.authority = n
|
||||||
return ""
|
return ""
|
||||||
end)
|
end)
|
||||||
|
@ -262,6 +262,7 @@ int socket_recv(p_socket ps, char *data, size_t count, size_t *got,
|
|||||||
if (err != WSAEWOULDBLOCK) {
|
if (err != WSAEWOULDBLOCK) {
|
||||||
if (err != WSAECONNRESET || prev == WSAECONNRESET) return err;
|
if (err != WSAECONNRESET || prev == WSAECONNRESET) return err;
|
||||||
prev = err;
|
prev = err;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err;
|
if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err;
|
||||||
}
|
}
|
||||||
@ -291,6 +292,7 @@ int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got,
|
|||||||
if (err != WSAEWOULDBLOCK) {
|
if (err != WSAEWOULDBLOCK) {
|
||||||
if (err != WSAECONNRESET || prev == WSAECONNRESET) return err;
|
if (err != WSAECONNRESET || prev == WSAECONNRESET) return err;
|
||||||
prev = err;
|
prev = err;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err;
|
if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user