summaryrefslogtreecommitdiff
path: root/networking/wget.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-10-07 14:28:28 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-10-07 14:28:28 +0000
commita655152b0045a9ac39718dcbf60b314f32c43413 (patch)
tree2906125add0931ee380fac5e2c1b890679e642e5 /networking/wget.c
parentbede7d0ebea13a0edc1c116ce2036028b487485a (diff)
downloadbusybox-w32-a655152b0045a9ac39718dcbf60b314f32c43413.tar.gz
busybox-w32-a655152b0045a9ac39718dcbf60b314f32c43413.tar.bz2
busybox-w32-a655152b0045a9ac39718dcbf60b314f32c43413.zip
wget: fix download of URLs like:
http://busybox.net?var=a/b http://busybox.net?login=john@doe http://busybox.net#test/test
Diffstat (limited to 'networking/wget.c')
-rw-r--r--networking/wget.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/networking/wget.c b/networking/wget.c
index 0054a9876..3f36e4861 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -351,6 +351,7 @@ read_response:
351 } 351 }
352 if (strcasecmp(buf, "location") == 0) { 352 if (strcasecmp(buf, "location") == 0) {
353 if (s[0] == '/') 353 if (s[0] == '/')
354 // FIXME: this is dirty
354 target.path = xstrdup(s+1); 355 target.path = xstrdup(s+1);
355 else { 356 else {
356 parse_url(xstrdup(s), &target); 357 parse_url(xstrdup(s), &target);
@@ -500,25 +501,48 @@ read_response:
500 501
501static void parse_url(char *url, struct host_info *h) 502static void parse_url(char *url, struct host_info *h)
502{ 503{
503 char *cp, *sp, *up, *pp; 504 char *p, *cp, *sp, *up, *pp;
504 505
505 if (strncmp(url, "http://", 7) == 0) { 506 if (strncmp(url, "http://", 7) == 0) {
506 h->port = bb_lookup_port("http", "tcp", 80); 507 h->port = bb_lookup_port("http", "tcp", 80);
507 h->host = url + 7; 508 h->host = url + 7;
508 h->is_ftp = 0; 509 h->is_ftp = 0;
509 } else if (strncmp(url, "ftp://", 6) == 0) { 510 } else if (strncmp(url, "ftp://", 6) == 0) {
510 h->port = bb_lookup_port("ftp", "tfp", 21); 511 h->port = bb_lookup_port("ftp", "tcp", 21);
511 h->host = url + 6; 512 h->host = url + 6;
512 h->is_ftp = 1; 513 h->is_ftp = 1;
513 } else 514 } else
514 bb_error_msg_and_die("not an http or ftp url: %s", url); 515 bb_error_msg_and_die("not an http or ftp url: %s", url);
515 516
517 // FYI:
518 // "Real" wget 'http://busybox.net?var=a/b' sends this request:
519 // 'GET /?var=a/b HTTP 1.0'
520 // and saves 'index.html?var=a%2Fb'
521 // wget 'http://busybox.net?login=john@doe':
522 // request: 'GET /?login=john@doe HTTP/1.0'
523 // saves: 'index.html?login=john@doe' (we save ?login=john@doe)
524 // wget 'http://busybox.net#test/test':
525 // request: 'GET / HTTP/1.0'
526 // saves: 'index.html' (we save 'test')
527 //
528 // We also don't add unique .N suffix if file exists...
516 sp = strchr(h->host, '/'); 529 sp = strchr(h->host, '/');
517 if (sp) { 530 p = strchr(h->host, '?'); if (!sp || (p && sp > p)) sp = p;
531 p = strchr(h->host, '#'); if (!sp || (p && sp > p)) sp = p;
532 if (!sp) {
533 h->path = "";
534 } else if (*sp == '/') {
518 *sp++ = '\0'; 535 *sp++ = '\0';
519 h->path = sp; 536 h->path = sp;
520 } else 537 } else { // '#' or '?'
521 h->path = xstrdup(""); 538 // http://busybox.net?login=john@doe is a valid URL
539 // memmove converts to:
540 // http:/busybox.nett?login=john@doe...
541 memmove(h->host-1, h->host, sp - h->host);
542 h->host--;
543 sp[-1] = '\0';
544 h->path = sp;
545 }
522 546
523 up = strrchr(h->host, '@'); 547 up = strrchr(h->host, '@');
524 if (up != NULL) { 548 if (up != NULL) {
@@ -535,7 +559,7 @@ static void parse_url(char *url, struct host_info *h)
535 char *ep; 559 char *ep;
536 560
537 ep = h->host + 1; 561 ep = h->host + 1;
538 while (*ep == ':' || isxdigit (*ep)) 562 while (*ep == ':' || isxdigit(*ep))
539 ep++; 563 ep++;
540 if (*ep == ']') { 564 if (*ep == ']') {
541 h->host++; 565 h->host++;