1 /* vi: set sw=4 ts=4: */
3 * wget - retrieve a file using HTTP or FTP
5 * Chip Rosenthal Covad Communications <chip@laserlink.net>
6 * Licensed under GPLv2, see file LICENSE in this source tree.
8 * Copyright (C) 2010 Bradley M. Kuhn <bkuhn@ebb.org>
9 * Kuhn's copyrights are licensed GPLv2-or-later. File as a whole remains GPLv2.
13 //#define log_io(...) bb_error_msg(__VA_ARGS__)
14 #define log_io(...) ((void)0)
29 off_t content_len; /* Content-length of the file */
30 off_t beg_range; /* Range at which continue begins */
31 #if ENABLE_FEATURE_WGET_STATUSBAR
32 off_t transferred; /* Number of bytes transferred so far */
33 const char *curfile; /* Name of current file being transferred */
37 #if ENABLE_FEATURE_WGET_LONG_OPTIONS
41 char *fname_out; /* where to direct output (-O) */
42 const char *proxy_flag; /* Use proxies if env vars are set */
43 const char *user_agent; /* "User-Agent" header field */
44 #if ENABLE_FEATURE_WGET_TIMEOUT
45 unsigned timeout_seconds;
49 smallint chunked; /* chunked transfer encoding */
50 smallint got_clen; /* got content-length: from server */
51 /* Local downloads do benefit from big buffer.
52 * With 512 byte buffer, it was measured to be
53 * an order of magnitude slower than with big one.
55 uint64_t just_to_align_next_member;
56 char wget_buf[CONFIG_FEATURE_COPYBUF_KB*1024];
58 #define G (*ptr_to_globals)
59 #define INIT_G() do { \
60 SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
61 IF_FEATURE_WGET_TIMEOUT(G.timeout_seconds = 900;) \
65 /* Must match option string! */
67 WGET_OPT_CONTINUE = (1 << 0),
68 WGET_OPT_SPIDER = (1 << 1),
69 WGET_OPT_QUIET = (1 << 2),
70 WGET_OPT_OUTNAME = (1 << 3),
71 WGET_OPT_PREFIX = (1 << 4),
72 WGET_OPT_PROXY = (1 << 5),
73 WGET_OPT_USER_AGENT = (1 << 6),
74 WGET_OPT_NETWORK_READ_TIMEOUT = (1 << 7),
75 WGET_OPT_RETRIES = (1 << 8),
76 WGET_OPT_PASSIVE = (1 << 9),
77 WGET_OPT_HEADER = (1 << 10) * ENABLE_FEATURE_WGET_LONG_OPTIONS,
78 WGET_OPT_POST_DATA = (1 << 11) * ENABLE_FEATURE_WGET_LONG_OPTIONS,
86 #if ENABLE_FEATURE_WGET_STATUSBAR
87 static void progress_meter(int flag)
89 if (option_mask32 & WGET_OPT_QUIET)
92 if (flag == PROGRESS_START)
93 bb_progress_init(&G.pmt, G.curfile);
95 bb_progress_update(&G.pmt,
98 (G.chunked || !G.got_clen) ? 0 : G.beg_range + G.transferred + G.content_len
101 if (flag == PROGRESS_END) {
102 bb_progress_free(&G.pmt);
103 bb_putchar_stderr('\n');
108 static ALWAYS_INLINE void progress_meter(int flag UNUSED_PARAM) { }
112 /* IPv6 knows scoped address types i.e. link and site local addresses. Link
113 * local addresses can have a scope identifier to specify the
114 * interface/link an address is valid on (e.g. fe80::1%eth0). This scope
115 * identifier is only valid on a single node.
117 * RFC 4007 says that the scope identifier MUST NOT be sent across the wire,
118 * unless all nodes agree on the semantic. Apache e.g. regards zone identifiers
119 * in the Host header as invalid requests, see
120 * https://issues.apache.org/bugzilla/show_bug.cgi?id=35122
122 static void strip_ipv6_scope_id(char *host)
126 /* bbox wget actually handles IPv6 addresses without [], like
127 * wget "http://::1/xxx", but this is not standard.
128 * To save code, _here_ we do not support it. */
131 return; /* not IPv6 */
133 scope = strchr(host, '%');
137 /* Remove the IPv6 zone identifier from the host address */
138 cp = strchr(host, ']');
139 if (!cp || (cp[1] != ':' && cp[1] != '\0')) {
140 /* malformed address (not "[xx]:nn" or "[xx]") */
144 /* cp points to "]...", scope points to "%eth0]..." */
145 overlapping_strcpy(scope, cp);
148 #if ENABLE_FEATURE_WGET_AUTHENTICATION
149 /* Base64-encode character string. */
150 static char *base64enc(const char *str)
152 unsigned len = strlen(str);
153 if (len > sizeof(G.wget_buf)/4*3 - 10) /* paranoia */
154 len = sizeof(G.wget_buf)/4*3 - 10;
155 bb_uuencode(G.wget_buf, str, len, bb_uuenc_tbl_base64);
160 static char* sanitize_string(char *s)
162 unsigned char *p = (void *) s;
169 static FILE *open_socket(len_and_sockaddr *lsa)
173 /* glibc 2.4 seems to try seeking on it - ??! */
174 /* hopefully it understands what ESPIPE means... */
175 fp = fdopen(xconnect_stream(lsa), "r+");
177 bb_perror_msg_and_die(bb_msg_memory_exhausted);
182 /* Returns '\n' if it was seen, else '\0'. Trims at first '\r' or '\n' */
183 static char fgets_and_trim(FILE *fp)
188 if (fgets(G.wget_buf, sizeof(G.wget_buf) - 1, fp) == NULL)
189 bb_perror_msg_and_die("error getting response");
191 buf_ptr = strchrnul(G.wget_buf, '\n');
194 buf_ptr = strchrnul(G.wget_buf, '\r');
197 log_io("< %s", G.wget_buf);
202 static int ftpcmd(const char *s1, const char *s2, FILE *fp)
208 fprintf(fp, "%s%s\r\n", s1, s2);
210 log_io("> %s%s", s1, s2);
215 } while (!isdigit(G.wget_buf[0]) || G.wget_buf[3] != ' ');
217 G.wget_buf[3] = '\0';
218 result = xatoi_positive(G.wget_buf);
223 static void parse_url(const char *src_url, struct host_info *h)
228 h->allocated = url = xstrdup(src_url);
230 if (strncmp(url, "http://", 7) == 0) {
231 h->port = bb_lookup_port("http", "tcp", 80);
234 } else if (strncmp(url, "ftp://", 6) == 0) {
235 h->port = bb_lookup_port("ftp", "tcp", 21);
239 bb_error_msg_and_die("not an http or ftp url: %s", sanitize_string(url));
242 // "Real" wget 'http://busybox.net?var=a/b' sends this request:
243 // 'GET /?var=a/b HTTP 1.0'
244 // and saves 'index.html?var=a%2Fb' (we save 'b')
245 // wget 'http://busybox.net?login=john@doe':
246 // request: 'GET /?login=john@doe HTTP/1.0'
247 // saves: 'index.html?login=john@doe' (we save '?login=john@doe')
248 // wget 'http://busybox.net#test/test':
249 // request: 'GET / HTTP/1.0'
250 // saves: 'index.html' (we save 'test')
252 // We also don't add unique .N suffix if file exists...
253 sp = strchr(h->host, '/');
254 p = strchr(h->host, '?'); if (!sp || (p && sp > p)) sp = p;
255 p = strchr(h->host, '#'); if (!sp || (p && sp > p)) sp = p;
258 } else if (*sp == '/') {
261 } else { // '#' or '?'
262 // http://busybox.net?login=john@doe is a valid URL
263 // memmove converts to:
264 // http:/busybox.nett?login=john@doe...
265 memmove(h->host - 1, h->host, sp - h->host);
271 // We used to set h->user to NULL here, but this interferes
272 // with handling of code 302 ("object was moved")
274 sp = strrchr(h->host, '@');
284 static char *gethdr(FILE *fp)
291 /* retrieve header line */
292 c = fgets_and_trim(fp);
294 /* end of the headers? */
295 if (G.wget_buf[0] == '\0')
298 /* convert the header name to lower case */
299 for (s = G.wget_buf; isalnum(*s) || *s == '-' || *s == '.'; ++s) {
300 /* tolower for "A-Z", no-op for "0-9a-z-." */
304 /* verify we are at the end of the header name */
306 bb_error_msg_and_die("bad header line: %s", sanitize_string(G.wget_buf));
308 /* locate the start of the header value */
310 hdrval = skip_whitespace(s);
313 /* Rats! The buffer isn't big enough to hold the entire header value */
314 while (c = getc(fp), c != EOF && c != '\n')
321 #if ENABLE_FEATURE_WGET_LONG_OPTIONS
322 static char *URL_escape(const char *str)
324 /* URL encode, see RFC 2396 */
326 char *res = dst = xmalloc(strlen(str) * 3 + 1);
332 /* || strchr("!&'()*-.=_~", c) - more code */
344 || (c >= '0' && c <= '9')
345 || ((c|0x20) >= 'a' && (c|0x20) <= 'z')
352 *dst++ = bb_hexdigits_upcase[c >> 4];
353 *dst++ = bb_hexdigits_upcase[c & 0xf];
359 static FILE* prepare_ftp_session(FILE **dfpp, struct host_info *target, len_and_sockaddr *lsa)
366 target->user = xstrdup("anonymous:busybox@");
368 sfp = open_socket(lsa);
369 if (ftpcmd(NULL, NULL, sfp) != 220)
370 bb_error_msg_and_die("%s", sanitize_string(G.wget_buf + 4));
373 * Splitting username:password pair,
376 str = strchr(target->user, ':');
379 switch (ftpcmd("USER ", target->user, sfp)) {
383 if (ftpcmd("PASS ", str, sfp) == 230)
385 /* fall through (failed login) */
387 bb_error_msg_and_die("ftp login: %s", sanitize_string(G.wget_buf + 4));
390 ftpcmd("TYPE I", NULL, sfp);
395 if (ftpcmd("SIZE ", target->path, sfp) == 213) {
396 G.content_len = BB_STRTOOFF(G.wget_buf + 4, NULL, 10);
397 if (G.content_len < 0 || errno) {
398 bb_error_msg_and_die("SIZE value is garbage");
404 * Entering passive mode
406 if (ftpcmd("PASV", NULL, sfp) != 227) {
408 bb_error_msg_and_die("bad response to %s: %s", "PASV", sanitize_string(G.wget_buf));
410 // Response is "227 garbageN1,N2,N3,N4,P1,P2[)garbage]
411 // Server's IP is N1.N2.N3.N4 (we ignore it)
412 // Server's port for data connection is P1*256+P2
413 str = strrchr(G.wget_buf, ')');
414 if (str) str[0] = '\0';
415 str = strrchr(G.wget_buf, ',');
416 if (!str) goto pasv_error;
417 port = xatou_range(str+1, 0, 255);
419 str = strrchr(G.wget_buf, ',');
420 if (!str) goto pasv_error;
421 port += xatou_range(str+1, 0, 255) * 256;
422 set_nport(lsa, htons(port));
424 *dfpp = open_socket(lsa);
427 sprintf(G.wget_buf, "REST %"OFF_FMT"u", G.beg_range);
428 if (ftpcmd(G.wget_buf, NULL, sfp) == 350)
429 G.content_len -= G.beg_range;
432 if (ftpcmd("RETR ", target->path, sfp) > 150)
433 bb_error_msg_and_die("bad response to %s: %s", "RETR", sanitize_string(G.wget_buf));
438 static void NOINLINE retrieve_file_data(FILE *dfp)
440 #if ENABLE_FEATURE_WGET_STATUSBAR || ENABLE_FEATURE_WGET_TIMEOUT
441 # if ENABLE_FEATURE_WGET_TIMEOUT
444 struct pollfd polldata;
446 polldata.fd = fileno(dfp);
447 polldata.events = POLLIN | POLLPRI;
449 progress_meter(PROGRESS_START);
454 /* Loops only if chunked */
457 #if ENABLE_FEATURE_WGET_STATUSBAR || ENABLE_FEATURE_WGET_TIMEOUT
458 /* Must use nonblocking I/O, otherwise fread will loop
459 * and *block* until it reads full buffer,
460 * which messes up progress bar and/or timeout logic.
461 * Because of nonblocking I/O, we need to dance
462 * very carefully around EAGAIN. See explanation at
465 ndelay_on(polldata.fd);
471 rdsz = sizeof(G.wget_buf);
473 if (G.content_len < (off_t)sizeof(G.wget_buf)) {
474 if ((int)G.content_len <= 0)
476 rdsz = (unsigned)G.content_len;
480 #if ENABLE_FEATURE_WGET_STATUSBAR || ENABLE_FEATURE_WGET_TIMEOUT
481 # if ENABLE_FEATURE_WGET_TIMEOUT
482 second_cnt = G.timeout_seconds;
485 if (safe_poll(&polldata, 1, 1000) != 0)
486 break; /* error, EOF, or data is available */
487 # if ENABLE_FEATURE_WGET_TIMEOUT
488 if (second_cnt != 0 && --second_cnt == 0) {
489 progress_meter(PROGRESS_END);
490 bb_error_msg_and_die("download timed out");
493 /* Needed for "stalled" indicator */
494 progress_meter(PROGRESS_BUMP);
497 /* fread internally uses read loop, which in our case
498 * is usually exited when we get EAGAIN.
499 * In this case, libc sets error marker on the stream.
500 * Need to clear it before next fread to avoid possible
501 * rare false positive ferror below. Rare because usually
502 * fread gets more than zero bytes, and we don't fall
503 * into if (n <= 0) ...
508 n = fread(G.wget_buf, 1, rdsz, dfp);
510 * If error occurs, or EOF is reached, the return value
511 * is a short item count (or zero).
512 * fread does not distinguish between EOF and error.
515 #if ENABLE_FEATURE_WGET_STATUSBAR || ENABLE_FEATURE_WGET_TIMEOUT
516 if (errno == EAGAIN) /* poll lied, there is no data? */
520 bb_perror_msg_and_die(bb_msg_read_error);
521 break; /* EOF, not error */
524 xwrite(G.output_fd, G.wget_buf, n);
526 #if ENABLE_FEATURE_WGET_STATUSBAR
528 progress_meter(PROGRESS_BUMP);
532 if (G.content_len == 0)
536 #if ENABLE_FEATURE_WGET_STATUSBAR || ENABLE_FEATURE_WGET_TIMEOUT
538 ndelay_off(polldata.fd); /* else fgets can get very unhappy */
543 fgets_and_trim(dfp); /* Eat empty line */
546 G.content_len = STRTOOFF(G.wget_buf, NULL, 16);
547 /* FIXME: error check? */
548 if (G.content_len == 0)
549 break; /* all done! */
553 /* Draw full bar and free its resources */
554 G.chunked = 0; /* makes it show 100% even for chunked download */
555 G.got_clen = 1; /* makes it show 100% even for download of (formerly) unknown size */
556 progress_meter(PROGRESS_END);
559 static void download_one_url(const char *url)
561 bool use_proxy; /* Use proxies if env vars are set */
563 len_and_sockaddr *lsa;
564 FILE *sfp; /* socket to web/ftp server */
565 FILE *dfp; /* socket to ftp server (data) */
567 char *fname_out_alloc;
568 struct host_info server;
569 struct host_info target;
571 server.allocated = NULL;
572 target.allocated = NULL;
576 parse_url(url, &target);
578 /* Use the proxy if necessary */
579 use_proxy = (strcmp(G.proxy_flag, "off") != 0);
581 proxy = getenv(target.is_ftp ? "ftp_proxy" : "http_proxy");
582 use_proxy = (proxy && proxy[0]);
584 parse_url(proxy, &server);
587 server.port = target.port;
588 if (ENABLE_FEATURE_IPV6) {
589 //free(server.allocated); - can't be non-NULL
590 server.host = server.allocated = xstrdup(target.host);
592 server.host = target.host;
596 if (ENABLE_FEATURE_IPV6)
597 strip_ipv6_scope_id(target.host);
599 /* If there was no -O FILE, guess output filename */
600 fname_out_alloc = NULL;
601 if (!(option_mask32 & WGET_OPT_OUTNAME)) {
602 G.fname_out = bb_get_last_path_component_nostrip(target.path);
603 /* handle "wget http://kernel.org//" */
604 if (G.fname_out[0] == '/' || !G.fname_out[0])
605 G.fname_out = (char*)"index.html";
606 /* -P DIR is considered only if there was no -O FILE */
609 G.fname_out = fname_out_alloc = concat_path_file(G.dir_prefix, G.fname_out);
611 /* redirects may free target.path later, need to make a copy */
612 G.fname_out = fname_out_alloc = xstrdup(G.fname_out);
616 #if ENABLE_FEATURE_WGET_STATUSBAR
617 G.curfile = bb_get_last_path_component_nostrip(G.fname_out);
620 /* Determine where to start transfer */
622 if (option_mask32 & WGET_OPT_CONTINUE) {
623 G.output_fd = open(G.fname_out, O_WRONLY);
624 if (G.output_fd >= 0) {
625 G.beg_range = xlseek(G.output_fd, 0, SEEK_END);
627 /* File doesn't exist. We do not create file here yet.
628 * We are not sure it exists on remote side */
633 lsa = xhost2sockaddr(server.host, server.port);
634 if (!(option_mask32 & WGET_OPT_QUIET)) {
635 char *s = xmalloc_sockaddr2dotted(&lsa->u.sa);
636 fprintf(stderr, "Connecting to %s (%s)\n", server.host, s);
640 /*G.content_len = 0; - redundant, got_clen = 0 is enough */
643 if (use_proxy || !target.is_ftp) {
651 /* Open socket to http server */
652 sfp = open_socket(lsa);
654 /* Send HTTP request */
656 fprintf(sfp, "GET %stp://%s/%s HTTP/1.1\r\n",
657 target.is_ftp ? "f" : "ht", target.host,
660 if (option_mask32 & WGET_OPT_POST_DATA)
661 fprintf(sfp, "POST /%s HTTP/1.1\r\n", target.path);
663 fprintf(sfp, "GET /%s HTTP/1.1\r\n", target.path);
666 fprintf(sfp, "Host: %s\r\nUser-Agent: %s\r\n",
667 target.host, G.user_agent);
669 /* Ask server to close the connection as soon as we are done
670 * (IOW: we do not intend to send more requests)
672 fprintf(sfp, "Connection: close\r\n");
674 #if ENABLE_FEATURE_WGET_AUTHENTICATION
676 fprintf(sfp, "Proxy-Authorization: Basic %s\r\n"+6,
677 base64enc(target.user));
679 if (use_proxy && server.user) {
680 fprintf(sfp, "Proxy-Authorization: Basic %s\r\n",
681 base64enc(server.user));
686 fprintf(sfp, "Range: bytes=%"OFF_FMT"u-\r\n", G.beg_range);
688 #if ENABLE_FEATURE_WGET_LONG_OPTIONS
690 fputs(G.extra_headers, sfp);
692 if (option_mask32 & WGET_OPT_POST_DATA) {
693 char *estr = URL_escape(G.post_data);
695 "Content-Type: application/x-www-form-urlencoded\r\n"
696 "Content-Length: %u\r\n"
699 (int) strlen(estr), estr
705 fprintf(sfp, "\r\n");
711 * Retrieve HTTP response line and check for "200" status code.
717 str = skip_non_whitespace(str);
718 str = skip_whitespace(str);
719 // FIXME: no error check
720 // xatou wouldn't work: "200 OK"
725 while (gethdr(sfp) != NULL)
726 /* eat all remaining headers */;
730 Response 204 doesn't say "null file", it says "metadata
731 has changed but data didn't":
733 "10.2.5 204 No Content
734 The server has fulfilled the request but does not need to return
735 an entity-body, and might want to return updated metainformation.
736 The response MAY include new or updated metainformation in the form
737 of entity-headers, which if present SHOULD be associated with
738 the requested variant.
740 If the client is a user agent, it SHOULD NOT change its document
741 view from that which caused the request to be sent. This response
742 is primarily intended to allow input for actions to take place
743 without causing a change to the user agent's active document view,
744 although any new or updated metainformation SHOULD be applied
745 to the document currently in the user agent's active view.
747 The 204 response MUST NOT include a message-body, and thus
748 is always terminated by the first empty line after the header fields."
750 However, in real world it was observed that some web servers
751 (e.g. Boa/0.94.14rc21) simply use code 204 when file size is zero.
755 case 300: /* redirection */
765 bb_error_msg_and_die("server returned error: %s", sanitize_string(G.wget_buf));
769 * Retrieve HTTP headers.
771 while ((str = gethdr(sfp)) != NULL) {
772 static const char keywords[] ALIGN1 =
773 "content-length\0""transfer-encoding\0""location\0";
775 KEY_content_length = 1, KEY_transfer_encoding, KEY_location
779 /* gethdr converted "FOO:" string to lowercase */
781 /* strip trailing whitespace */
782 char *s = strchrnul(str, '\0') - 1;
783 while (s >= str && (*s == ' ' || *s == '\t')) {
787 key = index_in_strings(keywords, G.wget_buf) + 1;
788 if (key == KEY_content_length) {
789 G.content_len = BB_STRTOOFF(str, NULL, 10);
790 if (G.content_len < 0 || errno) {
791 bb_error_msg_and_die("content-length %s is garbage", sanitize_string(str));
796 if (key == KEY_transfer_encoding) {
797 if (strcmp(str_tolower(str), "chunked") != 0)
798 bb_error_msg_and_die("transfer encoding '%s' is not supported", sanitize_string(str));
801 if (key == KEY_location && status >= 300) {
802 if (--redir_limit == 0)
803 bb_error_msg_and_die("too many redirections");
806 free(target.allocated);
807 target.path = target.allocated = xstrdup(str+1);
808 /* lsa stays the same: it's on the same server */
810 parse_url(str, &target);
812 free(server.allocated);
813 server.allocated = NULL;
814 server.host = target.host;
815 /* strip_ipv6_scope_id(target.host); - no! */
816 /* we assume remote never gives us IPv6 addr with scope id */
817 server.port = target.port;
820 } /* else: lsa stays the same: we use proxy */
822 goto establish_session;
825 // if (status >= 300)
826 // bb_error_msg_and_die("bad redirection (no Location: header from server)");
828 /* For HTTP, data is pumped over the same connection */
835 sfp = prepare_ftp_session(&dfp, &target, lsa);
840 if (!(option_mask32 & WGET_OPT_SPIDER)) {
842 G.output_fd = xopen(G.fname_out, G.o_flags);
843 retrieve_file_data(dfp);
844 if (!(option_mask32 & WGET_OPT_OUTNAME)) {
851 /* It's ftp. Close data connection properly */
853 if (ftpcmd(NULL, NULL, sfp) != 226)
854 bb_error_msg_and_die("ftp error: %s", sanitize_string(G.wget_buf + 4));
855 /* ftpcmd("QUIT", NULL, sfp); - why bother? */
859 free(server.allocated);
860 free(target.allocated);
861 free(fname_out_alloc);
864 int wget_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
865 int wget_main(int argc UNUSED_PARAM, char **argv)
867 #if ENABLE_FEATURE_WGET_LONG_OPTIONS
868 static const char wget_longopts[] ALIGN1 =
869 /* name, has_arg, val */
870 "continue\0" No_argument "c"
871 //FIXME: -s isn't --spider, it's --save-headers!
872 "spider\0" No_argument "s"
873 "quiet\0" No_argument "q"
874 "output-document\0" Required_argument "O"
875 "directory-prefix\0" Required_argument "P"
876 "proxy\0" Required_argument "Y"
877 "user-agent\0" Required_argument "U"
878 #if ENABLE_FEATURE_WGET_TIMEOUT
879 "timeout\0" Required_argument "T"
882 // "tries\0" Required_argument "t"
883 /* Ignored (we always use PASV): */
884 "passive-ftp\0" No_argument "\xff"
885 "header\0" Required_argument "\xfe"
886 "post-data\0" Required_argument "\xfd"
887 /* Ignored (we don't do ssl) */
888 "no-check-certificate\0" No_argument "\xfc"
892 #if ENABLE_FEATURE_WGET_LONG_OPTIONS
893 llist_t *headers_llist = NULL;
898 IF_FEATURE_WGET_TIMEOUT(G.timeout_seconds = 900;)
899 G.proxy_flag = "on"; /* use proxies if env vars are set */
900 G.user_agent = "Wget"; /* "User-Agent" header field */
902 #if ENABLE_FEATURE_WGET_LONG_OPTIONS
903 applet_long_options = wget_longopts;
905 opt_complementary = "-1" IF_FEATURE_WGET_TIMEOUT(":T+") IF_FEATURE_WGET_LONG_OPTIONS(":\xfe::");
906 getopt32(argv, "csqO:P:Y:U:T:" /*ignored:*/ "t:",
907 &G.fname_out, &G.dir_prefix,
908 &G.proxy_flag, &G.user_agent,
909 IF_FEATURE_WGET_TIMEOUT(&G.timeout_seconds) IF_NOT_FEATURE_WGET_TIMEOUT(NULL),
910 NULL /* -t RETRIES */
911 IF_FEATURE_WGET_LONG_OPTIONS(, &headers_llist)
912 IF_FEATURE_WGET_LONG_OPTIONS(, &G.post_data)
916 #if ENABLE_FEATURE_WGET_LONG_OPTIONS
920 llist_t *ll = headers_llist;
922 size += strlen(ll->data) + 2;
925 G.extra_headers = cp = xmalloc(size);
926 while (headers_llist) {
927 cp += sprintf(cp, "%s\r\n", (char*)llist_pop(&headers_llist));
933 G.o_flags = O_WRONLY | O_CREAT | O_TRUNC | O_EXCL;
934 if (G.fname_out) { /* -O FILE ? */
935 if (LONE_DASH(G.fname_out)) { /* -O - ? */
937 option_mask32 &= ~WGET_OPT_CONTINUE;
939 /* compat with wget: -O FILE can overwrite */
940 G.o_flags = O_WRONLY | O_CREAT | O_TRUNC;
944 download_one_url(*argv++);
946 if (G.output_fd >= 0)