diff options
author | Diego Nehab <diego@impa.br> | 2015-02-18 20:51:37 -0200 |
---|---|---|
committer | Diego Nehab <diego@impa.br> | 2015-02-18 20:51:37 -0200 |
commit | ddf429282460323e24652e6beec8e750f8e4a958 (patch) | |
tree | 071ee7879bbd4c917c92e5383c759e98a90cf78e | |
parent | 5edf093643cceb329392aec9606ab3988579b821 (diff) | |
download | luasocket-ddf429282460323e24652e6beec8e750f8e4a958.tar.gz luasocket-ddf429282460323e24652e6beec8e750f8e4a958.tar.bz2 luasocket-ddf429282460323e24652e6beec8e750f8e4a958.zip |
Out of the box support for Lua 5.3.
-rw-r--r-- | makefile | 18 | ||||
-rw-r--r-- | src/luasocket.c | 14 | ||||
-rw-r--r-- | src/makefile | 8 | ||||
-rw-r--r-- | src/mime.c | 105 | ||||
-rw-r--r-- | test/auth/.htaccess | 4 | ||||
-rw-r--r-- | test/auth/.htpasswd | 2 | ||||
-rw-r--r-- | test/httptest.lua | 30 |
7 files changed, 96 insertions, 85 deletions
@@ -5,8 +5,8 @@ | |||
5 | # Targets: | 5 | # Targets: |
6 | # install install system independent support | 6 | # install install system independent support |
7 | # install-unix also install unix-only support | 7 | # install-unix also install unix-only support |
8 | # install-both install for both lua5.1 and lua5.2 | 8 | # install-both install for lua51 lua52 lua53 |
9 | # install-both-unix also install unix-only | 9 | # install-both-unix also install unix-only |
10 | # print print the build settings | 10 | # print print the build settings |
11 | 11 | ||
12 | PLAT?= linux | 12 | PLAT?= linux |
@@ -24,20 +24,26 @@ test: | |||
24 | lua test/hello.lua | 24 | lua test/hello.lua |
25 | 25 | ||
26 | install-both: | 26 | install-both: |
27 | $(MAKE) clean | 27 | $(MAKE) clean |
28 | @cd src; $(MAKE) $(PLAT) LUAV=5.1 | 28 | @cd src; $(MAKE) $(PLAT) LUAV=5.1 |
29 | @cd src; $(MAKE) install LUAV=5.1 | 29 | @cd src; $(MAKE) install LUAV=5.1 |
30 | $(MAKE) clean | 30 | $(MAKE) clean |
31 | @cd src; $(MAKE) $(PLAT) LUAV=5.2 | 31 | @cd src; $(MAKE) $(PLAT) LUAV=5.2 |
32 | @cd src; $(MAKE) install LUAV=5.2 | 32 | @cd src; $(MAKE) install LUAV=5.2 |
33 | $(MAKE) clean | ||
34 | @cd src; $(MAKE) $(PLAT) LUAV=5.3 | ||
35 | @cd src; $(MAKE) install LUAV=5.3 | ||
33 | 36 | ||
34 | install-both-unix: | 37 | install-both-unix: |
35 | $(MAKE) clean | 38 | $(MAKE) clean |
36 | @cd src; $(MAKE) $(PLAT) LUAV=5.1 | 39 | @cd src; $(MAKE) $(PLAT) LUAV=5.1 |
37 | @cd src; $(MAKE) install-unix LUAV=5.1 | 40 | @cd src; $(MAKE) install-unix LUAV=5.1 |
38 | $(MAKE) clean | 41 | $(MAKE) clean |
39 | @cd src; $(MAKE) $(PLAT) LUAV=5.2 | 42 | @cd src; $(MAKE) $(PLAT) LUAV=5.2 |
40 | @cd src; $(MAKE) install-unix LUAV=5.2 | 43 | @cd src; $(MAKE) install-unix LUAV=5.2 |
44 | $(MAKE) clean | ||
45 | @cd src; $(MAKE) $(PLAT) LUAV=5.3 | ||
46 | @cd src; $(MAKE) install-unix LUAV=5.3 | ||
41 | 47 | ||
42 | .PHONY: test | 48 | .PHONY: test |
43 | 49 | ||
diff --git a/src/luasocket.c b/src/luasocket.c index e6ee747..40731f1 100644 --- a/src/luasocket.c +++ b/src/luasocket.c | |||
@@ -18,7 +18,6 @@ | |||
18 | #include "lua.h" | 18 | #include "lua.h" |
19 | #include "lauxlib.h" | 19 | #include "lauxlib.h" |
20 | 20 | ||
21 | |||
22 | /*=========================================================================*\ | 21 | /*=========================================================================*\ |
23 | * LuaSocket includes | 22 | * LuaSocket includes |
24 | \*=========================================================================*/ | 23 | \*=========================================================================*/ |
@@ -32,6 +31,11 @@ | |||
32 | #include "udp.h" | 31 | #include "udp.h" |
33 | #include "select.h" | 32 | #include "select.h" |
34 | 33 | ||
34 | #if LUA_VERSION_NUM > 502 && !defined(LUA_COMPAT_APIINTCASTS) | ||
35 | #define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n))) | ||
36 | #define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) | ||
37 | #endif | ||
38 | |||
35 | /*-------------------------------------------------------------------------*\ | 39 | /*-------------------------------------------------------------------------*\ |
36 | * Internal function prototypes | 40 | * Internal function prototypes |
37 | \*-------------------------------------------------------------------------*/ | 41 | \*-------------------------------------------------------------------------*/ |
@@ -78,14 +82,6 @@ static int global_unload(lua_State *L) { | |||
78 | return 0; | 82 | return 0; |
79 | } | 83 | } |
80 | 84 | ||
81 | #if LUA_VERSION_NUM > 501 | ||
82 | int luaL_typerror (lua_State *L, int narg, const char *tname) { | ||
83 | const char *msg = lua_pushfstring(L, "%s expected, got %s", | ||
84 | tname, luaL_typename(L, narg)); | ||
85 | return luaL_argerror(L, narg, msg); | ||
86 | } | ||
87 | #endif | ||
88 | |||
89 | /*-------------------------------------------------------------------------*\ | 85 | /*-------------------------------------------------------------------------*\ |
90 | * Setup basic stuff. | 86 | * Setup basic stuff. |
91 | \*-------------------------------------------------------------------------*/ | 87 | \*-------------------------------------------------------------------------*/ |
diff --git a/src/makefile b/src/makefile index 8d3521e..7f118a7 100644 --- a/src/makefile +++ b/src/makefile | |||
@@ -147,7 +147,7 @@ DEF_macosx= -DLUASOCKET_$(DEBUG) -DUNIX_HAS_SUN_LEN -DLUA_$(COMPAT)_MODULE \ | |||
147 | -DLUASOCKET_API='__attribute__((visibility("default")))' \ | 147 | -DLUASOCKET_API='__attribute__((visibility("default")))' \ |
148 | -DUNIX_API='__attribute__((visibility("default")))' \ | 148 | -DUNIX_API='__attribute__((visibility("default")))' \ |
149 | -DMIME_API='__attribute__((visibility("default")))' | 149 | -DMIME_API='__attribute__((visibility("default")))' |
150 | CFLAGS_macosx= -I$(LUAINC) $(DEF) -pedantic -Wall -O2 -fno-common \ | 150 | CFLAGS_macosx= -I$(LUAINC) $(DEF) -Wall -O2 -fno-common \ |
151 | -fvisibility=hidden | 151 | -fvisibility=hidden |
152 | LDFLAGS_macosx= -bundle -undefined dynamic_lookup -o | 152 | LDFLAGS_macosx= -bundle -undefined dynamic_lookup -o |
153 | LD_macosx= export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc | 153 | LD_macosx= export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc |
@@ -163,7 +163,7 @@ DEF_linux=-DLUASOCKET_$(DEBUG) -DLUA_$(COMPAT)_MODULE \ | |||
163 | -DLUASOCKET_API='__attribute__((visibility("default")))' \ | 163 | -DLUASOCKET_API='__attribute__((visibility("default")))' \ |
164 | -DUNIX_API='__attribute__((visibility("default")))' \ | 164 | -DUNIX_API='__attribute__((visibility("default")))' \ |
165 | -DMIME_API='__attribute__((visibility("default")))' | 165 | -DMIME_API='__attribute__((visibility("default")))' |
166 | CFLAGS_linux= -I$(LUAINC) $(DEF) -pedantic -Wall -Wshadow -Wextra \ | 166 | CFLAGS_linux= -I$(LUAINC) $(DEF) -Wall -Wshadow -Wextra \ |
167 | -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden | 167 | -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden |
168 | LDFLAGS_linux=-O -shared -fpic -o | 168 | LDFLAGS_linux=-O -shared -fpic -o |
169 | LD_linux=gcc | 169 | LD_linux=gcc |
@@ -179,7 +179,7 @@ DEF_freebsd=-DLUASOCKET_$(DEBUG) -DLUA_$(COMPAT)_MODULE \ | |||
179 | -DLUASOCKET_API='__attribute__((visibility("default")))' \ | 179 | -DLUASOCKET_API='__attribute__((visibility("default")))' \ |
180 | -DUNIX_API='__attribute__((visibility("default")))' \ | 180 | -DUNIX_API='__attribute__((visibility("default")))' \ |
181 | -DMIME_API='__attribute__((visibility("default")))' | 181 | -DMIME_API='__attribute__((visibility("default")))' |
182 | CFLAGS_freebsd= -I$(LUAINC) $(DEF) -pedantic -Wall -Wshadow -Wextra \ | 182 | CFLAGS_freebsd= -I$(LUAINC) $(DEF) -Wall -Wshadow -Wextra \ |
183 | -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden | 183 | -Wimplicit -O2 -ggdb3 -fpic -fvisibility=hidden |
184 | LDFLAGS_freebsd=-O -shared -fpic -o | 184 | LDFLAGS_freebsd=-O -shared -fpic -o |
185 | LD_freebsd=gcc | 185 | LD_freebsd=gcc |
@@ -194,7 +194,7 @@ CC_mingw=gcc | |||
194 | DEF_mingw= -DLUASOCKET_INET_PTON -DLUASOCKET_$(DEBUG) -DLUA_$(COMPAT)_MODULE \ | 194 | DEF_mingw= -DLUASOCKET_INET_PTON -DLUASOCKET_$(DEBUG) -DLUA_$(COMPAT)_MODULE \ |
195 | -DWINVER=0x0501 -DLUASOCKET_API='__declspec(dllexport)' \ | 195 | -DWINVER=0x0501 -DLUASOCKET_API='__declspec(dllexport)' \ |
196 | -DMIME_API='__declspec(dllexport)' | 196 | -DMIME_API='__declspec(dllexport)' |
197 | CFLAGS_mingw= -I$(LUAINC) $(DEF) -pedantic -Wall -O2 -fno-common \ | 197 | CFLAGS_mingw= -I$(LUAINC) $(DEF) -Wall -O2 -fno-common \ |
198 | -fvisibility=hidden | 198 | -fvisibility=hidden |
199 | LDFLAGS_mingw= $(LUALIB) -shared -Wl,-s -lws2_32 -o | 199 | LDFLAGS_mingw= $(LUALIB) -shared -Wl,-s -lws2_32 -o |
200 | LD_mingw=gcc | 200 | LD_mingw=gcc |
@@ -13,6 +13,11 @@ | |||
13 | 13 | ||
14 | #include "mime.h" | 14 | #include "mime.h" |
15 | 15 | ||
16 | #if LUA_VERSION_NUM > 502 && !defined(LUA_COMPAT_APIINTCASTS) | ||
17 | #define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n))) | ||
18 | #define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) | ||
19 | #endif | ||
20 | |||
16 | /*=========================================================================*\ | 21 | /*=========================================================================*\ |
17 | * Don't want to trust escape character constants | 22 | * Don't want to trust escape character constants |
18 | \*=========================================================================*/ | 23 | \*=========================================================================*/ |
@@ -41,7 +46,7 @@ static size_t b64decode(UC c, UC *input, size_t size, luaL_Buffer *buffer); | |||
41 | static void qpsetup(UC *class, UC *unbase); | 46 | static void qpsetup(UC *class, UC *unbase); |
42 | static void qpquote(UC c, luaL_Buffer *buffer); | 47 | static void qpquote(UC c, luaL_Buffer *buffer); |
43 | static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer); | 48 | static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer); |
44 | static size_t qpencode(UC c, UC *input, size_t size, | 49 | static size_t qpencode(UC c, UC *input, size_t size, |
45 | const char *marker, luaL_Buffer *buffer); | 50 | const char *marker, luaL_Buffer *buffer); |
46 | static size_t qppad(UC *input, size_t size, luaL_Buffer *buffer); | 51 | static size_t qppad(UC *input, size_t size, luaL_Buffer *buffer); |
47 | 52 | ||
@@ -103,9 +108,9 @@ MIME_API int luaopen_mime_core(lua_State *L) | |||
103 | /*-------------------------------------------------------------------------*\ | 108 | /*-------------------------------------------------------------------------*\ |
104 | * Incrementaly breaks a string into lines. The string can have CRLF breaks. | 109 | * Incrementaly breaks a string into lines. The string can have CRLF breaks. |
105 | * A, n = wrp(l, B, length) | 110 | * A, n = wrp(l, B, length) |
106 | * A is a copy of B, broken into lines of at most 'length' bytes. | 111 | * A is a copy of B, broken into lines of at most 'length' bytes. |
107 | * 'l' is how many bytes are left for the first line of B. | 112 | * 'l' is how many bytes are left for the first line of B. |
108 | * 'n' is the number of bytes left in the last line of A. | 113 | * 'n' is the number of bytes left in the last line of A. |
109 | \*-------------------------------------------------------------------------*/ | 114 | \*-------------------------------------------------------------------------*/ |
110 | static int mime_global_wrp(lua_State *L) | 115 | static int mime_global_wrp(lua_State *L) |
111 | { | 116 | { |
@@ -123,7 +128,7 @@ static int mime_global_wrp(lua_State *L) | |||
123 | else lua_pushnil(L); | 128 | else lua_pushnil(L); |
124 | lua_pushnumber(L, length); | 129 | lua_pushnumber(L, length); |
125 | return 2; | 130 | return 2; |
126 | } | 131 | } |
127 | luaL_buffinit(L, &buffer); | 132 | luaL_buffinit(L, &buffer); |
128 | while (input < last) { | 133 | while (input < last) { |
129 | switch (*input) { | 134 | switch (*input) { |
@@ -150,9 +155,9 @@ static int mime_global_wrp(lua_State *L) | |||
150 | } | 155 | } |
151 | 156 | ||
152 | /*-------------------------------------------------------------------------*\ | 157 | /*-------------------------------------------------------------------------*\ |
153 | * Fill base64 decode map. | 158 | * Fill base64 decode map. |
154 | \*-------------------------------------------------------------------------*/ | 159 | \*-------------------------------------------------------------------------*/ |
155 | static void b64setup(UC *unbase) | 160 | static void b64setup(UC *unbase) |
156 | { | 161 | { |
157 | int i; | 162 | int i; |
158 | for (i = 0; i <= 255; i++) unbase[i] = (UC) 255; | 163 | for (i = 0; i <= 255; i++) unbase[i] = (UC) 255; |
@@ -161,11 +166,11 @@ static void b64setup(UC *unbase) | |||
161 | } | 166 | } |
162 | 167 | ||
163 | /*-------------------------------------------------------------------------*\ | 168 | /*-------------------------------------------------------------------------*\ |
164 | * Acumulates bytes in input buffer until 3 bytes are available. | 169 | * Acumulates bytes in input buffer until 3 bytes are available. |
165 | * Translate the 3 bytes into Base64 form and append to buffer. | 170 | * Translate the 3 bytes into Base64 form and append to buffer. |
166 | * Returns new number of bytes in buffer. | 171 | * Returns new number of bytes in buffer. |
167 | \*-------------------------------------------------------------------------*/ | 172 | \*-------------------------------------------------------------------------*/ |
168 | static size_t b64encode(UC c, UC *input, size_t size, | 173 | static size_t b64encode(UC c, UC *input, size_t size, |
169 | luaL_Buffer *buffer) | 174 | luaL_Buffer *buffer) |
170 | { | 175 | { |
171 | input[size++] = c; | 176 | input[size++] = c; |
@@ -174,7 +179,7 @@ static size_t b64encode(UC c, UC *input, size_t size, | |||
174 | unsigned long value = 0; | 179 | unsigned long value = 0; |
175 | value += input[0]; value <<= 8; | 180 | value += input[0]; value <<= 8; |
176 | value += input[1]; value <<= 8; | 181 | value += input[1]; value <<= 8; |
177 | value += input[2]; | 182 | value += input[2]; |
178 | code[3] = b64base[value & 0x3f]; value >>= 6; | 183 | code[3] = b64base[value & 0x3f]; value >>= 6; |
179 | code[2] = b64base[value & 0x3f]; value >>= 6; | 184 | code[2] = b64base[value & 0x3f]; value >>= 6; |
180 | code[1] = b64base[value & 0x3f]; value >>= 6; | 185 | code[1] = b64base[value & 0x3f]; value >>= 6; |
@@ -186,11 +191,11 @@ static size_t b64encode(UC c, UC *input, size_t size, | |||
186 | } | 191 | } |
187 | 192 | ||
188 | /*-------------------------------------------------------------------------*\ | 193 | /*-------------------------------------------------------------------------*\ |
189 | * Encodes the Base64 last 1 or 2 bytes and adds padding '=' | 194 | * Encodes the Base64 last 1 or 2 bytes and adds padding '=' |
190 | * Result, if any, is appended to buffer. | 195 | * Result, if any, is appended to buffer. |
191 | * Returns 0. | 196 | * Returns 0. |
192 | \*-------------------------------------------------------------------------*/ | 197 | \*-------------------------------------------------------------------------*/ |
193 | static size_t b64pad(const UC *input, size_t size, | 198 | static size_t b64pad(const UC *input, size_t size, |
194 | luaL_Buffer *buffer) | 199 | luaL_Buffer *buffer) |
195 | { | 200 | { |
196 | unsigned long value = 0; | 201 | unsigned long value = 0; |
@@ -203,7 +208,7 @@ static size_t b64pad(const UC *input, size_t size, | |||
203 | luaL_addlstring(buffer, (char *) code, 4); | 208 | luaL_addlstring(buffer, (char *) code, 4); |
204 | break; | 209 | break; |
205 | case 2: | 210 | case 2: |
206 | value = input[0]; value <<= 8; | 211 | value = input[0]; value <<= 8; |
207 | value |= input[1]; value <<= 2; | 212 | value |= input[1]; value <<= 2; |
208 | code[2] = b64base[value & 0x3f]; value >>= 6; | 213 | code[2] = b64base[value & 0x3f]; value >>= 6; |
209 | code[1] = b64base[value & 0x3f]; value >>= 6; | 214 | code[1] = b64base[value & 0x3f]; value >>= 6; |
@@ -217,11 +222,11 @@ static size_t b64pad(const UC *input, size_t size, | |||
217 | } | 222 | } |
218 | 223 | ||
219 | /*-------------------------------------------------------------------------*\ | 224 | /*-------------------------------------------------------------------------*\ |
220 | * Acumulates bytes in input buffer until 4 bytes are available. | 225 | * Acumulates bytes in input buffer until 4 bytes are available. |
221 | * Translate the 4 bytes from Base64 form and append to buffer. | 226 | * Translate the 4 bytes from Base64 form and append to buffer. |
222 | * Returns new number of bytes in buffer. | 227 | * Returns new number of bytes in buffer. |
223 | \*-------------------------------------------------------------------------*/ | 228 | \*-------------------------------------------------------------------------*/ |
224 | static size_t b64decode(UC c, UC *input, size_t size, | 229 | static size_t b64decode(UC c, UC *input, size_t size, |
225 | luaL_Buffer *buffer) | 230 | luaL_Buffer *buffer) |
226 | { | 231 | { |
227 | /* ignore invalid characters */ | 232 | /* ignore invalid characters */ |
@@ -239,7 +244,7 @@ static size_t b64decode(UC c, UC *input, size_t size, | |||
239 | decoded[1] = (UC) (value & 0xff); value >>= 8; | 244 | decoded[1] = (UC) (value & 0xff); value >>= 8; |
240 | decoded[0] = (UC) value; | 245 | decoded[0] = (UC) value; |
241 | /* take care of paddding */ | 246 | /* take care of paddding */ |
242 | valid = (input[2] == '=') ? 1 : (input[3] == '=') ? 2 : 3; | 247 | valid = (input[2] == '=') ? 1 : (input[3] == '=') ? 2 : 3; |
243 | luaL_addlstring(buffer, (char *) decoded, valid); | 248 | luaL_addlstring(buffer, (char *) decoded, valid); |
244 | return 0; | 249 | return 0; |
245 | /* need more data */ | 250 | /* need more data */ |
@@ -251,7 +256,7 @@ static size_t b64decode(UC c, UC *input, size_t size, | |||
251 | * A, B = b64(C, D) | 256 | * A, B = b64(C, D) |
252 | * A is the encoded version of the largest prefix of C .. D that is | 257 | * A is the encoded version of the largest prefix of C .. D that is |
253 | * divisible by 3. B has the remaining bytes of C .. D, *without* encoding. | 258 | * divisible by 3. B has the remaining bytes of C .. D, *without* encoding. |
254 | * The easiest thing would be to concatenate the two strings and | 259 | * The easiest thing would be to concatenate the two strings and |
255 | * encode the result, but we can't afford that or Lua would dupplicate | 260 | * encode the result, but we can't afford that or Lua would dupplicate |
256 | * every chunk we received. | 261 | * every chunk we received. |
257 | \*-------------------------------------------------------------------------*/ | 262 | \*-------------------------------------------------------------------------*/ |
@@ -272,7 +277,7 @@ static int mime_global_b64(lua_State *L) | |||
272 | lua_settop(L, 2); | 277 | lua_settop(L, 2); |
273 | /* process first part of the input */ | 278 | /* process first part of the input */ |
274 | luaL_buffinit(L, &buffer); | 279 | luaL_buffinit(L, &buffer); |
275 | while (input < last) | 280 | while (input < last) |
276 | asize = b64encode(*input++, atom, asize, &buffer); | 281 | asize = b64encode(*input++, atom, asize, &buffer); |
277 | input = (UC *) luaL_optlstring(L, 2, NULL, &isize); | 282 | input = (UC *) luaL_optlstring(L, 2, NULL, &isize); |
278 | /* if second part is nil, we are done */ | 283 | /* if second part is nil, we are done */ |
@@ -288,7 +293,7 @@ static int mime_global_b64(lua_State *L) | |||
288 | } | 293 | } |
289 | /* otherwise process the second part */ | 294 | /* otherwise process the second part */ |
290 | last = input + isize; | 295 | last = input + isize; |
291 | while (input < last) | 296 | while (input < last) |
292 | asize = b64encode(*input++, atom, asize, &buffer); | 297 | asize = b64encode(*input++, atom, asize, &buffer); |
293 | luaL_pushresult(&buffer); | 298 | luaL_pushresult(&buffer); |
294 | lua_pushlstring(L, (char *) atom, asize); | 299 | lua_pushlstring(L, (char *) atom, asize); |
@@ -318,7 +323,7 @@ static int mime_global_unb64(lua_State *L) | |||
318 | lua_settop(L, 2); | 323 | lua_settop(L, 2); |
319 | /* process first part of the input */ | 324 | /* process first part of the input */ |
320 | luaL_buffinit(L, &buffer); | 325 | luaL_buffinit(L, &buffer); |
321 | while (input < last) | 326 | while (input < last) |
322 | asize = b64decode(*input++, atom, asize, &buffer); | 327 | asize = b64decode(*input++, atom, asize, &buffer); |
323 | input = (UC *) luaL_optlstring(L, 2, NULL, &isize); | 328 | input = (UC *) luaL_optlstring(L, 2, NULL, &isize); |
324 | /* if second is nil, we are done */ | 329 | /* if second is nil, we are done */ |
@@ -333,7 +338,7 @@ static int mime_global_unb64(lua_State *L) | |||
333 | } | 338 | } |
334 | /* otherwise, process the rest of the input */ | 339 | /* otherwise, process the rest of the input */ |
335 | last = input + isize; | 340 | last = input + isize; |
336 | while (input < last) | 341 | while (input < last) |
337 | asize = b64decode(*input++, atom, asize, &buffer); | 342 | asize = b64decode(*input++, atom, asize, &buffer); |
338 | luaL_pushresult(&buffer); | 343 | luaL_pushresult(&buffer); |
339 | lua_pushlstring(L, (char *) atom, asize); | 344 | lua_pushlstring(L, (char *) atom, asize); |
@@ -349,7 +354,7 @@ static int mime_global_unb64(lua_State *L) | |||
349 | * 9 and 32 can be plain, unless in the end of a line, where must be =XX | 354 | * 9 and 32 can be plain, unless in the end of a line, where must be =XX |
350 | * encoded lines must be no longer than 76 not counting CRLF | 355 | * encoded lines must be no longer than 76 not counting CRLF |
351 | * soft line-break are =CRLF | 356 | * soft line-break are =CRLF |
352 | * To encode one byte, we need to see the next two. | 357 | * To encode one byte, we need to see the next two. |
353 | * Worst case is when we see a space, and wonder if a CRLF is comming | 358 | * Worst case is when we see a space, and wonder if a CRLF is comming |
354 | \*-------------------------------------------------------------------------*/ | 359 | \*-------------------------------------------------------------------------*/ |
355 | /*-------------------------------------------------------------------------*\ | 360 | /*-------------------------------------------------------------------------*\ |
@@ -362,7 +367,7 @@ static void qpsetup(UC *cl, UC *unbase) | |||
362 | for (i = 0; i < 256; i++) cl[i] = QP_QUOTED; | 367 | for (i = 0; i < 256; i++) cl[i] = QP_QUOTED; |
363 | for (i = 33; i <= 60; i++) cl[i] = QP_PLAIN; | 368 | for (i = 33; i <= 60; i++) cl[i] = QP_PLAIN; |
364 | for (i = 62; i <= 126; i++) cl[i] = QP_PLAIN; | 369 | for (i = 62; i <= 126; i++) cl[i] = QP_PLAIN; |
365 | cl['\t'] = QP_IF_LAST; | 370 | cl['\t'] = QP_IF_LAST; |
366 | cl[' '] = QP_IF_LAST; | 371 | cl[' '] = QP_IF_LAST; |
367 | cl['\r'] = QP_CR; | 372 | cl['\r'] = QP_CR; |
368 | for (i = 0; i < 256; i++) unbase[i] = 255; | 373 | for (i = 0; i < 256; i++) unbase[i] = 255; |
@@ -388,9 +393,9 @@ static void qpquote(UC c, luaL_Buffer *buffer) | |||
388 | 393 | ||
389 | /*-------------------------------------------------------------------------*\ | 394 | /*-------------------------------------------------------------------------*\ |
390 | * Accumulate characters until we are sure about how to deal with them. | 395 | * Accumulate characters until we are sure about how to deal with them. |
391 | * Once we are sure, output to the buffer, in the correct form. | 396 | * Once we are sure, output to the buffer, in the correct form. |
392 | \*-------------------------------------------------------------------------*/ | 397 | \*-------------------------------------------------------------------------*/ |
393 | static size_t qpencode(UC c, UC *input, size_t size, | 398 | static size_t qpencode(UC c, UC *input, size_t size, |
394 | const char *marker, luaL_Buffer *buffer) | 399 | const char *marker, luaL_Buffer *buffer) |
395 | { | 400 | { |
396 | input[size++] = c; | 401 | input[size++] = c; |
@@ -431,7 +436,7 @@ static size_t qpencode(UC c, UC *input, size_t size, | |||
431 | } | 436 | } |
432 | 437 | ||
433 | /*-------------------------------------------------------------------------*\ | 438 | /*-------------------------------------------------------------------------*\ |
434 | * Deal with the final characters | 439 | * Deal with the final characters |
435 | \*-------------------------------------------------------------------------*/ | 440 | \*-------------------------------------------------------------------------*/ |
436 | static size_t qppad(UC *input, size_t size, luaL_Buffer *buffer) | 441 | static size_t qppad(UC *input, size_t size, luaL_Buffer *buffer) |
437 | { | 442 | { |
@@ -448,8 +453,8 @@ static size_t qppad(UC *input, size_t size, luaL_Buffer *buffer) | |||
448 | * Incrementally converts a string to quoted-printable | 453 | * Incrementally converts a string to quoted-printable |
449 | * A, B = qp(C, D, marker) | 454 | * A, B = qp(C, D, marker) |
450 | * Marker is the text to be used to replace CRLF sequences found in A. | 455 | * Marker is the text to be used to replace CRLF sequences found in A. |
451 | * A is the encoded version of the largest prefix of C .. D that | 456 | * A is the encoded version of the largest prefix of C .. D that |
452 | * can be encoded without doubts. | 457 | * can be encoded without doubts. |
453 | * B has the remaining bytes of C .. D, *without* encoding. | 458 | * B has the remaining bytes of C .. D, *without* encoding. |
454 | \*-------------------------------------------------------------------------*/ | 459 | \*-------------------------------------------------------------------------*/ |
455 | static int mime_global_qp(lua_State *L) | 460 | static int mime_global_qp(lua_State *L) |
@@ -493,7 +498,7 @@ static int mime_global_qp(lua_State *L) | |||
493 | 498 | ||
494 | /*-------------------------------------------------------------------------*\ | 499 | /*-------------------------------------------------------------------------*\ |
495 | * Accumulate characters until we are sure about how to deal with them. | 500 | * Accumulate characters until we are sure about how to deal with them. |
496 | * Once we are sure, output the to the buffer, in the correct form. | 501 | * Once we are sure, output the to the buffer, in the correct form. |
497 | \*-------------------------------------------------------------------------*/ | 502 | \*-------------------------------------------------------------------------*/ |
498 | static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer) { | 503 | static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer) { |
499 | int d; | 504 | int d; |
@@ -501,8 +506,8 @@ static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer) { | |||
501 | /* deal with all characters we can deal */ | 506 | /* deal with all characters we can deal */ |
502 | switch (input[0]) { | 507 | switch (input[0]) { |
503 | /* if we have an escape character */ | 508 | /* if we have an escape character */ |
504 | case '=': | 509 | case '=': |
505 | if (size < 3) return size; | 510 | if (size < 3) return size; |
506 | /* eliminate soft line break */ | 511 | /* eliminate soft line break */ |
507 | if (input[1] == '\r' && input[2] == '\n') return 0; | 512 | if (input[1] == '\r' && input[2] == '\n') return 0; |
508 | /* decode quoted representation */ | 513 | /* decode quoted representation */ |
@@ -512,7 +517,7 @@ static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer) { | |||
512 | else luaL_addchar(buffer, (char) ((c << 4) + d)); | 517 | else luaL_addchar(buffer, (char) ((c << 4) + d)); |
513 | return 0; | 518 | return 0; |
514 | case '\r': | 519 | case '\r': |
515 | if (size < 2) return size; | 520 | if (size < 2) return size; |
516 | if (input[1] == '\n') luaL_addlstring(buffer, (char *)input, 2); | 521 | if (input[1] == '\n') luaL_addlstring(buffer, (char *)input, 2); |
517 | return 0; | 522 | return 0; |
518 | default: | 523 | default: |
@@ -525,8 +530,8 @@ static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer) { | |||
525 | /*-------------------------------------------------------------------------*\ | 530 | /*-------------------------------------------------------------------------*\ |
526 | * Incrementally decodes a string in quoted-printable | 531 | * Incrementally decodes a string in quoted-printable |
527 | * A, B = qp(C, D) | 532 | * A, B = qp(C, D) |
528 | * A is the decoded version of the largest prefix of C .. D that | 533 | * A is the decoded version of the largest prefix of C .. D that |
529 | * can be decoded without doubts. | 534 | * can be decoded without doubts. |
530 | * B has the remaining bytes of C .. D, *without* decoding. | 535 | * B has the remaining bytes of C .. D, *without* decoding. |
531 | \*-------------------------------------------------------------------------*/ | 536 | \*-------------------------------------------------------------------------*/ |
532 | static int mime_global_unqp(lua_State *L) | 537 | static int mime_global_unqp(lua_State *L) |
@@ -555,7 +560,7 @@ static int mime_global_unqp(lua_State *L) | |||
555 | if (!(*lua_tostring(L, -1))) lua_pushnil(L); | 560 | if (!(*lua_tostring(L, -1))) lua_pushnil(L); |
556 | lua_pushnil(L); | 561 | lua_pushnil(L); |
557 | return 2; | 562 | return 2; |
558 | } | 563 | } |
559 | /* otherwise process rest of input */ | 564 | /* otherwise process rest of input */ |
560 | last = input + isize; | 565 | last = input + isize; |
561 | while (input < last) | 566 | while (input < last) |
@@ -568,9 +573,9 @@ static int mime_global_unqp(lua_State *L) | |||
568 | /*-------------------------------------------------------------------------*\ | 573 | /*-------------------------------------------------------------------------*\ |
569 | * Incrementally breaks a quoted-printed string into lines | 574 | * Incrementally breaks a quoted-printed string into lines |
570 | * A, n = qpwrp(l, B, length) | 575 | * A, n = qpwrp(l, B, length) |
571 | * A is a copy of B, broken into lines of at most 'length' bytes. | 576 | * A is a copy of B, broken into lines of at most 'length' bytes. |
572 | * 'l' is how many bytes are left for the first line of B. | 577 | * 'l' is how many bytes are left for the first line of B. |
573 | * 'n' is the number of bytes left in the last line of A. | 578 | * 'n' is the number of bytes left in the last line of A. |
574 | * There are two complications: lines can't be broken in the middle | 579 | * There are two complications: lines can't be broken in the middle |
575 | * of an encoded =XX, and there might be line breaks already | 580 | * of an encoded =XX, and there might be line breaks already |
576 | \*-------------------------------------------------------------------------*/ | 581 | \*-------------------------------------------------------------------------*/ |
@@ -603,11 +608,11 @@ static int mime_global_qpwrp(lua_State *L) | |||
603 | if (left <= 3) { | 608 | if (left <= 3) { |
604 | left = length; | 609 | left = length; |
605 | luaL_addstring(&buffer, EQCRLF); | 610 | luaL_addstring(&buffer, EQCRLF); |
606 | } | 611 | } |
607 | luaL_addchar(&buffer, *input); | 612 | luaL_addchar(&buffer, *input); |
608 | left--; | 613 | left--; |
609 | break; | 614 | break; |
610 | default: | 615 | default: |
611 | if (left <= 1) { | 616 | if (left <= 1) { |
612 | left = length; | 617 | left = length; |
613 | luaL_addstring(&buffer, EQCRLF); | 618 | luaL_addstring(&buffer, EQCRLF); |
@@ -635,7 +640,7 @@ static int mime_global_qpwrp(lua_State *L) | |||
635 | * last is the previous character | 640 | * last is the previous character |
636 | \*-------------------------------------------------------------------------*/ | 641 | \*-------------------------------------------------------------------------*/ |
637 | #define eolcandidate(c) (c == '\r' || c == '\n') | 642 | #define eolcandidate(c) (c == '\r' || c == '\n') |
638 | static int eolprocess(int c, int last, const char *marker, | 643 | static int eolprocess(int c, int last, const char *marker, |
639 | luaL_Buffer *buffer) | 644 | luaL_Buffer *buffer) |
640 | { | 645 | { |
641 | if (eolcandidate(c)) { | 646 | if (eolcandidate(c)) { |
@@ -653,10 +658,10 @@ static int eolprocess(int c, int last, const char *marker, | |||
653 | } | 658 | } |
654 | 659 | ||
655 | /*-------------------------------------------------------------------------*\ | 660 | /*-------------------------------------------------------------------------*\ |
656 | * Converts a string to uniform EOL convention. | 661 | * Converts a string to uniform EOL convention. |
657 | * A, n = eol(o, B, marker) | 662 | * A, n = eol(o, B, marker) |
658 | * A is the converted version of the largest prefix of B that can be | 663 | * A is the converted version of the largest prefix of B that can be |
659 | * converted unambiguously. 'o' is the context returned by the previous | 664 | * converted unambiguously. 'o' is the context returned by the previous |
660 | * call. 'n' is the new context. | 665 | * call. 'n' is the new context. |
661 | \*-------------------------------------------------------------------------*/ | 666 | \*-------------------------------------------------------------------------*/ |
662 | static int mime_global_eol(lua_State *L) | 667 | static int mime_global_eol(lua_State *L) |
@@ -683,18 +688,18 @@ static int mime_global_eol(lua_State *L) | |||
683 | } | 688 | } |
684 | 689 | ||
685 | /*-------------------------------------------------------------------------*\ | 690 | /*-------------------------------------------------------------------------*\ |
686 | * Takes one byte and stuff it if needed. | 691 | * Takes one byte and stuff it if needed. |
687 | \*-------------------------------------------------------------------------*/ | 692 | \*-------------------------------------------------------------------------*/ |
688 | static size_t dot(int c, size_t state, luaL_Buffer *buffer) | 693 | static size_t dot(int c, size_t state, luaL_Buffer *buffer) |
689 | { | 694 | { |
690 | luaL_addchar(buffer, (char) c); | 695 | luaL_addchar(buffer, (char) c); |
691 | switch (c) { | 696 | switch (c) { |
692 | case '\r': | 697 | case '\r': |
693 | return 1; | 698 | return 1; |
694 | case '\n': | 699 | case '\n': |
695 | return (state == 1)? 2: 0; | 700 | return (state == 1)? 2: 0; |
696 | case '.': | 701 | case '.': |
697 | if (state == 2) | 702 | if (state == 2) |
698 | luaL_addchar(buffer, '.'); | 703 | luaL_addchar(buffer, '.'); |
699 | default: | 704 | default: |
700 | return 0; | 705 | return 0; |
@@ -719,7 +724,7 @@ static int mime_global_dot(lua_State *L) | |||
719 | } | 724 | } |
720 | /* process all input */ | 725 | /* process all input */ |
721 | luaL_buffinit(L, &buffer); | 726 | luaL_buffinit(L, &buffer); |
722 | while (input < last) | 727 | while (input < last) |
723 | state = dot(*input++, state, &buffer); | 728 | state = dot(*input++, state, &buffer); |
724 | luaL_pushresult(&buffer); | 729 | luaL_pushresult(&buffer); |
725 | lua_pushnumber(L, (lua_Number) state); | 730 | lua_pushnumber(L, (lua_Number) state); |
diff --git a/test/auth/.htaccess b/test/auth/.htaccess new file mode 100644 index 0000000..bb2794a --- /dev/null +++ b/test/auth/.htaccess | |||
@@ -0,0 +1,4 @@ | |||
1 | AuthName "test-auth" | ||
2 | AuthType Basic | ||
3 | AuthUserFile /Users/diego/impa/luasocket/test/auth/.htpasswd | ||
4 | Require valid-user | ||
diff --git a/test/auth/.htpasswd b/test/auth/.htpasswd index fd9002b..cfb2603 100644 --- a/test/auth/.htpasswd +++ b/test/auth/.htpasswd | |||
@@ -1 +1 @@ | |||
luasocket:l8n2npozPB.sQ | luasocket:$apr1$47u2O.Me$.m/5BWAtt7GVoxsouIPBR1 | ||
diff --git a/test/httptest.lua b/test/httptest.lua index d5fbb37..63ff921 100644 --- a/test/httptest.lua +++ b/test/httptest.lua | |||
@@ -1,4 +1,4 @@ | |||
1 | -- needs Alias from /home/c/diego/tec/luasocket/test to | 1 | -- needs Alias from /home/c/diego/tec/luasocket/test to |
2 | -- "/luasocket-test" and "/luasocket-test/" | 2 | -- "/luasocket-test" and "/luasocket-test/" |
3 | -- needs ScriptAlias from /home/c/diego/tec/luasocket/test/cgi | 3 | -- needs ScriptAlias from /home/c/diego/tec/luasocket/test/cgi |
4 | -- to "/luasocket-test-cgi" and "/luasocket-test-cgi/" | 4 | -- to "/luasocket-test-cgi" and "/luasocket-test-cgi/" |
@@ -36,22 +36,22 @@ index = readfile(index_file) | |||
36 | local check_result = function(response, expect, ignore) | 36 | local check_result = function(response, expect, ignore) |
37 | for i,v in pairs(response) do | 37 | for i,v in pairs(response) do |
38 | if not ignore[i] then | 38 | if not ignore[i] then |
39 | if v ~= expect[i] then | 39 | if v ~= expect[i] then |
40 | local f = io.open("err", "w") | 40 | local f = io.open("err", "w") |
41 | f:write(tostring(v), "\n\n versus\n\n", tostring(expect[i])) | 41 | f:write(tostring(v), "\n\n versus\n\n", tostring(expect[i])) |
42 | f:close() | 42 | f:close() |
43 | fail(i .. " differs!") | 43 | fail(i .. " differs!") |
44 | end | 44 | end |
45 | end | 45 | end |
46 | end | 46 | end |
47 | for i,v in pairs(expect) do | 47 | for i,v in pairs(expect) do |
48 | if not ignore[i] then | 48 | if not ignore[i] then |
49 | if v ~= response[i] then | 49 | if v ~= response[i] then |
50 | local f = io.open("err", "w") | 50 | local f = io.open("err", "w") |
51 | f:write(tostring(response[i]), "\n\n versus\n\n", tostring(v)) | 51 | f:write(tostring(response[i]), "\n\n versus\n\n", tostring(v)) |
52 | v = string.sub(type(v) == "string" and v or "", 1, 70) | 52 | v = string.sub(type(v) == "string" and v or "", 1, 70) |
53 | f:close() | 53 | f:close() |
54 | fail(i .. " differs!") | 54 | fail(i .. " differs!") |
55 | end | 55 | end |
56 | end | 56 | end |
57 | end | 57 | end |
@@ -61,10 +61,10 @@ end | |||
61 | local check_request = function(request, expect, ignore) | 61 | local check_request = function(request, expect, ignore) |
62 | local t | 62 | local t |
63 | if not request.sink then request.sink, t = ltn12.sink.table() end | 63 | if not request.sink then request.sink, t = ltn12.sink.table() end |
64 | request.source = request.source or | 64 | request.source = request.source or |
65 | (request.body and ltn12.source.string(request.body)) | 65 | (request.body and ltn12.source.string(request.body)) |
66 | local response = {} | 66 | local response = {} |
67 | response.code, response.headers, response.status = | 67 | response.code, response.headers, response.status = |
68 | socket.skip(1, http.request(request)) | 68 | socket.skip(1, http.request(request)) |
69 | if t and #t > 0 then response.body = table.concat(t) end | 69 | if t and #t > 0 then response.body = table.concat(t) end |
70 | check_result(response, expect, ignore) | 70 | check_result(response, expect, ignore) |
@@ -82,7 +82,7 @@ else fail(back.query) end | |||
82 | ------------------------------------------------------------------------ | 82 | ------------------------------------------------------------------------ |
83 | io.write("testing query string correctness: ") | 83 | io.write("testing query string correctness: ") |
84 | forth = "this+is+the+query+string" | 84 | forth = "this+is+the+query+string" |
85 | back = http.request("http://" .. host .. cgiprefix .. | 85 | back = http.request("http://" .. host .. cgiprefix .. |
86 | "/query-string?" .. forth) | 86 | "/query-string?" .. forth) |
87 | if similar(back, forth) then print("ok") | 87 | if similar(back, forth) then print("ok") |
88 | else fail("failed!") end | 88 | else fail("failed!") end |
@@ -120,10 +120,10 @@ check_request(request, expect, ignore) | |||
120 | ------------------------------------------------------------------------ | 120 | ------------------------------------------------------------------------ |
121 | io.write("testing invalid url: ") | 121 | io.write("testing invalid url: ") |
122 | local r, e = http.request{url = host .. prefix} | 122 | local r, e = http.request{url = host .. prefix} |
123 | assert(r == nil and e == "invalid host ''") | 123 | assert(r == nil and e == "invalid host ''") |
124 | r, re = http.request(host .. prefix) | 124 | r, re = http.request(host .. prefix) |
125 | assert(r == nil and e == re, tostring(r) ..", " .. tostring(re) .. | 125 | assert(r == nil and e == re, tostring(r) ..", " .. tostring(re) .. |
126 | " vs " .. tostring(e)) | 126 | " vs " .. tostring(e)) |
127 | print("ok") | 127 | print("ok") |
128 | 128 | ||
129 | io.write("testing invalid empty port: ") | 129 | io.write("testing invalid empty port: ") |
@@ -212,7 +212,7 @@ os.remove(index_file .. "-back") | |||
212 | io.write("testing ltn12.(sink|source).chain and mime.(encode|decode): ") | 212 | io.write("testing ltn12.(sink|source).chain and mime.(encode|decode): ") |
213 | 213 | ||
214 | local function b64length(len) | 214 | local function b64length(len) |
215 | local a = math.ceil(len/3)*4 | 215 | local a = math.ceil(len/3)*4 |
216 | local l = math.ceil(a/76) | 216 | local l = math.ceil(a/76) |
217 | return a + l*2 | 217 | return a + l*2 |
218 | end | 218 | end |
@@ -313,7 +313,7 @@ ignore = { | |||
313 | headers = 1 | 313 | headers = 1 |
314 | } | 314 | } |
315 | check_request(request, expect, ignore) | 315 | check_request(request, expect, ignore) |
316 | 316 | ||
317 | ------------------------------------------------------------------------ | 317 | ------------------------------------------------------------------------ |
318 | io.write("testing document not found: ") | 318 | io.write("testing document not found: ") |
319 | request = { | 319 | request = { |
@@ -429,9 +429,9 @@ print("ok") | |||
429 | io.write("testing host not found: ") | 429 | io.write("testing host not found: ") |
430 | local c, e = socket.connect("example.invalid", 80) | 430 | local c, e = socket.connect("example.invalid", 80) |
431 | local r, re = http.request{url = "http://example.invalid/does/not/exist"} | 431 | local r, re = http.request{url = "http://example.invalid/does/not/exist"} |
432 | assert(r == nil and e == re, tostring(r) .. " " .. tostring(re)) | 432 | assert(r == nil and e == re, tostring(r) .. " " .. tostring(re)) |
433 | r, re = http.request("http://example.invalid/does/not/exist") | 433 | r, re = http.request("http://example.invalid/does/not/exist") |
434 | assert(r == nil and e == re) | 434 | assert(r == nil and e == re) |
435 | print("ok") | 435 | print("ok") |
436 | 436 | ||
437 | ------------------------------------------------------------------------ | 437 | ------------------------------------------------------------------------ |