Out of the box support for Lua 5.3.

master
Diego Nehab 2015-02-18 20:51:37 -02:00
parent 5edf093643
commit ddf4292824
7 changed files with 96 additions and 85 deletions

View File

@ -5,8 +5,8 @@
# Targets:
# install install system independent support
# install-unix also install unix-only support
# install-both install for both lua5.1 and lua5.2
# install-both-unix also install unix-only
# install-both install for lua51 lua52 lua53
# install-both-unix also install unix-only
# print print the build settings
PLAT?= linux
@ -24,20 +24,26 @@ test:
lua test/hello.lua
install-both:
$(MAKE) clean
$(MAKE) clean
@cd src; $(MAKE) $(PLAT) LUAV=5.1
@cd src; $(MAKE) install LUAV=5.1
$(MAKE) clean
$(MAKE) clean
@cd src; $(MAKE) $(PLAT) LUAV=5.2
@cd src; $(MAKE) install LUAV=5.2
$(MAKE) clean
@cd src; $(MAKE) $(PLAT) LUAV=5.3
@cd src; $(MAKE) install LUAV=5.3
install-both-unix:
$(MAKE) clean
$(MAKE) clean
@cd src; $(MAKE) $(PLAT) LUAV=5.1
@cd src; $(MAKE) install-unix LUAV=5.1
$(MAKE) clean
$(MAKE) clean
@cd src; $(MAKE) $(PLAT) LUAV=5.2
@cd src; $(MAKE) install-unix LUAV=5.2
$(MAKE) clean
@cd src; $(MAKE) $(PLAT) LUAV=5.3
@cd src; $(MAKE) install-unix LUAV=5.3
.PHONY: test

View File

@ -18,7 +18,6 @@
#include "lua.h"
#include "lauxlib.h"
/*=========================================================================*\
* LuaSocket includes
\*=========================================================================*/
@ -32,6 +31,11 @@
#include "udp.h"
#include "select.h"
#if LUA_VERSION_NUM > 502 && !defined(LUA_COMPAT_APIINTCASTS)
#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n)))
#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d)))
#endif
/*-------------------------------------------------------------------------*\
* Internal function prototypes
\*-------------------------------------------------------------------------*/
@ -78,14 +82,6 @@ static int global_unload(lua_State *L) {
return 0;
}
#if LUA_VERSION_NUM > 501
int luaL_typerror (lua_State *L, int narg, const char *tname) {
const char *msg = lua_pushfstring(L, "%s expected, got %s",
tname, luaL_typename(L, narg));
return luaL_argerror(L, narg, msg);
}
#endif
/*-------------------------------------------------------------------------*\
* Setup basic stuff.
\*-------------------------------------------------------------------------*/

View File

