aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-04-10 18:17:05 +0000
committerEric Andersen <andersen@codepoet.org>2001-04-10 18:17:05 +0000
commit6d7fa438a7dc33b20de746e31b5e8078c53c4d05 (patch)
tree97d81954d38c59c9ecd862ba429cf7fe4c399fb6
parentfd402941a7612b5254a65edfedc074d66da3883a (diff)
downloadbusybox-w32-6d7fa438a7dc33b20de746e31b5e8078c53c4d05.tar.gz
busybox-w32-6d7fa438a7dc33b20de746e31b5e8078c53c4d05.tar.bz2
busybox-w32-6d7fa438a7dc33b20de746e31b5e8078c53c4d05.zip
This patch from Laurence Anderson <laurence@zxmail.com> fixes
wget HTTP 1.1 support and addes chunked encoding so bb wget is now fully RFC compliant.
-rw-r--r--Changelog20
-rw-r--r--docs/busybox.pod3
-rw-r--r--networking/wget.c47
-rw-r--r--wget.c47
4 files changed, 73 insertions, 44 deletions
diff --git a/Changelog b/Changelog
index 4adc7746c..296106d49 100644
--- a/Changelog
+++ b/Changelog
@@ -22,6 +22,8 @@
22 * Erik Andersen -- Cleanups for libc5, glibc, and uClibc. 22 * Erik Andersen -- Cleanups for libc5, glibc, and uClibc.
23 * Erik Andersen and Matt Kraai -- Cleanups for the human-readable 23 * Erik Andersen and Matt Kraai -- Cleanups for the human-readable
24 output from ls, du, and df. 24 output from ls, du, and df.
25 * Laurence Anderson <laurence@zxmail.com> -- Fixed wget HTTP 1.1
26 support and added chunked encoding so it is now RFC compliant.
25 * John Beppu -- The busybox.pod documentation is now automagically 27 * John Beppu -- The busybox.pod documentation is now automagically
26 generated from the source code. This makes it _much_ simpler. 28 generated from the source code. This makes it _much_ simpler.
27 Now to update the docs, just update the usage message... 29 Now to update the docs, just update the usage message...
@@ -51,6 +53,7 @@
51 * Vladimir Oleynik -- More cmdedit updates 53 * Vladimir Oleynik -- More cmdedit updates
52 * Vladimir Oleynik -- Fixed `du' applet so it continues running 54 * Vladimir Oleynik -- Fixed `du' applet so it continues running
53 after permission errors. 55 after permission errors.
56 * Vladimir Oleynik -- Reduced stack usage in recursive_action()
54 * Pierre Peiffer <pierre.peiffer@sxb.bsf.alcatel.fr> -- made 57 * Pierre Peiffer <pierre.peiffer@sxb.bsf.alcatel.fr> -- made
55 find_pid_by_name() cope with swapped out processes. 58 find_pid_by_name() cope with swapped out processes.
56 * Jari Ruusu <jari.ruusu@pp.inet.fi> -- updates so that setting 59 * Jari Ruusu <jari.ruusu@pp.inet.fi> -- updates so that setting
@@ -58,13 +61,12 @@
58 * Anthony Towns <aj@azure.humbug.org.au> -- fixed a bug with 61 * Anthony Towns <aj@azure.humbug.org.au> -- fixed a bug with
59 sed address range handling 62 sed address range handling
60 * Dmitry Zakharov <dmit@crp.bank.gov.ua> -- a number of updates 63 * Dmitry Zakharov <dmit@crp.bank.gov.ua> -- a number of updates
61 to wget: support for ftp downloads, basic HTTP basic auth, 64 to wget: support for ftp downloads, basic HTTP basic auth, handling
62 handling of http redirects, protocol changed to 1.0 to stop 65 of http redirects, when attempting to continue an aborted download
63 servers from requesting chunked encoding, when attempting to 66 but server doesn't support restarts then reopen output file in
64 continue an aborted download but server doesn't support restarts 67 write mode, bugfix: when content-length not given, wget didn't
65 then reopen output file in write mode, bugfix: when content-length 68 download anything, if -c is not specified, it no longer default to
66 not given, wget didn't download anything, if -c is not specified, 69 restarting an aborted download.
67 it no longer default to restarting an aborted download.
68 70
69 71
70 -Erik Andersen, not yet released 72 -Erik Andersen, not yet released
@@ -76,8 +78,8 @@
76 * Erik Andersen -- lash environment variable expansion rewritten, 78 * Erik Andersen -- lash environment variable expansion rewritten,
77 with lots of help/fixes/testing from Larry Doolittle. 79 with lots of help/fixes/testing from Larry Doolittle.
78 * Erik Andersen -- Fix use of busybox with dmalloc debugging lib 80 * Erik Andersen -- Fix use of busybox with dmalloc debugging lib
79 * Erik Andersen -- fixed ls behavior for broken or very narrow terminals. 81 * Erik Andersen -- fixed ls behavior for broken or very narrow terminals
80 * Erik Andersen -- stub umount2 and pivot_root if they are not available. 82 * Erik Andersen -- stub umount2 and pivot_root if they are not available
81 * Erik Andersen -- libc5 fixes 83 * Erik Andersen -- libc5 fixes
82 * Erik Andersen -- make init work with devfsd 84 * Erik Andersen -- make init work with devfsd
83 * Erik Andersen -- fixed df for nfs and dos where blksize = 512 85 * Erik Andersen -- fixed df for nfs and dos where blksize = 512
diff --git a/docs/busybox.pod b/docs/busybox.pod
index ca3ce97b5..8e8a5492d 100644
--- a/docs/busybox.pod
+++ b/docs/busybox.pod
@@ -770,6 +770,7 @@ Options:
770 -H prefix output lines with filename where match was found 770 -H prefix output lines with filename where match was found
771 -h suppress the prefixing filename on output 771 -h suppress the prefixing filename on output
772 -i ignore case distinctions 772 -i ignore case distinctions
773 -l list names of files that match
773 -n print line number with output lines 774 -n print line number with output lines
774 -q be quiet. Returns 0 if result was found, 1 otherwise 775 -q be quiet. Returns 0 if result was found, 1 otherwise
775 -v select non-matching lines 776 -v select non-matching lines
@@ -2536,4 +2537,4 @@ Enrique Zanardi <ezanardi@ull.es>
2536 2537
2537=cut 2538=cut
2538 2539
2539# $Id: busybox.pod,v 1.99 2001/04/10 00:00:05 kraai Exp $ 2540# $Id: busybox.pod,v 1.100 2001/04/10 18:17:05 andersen Exp $
diff --git a/networking/wget.c b/networking/wget.c
index 5bec0ddd5..79f7e61cf 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -4,14 +4,6 @@
4 * 4 *
5 * Chip Rosenthal Covad Communications <chip@laserlink.net> 5 * Chip Rosenthal Covad Communications <chip@laserlink.net>
6 * 6 *
7 * Note: According to RFC2616 section 3.6.1, "All HTTP/1.1 applications MUST be
8 * able to receive and decode the "chunked" transfer-coding, and MUST ignore
9 * chunk-extension extensions they do not understand."
10 *
11 * This prevents this particular wget app from completely RFC compliant, and as
12 * such, prevents it from being used as a general purpose web browser... This
13 * is a design decision, since it makes the code smaller.
14 *
15 */ 7 */
16 8
17#include <stdio.h> 9#include <stdio.h>
@@ -63,6 +55,7 @@ static void progressmeter(int flag);
63 55
64/* Globals (can be accessed from signal handlers */ 56/* Globals (can be accessed from signal handlers */
65static off_t filesize = 0; /* content-length of the file */ 57static off_t filesize = 0; /* content-length of the file */
58static int chunked = 0; /* chunked transfer encoding */
66#ifdef BB_FEATURE_WGET_STATUSBAR 59#ifdef BB_FEATURE_WGET_STATUSBAR
67static char *curfile; /* Name of current file being transferred. */ 60static char *curfile; /* Name of current file being transferred. */
68static struct timeval start; /* Time a transfer started. */ 61static struct timeval start; /* Time a transfer started. */
@@ -231,11 +224,11 @@ int wget_main(int argc, char **argv)
231 * Send HTTP request. 224 * Send HTTP request.
232 */ 225 */
233 if (proxy) { 226 if (proxy) {
234 fprintf(sfp, "GET %stp://%s:%d/%s HTTP/1.0\r\n", 227 fprintf(sfp, "GET %stp://%s:%d/%s HTTP/1.1\r\n",
235 target.is_ftp ? "f" : "ht", target.host, 228 target.is_ftp ? "f" : "ht", target.host,
236 target.port, target.path); 229 target.port, target.path);
237 } else { 230 } else {
238 fprintf(sfp, "GET /%s HTTP/1.0\r\n", target.path); 231 fprintf(sfp, "GET /%s HTTP/1.1\r\n", target.path);
239 } 232 }
240 233
241 fprintf(sfp, "Host: %s\r\nUser-Agent: Wget\r\n", target.host); 234 fprintf(sfp, "Host: %s\r\nUser-Agent: Wget\r\n", target.host);
@@ -258,7 +251,7 @@ int wget_main(int argc, char **argv)
258 /* 251 /*
259 * Retrieve HTTP response line and check for "200" status code. 252 * Retrieve HTTP response line and check for "200" status code.
260 */ 253 */
261 if (fgets(buf, sizeof(buf), sfp) == NULL) 254read_response: if (fgets(buf, sizeof(buf), sfp) == NULL)
262 close_delete_and_die("no response from server"); 255 close_delete_and_die("no response from server");
263 256
264 for (s = buf ; *s != '\0' && !isspace(*s) ; ++s) 257 for (s = buf ; *s != '\0' && !isspace(*s) ; ++s)
@@ -267,6 +260,9 @@ int wget_main(int argc, char **argv)
267 ; 260 ;
268 switch (status = atoi(s)) { 261 switch (status = atoi(s)) {
269 case 0: 262 case 0:
263 case 100:
264 while (gethdr(buf, sizeof(buf), sfp, &n) != NULL);
265 goto read_response;
270 case 200: 266 case 200:
271 if (do_continue && output != stdout) 267 if (do_continue && output != stdout)
272 output = freopen(fname_out, "w", output); 268 output = freopen(fname_out, "w", output);
@@ -295,9 +291,13 @@ int wget_main(int argc, char **argv)
295 got_clen = 1; 291 got_clen = 1;
296 continue; 292 continue;
297 } 293 }
298 if (strcasecmp(buf, "transfer-encoding") == 0) 294 if (strcasecmp(buf, "transfer-encoding") == 0) {
295 if (strcasecmp(s, "chunked") == 0) {
296 chunked = got_clen = 1;
297 } else {
299 close_delete_and_die("server wants to do %s transfer encoding", s); 298 close_delete_and_die("server wants to do %s transfer encoding", s);
300 299 }
300 }
301 if (strcasecmp(buf, "location") == 0) { 301 if (strcasecmp(buf, "location") == 0) {
302 if (s[0] == '/') 302 if (s[0] == '/')
303 target.path = xstrdup(s+1); 303 target.path = xstrdup(s+1);
@@ -386,12 +386,17 @@ int wget_main(int argc, char **argv)
386 /* 386 /*
387 * Retrieve file 387 * Retrieve file
388 */ 388 */
389 if (chunked) {
390 fgets(buf, sizeof(buf), dfp);
391 filesize = strtol(buf, (char **) NULL, 16);
392 }
393 do {
389#ifdef BB_FEATURE_WGET_STATUSBAR 394#ifdef BB_FEATURE_WGET_STATUSBAR
390 statbytes=0; 395 statbytes=0;
391 if (quiet_flag==FALSE) 396 if (quiet_flag==FALSE)
392 progressmeter(-1); 397 progressmeter(-1);
393#endif 398#endif
394 while ((filesize > 0 || !got_clen) && (n = fread(buf, 1, sizeof(buf), dfp)) > 0) { 399 while ((filesize > 0 || !got_clen) && (n = fread(buf, 1, chunked ? (filesize > sizeof(buf) ? sizeof(buf) : filesize) : sizeof(buf), dfp)) > 0) {
395 fwrite(buf, 1, n, output); 400 fwrite(buf, 1, n, output);
396#ifdef BB_FEATURE_WGET_STATUSBAR 401#ifdef BB_FEATURE_WGET_STATUSBAR
397 statbytes+=n; 402 statbytes+=n;
@@ -402,8 +407,16 @@ int wget_main(int argc, char **argv)
402 filesize -= n; 407 filesize -= n;
403 } 408 }
404 409
410 if (chunked) {
411 fgets(buf, sizeof(buf), dfp); /* This is a newline */
412 fgets(buf, sizeof(buf), dfp);
413 filesize = strtol(buf, (char **) NULL, 16);
414 if (filesize==0) chunked = 0; /* all done! */
415 }
416
405 if (n == 0 && ferror(dfp)) 417 if (n == 0 && ferror(dfp))
406 perror_msg_and_die("network read error"); 418 perror_msg_and_die("network read error");
419 } while (chunked);
407 420
408 if (!proxy && target.is_ftp) { 421 if (!proxy && target.is_ftp) {
409 fclose(dfp); 422 fclose(dfp);
@@ -411,7 +424,7 @@ int wget_main(int argc, char **argv)
411 error_msg_and_die("ftp error: %s", buf+4); 424 error_msg_and_die("ftp error: %s", buf+4);
412 ftpcmd("QUIT", NULL, sfp, buf); 425 ftpcmd("QUIT", NULL, sfp, buf);
413 } 426 }
414 427 printf("\n");
415 exit(EXIT_SUCCESS); 428 exit(EXIT_SUCCESS);
416} 429}
417 430
@@ -608,7 +621,7 @@ progressmeter(int flag)
608 621
609 (void) gettimeofday(&now, (struct timezone *) 0); 622 (void) gettimeofday(&now, (struct timezone *) 0);
610 cursize = statbytes; 623 cursize = statbytes;
611 if (filesize != 0) { 624 if (filesize != 0 && !chunked) {
612 ratio = 100.0 * cursize / filesize; 625 ratio = 100.0 * cursize / filesize;
613 ratio = MAX(ratio, 0); 626 ratio = MAX(ratio, 0);
614 ratio = MIN(ratio, 100); 627 ratio = MIN(ratio, 100);
@@ -719,7 +732,7 @@ progressmeter(int flag)
719 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 732 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
720 * SUCH DAMAGE. 733 * SUCH DAMAGE.
721 * 734 *
722 * $Id: wget.c,v 1.31 2001/04/05 21:45:53 andersen Exp $ 735 * $Id: wget.c,v 1.32 2001/04/10 18:17:05 andersen Exp $
723 */ 736 */
724 737
725 738
diff --git a/wget.c b/wget.c
index 5bec0ddd5..79f7e61cf 100644
--- a/wget.c
+++ b/wget.c
@@ -4,14 +4,6 @@
4 * 4 *
5 * Chip Rosenthal Covad Communications <chip@laserlink.net> 5 * Chip Rosenthal Covad Communications <chip@laserlink.net>
6 * 6 *
7 * Note: According to RFC2616 section 3.6.1, "All HTTP/1.1 applications MUST be
8 * able to receive and decode the "chunked" transfer-coding, and MUST ignore
9 * chunk-extension extensions they do not understand."
10 *
11 * This prevents this particular wget app from completely RFC compliant, and as
12 * such, prevents it from being used as a general purpose web browser... This
13 * is a design decision, since it makes the code smaller.
14 *
15 */ 7 */
16 8
17#include <stdio.h> 9#include <stdio.h>
@@ -63,6 +55,7 @@ static void progressmeter(int flag);
63 55
64/* Globals (can be accessed from signal handlers */ 56/* Globals (can be accessed from signal handlers */
65static off_t filesize = 0; /* content-length of the file */ 57static off_t filesize = 0; /* content-length of the file */
58static int chunked = 0; /* chunked transfer encoding */
66#ifdef BB_FEATURE_WGET_STATUSBAR 59#ifdef BB_FEATURE_WGET_STATUSBAR
67static char *curfile; /* Name of current file being transferred. */ 60static char *curfile; /* Name of current file being transferred. */
68static struct timeval start; /* Time a transfer started. */ 61static struct timeval start; /* Time a transfer started. */
@@ -231,11 +224,11 @@ int wget_main(int argc, char **argv)
231 * Send HTTP request. 224 * Send HTTP request.
232 */ 225 */
233 if (proxy) { 226 if (proxy) {
234 fprintf(sfp, "GET %stp://%s:%d/%s HTTP/1.0\r\n", 227 fprintf(sfp, "GET %stp://%s:%d/%s HTTP/1.1\r\n",
235 target.is_ftp ? "f" : "ht", target.host, 228 target.is_ftp ? "f" : "ht", target.host,
236 target.port, target.path); 229 target.port, target.path);
237 } else { 230 } else {
238 fprintf(sfp, "GET /%s HTTP/1.0\r\n", target.path); 231 fprintf(sfp, "GET /%s HTTP/1.1\r\n", target.path);
239 } 232 }
240 233
241 fprintf(sfp, "Host: %s\r\nUser-Agent: Wget\r\n", target.host); 234 fprintf(sfp, "Host: %s\r\nUser-Agent: Wget\r\n", target.host);
@@ -258,7 +251,7 @@ int wget_main(int argc, char **argv)
258 /* 251 /*
259 * Retrieve HTTP response line and check for "200" status code. 252 * Retrieve HTTP response line and check for "200" status code.
260 */ 253 */
261 if (fgets(buf, sizeof(buf), sfp) == NULL) 254read_response: if (fgets(buf, sizeof(buf), sfp) == NULL)
262 close_delete_and_die("no response from server"); 255 close_delete_and_die("no response from server");
263 256
264 for (s = buf ; *s != '\0' && !isspace(*s) ; ++s) 257 for (s = buf ; *s != '\0' && !isspace(*s) ; ++s)
@@ -267,6 +260,9 @@ int wget_main(int argc, char **argv)
267 ; 260 ;
268 switch (status = atoi(s)) { 261 switch (status = atoi(s)) {
269 case 0: 262 case 0:
263 case 100:
264 while (gethdr(buf, sizeof(buf), sfp, &n) != NULL);
265 goto read_response;
270 case 200: 266 case 200:
271 if (do_continue && output != stdout) 267 if (do_continue && output != stdout)
272 output = freopen(fname_out, "w", output); 268 output = freopen(fname_out, "w", output);
@@ -295,9 +291,13 @@ int wget_main(int argc, char **argv)
295 got_clen = 1; 291 got_clen = 1;
296 continue; 292 continue;
297 } 293 }
298 if (strcasecmp(buf, "transfer-encoding") == 0) 294 if (strcasecmp(buf, "transfer-encoding") == 0) {
295 if (strcasecmp(s, "chunked") == 0) {
296 chunked = got_clen = 1;
297 } else {
299 close_delete_and_die("server wants to do %s transfer encoding", s); 298 close_delete_and_die("server wants to do %s transfer encoding", s);
300 299 }
300 }
301 if (strcasecmp(buf, "location") == 0) { 301 if (strcasecmp(buf, "location") == 0) {
302 if (s[0] == '/') 302 if (s[0] == '/')
303 target.path = xstrdup(s+1); 303 target.path = xstrdup(s+1);
@@ -386,12 +386,17 @@ int wget_main(int argc, char **argv)
386 /* 386 /*
387 * Retrieve file 387 * Retrieve file
388 */ 388 */
389 if (chunked) {
390 fgets(buf, sizeof(buf), dfp);
391 filesize = strtol(buf, (char **) NULL, 16);
392 }
393 do {
389#ifdef BB_FEATURE_WGET_STATUSBAR 394#ifdef BB_FEATURE_WGET_STATUSBAR
390 statbytes=0; 395 statbytes=0;
391 if (quiet_flag==FALSE) 396 if (quiet_flag==FALSE)
392 progressmeter(-1); 397 progressmeter(-1);
393#endif 398#endif
394 while ((filesize > 0 || !got_clen) && (n = fread(buf, 1, sizeof(buf), dfp)) > 0) { 399 while ((filesize > 0 || !got_clen) && (n = fread(buf, 1, chunked ? (filesize > sizeof(buf) ? sizeof(buf) : filesize) : sizeof(buf), dfp)) > 0) {
395 fwrite(buf, 1, n, output); 400 fwrite(buf, 1, n, output);
396#ifdef BB_FEATURE_WGET_STATUSBAR 401#ifdef BB_FEATURE_WGET_STATUSBAR
397 statbytes+=n; 402 statbytes+=n;
@@ -402,8 +407,16 @@ int wget_main(int argc, char **argv)
402 filesize -= n; 407 filesize -= n;
403 } 408 }
404 409
410 if (chunked) {
411 fgets(buf, sizeof(buf), dfp); /* This is a newline */
412 fgets(buf, sizeof(buf), dfp);
413 filesize = strtol(buf, (char **) NULL, 16);
414 if (filesize==0) chunked = 0; /* all done! */
415 }
416
405 if (n == 0 && ferror(dfp)) 417 if (n == 0 && ferror(dfp))
406 perror_msg_and_die("network read error"); 418 perror_msg_and_die("network read error");
419 } while (chunked);
407 420
408 if (!proxy && target.is_ftp) { 421 if (!proxy && target.is_ftp) {
409 fclose(dfp); 422 fclose(dfp);
@@ -411,7 +424,7 @@ int wget_main(int argc, char **argv)
411 error_msg_and_die("ftp error: %s", buf+4); 424 error_msg_and_die("ftp error: %s", buf+4);
412 ftpcmd("QUIT", NULL, sfp, buf); 425 ftpcmd("QUIT", NULL, sfp, buf);
413 } 426 }
414 427 printf("\n");
415 exit(EXIT_SUCCESS); 428 exit(EXIT_SUCCESS);
416} 429}
417 430
@@ -608,7 +621,7 @@ progressmeter(int flag)
608 621
609 (void) gettimeofday(&now, (struct timezone *) 0); 622 (void) gettimeofday(&now, (struct timezone *) 0);
610 cursize = statbytes; 623 cursize = statbytes;
611 if (filesize != 0) { 624 if (filesize != 0 && !chunked) {
612 ratio = 100.0 * cursize / filesize; 625 ratio = 100.0 * cursize / filesize;
613 ratio = MAX(ratio, 0); 626 ratio = MAX(ratio, 0);
614 ratio = MIN(ratio, 100); 627 ratio = MIN(ratio, 100);
@@ -719,7 +732,7 @@ progressmeter(int flag)
719 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 732 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
720 * SUCH DAMAGE. 733 * SUCH DAMAGE.
721 * 734 *
722 * $Id: wget.c,v 1.31 2001/04/05 21:45:53 andersen Exp $ 735 * $Id: wget.c,v 1.32 2001/04/10 18:17:05 andersen Exp $
723 */ 736 */
724 737
725 738