Hello,

>> The attached patch adds --post-data option to the wget applet.

> Please resend as attachment. (rediff against current svn first).

Attachment: wget-post-data.diff diffed against Revision 25485

Regards
Harald

--- wget.c.orig	2009-03-02 21:57:05.000000000 +0100
+++ wget.c	2009-03-02 22:05:22.000000000 +0100
@@ -387,6 +387,24 @@
 	return hdrval;
 }
 
+#if ENABLE_FEATURE_WGET_LONG_OPTIONS
+static unsigned char URL_escape_char(unsigned char c)
+{
+	/* URL encode, see RFC 2396 */ 
+	if (	(c >= '0' && c <= '9') ||
+		(c >= 'a' && c <= 'z') ||
+		(c >= 'A' && c <= 'Z') ||
+		c == '-'  || c == '_' ||
+		c == '.'  || c == '!' ||
+		c == '~'  || c == '*' ||
+		c == '\'' || c == '(' ||
+		c == ')'  || c == '=' ||
+		c == '&' )
+		return (0);
+	else
+		return(1);
+}
+#endif
 
 int wget_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int wget_main(int argc UNUSED_PARAM, char **argv)
@@ -402,6 +420,7 @@
 	char *proxy = 0;
 	char *dir_prefix = NULL;
 #if ENABLE_FEATURE_WGET_LONG_OPTIONS
+	char *post_data = NULL;
 	char *extra_headers = NULL;
 	llist_t *headers_llist = NULL;
 #endif
@@ -429,8 +448,9 @@
 		WGET_OPT_USER_AGENT = (1 << 6),
 		WGET_OPT_RETRIES    = (1 << 7),
 		WGET_OPT_NETWORK_READ_TIMEOUT = (1 << 8),
-		WGET_OPT_PASSIVE    = (1 << 9),
-		WGET_OPT_HEADER     = (1 << 10),
+		WGET_OPT_POST_DATA  = (1 << 9),
+		WGET_OPT_PASSIVE    = (1 << 10),
+		WGET_OPT_HEADER     = (1 << 11),
 	};
 #if ENABLE_FEATURE_WGET_LONG_OPTIONS
 	static const char wget_longopts[] ALIGN1 =
@@ -445,6 +465,7 @@
 		/* Ignored: */
 		// "tries\0"            Required_argument "t"
 		// "timeout\0"          Required_argument "T"
+		"post-data\0"        Required_argument "\xfd"
 		/* Ignored (we always use PASV): */
 		"passive-ftp\0"      No_argument       "\xff"
 		"header\0"           Required_argument "\xfe"
@@ -458,11 +479,18 @@
 #endif
 	/* server.allocated = target.allocated = NULL; */
 	opt_complementary = "-1" USE_FEATURE_WGET_LONG_OPTIONS(":\xfe::");
+#if ENABLE_FEATURE_WGET_LONG_OPTIONS
+	opt = getopt32(argv, "csqO:P:Y:U:" /*ignored:*/ "t:T:\xfd:",
+#else
 	opt = getopt32(argv, "csqO:P:Y:U:" /*ignored:*/ "t:T:",
+#endif
 				&fname_out, &dir_prefix,
 				&proxy_flag, &user_agent,
 				NULL, /* -t RETRIES */
 				NULL /* -T NETWORK_READ_TIMEOUT */
+#if ENABLE_FEATURE_WGET_LONG_OPTIONS
+				,&post_data
+#endif
 				USE_FEATURE_WGET_LONG_OPTIONS(, &headers_llist)
 				);
 	if (strcmp(proxy_flag, "off") == 0) {
@@ -483,6 +511,11 @@
 			cp += sprintf(cp, "%s\r\n", (char*)llist_pop(&headers_llist));
 		}
 	}
+
+	if (opt & WGET_OPT_POST_DATA) {
+		if (strlen(post_data) == 0)
+			opt &= ~WGET_OPT_POST_DATA; // if no string was supplied remove option
+	}
 #endif
 
 	parse_url(argv[optind], &target);
@@ -564,7 +597,12 @@
 					target.is_ftp ? "f" : "ht", target.host,
 					target.path);
 			} else {
-				fprintf(sfp, "GET /%s HTTP/1.1\r\n", target.path);
+#if ENABLE_FEATURE_WGET_LONG_OPTIONS
+				if (opt & WGET_OPT_POST_DATA)
+					fprintf(sfp, "POST /%s HTTP/1.1\r\n", target.path);
+				else
+#endif
+					fprintf(sfp, "GET /%s HTTP/1.1\r\n", target.path);
 			}
 
 			fprintf(sfp, "Host: %s\r\nUser-Agent: %s\r\n",
@@ -586,6 +624,29 @@
 #if ENABLE_FEATURE_WGET_LONG_OPTIONS
 			if (extra_headers)
 				fputs(extra_headers, sfp);
+
+			if (opt & WGET_OPT_POST_DATA) {
+				int i;
+				int post_data_size = 0;
+				fprintf(sfp, "Content-Type: application/x-www-form-urlencoded\r\n");
+				for (i=0; i<strlen(post_data); i++) {
+					if (URL_escape_char(post_data[i]))
+						post_data_size  +=3;
+					else
+						post_data_size  ++;
+				}
+				fprintf(sfp, "Content-Length: %d\r\n", post_data_size );
+				fprintf(sfp, "Connection: Keep-Alive\r\n\r\n");
+
+				for (i=0; i<strlen(post_data); i++)
+				{
+					if (URL_escape_char(post_data[i]))
+						fprintf(sfp, "%%%02X", post_data[i]);
+					else
+						fprintf(sfp, "%c", post_data[i]);
+				}
+				fprintf(sfp, "\r\n");
+			}
 #endif
 			fprintf(sfp, "Connection: close\r\n\r\n");
 
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to