@ -147,7 +147,7 @@ DEF_macosx= -DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN -DLUA_$(COMPAT)_MODULE \
-DLUASOCKET_API='__attribute__((visibility("default")))' \
-DUNIX_API='__attribute__((visibility("default")))' \
-DMIME_API='__attribute__((visibility("default")))'
CFLAGS_macosx= -I$(LUAINC) $(DEF) -pedantic -Wall -O2 -fno-common \
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
@ -163,7 +163,7 @@ DEF_linux=-DLUASOCKET_$(DEBUG) -DLUA_$(COMPAT)_MODULE \
-DLUASOCKET_API='__attribute__((visibility("default")))' \
-DUNIX_API='__attribute__((visibility("default")))' \
-DMIME_API='__attribute__((visibility("default")))'
CFLAGS_linux= -I$(LUAINC) $(DEF) -pedantic -Wall -Wshadow -Wextra \
CFLAGS_linux= -I$(LUAINC) $(DEF) -Wall -Wshadow -Wextra \
-Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden
LDFLAGS_linux=-O -shared -fpic -o
LD_linux=gcc
@ -179,7 +179,7 @@ DEF_freebsd=-DLUASOCKET_$(DEBUG) -DLUA_$(COMPAT)_MODULE \
-DLUASOCKET_API='__attribute__((visibility("default")))' \
-DUNIX_API='__attribute__((visibility("default")))' \
-DMIME_API='__attribute__((visibility("default")))'
CFLAGS_freebsd= -I$(LUAINC) $(DEF) -pedantic -Wall -Wshadow -Wextra \
CFLAGS_freebsd= -I$(LUAINC) $(DEF) -Wall -Wshadow -Wextra \
-Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden
LDFLAGS_freebsd=-O -shared -fpic -o
LD_freebsd=gcc
@ -194,7 +194,7 @@ CC_mingw=gcc
DEF_mingw= -DLUASOCKET_INET_PTON -DLUASOCKET_$(DEBUG) -DLUA_$(COMPAT)_MODULE \
-DWINVER=0x0501 -DLUASOCKET_API='__declspec(dllexport)' \
-DMIME_API='__declspec(dllexport)'
CFLAGS_mingw= -I$(LUAINC) $(DEF) -pedantic -Wall -O2 -fno-common \
CFLAGS_mingw= -I$(LUAINC) $(DEF) -Wall -O2 -fno-common \
-fvisibility=hidden
LDFLAGS_mingw= $(LUALIB) -shared -Wl,-s -lws2_32 -o
LD_mingw=gcc

View File

