aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-09-24 13:51:54 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-09-24 13:51:54 +0000
commit06783a51409e4245a54c751e426f1c5eaf117e39 (patch)
tree3c7ed3938e68bc0313f18d1ba5f12be0fe311a70
parent512a545f0dfd0717694f8694398c1a811e70b607 (diff)
downloadbusybox-w32-06783a51409e4245a54c751e426f1c5eaf117e39.tar.gz
busybox-w32-06783a51409e4245a54c751e426f1c5eaf117e39.tar.bz2
busybox-w32-06783a51409e4245a54c751e426f1c5eaf117e39.zip
wget: allow dots in header field names.
wget: code shrink function old new delta gethdr 211 190 -21 wget_main 2609 2557 -52 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-73) Total: -73 bytes
-rw-r--r--networking/wget.c72
1 files changed, 36 insertions, 36 deletions
diff --git a/networking/wget.c b/networking/wget.c
index 8af7a3399..39d63f116 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -25,7 +25,7 @@ struct host_info {
25 25
26static void parse_url(char *url, struct host_info *h); 26static void parse_url(char *url, struct host_info *h);
27static FILE *open_socket(len_and_sockaddr *lsa); 27static FILE *open_socket(len_and_sockaddr *lsa);
28static char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc); 28static char *gethdr(char *buf, size_t bufsiz, FILE *fp /*,int *istrunc*/ );
29static int ftpcmd(const char *s1, const char *s2, FILE *fp, char *buf); 29static int ftpcmd(const char *s1, const char *s2, FILE *fp, char *buf);
30 30
31/* Globals (can be accessed from signal handlers */ 31/* Globals (can be accessed from signal handlers */
@@ -94,7 +94,7 @@ int wget_main(int argc, char **argv)
94 char buf[512]; 94 char buf[512];
95 struct host_info server, target; 95 struct host_info server, target;
96 len_and_sockaddr *lsa; 96 len_and_sockaddr *lsa;
97 int n, status; 97 int status;
98 int port; 98 int port;
99 int try = 5; 99 int try = 5;
100 unsigned opt; 100 unsigned opt;
@@ -301,7 +301,7 @@ int wget_main(int argc, char **argv)
301 switch (status) { 301 switch (status) {
302 case 0: 302 case 0:
303 case 100: 303 case 100:
304 while (gethdr(buf, sizeof(buf), sfp, &n) != NULL) 304 while (gethdr(buf, sizeof(buf), sfp /*, &n*/) != NULL)
305 /* eat all remaining headers */; 305 /* eat all remaining headers */;
306 goto read_response; 306 goto read_response;
307 case 200: 307 case 200:
@@ -324,7 +324,7 @@ int wget_main(int argc, char **argv)
324 /* 324 /*
325 * Retrieve HTTP headers. 325 * Retrieve HTTP headers.
326 */ 326 */
327 while ((str = gethdr(buf, sizeof(buf), sfp, &n)) != NULL) { 327 while ((str = gethdr(buf, sizeof(buf), sfp /*, &n*/)) != NULL) {
328 /* gethdr did already convert the "FOO:" string to lowercase */ 328 /* gethdr did already convert the "FOO:" string to lowercase */
329 smalluint key = index_in_strings(keywords, *&buf) + 1; 329 smalluint key = index_in_strings(keywords, *&buf) + 1;
330 if (key == KEY_content_length) { 330 if (key == KEY_content_length) {
@@ -457,39 +457,40 @@ int wget_main(int argc, char **argv)
457 if (!(opt & WGET_OPT_QUIET)) 457 if (!(opt & WGET_OPT_QUIET))
458 progressmeter(-1); 458 progressmeter(-1);
459 459
460 do { 460 /* Loops only if chunked */
461 while (1) {
461 while (content_len > 0 || !got_clen) { 462 while (content_len > 0 || !got_clen) {
463 int n;
462 unsigned rdsz = sizeof(buf); 464 unsigned rdsz = sizeof(buf);
465
463 if (content_len < sizeof(buf) && (chunked || got_clen)) 466 if (content_len < sizeof(buf) && (chunked || got_clen))
464 rdsz = (unsigned)content_len; 467 rdsz = (unsigned)content_len;
465 n = safe_fread(buf, rdsz, dfp); 468 n = safe_fread(buf, rdsz, dfp);
466 if (n <= 0) 469 if (n <= 0) {
470 if (ferror(dfp)) {
471 /* perror will not work: ferror doesn't set errno */
472 bb_error_msg_and_die(bb_msg_read_error);
473 }
467 break; 474 break;
468 if (full_write(output_fd, buf, n) != n) {
469 bb_perror_msg_and_die(bb_msg_write_error);
470 } 475 }
476 xwrite(output_fd, buf, n);
471#if ENABLE_FEATURE_WGET_STATUSBAR 477#if ENABLE_FEATURE_WGET_STATUSBAR
472 transferred += n; 478 transferred += n;
473#endif 479#endif
474 if (got_clen) { 480 if (got_clen)
475 content_len -= n; 481 content_len -= n;
476 }
477 } 482 }
478 483
479 if (chunked) { 484 if (!chunked)
480 safe_fgets(buf, sizeof(buf), dfp); /* This is a newline */ 485 break;
481 safe_fgets(buf, sizeof(buf), dfp);
482 content_len = STRTOOFF(buf, NULL, 16);
483 /* FIXME: error check? */
484 if (content_len == 0) {
485 chunked = 0; /* all done! */
486 }
487 }
488 486
489 if (n == 0 && ferror(dfp)) { 487 safe_fgets(buf, sizeof(buf), dfp); /* This is a newline */
490 bb_perror_msg_and_die(bb_msg_read_error); 488 safe_fgets(buf, sizeof(buf), dfp);
491 } 489 content_len = STRTOOFF(buf, NULL, 16);
492 } while (chunked); 490 /* FIXME: error check? */
491 if (content_len == 0)
492 break; /* all done! */
493 }
493 494
494 if (!(opt & WGET_OPT_QUIET)) 495 if (!(opt & WGET_OPT_QUIET))
495 progressmeter(1); 496 progressmeter(1);
@@ -580,12 +581,12 @@ static FILE *open_socket(len_and_sockaddr *lsa)
580} 581}
581 582
582 583
583static char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc) 584static char *gethdr(char *buf, size_t bufsiz, FILE *fp /*, int *istrunc*/)
584{ 585{
585 char *s, *hdrval; 586 char *s, *hdrval;
586 int c; 587 int c;
587 588
588 *istrunc = 0; 589 /* *istrunc = 0; */
589 590
590 /* retrieve header line */ 591 /* retrieve header line */
591 if (fgets(buf, bufsiz, fp) == NULL) 592 if (fgets(buf, bufsiz, fp) == NULL)
@@ -593,12 +594,12 @@ static char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc)
593 594
594 /* see if we are at the end of the headers */ 595 /* see if we are at the end of the headers */
595 for (s = buf; *s == '\r'; ++s) 596 for (s = buf; *s == '\r'; ++s)
596 ; 597 continue;
597 if (s[0] == '\n') 598 if (*s == '\n')
598 return NULL; 599 return NULL;
599 600
600 /* convert the header name to lower case */ 601 /* convert the header name to lower case */
601 for (s = buf; isalnum(*s) || *s == '-'; ++s) 602 for (s = buf; isalnum(*s) || *s == '-' || *s == '.'; ++s)
602 *s = tolower(*s); 603 *s = tolower(*s);
603 604
604 /* verify we are at the end of the header name */ 605 /* verify we are at the end of the header name */
@@ -606,24 +607,23 @@ static char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc)
606 bb_error_msg_and_die("bad header line: %s", buf); 607 bb_error_msg_and_die("bad header line: %s", buf);
607 608
608 /* locate the start of the header value */ 609 /* locate the start of the header value */
609 for (*s++ = '\0'; *s == ' ' || *s == '\t'; ++s) 610 *s++ = '\0';
610 ; 611 hdrval = skip_whitespace(s);
611 hdrval = s;
612 612
613 /* locate the end of header */ 613 /* locate the end of header */
614 while (*s != '\0' && *s != '\r' && *s != '\n') 614 while (*s && *s != '\r' && *s != '\n')
615 ++s; 615 ++s;
616 616
617 /* end of header found */ 617 /* end of header found */
618 if (*s != '\0') { 618 if (*s) {
619 *s = '\0'; 619 *s = '\0';
620 return hdrval; 620 return hdrval;
621 } 621 }
622 622
623 /* Rats! The buffer isn't big enough to hold the entire header value. */ 623 /* Rats! The buffer isn't big enough to hold the entire header value. */
624 while (c = getc(fp), c != EOF && c != '\n') 624 while (c = getc(fp), c != EOF && c != '\n')
625 ; 625 continue;
626 *istrunc = 1; 626 /* *istrunc = 1; */
627 return hdrval; 627 return hdrval;
628} 628}
629 629