blob: 6c1aa74b7e4ca21c289283f1f6998510d87d62ed [file] [log] [blame]
Eric Andersen96700832000-09-04 15:15:55 +00001/* vi: set sw=4 ts=4: */
2/*
Eric Andersen79757c92001-04-05 21:45:54 +00003 * wget - retrieve a file using HTTP or FTP
Eric Andersen96700832000-09-04 15:15:55 +00004 *
Eric Andersen4e573f42000-11-14 23:29:24 +00005 * Chip Rosenthal Covad Communications <chip@laserlink.net>
Eric Andersenb520e082000-10-03 00:21:45 +00006 *
Eric Andersen96700832000-09-04 15:15:55 +00007 */
8
Eric Andersen96700832000-09-04 15:15:55 +00009#include <stdio.h>
Eric Andersendff9d542001-01-26 02:04:49 +000010#include <errno.h>
Eric Andersen96700832000-09-04 15:15:55 +000011#include <stdlib.h>
12#include <unistd.h>
13#include <ctype.h>
14#include <string.h>
Bernhard Reutner-Fischera2a647d2006-05-19 12:30:00 +000015#include <strings.h>
Eric Andersenb520e082000-10-03 00:21:45 +000016#include <unistd.h>
17#include <signal.h>
18#include <sys/ioctl.h>
Eric Andersen96700832000-09-04 15:15:55 +000019
20#include <sys/types.h>
21#include <sys/stat.h>
22#include <sys/socket.h>
23#include <netinet/in.h>
24#include <arpa/inet.h>
25#include <netdb.h>
26
Eric Andersen50ae3102001-05-15 17:51:37 +000027#include <getopt.h>
28
Eric Andersencbe31da2001-02-20 06:14:08 +000029#include "busybox.h"
30
Eric Andersen79757c92001-04-05 21:45:54 +000031struct host_info {
32 char *host;
33 int port;
34 char *path;
35 int is_ftp;
36 char *user;
37};
38
39static void parse_url(char *url, struct host_info *h);
Glenn L McGrathffccf6e2003-12-20 01:47:18 +000040static FILE *open_socket(struct sockaddr_in *s_in);
Eric Andersen3e6ff902001-03-09 21:24:12 +000041static char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc);
Eric Andersen79757c92001-04-05 21:45:54 +000042static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf);
Eric Andersen96700832000-09-04 15:15:55 +000043
Eric Andersenb520e082000-10-03 00:21:45 +000044/* Globals (can be accessed from signal handlers */
Rob Landley19a39402006-06-13 17:10:26 +000045static off_t filesize; /* content-length of the file */
46static int chunked; /* chunked transfer encoding */
Eric Andersenbdfd0d72001-10-24 05:00:29 +000047#ifdef CONFIG_FEATURE_WGET_STATUSBAR
Eric Andersen20aab262001-07-19 22:28:02 +000048static void progressmeter(int flag);
Rob Landley19a39402006-06-13 17:10:26 +000049static char *curfile; /* Name of current file being transferred. */
Eric Andersenb520e082000-10-03 00:21:45 +000050static struct timeval start; /* Time a transfer started. */
Rob Landley19a39402006-06-13 17:10:26 +000051static off_t transferred; /* Number of bytes transferred so far. */
Eric Andersenb520e082000-10-03 00:21:45 +000052/* For progressmeter() -- number of seconds before xfer considered "stalled" */
Rob Landley19a39402006-06-13 17:10:26 +000053enum {
54 STALLTIME = 5
55};
56#else
57static inline void progressmeter(int flag) {}
Eric Andersenb520e082000-10-03 00:21:45 +000058#endif
Eric Andersenc7bda1c2004-03-15 08:29:22 +000059
Eric Andersen3e6ff902001-03-09 21:24:12 +000060static void close_and_delete_outfile(FILE* output, char *fname_out, int do_continue)
Eric Andersen7d697012001-01-24 20:28:35 +000061{
62 if (output != stdout && do_continue==0) {
63 fclose(output);
64 unlink(fname_out);
65 }
66}
Eric Andersen96700832000-09-04 15:15:55 +000067
Matt Kraai854125f2001-05-09 19:15:46 +000068/* Read NMEMB elements of SIZE bytes into PTR from STREAM. Returns the
69 * number of elements read, and a short count if an eof or non-interrupt
70 * error is encountered. */
71static size_t safe_fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
72{
73 size_t ret = 0;
74
75 do {
76 clearerr(stream);
77 ret += fread((char *)ptr + (ret * size), size, nmemb - ret, stream);
78 } while (ret < nmemb && ferror(stream) && errno == EINTR);
79
80 return ret;
81}
82
83/* Write NMEMB elements of SIZE bytes from PTR to STREAM. Returns the
84 * number of elements written, and a short count if an eof or non-interrupt
85 * error is encountered. */
86static size_t safe_fwrite(void *ptr, size_t size, size_t nmemb, FILE *stream)
87{
88 size_t ret = 0;
89
90 do {
91 clearerr(stream);
92 ret += fwrite((char *)ptr + (ret * size), size, nmemb - ret, stream);
93 } while (ret < nmemb && ferror(stream) && errno == EINTR);
94
95 return ret;
96}
97
98/* Read a line or SIZE - 1 bytes into S, whichever is less, from STREAM.
99 * Returns S, or NULL if an eof or non-interrupt error is encountered. */
100static char *safe_fgets(char *s, int size, FILE *stream)
101{
102 char *ret;
103
104 do {
105 clearerr(stream);
106 ret = fgets(s, size, stream);
107 } while (ret == NULL && ferror(stream) && errno == EINTR);
108
109 return ret;
110}
111
Eric Andersen79757c92001-04-05 21:45:54 +0000112#define close_delete_and_die(s...) { \
113 close_and_delete_outfile(output, fname_out, do_continue); \
Manuel Novoa III cad53642003-03-19 09:13:01 +0000114 bb_error_msg_and_die(s); }
Eric Andersen79757c92001-04-05 21:45:54 +0000115
116
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000117#ifdef CONFIG_FEATURE_WGET_AUTHENTICATION
Eric Andersen79757c92001-04-05 21:45:54 +0000118/*
119 * Base64-encode character string
120 * oops... isn't something similar in uuencode.c?
Eric Andersen14f5c8d2005-04-16 19:39:00 +0000121 * XXX: It would be better to use already existing code
Eric Andersen79757c92001-04-05 21:45:54 +0000122 */
Eric Andersen14f5c8d2005-04-16 19:39:00 +0000123static char *base64enc(unsigned char *p, char *buf, int len) {
Eric Andersen79757c92001-04-05 21:45:54 +0000124
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000125 char al[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
126 "0123456789+/";
Rob Landley76ef08c2006-06-13 16:44:26 +0000127 char *s = buf;
Eric Andersen79757c92001-04-05 21:45:54 +0000128
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000129 while(*p) {
Rob Landley76ef08c2006-06-13 16:44:26 +0000130 if (s >= buf+len-4)
131 bb_error_msg_and_die("buffer overflow");
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000132 *(s++) = al[(*p >> 2) & 0x3F];
133 *(s++) = al[((*p << 4) & 0x30) | ((*(p+1) >> 4) & 0x0F)];
134 *s = *(s+1) = '=';
135 *(s+2) = 0;
136 if (! *(++p)) break;
137 *(s++) = al[((*p << 2) & 0x3C) | ((*(p+1) >> 6) & 0x03)];
138 if (! *(++p)) break;
139 *(s++) = al[*(p++) & 0x3F];
140 }
Eric Andersen79757c92001-04-05 21:45:54 +0000141
Rob Landley76ef08c2006-06-13 16:44:26 +0000142 return buf;
Eric Andersen79757c92001-04-05 21:45:54 +0000143}
144#endif
145
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000146#define WGET_OPT_CONTINUE 1
147#define WGET_OPT_QUIET 2
148#define WGET_OPT_PASSIVE 4
149#define WGET_OPT_OUTNAME 8
150#define WGET_OPT_HEADER 16
151#define WGET_OPT_PREFIX 32
152#define WGET_OPT_PROXY 64
153
Bernhard Reutner-Fischer8d3a6f72006-05-31 14:11:38 +0000154#if ENABLE_WGET_LONG_OPTIONS
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000155static const struct option wget_long_options[] = {
156 { "continue", 0, NULL, 'c' },
157 { "quiet", 0, NULL, 'q' },
158 { "passive-ftp", 0, NULL, 139 },
159 { "output-document", 1, NULL, 'O' },
Rob Landley76ef08c2006-06-13 16:44:26 +0000160 { "header", 1, NULL, 131 },
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000161 { "directory-prefix",1, NULL, 'P' },
162 { "proxy", 1, NULL, 'Y' },
163 { 0, 0, 0, 0 }
164};
Bernhard Reutner-Fischer8d3a6f72006-05-31 14:11:38 +0000165#endif
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000166
Eric Andersen96700832000-09-04 15:15:55 +0000167int wget_main(int argc, char **argv)
168{
Eric Andersen79757c92001-04-05 21:45:54 +0000169 int n, try=5, status;
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000170 unsigned long opt;
Eric Andersen79757c92001-04-05 21:45:54 +0000171 int port;
Robert Griebld7760112002-05-14 23:36:45 +0000172 char *proxy = 0;
Eric Andersen8071c022001-06-21 19:45:06 +0000173 char *dir_prefix=NULL;
Eric Andersen29edd002000-12-09 16:55:35 +0000174 char *s, buf[512];
175 struct stat sbuf;
Eric Andersen50ae3102001-05-15 17:51:37 +0000176 char extra_headers[1024];
177 char *extra_headers_ptr = extra_headers;
178 int extra_headers_left = sizeof(extra_headers);
Eric Andersen79757c92001-04-05 21:45:54 +0000179 struct host_info server, target;
Eric Andersene6dc4392003-10-31 09:31:46 +0000180 struct sockaddr_in s_in;
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000181 llist_t *headers_llist = NULL;
Eric Andersen79757c92001-04-05 21:45:54 +0000182
"Vladimir N. Oleynik"f704b272005-10-14 09:56:52 +0000183 FILE *sfp = NULL; /* socket to web/ftp server */
184 FILE *dfp = NULL; /* socket to ftp server (data) */
185 char *fname_out = NULL; /* where to direct output (-O) */
186 int do_continue = 0; /* continue a prev transfer (-c) */
187 long beg_range = 0L; /* range at which continue begins */
188 int got_clen = 0; /* got content-length: from server */
189 FILE *output; /* socket to web server */
190 int quiet_flag = FALSE; /* Be verry, verry quiet... */
191 int use_proxy = 1; /* Use proxies if env vars are set */
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000192 char *proxy_flag = "on"; /* Use proxies if env vars are set */
Eric Andersen29edd002000-12-09 16:55:35 +0000193
Eric Andersen96700832000-09-04 15:15:55 +0000194 /*
195 * Crack command line.
196 */
"Vladimir N. Oleynik"f704b272005-10-14 09:56:52 +0000197 bb_opt_complementally = "-1:\203::";
Bernhard Reutner-Fischer8d3a6f72006-05-31 14:11:38 +0000198#if ENABLE_WGET_LONG_OPTIONS
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000199 bb_applet_long_options = wget_long_options;
Bernhard Reutner-Fischer8d3a6f72006-05-31 14:11:38 +0000200#endif
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000201 opt = bb_getopt_ulflags(argc, argv, "cq\213O:\203:P:Y:",
202 &fname_out, &headers_llist,
"Vladimir N. Oleynik"f704b272005-10-14 09:56:52 +0000203 &dir_prefix, &proxy_flag);
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000204 if (opt & WGET_OPT_CONTINUE) {
205 ++do_continue;
206 }
207 if (opt & WGET_OPT_QUIET) {
208 quiet_flag = TRUE;
209 }
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000210 if (strcmp(proxy_flag, "off") == 0) {
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000211 /* Use the proxy if necessary. */
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000212 use_proxy = 0;
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000213 }
214 if (opt & WGET_OPT_HEADER) {
215 while (headers_llist) {
216 int arglen = strlen(headers_llist->data);
217 if (extra_headers_left - arglen - 2 <= 0)
218 bb_error_msg_and_die("extra_headers buffer too small(need %i)", extra_headers_left - arglen);
219 strcpy(extra_headers_ptr, headers_llist->data);
220 extra_headers_ptr += arglen;
221 extra_headers_left -= ( arglen + 2 );
222 *extra_headers_ptr++ = '\r';
223 *extra_headers_ptr++ = '\n';
224 *(extra_headers_ptr + 1) = 0;
225 headers_llist = headers_llist->link;
Eric Andersen96700832000-09-04 15:15:55 +0000226 }
227 }
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000228
Eric Andersen79757c92001-04-05 21:45:54 +0000229 parse_url(argv[optind], &target);
230 server.host = target.host;
231 server.port = target.port;
232
Eric Andersen96700832000-09-04 15:15:55 +0000233 /*
Eric Andersenf3b2b522000-12-07 22:42:11 +0000234 * Use the proxy if necessary.
Eric Andersen96700832000-09-04 15:15:55 +0000235 */
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000236 if (use_proxy) {
Robert Griebld7760112002-05-14 23:36:45 +0000237 proxy = getenv(target.is_ftp ? "ftp_proxy" : "http_proxy");
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000238 if (proxy && *proxy) {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000239 parse_url(bb_xstrdup(proxy), &server);
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000240 } else {
241 use_proxy = 0;
242 }
Robert Griebld7760112002-05-14 23:36:45 +0000243 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000244
Eric Andersen29edd002000-12-09 16:55:35 +0000245 /* Guess an output filename */
246 if (!fname_out) {
Eric Andersen751750e2004-10-08 08:27:40 +0000247 // Dirty hack. Needed because bb_get_last_path_component
248 // will destroy trailing / by storing '\0' in last byte!
Rob Landley6f2a0b22006-02-21 18:34:54 +0000249 if(*target.path && target.path[strlen(target.path)-1]!='/') {
Eric Andersen751750e2004-10-08 08:27:40 +0000250 fname_out =
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000251#ifdef CONFIG_FEATURE_WGET_STATUSBAR
Eric Andersen751750e2004-10-08 08:27:40 +0000252 curfile =
Eric Andersen29edd002000-12-09 16:55:35 +0000253#endif
Eric Andersen751750e2004-10-08 08:27:40 +0000254 bb_get_last_path_component(target.path);
255 }
Eric Andersen29edd002000-12-09 16:55:35 +0000256 if (fname_out==NULL || strlen(fname_out)<1) {
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000257 fname_out =
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000258#ifdef CONFIG_FEATURE_WGET_STATUSBAR
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000259 curfile =
Eric Andersen29edd002000-12-09 16:55:35 +0000260#endif
261 "index.html";
262 }
Matt Kraai0382eb82001-07-19 19:13:55 +0000263 if (dir_prefix != NULL)
264 fname_out = concat_path_file(dir_prefix, fname_out);
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000265#ifdef CONFIG_FEATURE_WGET_STATUSBAR
Eric Andersen29edd002000-12-09 16:55:35 +0000266 } else {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000267 curfile = bb_get_last_path_component(fname_out);
Eric Andersen29edd002000-12-09 16:55:35 +0000268#endif
269 }
Eric Andersen7d697012001-01-24 20:28:35 +0000270 if (do_continue && !fname_out)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000271 bb_error_msg_and_die("cannot specify continue (-c) without a filename (-O)");
Eric Andersen29edd002000-12-09 16:55:35 +0000272
Eric Andersen96700832000-09-04 15:15:55 +0000273
274 /*
Eric Andersen29edd002000-12-09 16:55:35 +0000275 * Open the output file stream.
Eric Andersen96700832000-09-04 15:15:55 +0000276 */
Matt Kraai65317ea2001-04-11 20:03:01 +0000277 if (strcmp(fname_out, "-") == 0) {
Randolph Chung02553a22000-12-07 03:53:47 +0000278 output = stdout;
Eric Andersen95a349f2001-05-13 00:55:54 +0000279 quiet_flag = TRUE;
Matt Kraai65317ea2001-04-11 20:03:01 +0000280 } else {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000281 output = bb_xfopen(fname_out, (do_continue ? "a" : "w"));
Eric Andersen96700832000-09-04 15:15:55 +0000282 }
283
284 /*
285 * Determine where to start transfer.
286 */
287 if (do_continue) {
Eric Andersenb520e082000-10-03 00:21:45 +0000288 if (fstat(fileno(output), &sbuf) < 0)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000289 bb_perror_msg_and_die("fstat()");
Eric Andersen96700832000-09-04 15:15:55 +0000290 if (sbuf.st_size > 0)
291 beg_range = sbuf.st_size;
292 else
293 do_continue = 0;
294 }
295
Eric Andersene6dc4392003-10-31 09:31:46 +0000296 /* We want to do exactly _one_ DNS lookup, since some
297 * sites (i.e. ftp.us.debian.org) use round-robin DNS
298 * and we want to connect to only one IP... */
Glenn L McGrathffccf6e2003-12-20 01:47:18 +0000299 bb_lookup_host(&s_in, server.host);
300 s_in.sin_port = server.port;
Eric Andersene6dc4392003-10-31 09:31:46 +0000301 if (quiet_flag==FALSE) {
302 fprintf(stdout, "Connecting to %s[%s]:%d\n",
Glenn L McGrathffccf6e2003-12-20 01:47:18 +0000303 server.host, inet_ntoa(s_in.sin_addr), ntohs(server.port));
Eric Andersene6dc4392003-10-31 09:31:46 +0000304 }
305
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000306 if (use_proxy || !target.is_ftp) {
Eric Andersen79757c92001-04-05 21:45:54 +0000307 /*
308 * HTTP session
309 */
310 do {
Glenn L McGrathe7bdfcc2003-08-28 22:03:19 +0000311 got_clen = chunked = 0;
312
Eric Andersen79757c92001-04-05 21:45:54 +0000313 if (! --try)
314 close_delete_and_die("too many redirections");
Eric Andersen7d697012001-01-24 20:28:35 +0000315
Eric Andersen79757c92001-04-05 21:45:54 +0000316 /*
317 * Open socket to http server
318 */
319 if (sfp) fclose(sfp);
Glenn L McGrathffccf6e2003-12-20 01:47:18 +0000320 sfp = open_socket(&s_in);
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000321
Eric Andersen79757c92001-04-05 21:45:54 +0000322 /*
323 * Send HTTP request.
324 */
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000325 if (use_proxy) {
Glenn L McGrathcc20ebc2003-09-10 23:52:15 +0000326 const char *format = "GET %stp://%s:%d/%s HTTP/1.1\r\n";
327#ifdef CONFIG_FEATURE_WGET_IP6_LITERAL
Rob Landley19a39402006-06-13 17:10:26 +0000328 if (strchr(target.host, ':'))
Glenn L McGrathcc20ebc2003-09-10 23:52:15 +0000329 format = "GET %stp://[%s]:%d/%s HTTP/1.1\r\n";
330#endif
331 fprintf(sfp, format,
Eric Andersen79757c92001-04-05 21:45:54 +0000332 target.is_ftp ? "f" : "ht", target.host,
Glenn L McGrath24cb17f2004-01-31 08:08:57 +0000333 ntohs(target.port), target.path);
Eric Andersen79757c92001-04-05 21:45:54 +0000334 } else {
Eric Andersen6d7fa432001-04-10 18:17:05 +0000335 fprintf(sfp, "GET /%s HTTP/1.1\r\n", target.path);
Eric Andersen79757c92001-04-05 21:45:54 +0000336 }
Eric Andersen96700832000-09-04 15:15:55 +0000337
Eric Andersen79757c92001-04-05 21:45:54 +0000338 fprintf(sfp, "Host: %s\r\nUser-Agent: Wget\r\n", target.host);
339
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000340#ifdef CONFIG_FEATURE_WGET_AUTHENTICATION
Eric Andersen79757c92001-04-05 21:45:54 +0000341 if (target.user) {
342 fprintf(sfp, "Authorization: Basic %s\r\n",
Eric Andersen0cb6f352006-01-30 22:30:41 +0000343 base64enc((unsigned char*)target.user, buf, sizeof(buf)));
Eric Andersen79757c92001-04-05 21:45:54 +0000344 }
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000345 if (use_proxy && server.user) {
Eric Andersen79757c92001-04-05 21:45:54 +0000346 fprintf(sfp, "Proxy-Authorization: Basic %s\r\n",
Eric Andersen0cb6f352006-01-30 22:30:41 +0000347 base64enc((unsigned char*)server.user, buf, sizeof(buf)));
Eric Andersen79757c92001-04-05 21:45:54 +0000348 }
349#endif
350
Eric Andersenb520e082000-10-03 00:21:45 +0000351 if (do_continue)
Eric Andersen79757c92001-04-05 21:45:54 +0000352 fprintf(sfp, "Range: bytes=%ld-\r\n", beg_range);
Eric Andersen50ae3102001-05-15 17:51:37 +0000353 if(extra_headers_left < sizeof(extra_headers))
Eric Andersen9abfe852001-05-15 20:11:49 +0000354 fputs(extra_headers,sfp);
Eric Andersen79757c92001-04-05 21:45:54 +0000355 fprintf(sfp,"Connection: close\r\n\r\n");
356
357 /*
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000358 * Retrieve HTTP response line and check for "200" status code.
359 */
Glenn L McGrathe7bdfcc2003-08-28 22:03:19 +0000360read_response:
361 if (fgets(buf, sizeof(buf), sfp) == NULL)
Eric Andersen79757c92001-04-05 21:45:54 +0000362 close_delete_and_die("no response from server");
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000363
Eric Andersen79757c92001-04-05 21:45:54 +0000364 for (s = buf ; *s != '\0' && !isspace(*s) ; ++s)
Rob Landley76ef08c2006-06-13 16:44:26 +0000365 ;
Eric Andersen79757c92001-04-05 21:45:54 +0000366 for ( ; isspace(*s) ; ++s)
Rob Landley76ef08c2006-06-13 16:44:26 +0000367 ;
Eric Andersen79757c92001-04-05 21:45:54 +0000368 switch (status = atoi(s)) {
369 case 0:
Eric Andersen6d7fa432001-04-10 18:17:05 +0000370 case 100:
371 while (gethdr(buf, sizeof(buf), sfp, &n) != NULL);
372 goto read_response;
Eric Andersen79757c92001-04-05 21:45:54 +0000373 case 200:
374 if (do_continue && output != stdout)
375 output = freopen(fname_out, "w", output);
376 do_continue = 0;
377 break;
378 case 300: /* redirection */
379 case 301:
380 case 302:
381 case 303:
382 break;
383 case 206:
384 if (do_continue)
385 break;
386 /*FALLTHRU*/
387 default:
388 chomp(buf);
389 close_delete_and_die("server returned error %d: %s", atoi(s), buf);
390 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000391
Eric Andersen79757c92001-04-05 21:45:54 +0000392 /*
393 * Retrieve HTTP headers.
394 */
395 while ((s = gethdr(buf, sizeof(buf), sfp, &n)) != NULL) {
396 if (strcasecmp(buf, "content-length") == 0) {
Eric Andersen24794452004-03-06 22:11:45 +0000397 unsigned long value;
398 if (safe_strtoul(s, &value)) {
399 close_delete_and_die("content-length %s is garbage", s);
400 }
401 filesize = value;
Eric Andersen79757c92001-04-05 21:45:54 +0000402 got_clen = 1;
403 continue;
404 }
Eric Andersen6d7fa432001-04-10 18:17:05 +0000405 if (strcasecmp(buf, "transfer-encoding") == 0) {
406 if (strcasecmp(s, "chunked") == 0) {
407 chunked = got_clen = 1;
408 } else {
Rob Landley76ef08c2006-06-13 16:44:26 +0000409 close_delete_and_die("server wants to do %s transfer encoding", s);
Eric Andersen6d7fa432001-04-10 18:17:05 +0000410 }
411 }
Eric Andersen79757c92001-04-05 21:45:54 +0000412 if (strcasecmp(buf, "location") == 0) {
413 if (s[0] == '/')
Manuel Novoa III cad53642003-03-19 09:13:01 +0000414 target.path = bb_xstrdup(s+1);
Eric Andersen79757c92001-04-05 21:45:54 +0000415 else {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000416 parse_url(bb_xstrdup(s), &target);
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000417 if (use_proxy == 0) {
Eric Andersen79757c92001-04-05 21:45:54 +0000418 server.host = target.host;
419 server.port = target.port;
420 }
Glenn L McGrath58a2e0e2004-01-17 23:07:14 +0000421 bb_lookup_host(&s_in, server.host);
422 s_in.sin_port = server.port;
423 break;
Eric Andersen79757c92001-04-05 21:45:54 +0000424 }
425 }
426 }
427 } while(status >= 300);
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000428
Eric Andersen79757c92001-04-05 21:45:54 +0000429 dfp = sfp;
430 }
431 else
432 {
433 /*
434 * FTP session
435 */
436 if (! target.user)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000437 target.user = bb_xstrdup("anonymous:busybox@");
Eric Andersen79757c92001-04-05 21:45:54 +0000438
Glenn L McGrathffccf6e2003-12-20 01:47:18 +0000439 sfp = open_socket(&s_in);
Eric Andersen79757c92001-04-05 21:45:54 +0000440 if (ftpcmd(NULL, NULL, sfp, buf) != 220)
441 close_delete_and_die("%s", buf+4);
442
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000443 /*
Eric Andersen79757c92001-04-05 21:45:54 +0000444 * Splitting username:password pair,
445 * trying to log in
446 */
447 s = strchr(target.user, ':');
448 if (s)
449 *(s++) = '\0';
450 switch(ftpcmd("USER ", target.user, sfp, buf)) {
451 case 230:
Eric Andersenb520e082000-10-03 00:21:45 +0000452 break;
Eric Andersen79757c92001-04-05 21:45:54 +0000453 case 331:
454 if (ftpcmd("PASS ", s, sfp, buf) == 230)
455 break;
456 /* FALLTHRU (failed login) */
457 default:
458 close_delete_and_die("ftp login: %s", buf+4);
459 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000460
Eric Andersen79757c92001-04-05 21:45:54 +0000461 ftpcmd("CDUP", NULL, sfp, buf);
462 ftpcmd("TYPE I", NULL, sfp, buf);
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000463
Eric Andersen79757c92001-04-05 21:45:54 +0000464 /*
465 * Querying file size
466 */
467 if (ftpcmd("SIZE /", target.path, sfp, buf) == 213) {
Eric Andersen24794452004-03-06 22:11:45 +0000468 unsigned long value;
469 if (safe_strtoul(buf+4, &value)) {
470 close_delete_and_die("SIZE value is garbage");
471 }
472 filesize = value;
Eric Andersen96700832000-09-04 15:15:55 +0000473 got_clen = 1;
Eric Andersen96700832000-09-04 15:15:55 +0000474 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000475
Eric Andersen79757c92001-04-05 21:45:54 +0000476 /*
477 * Entering passive mode
478 */
479 if (ftpcmd("PASV", NULL, sfp, buf) != 227)
480 close_delete_and_die("PASV: %s", buf+4);
481 s = strrchr(buf, ',');
482 *s = 0;
483 port = atoi(s+1);
484 s = strrchr(buf, ',');
485 port += atoi(s+1) * 256;
Glenn L McGrathffccf6e2003-12-20 01:47:18 +0000486 s_in.sin_port = htons(port);
487 dfp = open_socket(&s_in);
Eric Andersen79757c92001-04-05 21:45:54 +0000488
489 if (do_continue) {
490 sprintf(buf, "REST %ld", beg_range);
491 if (ftpcmd(buf, NULL, sfp, buf) != 350) {
492 if (output != stdout)
493 output = freopen(fname_out, "w", output);
494 do_continue = 0;
495 } else
496 filesize -= beg_range;
Eric Andersen96700832000-09-04 15:15:55 +0000497 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000498
Eric Andersen79757c92001-04-05 21:45:54 +0000499 if (ftpcmd("RETR /", target.path, sfp, buf) > 150)
500 close_delete_and_die("RETR: %s", buf+4);
Eric Andersen96700832000-09-04 15:15:55 +0000501 }
502
Eric Andersen79757c92001-04-05 21:45:54 +0000503
Eric Andersen96700832000-09-04 15:15:55 +0000504 /*
Eric Andersen79757c92001-04-05 21:45:54 +0000505 * Retrieve file
Eric Andersen96700832000-09-04 15:15:55 +0000506 */
Eric Andersen6d7fa432001-04-10 18:17:05 +0000507 if (chunked) {
508 fgets(buf, sizeof(buf), dfp);
509 filesize = strtol(buf, (char **) NULL, 16);
510 }
Rob Landley19a39402006-06-13 17:10:26 +0000511
Glenn L McGrath1bca5ed2000-12-09 08:12:06 +0000512 if (quiet_flag==FALSE)
513 progressmeter(-1);
Rob Landley19a39402006-06-13 17:10:26 +0000514
Mark Whitley30ac01c2001-04-17 18:13:16 +0000515 do {
Glenn L McGrath23365972003-08-29 06:25:04 +0000516 while ((filesize > 0 || !got_clen) && (n = safe_fread(buf, 1, ((chunked || got_clen) && (filesize < sizeof(buf)) ? filesize : sizeof(buf)), dfp)) > 0) {
Glenn L McGrath83e4a5b2003-08-28 21:55:22 +0000517 if (safe_fwrite(buf, 1, n, output) != n) {
Bernhard Reutner-Fischer1b9d7c92006-06-03 22:45:37 +0000518 bb_perror_msg_and_die(bb_msg_write_error);
Glenn L McGrath83e4a5b2003-08-28 21:55:22 +0000519 }
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000520#ifdef CONFIG_FEATURE_WGET_STATUSBAR
Rob Landley19a39402006-06-13 17:10:26 +0000521 transferred += n;
Eric Andersenb520e082000-10-03 00:21:45 +0000522#endif
Glenn L McGrath83e4a5b2003-08-28 21:55:22 +0000523 if (got_clen) {
524 filesize -= n;
525 }
526 }
Eric Andersen79757c92001-04-05 21:45:54 +0000527
Eric Andersen6d7fa432001-04-10 18:17:05 +0000528 if (chunked) {
Matt Kraai854125f2001-05-09 19:15:46 +0000529 safe_fgets(buf, sizeof(buf), dfp); /* This is a newline */
530 safe_fgets(buf, sizeof(buf), dfp);
Eric Andersen6d7fa432001-04-10 18:17:05 +0000531 filesize = strtol(buf, (char **) NULL, 16);
Glenn L McGrath83e4a5b2003-08-28 21:55:22 +0000532 if (filesize==0) {
533 chunked = 0; /* all done! */
534 }
Eric Andersen6d7fa432001-04-10 18:17:05 +0000535 }
536
Glenn L McGrath83e4a5b2003-08-28 21:55:22 +0000537 if (n == 0 && ferror(dfp)) {
Bernhard Reutner-Fischer1b9d7c92006-06-03 22:45:37 +0000538 bb_perror_msg_and_die(bb_msg_read_error);
Glenn L McGrath83e4a5b2003-08-28 21:55:22 +0000539 }
Eric Andersen6d7fa432001-04-10 18:17:05 +0000540 } while (chunked);
Rob Landley19a39402006-06-13 17:10:26 +0000541
Mark Whitley30ac01c2001-04-17 18:13:16 +0000542 if (quiet_flag==FALSE)
543 progressmeter(1);
Rob Landley19a39402006-06-13 17:10:26 +0000544
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000545 if ((use_proxy == 0) && target.is_ftp) {
Eric Andersen79757c92001-04-05 21:45:54 +0000546 fclose(dfp);
547 if (ftpcmd(NULL, NULL, sfp, buf) != 226)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000548 bb_error_msg_and_die("ftp error: %s", buf+4);
Eric Andersen79757c92001-04-05 21:45:54 +0000549 ftpcmd("QUIT", NULL, sfp, buf);
550 }
Eric Andersen79757c92001-04-05 21:45:54 +0000551 exit(EXIT_SUCCESS);
Eric Andersen96700832000-09-04 15:15:55 +0000552}
553
554
Eric Andersen79757c92001-04-05 21:45:54 +0000555void parse_url(char *url, struct host_info *h)
Eric Andersen96700832000-09-04 15:15:55 +0000556{
Glenn L McGrathcc20ebc2003-09-10 23:52:15 +0000557 char *cp, *sp, *up, *pp;
Eric Andersen96700832000-09-04 15:15:55 +0000558
Eric Andersen79757c92001-04-05 21:45:54 +0000559 if (strncmp(url, "http://", 7) == 0) {
Glenn L McGrath036dbaa2004-01-17 05:03:31 +0000560 h->port = bb_lookup_port("http", "tcp", 80);
Eric Andersen79757c92001-04-05 21:45:54 +0000561 h->host = url + 7;
562 h->is_ftp = 0;
563 } else if (strncmp(url, "ftp://", 6) == 0) {
Glenn L McGrath036dbaa2004-01-17 05:03:31 +0000564 h->port = bb_lookup_port("ftp", "tfp", 21);
Eric Andersen79757c92001-04-05 21:45:54 +0000565 h->host = url + 6;
566 h->is_ftp = 1;
567 } else
Manuel Novoa III cad53642003-03-19 09:13:01 +0000568 bb_error_msg_and_die("not an http or ftp url: %s", url);
Eric Andersen96700832000-09-04 15:15:55 +0000569
Eric Andersen79757c92001-04-05 21:45:54 +0000570 sp = strchr(h->host, '/');
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000571 if (sp) {
Matt Kraaia9711a52001-01-03 16:15:15 +0000572 *sp++ = '\0';
Eric Andersen79757c92001-04-05 21:45:54 +0000573 h->path = sp;
Matt Kraaia9711a52001-01-03 16:15:15 +0000574 } else
Manuel Novoa III cad53642003-03-19 09:13:01 +0000575 h->path = bb_xstrdup("");
Eric Andersen79757c92001-04-05 21:45:54 +0000576
577 up = strrchr(h->host, '@');
578 if (up != NULL) {
579 h->user = h->host;
580 *up++ = '\0';
581 h->host = up;
582 } else
583 h->user = NULL;
584
Glenn L McGrathcc20ebc2003-09-10 23:52:15 +0000585 pp = h->host;
586
587#ifdef CONFIG_FEATURE_WGET_IP6_LITERAL
588 if (h->host[0] == '[') {
589 char *ep;
590
591 ep = h->host + 1;
Eric Andersen6231f092003-09-11 08:25:11 +0000592 while (*ep == ':' || isxdigit (*ep))
Glenn L McGrathcc20ebc2003-09-10 23:52:15 +0000593 ep++;
594 if (*ep == ']') {
595 h->host++;
596 *ep = '\0';
597 pp = ep + 1;
598 }
599 }
600#endif
601
602 cp = strchr(pp, ':');
Eric Andersen79757c92001-04-05 21:45:54 +0000603 if (cp != NULL) {
604 *cp++ = '\0';
Glenn L McGrathf980bd52003-12-27 00:21:47 +0000605 h->port = htons(atoi(cp));
Eric Andersen79757c92001-04-05 21:45:54 +0000606 }
Eric Andersen96700832000-09-04 15:15:55 +0000607}
608
609
Glenn L McGrathffccf6e2003-12-20 01:47:18 +0000610FILE *open_socket(struct sockaddr_in *s_in)
Eric Andersen96700832000-09-04 15:15:55 +0000611{
Eric Andersen96700832000-09-04 15:15:55 +0000612 FILE *fp;
613
Glenn L McGrathffccf6e2003-12-20 01:47:18 +0000614 fp = fdopen(xconnect(s_in), "r+");
615 if (fp == NULL)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000616 bb_perror_msg_and_die("fdopen()");
Eric Andersen96700832000-09-04 15:15:55 +0000617
618 return fp;
619}
620
621
622char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc)
623{
624 char *s, *hdrval;
625 int c;
626
627 *istrunc = 0;
628
629 /* retrieve header line */
630 if (fgets(buf, bufsiz, fp) == NULL)
631 return NULL;
632
633 /* see if we are at the end of the headers */
634 for (s = buf ; *s == '\r' ; ++s)
635 ;
636 if (s[0] == '\n')
637 return NULL;
638
639 /* convert the header name to lower case */
640 for (s = buf ; isalnum(*s) || *s == '-' ; ++s)
641 *s = tolower(*s);
642
643 /* verify we are at the end of the header name */
644 if (*s != ':')
Manuel Novoa III cad53642003-03-19 09:13:01 +0000645 bb_error_msg_and_die("bad header line: %s", buf);
Eric Andersen96700832000-09-04 15:15:55 +0000646
647 /* locate the start of the header value */
648 for (*s++ = '\0' ; *s == ' ' || *s == '\t' ; ++s)
649 ;
650 hdrval = s;
651
652 /* locate the end of header */
653 while (*s != '\0' && *s != '\r' && *s != '\n')
654 ++s;
655
656 /* end of header found */
657 if (*s != '\0') {
658 *s = '\0';
659 return hdrval;
660 }
661
Eric Andersen5d638842000-09-14 21:46:30 +0000662 /* Rats! The buffer isn't big enough to hold the entire header value. */
Eric Andersen96700832000-09-04 15:15:55 +0000663 while (c = getc(fp), c != EOF && c != '\n')
664 ;
665 *istrunc = 1;
666 return hdrval;
667}
668
Eric Andersen79757c92001-04-05 21:45:54 +0000669static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf)
670{
Eric Andersen79757c92001-04-05 21:45:54 +0000671 if (s1) {
672 if (!s2) s2="";
Eric Andersen3f1cf452003-03-11 18:03:39 +0000673 fprintf(fp, "%s%s\r\n", s1, s2);
Eric Andersen79757c92001-04-05 21:45:54 +0000674 fflush(fp);
675 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000676
Eric Andersen79757c92001-04-05 21:45:54 +0000677 do {
Glenn L McGrath32da8852004-04-08 10:27:11 +0000678 char *buf_ptr;
679
680 if (fgets(buf, 510, fp) == NULL) {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000681 bb_perror_msg_and_die("fgets()");
Glenn L McGrath32da8852004-04-08 10:27:11 +0000682 }
683 buf_ptr = strstr(buf, "\r\n");
684 if (buf_ptr) {
685 *buf_ptr = '\0';
686 }
Eric Andersen79757c92001-04-05 21:45:54 +0000687 } while (! isdigit(buf[0]) || buf[3] != ' ');
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000688
Eric Andersen79757c92001-04-05 21:45:54 +0000689 return atoi(buf);
690}
691
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000692#ifdef CONFIG_FEATURE_WGET_STATUSBAR
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000693/* Stuff below is from BSD rcp util.c, as added to openshh.
Eric Andersen4e573f42000-11-14 23:29:24 +0000694 * Original copyright notice is retained at the end of this file.
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000695 *
696 */
Eric Andersenb520e082000-10-03 00:21:45 +0000697
698
Eric Andersen3e6ff902001-03-09 21:24:12 +0000699static int
Eric Andersenb520e082000-10-03 00:21:45 +0000700getttywidth(void)
701{
Eric Andersen8efe9672003-09-15 08:33:45 +0000702 int width=0;
703 get_terminal_width_height(0, &width, NULL);
704 return (width);
Eric Andersenb520e082000-10-03 00:21:45 +0000705}
706
Eric Andersen3e6ff902001-03-09 21:24:12 +0000707static void
Eric Andersenb520e082000-10-03 00:21:45 +0000708updateprogressmeter(int ignore)
709{
710 int save_errno = errno;
711
712 progressmeter(0);
713 errno = save_errno;
714}
715
Eric Andersen3e6ff902001-03-09 21:24:12 +0000716static void
Eric Andersenb520e082000-10-03 00:21:45 +0000717alarmtimer(int wait)
718{
719 struct itimerval itv;
720
721 itv.it_value.tv_sec = wait;
722 itv.it_value.tv_usec = 0;
723 itv.it_interval = itv.it_value;
724 setitimer(ITIMER_REAL, &itv, NULL);
725}
726
727
Eric Andersen3e6ff902001-03-09 21:24:12 +0000728static void
Eric Andersenb520e082000-10-03 00:21:45 +0000729progressmeter(int flag)
730{
Eric Andersenb520e082000-10-03 00:21:45 +0000731 static struct timeval lastupdate;
Mark Whitley30ac01c2001-04-17 18:13:16 +0000732 static off_t lastsize, totalsize;
Rob Landley19a39402006-06-13 17:10:26 +0000733
Eric Andersenb520e082000-10-03 00:21:45 +0000734 struct timeval now, td, wait;
Rob Landley19a39402006-06-13 17:10:26 +0000735 off_t abbrevsize;
736 int elapsed, ratio, barlength, i;
Eric Andersenb520e082000-10-03 00:21:45 +0000737 char buf[256];
738
739 if (flag == -1) {
740 (void) gettimeofday(&start, (struct timezone *) 0);
741 lastupdate = start;
742 lastsize = 0;
Mark Whitley30ac01c2001-04-17 18:13:16 +0000743 totalsize = filesize; /* as filesize changes.. */
Eric Andersenb520e082000-10-03 00:21:45 +0000744 }
745
746 (void) gettimeofday(&now, (struct timezone *) 0);
Rob Landley19a39402006-06-13 17:10:26 +0000747 ratio = 100;
Mark Whitley30ac01c2001-04-17 18:13:16 +0000748 if (totalsize != 0 && !chunked) {
Rob Landley19a39402006-06-13 17:10:26 +0000749 ratio = (int) (100 * transferred / totalsize);
Eric Andersenb520e082000-10-03 00:21:45 +0000750 ratio = MIN(ratio, 100);
Rob Landley19a39402006-06-13 17:10:26 +0000751 }
Eric Andersenb520e082000-10-03 00:21:45 +0000752
Rob Landley19a39402006-06-13 17:10:26 +0000753 fprintf(stderr, "\r%-20.20s%4d%% ", curfile, ratio);
Eric Andersenb520e082000-10-03 00:21:45 +0000754
755 barlength = getttywidth() - 51;
Rob Landley19a39402006-06-13 17:10:26 +0000756 if (barlength > 0 && barlength < sizeof(buf)) {
Eric Andersenb520e082000-10-03 00:21:45 +0000757 i = barlength * ratio / 100;
Rob Landley19a39402006-06-13 17:10:26 +0000758 memset(buf, '*', i);
759 memset(buf + i, ' ', barlength - i);
760 buf[barlength] = '\0';
761 fprintf(stderr, "|%s|", buf);
Eric Andersenb520e082000-10-03 00:21:45 +0000762 }
763 i = 0;
Rob Landley19a39402006-06-13 17:10:26 +0000764 abbrevsize = transferred;
765 while (abbrevsize >= 100000) {
Eric Andersenb520e082000-10-03 00:21:45 +0000766 i++;
767 abbrevsize >>= 10;
768 }
Rob Landley19a39402006-06-13 17:10:26 +0000769 /* See http://en.wikipedia.org/wiki/Tera */
770 fprintf(stderr, "%6d %c%c ", (int)abbrevsize, " KMGTPEZY"[i], i?'B':' ');
Eric Andersenb520e082000-10-03 00:21:45 +0000771
772 timersub(&now, &lastupdate, &wait);
Rob Landley19a39402006-06-13 17:10:26 +0000773 if (transferred > lastsize) {
Eric Andersenb520e082000-10-03 00:21:45 +0000774 lastupdate = now;
Rob Landley19a39402006-06-13 17:10:26 +0000775 lastsize = transferred;
776 if (wait.tv_sec >= STALLTIME)
777 timeradd(&start, &wait, &start);
Eric Andersenb520e082000-10-03 00:21:45 +0000778 wait.tv_sec = 0;
779 }
780 timersub(&now, &start, &td);
Rob Landley19a39402006-06-13 17:10:26 +0000781 elapsed = td.tv_sec;
Eric Andersenb520e082000-10-03 00:21:45 +0000782
Mark Whitley30ac01c2001-04-17 18:13:16 +0000783 if (wait.tv_sec >= STALLTIME) {
Rob Landley19a39402006-06-13 17:10:26 +0000784 fprintf(stderr, " - stalled -");
785 } else if (transferred <= 0 || elapsed <= 0 || transferred > totalsize || chunked) {
786 fprintf(stderr, "--:--:-- ETA");
Eric Andersenb520e082000-10-03 00:21:45 +0000787 } else {
Rob Landley19a39402006-06-13 17:10:26 +0000788 /* totalsize / (transferred/elapsed) - elapsed: */
789 int eta = (int) (totalsize*elapsed/transferred - elapsed);
790 i = eta % 3600;
791 fprintf(stderr, "%02d:%02d:%02d ETA", eta / 3600, i / 60, i % 60);
Eric Andersenb520e082000-10-03 00:21:45 +0000792 }
Eric Andersenb520e082000-10-03 00:21:45 +0000793
794 if (flag == -1) {
795 struct sigaction sa;
796 sa.sa_handler = updateprogressmeter;
797 sigemptyset(&sa.sa_mask);
798 sa.sa_flags = SA_RESTART;
799 sigaction(SIGALRM, &sa, NULL);
800 alarmtimer(1);
801 } else if (flag == 1) {
802 alarmtimer(0);
Rob Landley19a39402006-06-13 17:10:26 +0000803 transferred = 0;
Mark Whitley30ac01c2001-04-17 18:13:16 +0000804 putc('\n', stderr);
Eric Andersenb520e082000-10-03 00:21:45 +0000805 }
806}
807#endif
Eric Andersen4e573f42000-11-14 23:29:24 +0000808
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000809/* Original copyright notice which applies to the CONFIG_FEATURE_WGET_STATUSBAR stuff,
Eric Andersenaff114c2004-04-14 17:51:38 +0000810 * much of which was blatantly stolen from openssh. */
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000811
Eric Andersen4e573f42000-11-14 23:29:24 +0000812/*-
813 * Copyright (c) 1992, 1993
814 * The Regents of the University of California. All rights reserved.
815 *
816 * Redistribution and use in source and binary forms, with or without
817 * modification, are permitted provided that the following conditions
818 * are met:
819 * 1. Redistributions of source code must retain the above copyright
820 * notice, this list of conditions and the following disclaimer.
821 * 2. Redistributions in binary form must reproduce the above copyright
822 * notice, this list of conditions and the following disclaimer in the
823 * documentation and/or other materials provided with the distribution.
824 *
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000825 * 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change
826 * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change>
Eric Andersen4e573f42000-11-14 23:29:24 +0000827 *
828 * 4. Neither the name of the University nor the names of its contributors
829 * may be used to endorse or promote products derived from this software
830 * without specific prior written permission.
831 *
832 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
833 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
834 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
835 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
836 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
837 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
838 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
839 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
840 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
841 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
842 * SUCH DAMAGE.
843 *
Eric Andersen751750e2004-10-08 08:27:40 +0000844 * $Id: wget.c,v 1.75 2004/10/08 08:27:40 andersen Exp $
Eric Andersen4e573f42000-11-14 23:29:24 +0000845 */