aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-01-19 06:07:17 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-01-19 06:07:17 +0000
commit32a3b93512d946dfcfeaafb7e49162c844c4f3ce (patch)
tree59cfbb8c400247e9c0ba5af4837f9198d8b04437 /src
parent5b8d7dec541a618b4ca7f2205470a28cde2e3e25 (diff)
downloadluasocket-32a3b93512d946dfcfeaafb7e49162c844c4f3ce.tar.gz
luasocket-32a3b93512d946dfcfeaafb7e49162c844c4f3ce.tar.bz2
luasocket-32a3b93512d946dfcfeaafb7e49162c844c4f3ce.zip
Added -ansi -pedantic and faced the consequences...
Diffstat (limited to 'src')
-rw-r--r--src/mime.c79
-rw-r--r--src/tcp.c3
2 files changed, 44 insertions, 38 deletions
diff --git a/src/mime.c b/src/mime.c
index 6807af5..6ed2787 100644
--- a/src/mime.c
+++ b/src/mime.c
@@ -113,22 +113,23 @@ void mime_open(lua_State *L)
113static int mime_global_fmt(lua_State *L) 113static int mime_global_fmt(lua_State *L)
114{ 114{
115 size_t size = 0; 115 size_t size = 0;
116 const UC *input = lua_isnil(L, 1)? NULL: luaL_checklstring(L, 1, &size); 116 const UC *input = (UC *) (lua_isnil(L, 1)? NULL:
117 luaL_checklstring(L, 1, &size));
117 const UC *last = input + size; 118 const UC *last = input + size;
118 int length = (int) luaL_checknumber(L, 2); 119 int length = (int) luaL_checknumber(L, 2);
119 int left = (int) luaL_optnumber(L, 3, length); 120 int left = (int) luaL_optnumber(L, 3, length);
120 const UC *marker = luaL_optstring(L, 4, CRLF); 121 const UC *marker = (UC *) luaL_optstring(L, 4, (char *) CRLF);
121 luaL_Buffer buffer; 122 luaL_Buffer buffer;
122 luaL_buffinit(L, &buffer); 123 luaL_buffinit(L, &buffer);
123 while (input < last) { 124 while (input < last) {
124 luaL_putchar(&buffer, *input++); 125 luaL_putchar(&buffer, *input++);
125 if (--left <= 0) { 126 if (--left <= 0) {
126 luaL_addstring(&buffer, marker); 127 luaL_addstring(&buffer, (char *) marker);
127 left = length; 128 left = length;
128 } 129 }
129 } 130 }
130 if (!input && left < length) { 131 if (!input && left < length) {
131 luaL_addstring(&buffer, marker); 132 luaL_addstring(&buffer, (char *) marker);
132 left = length; 133 left = length;
133 } 134 }
134 luaL_pushresult(&buffer); 135 luaL_pushresult(&buffer);
@@ -166,7 +167,7 @@ static size_t b64encode(UC c, UC *input, size_t size,
166 code[2] = b64base[value & 0x3f]; value >>= 6; 167 code[2] = b64base[value & 0x3f]; value >>= 6;
167 code[1] = b64base[value & 0x3f]; value >>= 6; 168 code[1] = b64base[value & 0x3f]; value >>= 6;
168 code[0] = b64base[value]; 169 code[0] = b64base[value];
169 luaL_addlstring(buffer, code, 4); 170 luaL_addlstring(buffer, (char *) code, 4);
170 size = 0; 171 size = 0;
171 } 172 }
172 return size; 173 return size;
@@ -187,7 +188,7 @@ static size_t b64pad(const UC *input, size_t size,
187 value = input[0] << 4; 188 value = input[0] << 4;
188 code[1] = b64base[value & 0x3f]; value >>= 6; 189 code[1] = b64base[value & 0x3f]; value >>= 6;
189 code[0] = b64base[value]; 190 code[0] = b64base[value];
190 luaL_addlstring(buffer, code, 4); 191 luaL_addlstring(buffer, (char *) code, 4);
191 break; 192 break;
192 case 2: 193 case 2:
193 value = input[0]; value <<= 8; 194 value = input[0]; value <<= 8;
@@ -195,7 +196,7 @@ static size_t b64pad(const UC *input, size_t size,
195 code[2] = b64base[value & 0x3f]; value >>= 6; 196 code[2] = b64base[value & 0x3f]; value >>= 6;
196 code[1] = b64base[value & 0x3f]; value >>= 6; 197 code[1] = b64base[value & 0x3f]; value >>= 6;
197 code[0] = b64base[value]; 198 code[0] = b64base[value];
198 luaL_addlstring(buffer, code, 4); 199 luaL_addlstring(buffer, (char *) code, 4);
199 break; 200 break;
200 case 0: /* fall through */ 201 case 0: /* fall through */
201 default: 202 default:
@@ -229,7 +230,7 @@ static size_t b64decode(UC c, UC *input, size_t size,
229 decoded[0] = (UC) value; 230 decoded[0] = (UC) value;
230 /* take care of paddding */ 231 /* take care of paddding */
231 valid = (input[2] == '=') ? 1 : (input[3] == '=') ? 2 : 3; 232 valid = (input[2] == '=') ? 1 : (input[3] == '=') ? 2 : 3;
232 luaL_addlstring(buffer, decoded, valid); 233 luaL_addlstring(buffer, (char *) decoded, valid);
233 return 0; 234 return 0;
234 /* need more data */ 235 /* need more data */
235 } else return size; 236 } else return size;
@@ -248,13 +249,13 @@ static int mime_global_b64(lua_State *L)
248{ 249{
249 UC atom[3]; 250 UC atom[3];
250 size_t isize = 0, asize = 0; 251 size_t isize = 0, asize = 0;
251 const UC *input = luaL_checklstring(L, 1, &isize); 252 const UC *input = (UC *) luaL_checklstring(L, 1, &isize);
252 const UC *last = input + isize; 253 const UC *last = input + isize;
253 luaL_Buffer buffer; 254 luaL_Buffer buffer;
254 luaL_buffinit(L, &buffer); 255 luaL_buffinit(L, &buffer);
255 while (input < last) 256 while (input < last)
256 asize = b64encode(*input++, atom, asize, &buffer); 257 asize = b64encode(*input++, atom, asize, &buffer);
257 input = luaL_optlstring(L, 2, NULL, &isize); 258 input = (UC *) luaL_optlstring(L, 2, NULL, &isize);
258 if (input) { 259 if (input) {
259 last = input + isize; 260 last = input + isize;
260 while (input < last) 261 while (input < last)
@@ -262,7 +263,7 @@ static int mime_global_b64(lua_State *L)
262 } else 263 } else
263 asize = b64pad(atom, asize, &buffer); 264 asize = b64pad(atom, asize, &buffer);
264 luaL_pushresult(&buffer); 265 luaL_pushresult(&buffer);
265 lua_pushlstring(L, atom, asize); 266 lua_pushlstring(L, (char *) atom, asize);
266 return 2; 267 return 2;
267} 268}
268 269
@@ -276,20 +277,20 @@ static int mime_global_unb64(lua_State *L)
276{ 277{
277 UC atom[4]; 278 UC atom[4];
278 size_t isize = 0, asize = 0; 279 size_t isize = 0, asize = 0;
279 const UC *input = luaL_checklstring(L, 1, &isize); 280 const UC *input = (UC *) luaL_checklstring(L, 1, &isize);
280 const UC *last = input + isize; 281 const UC *last = input + isize;
281 luaL_Buffer buffer; 282 luaL_Buffer buffer;
282 luaL_buffinit(L, &buffer); 283 luaL_buffinit(L, &buffer);
283 while (input < last) 284 while (input < last)
284 asize = b64decode(*input++, atom, asize, &buffer); 285 asize = b64decode(*input++, atom, asize, &buffer);
285 input = luaL_optlstring(L, 2, NULL, &isize); 286 input = (UC *) luaL_optlstring(L, 2, NULL, &isize);
286 if (input) { 287 if (input) {
287 last = input + isize; 288 last = input + isize;
288 while (input < last) 289 while (input < last)
289 asize = b64decode(*input++, atom, asize, &buffer); 290 asize = b64decode(*input++, atom, asize, &buffer);
290 } 291 }
291 luaL_pushresult(&buffer); 292 luaL_pushresult(&buffer);
292 lua_pushlstring(L, atom, asize); 293 lua_pushlstring(L, (char *) atom, asize);
293 return 2; 294 return 2;
294} 295}
295 296
@@ -361,7 +362,7 @@ static size_t qpencode(UC c, UC *input, size_t size,
361 case QP_CR: 362 case QP_CR:
362 if (size < 2) return size; 363 if (size < 2) return size;
363 if (input[1] == LF) { 364 if (input[1] == LF) {
364 luaL_addstring(buffer, marker); 365 luaL_addstring(buffer, (char *) marker);
365 return 0; 366 return 0;
366 } else qpquote(input[0], buffer); 367 } else qpquote(input[0], buffer);
367 break; 368 break;
@@ -371,7 +372,7 @@ static size_t qpencode(UC c, UC *input, size_t size,
371 /* if it is the last, quote it and we are done */ 372 /* if it is the last, quote it and we are done */
372 if (input[1] == CR && input[2] == LF) { 373 if (input[1] == CR && input[2] == LF) {
373 qpquote(input[0], buffer); 374 qpquote(input[0], buffer);
374 luaL_addstring(buffer, marker); 375 luaL_addstring(buffer, (char *) marker);
375 return 0; 376 return 0;
376 } else luaL_putchar(buffer, input[0]); 377 } else luaL_putchar(buffer, input[0]);
377 break; 378 break;
@@ -400,7 +401,7 @@ static void qppad(UC *input, size_t size, luaL_Buffer *buffer)
400 if (qpclass[input[i]] == QP_PLAIN) luaL_putchar(buffer, input[i]); 401 if (qpclass[input[i]] == QP_PLAIN) luaL_putchar(buffer, input[i]);
401 else qpquote(input[i], buffer); 402 else qpquote(input[i], buffer);
402 } 403 }
403 luaL_addstring(buffer, EQCRLF); 404 luaL_addstring(buffer, (char *) EQCRLF);
404} 405}
405 406
406/*-------------------------------------------------------------------------*\ 407/*-------------------------------------------------------------------------*\
@@ -416,21 +417,22 @@ static int mime_global_qp(lua_State *L)
416 417
417 size_t asize = 0, isize = 0; 418 size_t asize = 0, isize = 0;
418 UC atom[3]; 419 UC atom[3];
419 const UC *input = lua_isnil(L, 1) ? NULL: luaL_checklstring(L, 1, &isize); 420 const UC *input = (UC *) (lua_isnil(L, 1) ? NULL:
421 luaL_checklstring(L, 1, &isize));
420 const UC *last = input + isize; 422 const UC *last = input + isize;
421 const UC *marker = luaL_optstring(L, 3, CRLF); 423 const UC *marker = (UC *) luaL_optstring(L, 3, (char *) CRLF);
422 luaL_Buffer buffer; 424 luaL_Buffer buffer;
423 luaL_buffinit(L, &buffer); 425 luaL_buffinit(L, &buffer);
424 while (input < last) 426 while (input < last)
425 asize = qpencode(*input++, atom, asize, marker, &buffer); 427 asize = qpencode(*input++, atom, asize, marker, &buffer);
426 input = luaL_optlstring(L, 2, NULL, &isize); 428 input = (UC *) luaL_optlstring(L, 2, NULL, &isize);
427 if (input) { 429 if (input) {
428 last = input + isize; 430 last = input + isize;
429 while (input < last) 431 while (input < last)
430 asize = qpencode(*input++, atom, asize, marker, &buffer); 432 asize = qpencode(*input++, atom, asize, marker, &buffer);
431 } else qppad(atom, asize, &buffer); 433 } else qppad(atom, asize, &buffer);
432 luaL_pushresult(&buffer); 434 luaL_pushresult(&buffer);
433 lua_pushlstring(L, atom, asize); 435 lua_pushlstring(L, (char *) atom, asize);
434 return 2; 436 return 2;
435} 437}
436 438
@@ -454,12 +456,12 @@ static size_t qpdecode(UC c, UC *input, size_t size,
454 /* decode quoted representation */ 456 /* decode quoted representation */
455 c = qpunbase[input[1]]; d = qpunbase[input[2]]; 457 c = qpunbase[input[1]]; d = qpunbase[input[2]];
456 /* if it is an invalid, do not decode */ 458 /* if it is an invalid, do not decode */
457 if (c > 15 || d > 15) luaL_addlstring(buffer, input, 3); 459 if (c > 15 || d > 15) luaL_addlstring(buffer, (char *)input, 3);
458 else luaL_putchar(buffer, (c << 4) + d); 460 else luaL_putchar(buffer, (c << 4) + d);
459 return 0; 461 return 0;
460 case CR: 462 case CR:
461 if (size < 2) return size; 463 if (size < 2) return size;
462 if (input[1] == LF) luaL_addlstring(buffer, input, 2); 464 if (input[1] == LF) luaL_addlstring(buffer, (char *)input, 2);
463 return 0; 465 return 0;
464 default: 466 default:
465 if (input[0] == HT || (input[0] > 31 && input[0] < 127)) 467 if (input[0] == HT || (input[0] > 31 && input[0] < 127))
@@ -484,20 +486,21 @@ static int mime_global_unqp(lua_State *L)
484 486
485 size_t asize = 0, isize = 0; 487 size_t asize = 0, isize = 0;
486 UC atom[3]; 488 UC atom[3];
487 const UC *input = lua_isnil(L, 1) ? NULL: luaL_checklstring(L, 1, &isize); 489 const UC *input = (UC *) (lua_isnil(L, 1) ? NULL:
490 luaL_checklstring(L, 1, &isize));
488 const UC *last = input + isize; 491 const UC *last = input + isize;
489 luaL_Buffer buffer; 492 luaL_Buffer buffer;
490 luaL_buffinit(L, &buffer); 493 luaL_buffinit(L, &buffer);
491 while (input < last) 494 while (input < last)
492 asize = qpdecode(*input++, atom, asize, &buffer); 495 asize = qpdecode(*input++, atom, asize, &buffer);
493 input = luaL_optlstring(L, 2, NULL, &isize); 496 input = (UC *) luaL_optlstring(L, 2, NULL, &isize);
494 if (input) { 497 if (input) {
495 last = input + isize; 498 last = input + isize;
496 while (input < last) 499 while (input < last)
497 asize = qpdecode(*input++, atom, asize, &buffer); 500 asize = qpdecode(*input++, atom, asize, &buffer);
498 } 501 }
499 luaL_pushresult(&buffer); 502 luaL_pushresult(&buffer);
500 lua_pushlstring(L, atom, asize); 503 lua_pushlstring(L, (char *) atom, asize);
501 return 2; 504 return 2;
502} 505}
503 506
@@ -513,7 +516,8 @@ static int mime_global_unqp(lua_State *L)
513static int mime_global_qpfmt(lua_State *L) 516static int mime_global_qpfmt(lua_State *L)
514{ 517{
515 size_t size = 0; 518 size_t size = 0;
516 const UC *input = lua_isnil(L, 1)? NULL: luaL_checklstring(L, 1, &size); 519 const UC *input = (UC *) (lua_isnil(L, 1)? NULL:
520 luaL_checklstring(L, 1, &size));
517 const UC *last = input + size; 521 const UC *last = input + size;
518 int length = (int) luaL_checknumber(L, 2); 522 int length = (int) luaL_checknumber(L, 2);
519 int left = (int) luaL_optnumber(L, 3, length); 523 int left = (int) luaL_optnumber(L, 3, length);
@@ -526,7 +530,7 @@ static int mime_global_qpfmt(lua_State *L)
526 /* if there's no room in this line for the quoted char, 530 /* if there's no room in this line for the quoted char,
527 * output a soft line break now */ 531 * output a soft line break now */
528 if (left <= 3) { 532 if (left <= 3) {
529 luaL_addstring(&buffer, EQCRLF); 533 luaL_addstring(&buffer, (char *) EQCRLF);
530 left = length; 534 left = length;
531 } 535 }
532 break; 536 break;
@@ -539,7 +543,7 @@ static int mime_global_qpfmt(lua_State *L)
539 default: 543 default:
540 /* if in last column, output a soft line break */ 544 /* if in last column, output a soft line break */
541 if (left <= 1) { 545 if (left <= 1) {
542 luaL_addstring(&buffer, EQCRLF); 546 luaL_addstring(&buffer, (char *) EQCRLF);
543 left = length; 547 left = length;
544 } 548 }
545 } 549 }
@@ -547,7 +551,7 @@ static int mime_global_qpfmt(lua_State *L)
547 input++; 551 input++;
548 } 552 }
549 if (!input && left < length) { 553 if (!input && left < length) {
550 luaL_addstring(&buffer, EQCRLF); 554 luaL_addstring(&buffer, (char *) EQCRLF);
551 left = length; 555 left = length;
552 } 556 }
553 luaL_pushresult(&buffer); 557 luaL_pushresult(&buffer);
@@ -571,9 +575,9 @@ static size_t eolconvert(UC c, UC *input, size_t size,
571 /* deal with all characters we can deal */ 575 /* deal with all characters we can deal */
572 if (eolcandidate(input[0])) { 576 if (eolcandidate(input[0])) {
573 if (size < 2) return size; 577 if (size < 2) return size;
574 luaL_addstring(buffer, marker); 578 luaL_addstring(buffer, (char *) marker);
575 if (eolcandidate(input[1])) { 579 if (eolcandidate(input[1])) {
576 if (input[0] == input[1]) luaL_addstring(buffer, marker); 580 if (input[0] == input[1]) luaL_addstring(buffer, (char *) marker);
577 } else luaL_putchar(buffer, input[1]); 581 } else luaL_putchar(buffer, input[1]);
578 return 0; 582 return 0;
579 } else { 583 } else {
@@ -593,22 +597,23 @@ static int mime_global_eol(lua_State *L)
593{ 597{
594 size_t asize = 0, isize = 0; 598 size_t asize = 0, isize = 0;
595 UC atom[2]; 599 UC atom[2];
596 const UC *input = lua_isnil(L, 1)? NULL: luaL_checklstring(L, 1, &isize); 600 const UC *input = (UC *) (lua_isnil(L, 1)? NULL:
601 luaL_checklstring(L, 1, &isize));
597 const UC *last = input + isize; 602 const UC *last = input + isize;
598 const UC *marker = luaL_optstring(L, 3, CRLF); 603 const UC *marker = (UC *) luaL_optstring(L, 3, (char *) CRLF);
599 luaL_Buffer buffer; 604 luaL_Buffer buffer;
600 luaL_buffinit(L, &buffer); 605 luaL_buffinit(L, &buffer);
601 while (input < last) 606 while (input < last)
602 asize = eolconvert(*input++, atom, asize, marker, &buffer); 607 asize = eolconvert(*input++, atom, asize, marker, &buffer);
603 input = luaL_optlstring(L, 2, NULL, &isize); 608 input = (UC *) luaL_optlstring(L, 2, NULL, &isize);
604 if (input) { 609 if (input) {
605 last = input + isize; 610 last = input + isize;
606 while (input < last) 611 while (input < last)
607 asize = eolconvert(*input++, atom, asize, marker, &buffer); 612 asize = eolconvert(*input++, atom, asize, marker, &buffer);
608 /* if there is something in atom, it's one character, and it 613 /* if there is something in atom, it's one character, and it
609 * is a candidate. so we output a new line */ 614 * is a candidate. so we output a new line */
610 } else if (asize > 0) luaL_addstring(&buffer, marker); 615 } else if (asize > 0) luaL_addstring(&buffer, (char *) marker);
611 luaL_pushresult(&buffer); 616 luaL_pushresult(&buffer);
612 lua_pushlstring(L, atom, asize); 617 lua_pushlstring(L, (char *) atom, asize);
613 return 2; 618 return 2;
614} 619}
diff --git a/src/tcp.c b/src/tcp.c
index b4b9fd9..21aa7f5 100644
--- a/src/tcp.c
+++ b/src/tcp.c
@@ -203,8 +203,9 @@ static int meth_accept(lua_State *L)
203 p_tcp server = (p_tcp) aux_checkclass(L, "tcp{server}", 1); 203 p_tcp server = (p_tcp) aux_checkclass(L, "tcp{server}", 1);
204 p_tm tm = &server->tm; 204 p_tm tm = &server->tm;
205 t_sock sock; 205 t_sock sock;
206 const char *err;
206 tm_markstart(tm); 207 tm_markstart(tm);
207 const char *err = inet_tryaccept(&server->sock, tm, &sock); 208 err = inet_tryaccept(&server->sock, tm, &sock);
208 /* if successful, push client socket */ 209 /* if successful, push client socket */
209 if (!err) { 210 if (!err) {
210 p_tcp clnt = lua_newuserdata(L, sizeof(t_tcp)); 211 p_tcp clnt = lua_newuserdata(L, sizeof(t_tcp));