Hello,
The attached patch adds --post-data option to the wget applet.
Additionally
+ "tries\0" Required_argument "t"
+ "timeout\0" Required_argument "T"
must be added to wget_longopts[] otherwise WGET_OPT_HEADER dose not match to
the bits of the return value of getopt32().
Best regards
Harald
--- wget.c.orig 2008-11-09 18:27:59.000000000 +0100
+++ wget.c 2009-02-28 21:28:47.000000000 +0100
@@ -384,6 +384,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)
@@ -399,6 +417,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
@@ -424,8 +443,11 @@
WGET_OPT_PREFIX = 0x10,
WGET_OPT_PROXY = 0x20,
WGET_OPT_USER_AGENT = 0x40,
- WGET_OPT_PASSIVE = 0x80,
- WGET_OPT_HEADER = 0x100,
+ WGET_OPT_RETRIES = 0x80,
+ WGET_OPT_NETWORK_READ_TIMEOUT = 0x100,
+ WGET_OPT_POST_DATA = 0x200,
+ WGET_OPT_PASSIVE = 0x400,
+ WGET_OPT_HEADER = 0x800,
};
#if ENABLE_FEATURE_WGET_LONG_OPTIONS
static const char wget_longopts[] ALIGN1 =
@@ -437,6 +459,9 @@
"directory-prefix\0" Required_argument "P"
"proxy\0" Required_argument "Y"
"user-agent\0" Required_argument "U"
+ "tries\0" Required_argument "t"
+ "timeout\0" Required_argument "T"
+ "post-data\0" Required_argument "\xfd"
"passive-ftp\0" No_argument "\xff"
"header\0" Required_argument "\xfe"
;
@@ -449,11 +474,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) {
@@ -474,6 +506,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);
@@ -555,7 +592,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",
@@ -577,6 +619,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