@ -13,6 +13,11 @@
#include "mime.h"
#if LUA_VERSION_NUM > 502 && !defined(LUA_COMPAT_APIINTCASTS)
#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n)))
#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d)))
#endif
/*=========================================================================*\
* Don't want to trust escape character constants
\*=========================================================================*/
@ -41,7 +46,7 @@ static size_t b64decode(UC c, UC *input, size_t size, luaL_Buffer *buffer);
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,
static size_t qpencode(UC c, UC *input, size_t size,
const char *marker, luaL_Buffer *buffer);
static size_t qppad(UC *input, size_t size, luaL_Buffer *buffer);
@ -103,9 +108,9 @@ MIME_API int luaopen_mime_core(lua_State *L)
/*-------------------------------------------------------------------------*\
* Incrementaly breaks a string into lines. The string can have CRLF breaks.
* A, n = wrp(l, B, length)
* A is a copy of B, broken into lines of at most 'length' bytes.
* 'l' is how many bytes are left for the first line of B.
* 'n' is the number of bytes left in the last line of A.
* A is a copy of B, broken into lines of at most 'length' bytes.
* 'l' is how many bytes are left for the first line of B.
* 'n' is the number of bytes left in the last line of A.
\*-------------------------------------------------------------------------*/
static int mime_global_wrp(lua_State *L)
{
@ -123,7 +128,7 @@ static int mime_global_wrp(lua_State *L)
else lua_pushnil(L);
lua_pushnumber(L, length);
return 2;
}
}
luaL_buffinit(L, &buffer);
while (input < last) {
switch (*input) {
@ -150,9 +155,9 @@ static int mime_global_wrp(lua_State *L)
}
/*-------------------------------------------------------------------------*\
* Fill base64 decode map.
* Fill base64 decode map.
\*-------------------------------------------------------------------------*/
static void b64setup(UC *unbase)
static void b64setup(UC *unbase)
{
int i;
for (i = 0; i <= 255; i++) unbase[i] = (UC) 255;
@ -161,11 +166,11 @@ static void b64setup(UC *unbase)
}
/*-------------------------------------------------------------------------*\
* Acumulates bytes in input buffer until 3 bytes are available.
* Acumulates bytes in input buffer until 3 bytes are available.
* Translate the 3 bytes into Base64 form and append to buffer.
* Returns new number of bytes in buffer.
\*-------------------------------------------------------------------------*/
static size_t b64encode(UC c, UC *input, size_t size,
static size_t b64encode(UC c, UC *input, size_t size,
luaL_Buffer *buffer)
{
input[size++] = c;
@ -174,7 +179,7 @@ static size_t b64encode(UC c, UC *input, size_t size,
unsigned long value = 0;
value += input[0]; value <<= 8;
value += input[1]; value <<= 8;
value += input[2];
value += input[2];
code[3] = b64base[value & 0x3f]; value >>= 6;
code[2] = b64base[value & 0x3f]; value >>= 6;
code[1] = b64base[value & 0x3f]; value >>= 6;
@ -186,11 +191,11 @@ static size_t b64encode(UC c, UC *input, size_t size,
}
/*-------------------------------------------------------------------------*\
* Encodes the Base64 last 1 or 2 bytes and adds padding '='
* Encodes the Base64 last 1 or 2 bytes and adds padding '='
* Result, if any, is appended to buffer.
* Returns 0.
\*-------------------------------------------------------------------------*/
static size_t b64pad(const UC *input, size_t size,
static size_t b64pad(const UC *input, size_t size,
luaL_Buffer *buffer)
{
unsigned long value = 0;
@ -203,7 +208,7 @@ static size_t b64pad(const UC *input, size_t size,
luaL_addlstring(buffer, (char *) code, 4);
break;
case 2:
value = input[0]; value <<= 8;
value = input[0]; value <<= 8;
value |= input[1]; value <<= 2;
code[2] = b64base[value & 0x3f]; value >>= 6;
code[1] = b64base[value & 0x3f]; value >>= 6;
@ -217,11 +222,11 @@ static size_t b64pad(const UC *input, size_t size,
}
/*-------------------------------------------------------------------------*\
* Acumulates bytes in input buffer until 4 bytes are available.
* Acumulates bytes in input buffer until 4 bytes are available.
* Translate the 4 bytes from Base64 form and append to buffer.
* Returns new number of bytes in buffer.
\*-------------------------------------------------------------------------*/
static size_t b64decode(UC c, UC *input, size_t size,
static size_t b64decode(UC c, UC *input, size_t size,
luaL_Buffer *buffer)
{
/* ignore invalid characters */
@ -239,7 +244,7 @@ static size_t b64decode(UC c, UC *input, size_t size,
decoded[1] = (UC) (value & 0xff); value >>= 8;
decoded[0] = (UC) value;
/* take care of paddding */
valid = (input[2] == '=') ? 1 : (input[3] == '=') ? 2 : 3;
valid = (input[2] == '=') ? 1 : (input[3] == '=') ? 2 : 3;
luaL_addlstring(buffer, (char *) decoded, valid);
return 0;
/* need more data */
@ -251,7 +256,7 @@ static size_t b64decode(UC c, UC *input, size_t size,
* A, B = b64(C, D)
* A is the encoded version of the largest prefix of C .. D that is
* divisible by 3. B has the remaining bytes of C .. D, *without* encoding.
* The easiest thing would be to concatenate the two strings and
* The easiest thing would be to concatenate the two strings and
* encode the result, but we can't afford that or Lua would dupplicate
* every chunk we received.
\*-------------------------------------------------------------------------*/
@ -272,7 +277,7 @@ static int mime_global_b64(lua_State *L)
lua_settop(L, 2);
/* process first part of the input */
luaL_buffinit(L, &buffer);
while (input < last)
while (input < last)
asize = b64encode(*input++, atom, asize, &buffer);
input = (UC *) luaL_optlstring(L, 2, NULL, &isize);
/* if second part is nil, we are done */
@ -288,7 +293,7 @@ static int mime_global_b64(lua_State *L)
}
/* otherwise process the second part */
last = input + isize;
while (input < last)
while (input < last)
asize = b64encode(*input++, atom, asize, &buffer);
luaL_pushresult(&buffer);
lua_pushlstring(L, (char *) atom, asize);
@ -318,7 +323,7 @@ static int mime_global_unb64(lua_State *L)
lua_settop(L, 2);
/* process first part of the input */
luaL_buffinit(L, &buffer);
while (input < last)
while (input < last)
asize = b64decode(*input++, atom, asize, &buffer);
input = (UC *) luaL_optlstring(L, 2, NULL, &isize);
/* if second is nil, we are done */
@ -333,7 +338,7 @@ static int mime_global_unb64(lua_State *L)
}
/* otherwise, process the rest of the input */
last = input + isize;
while (input < last)
while (input < last)
asize = b64decode(*input++, atom, asize, &buffer);
luaL_pushresult(&buffer);
lua_pushlstring(L, (char *) atom, asize);
@ -349,7 +354,7 @@ static int mime_global_unb64(lua_State *L)
* 9 and 32 can be plain, unless in the end of a line, where must be =XX
* encoded lines must be no longer than 76 not counting CRLF
* soft line-break are =CRLF
* To encode one byte, we need to see the next two.
* 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
\*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*\
@ -362,7 +367,7 @@ static void qpsetup(UC *cl, UC *unbase)
for (i = 0; i < 256; i++) cl[i] = QP_QUOTED;
for (i = 33; i <= 60; i++) cl[i] = QP_PLAIN;
for (i = 62; i <= 126; i++) cl[i] = QP_PLAIN;
cl['\t'] = QP_IF_LAST;
cl['\t'] = QP_IF_LAST;
cl[' '] = QP_IF_LAST;
cl['\r'] = QP_CR;
for (i = 0; i < 256; i++) unbase[i] = 255;
@ -388,9 +393,9 @@ static void qpquote(UC c, luaL_Buffer *buffer)
/*-------------------------------------------------------------------------*\
* Accumulate characters until we are sure about how to deal with them.
* Once we are sure, output to the buffer, in the correct form.
* Once we are sure, output to the buffer, in the correct form.
\*-------------------------------------------------------------------------*/
static size_t qpencode(UC c, UC *input, size_t size,
static size_t qpencode(UC c, UC *input, size_t size,
const char *marker, luaL_Buffer *buffer)
{
input[size++] = c;
@ -431,7 +436,7 @@ static size_t qpencode(UC c, UC *input, size_t size,
}
/*-------------------------------------------------------------------------*\
* Deal with the final characters
* Deal with the final characters
\*-------------------------------------------------------------------------*/
static size_t qppad(UC *input, size_t size, luaL_Buffer *buffer)
{
@ -448,8 +453,8 @@ static size_t qppad(UC *input, size_t size, luaL_Buffer *buffer)
* Incrementally converts a string to quoted-printable
* A, B = qp(C, D, marker)
* Marker is the text to be used to replace CRLF sequences found in A.
* A is the encoded version of the largest prefix of C .. D that
* can be encoded without doubts.
* A is the encoded version of the largest prefix of C .. D that
* can be encoded without doubts.
* B has the remaining bytes of C .. D, *without* encoding.
\*-------------------------------------------------------------------------*/
static int mime_global_qp(lua_State *L)
@ -493,7 +498,7 @@ static int mime_global_qp(lua_State *L)
/*-------------------------------------------------------------------------*\
* Accumulate characters until we are sure about how to deal with them.
* Once we are sure, output the to the buffer, in the correct form.
* Once we are sure, output the to the buffer, in the correct form.
\*-------------------------------------------------------------------------*/
static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer) {
int d;
@ -501,8 +506,8 @@ static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer) {
/* deal with all characters we can deal */
switch (input[0]) {
/* if we have an escape character */
case '=':
if (size < 3) return size;
case '=':
if (size < 3) return size;
/* eliminate soft line break */
if (input[1] == '\r' && input[2] == '\n') return 0;
/* decode quoted representation */
@ -512,7 +517,7 @@ static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer) {
else luaL_addchar(buffer, (char) ((c << 4) + d));
return 0;
case '\r':
if (size < 2) return size;
if (size < 2) return size;
if (input[1] == '\n') luaL_addlstring(buffer, (char *)input, 2);
return 0;
default:
@ -525,8 +530,8 @@ static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer) {
/*-------------------------------------------------------------------------*\
* Incrementally decodes a string in quoted-printable
* A, B = qp(C, D)
* A is the decoded version of the largest prefix of C .. D that
* can be decoded without doubts.
* A is the decoded version of the largest prefix of C .. D that
* can be decoded without doubts.
* B has the remaining bytes of C .. D, *without* decoding.
\*-------------------------------------------------------------------------*/
static int mime_global_unqp(lua_State *L)
@ -555,7 +560,7 @@ static int mime_global_unqp(lua_State *L)
if (!(*lua_tostring(L, -1))) lua_pushnil(L);
lua_pushnil(L);
return 2;
}
}
/* otherwise process rest of input */
last = input + isize;
while (input < last)
@ -568,9 +573,9 @@ static int mime_global_unqp(lua_State *L)
/*-------------------------------------------------------------------------*\
* Incrementally breaks a quoted-printed string into lines
* A, n = qpwrp(l, B, length)
* A is a copy of B, broken into lines of at most 'length' bytes.
* 'l' is how many bytes are left for the first line of B.
* 'n' is the number of bytes left in the last line of A.
* A is a copy of B, broken into lines of at most 'length' bytes.
* 'l' is how many bytes are left for the first line of B.
* 'n' is the number of bytes left in the last line of A.
* There are two complications: lines can't be broken in the middle
* of an encoded =XX, and there might be line breaks already
\*-------------------------------------------------------------------------*/
@ -603,11 +608,11 @@ static int mime_global_qpwrp(lua_State *L)
if (left <= 3) {
left = length;
luaL_addstring(&buffer, EQCRLF);
}
}
luaL_addchar(&buffer, *input);
left--;
break;
default:
default:
if (left <= 1) {
left = length;
luaL_addstring(&buffer, EQCRLF);
@ -635,7 +640,7 @@ static int mime_global_qpwrp(lua_State *L)
* last is the previous character
\*-------------------------------------------------------------------------*/
#define eolcandidate(c) (c == '\r' || c == '\n')
static int eolprocess(int c, int last, const char *marker,
static int eolprocess(int c, int last, const char *marker,
luaL_Buffer *buffer)
{
if (eolcandidate(c)) {
@ -653,10 +658,10 @@ static int eolprocess(int c, int last, const char *marker,
}
/*-------------------------------------------------------------------------*\
* Converts a string to uniform EOL convention.
* Converts a string to uniform EOL convention.
* A, n = eol(o, B, marker)
* A is the converted version of the largest prefix of B that can be
* converted unambiguously. 'o' is the context returned by the previous
* converted unambiguously. 'o' is the context returned by the previous
* call. 'n' is the new context.
\*-------------------------------------------------------------------------*/
static int mime_global_eol(lua_State *L)
@ -683,18 +688,18 @@ static int mime_global_eol(lua_State *L)
}
/*-------------------------------------------------------------------------*\
* Takes one byte and stuff it if needed.
* Takes one byte and stuff it if needed.
\*-------------------------------------------------------------------------*/
static size_t dot(int c, size_t state, luaL_Buffer *buffer)
{
luaL_addchar(buffer, (char) c);
switch (c) {
case '\r':
case '\r':
return 1;
case '\n':
return (state == 1)? 2: 0;
case '.':
if (state == 2)
case '\n':
return (state == 1)? 2: 0;
case '.':
if (state == 2)
luaL_addchar(buffer, '.');
default:
return 0;
@ -719,7 +724,7 @@ static int mime_global_dot(lua_State *L)
}
/* process all input */
luaL_buffinit(L, &buffer);
while (input < last)
while (input < last)
state = dot(*input++, state, &buffer);
luaL_pushresult(&buffer);
lua_pushnumber(L, (lua_Number) state);

4
test/auth/.htaccess Normal file
View File

@ -0,0 +1,4 @@
AuthName "test-auth"
AuthType Basic
AuthUserFile /Users/diego/impa/luasocket/test/auth/.htpasswd
Require valid-user

View File

@ -1 +1 @@
luasocket:l8n2npozPB.sQ
luasocket:$apr1$47u2O.Me$.m/5BWAtt7GVoxsouIPBR1

View File

@ -1,4 +1,4 @@
-- needs Alias from /home/c/diego/tec/luasocket/test to
-- needs Alias from /home/c/diego/tec/luasocket/test to
-- "/luasocket-test" and "/luasocket-test/"
-- needs ScriptAlias from /home/c/diego/tec/luasocket/test/cgi
-- to "/luasocket-test-cgi" and "/luasocket-test-cgi/"
@ -36,22 +36,22 @@ index = readfile(index_file)
local check_result = function(response, expect, ignore)
for i,v in pairs(response) do
if not ignore[i] then
if v ~= expect[i] then
if v ~= expect[i] then
local f = io.open("err", "w")
f:write(tostring(v), "\n\n versus\n\n", tostring(expect[i]))
f:close()
fail(i .. " differs!")
fail(i .. " differs!")
end
end
end
for i,v in pairs(expect) do
if not ignore[i] then
if v ~= response[i] then
if v ~= response[i] then
local f = io.open("err", "w")
f:write(tostring(response[i]), "\n\n versus\n\n", tostring(v))
v = string.sub(type(v) == "string" and v or "", 1, 70)
f:close()
fail(i .. " differs!")
fail(i .. " differs!")
end
end
end
@ -61,10 +61,10 @@ end
local check_request = function(request, expect, ignore)
local t
if not request.sink then request.sink, t = ltn12.sink.table() end
request.source = request.source or
request.source = request.source or
(request.body and ltn12.source.string(request.body))
local response = {}
response.code, response.headers, response.status =
response.code, response.headers, response.status =
socket.skip(1, http.request(request))
if t and #t > 0 then response.body = table.concat(t) end
check_result(response, expect, ignore)
@ -82,7 +82,7 @@ else fail(back.query) end
------------------------------------------------------------------------
io.write("testing query string correctness: ")
forth = "this+is+the+query+string"
back = http.request("http://" .. host .. cgiprefix ..
back = http.request("http://" .. host .. cgiprefix ..
"/query-string?" .. forth)
if similar(back, forth) then print("ok")
else fail("failed!") end
@ -120,10 +120,10 @@ check_request(request, expect, ignore)
------------------------------------------------------------------------
io.write("testing invalid url: ")
local r, e = http.request{url = host .. prefix}
assert(r == nil and e == "invalid host ''")
assert(r == nil and e == "invalid host ''")
r, re = http.request(host .. prefix)
assert(r == nil and e == re, tostring(r) ..", " .. tostring(re) ..
" vs " .. tostring(e))
assert(r == nil and e == re, tostring(r) ..", " .. tostring(re) ..
" vs " .. tostring(e))
print("ok")
io.write("testing invalid empty port: ")
@ -212,7 +212,7 @@ os.remove(index_file .. "-back")
io.write("testing ltn12.(sink|source).chain and mime.(encode|decode): ")
local function b64length(len)
local a = math.ceil(len/3)*4
local a = math.ceil(len/3)*4
local l = math.ceil(a/76)
return a + l*2
end
@ -313,7 +313,7 @@ ignore = {
headers = 1
}
check_request(request, expect, ignore)
------------------------------------------------------------------------
io.write("testing document not found: ")
request = {
@ -429,9 +429,9 @@ print("ok")
io.write("testing host not found: ")
local c, e = socket.connect("example.invalid", 80)
local r, re = http.request{url = "http://example.invalid/does/not/exist"}
assert(r == nil and e == re, tostring(r) .. " " .. tostring(re))
assert(r == nil and e == re, tostring(r) .. " " .. tostring(re))
r, re = http.request("http://example.invalid/does/not/exist")
assert(r == nil and e == re)
assert(r == nil and e == re)
print("ok")
------------------------------------------------------------------------