aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2021-09-28 09:27:40 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2021-10-01 14:55:18 +0200
commited9aa89269569c58bd47d085f25eece0a6221973 (patch)
tree1aea7c70884308341381bbb4be4de9f4d87a2a00
parent1f5a44d20c7963a347165a033aea6da3bbfa9d2c (diff)
downloadbusybox-w32-ed9aa89269569c58bd47d085f25eece0a6221973.tar.gz
busybox-w32-ed9aa89269569c58bd47d085f25eece0a6221973.tar.bz2
busybox-w32-ed9aa89269569c58bd47d085f25eece0a6221973.zip
wget: implement --post-file
Add the --post-file option to send form data from a file. As with --post-data it's up to the user to ensure that the data is encoded as appropriate: all wget does is stuff the provided data into the request. The --post-data and --post-file options are mutually exclusive and only one instance of either may be given. Additionally: - update the usage message to include missing details of the --post-data and --header options; - free POST data if FEATURE_CLEAN_UP is enabled. function old new delta packed_usage 34158 34214 +56 wget_main 2762 2805 +43 .rodata 99225 99240 +15 static.wget_longopts 266 278 +12 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/0 up/down: 126/0) Total: 126 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/wget.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/networking/wget.c b/networking/wget.c
index 6a9604421..91ef99eab 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -135,7 +135,8 @@
135 135
136//usage:#define wget_trivial_usage 136//usage:#define wget_trivial_usage
137//usage: IF_FEATURE_WGET_LONG_OPTIONS( 137//usage: IF_FEATURE_WGET_LONG_OPTIONS(
138//usage: "[-cqS] [--spider] [-O FILE] [-o LOGFILE] [--header 'HEADER: VALUE'] [-Y on/off]\n" 138//usage: "[-cqS] [--spider] [-O FILE] [-o LOGFILE] [--header STR]\n"
139//usage: " [--post-data STR | --post-file FILE] [-Y on/off]\n"
139/* Since we ignore these opts, we don't show them in --help */ 140/* Since we ignore these opts, we don't show them in --help */
140/* //usage: " [--no-cache] [--passive-ftp] [-t TRIES]" */ 141/* //usage: " [--no-cache] [--passive-ftp] [-t TRIES]" */
141/* //usage: " [-nv] [-nc] [-nH] [-np]" */ 142/* //usage: " [-nv] [-nc] [-nH] [-np]" */
@@ -148,6 +149,9 @@
148//usage: "Retrieve files via HTTP or FTP\n" 149//usage: "Retrieve files via HTTP or FTP\n"
149//usage: IF_FEATURE_WGET_LONG_OPTIONS( 150//usage: IF_FEATURE_WGET_LONG_OPTIONS(
150//usage: "\n --spider Only check URL existence: $? is 0 if exists" 151//usage: "\n --spider Only check URL existence: $? is 0 if exists"
152//usage: "\n --header STR Add STR (of form 'header: value') to headers"
153//usage: "\n --post-data STR Send STR using POST method"
154//usage: "\n --post-file FILE Send FILE using POST method"
151//usage: IF_FEATURE_WGET_OPENSSL( 155//usage: IF_FEATURE_WGET_OPENSSL(
152//usage: "\n --no-check-certificate Don't validate the server's certificate" 156//usage: "\n --no-check-certificate Don't validate the server's certificate"
153//usage: ) 157//usage: )
@@ -244,6 +248,7 @@ struct globals {
244 char *dir_prefix; 248 char *dir_prefix;
245#if ENABLE_FEATURE_WGET_LONG_OPTIONS 249#if ENABLE_FEATURE_WGET_LONG_OPTIONS
246 char *post_data; 250 char *post_data;
251 char *post_file;
247 char *extra_headers; 252 char *extra_headers;
248 unsigned char user_headers; /* Headers mentioned by the user */ 253 unsigned char user_headers; /* Headers mentioned by the user */
249#endif 254#endif
@@ -292,10 +297,13 @@ enum {
292 WGET_OPT_POST_DATA = (1 << 12) * ENABLE_FEATURE_WGET_LONG_OPTIONS, 297 WGET_OPT_POST_DATA = (1 << 12) * ENABLE_FEATURE_WGET_LONG_OPTIONS,
293 WGET_OPT_SPIDER = (1 << 13) * ENABLE_FEATURE_WGET_LONG_OPTIONS, 298 WGET_OPT_SPIDER = (1 << 13) * ENABLE_FEATURE_WGET_LONG_OPTIONS,
294 WGET_OPT_NO_CHECK_CERT = (1 << 14) * ENABLE_FEATURE_WGET_LONG_OPTIONS, 299 WGET_OPT_NO_CHECK_CERT = (1 << 14) * ENABLE_FEATURE_WGET_LONG_OPTIONS,
300 WGET_OPT_POST_FILE = (1 << 15) * ENABLE_FEATURE_WGET_LONG_OPTIONS,
295 /* hijack this bit for other than opts purposes: */ 301 /* hijack this bit for other than opts purposes: */
296 WGET_NO_FTRUNCATE = (1 << 31) 302 WGET_NO_FTRUNCATE = (1 << 31)
297}; 303};
298 304
305#define WGET_OPT_POST (WGET_OPT_POST_DATA | WGET_OPT_POST_FILE)
306
299enum { 307enum {
300 PROGRESS_START = -1, 308 PROGRESS_START = -1,
301 PROGRESS_END = 0, 309 PROGRESS_END = 0,
@@ -1213,7 +1221,7 @@ static void download_one_url(const char *url)
1213 target.path); 1221 target.path);
1214 } else { 1222 } else {
1215 SENDFMT(sfp, "%s /%s HTTP/1.1\r\n", 1223 SENDFMT(sfp, "%s /%s HTTP/1.1\r\n",
1216 (option_mask32 & WGET_OPT_POST_DATA) ? "POST" : "GET", 1224 (option_mask32 & WGET_OPT_POST) ? "POST" : "GET",
1217 target.path); 1225 target.path);
1218 } 1226 }
1219 if (!USR_HEADER_HOST) 1227 if (!USR_HEADER_HOST)
@@ -1246,7 +1254,13 @@ static void download_one_url(const char *url)
1246 fputs(G.extra_headers, sfp); 1254 fputs(G.extra_headers, sfp);
1247 } 1255 }
1248 1256
1249 if (option_mask32 & WGET_OPT_POST_DATA) { 1257 if (option_mask32 & WGET_OPT_POST_FILE) {
1258 int fd = xopen_stdin(G.post_file);
1259 G.post_data = xmalloc_read(fd, NULL);
1260 close(fd);
1261 }
1262
1263 if (G.post_data) {
1250 SENDFMT(sfp, 1264 SENDFMT(sfp,
1251 "Content-Type: application/x-www-form-urlencoded\r\n" 1265 "Content-Type: application/x-www-form-urlencoded\r\n"
1252 "Content-Length: %u\r\n" 1266 "Content-Length: %u\r\n"
@@ -1489,6 +1503,7 @@ IF_DESKTOP( "tries\0" Required_argument "t")
1489 "post-data\0" Required_argument "\xfe" 1503 "post-data\0" Required_argument "\xfe"
1490 "spider\0" No_argument "\xfd" 1504 "spider\0" No_argument "\xfd"
1491 "no-check-certificate\0" No_argument "\xfc" 1505 "no-check-certificate\0" No_argument "\xfc"
1506 "post-file\0" Required_argument "\xfb"
1492 /* Ignored (we always use PASV): */ 1507 /* Ignored (we always use PASV): */
1493IF_DESKTOP( "passive-ftp\0" No_argument "\xf0") 1508IF_DESKTOP( "passive-ftp\0" No_argument "\xf0")
1494 /* Ignored (we don't support caching) */ 1509 /* Ignored (we don't support caching) */
@@ -1532,6 +1547,9 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0")
1532 */ 1547 */
1533 "\0" 1548 "\0"
1534 "-1" /* at least one URL */ 1549 "-1" /* at least one URL */
1550 IF_FEATURE_WGET_LONG_OPTIONS(":\xfe--\xfb")
1551 IF_FEATURE_WGET_LONG_OPTIONS(":\xfe--\xfe")
1552 IF_FEATURE_WGET_LONG_OPTIONS(":\xfb--\xfb")
1535 IF_FEATURE_WGET_LONG_OPTIONS(":\xff::") /* --header is a list */ 1553 IF_FEATURE_WGET_LONG_OPTIONS(":\xff::") /* --header is a list */
1536 LONGOPTS 1554 LONGOPTS
1537 , &G.fname_out, &G.fname_log, &G.dir_prefix, 1555 , &G.fname_out, &G.fname_log, &G.dir_prefix,
@@ -1541,6 +1559,7 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0")
1541 NULL /* -n[ARG] */ 1559 NULL /* -n[ARG] */
1542 IF_FEATURE_WGET_LONG_OPTIONS(, &headers_llist) 1560 IF_FEATURE_WGET_LONG_OPTIONS(, &headers_llist)
1543 IF_FEATURE_WGET_LONG_OPTIONS(, &G.post_data) 1561 IF_FEATURE_WGET_LONG_OPTIONS(, &G.post_data)
1562 IF_FEATURE_WGET_LONG_OPTIONS(, &G.post_file)
1544 ); 1563 );
1545#if 0 /* option bits debug */ 1564#if 0 /* option bits debug */
1546 if (option_mask32 & WGET_OPT_RETRIES) bb_error_msg("-t NUM"); 1565 if (option_mask32 & WGET_OPT_RETRIES) bb_error_msg("-t NUM");
@@ -1549,6 +1568,7 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0")
1549 if (option_mask32 & WGET_OPT_POST_DATA) bb_error_msg("--post-data"); 1568 if (option_mask32 & WGET_OPT_POST_DATA) bb_error_msg("--post-data");
1550 if (option_mask32 & WGET_OPT_SPIDER) bb_error_msg("--spider"); 1569 if (option_mask32 & WGET_OPT_SPIDER) bb_error_msg("--spider");
1551 if (option_mask32 & WGET_OPT_NO_CHECK_CERT) bb_error_msg("--no-check-certificate"); 1570 if (option_mask32 & WGET_OPT_NO_CHECK_CERT) bb_error_msg("--no-check-certificate");
1571 if (option_mask32 & WGET_OPT_POST_FILE) bb_error_msg("--post-file");
1552 exit(0); 1572 exit(0);
1553#endif 1573#endif
1554 argv += optind; 1574 argv += optind;