svn commit: trunk/busybox/networking

vda at busybox.net vda at busybox.net
Sat Oct 7 14:28:29 UTC 2006


Author: vda
Date: 2006-10-07 07:28:28 -0700 (Sat, 07 Oct 2006)
New Revision: 16336

Log:
wget: fix download of URLs like:
http://busybox.net?var=a/b
http://busybox.net?login=john@doe
http://busybox.net#test/test


Modified:
   trunk/busybox/networking/wget.c


Changeset:
Modified: trunk/busybox/networking/wget.c
===================================================================
--- trunk/busybox/networking/wget.c	2006-10-07 06:54:35 UTC (rev 16335)
+++ trunk/busybox/networking/wget.c	2006-10-07 14:28:28 UTC (rev 16336)
@@ -351,6 +351,7 @@
 				}
 				if (strcasecmp(buf, "location") == 0) {
 					if (s[0] == '/')
+						// FIXME: this is dirty
 						target.path = xstrdup(s+1);
 					else {
 						parse_url(xstrdup(s), &target);
@@ -500,25 +501,48 @@
 
 static void parse_url(char *url, struct host_info *h)
 {
-	char *cp, *sp, *up, *pp;
+	char *p, *cp, *sp, *up, *pp;
 
 	if (strncmp(url, "http://", 7) == 0) {
 		h->port = bb_lookup_port("http", "tcp", 80);
 		h->host = url + 7;
 		h->is_ftp = 0;
 	} else if (strncmp(url, "ftp://", 6) == 0) {
-		h->port = bb_lookup_port("ftp", "tfp", 21);
+		h->port = bb_lookup_port("ftp", "tcp", 21);
 		h->host = url + 6;
 		h->is_ftp = 1;
 	} else
 		bb_error_msg_and_die("not an http or ftp url: %s", url);
 
+	// FYI:
+	// "Real" wget 'http://busybox.net?var=a/b' sends this request:
+	//   'GET /?var=a/b HTTP 1.0'
+	//   and saves 'index.html?var=a%2Fb'
+	// wget 'http://busybox.net?login=john@doe':
+	//   request: 'GET /?login=john at doe HTTP/1.0'
+	//   saves: 'index.html?login=john at doe' (we save ?login=john at doe)
+	// wget 'http://busybox.net#test/test':
+	//   request: 'GET / HTTP/1.0'
+	//   saves: 'index.html' (we save 'test')
+	//
+	// We also don't add unique .N suffix if file exists...
 	sp = strchr(h->host, '/');
-	if (sp) {
+	p = strchr(h->host, '?'); if (!sp || (p && sp > p)) sp = p;
+	p = strchr(h->host, '#'); if (!sp || (p && sp > p)) sp = p;
+	if (!sp) {
+		h->path = "";
+	} else if (*sp == '/') {
 		*sp++ = '\0';
 		h->path = sp;
-	} else
-		h->path = xstrdup("");
+	} else { // '#' or '?'
+		// http://busybox.net?login=john@doe is a valid URL
+		// memmove converts to:
+		// http:/busybox.nett?login=john at doe...
+		memmove(h->host-1, h->host, sp - h->host);
+		h->host--;
+		sp[-1] = '\0';
+		h->path = sp;
+	}
 
 	up = strrchr(h->host, '@');
 	if (up != NULL) {
@@ -535,7 +559,7 @@
 		char *ep;
 
 		ep = h->host + 1;
-		while (*ep == ':' || isxdigit (*ep))
+		while (*ep == ':' || isxdigit(*ep))
 			ep++;
 		if (*ep == ']') {
 			h->host++;




More information about the busybox-cvs mailing list