aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-01-24 21:41:43 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2017-01-24 21:41:43 +0100
commitdff9fefd500401ad7821c9890fee4c3fb88f64eb (patch)
tree7cae58ea31a99f4f7cfab543de97f5b34a202999
parentbca4ea8b68403e6f751341b82c65937f14590679 (diff)
downloadbusybox-w32-dff9fefd500401ad7821c9890fee4c3fb88f64eb.tar.gz
busybox-w32-dff9fefd500401ad7821c9890fee4c3fb88f64eb.tar.bz2
busybox-w32-dff9fefd500401ad7821c9890fee4c3fb88f64eb.zip
wget: add support for -S --server-response
Based on the patch by stephane.billiart@gmail.com function old new delta ftpcmd 87 129 +42 fgets_and_trim 86 119 +33 static.wget_longopts 234 252 +18 packed_usage 31002 31015 +13 wget_main 2535 2540 +5 gethdr 158 163 +5 retrieve_file_data 424 428 +4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 7/0 up/down: 120/0) Total: 120 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/wget.c49
1 files changed, 29 insertions, 20 deletions
diff --git a/networking/wget.c b/networking/wget.c
index a448acdae..90eedaf7a 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -94,20 +94,21 @@
94/* Since we ignore these opts, we don't show them in --help */ 94/* Since we ignore these opts, we don't show them in --help */
95/* //usage: " [--no-check-certificate] [--no-cache] [--passive-ftp] [-t TRIES]" */ 95/* //usage: " [--no-check-certificate] [--no-cache] [--passive-ftp] [-t TRIES]" */
96/* //usage: " [-nv] [-nc] [-nH] [-np]" */ 96/* //usage: " [-nv] [-nc] [-nH] [-np]" */
97//usage: " [-U|--user-agent AGENT]" IF_FEATURE_WGET_TIMEOUT(" [-T SEC]") " URL..." 97//usage: " [-S|--server-response] [-U|--user-agent AGENT]" IF_FEATURE_WGET_TIMEOUT(" [-T SEC]") " URL..."
98//usage: ) 98//usage: )
99//usage: IF_NOT_FEATURE_WGET_LONG_OPTIONS( 99//usage: IF_NOT_FEATURE_WGET_LONG_OPTIONS(
100//usage: "[-cq] [-O FILE] [-Y on/off] [-P DIR] [-U AGENT]" 100//usage: "[-cq] [-O FILE] [-Y on/off] [-P DIR] [-S] [-U AGENT]"
101//usage: IF_FEATURE_WGET_TIMEOUT(" [-T SEC]") " URL..." 101//usage: IF_FEATURE_WGET_TIMEOUT(" [-T SEC]") " URL..."
102//usage: ) 102//usage: )
103//usage:#define wget_full_usage "\n\n" 103//usage:#define wget_full_usage "\n\n"
104//usage: "Retrieve files via HTTP or FTP\n" 104//usage: "Retrieve files via HTTP or FTP\n"
105//usage: IF_FEATURE_WGET_LONG_OPTIONS( 105//usage: IF_FEATURE_WGET_LONG_OPTIONS(
106//usage: "\n --spider Spider mode - only check file existence" 106//usage: "\n --spider Only check URL existence: $? is 0 if exists"
107//usage: ) 107//usage: )
108//usage: "\n -c Continue retrieval of aborted transfer" 108//usage: "\n -c Continue retrieval of aborted transfer"
109//usage: "\n -q Quiet" 109//usage: "\n -q Quiet"
110//usage: "\n -P DIR Save to DIR (default .)" 110//usage: "\n -P DIR Save to DIR (default .)"
111//usage: "\n -S Show server response"
111//usage: IF_FEATURE_WGET_TIMEOUT( 112//usage: IF_FEATURE_WGET_TIMEOUT(
112//usage: "\n -T SEC Network read timeout is SEC seconds" 113//usage: "\n -T SEC Network read timeout is SEC seconds"
113//usage: ) 114//usage: )
@@ -223,16 +224,17 @@ struct globals {
223enum { 224enum {
224 WGET_OPT_CONTINUE = (1 << 0), 225 WGET_OPT_CONTINUE = (1 << 0),
225 WGET_OPT_QUIET = (1 << 1), 226 WGET_OPT_QUIET = (1 << 1),
226 WGET_OPT_OUTNAME = (1 << 2), 227 WGET_OPT_SERVER_RESPONSE = (1 << 2),
227 WGET_OPT_PREFIX = (1 << 3), 228 WGET_OPT_OUTNAME = (1 << 3),
228 WGET_OPT_PROXY = (1 << 4), 229 WGET_OPT_PREFIX = (1 << 4),
229 WGET_OPT_USER_AGENT = (1 << 5), 230 WGET_OPT_PROXY = (1 << 5),
230 WGET_OPT_NETWORK_READ_TIMEOUT = (1 << 6), 231 WGET_OPT_USER_AGENT = (1 << 6),
231 WGET_OPT_RETRIES = (1 << 7), 232 WGET_OPT_NETWORK_READ_TIMEOUT = (1 << 7),
232 WGET_OPT_nsomething = (1 << 8), 233 WGET_OPT_RETRIES = (1 << 8),
233 WGET_OPT_HEADER = (1 << 9) * ENABLE_FEATURE_WGET_LONG_OPTIONS, 234 WGET_OPT_nsomething = (1 << 9),
234 WGET_OPT_POST_DATA = (1 << 10) * ENABLE_FEATURE_WGET_LONG_OPTIONS, 235 WGET_OPT_HEADER = (1 << 10) * ENABLE_FEATURE_WGET_LONG_OPTIONS,
235 WGET_OPT_SPIDER = (1 << 11) * ENABLE_FEATURE_WGET_LONG_OPTIONS, 236 WGET_OPT_POST_DATA = (1 << 11) * ENABLE_FEATURE_WGET_LONG_OPTIONS,
237 WGET_OPT_SPIDER = (1 << 12) * ENABLE_FEATURE_WGET_LONG_OPTIONS,
236}; 238};
237 239
238enum { 240enum {
@@ -386,7 +388,7 @@ static FILE *open_socket(len_and_sockaddr *lsa)
386} 388}
387 389
388/* Returns '\n' if it was seen, else '\0'. Trims at first '\r' or '\n' */ 390/* Returns '\n' if it was seen, else '\0'. Trims at first '\r' or '\n' */
389static char fgets_and_trim(FILE *fp) 391static char fgets_and_trim(FILE *fp, const char *fmt)
390{ 392{
391 char c; 393 char c;
392 char *buf_ptr; 394 char *buf_ptr;
@@ -404,6 +406,9 @@ static char fgets_and_trim(FILE *fp)
404 406
405 log_io("< %s", G.wget_buf); 407 log_io("< %s", G.wget_buf);
406 408
409 if (fmt && (option_mask32 & WGET_OPT_SERVER_RESPONSE))
410 fprintf(stderr, fmt, G.wget_buf);
411
407 return c; 412 return c;
408} 413}
409 414
@@ -414,12 +419,15 @@ static int ftpcmd(const char *s1, const char *s2, FILE *fp)
414 if (!s2) 419 if (!s2)
415 s2 = ""; 420 s2 = "";
416 fprintf(fp, "%s%s\r\n", s1, s2); 421 fprintf(fp, "%s%s\r\n", s1, s2);
422 /* With --server-response, wget also shows its ftp commands */
423 if (option_mask32 & WGET_OPT_SERVER_RESPONSE)
424 fprintf(stderr, "--> %s%s\n\n", s1, s2);
417 fflush(fp); 425 fflush(fp);
418 log_io("> %s%s", s1, s2); 426 log_io("> %s%s", s1, s2);
419 } 427 }
420 428
421 do { 429 do {
422 fgets_and_trim(fp); 430 fgets_and_trim(fp, "%s\n");
423 } while (!isdigit(G.wget_buf[0]) || G.wget_buf[3] != ' '); 431 } while (!isdigit(G.wget_buf[0]) || G.wget_buf[3] != ' ');
424 432
425 G.wget_buf[3] = '\0'; 433 G.wget_buf[3] = '\0';
@@ -516,7 +524,7 @@ static char *gethdr(FILE *fp)
516 int c; 524 int c;
517 525
518 /* retrieve header line */ 526 /* retrieve header line */
519 c = fgets_and_trim(fp); 527 c = fgets_and_trim(fp, " %s\n");
520 528
521 /* end of the headers? */ 529 /* end of the headers? */
522 if (G.wget_buf[0] == '\0') 530 if (G.wget_buf[0] == '\0')
@@ -884,9 +892,9 @@ static void NOINLINE retrieve_file_data(FILE *dfp)
884 if (!G.chunked) 892 if (!G.chunked)
885 break; 893 break;
886 894
887 fgets_and_trim(dfp); /* Eat empty line */ 895 fgets_and_trim(dfp, NULL); /* Eat empty line */
888 get_clen: 896 get_clen:
889 fgets_and_trim(dfp); 897 fgets_and_trim(dfp, NULL);
890 G.content_len = STRTOOFF(G.wget_buf, NULL, 16); 898 G.content_len = STRTOOFF(G.wget_buf, NULL, 16);
891 /* FIXME: error check? */ 899 /* FIXME: error check? */
892 if (G.content_len == 0) 900 if (G.content_len == 0)
@@ -1116,7 +1124,7 @@ static void download_one_url(const char *url)
1116 * Retrieve HTTP response line and check for "200" status code. 1124 * Retrieve HTTP response line and check for "200" status code.
1117 */ 1125 */
1118 read_response: 1126 read_response:
1119 fgets_and_trim(sfp); 1127 fgets_and_trim(sfp, " %s\n");
1120 1128
1121 str = G.wget_buf; 1129 str = G.wget_buf;
1122 str = skip_non_whitespace(str); 1130 str = skip_non_whitespace(str);
@@ -1301,6 +1309,7 @@ int wget_main(int argc UNUSED_PARAM, char **argv)
1301 /* name, has_arg, val */ 1309 /* name, has_arg, val */
1302 "continue\0" No_argument "c" 1310 "continue\0" No_argument "c"
1303 "quiet\0" No_argument "q" 1311 "quiet\0" No_argument "q"
1312 "server-response\0" No_argument "S"
1304 "output-document\0" Required_argument "O" 1313 "output-document\0" Required_argument "O"
1305 "directory-prefix\0" Required_argument "P" 1314 "directory-prefix\0" Required_argument "P"
1306 "proxy\0" Required_argument "Y" 1315 "proxy\0" Required_argument "Y"
@@ -1343,7 +1352,7 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0")
1343#endif 1352#endif
1344 opt_complementary = "-1" /* at least one URL */ 1353 opt_complementary = "-1" /* at least one URL */
1345 IF_FEATURE_WGET_LONG_OPTIONS(":\xff::"); /* --header is a list */ 1354 IF_FEATURE_WGET_LONG_OPTIONS(":\xff::"); /* --header is a list */
1346 getopt32(argv, "cqO:P:Y:U:T:+" 1355 getopt32(argv, "cqSO:P:Y:U:T:+"
1347 /*ignored:*/ "t:" 1356 /*ignored:*/ "t:"
1348 /*ignored:*/ "n::" 1357 /*ignored:*/ "n::"
1349 /* wget has exactly four -n<letter> opts, all of which we can ignore: 1358 /* wget has exactly four -n<letter> opts, all of which we can ignore: