diff options
author | Ron Yorston <rmy@pobox.com> | 2019-01-10 08:38:15 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2019-01-10 08:38:15 +0000 |
commit | f99a280743e877c14ee90a3f9e93a34ca3476a27 (patch) | |
tree | 60ca3d17596e190c8c7cbca587168946598bee8a /networking/wget.c | |
parent | 40d5dd07ea1f290eaed30a03fd598e33a8eaf495 (diff) | |
parent | 6ca8e347fed8c24655df692f22694baf7c572770 (diff) | |
download | busybox-w32-f99a280743e877c14ee90a3f9e93a34ca3476a27.tar.gz busybox-w32-f99a280743e877c14ee90a3f9e93a34ca3476a27.tar.bz2 busybox-w32-f99a280743e877c14ee90a3f9e93a34ca3476a27.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'networking/wget.c')
-rw-r--r-- | networking/wget.c | 64 |
1 files changed, 48 insertions, 16 deletions
diff --git a/networking/wget.c b/networking/wget.c index ae5c945d0..3cae1192c 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -9,7 +9,7 @@ | |||
9 | * Kuhn's copyrights are licensed GPLv2-or-later. File as a whole remains GPLv2. | 9 | * Kuhn's copyrights are licensed GPLv2-or-later. File as a whole remains GPLv2. |
10 | */ | 10 | */ |
11 | //config:config WGET | 11 | //config:config WGET |
12 | //config: bool "wget (35 kb)" | 12 | //config: bool "wget (38 kb)" |
13 | //config: default y | 13 | //config: default y |
14 | //config: help | 14 | //config: help |
15 | //config: wget is a utility for non-interactive download of files from HTTP | 15 | //config: wget is a utility for non-interactive download of files from HTTP |
@@ -123,14 +123,14 @@ | |||
123 | //usage:#define wget_trivial_usage | 123 | //usage:#define wget_trivial_usage |
124 | //usage: IF_FEATURE_WGET_LONG_OPTIONS( | 124 | //usage: IF_FEATURE_WGET_LONG_OPTIONS( |
125 | //usage: "[-c|--continue] [--spider] [-q|--quiet] [-O|--output-document FILE]\n" | 125 | //usage: "[-c|--continue] [--spider] [-q|--quiet] [-O|--output-document FILE]\n" |
126 | //usage: " [--header 'header: value'] [-Y|--proxy on/off] [-P DIR]\n" | 126 | //usage: " [-o|--output-file FILE] [--header 'header: value'] [-Y|--proxy on/off]\n" |
127 | /* Since we ignore these opts, we don't show them in --help */ | 127 | /* Since we ignore these opts, we don't show them in --help */ |
128 | /* //usage: " [--no-check-certificate] [--no-cache] [--passive-ftp] [-t TRIES]" */ | 128 | /* //usage: " [--no-check-certificate] [--no-cache] [--passive-ftp] [-t TRIES]" */ |
129 | /* //usage: " [-nv] [-nc] [-nH] [-np]" */ | 129 | /* //usage: " [-nv] [-nc] [-nH] [-np]" */ |
130 | //usage: " [-S|--server-response] [-U|--user-agent AGENT]" IF_FEATURE_WGET_TIMEOUT(" [-T SEC]") " URL..." | 130 | //usage: " [-P DIR] [-S|--server-response] [-U|--user-agent AGENT]" IF_FEATURE_WGET_TIMEOUT(" [-T SEC]") " URL..." |
131 | //usage: ) | 131 | //usage: ) |
132 | //usage: IF_NOT_FEATURE_WGET_LONG_OPTIONS( | 132 | //usage: IF_NOT_FEATURE_WGET_LONG_OPTIONS( |
133 | //usage: "[-cq] [-O FILE] [-Y on/off] [-P DIR] [-S] [-U AGENT]" | 133 | //usage: "[-cq] [-O FILE] [-o FILE] [-Y on/off] [-P DIR] [-S] [-U AGENT]" |
134 | //usage: IF_FEATURE_WGET_TIMEOUT(" [-T SEC]") " URL..." | 134 | //usage: IF_FEATURE_WGET_TIMEOUT(" [-T SEC]") " URL..." |
135 | //usage: ) | 135 | //usage: ) |
136 | //usage:#define wget_full_usage "\n\n" | 136 | //usage:#define wget_full_usage "\n\n" |
@@ -147,6 +147,7 @@ | |||
147 | //usage: "\n -T SEC Network read timeout is SEC seconds" | 147 | //usage: "\n -T SEC Network read timeout is SEC seconds" |
148 | //usage: ) | 148 | //usage: ) |
149 | //usage: "\n -O FILE Save to FILE ('-' for stdout)" | 149 | //usage: "\n -O FILE Save to FILE ('-' for stdout)" |
150 | //usage: "\n -o FILE Log messages to FILE" | ||
150 | //usage: "\n -U STR Use STR for User-Agent header" | 151 | //usage: "\n -U STR Use STR for User-Agent header" |
151 | //usage: "\n -Y on/off Use proxy" | 152 | //usage: "\n -Y on/off Use proxy" |
152 | 153 | ||
@@ -231,9 +232,11 @@ struct globals { | |||
231 | unsigned char user_headers; /* Headers mentioned by the user */ | 232 | unsigned char user_headers; /* Headers mentioned by the user */ |
232 | #endif | 233 | #endif |
233 | char *fname_out; /* where to direct output (-O) */ | 234 | char *fname_out; /* where to direct output (-O) */ |
235 | char *fname_log; /* where to direct log (-o) */ | ||
234 | const char *proxy_flag; /* Use proxies if env vars are set */ | 236 | const char *proxy_flag; /* Use proxies if env vars are set */ |
235 | const char *user_agent; /* "User-Agent" header field */ | 237 | const char *user_agent; /* "User-Agent" header field */ |
236 | int output_fd; | 238 | int output_fd; |
239 | int log_fd; | ||
237 | int o_flags; | 240 | int o_flags; |
238 | #if ENABLE_FEATURE_WGET_TIMEOUT | 241 | #if ENABLE_FEATURE_WGET_TIMEOUT |
239 | unsigned timeout_seconds; | 242 | unsigned timeout_seconds; |
@@ -262,16 +265,17 @@ enum { | |||
262 | WGET_OPT_QUIET = (1 << 1), | 265 | WGET_OPT_QUIET = (1 << 1), |
263 | WGET_OPT_SERVER_RESPONSE = (1 << 2), | 266 | WGET_OPT_SERVER_RESPONSE = (1 << 2), |
264 | WGET_OPT_OUTNAME = (1 << 3), | 267 | WGET_OPT_OUTNAME = (1 << 3), |
265 | WGET_OPT_PREFIX = (1 << 4), | 268 | WGET_OPT_LOGNAME = (1 << 4), |
266 | WGET_OPT_PROXY = (1 << 5), | 269 | WGET_OPT_PREFIX = (1 << 5), |
267 | WGET_OPT_USER_AGENT = (1 << 6), | 270 | WGET_OPT_PROXY = (1 << 6), |
268 | WGET_OPT_NETWORK_READ_TIMEOUT = (1 << 7), | 271 | WGET_OPT_USER_AGENT = (1 << 7), |
269 | WGET_OPT_RETRIES = (1 << 8), | 272 | WGET_OPT_NETWORK_READ_TIMEOUT = (1 << 8), |
270 | WGET_OPT_nsomething = (1 << 9), | 273 | WGET_OPT_RETRIES = (1 << 9), |
271 | WGET_OPT_HEADER = (1 << 10) * ENABLE_FEATURE_WGET_LONG_OPTIONS, | 274 | WGET_OPT_nsomething = (1 << 10), |
272 | WGET_OPT_POST_DATA = (1 << 11) * ENABLE_FEATURE_WGET_LONG_OPTIONS, | 275 | WGET_OPT_HEADER = (1 << 11) * ENABLE_FEATURE_WGET_LONG_OPTIONS, |
273 | WGET_OPT_SPIDER = (1 << 12) * ENABLE_FEATURE_WGET_LONG_OPTIONS, | 276 | WGET_OPT_POST_DATA = (1 << 12) * ENABLE_FEATURE_WGET_LONG_OPTIONS, |
274 | WGET_OPT_NO_CHECK_CERT = (1 << 13) * ENABLE_FEATURE_WGET_LONG_OPTIONS, | 277 | WGET_OPT_SPIDER = (1 << 13) * ENABLE_FEATURE_WGET_LONG_OPTIONS, |
278 | WGET_OPT_NO_CHECK_CERT = (1 << 14) * ENABLE_FEATURE_WGET_LONG_OPTIONS, | ||
275 | }; | 279 | }; |
276 | 280 | ||
277 | enum { | 281 | enum { |
@@ -287,6 +291,10 @@ static void progress_meter(int flag) | |||
287 | if (option_mask32 & WGET_OPT_QUIET) | 291 | if (option_mask32 & WGET_OPT_QUIET) |
288 | return; | 292 | return; |
289 | 293 | ||
294 | /* Don't save progress to log file */ | ||
295 | if (G.log_fd >= 0) | ||
296 | return; | ||
297 | |||
290 | if (flag == PROGRESS_START) | 298 | if (flag == PROGRESS_START) |
291 | bb_progress_init(&G.pmt, G.curfile); | 299 | bb_progress_init(&G.pmt, G.curfile); |
292 | 300 | ||
@@ -900,6 +908,10 @@ static void NOINLINE retrieve_file_data(FILE *dfp) | |||
900 | polldata.fd = fileno(dfp); | 908 | polldata.fd = fileno(dfp); |
901 | polldata.events = POLLIN | POLLPRI; | 909 | polldata.events = POLLIN | POLLPRI; |
902 | #endif | 910 | #endif |
911 | if (G.output_fd == 1) | ||
912 | fprintf(stderr, "writing to stdout\n"); | ||
913 | else | ||
914 | fprintf(stderr, "saving to '%s'\n", G.fname_out); | ||
903 | progress_meter(PROGRESS_START); | 915 | progress_meter(PROGRESS_START); |
904 | 916 | ||
905 | if (G.chunked) | 917 | if (G.chunked) |
@@ -1045,6 +1057,10 @@ static void NOINLINE retrieve_file_data(FILE *dfp) | |||
1045 | G.chunked = 0; /* makes it show 100% even for chunked download */ | 1057 | G.chunked = 0; /* makes it show 100% even for chunked download */ |
1046 | G.got_clen = 1; /* makes it show 100% even for download of (formerly) unknown size */ | 1058 | G.got_clen = 1; /* makes it show 100% even for download of (formerly) unknown size */ |
1047 | progress_meter(PROGRESS_END); | 1059 | progress_meter(PROGRESS_END); |
1060 | if (G.output_fd == 1) | ||
1061 | fprintf(stderr, "written to stdout\n"); | ||
1062 | else | ||
1063 | fprintf(stderr, "'%s' saved\n", G.fname_out); | ||
1048 | } | 1064 | } |
1049 | 1065 | ||
1050 | static void download_one_url(const char *url) | 1066 | static void download_one_url(const char *url) |
@@ -1404,6 +1420,8 @@ However, in real world it was observed that some web servers | |||
1404 | xclose(G.output_fd); | 1420 | xclose(G.output_fd); |
1405 | G.output_fd = -1; | 1421 | G.output_fd = -1; |
1406 | } | 1422 | } |
1423 | } else { | ||
1424 | fprintf(stderr, "remote file exists\n"); | ||
1407 | } | 1425 | } |
1408 | 1426 | ||
1409 | if (dfp != sfp) { | 1427 | if (dfp != sfp) { |
@@ -1433,6 +1451,7 @@ int wget_main(int argc UNUSED_PARAM, char **argv) | |||
1433 | "quiet\0" No_argument "q" | 1451 | "quiet\0" No_argument "q" |
1434 | "server-response\0" No_argument "S" | 1452 | "server-response\0" No_argument "S" |
1435 | "output-document\0" Required_argument "O" | 1453 | "output-document\0" Required_argument "O" |
1454 | "output-file\0" Required_argument "o" | ||
1436 | "directory-prefix\0" Required_argument "P" | 1455 | "directory-prefix\0" Required_argument "P" |
1437 | "proxy\0" Required_argument "Y" | 1456 | "proxy\0" Required_argument "Y" |
1438 | "user-agent\0" Required_argument "U" | 1457 | "user-agent\0" Required_argument "U" |
@@ -1476,7 +1495,7 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0") | |||
1476 | #if ENABLE_FEATURE_WGET_LONG_OPTIONS | 1495 | #if ENABLE_FEATURE_WGET_LONG_OPTIONS |
1477 | #endif | 1496 | #endif |
1478 | GETOPT32(argv, "^" | 1497 | GETOPT32(argv, "^" |
1479 | "cqSO:P:Y:U:T:+" | 1498 | "cqSO:o:P:Y:U:T:+" |
1480 | /*ignored:*/ "t:" | 1499 | /*ignored:*/ "t:" |
1481 | /*ignored:*/ "n::" | 1500 | /*ignored:*/ "n::" |
1482 | /* wget has exactly four -n<letter> opts, all of which we can ignore: | 1501 | /* wget has exactly four -n<letter> opts, all of which we can ignore: |
@@ -1491,7 +1510,7 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0") | |||
1491 | "-1" /* at least one URL */ | 1510 | "-1" /* at least one URL */ |
1492 | IF_FEATURE_WGET_LONG_OPTIONS(":\xff::") /* --header is a list */ | 1511 | IF_FEATURE_WGET_LONG_OPTIONS(":\xff::") /* --header is a list */ |
1493 | LONGOPTS | 1512 | LONGOPTS |
1494 | , &G.fname_out, &G.dir_prefix, | 1513 | , &G.fname_out, &G.fname_log, &G.dir_prefix, |
1495 | &G.proxy_flag, &G.user_agent, | 1514 | &G.proxy_flag, &G.user_agent, |
1496 | IF_FEATURE_WGET_TIMEOUT(&G.timeout_seconds) IF_NOT_FEATURE_WGET_TIMEOUT(NULL), | 1515 | IF_FEATURE_WGET_TIMEOUT(&G.timeout_seconds) IF_NOT_FEATURE_WGET_TIMEOUT(NULL), |
1497 | NULL, /* -t RETRIES */ | 1516 | NULL, /* -t RETRIES */ |
@@ -1553,12 +1572,25 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0") | |||
1553 | G.o_flags = O_WRONLY | O_CREAT | O_TRUNC; | 1572 | G.o_flags = O_WRONLY | O_CREAT | O_TRUNC; |
1554 | } | 1573 | } |
1555 | 1574 | ||
1575 | G.log_fd = -1; | ||
1576 | if (G.fname_log) { /* -o FILE ? */ | ||
1577 | if (!LONE_DASH(G.fname_log)) { /* not -o - ? */ | ||
1578 | /* compat with wget: -o FILE can overwrite */ | ||
1579 | G.log_fd = xopen(G.fname_log, O_WRONLY | O_CREAT | O_TRUNC); | ||
1580 | /* Redirect only stderr to log file, so -O - will work */ | ||
1581 | xdup2(G.log_fd, STDERR_FILENO); | ||
1582 | } | ||
1583 | } | ||
1584 | |||
1556 | while (*argv) | 1585 | while (*argv) |
1557 | download_one_url(*argv++); | 1586 | download_one_url(*argv++); |
1558 | 1587 | ||
1559 | if (G.output_fd >= 0) | 1588 | if (G.output_fd >= 0) |
1560 | xclose(G.output_fd); | 1589 | xclose(G.output_fd); |
1561 | 1590 | ||
1591 | if (G.log_fd >= 0) | ||
1592 | xclose(G.log_fd); | ||
1593 | |||
1562 | #if ENABLE_FEATURE_CLEAN_UP && ENABLE_FEATURE_WGET_LONG_OPTIONS | 1594 | #if ENABLE_FEATURE_CLEAN_UP && ENABLE_FEATURE_WGET_LONG_OPTIONS |
1563 | free(G.extra_headers); | 1595 | free(G.extra_headers); |
1564 | #endif | 1596 | #endif |