Changeset 5895
- Timestamp:
- 03/21/10 03:27:29 (3 years ago)
- Location:
- luci/trunk/contrib/package/uhttpd/src
- Files:
-
- 2 modified
-
uhttpd-cgi.c (modified) (15 diffs)
-
uhttpd-file.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
luci/trunk/contrib/package/uhttpd/src/uhttpd-cgi.c
r5894 r5895 119 119 } 120 120 121 static voiduh_cgi_error_500(struct client *cl, struct http_request *req, const char *message)121 static int uh_cgi_error_500(struct client *cl, struct http_request *req, const char *message) 122 122 { 123 uh_http_sendf(cl, NULL,123 if( uh_http_sendf(cl, NULL, 124 124 "HTTP/%.1f 500 Internal Server Error\r\n" 125 125 "Content-Type: text/plain\r\n%s\r\n", … … 127 127 (req->version > 1.0) 128 128 ? "Transfer-Encoding: chunked\r\n" : "" 129 ); 130 131 uh_http_send(cl, req, message, -1); 129 ) >= 0 130 ) { 131 return uh_http_send(cl, req, message, -1); 132 } 133 134 return -1; 132 135 } 133 136 … … 348 351 349 352 memset(hdr, 0, sizeof(hdr)); 353 354 #define ensure(x) \ 355 do { if( x < 0 ) goto out; } while(0) 350 356 351 357 /* I/O loop, watch our pipe ends and dispatch child reads/writes from/to socket */ … … 391 397 392 398 /* there is no more post data, close pipe to child's stdin */ 393 else 399 else if( content_length > -1 ) 394 400 { 395 401 close(wfd[1]); … … 424 430 { 425 431 /* write status */ 426 uh_http_sendf(cl, NULL, "HTTP/%.1f %03d %s\r\n", 427 req->version, res->statuscode, res->statusmsg); 432 ensure(uh_http_sendf(cl, NULL, 433 "HTTP/%.1f %03d %s\r\n", 434 req->version, res->statuscode, 435 res->statusmsg)); 428 436 429 437 /* add Content-Type if no Location or Content-Type */ … … 431 439 !uh_cgi_header_lookup(res, "Content-Type") 432 440 ) { 433 uh_http_send(cl, NULL,434 "Content-Type: text/plain\r\n", -1) ;441 ensure(uh_http_send(cl, NULL, 442 "Content-Type: text/plain\r\n", -1)); 435 443 } 436 444 … … 439 447 !uh_cgi_header_lookup(res, "Transfer-Encoding") 440 448 ) { 441 uh_http_send(cl, NULL,442 "Transfer-Encoding: chunked\r\n", -1) ;449 ensure(uh_http_send(cl, NULL, 450 "Transfer-Encoding: chunked\r\n", -1)); 443 451 } 444 452 … … 446 454 foreach_header(i, res->headers) 447 455 { 448 uh_http_sendf(cl, NULL, "%s: %s\r\n",449 res->headers[i], res->headers[i+1]) ;456 ensure(uh_http_sendf(cl, NULL, "%s: %s\r\n", 457 res->headers[i], res->headers[i+1])); 450 458 } 451 459 452 460 /* terminate header */ 453 uh_http_send(cl, NULL, "\r\n", -1);461 ensure(uh_http_send(cl, NULL, "\r\n", -1)); 454 462 455 463 /* push out remaining head buffer */ 456 464 if( hdroff < hdrlen ) 457 uh_http_send(cl, req, &hdr[hdroff], hdrlen - hdroff);465 ensure(uh_http_send(cl, req, &hdr[hdroff], hdrlen - hdroff)); 458 466 } 459 467 … … 461 469 else if( hdrlen >= sizeof(hdr) ) 462 470 { 463 uh_cgi_error_500(cl, req,464 "The CGI program generated an invalid response:\n\n") ;465 466 uh_http_send(cl, req, hdr, hdrlen);471 ensure(uh_cgi_error_500(cl, req, 472 "The CGI program generated an invalid response:\n\n")); 473 474 ensure(uh_http_send(cl, req, hdr, hdrlen)); 467 475 } 468 476 … … 475 483 /* push out remaining read buffer */ 476 484 if( bufoff < buflen ) 477 uh_http_send(cl, req, &buf[bufoff], buflen - bufoff);485 ensure(uh_http_send(cl, req, &buf[bufoff], buflen - bufoff)); 478 486 479 487 header_sent = 1; … … 483 491 484 492 /* headers complete, pass through buffer to socket */ 485 uh_http_send(cl, req, buf, buflen);493 ensure(uh_http_send(cl, req, buf, buflen)); 486 494 } 487 495 … … 503 511 */ 504 512 505 uh_http_sendf(cl, NULL,513 ensure(uh_http_sendf(cl, NULL, 506 514 "HTTP/%.1f 200 OK\r\n" 507 515 "Content-Type: text/plain\r\n" … … 509 517 req->version, (req->version > 1.0) 510 518 ? "Transfer-Encoding: chunked\r\n" : "" 511 ) ;512 513 uh_http_send(cl, req, hdr, hdrlen);519 )); 520 521 ensure(uh_http_send(cl, req, hdr, hdrlen)); 514 522 } 515 523 516 524 /* send final chunk if we're in chunked transfer mode */ 517 uh_http_send(cl, req, "", 0);525 ensure(uh_http_send(cl, req, "", 0)); 518 526 break; 519 527 } … … 524 532 else 525 533 { 526 uh_http_sendhf(cl, 504, "Gateway Timeout",527 "The CGI script took too long to produce a response") ;534 ensure(uh_http_sendhf(cl, 504, "Gateway Timeout", 535 "The CGI script took too long to produce a response")); 528 536 529 537 break; … … 531 539 } 532 540 541 out: 533 542 close(rfd[0]); 534 543 close(wfd[1]); -
luci/trunk/contrib/package/uhttpd/src/uhttpd-file.c
r5892 r5895 350 350 while( (rlen = read(fd, buf, sizeof(buf))) > 0 ) 351 351 { 352 uh_http_send(cl, req, buf, rlen); 352 if( uh_http_send(cl, req, buf, rlen) < 0 ) 353 break; 353 354 } 354 355
