blob: 181ea9397b9f84dcf75bb524a8c080ac512b6ba2 [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
Rob Landleyaf12cb32006-06-27 18:41:03 +00009#include "busybox.h"
Eric Andersen50ae3102001-05-15 17:51:37 +000010#include <getopt.h>
11
Eric Andersencbe31da2001-02-20 06:14:08 +000012
Eric Andersen79757c92001-04-05 21:45:54 +000013struct host_info {
14 char *host;
15 int port;
16 char *path;
17 int is_ftp;
18 char *user;
19};
20
21static void parse_url(char *url, struct host_info *h);
Glenn L McGrathffccf6e2003-12-20 01:47:18 +000022static FILE *open_socket(struct sockaddr_in *s_in);
Eric Andersen3e6ff902001-03-09 21:24:12 +000023static char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc);
Eric Andersen79757c92001-04-05 21:45:54 +000024static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf);
Eric Andersen96700832000-09-04 15:15:55 +000025
Eric Andersenb520e082000-10-03 00:21:45 +000026/* Globals (can be accessed from signal handlers */
Rob Landley19a39402006-06-13 17:10:26 +000027static off_t filesize; /* content-length of the file */
28static int chunked; /* chunked transfer encoding */
Eric Andersenbdfd0d72001-10-24 05:00:29 +000029#ifdef CONFIG_FEATURE_WGET_STATUSBAR
Eric Andersen20aab262001-07-19 22:28:02 +000030static void progressmeter(int flag);
Rob Landley19a39402006-06-13 17:10:26 +000031static char *curfile; /* Name of current file being transferred. */
Eric Andersenb520e082000-10-03 00:21:45 +000032static struct timeval start; /* Time a transfer started. */
Rob Landley19a39402006-06-13 17:10:26 +000033static off_t transferred; /* Number of bytes transferred so far. */
Eric Andersenb520e082000-10-03 00:21:45 +000034/* For progressmeter() -- number of seconds before xfer considered "stalled" */
Rob Landley19a39402006-06-13 17:10:26 +000035enum {
36 STALLTIME = 5
37};
38#else
Rob Landleyf5fc1382006-09-15 04:08:25 +000039static void progressmeter(int flag) {}
Eric Andersenb520e082000-10-03 00:21:45 +000040#endif
Eric Andersenc7bda1c2004-03-15 08:29:22 +000041
Eric Andersen3e6ff902001-03-09 21:24:12 +000042static void close_and_delete_outfile(FILE* output, char *fname_out, int do_continue)
Eric Andersen7d697012001-01-24 20:28:35 +000043{
Denis Vlasenko3526a132006-09-09 12:20:57 +000044 if (output != stdout && do_continue == 0) {
Eric Andersen7d697012001-01-24 20:28:35 +000045 fclose(output);
46 unlink(fname_out);
47 }
48}
Eric Andersen96700832000-09-04 15:15:55 +000049
Matt Kraai854125f2001-05-09 19:15:46 +000050/* Read NMEMB elements of SIZE bytes into PTR from STREAM. Returns the
51 * number of elements read, and a short count if an eof or non-interrupt
52 * error is encountered. */
53static size_t safe_fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
54{
55 size_t ret = 0;
56
57 do {
58 clearerr(stream);
59 ret += fread((char *)ptr + (ret * size), size, nmemb - ret, stream);
60 } while (ret < nmemb && ferror(stream) && errno == EINTR);
61
62 return ret;
63}
64
65/* Write NMEMB elements of SIZE bytes from PTR to STREAM. Returns the
66 * number of elements written, and a short count if an eof or non-interrupt
67 * error is encountered. */
68static size_t safe_fwrite(void *ptr, size_t size, size_t nmemb, FILE *stream)
69{
70 size_t ret = 0;
71
72 do {
73 clearerr(stream);
74 ret += fwrite((char *)ptr + (ret * size), size, nmemb - ret, stream);
75 } while (ret < nmemb && ferror(stream) && errno == EINTR);
76
77 return ret;
78}
79
80/* Read a line or SIZE - 1 bytes into S, whichever is less, from STREAM.
81 * Returns S, or NULL if an eof or non-interrupt error is encountered. */
82static char *safe_fgets(char *s, int size, FILE *stream)
83{
84 char *ret;
85
86 do {
87 clearerr(stream);
88 ret = fgets(s, size, stream);
89 } while (ret == NULL && ferror(stream) && errno == EINTR);
90
91 return ret;
92}
93
Eric Andersen79757c92001-04-05 21:45:54 +000094#define close_delete_and_die(s...) { \
95 close_and_delete_outfile(output, fname_out, do_continue); \
Manuel Novoa III cad53642003-03-19 09:13:01 +000096 bb_error_msg_and_die(s); }
Eric Andersen79757c92001-04-05 21:45:54 +000097
98
Eric Andersenbdfd0d72001-10-24 05:00:29 +000099#ifdef CONFIG_FEATURE_WGET_AUTHENTICATION
Eric Andersen79757c92001-04-05 21:45:54 +0000100/*
Denis Vlasenko21afc7d2006-09-03 15:49:40 +0000101 * Base64-encode character string and return the string.
Eric Andersen79757c92001-04-05 21:45:54 +0000102 */
Denis Vlasenko3526a132006-09-09 12:20:57 +0000103static char *base64enc(unsigned char *p, char *buf, int len)
104{
Denis Vlasenko21afc7d2006-09-03 15:49:40 +0000105 bb_uuencode(p, buf, len, bb_uuenc_tbl_base64);
Rob Landley76ef08c2006-06-13 16:44:26 +0000106 return buf;
Eric Andersen79757c92001-04-05 21:45:54 +0000107}
108#endif
109
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000110#define WGET_OPT_CONTINUE 1
111#define WGET_OPT_QUIET 2
112#define WGET_OPT_PASSIVE 4
113#define WGET_OPT_OUTNAME 8
114#define WGET_OPT_HEADER 16
115#define WGET_OPT_PREFIX 32
116#define WGET_OPT_PROXY 64
Bernhard Reutner-Fischerbfbc4eb2006-09-02 15:30:26 +0000117#define WGET_OPT_USER_AGENT 128
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000118
Bernhard Reutner-Fischer289e86a2006-08-20 20:01:24 +0000119#if ENABLE_FEATURE_WGET_LONG_OPTIONS
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000120static const struct option wget_long_options[] = {
121 { "continue", 0, NULL, 'c' },
122 { "quiet", 0, NULL, 'q' },
123 { "passive-ftp", 0, NULL, 139 },
124 { "output-document", 1, NULL, 'O' },
Rob Landley76ef08c2006-06-13 16:44:26 +0000125 { "header", 1, NULL, 131 },
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000126 { "directory-prefix",1, NULL, 'P' },
127 { "proxy", 1, NULL, 'Y' },
Bernhard Reutner-Fischerbfbc4eb2006-09-02 15:30:26 +0000128 { "user-agent", 1, NULL, 'U' },
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000129 { 0, 0, 0, 0 }
130};
Bernhard Reutner-Fischer8d3a6f72006-05-31 14:11:38 +0000131#endif
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000132
Eric Andersen96700832000-09-04 15:15:55 +0000133int wget_main(int argc, char **argv)
134{
Eric Andersen79757c92001-04-05 21:45:54 +0000135 int n, try=5, status;
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000136 unsigned long opt;
Eric Andersen79757c92001-04-05 21:45:54 +0000137 int port;
Robert Griebld7760112002-05-14 23:36:45 +0000138 char *proxy = 0;
Eric Andersen8071c022001-06-21 19:45:06 +0000139 char *dir_prefix=NULL;
Eric Andersen29edd002000-12-09 16:55:35 +0000140 char *s, buf[512];
141 struct stat sbuf;
Eric Andersen50ae3102001-05-15 17:51:37 +0000142 char extra_headers[1024];
143 char *extra_headers_ptr = extra_headers;
144 int extra_headers_left = sizeof(extra_headers);
Eric Andersen79757c92001-04-05 21:45:54 +0000145 struct host_info server, target;
Eric Andersene6dc4392003-10-31 09:31:46 +0000146 struct sockaddr_in s_in;
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000147 llist_t *headers_llist = NULL;
Eric Andersen79757c92001-04-05 21:45:54 +0000148
"Vladimir N. Oleynik"f704b272005-10-14 09:56:52 +0000149 FILE *sfp = NULL; /* socket to web/ftp server */
150 FILE *dfp = NULL; /* socket to ftp server (data) */
151 char *fname_out = NULL; /* where to direct output (-O) */
152 int do_continue = 0; /* continue a prev transfer (-c) */
153 long beg_range = 0L; /* range at which continue begins */
154 int got_clen = 0; /* got content-length: from server */
155 FILE *output; /* socket to web server */
156 int quiet_flag = FALSE; /* Be verry, verry quiet... */
157 int use_proxy = 1; /* Use proxies if env vars are set */
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000158 char *proxy_flag = "on"; /* Use proxies if env vars are set */
Bernhard Reutner-Fischerbfbc4eb2006-09-02 15:30:26 +0000159 char *user_agent = "Wget"; /* Content of the "User-Agent" header field */
Eric Andersen29edd002000-12-09 16:55:35 +0000160
Eric Andersen96700832000-09-04 15:15:55 +0000161 /*
162 * Crack command line.
163 */
"Vladimir N. Oleynik"f704b272005-10-14 09:56:52 +0000164 bb_opt_complementally = "-1:\203::";
Bernhard Reutner-Fischer289e86a2006-08-20 20:01:24 +0000165#if ENABLE_FEATURE_WGET_LONG_OPTIONS
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000166 bb_applet_long_options = wget_long_options;
Bernhard Reutner-Fischer8d3a6f72006-05-31 14:11:38 +0000167#endif
Bernhard Reutner-Fischerbfbc4eb2006-09-02 15:30:26 +0000168 opt = bb_getopt_ulflags(argc, argv, "cq\213O:\203:P:Y:U:",
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000169 &fname_out, &headers_llist,
Bernhard Reutner-Fischerbfbc4eb2006-09-02 15:30:26 +0000170 &dir_prefix, &proxy_flag, &user_agent);
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000171 if (opt & WGET_OPT_CONTINUE) {
172 ++do_continue;
173 }
174 if (opt & WGET_OPT_QUIET) {
175 quiet_flag = TRUE;
176 }
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000177 if (strcmp(proxy_flag, "off") == 0) {
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000178 /* Use the proxy if necessary. */
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000179 use_proxy = 0;
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000180 }
181 if (opt & WGET_OPT_HEADER) {
182 while (headers_llist) {
183 int arglen = strlen(headers_llist->data);
184 if (extra_headers_left - arglen - 2 <= 0)
Denis Vlasenko3526a132006-09-09 12:20:57 +0000185 bb_error_msg_and_die("extra_headers buffer too small "
186 "(need %i)", extra_headers_left - arglen);
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000187 strcpy(extra_headers_ptr, headers_llist->data);
188 extra_headers_ptr += arglen;
189 extra_headers_left -= ( arglen + 2 );
190 *extra_headers_ptr++ = '\r';
191 *extra_headers_ptr++ = '\n';
192 *(extra_headers_ptr + 1) = 0;
193 headers_llist = headers_llist->link;
Eric Andersen96700832000-09-04 15:15:55 +0000194 }
195 }
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000196
Eric Andersen79757c92001-04-05 21:45:54 +0000197 parse_url(argv[optind], &target);
198 server.host = target.host;
199 server.port = target.port;
200
Eric Andersen96700832000-09-04 15:15:55 +0000201 /*
Eric Andersenf3b2b522000-12-07 22:42:11 +0000202 * Use the proxy if necessary.
Eric Andersen96700832000-09-04 15:15:55 +0000203 */
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000204 if (use_proxy) {
Robert Griebld7760112002-05-14 23:36:45 +0000205 proxy = getenv(target.is_ftp ? "ftp_proxy" : "http_proxy");
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000206 if (proxy && *proxy) {
Rob Landleyd921b2e2006-08-03 15:41:12 +0000207 parse_url(xstrdup(proxy), &server);
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000208 } else {
209 use_proxy = 0;
210 }
Robert Griebld7760112002-05-14 23:36:45 +0000211 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000212
Eric Andersen29edd002000-12-09 16:55:35 +0000213 /* Guess an output filename */
214 if (!fname_out) {
Eric Andersen751750e2004-10-08 08:27:40 +0000215 // Dirty hack. Needed because bb_get_last_path_component
216 // will destroy trailing / by storing '\0' in last byte!
Denis Vlasenko3526a132006-09-09 12:20:57 +0000217 if (*target.path && target.path[strlen(target.path)-1] != '/') {
Eric Andersen751750e2004-10-08 08:27:40 +0000218 fname_out =
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000219#ifdef CONFIG_FEATURE_WGET_STATUSBAR
Eric Andersen751750e2004-10-08 08:27:40 +0000220 curfile =
Eric Andersen29edd002000-12-09 16:55:35 +0000221#endif
Eric Andersen751750e2004-10-08 08:27:40 +0000222 bb_get_last_path_component(target.path);
223 }
Denis Vlasenko3526a132006-09-09 12:20:57 +0000224 if (fname_out == NULL || strlen(fname_out) < 1) {
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000225 fname_out =
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000226#ifdef CONFIG_FEATURE_WGET_STATUSBAR
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000227 curfile =
Eric Andersen29edd002000-12-09 16:55:35 +0000228#endif
229 "index.html";
230 }
Matt Kraai0382eb82001-07-19 19:13:55 +0000231 if (dir_prefix != NULL)
232 fname_out = concat_path_file(dir_prefix, fname_out);
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000233#ifdef CONFIG_FEATURE_WGET_STATUSBAR
Eric Andersen29edd002000-12-09 16:55:35 +0000234 } else {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000235 curfile = bb_get_last_path_component(fname_out);
Eric Andersen29edd002000-12-09 16:55:35 +0000236#endif
237 }
Eric Andersen7d697012001-01-24 20:28:35 +0000238 if (do_continue && !fname_out)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000239 bb_error_msg_and_die("cannot specify continue (-c) without a filename (-O)");
Eric Andersen29edd002000-12-09 16:55:35 +0000240
Eric Andersen96700832000-09-04 15:15:55 +0000241
242 /*
Eric Andersen29edd002000-12-09 16:55:35 +0000243 * Open the output file stream.
Eric Andersen96700832000-09-04 15:15:55 +0000244 */
Matt Kraai65317ea2001-04-11 20:03:01 +0000245 if (strcmp(fname_out, "-") == 0) {
Randolph Chung02553a22000-12-07 03:53:47 +0000246 output = stdout;
Eric Andersen95a349f2001-05-13 00:55:54 +0000247 quiet_flag = TRUE;
Matt Kraai65317ea2001-04-11 20:03:01 +0000248 } else {
Rob Landleyd921b2e2006-08-03 15:41:12 +0000249 output = xfopen(fname_out, (do_continue ? "a" : "w"));
Eric Andersen96700832000-09-04 15:15:55 +0000250 }
251
252 /*
253 * Determine where to start transfer.
254 */
255 if (do_continue) {
Eric Andersenb520e082000-10-03 00:21:45 +0000256 if (fstat(fileno(output), &sbuf) < 0)
Denis Vlasenko3526a132006-09-09 12:20:57 +0000257 bb_perror_msg_and_die("fstat");
Eric Andersen96700832000-09-04 15:15:55 +0000258 if (sbuf.st_size > 0)
259 beg_range = sbuf.st_size;
260 else
261 do_continue = 0;
262 }
263
Eric Andersene6dc4392003-10-31 09:31:46 +0000264 /* We want to do exactly _one_ DNS lookup, since some
265 * sites (i.e. ftp.us.debian.org) use round-robin DNS
266 * and we want to connect to only one IP... */
Glenn L McGrathffccf6e2003-12-20 01:47:18 +0000267 bb_lookup_host(&s_in, server.host);
268 s_in.sin_port = server.port;
Denis Vlasenko3526a132006-09-09 12:20:57 +0000269 if (quiet_flag == FALSE) {
270 printf("Connecting to %s[%s]:%d\n",
Glenn L McGrathffccf6e2003-12-20 01:47:18 +0000271 server.host, inet_ntoa(s_in.sin_addr), ntohs(server.port));
Eric Andersene6dc4392003-10-31 09:31:46 +0000272 }
273
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000274 if (use_proxy || !target.is_ftp) {
Eric Andersen79757c92001-04-05 21:45:54 +0000275 /*
276 * HTTP session
277 */
278 do {
Glenn L McGrathe7bdfcc2003-08-28 22:03:19 +0000279 got_clen = chunked = 0;
280
Denis Vlasenko3526a132006-09-09 12:20:57 +0000281 if (!--try)
Eric Andersen79757c92001-04-05 21:45:54 +0000282 close_delete_and_die("too many redirections");
Eric Andersen7d697012001-01-24 20:28:35 +0000283
Eric Andersen79757c92001-04-05 21:45:54 +0000284 /*
285 * Open socket to http server
286 */
287 if (sfp) fclose(sfp);
Glenn L McGrathffccf6e2003-12-20 01:47:18 +0000288 sfp = open_socket(&s_in);
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000289
Eric Andersen79757c92001-04-05 21:45:54 +0000290 /*
291 * Send HTTP request.
292 */
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000293 if (use_proxy) {
Glenn L McGrathcc20ebc2003-09-10 23:52:15 +0000294 const char *format = "GET %stp://%s:%d/%s HTTP/1.1\r\n";
295#ifdef CONFIG_FEATURE_WGET_IP6_LITERAL
Rob Landley19a39402006-06-13 17:10:26 +0000296 if (strchr(target.host, ':'))
Glenn L McGrathcc20ebc2003-09-10 23:52:15 +0000297 format = "GET %stp://[%s]:%d/%s HTTP/1.1\r\n";
298#endif
299 fprintf(sfp, format,
Eric Andersen79757c92001-04-05 21:45:54 +0000300 target.is_ftp ? "f" : "ht", target.host,
Glenn L McGrath24cb17f2004-01-31 08:08:57 +0000301 ntohs(target.port), target.path);
Eric Andersen79757c92001-04-05 21:45:54 +0000302 } else {
Eric Andersen6d7fa432001-04-10 18:17:05 +0000303 fprintf(sfp, "GET /%s HTTP/1.1\r\n", target.path);
Eric Andersen79757c92001-04-05 21:45:54 +0000304 }
Eric Andersen96700832000-09-04 15:15:55 +0000305
Bernhard Reutner-Fischerbfbc4eb2006-09-02 15:30:26 +0000306 fprintf(sfp, "Host: %s\r\nUser-Agent: %s\r\n", target.host,
307 user_agent);
Eric Andersen79757c92001-04-05 21:45:54 +0000308
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000309#ifdef CONFIG_FEATURE_WGET_AUTHENTICATION
Eric Andersen79757c92001-04-05 21:45:54 +0000310 if (target.user) {
311 fprintf(sfp, "Authorization: Basic %s\r\n",
Eric Andersen0cb6f352006-01-30 22:30:41 +0000312 base64enc((unsigned char*)target.user, buf, sizeof(buf)));
Eric Andersen79757c92001-04-05 21:45:54 +0000313 }
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000314 if (use_proxy && server.user) {
Eric Andersen79757c92001-04-05 21:45:54 +0000315 fprintf(sfp, "Proxy-Authorization: Basic %s\r\n",
Eric Andersen0cb6f352006-01-30 22:30:41 +0000316 base64enc((unsigned char*)server.user, buf, sizeof(buf)));
Eric Andersen79757c92001-04-05 21:45:54 +0000317 }
318#endif
319
Eric Andersenb520e082000-10-03 00:21:45 +0000320 if (do_continue)
Eric Andersen79757c92001-04-05 21:45:54 +0000321 fprintf(sfp, "Range: bytes=%ld-\r\n", beg_range);
Eric Andersen50ae3102001-05-15 17:51:37 +0000322 if(extra_headers_left < sizeof(extra_headers))
Eric Andersen9abfe852001-05-15 20:11:49 +0000323 fputs(extra_headers,sfp);
Eric Andersen79757c92001-04-05 21:45:54 +0000324 fprintf(sfp,"Connection: close\r\n\r\n");
325
326 /*
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000327 * Retrieve HTTP response line and check for "200" status code.
328 */
Glenn L McGrathe7bdfcc2003-08-28 22:03:19 +0000329read_response:
330 if (fgets(buf, sizeof(buf), sfp) == NULL)
Eric Andersen79757c92001-04-05 21:45:54 +0000331 close_delete_and_die("no response from server");
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000332
Eric Andersen79757c92001-04-05 21:45:54 +0000333 for (s = buf ; *s != '\0' && !isspace(*s) ; ++s)
Rob Landley76ef08c2006-06-13 16:44:26 +0000334 ;
Eric Andersen79757c92001-04-05 21:45:54 +0000335 for ( ; isspace(*s) ; ++s)
Rob Landley76ef08c2006-06-13 16:44:26 +0000336 ;
Eric Andersen79757c92001-04-05 21:45:54 +0000337 switch (status = atoi(s)) {
338 case 0:
Eric Andersen6d7fa432001-04-10 18:17:05 +0000339 case 100:
340 while (gethdr(buf, sizeof(buf), sfp, &n) != NULL);
341 goto read_response;
Eric Andersen79757c92001-04-05 21:45:54 +0000342 case 200:
343 if (do_continue && output != stdout)
344 output = freopen(fname_out, "w", output);
345 do_continue = 0;
346 break;
347 case 300: /* redirection */
348 case 301:
349 case 302:
350 case 303:
351 break;
352 case 206:
353 if (do_continue)
354 break;
355 /*FALLTHRU*/
356 default:
357 chomp(buf);
358 close_delete_and_die("server returned error %d: %s", atoi(s), buf);
359 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000360
Eric Andersen79757c92001-04-05 21:45:54 +0000361 /*
362 * Retrieve HTTP headers.
363 */
364 while ((s = gethdr(buf, sizeof(buf), sfp, &n)) != NULL) {
365 if (strcasecmp(buf, "content-length") == 0) {
Eric Andersen24794452004-03-06 22:11:45 +0000366 unsigned long value;
367 if (safe_strtoul(s, &value)) {
368 close_delete_and_die("content-length %s is garbage", s);
369 }
370 filesize = value;
Eric Andersen79757c92001-04-05 21:45:54 +0000371 got_clen = 1;
372 continue;
373 }
Eric Andersen6d7fa432001-04-10 18:17:05 +0000374 if (strcasecmp(buf, "transfer-encoding") == 0) {
375 if (strcasecmp(s, "chunked") == 0) {
376 chunked = got_clen = 1;
377 } else {
Rob Landley76ef08c2006-06-13 16:44:26 +0000378 close_delete_and_die("server wants to do %s transfer encoding", s);
Eric Andersen6d7fa432001-04-10 18:17:05 +0000379 }
380 }
Eric Andersen79757c92001-04-05 21:45:54 +0000381 if (strcasecmp(buf, "location") == 0) {
382 if (s[0] == '/')
Rob Landleyd921b2e2006-08-03 15:41:12 +0000383 target.path = xstrdup(s+1);
Eric Andersen79757c92001-04-05 21:45:54 +0000384 else {
Rob Landleyd921b2e2006-08-03 15:41:12 +0000385 parse_url(xstrdup(s), &target);
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000386 if (use_proxy == 0) {
Eric Andersen79757c92001-04-05 21:45:54 +0000387 server.host = target.host;
388 server.port = target.port;
389 }
Glenn L McGrath58a2e0e2004-01-17 23:07:14 +0000390 bb_lookup_host(&s_in, server.host);
391 s_in.sin_port = server.port;
392 break;
Eric Andersen79757c92001-04-05 21:45:54 +0000393 }
394 }
395 }
396 } while(status >= 300);
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000397
Eric Andersen79757c92001-04-05 21:45:54 +0000398 dfp = sfp;
399 }
400 else
401 {
402 /*
403 * FTP session
404 */
Denis Vlasenko3526a132006-09-09 12:20:57 +0000405 if (!target.user)
Rob Landleyd921b2e2006-08-03 15:41:12 +0000406 target.user = xstrdup("anonymous:busybox@");
Eric Andersen79757c92001-04-05 21:45:54 +0000407
Glenn L McGrathffccf6e2003-12-20 01:47:18 +0000408 sfp = open_socket(&s_in);
Eric Andersen79757c92001-04-05 21:45:54 +0000409 if (ftpcmd(NULL, NULL, sfp, buf) != 220)
410 close_delete_and_die("%s", buf+4);
411
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000412 /*
Eric Andersen79757c92001-04-05 21:45:54 +0000413 * Splitting username:password pair,
414 * trying to log in
415 */
416 s = strchr(target.user, ':');
417 if (s)
418 *(s++) = '\0';
419 switch(ftpcmd("USER ", target.user, sfp, buf)) {
420 case 230:
Eric Andersenb520e082000-10-03 00:21:45 +0000421 break;
Eric Andersen79757c92001-04-05 21:45:54 +0000422 case 331:
423 if (ftpcmd("PASS ", s, sfp, buf) == 230)
424 break;
425 /* FALLTHRU (failed login) */
426 default:
427 close_delete_and_die("ftp login: %s", buf+4);
428 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000429
Eric Andersen79757c92001-04-05 21:45:54 +0000430 ftpcmd("TYPE I", NULL, sfp, buf);
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000431
Eric Andersen79757c92001-04-05 21:45:54 +0000432 /*
433 * Querying file size
434 */
Rob Landleyaf12cb32006-06-27 18:41:03 +0000435 if (ftpcmd("SIZE ", target.path, sfp, buf) == 213) {
Eric Andersen24794452004-03-06 22:11:45 +0000436 unsigned long value;
437 if (safe_strtoul(buf+4, &value)) {
438 close_delete_and_die("SIZE value is garbage");
439 }
440 filesize = value;
Eric Andersen96700832000-09-04 15:15:55 +0000441 got_clen = 1;
Eric Andersen96700832000-09-04 15:15:55 +0000442 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000443
Eric Andersen79757c92001-04-05 21:45:54 +0000444 /*
445 * Entering passive mode
446 */
447 if (ftpcmd("PASV", NULL, sfp, buf) != 227)
448 close_delete_and_die("PASV: %s", buf+4);
449 s = strrchr(buf, ',');
450 *s = 0;
451 port = atoi(s+1);
452 s = strrchr(buf, ',');
453 port += atoi(s+1) * 256;
Glenn L McGrathffccf6e2003-12-20 01:47:18 +0000454 s_in.sin_port = htons(port);
455 dfp = open_socket(&s_in);
Eric Andersen79757c92001-04-05 21:45:54 +0000456
457 if (do_continue) {
458 sprintf(buf, "REST %ld", beg_range);
459 if (ftpcmd(buf, NULL, sfp, buf) != 350) {
460 if (output != stdout)
461 output = freopen(fname_out, "w", output);
462 do_continue = 0;
463 } else
464 filesize -= beg_range;
Eric Andersen96700832000-09-04 15:15:55 +0000465 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000466
Rob Landleyaf12cb32006-06-27 18:41:03 +0000467 if (ftpcmd("RETR ", target.path, sfp, buf) > 150)
Eric Andersen79757c92001-04-05 21:45:54 +0000468 close_delete_and_die("RETR: %s", buf+4);
Eric Andersen96700832000-09-04 15:15:55 +0000469 }
470
Eric Andersen79757c92001-04-05 21:45:54 +0000471
Eric Andersen96700832000-09-04 15:15:55 +0000472 /*
Eric Andersen79757c92001-04-05 21:45:54 +0000473 * Retrieve file
Eric Andersen96700832000-09-04 15:15:55 +0000474 */
Eric Andersen6d7fa432001-04-10 18:17:05 +0000475 if (chunked) {
476 fgets(buf, sizeof(buf), dfp);
477 filesize = strtol(buf, (char **) NULL, 16);
478 }
Rob Landley19a39402006-06-13 17:10:26 +0000479
Denis Vlasenko3526a132006-09-09 12:20:57 +0000480 if (quiet_flag == FALSE)
Glenn L McGrath1bca5ed2000-12-09 08:12:06 +0000481 progressmeter(-1);
Rob Landley19a39402006-06-13 17:10:26 +0000482
Mark Whitley30ac01c2001-04-17 18:13:16 +0000483 do {
Denis Vlasenko3526a132006-09-09 12:20:57 +0000484 while (filesize > 0 || !got_clen) {
485 unsigned rdsz = sizeof(buf);
486 if (filesize < sizeof(buf) && (chunked || got_clen))
487 rdsz = filesize;
488 n = safe_fread(buf, 1, rdsz, dfp);
489 if (n <= 0)
490 break;
Glenn L McGrath83e4a5b2003-08-28 21:55:22 +0000491 if (safe_fwrite(buf, 1, n, output) != n) {
Bernhard Reutner-Fischer1b9d7c92006-06-03 22:45:37 +0000492 bb_perror_msg_and_die(bb_msg_write_error);
Glenn L McGrath83e4a5b2003-08-28 21:55:22 +0000493 }
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000494#ifdef CONFIG_FEATURE_WGET_STATUSBAR
Rob Landley19a39402006-06-13 17:10:26 +0000495 transferred += n;
Eric Andersenb520e082000-10-03 00:21:45 +0000496#endif
Glenn L McGrath83e4a5b2003-08-28 21:55:22 +0000497 if (got_clen) {
498 filesize -= n;
499 }
500 }
Eric Andersen79757c92001-04-05 21:45:54 +0000501
Eric Andersen6d7fa432001-04-10 18:17:05 +0000502 if (chunked) {
Matt Kraai854125f2001-05-09 19:15:46 +0000503 safe_fgets(buf, sizeof(buf), dfp); /* This is a newline */
504 safe_fgets(buf, sizeof(buf), dfp);
Eric Andersen6d7fa432001-04-10 18:17:05 +0000505 filesize = strtol(buf, (char **) NULL, 16);
Denis Vlasenko3526a132006-09-09 12:20:57 +0000506 if (filesize == 0) {
Glenn L McGrath83e4a5b2003-08-28 21:55:22 +0000507 chunked = 0; /* all done! */
508 }
Eric Andersen6d7fa432001-04-10 18:17:05 +0000509 }
510
Glenn L McGrath83e4a5b2003-08-28 21:55:22 +0000511 if (n == 0 && ferror(dfp)) {
Bernhard Reutner-Fischer1b9d7c92006-06-03 22:45:37 +0000512 bb_perror_msg_and_die(bb_msg_read_error);
Glenn L McGrath83e4a5b2003-08-28 21:55:22 +0000513 }
Eric Andersen6d7fa432001-04-10 18:17:05 +0000514 } while (chunked);
Rob Landley19a39402006-06-13 17:10:26 +0000515
Denis Vlasenko3526a132006-09-09 12:20:57 +0000516 if (quiet_flag == FALSE)
Mark Whitley30ac01c2001-04-17 18:13:16 +0000517 progressmeter(1);
Rob Landley19a39402006-06-13 17:10:26 +0000518
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000519 if ((use_proxy == 0) && target.is_ftp) {
Eric Andersen79757c92001-04-05 21:45:54 +0000520 fclose(dfp);
521 if (ftpcmd(NULL, NULL, sfp, buf) != 226)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000522 bb_error_msg_and_die("ftp error: %s", buf+4);
Eric Andersen79757c92001-04-05 21:45:54 +0000523 ftpcmd("QUIT", NULL, sfp, buf);
524 }
Eric Andersen79757c92001-04-05 21:45:54 +0000525 exit(EXIT_SUCCESS);
Eric Andersen96700832000-09-04 15:15:55 +0000526}
527
528
Eric Andersen79757c92001-04-05 21:45:54 +0000529void parse_url(char *url, struct host_info *h)
Eric Andersen96700832000-09-04 15:15:55 +0000530{
Glenn L McGrathcc20ebc2003-09-10 23:52:15 +0000531 char *cp, *sp, *up, *pp;
Eric Andersen96700832000-09-04 15:15:55 +0000532
Eric Andersen79757c92001-04-05 21:45:54 +0000533 if (strncmp(url, "http://", 7) == 0) {
Glenn L McGrath036dbaa2004-01-17 05:03:31 +0000534 h->port = bb_lookup_port("http", "tcp", 80);
Eric Andersen79757c92001-04-05 21:45:54 +0000535 h->host = url + 7;
536 h->is_ftp = 0;
537 } else if (strncmp(url, "ftp://", 6) == 0) {
Glenn L McGrath036dbaa2004-01-17 05:03:31 +0000538 h->port = bb_lookup_port("ftp", "tfp", 21);
Eric Andersen79757c92001-04-05 21:45:54 +0000539 h->host = url + 6;
540 h->is_ftp = 1;
541 } else
Manuel Novoa III cad53642003-03-19 09:13:01 +0000542 bb_error_msg_and_die("not an http or ftp url: %s", url);
Eric Andersen96700832000-09-04 15:15:55 +0000543
Eric Andersen79757c92001-04-05 21:45:54 +0000544 sp = strchr(h->host, '/');
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000545 if (sp) {
Matt Kraaia9711a52001-01-03 16:15:15 +0000546 *sp++ = '\0';
Eric Andersen79757c92001-04-05 21:45:54 +0000547 h->path = sp;
Matt Kraaia9711a52001-01-03 16:15:15 +0000548 } else
Rob Landleyd921b2e2006-08-03 15:41:12 +0000549 h->path = xstrdup("");
Eric Andersen79757c92001-04-05 21:45:54 +0000550
551 up = strrchr(h->host, '@');
552 if (up != NULL) {
553 h->user = h->host;
554 *up++ = '\0';
555 h->host = up;
556 } else
557 h->user = NULL;
558
Glenn L McGrathcc20ebc2003-09-10 23:52:15 +0000559 pp = h->host;
560
561#ifdef CONFIG_FEATURE_WGET_IP6_LITERAL
562 if (h->host[0] == '[') {
563 char *ep;
564
565 ep = h->host + 1;
Eric Andersen6231f092003-09-11 08:25:11 +0000566 while (*ep == ':' || isxdigit (*ep))
Glenn L McGrathcc20ebc2003-09-10 23:52:15 +0000567 ep++;
568 if (*ep == ']') {
569 h->host++;
570 *ep = '\0';
571 pp = ep + 1;
572 }
573 }
574#endif
575
576 cp = strchr(pp, ':');
Eric Andersen79757c92001-04-05 21:45:54 +0000577 if (cp != NULL) {
578 *cp++ = '\0';
Glenn L McGrathf980bd52003-12-27 00:21:47 +0000579 h->port = htons(atoi(cp));
Eric Andersen79757c92001-04-05 21:45:54 +0000580 }
Eric Andersen96700832000-09-04 15:15:55 +0000581}
582
583
Glenn L McGrathffccf6e2003-12-20 01:47:18 +0000584FILE *open_socket(struct sockaddr_in *s_in)
Eric Andersen96700832000-09-04 15:15:55 +0000585{
Eric Andersen96700832000-09-04 15:15:55 +0000586 FILE *fp;
587
Glenn L McGrathffccf6e2003-12-20 01:47:18 +0000588 fp = fdopen(xconnect(s_in), "r+");
589 if (fp == NULL)
Denis Vlasenko3526a132006-09-09 12:20:57 +0000590 bb_perror_msg_and_die("fdopen");
Eric Andersen96700832000-09-04 15:15:55 +0000591
592 return fp;
593}
594
595
596char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc)
597{
598 char *s, *hdrval;
599 int c;
600
601 *istrunc = 0;
602
603 /* retrieve header line */
604 if (fgets(buf, bufsiz, fp) == NULL)
605 return NULL;
606
607 /* see if we are at the end of the headers */
608 for (s = buf ; *s == '\r' ; ++s)
609 ;
610 if (s[0] == '\n')
611 return NULL;
612
613 /* convert the header name to lower case */
614 for (s = buf ; isalnum(*s) || *s == '-' ; ++s)
615 *s = tolower(*s);
616
617 /* verify we are at the end of the header name */
618 if (*s != ':')
Manuel Novoa III cad53642003-03-19 09:13:01 +0000619 bb_error_msg_and_die("bad header line: %s", buf);
Eric Andersen96700832000-09-04 15:15:55 +0000620
621 /* locate the start of the header value */
622 for (*s++ = '\0' ; *s == ' ' || *s == '\t' ; ++s)
623 ;
624 hdrval = s;
625
626 /* locate the end of header */
627 while (*s != '\0' && *s != '\r' && *s != '\n')
628 ++s;
629
630 /* end of header found */
631 if (*s != '\0') {
632 *s = '\0';
633 return hdrval;
634 }
635
Eric Andersen5d638842000-09-14 21:46:30 +0000636 /* Rats! The buffer isn't big enough to hold the entire header value. */
Eric Andersen96700832000-09-04 15:15:55 +0000637 while (c = getc(fp), c != EOF && c != '\n')
638 ;
639 *istrunc = 1;
640 return hdrval;
641}
642
Eric Andersen79757c92001-04-05 21:45:54 +0000643static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf)
644{
Eric Andersen79757c92001-04-05 21:45:54 +0000645 if (s1) {
646 if (!s2) s2="";
Eric Andersen3f1cf452003-03-11 18:03:39 +0000647 fprintf(fp, "%s%s\r\n", s1, s2);
Eric Andersen79757c92001-04-05 21:45:54 +0000648 fflush(fp);
649 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000650
Eric Andersen79757c92001-04-05 21:45:54 +0000651 do {
Glenn L McGrath32da8852004-04-08 10:27:11 +0000652 char *buf_ptr;
653
654 if (fgets(buf, 510, fp) == NULL) {
Denis Vlasenko3526a132006-09-09 12:20:57 +0000655 bb_perror_msg_and_die("fgets");
Glenn L McGrath32da8852004-04-08 10:27:11 +0000656 }
657 buf_ptr = strstr(buf, "\r\n");
658 if (buf_ptr) {
659 *buf_ptr = '\0';
660 }
Denis Vlasenko3526a132006-09-09 12:20:57 +0000661 } while (!isdigit(buf[0]) || buf[3] != ' ');
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000662
Eric Andersen79757c92001-04-05 21:45:54 +0000663 return atoi(buf);
664}
665
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000666#ifdef CONFIG_FEATURE_WGET_STATUSBAR
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000667/* Stuff below is from BSD rcp util.c, as added to openshh.
Eric Andersen4e573f42000-11-14 23:29:24 +0000668 * Original copyright notice is retained at the end of this file.
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000669 *
670 */
Eric Andersenb520e082000-10-03 00:21:45 +0000671
672
Eric Andersen3e6ff902001-03-09 21:24:12 +0000673static int
Eric Andersenb520e082000-10-03 00:21:45 +0000674getttywidth(void)
675{
Eric Andersen8efe9672003-09-15 08:33:45 +0000676 int width=0;
677 get_terminal_width_height(0, &width, NULL);
678 return (width);
Eric Andersenb520e082000-10-03 00:21:45 +0000679}
680
Eric Andersen3e6ff902001-03-09 21:24:12 +0000681static void
Eric Andersenb520e082000-10-03 00:21:45 +0000682updateprogressmeter(int ignore)
683{
684 int save_errno = errno;
685
686 progressmeter(0);
687 errno = save_errno;
688}
689
Rob Landleyc9c1a412006-07-12 19:17:55 +0000690static void alarmtimer(int iwait)
Eric Andersenb520e082000-10-03 00:21:45 +0000691{
692 struct itimerval itv;
693
Rob Landleyc9c1a412006-07-12 19:17:55 +0000694 itv.it_value.tv_sec = iwait;
Eric Andersenb520e082000-10-03 00:21:45 +0000695 itv.it_value.tv_usec = 0;
696 itv.it_interval = itv.it_value;
697 setitimer(ITIMER_REAL, &itv, NULL);
698}
699
700
Eric Andersen3e6ff902001-03-09 21:24:12 +0000701static void
Eric Andersenb520e082000-10-03 00:21:45 +0000702progressmeter(int flag)
703{
Eric Andersenb520e082000-10-03 00:21:45 +0000704 static struct timeval lastupdate;
Mark Whitley30ac01c2001-04-17 18:13:16 +0000705 static off_t lastsize, totalsize;
Rob Landley19a39402006-06-13 17:10:26 +0000706
Rob Landleyc9c1a412006-07-12 19:17:55 +0000707 struct timeval now, td, tvwait;
Rob Landley19a39402006-06-13 17:10:26 +0000708 off_t abbrevsize;
709 int elapsed, ratio, barlength, i;
Eric Andersenb520e082000-10-03 00:21:45 +0000710 char buf[256];
711
712 if (flag == -1) {
713 (void) gettimeofday(&start, (struct timezone *) 0);
714 lastupdate = start;
715 lastsize = 0;
Mark Whitley30ac01c2001-04-17 18:13:16 +0000716 totalsize = filesize; /* as filesize changes.. */
Eric Andersenb520e082000-10-03 00:21:45 +0000717 }
718
719 (void) gettimeofday(&now, (struct timezone *) 0);
Rob Landley19a39402006-06-13 17:10:26 +0000720 ratio = 100;
Mark Whitley30ac01c2001-04-17 18:13:16 +0000721 if (totalsize != 0 && !chunked) {
Rob Landley19a39402006-06-13 17:10:26 +0000722 ratio = (int) (100 * transferred / totalsize);
Eric Andersenb520e082000-10-03 00:21:45 +0000723 ratio = MIN(ratio, 100);
Rob Landley19a39402006-06-13 17:10:26 +0000724 }
Eric Andersenb520e082000-10-03 00:21:45 +0000725
Rob Landley19a39402006-06-13 17:10:26 +0000726 fprintf(stderr, "\r%-20.20s%4d%% ", curfile, ratio);
Eric Andersenb520e082000-10-03 00:21:45 +0000727
728 barlength = getttywidth() - 51;
Rob Landley19a39402006-06-13 17:10:26 +0000729 if (barlength > 0 && barlength < sizeof(buf)) {
Eric Andersenb520e082000-10-03 00:21:45 +0000730 i = barlength * ratio / 100;
Rob Landley19a39402006-06-13 17:10:26 +0000731 memset(buf, '*', i);
732 memset(buf + i, ' ', barlength - i);
733 buf[barlength] = '\0';
734 fprintf(stderr, "|%s|", buf);
Eric Andersenb520e082000-10-03 00:21:45 +0000735 }
736 i = 0;
Rob Landley19a39402006-06-13 17:10:26 +0000737 abbrevsize = transferred;
738 while (abbrevsize >= 100000) {
Eric Andersenb520e082000-10-03 00:21:45 +0000739 i++;
740 abbrevsize >>= 10;
741 }
Rob Landley19a39402006-06-13 17:10:26 +0000742 /* See http://en.wikipedia.org/wiki/Tera */
743 fprintf(stderr, "%6d %c%c ", (int)abbrevsize, " KMGTPEZY"[i], i?'B':' ');
Eric Andersenb520e082000-10-03 00:21:45 +0000744
Rob Landleyc9c1a412006-07-12 19:17:55 +0000745 timersub(&now, &lastupdate, &tvwait);
Rob Landley19a39402006-06-13 17:10:26 +0000746 if (transferred > lastsize) {
Eric Andersenb520e082000-10-03 00:21:45 +0000747 lastupdate = now;
Rob Landley19a39402006-06-13 17:10:26 +0000748 lastsize = transferred;
Rob Landleyc9c1a412006-07-12 19:17:55 +0000749 if (tvwait.tv_sec >= STALLTIME)
750 timeradd(&start, &tvwait, &start);
751 tvwait.tv_sec = 0;
Eric Andersenb520e082000-10-03 00:21:45 +0000752 }
753 timersub(&now, &start, &td);
Rob Landley19a39402006-06-13 17:10:26 +0000754 elapsed = td.tv_sec;
Eric Andersenb520e082000-10-03 00:21:45 +0000755
Rob Landleyc9c1a412006-07-12 19:17:55 +0000756 if (tvwait.tv_sec >= STALLTIME) {
Rob Landley19a39402006-06-13 17:10:26 +0000757 fprintf(stderr, " - stalled -");
758 } else if (transferred <= 0 || elapsed <= 0 || transferred > totalsize || chunked) {
759 fprintf(stderr, "--:--:-- ETA");
Eric Andersenb520e082000-10-03 00:21:45 +0000760 } else {
Rob Landley19a39402006-06-13 17:10:26 +0000761 /* totalsize / (transferred/elapsed) - elapsed: */
762 int eta = (int) (totalsize*elapsed/transferred - elapsed);
763 i = eta % 3600;
764 fprintf(stderr, "%02d:%02d:%02d ETA", eta / 3600, i / 60, i % 60);
Eric Andersenb520e082000-10-03 00:21:45 +0000765 }
Eric Andersenb520e082000-10-03 00:21:45 +0000766
767 if (flag == -1) {
768 struct sigaction sa;
769 sa.sa_handler = updateprogressmeter;
770 sigemptyset(&sa.sa_mask);
771 sa.sa_flags = SA_RESTART;
772 sigaction(SIGALRM, &sa, NULL);
773 alarmtimer(1);
774 } else if (flag == 1) {
775 alarmtimer(0);
Rob Landley19a39402006-06-13 17:10:26 +0000776 transferred = 0;
Mark Whitley30ac01c2001-04-17 18:13:16 +0000777 putc('\n', stderr);
Eric Andersenb520e082000-10-03 00:21:45 +0000778 }
779}
780#endif
Eric Andersen4e573f42000-11-14 23:29:24 +0000781
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000782/* Original copyright notice which applies to the CONFIG_FEATURE_WGET_STATUSBAR stuff,
Eric Andersenaff114c2004-04-14 17:51:38 +0000783 * much of which was blatantly stolen from openssh. */
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000784
Eric Andersen4e573f42000-11-14 23:29:24 +0000785/*-
786 * Copyright (c) 1992, 1993
787 * The Regents of the University of California. All rights reserved.
788 *
789 * Redistribution and use in source and binary forms, with or without
790 * modification, are permitted provided that the following conditions
791 * are met:
792 * 1. Redistributions of source code must retain the above copyright
793 * notice, this list of conditions and the following disclaimer.
794 * 2. Redistributions in binary form must reproduce the above copyright
795 * notice, this list of conditions and the following disclaimer in the
796 * documentation and/or other materials provided with the distribution.
797 *
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000798 * 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change
799 * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change>
Eric Andersen4e573f42000-11-14 23:29:24 +0000800 *
801 * 4. Neither the name of the University nor the names of its contributors
802 * may be used to endorse or promote products derived from this software
803 * without specific prior written permission.
804 *
805 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
806 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
807 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
808 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
809 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
810 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
811 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
812 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
813 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
814 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
815 * SUCH DAMAGE.
816 *
Eric Andersen751750e2004-10-08 08:27:40 +0000817 * $Id: wget.c,v 1.75 2004/10/08 08:27:40 andersen Exp $
Eric Andersen4e573f42000-11-14 23:29:24 +0000818 */