diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ftp.lua | 2 | ||||
-rw-r--r-- | src/inet.c | 1 | ||||
-rw-r--r-- | src/luasocket.c | 11 | ||||
-rw-r--r-- | src/makefile | 8 | ||||
-rw-r--r-- | src/mime.c | 122 | ||||
-rw-r--r-- | src/options.h | 3 | ||||
-rw-r--r-- | src/udp.c | 2 |
7 files changed, 71 insertions, 78 deletions
diff --git a/src/ftp.lua b/src/ftp.lua index ea1145b..917cd89 100644 --- a/src/ftp.lua +++ b/src/ftp.lua | |||
@@ -268,7 +268,7 @@ _M.command = socket.protect(function(cmdt) | |||
268 | cmdt = override(cmdt) | 268 | cmdt = override(cmdt) |
269 | socket.try(cmdt.host, "missing hostname") | 269 | socket.try(cmdt.host, "missing hostname") |
270 | socket.try(cmdt.command, "missing command") | 270 | socket.try(cmdt.command, "missing command") |
271 | local f = open(cmdt.host, cmdt.port, cmdt.create) | 271 | local f = _M.open(cmdt.host, cmdt.port, cmdt.create) |
272 | f:greet() | 272 | f:greet() |
273 | f:login(cmdt.user, cmdt.password) | 273 | f:login(cmdt.user, cmdt.password) |
274 | f.try(f.tp:command(cmdt.command, cmdt.argument)) | 274 | f.try(f.tp:command(cmdt.command, cmdt.argument)) |
@@ -183,6 +183,7 @@ static int inet_global_getaddrinfo(lua_State *L) | |||
183 | ret = getnameinfo(iterator->ai_addr, (socklen_t) iterator->ai_addrlen, | 183 | ret = getnameinfo(iterator->ai_addr, (socklen_t) iterator->ai_addrlen, |
184 | hbuf, (socklen_t) sizeof(hbuf), NULL, 0, NI_NUMERICHOST); | 184 | hbuf, (socklen_t) sizeof(hbuf), NULL, 0, NI_NUMERICHOST); |
185 | if (ret){ | 185 | if (ret){ |
186 | freeaddrinfo(resolved); | ||
186 | lua_pushnil(L); | 187 | lua_pushnil(L); |
187 | lua_pushstring(L, socket_gaistrerror(ret)); | 188 | lua_pushstring(L, socket_gaistrerror(ret)); |
188 | return 2; | 189 | return 2; |
diff --git a/src/luasocket.c b/src/luasocket.c index e6ee747..c4eeab3 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 | \*=========================================================================*/ |
@@ -64,7 +63,7 @@ static luaL_Reg func[] = { | |||
64 | * Skip a few arguments | 63 | * Skip a few arguments |
65 | \*-------------------------------------------------------------------------*/ | 64 | \*-------------------------------------------------------------------------*/ |
66 | static int global_skip(lua_State *L) { | 65 | static int global_skip(lua_State *L) { |
67 | int amount = luaL_checkint(L, 1); | 66 | int amount = luaL_checkinteger(L, 1); |
68 | int ret = lua_gettop(L) - amount - 1; | 67 | int ret = lua_gettop(L) - amount - 1; |
69 | return ret >= 0 ? ret : 0; | 68 | return ret >= 0 ? ret : 0; |
70 | } | 69 | } |
@@ -78,14 +77,6 @@ static int global_unload(lua_State *L) { | |||
78 | return 0; | 77 | return 0; |
79 | } | 78 | } |
80 | 79 | ||
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 | /*-------------------------------------------------------------------------*\ | 80 | /*-------------------------------------------------------------------------*\ |
90 | * Setup basic stuff. | 81 | * Setup basic stuff. |
91 | \*-------------------------------------------------------------------------*/ | 82 | \*-------------------------------------------------------------------------*/ |
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 |
@@ -41,7 +41,7 @@ static size_t b64decode(UC c, UC *input, size_t size, luaL_Buffer *buffer); | |||
41 | static void qpsetup(UC *class, UC *unbase); | 41 | static void qpsetup(UC *class, UC *unbase); |
42 | static void qpquote(UC c, luaL_Buffer *buffer); | 42 | static void qpquote(UC c, luaL_Buffer *buffer); |
43 | static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer); | 43 | 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, | 44 | static size_t qpencode(UC c, UC *input, size_t size, |
45 | const char *marker, luaL_Buffer *buffer); | 45 | const char *marker, luaL_Buffer *buffer); |
46 | static size_t qppad(UC *input, size_t size, luaL_Buffer *buffer); | 46 | static size_t qppad(UC *input, size_t size, luaL_Buffer *buffer); |
47 | 47 | ||
@@ -103,15 +103,15 @@ MIME_API int luaopen_mime_core(lua_State *L) | |||
103 | /*-------------------------------------------------------------------------*\ | 103 | /*-------------------------------------------------------------------------*\ |
104 | * Incrementaly breaks a string into lines. The string can have CRLF breaks. | 104 | * Incrementaly breaks a string into lines. The string can have CRLF breaks. |
105 | * A, n = wrp(l, B, length) | 105 | * A, n = wrp(l, B, length) |
106 | * A is a copy of B, broken into lines of at most 'length' bytes. | 106 | * 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. | 107 | * '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. | 108 | * 'n' is the number of bytes left in the last line of A. |
109 | \*-------------------------------------------------------------------------*/ | 109 | \*-------------------------------------------------------------------------*/ |
110 | static int mime_global_wrp(lua_State *L) | 110 | static int mime_global_wrp(lua_State *L) |
111 | { | 111 | { |
112 | size_t size = 0; | 112 | size_t size = 0; |
113 | int left = (int) luaL_checknumber(L, 1); | 113 | int left = (int) luaL_checknumber(L, 1); |
114 | const UC *input = (UC *) luaL_optlstring(L, 2, NULL, &size); | 114 | const UC *input = (const UC *) luaL_optlstring(L, 2, NULL, &size); |
115 | const UC *last = input + size; | 115 | const UC *last = input + size; |
116 | int length = (int) luaL_optnumber(L, 3, 76); | 116 | int length = (int) luaL_optnumber(L, 3, 76); |
117 | luaL_Buffer buffer; | 117 | luaL_Buffer buffer; |
@@ -123,7 +123,7 @@ static int mime_global_wrp(lua_State *L) | |||
123 | else lua_pushnil(L); | 123 | else lua_pushnil(L); |
124 | lua_pushnumber(L, length); | 124 | lua_pushnumber(L, length); |
125 | return 2; | 125 | return 2; |
126 | } | 126 | } |
127 | luaL_buffinit(L, &buffer); | 127 | luaL_buffinit(L, &buffer); |
128 | while (input < last) { | 128 | while (input < last) { |
129 | switch (*input) { | 129 | switch (*input) { |
@@ -150,9 +150,9 @@ static int mime_global_wrp(lua_State *L) | |||
150 | } | 150 | } |
151 | 151 | ||
152 | /*-------------------------------------------------------------------------*\ | 152 | /*-------------------------------------------------------------------------*\ |
153 | * Fill base64 decode map. | 153 | * Fill base64 decode map. |
154 | \*-------------------------------------------------------------------------*/ | 154 | \*-------------------------------------------------------------------------*/ |
155 | static void b64setup(UC *unbase) | 155 | static void b64setup(UC *unbase) |
156 | { | 156 | { |
157 | int i; | 157 | int i; |
158 | for (i = 0; i <= 255; i++) unbase[i] = (UC) 255; | 158 | for (i = 0; i <= 255; i++) unbase[i] = (UC) 255; |
@@ -161,11 +161,11 @@ static void b64setup(UC *unbase) | |||
161 | } | 161 | } |
162 | 162 | ||
163 | /*-------------------------------------------------------------------------*\ | 163 | /*-------------------------------------------------------------------------*\ |
164 | * Acumulates bytes in input buffer until 3 bytes are available. | 164 | * Acumulates bytes in input buffer until 3 bytes are available. |
165 | * Translate the 3 bytes into Base64 form and append to buffer. | 165 | * Translate the 3 bytes into Base64 form and append to buffer. |
166 | * Returns new number of bytes in buffer. | 166 | * Returns new number of bytes in buffer. |
167 | \*-------------------------------------------------------------------------*/ | 167 | \*-------------------------------------------------------------------------*/ |
168 | static size_t b64encode(UC c, UC *input, size_t size, | 168 | static size_t b64encode(UC c, UC *input, size_t size, |
169 | luaL_Buffer *buffer) | 169 | luaL_Buffer *buffer) |
170 | { | 170 | { |
171 | input[size++] = c; | 171 | input[size++] = c; |
@@ -174,7 +174,7 @@ static size_t b64encode(UC c, UC *input, size_t size, | |||
174 | unsigned long value = 0; | 174 | unsigned long value = 0; |
175 | value += input[0]; value <<= 8; | 175 | value += input[0]; value <<= 8; |
176 | value += input[1]; value <<= 8; | 176 | value += input[1]; value <<= 8; |
177 | value += input[2]; | 177 | value += input[2]; |
178 | code[3] = b64base[value & 0x3f]; value >>= 6; | 178 | code[3] = b64base[value & 0x3f]; value >>= 6; |
179 | code[2] = b64base[value & 0x3f]; value >>= 6; | 179 | code[2] = b64base[value & 0x3f]; value >>= 6; |
180 | code[1] = b64base[value & 0x3f]; value >>= 6; | 180 | code[1] = b64base[value & 0x3f]; value >>= 6; |
@@ -186,11 +186,11 @@ static size_t b64encode(UC c, UC *input, size_t size, | |||
186 | } | 186 | } |
187 | 187 | ||
188 | /*-------------------------------------------------------------------------*\ | 188 | /*-------------------------------------------------------------------------*\ |
189 | * Encodes the Base64 last 1 or 2 bytes and adds padding '=' | 189 | * Encodes the Base64 last 1 or 2 bytes and adds padding '=' |
190 | * Result, if any, is appended to buffer. | 190 | * Result, if any, is appended to buffer. |
191 | * Returns 0. | 191 | * Returns 0. |
192 | \*-------------------------------------------------------------------------*/ | 192 | \*-------------------------------------------------------------------------*/ |
193 | static size_t b64pad(const UC *input, size_t size, | 193 | static size_t b64pad(const UC *input, size_t size, |
194 | luaL_Buffer *buffer) | 194 | luaL_Buffer *buffer) |
195 | { | 195 | { |
196 | unsigned long value = 0; | 196 | unsigned long value = 0; |
@@ -203,7 +203,7 @@ static size_t b64pad(const UC *input, size_t size, | |||
203 | luaL_addlstring(buffer, (char *) code, 4); | 203 | luaL_addlstring(buffer, (char *) code, 4); |
204 | break; | 204 | break; |
205 | case 2: | 205 | case 2: |
206 | value = input[0]; value <<= 8; | 206 | value = input[0]; value <<= 8; |
207 | value |= input[1]; value <<= 2; | 207 | value |= input[1]; value <<= 2; |
208 | code[2] = b64base[value & 0x3f]; value >>= 6; | 208 | code[2] = b64base[value & 0x3f]; value >>= 6; |
209 | code[1] = b64base[value & 0x3f]; value >>= 6; | 209 | code[1] = b64base[value & 0x3f]; value >>= 6; |
@@ -217,11 +217,11 @@ static size_t b64pad(const UC *input, size_t size, | |||
217 | } | 217 | } |
218 | 218 | ||
219 | /*-------------------------------------------------------------------------*\ | 219 | /*-------------------------------------------------------------------------*\ |
220 | * Acumulates bytes in input buffer until 4 bytes are available. | 220 | * Acumulates bytes in input buffer until 4 bytes are available. |
221 | * Translate the 4 bytes from Base64 form and append to buffer. | 221 | * Translate the 4 bytes from Base64 form and append to buffer. |
222 | * Returns new number of bytes in buffer. | 222 | * Returns new number of bytes in buffer. |
223 | \*-------------------------------------------------------------------------*/ | 223 | \*-------------------------------------------------------------------------*/ |
224 | static size_t b64decode(UC c, UC *input, size_t size, | 224 | static size_t b64decode(UC c, UC *input, size_t size, |
225 | luaL_Buffer *buffer) | 225 | luaL_Buffer *buffer) |
226 | { | 226 | { |
227 | /* ignore invalid characters */ | 227 | /* ignore invalid characters */ |
@@ -239,7 +239,7 @@ static size_t b64decode(UC c, UC *input, size_t size, | |||
239 | decoded[1] = (UC) (value & 0xff); value >>= 8; | 239 | decoded[1] = (UC) (value & 0xff); value >>= 8; |
240 | decoded[0] = (UC) value; | 240 | decoded[0] = (UC) value; |
241 | /* take care of paddding */ | 241 | /* take care of paddding */ |
242 | valid = (input[2] == '=') ? 1 : (input[3] == '=') ? 2 : 3; | 242 | valid = (input[2] == '=') ? 1 : (input[3] == '=') ? 2 : 3; |
243 | luaL_addlstring(buffer, (char *) decoded, valid); | 243 | luaL_addlstring(buffer, (char *) decoded, valid); |
244 | return 0; | 244 | return 0; |
245 | /* need more data */ | 245 | /* need more data */ |
@@ -251,7 +251,7 @@ static size_t b64decode(UC c, UC *input, size_t size, | |||
251 | * A, B = b64(C, D) | 251 | * A, B = b64(C, D) |
252 | * A is the encoded version of the largest prefix of C .. D that is | 252 | * 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. | 253 | * 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 | 254 | * 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 | 255 | * encode the result, but we can't afford that or Lua would dupplicate |
256 | * every chunk we received. | 256 | * every chunk we received. |
257 | \*-------------------------------------------------------------------------*/ | 257 | \*-------------------------------------------------------------------------*/ |
@@ -259,7 +259,7 @@ static int mime_global_b64(lua_State *L) | |||
259 | { | 259 | { |
260 | UC atom[3]; | 260 | UC atom[3]; |
261 | size_t isize = 0, asize = 0; | 261 | size_t isize = 0, asize = 0; |
262 | const UC *input = (UC *) luaL_optlstring(L, 1, NULL, &isize); | 262 | const UC *input = (const UC *) luaL_optlstring(L, 1, NULL, &isize); |
263 | const UC *last = input + isize; | 263 | const UC *last = input + isize; |
264 | luaL_Buffer buffer; | 264 | luaL_Buffer buffer; |
265 | /* end-of-input blackhole */ | 265 | /* end-of-input blackhole */ |
@@ -272,9 +272,9 @@ static int mime_global_b64(lua_State *L) | |||
272 | lua_settop(L, 2); | 272 | lua_settop(L, 2); |
273 | /* process first part of the input */ | 273 | /* process first part of the input */ |
274 | luaL_buffinit(L, &buffer); | 274 | luaL_buffinit(L, &buffer); |
275 | while (input < last) | 275 | while (input < last) |
276 | asize = b64encode(*input++, atom, asize, &buffer); | 276 | asize = b64encode(*input++, atom, asize, &buffer); |
277 | input = (UC *) luaL_optlstring(L, 2, NULL, &isize); | 277 | input = (const UC *) luaL_optlstring(L, 2, NULL, &isize); |
278 | /* if second part is nil, we are done */ | 278 | /* if second part is nil, we are done */ |
279 | if (!input) { | 279 | if (!input) { |
280 | size_t osize = 0; | 280 | size_t osize = 0; |
@@ -288,7 +288,7 @@ static int mime_global_b64(lua_State *L) | |||
288 | } | 288 | } |
289 | /* otherwise process the second part */ | 289 | /* otherwise process the second part */ |
290 | last = input + isize; | 290 | last = input + isize; |
291 | while (input < last) | 291 | while (input < last) |
292 | asize = b64encode(*input++, atom, asize, &buffer); | 292 | asize = b64encode(*input++, atom, asize, &buffer); |
293 | luaL_pushresult(&buffer); | 293 | luaL_pushresult(&buffer); |
294 | lua_pushlstring(L, (char *) atom, asize); | 294 | lua_pushlstring(L, (char *) atom, asize); |
@@ -305,7 +305,7 @@ static int mime_global_unb64(lua_State *L) | |||
305 | { | 305 | { |
306 | UC atom[4]; | 306 | UC atom[4]; |
307 | size_t isize = 0, asize = 0; | 307 | size_t isize = 0, asize = 0; |
308 | const UC *input = (UC *) luaL_optlstring(L, 1, NULL, &isize); | 308 | const UC *input = (const UC *) luaL_optlstring(L, 1, NULL, &isize); |
309 | const UC *last = input + isize; | 309 | const UC *last = input + isize; |
310 | luaL_Buffer buffer; | 310 | luaL_Buffer buffer; |
311 | /* end-of-input blackhole */ | 311 | /* end-of-input blackhole */ |
@@ -318,9 +318,9 @@ static int mime_global_unb64(lua_State *L) | |||
318 | lua_settop(L, 2); | 318 | lua_settop(L, 2); |
319 | /* process first part of the input */ | 319 | /* process first part of the input */ |
320 | luaL_buffinit(L, &buffer); | 320 | luaL_buffinit(L, &buffer); |
321 | while (input < last) | 321 | while (input < last) |
322 | asize = b64decode(*input++, atom, asize, &buffer); | 322 | asize = b64decode(*input++, atom, asize, &buffer); |
323 | input = (UC *) luaL_optlstring(L, 2, NULL, &isize); | 323 | input = (const UC *) luaL_optlstring(L, 2, NULL, &isize); |
324 | /* if second is nil, we are done */ | 324 | /* if second is nil, we are done */ |
325 | if (!input) { | 325 | if (!input) { |
326 | size_t osize = 0; | 326 | size_t osize = 0; |
@@ -333,7 +333,7 @@ static int mime_global_unb64(lua_State *L) | |||
333 | } | 333 | } |
334 | /* otherwise, process the rest of the input */ | 334 | /* otherwise, process the rest of the input */ |
335 | last = input + isize; | 335 | last = input + isize; |
336 | while (input < last) | 336 | while (input < last) |
337 | asize = b64decode(*input++, atom, asize, &buffer); | 337 | asize = b64decode(*input++, atom, asize, &buffer); |
338 | luaL_pushresult(&buffer); | 338 | luaL_pushresult(&buffer); |
339 | lua_pushlstring(L, (char *) atom, asize); | 339 | lua_pushlstring(L, (char *) atom, asize); |
@@ -349,7 +349,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 | 349 | * 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 | 350 | * encoded lines must be no longer than 76 not counting CRLF |
351 | * soft line-break are =CRLF | 351 | * soft line-break are =CRLF |
352 | * To encode one byte, we need to see the next two. | 352 | * 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 | 353 | * Worst case is when we see a space, and wonder if a CRLF is comming |
354 | \*-------------------------------------------------------------------------*/ | 354 | \*-------------------------------------------------------------------------*/ |
355 | /*-------------------------------------------------------------------------*\ | 355 | /*-------------------------------------------------------------------------*\ |
@@ -362,7 +362,7 @@ static void qpsetup(UC *cl, UC *unbase) | |||
362 | for (i = 0; i < 256; i++) cl[i] = QP_QUOTED; | 362 | for (i = 0; i < 256; i++) cl[i] = QP_QUOTED; |
363 | for (i = 33; i <= 60; i++) cl[i] = QP_PLAIN; | 363 | for (i = 33; i <= 60; i++) cl[i] = QP_PLAIN; |
364 | for (i = 62; i <= 126; i++) cl[i] = QP_PLAIN; | 364 | for (i = 62; i <= 126; i++) cl[i] = QP_PLAIN; |
365 | cl['\t'] = QP_IF_LAST; | 365 | cl['\t'] = QP_IF_LAST; |
366 | cl[' '] = QP_IF_LAST; | 366 | cl[' '] = QP_IF_LAST; |
367 | cl['\r'] = QP_CR; | 367 | cl['\r'] = QP_CR; |
368 | for (i = 0; i < 256; i++) unbase[i] = 255; | 368 | for (i = 0; i < 256; i++) unbase[i] = 255; |
@@ -388,9 +388,9 @@ static void qpquote(UC c, luaL_Buffer *buffer) | |||
388 | 388 | ||
389 | /*-------------------------------------------------------------------------*\ | 389 | /*-------------------------------------------------------------------------*\ |
390 | * Accumulate characters until we are sure about how to deal with them. | 390 | * 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. | 391 | * Once we are sure, output to the buffer, in the correct form. |
392 | \*-------------------------------------------------------------------------*/ | 392 | \*-------------------------------------------------------------------------*/ |
393 | static size_t qpencode(UC c, UC *input, size_t size, | 393 | static size_t qpencode(UC c, UC *input, size_t size, |
394 | const char *marker, luaL_Buffer *buffer) | 394 | const char *marker, luaL_Buffer *buffer) |
395 | { | 395 | { |
396 | input[size++] = c; | 396 | input[size++] = c; |
@@ -431,7 +431,7 @@ static size_t qpencode(UC c, UC *input, size_t size, | |||
431 | } | 431 | } |
432 | 432 | ||
433 | /*-------------------------------------------------------------------------*\ | 433 | /*-------------------------------------------------------------------------*\ |
434 | * Deal with the final characters | 434 | * Deal with the final characters |
435 | \*-------------------------------------------------------------------------*/ | 435 | \*-------------------------------------------------------------------------*/ |
436 | static size_t qppad(UC *input, size_t size, luaL_Buffer *buffer) | 436 | static size_t qppad(UC *input, size_t size, luaL_Buffer *buffer) |
437 | { | 437 | { |
@@ -448,8 +448,8 @@ static size_t qppad(UC *input, size_t size, luaL_Buffer *buffer) | |||
448 | * Incrementally converts a string to quoted-printable | 448 | * Incrementally converts a string to quoted-printable |
449 | * A, B = qp(C, D, marker) | 449 | * A, B = qp(C, D, marker) |
450 | * Marker is the text to be used to replace CRLF sequences found in A. | 450 | * 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 | 451 | * A is the encoded version of the largest prefix of C .. D that |
452 | * can be encoded without doubts. | 452 | * can be encoded without doubts. |
453 | * B has the remaining bytes of C .. D, *without* encoding. | 453 | * B has the remaining bytes of C .. D, *without* encoding. |
454 | \*-------------------------------------------------------------------------*/ | 454 | \*-------------------------------------------------------------------------*/ |
455 | static int mime_global_qp(lua_State *L) | 455 | static int mime_global_qp(lua_State *L) |
@@ -457,7 +457,7 @@ static int mime_global_qp(lua_State *L) | |||
457 | 457 | ||
458 | size_t asize = 0, isize = 0; | 458 | size_t asize = 0, isize = 0; |
459 | UC atom[3]; | 459 | UC atom[3]; |
460 | const UC *input = (UC *) luaL_optlstring(L, 1, NULL, &isize); | 460 | const UC *input = (const UC *) luaL_optlstring(L, 1, NULL, &isize); |
461 | const UC *last = input + isize; | 461 | const UC *last = input + isize; |
462 | const char *marker = luaL_optstring(L, 3, CRLF); | 462 | const char *marker = luaL_optstring(L, 3, CRLF); |
463 | luaL_Buffer buffer; | 463 | luaL_Buffer buffer; |
@@ -473,7 +473,7 @@ static int mime_global_qp(lua_State *L) | |||
473 | luaL_buffinit(L, &buffer); | 473 | luaL_buffinit(L, &buffer); |
474 | while (input < last) | 474 | while (input < last) |
475 | asize = qpencode(*input++, atom, asize, marker, &buffer); | 475 | asize = qpencode(*input++, atom, asize, marker, &buffer); |
476 | input = (UC *) luaL_optlstring(L, 2, NULL, &isize); | 476 | input = (const UC *) luaL_optlstring(L, 2, NULL, &isize); |
477 | /* if second part is nil, we are done */ | 477 | /* if second part is nil, we are done */ |
478 | if (!input) { | 478 | if (!input) { |
479 | asize = qppad(atom, asize, &buffer); | 479 | asize = qppad(atom, asize, &buffer); |
@@ -493,7 +493,7 @@ static int mime_global_qp(lua_State *L) | |||
493 | 493 | ||
494 | /*-------------------------------------------------------------------------*\ | 494 | /*-------------------------------------------------------------------------*\ |
495 | * Accumulate characters until we are sure about how to deal with them. | 495 | * 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. | 496 | * Once we are sure, output the to the buffer, in the correct form. |
497 | \*-------------------------------------------------------------------------*/ | 497 | \*-------------------------------------------------------------------------*/ |
498 | static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer) { | 498 | static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer) { |
499 | int d; | 499 | int d; |
@@ -501,8 +501,8 @@ static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer) { | |||
501 | /* deal with all characters we can deal */ | 501 | /* deal with all characters we can deal */ |
502 | switch (input[0]) { | 502 | switch (input[0]) { |
503 | /* if we have an escape character */ | 503 | /* if we have an escape character */ |
504 | case '=': | 504 | case '=': |
505 | if (size < 3) return size; | 505 | if (size < 3) return size; |
506 | /* eliminate soft line break */ | 506 | /* eliminate soft line break */ |
507 | if (input[1] == '\r' && input[2] == '\n') return 0; | 507 | if (input[1] == '\r' && input[2] == '\n') return 0; |
508 | /* decode quoted representation */ | 508 | /* decode quoted representation */ |
@@ -512,7 +512,7 @@ static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer) { | |||
512 | else luaL_addchar(buffer, (char) ((c << 4) + d)); | 512 | else luaL_addchar(buffer, (char) ((c << 4) + d)); |
513 | return 0; | 513 | return 0; |
514 | case '\r': | 514 | case '\r': |
515 | if (size < 2) return size; | 515 | if (size < 2) return size; |
516 | if (input[1] == '\n') luaL_addlstring(buffer, (char *)input, 2); | 516 | if (input[1] == '\n') luaL_addlstring(buffer, (char *)input, 2); |
517 | return 0; | 517 | return 0; |
518 | default: | 518 | default: |
@@ -525,15 +525,15 @@ static size_t qpdecode(UC c, UC *input, size_t size, luaL_Buffer *buffer) { | |||
525 | /*-------------------------------------------------------------------------*\ | 525 | /*-------------------------------------------------------------------------*\ |
526 | * Incrementally decodes a string in quoted-printable | 526 | * Incrementally decodes a string in quoted-printable |
527 | * A, B = qp(C, D) | 527 | * A, B = qp(C, D) |
528 | * A is the decoded version of the largest prefix of C .. D that | 528 | * A is the decoded version of the largest prefix of C .. D that |
529 | * can be decoded without doubts. | 529 | * can be decoded without doubts. |
530 | * B has the remaining bytes of C .. D, *without* decoding. | 530 | * B has the remaining bytes of C .. D, *without* decoding. |
531 | \*-------------------------------------------------------------------------*/ | 531 | \*-------------------------------------------------------------------------*/ |
532 | static int mime_global_unqp(lua_State *L) | 532 | static int mime_global_unqp(lua_State *L) |
533 | { | 533 | { |
534 | size_t asize = 0, isize = 0; | 534 | size_t asize = 0, isize = 0; |
535 | UC atom[3]; | 535 | UC atom[3]; |
536 | const UC *input = (UC *) luaL_optlstring(L, 1, NULL, &isize); | 536 | const UC *input = (const UC *) luaL_optlstring(L, 1, NULL, &isize); |
537 | const UC *last = input + isize; | 537 | const UC *last = input + isize; |
538 | luaL_Buffer buffer; | 538 | luaL_Buffer buffer; |
539 | /* end-of-input blackhole */ | 539 | /* end-of-input blackhole */ |
@@ -548,14 +548,14 @@ static int mime_global_unqp(lua_State *L) | |||
548 | luaL_buffinit(L, &buffer); | 548 | luaL_buffinit(L, &buffer); |
549 | while (input < last) | 549 | while (input < last) |
550 | asize = qpdecode(*input++, atom, asize, &buffer); | 550 | asize = qpdecode(*input++, atom, asize, &buffer); |
551 | input = (UC *) luaL_optlstring(L, 2, NULL, &isize); | 551 | input = (const UC *) luaL_optlstring(L, 2, NULL, &isize); |
552 | /* if second part is nil, we are done */ | 552 | /* if second part is nil, we are done */ |
553 | if (!input) { | 553 | if (!input) { |
554 | luaL_pushresult(&buffer); | 554 | luaL_pushresult(&buffer); |
555 | if (!(*lua_tostring(L, -1))) lua_pushnil(L); | 555 | if (!(*lua_tostring(L, -1))) lua_pushnil(L); |
556 | lua_pushnil(L); | 556 | lua_pushnil(L); |
557 | return 2; | 557 | return 2; |
558 | } | 558 | } |
559 | /* otherwise process rest of input */ | 559 | /* otherwise process rest of input */ |
560 | last = input + isize; | 560 | last = input + isize; |
561 | while (input < last) | 561 | while (input < last) |
@@ -568,9 +568,9 @@ static int mime_global_unqp(lua_State *L) | |||
568 | /*-------------------------------------------------------------------------*\ | 568 | /*-------------------------------------------------------------------------*\ |
569 | * Incrementally breaks a quoted-printed string into lines | 569 | * Incrementally breaks a quoted-printed string into lines |
570 | * A, n = qpwrp(l, B, length) | 570 | * A, n = qpwrp(l, B, length) |
571 | * A is a copy of B, broken into lines of at most 'length' bytes. | 571 | * 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. | 572 | * '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. | 573 | * '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 | 574 | * There are two complications: lines can't be broken in the middle |
575 | * of an encoded =XX, and there might be line breaks already | 575 | * of an encoded =XX, and there might be line breaks already |
576 | \*-------------------------------------------------------------------------*/ | 576 | \*-------------------------------------------------------------------------*/ |
@@ -578,7 +578,7 @@ static int mime_global_qpwrp(lua_State *L) | |||
578 | { | 578 | { |
579 | size_t size = 0; | 579 | size_t size = 0; |
580 | int left = (int) luaL_checknumber(L, 1); | 580 | int left = (int) luaL_checknumber(L, 1); |
581 | const UC *input = (UC *) luaL_optlstring(L, 2, NULL, &size); | 581 | const UC *input = (const UC *) luaL_optlstring(L, 2, NULL, &size); |
582 | const UC *last = input + size; | 582 | const UC *last = input + size; |
583 | int length = (int) luaL_optnumber(L, 3, 76); | 583 | int length = (int) luaL_optnumber(L, 3, 76); |
584 | luaL_Buffer buffer; | 584 | luaL_Buffer buffer; |
@@ -603,11 +603,11 @@ static int mime_global_qpwrp(lua_State *L) | |||
603 | if (left <= 3) { | 603 | if (left <= 3) { |
604 | left = length; | 604 | left = length; |
605 | luaL_addstring(&buffer, EQCRLF); | 605 | luaL_addstring(&buffer, EQCRLF); |
606 | } | 606 | } |
607 | luaL_addchar(&buffer, *input); | 607 | luaL_addchar(&buffer, *input); |
608 | left--; | 608 | left--; |
609 | break; | 609 | break; |
610 | default: | 610 | default: |
611 | if (left <= 1) { | 611 | if (left <= 1) { |
612 | left = length; | 612 | left = length; |
613 | luaL_addstring(&buffer, EQCRLF); | 613 | luaL_addstring(&buffer, EQCRLF); |
@@ -635,7 +635,7 @@ static int mime_global_qpwrp(lua_State *L) | |||
635 | * last is the previous character | 635 | * last is the previous character |
636 | \*-------------------------------------------------------------------------*/ | 636 | \*-------------------------------------------------------------------------*/ |
637 | #define eolcandidate(c) (c == '\r' || c == '\n') | 637 | #define eolcandidate(c) (c == '\r' || c == '\n') |
638 | static int eolprocess(int c, int last, const char *marker, | 638 | static int eolprocess(int c, int last, const char *marker, |
639 | luaL_Buffer *buffer) | 639 | luaL_Buffer *buffer) |
640 | { | 640 | { |
641 | if (eolcandidate(c)) { | 641 | if (eolcandidate(c)) { |
@@ -653,15 +653,15 @@ static int eolprocess(int c, int last, const char *marker, | |||
653 | } | 653 | } |
654 | 654 | ||
655 | /*-------------------------------------------------------------------------*\ | 655 | /*-------------------------------------------------------------------------*\ |
656 | * Converts a string to uniform EOL convention. | 656 | * Converts a string to uniform EOL convention. |
657 | * A, n = eol(o, B, marker) | 657 | * A, n = eol(o, B, marker) |
658 | * A is the converted version of the largest prefix of B that can be | 658 | * 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 | 659 | * converted unambiguously. 'o' is the context returned by the previous |
660 | * call. 'n' is the new context. | 660 | * call. 'n' is the new context. |
661 | \*-------------------------------------------------------------------------*/ | 661 | \*-------------------------------------------------------------------------*/ |
662 | static int mime_global_eol(lua_State *L) | 662 | static int mime_global_eol(lua_State *L) |
663 | { | 663 | { |
664 | int ctx = luaL_checkint(L, 1); | 664 | int ctx = luaL_checkinteger(L, 1); |
665 | size_t isize = 0; | 665 | size_t isize = 0; |
666 | const char *input = luaL_optlstring(L, 2, NULL, &isize); | 666 | const char *input = luaL_optlstring(L, 2, NULL, &isize); |
667 | const char *last = input + isize; | 667 | const char *last = input + isize; |
@@ -683,18 +683,18 @@ static int mime_global_eol(lua_State *L) | |||
683 | } | 683 | } |
684 | 684 | ||
685 | /*-------------------------------------------------------------------------*\ | 685 | /*-------------------------------------------------------------------------*\ |
686 | * Takes one byte and stuff it if needed. | 686 | * Takes one byte and stuff it if needed. |
687 | \*-------------------------------------------------------------------------*/ | 687 | \*-------------------------------------------------------------------------*/ |
688 | static size_t dot(int c, size_t state, luaL_Buffer *buffer) | 688 | static size_t dot(int c, size_t state, luaL_Buffer *buffer) |
689 | { | 689 | { |
690 | luaL_addchar(buffer, (char) c); | 690 | luaL_addchar(buffer, (char) c); |
691 | switch (c) { | 691 | switch (c) { |
692 | case '\r': | 692 | case '\r': |
693 | return 1; | 693 | return 1; |
694 | case '\n': | 694 | case '\n': |
695 | return (state == 1)? 2: 0; | 695 | return (state == 1)? 2: 0; |
696 | case '.': | 696 | case '.': |
697 | if (state == 2) | 697 | if (state == 2) |
698 | luaL_addchar(buffer, '.'); | 698 | luaL_addchar(buffer, '.'); |
699 | default: | 699 | default: |
700 | return 0; | 700 | return 0; |
@@ -719,7 +719,7 @@ static int mime_global_dot(lua_State *L) | |||
719 | } | 719 | } |
720 | /* process all input */ | 720 | /* process all input */ |
721 | luaL_buffinit(L, &buffer); | 721 | luaL_buffinit(L, &buffer); |
722 | while (input < last) | 722 | while (input < last) |
723 | state = dot(*input++, state, &buffer); | 723 | state = dot(*input++, state, &buffer); |
724 | luaL_pushresult(&buffer); | 724 | luaL_pushresult(&buffer); |
725 | lua_pushnumber(L, (lua_Number) state); | 725 | lua_pushnumber(L, (lua_Number) state); |
diff --git a/src/options.h b/src/options.h index 5657a06..b75db37 100644 --- a/src/options.h +++ b/src/options.h | |||
@@ -51,7 +51,8 @@ int opt_get_error(lua_State *L, p_socket ps); | |||
51 | int opt_get_ip6_multicast_loop(lua_State *L, p_socket ps); | 51 | int opt_get_ip6_multicast_loop(lua_State *L, p_socket ps); |
52 | int opt_get_ip6_multicast_hops(lua_State *L, p_socket ps); | 52 | int opt_get_ip6_multicast_hops(lua_State *L, p_socket ps); |
53 | int opt_get_ip6_unicast_hops(lua_State *L, p_socket ps); | 53 | int opt_get_ip6_unicast_hops(lua_State *L, p_socket ps); |
54 | int opt_get_ip6_v6only(lua_State *L, p_socket ps); | 54 | int opt_get_ip6_v6only(lua_State *L, p_socket ps); |
55 | int opt_get_reuseport(lua_State *L, p_socket ps); | ||
55 | 56 | ||
56 | /* invokes the appropriate option handler */ | 57 | /* invokes the appropriate option handler */ |
57 | int opt_meth_setoption(lua_State *L, p_opt opt, p_socket ps); | 58 | int opt_meth_setoption(lua_State *L, p_opt opt, p_socket ps); |
@@ -131,7 +131,7 @@ int udp_open(lua_State *L) | |||
131 | /*=========================================================================*\ | 131 | /*=========================================================================*\ |
132 | * Lua methods | 132 | * Lua methods |
133 | \*=========================================================================*/ | 133 | \*=========================================================================*/ |
134 | const char *udp_strerror(int err) { | 134 | static const char *udp_strerror(int err) { |
135 | /* a 'closed' error on an unconnected means the target address was not | 135 | /* a 'closed' error on an unconnected means the target address was not |
136 | * accepted by the transport layer */ | 136 | * accepted by the transport layer */ |
137 | if (err == IO_CLOSED) return "refused"; | 137 | if (err == IO_CLOSED) return "refused"; |