blob: 4b5b3192dc53ff830b511bac7bf92809ed3c5499 [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 */
45static off_t filesize = 0; /* content-length of the file */
Eric Andersen6d7fa432001-04-10 18:17:05 +000046static int chunked = 0; /* 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);
Eric Andersenb520e082000-10-03 00:21:45 +000049static char *curfile; /* Name of current file being transferred. */
50static struct timeval start; /* Time a transfer started. */
Mark Whitley30ac01c2001-04-17 18:13:16 +000051static volatile unsigned long statbytes = 0; /* Number of bytes transferred so far. */
Eric Andersenb520e082000-10-03 00:21:45 +000052/* For progressmeter() -- number of seconds before xfer considered "stalled" */
Mark Whitley59ab0252001-01-23 22:30:04 +000053static const int STALLTIME = 5;
Eric Andersenb520e082000-10-03 00:21:45 +000054#endif
Eric Andersenc7bda1c2004-03-15 08:29:22 +000055
Eric Andersen3e6ff902001-03-09 21:24:12 +000056static void close_and_delete_outfile(FILE* output, char *fname_out, int do_continue)
Eric Andersen7d697012001-01-24 20:28:35 +000057{
58 if (output != stdout && do_continue==0) {
59 fclose(output);
60 unlink(fname_out);
61 }
62}
Eric Andersen96700832000-09-04 15:15:55 +000063
Matt Kraai854125f2001-05-09 19:15:46 +000064/* Read NMEMB elements of SIZE bytes into PTR from STREAM. Returns the
65 * number of elements read, and a short count if an eof or non-interrupt
66 * error is encountered. */
67static size_t safe_fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
68{
69 size_t ret = 0;
70
71 do {
72 clearerr(stream);
73 ret += fread((char *)ptr + (ret * size), size, nmemb - ret, stream);
74 } while (ret < nmemb && ferror(stream) && errno == EINTR);
75
76 return ret;
77}
78
79/* Write NMEMB elements of SIZE bytes from PTR to STREAM. Returns the
80 * number of elements written, and a short count if an eof or non-interrupt
81 * error is encountered. */
82static size_t safe_fwrite(void *ptr, size_t size, size_t nmemb, FILE *stream)
83{
84 size_t ret = 0;
85
86 do {
87 clearerr(stream);
88 ret += fwrite((char *)ptr + (ret * size), size, nmemb - ret, stream);
89 } while (ret < nmemb && ferror(stream) && errno == EINTR);
90
91 return ret;
92}
93
94/* Read a line or SIZE - 1 bytes into S, whichever is less, from STREAM.
95 * Returns S, or NULL if an eof or non-interrupt error is encountered. */
96static char *safe_fgets(char *s, int size, FILE *stream)
97{
98 char *ret;
99
100 do {
101 clearerr(stream);
102 ret = fgets(s, size, stream);
103 } while (ret == NULL && ferror(stream) && errno == EINTR);
104
105 return ret;
106}
107
Eric Andersen79757c92001-04-05 21:45:54 +0000108#define close_delete_and_die(s...) { \
109 close_and_delete_outfile(output, fname_out, do_continue); \
Manuel Novoa III cad53642003-03-19 09:13:01 +0000110 bb_error_msg_and_die(s); }
Eric Andersen79757c92001-04-05 21:45:54 +0000111
112
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000113#ifdef CONFIG_FEATURE_WGET_AUTHENTICATION
Eric Andersen79757c92001-04-05 21:45:54 +0000114/*
115 * Base64-encode character string
116 * oops... isn't something similar in uuencode.c?
Eric Andersen14f5c8d2005-04-16 19:39:00 +0000117 * XXX: It would be better to use already existing code
Eric Andersen79757c92001-04-05 21:45:54 +0000118 */
Eric Andersen14f5c8d2005-04-16 19:39:00 +0000119static char *base64enc(unsigned char *p, char *buf, int len) {
Eric Andersen79757c92001-04-05 21:45:54 +0000120
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000121 char al[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
122 "0123456789+/";
Eric Andersen79757c92001-04-05 21:45:54 +0000123 char *s = buf;
124
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000125 while(*p) {
Eric Andersen79757c92001-04-05 21:45:54 +0000126 if (s >= buf+len-4)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000127 bb_error_msg_and_die("buffer overflow");
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000128 *(s++) = al[(*p >> 2) & 0x3F];
129 *(s++) = al[((*p << 4) & 0x30) | ((*(p+1) >> 4) & 0x0F)];
130 *s = *(s+1) = '=';
131 *(s+2) = 0;
132 if (! *(++p)) break;
133 *(s++) = al[((*p << 2) & 0x3C) | ((*(p+1) >> 6) & 0x03)];
134 if (! *(++p)) break;
135 *(s++) = al[*(p++) & 0x3F];
136 }
Eric Andersen79757c92001-04-05 21:45:54 +0000137
138 return buf;
139}
140#endif
141
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000142#define WGET_OPT_CONTINUE 1
143#define WGET_OPT_QUIET 2
144#define WGET_OPT_PASSIVE 4
145#define WGET_OPT_OUTNAME 8
146#define WGET_OPT_HEADER 16
147#define WGET_OPT_PREFIX 32
148#define WGET_OPT_PROXY 64
149
Bernhard Reutner-Fischer8d3a6f72006-05-31 14:11:38 +0000150#if ENABLE_WGET_LONG_OPTIONS
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000151static const struct option wget_long_options[] = {
152 { "continue", 0, NULL, 'c' },
153 { "quiet", 0, NULL, 'q' },
154 { "passive-ftp", 0, NULL, 139 },
155 { "output-document", 1, NULL, 'O' },
156 { "header", 1, NULL, 131 },
157 { "directory-prefix",1, NULL, 'P' },
158 { "proxy", 1, NULL, 'Y' },
159 { 0, 0, 0, 0 }
160};
Bernhard Reutner-Fischer8d3a6f72006-05-31 14:11:38 +0000161#endif
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000162
Eric Andersen96700832000-09-04 15:15:55 +0000163int wget_main(int argc, char **argv)
164{
Eric Andersen79757c92001-04-05 21:45:54 +0000165 int n, try=5, status;
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000166 unsigned long opt;
Eric Andersen79757c92001-04-05 21:45:54 +0000167 int port;
Robert Griebld7760112002-05-14 23:36:45 +0000168 char *proxy = 0;
Eric Andersen8071c022001-06-21 19:45:06 +0000169 char *dir_prefix=NULL;
Eric Andersen29edd002000-12-09 16:55:35 +0000170 char *s, buf[512];
171 struct stat sbuf;
Eric Andersen50ae3102001-05-15 17:51:37 +0000172 char extra_headers[1024];
173 char *extra_headers_ptr = extra_headers;
174 int extra_headers_left = sizeof(extra_headers);
Eric Andersen79757c92001-04-05 21:45:54 +0000175 struct host_info server, target;
Eric Andersene6dc4392003-10-31 09:31:46 +0000176 struct sockaddr_in s_in;
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000177 llist_t *headers_llist = NULL;
Eric Andersen79757c92001-04-05 21:45:54 +0000178
"Vladimir N. Oleynik"f704b272005-10-14 09:56:52 +0000179 FILE *sfp = NULL; /* socket to web/ftp server */
180 FILE *dfp = NULL; /* socket to ftp server (data) */
181 char *fname_out = NULL; /* where to direct output (-O) */
182 int do_continue = 0; /* continue a prev transfer (-c) */
183 long beg_range = 0L; /* range at which continue begins */
184 int got_clen = 0; /* got content-length: from server */
185 FILE *output; /* socket to web server */
186 int quiet_flag = FALSE; /* Be verry, verry quiet... */
187 int use_proxy = 1; /* Use proxies if env vars are set */
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000188 char *proxy_flag = "on"; /* Use proxies if env vars are set */
Eric Andersen29edd002000-12-09 16:55:35 +0000189
Eric Andersen96700832000-09-04 15:15:55 +0000190 /*
191 * Crack command line.
192 */
"Vladimir N. Oleynik"f704b272005-10-14 09:56:52 +0000193 bb_opt_complementally = "-1:\203::";
Bernhard Reutner-Fischer8d3a6f72006-05-31 14:11:38 +0000194#if ENABLE_WGET_LONG_OPTIONS
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000195 bb_applet_long_options = wget_long_options;
Bernhard Reutner-Fischer8d3a6f72006-05-31 14:11:38 +0000196#endif
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000197 opt = bb_getopt_ulflags(argc, argv, "cq\213O:\203:P:Y:",
198 &fname_out, &headers_llist,
"Vladimir N. Oleynik"f704b272005-10-14 09:56:52 +0000199 &dir_prefix, &proxy_flag);
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000200 if (opt & WGET_OPT_CONTINUE) {
201 ++do_continue;
202 }
203 if (opt & WGET_OPT_QUIET) {
204 quiet_flag = TRUE;
205 }
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000206 if (strcmp(proxy_flag, "off") == 0) {
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000207 /* Use the proxy if necessary. */
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000208 use_proxy = 0;
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000209 }
210 if (opt & WGET_OPT_HEADER) {
211 while (headers_llist) {
212 int arglen = strlen(headers_llist->data);
213 if (extra_headers_left - arglen - 2 <= 0)
214 bb_error_msg_and_die("extra_headers buffer too small(need %i)", extra_headers_left - arglen);
215 strcpy(extra_headers_ptr, headers_llist->data);
216 extra_headers_ptr += arglen;
217 extra_headers_left -= ( arglen + 2 );
218 *extra_headers_ptr++ = '\r';
219 *extra_headers_ptr++ = '\n';
220 *(extra_headers_ptr + 1) = 0;
221 headers_llist = headers_llist->link;
Eric Andersen96700832000-09-04 15:15:55 +0000222 }
223 }
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000224
Eric Andersen79757c92001-04-05 21:45:54 +0000225 parse_url(argv[optind], &target);
226 server.host = target.host;
227 server.port = target.port;
228
Eric Andersen96700832000-09-04 15:15:55 +0000229 /*
Eric Andersenf3b2b522000-12-07 22:42:11 +0000230 * Use the proxy if necessary.
Eric Andersen96700832000-09-04 15:15:55 +0000231 */
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000232 if (use_proxy) {
Robert Griebld7760112002-05-14 23:36:45 +0000233 proxy = getenv(target.is_ftp ? "ftp_proxy" : "http_proxy");
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000234 if (proxy && *proxy) {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000235 parse_url(bb_xstrdup(proxy), &server);
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000236 } else {
237 use_proxy = 0;
238 }
Robert Griebld7760112002-05-14 23:36:45 +0000239 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000240
Eric Andersen29edd002000-12-09 16:55:35 +0000241 /* Guess an output filename */
242 if (!fname_out) {
Eric Andersen751750e2004-10-08 08:27:40 +0000243 // Dirty hack. Needed because bb_get_last_path_component
244 // will destroy trailing / by storing '\0' in last byte!
Rob Landley6f2a0b22006-02-21 18:34:54 +0000245 if(*target.path && target.path[strlen(target.path)-1]!='/') {
Eric Andersen751750e2004-10-08 08:27:40 +0000246 fname_out =
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000247#ifdef CONFIG_FEATURE_WGET_STATUSBAR
Eric Andersen751750e2004-10-08 08:27:40 +0000248 curfile =
Eric Andersen29edd002000-12-09 16:55:35 +0000249#endif
Eric Andersen751750e2004-10-08 08:27:40 +0000250 bb_get_last_path_component(target.path);
251 }
Eric Andersen29edd002000-12-09 16:55:35 +0000252 if (fname_out==NULL || strlen(fname_out)<1) {
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000253 fname_out =
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000254#ifdef CONFIG_FEATURE_WGET_STATUSBAR
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000255 curfile =
Eric Andersen29edd002000-12-09 16:55:35 +0000256#endif
257 "index.html";
258 }
Matt Kraai0382eb82001-07-19 19:13:55 +0000259 if (dir_prefix != NULL)
260 fname_out = concat_path_file(dir_prefix, fname_out);
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000261#ifdef CONFIG_FEATURE_WGET_STATUSBAR
Eric Andersen29edd002000-12-09 16:55:35 +0000262 } else {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000263 curfile = bb_get_last_path_component(fname_out);
Eric Andersen29edd002000-12-09 16:55:35 +0000264#endif
265 }
Eric Andersen7d697012001-01-24 20:28:35 +0000266 if (do_continue && !fname_out)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000267 bb_error_msg_and_die("cannot specify continue (-c) without a filename (-O)");
Eric Andersen29edd002000-12-09 16:55:35 +0000268
Eric Andersen96700832000-09-04 15:15:55 +0000269
270 /*
Eric Andersen29edd002000-12-09 16:55:35 +0000271 * Open the output file stream.
Eric Andersen96700832000-09-04 15:15:55 +0000272 */
Matt Kraai65317ea2001-04-11 20:03:01 +0000273 if (strcmp(fname_out, "-") == 0) {
Randolph Chung02553a22000-12-07 03:53:47 +0000274 output = stdout;
Eric Andersen95a349f2001-05-13 00:55:54 +0000275 quiet_flag = TRUE;
Matt Kraai65317ea2001-04-11 20:03:01 +0000276 } else {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000277 output = bb_xfopen(fname_out, (do_continue ? "a" : "w"));
Eric Andersen96700832000-09-04 15:15:55 +0000278 }
279
280 /*
281 * Determine where to start transfer.
282 */
283 if (do_continue) {
Eric Andersenb520e082000-10-03 00:21:45 +0000284 if (fstat(fileno(output), &sbuf) < 0)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000285 bb_perror_msg_and_die("fstat()");
Eric Andersen96700832000-09-04 15:15:55 +0000286 if (sbuf.st_size > 0)
287 beg_range = sbuf.st_size;
288 else
289 do_continue = 0;
290 }
291
Eric Andersene6dc4392003-10-31 09:31:46 +0000292 /* We want to do exactly _one_ DNS lookup, since some
293 * sites (i.e. ftp.us.debian.org) use round-robin DNS
294 * and we want to connect to only one IP... */
Glenn L McGrathffccf6e2003-12-20 01:47:18 +0000295 bb_lookup_host(&s_in, server.host);
296 s_in.sin_port = server.port;
Eric Andersene6dc4392003-10-31 09:31:46 +0000297 if (quiet_flag==FALSE) {
298 fprintf(stdout, "Connecting to %s[%s]:%d\n",
Glenn L McGrathffccf6e2003-12-20 01:47:18 +0000299 server.host, inet_ntoa(s_in.sin_addr), ntohs(server.port));
Eric Andersene6dc4392003-10-31 09:31:46 +0000300 }
301
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000302 if (use_proxy || !target.is_ftp) {
Eric Andersen79757c92001-04-05 21:45:54 +0000303 /*
304 * HTTP session
305 */
306 do {
Glenn L McGrathe7bdfcc2003-08-28 22:03:19 +0000307 got_clen = chunked = 0;
308
Eric Andersen79757c92001-04-05 21:45:54 +0000309 if (! --try)
310 close_delete_and_die("too many redirections");
Eric Andersen7d697012001-01-24 20:28:35 +0000311
Eric Andersen79757c92001-04-05 21:45:54 +0000312 /*
313 * Open socket to http server
314 */
315 if (sfp) fclose(sfp);
Glenn L McGrathffccf6e2003-12-20 01:47:18 +0000316 sfp = open_socket(&s_in);
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000317
Eric Andersen79757c92001-04-05 21:45:54 +0000318 /*
319 * Send HTTP request.
320 */
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000321 if (use_proxy) {
Glenn L McGrathcc20ebc2003-09-10 23:52:15 +0000322 const char *format = "GET %stp://%s:%d/%s HTTP/1.1\r\n";
323#ifdef CONFIG_FEATURE_WGET_IP6_LITERAL
324 if (strchr (target.host, ':'))
325 format = "GET %stp://[%s]:%d/%s HTTP/1.1\r\n";
326#endif
327 fprintf(sfp, format,
Eric Andersen79757c92001-04-05 21:45:54 +0000328 target.is_ftp ? "f" : "ht", target.host,
Glenn L McGrath24cb17f2004-01-31 08:08:57 +0000329 ntohs(target.port), target.path);
Eric Andersen79757c92001-04-05 21:45:54 +0000330 } else {
Eric Andersen6d7fa432001-04-10 18:17:05 +0000331 fprintf(sfp, "GET /%s HTTP/1.1\r\n", target.path);
Eric Andersen79757c92001-04-05 21:45:54 +0000332 }
Eric Andersen96700832000-09-04 15:15:55 +0000333
Eric Andersen79757c92001-04-05 21:45:54 +0000334 fprintf(sfp, "Host: %s\r\nUser-Agent: Wget\r\n", target.host);
335
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000336#ifdef CONFIG_FEATURE_WGET_AUTHENTICATION
Eric Andersen79757c92001-04-05 21:45:54 +0000337 if (target.user) {
338 fprintf(sfp, "Authorization: Basic %s\r\n",
Eric Andersen0cb6f352006-01-30 22:30:41 +0000339 base64enc((unsigned char*)target.user, buf, sizeof(buf)));
Eric Andersen79757c92001-04-05 21:45:54 +0000340 }
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000341 if (use_proxy && server.user) {
Eric Andersen79757c92001-04-05 21:45:54 +0000342 fprintf(sfp, "Proxy-Authorization: Basic %s\r\n",
Eric Andersen0cb6f352006-01-30 22:30:41 +0000343 base64enc((unsigned char*)server.user, buf, sizeof(buf)));
Eric Andersen79757c92001-04-05 21:45:54 +0000344 }
345#endif
346
Eric Andersenb520e082000-10-03 00:21:45 +0000347 if (do_continue)
Eric Andersen79757c92001-04-05 21:45:54 +0000348 fprintf(sfp, "Range: bytes=%ld-\r\n", beg_range);
Eric Andersen50ae3102001-05-15 17:51:37 +0000349 if(extra_headers_left < sizeof(extra_headers))
Eric Andersen9abfe852001-05-15 20:11:49 +0000350 fputs(extra_headers,sfp);
Eric Andersen79757c92001-04-05 21:45:54 +0000351 fprintf(sfp,"Connection: close\r\n\r\n");
352
353 /*
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000354 * Retrieve HTTP response line and check for "200" status code.
355 */
Glenn L McGrathe7bdfcc2003-08-28 22:03:19 +0000356read_response:
357 if (fgets(buf, sizeof(buf), sfp) == NULL)
Eric Andersen79757c92001-04-05 21:45:54 +0000358 close_delete_and_die("no response from server");
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000359
Eric Andersen79757c92001-04-05 21:45:54 +0000360 for (s = buf ; *s != '\0' && !isspace(*s) ; ++s)
361 ;
362 for ( ; isspace(*s) ; ++s)
363 ;
364 switch (status = atoi(s)) {
365 case 0:
Eric Andersen6d7fa432001-04-10 18:17:05 +0000366 case 100:
367 while (gethdr(buf, sizeof(buf), sfp, &n) != NULL);
368 goto read_response;
Eric Andersen79757c92001-04-05 21:45:54 +0000369 case 200:
370 if (do_continue && output != stdout)
371 output = freopen(fname_out, "w", output);
372 do_continue = 0;
373 break;
374 case 300: /* redirection */
375 case 301:
376 case 302:
377 case 303:
378 break;
379 case 206:
380 if (do_continue)
381 break;
382 /*FALLTHRU*/
383 default:
384 chomp(buf);
385 close_delete_and_die("server returned error %d: %s", atoi(s), buf);
386 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000387
Eric Andersen79757c92001-04-05 21:45:54 +0000388 /*
389 * Retrieve HTTP headers.
390 */
391 while ((s = gethdr(buf, sizeof(buf), sfp, &n)) != NULL) {
392 if (strcasecmp(buf, "content-length") == 0) {
Eric Andersen24794452004-03-06 22:11:45 +0000393 unsigned long value;
394 if (safe_strtoul(s, &value)) {
395 close_delete_and_die("content-length %s is garbage", s);
396 }
397 filesize = value;
Eric Andersen79757c92001-04-05 21:45:54 +0000398 got_clen = 1;
399 continue;
400 }
Eric Andersen6d7fa432001-04-10 18:17:05 +0000401 if (strcasecmp(buf, "transfer-encoding") == 0) {
402 if (strcasecmp(s, "chunked") == 0) {
403 chunked = got_clen = 1;
404 } else {
Eric Andersen79757c92001-04-05 21:45:54 +0000405 close_delete_and_die("server wants to do %s transfer encoding", s);
Eric Andersen6d7fa432001-04-10 18:17:05 +0000406 }
407 }
Eric Andersen79757c92001-04-05 21:45:54 +0000408 if (strcasecmp(buf, "location") == 0) {
409 if (s[0] == '/')
Manuel Novoa III cad53642003-03-19 09:13:01 +0000410 target.path = bb_xstrdup(s+1);
Eric Andersen79757c92001-04-05 21:45:54 +0000411 else {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000412 parse_url(bb_xstrdup(s), &target);
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000413 if (use_proxy == 0) {
Eric Andersen79757c92001-04-05 21:45:54 +0000414 server.host = target.host;
415 server.port = target.port;
416 }
Glenn L McGrath58a2e0e2004-01-17 23:07:14 +0000417 bb_lookup_host(&s_in, server.host);
418 s_in.sin_port = server.port;
419 break;
Eric Andersen79757c92001-04-05 21:45:54 +0000420 }
421 }
422 }
423 } while(status >= 300);
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000424
Eric Andersen79757c92001-04-05 21:45:54 +0000425 dfp = sfp;
426 }
427 else
428 {
429 /*
430 * FTP session
431 */
432 if (! target.user)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000433 target.user = bb_xstrdup("anonymous:busybox@");
Eric Andersen79757c92001-04-05 21:45:54 +0000434
Glenn L McGrathffccf6e2003-12-20 01:47:18 +0000435 sfp = open_socket(&s_in);
Eric Andersen79757c92001-04-05 21:45:54 +0000436 if (ftpcmd(NULL, NULL, sfp, buf) != 220)
437 close_delete_and_die("%s", buf+4);
438
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000439 /*
Eric Andersen79757c92001-04-05 21:45:54 +0000440 * Splitting username:password pair,
441 * trying to log in
442 */
443 s = strchr(target.user, ':');
444 if (s)
445 *(s++) = '\0';
446 switch(ftpcmd("USER ", target.user, sfp, buf)) {
447 case 230:
Eric Andersenb520e082000-10-03 00:21:45 +0000448 break;
Eric Andersen79757c92001-04-05 21:45:54 +0000449 case 331:
450 if (ftpcmd("PASS ", s, sfp, buf) == 230)
451 break;
452 /* FALLTHRU (failed login) */
453 default:
454 close_delete_and_die("ftp login: %s", buf+4);
455 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000456
Eric Andersen79757c92001-04-05 21:45:54 +0000457 ftpcmd("CDUP", NULL, sfp, buf);
458 ftpcmd("TYPE I", NULL, sfp, buf);
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000459
Eric Andersen79757c92001-04-05 21:45:54 +0000460 /*
461 * Querying file size
462 */
463 if (ftpcmd("SIZE /", target.path, sfp, buf) == 213) {
Eric Andersen24794452004-03-06 22:11:45 +0000464 unsigned long value;
465 if (safe_strtoul(buf+4, &value)) {
466 close_delete_and_die("SIZE value is garbage");
467 }
468 filesize = value;
Eric Andersen96700832000-09-04 15:15:55 +0000469 got_clen = 1;
Eric Andersen96700832000-09-04 15:15:55 +0000470 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000471
Eric Andersen79757c92001-04-05 21:45:54 +0000472 /*
473 * Entering passive mode
474 */
475 if (ftpcmd("PASV", NULL, sfp, buf) != 227)
476 close_delete_and_die("PASV: %s", buf+4);
477 s = strrchr(buf, ',');
478 *s = 0;
479 port = atoi(s+1);
480 s = strrchr(buf, ',');
481 port += atoi(s+1) * 256;
Glenn L McGrathffccf6e2003-12-20 01:47:18 +0000482 s_in.sin_port = htons(port);
483 dfp = open_socket(&s_in);
Eric Andersen79757c92001-04-05 21:45:54 +0000484
485 if (do_continue) {
486 sprintf(buf, "REST %ld", beg_range);
487 if (ftpcmd(buf, NULL, sfp, buf) != 350) {
488 if (output != stdout)
489 output = freopen(fname_out, "w", output);
490 do_continue = 0;
491 } else
492 filesize -= beg_range;
Eric Andersen96700832000-09-04 15:15:55 +0000493 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000494
Eric Andersen79757c92001-04-05 21:45:54 +0000495 if (ftpcmd("RETR /", target.path, sfp, buf) > 150)
496 close_delete_and_die("RETR: %s", buf+4);
497
Eric Andersen96700832000-09-04 15:15:55 +0000498 }
499
Eric Andersen79757c92001-04-05 21:45:54 +0000500
Eric Andersen96700832000-09-04 15:15:55 +0000501 /*
Eric Andersen79757c92001-04-05 21:45:54 +0000502 * Retrieve file
Eric Andersen96700832000-09-04 15:15:55 +0000503 */
Eric Andersen6d7fa432001-04-10 18:17:05 +0000504 if (chunked) {
505 fgets(buf, sizeof(buf), dfp);
506 filesize = strtol(buf, (char **) NULL, 16);
507 }
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000508#ifdef CONFIG_FEATURE_WGET_STATUSBAR
Glenn L McGrath1bca5ed2000-12-09 08:12:06 +0000509 if (quiet_flag==FALSE)
510 progressmeter(-1);
Eric Andersenb520e082000-10-03 00:21:45 +0000511#endif
Mark Whitley30ac01c2001-04-17 18:13:16 +0000512 do {
Glenn L McGrath23365972003-08-29 06:25:04 +0000513 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 +0000514 if (safe_fwrite(buf, 1, n, output) != n) {
Bernhard Reutner-Fischer1b9d7c92006-06-03 22:45:37 +0000515 bb_perror_msg_and_die(bb_msg_write_error);
Glenn L McGrath83e4a5b2003-08-28 21:55:22 +0000516 }
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000517#ifdef CONFIG_FEATURE_WGET_STATUSBAR
Glenn L McGrath83e4a5b2003-08-28 21:55:22 +0000518 statbytes+=n;
Eric Andersenb520e082000-10-03 00:21:45 +0000519#endif
Glenn L McGrath83e4a5b2003-08-28 21:55:22 +0000520 if (got_clen) {
521 filesize -= n;
522 }
523 }
Eric Andersen79757c92001-04-05 21:45:54 +0000524
Eric Andersen6d7fa432001-04-10 18:17:05 +0000525 if (chunked) {
Matt Kraai854125f2001-05-09 19:15:46 +0000526 safe_fgets(buf, sizeof(buf), dfp); /* This is a newline */
527 safe_fgets(buf, sizeof(buf), dfp);
Eric Andersen6d7fa432001-04-10 18:17:05 +0000528 filesize = strtol(buf, (char **) NULL, 16);
Glenn L McGrath83e4a5b2003-08-28 21:55:22 +0000529 if (filesize==0) {
530 chunked = 0; /* all done! */
531 }
Eric Andersen6d7fa432001-04-10 18:17:05 +0000532 }
533
Glenn L McGrath83e4a5b2003-08-28 21:55:22 +0000534 if (n == 0 && ferror(dfp)) {
Bernhard Reutner-Fischer1b9d7c92006-06-03 22:45:37 +0000535 bb_perror_msg_and_die(bb_msg_read_error);
Glenn L McGrath83e4a5b2003-08-28 21:55:22 +0000536 }
Eric Andersen6d7fa432001-04-10 18:17:05 +0000537 } while (chunked);
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000538#ifdef CONFIG_FEATURE_WGET_STATUSBAR
Mark Whitley30ac01c2001-04-17 18:13:16 +0000539 if (quiet_flag==FALSE)
540 progressmeter(1);
541#endif
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000542 if ((use_proxy == 0) && target.is_ftp) {
Eric Andersen79757c92001-04-05 21:45:54 +0000543 fclose(dfp);
544 if (ftpcmd(NULL, NULL, sfp, buf) != 226)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000545 bb_error_msg_and_die("ftp error: %s", buf+4);
Eric Andersen79757c92001-04-05 21:45:54 +0000546 ftpcmd("QUIT", NULL, sfp, buf);
547 }
Eric Andersen79757c92001-04-05 21:45:54 +0000548 exit(EXIT_SUCCESS);
Eric Andersen96700832000-09-04 15:15:55 +0000549}
550
551
Eric Andersen79757c92001-04-05 21:45:54 +0000552void parse_url(char *url, struct host_info *h)
Eric Andersen96700832000-09-04 15:15:55 +0000553{
Glenn L McGrathcc20ebc2003-09-10 23:52:15 +0000554 char *cp, *sp, *up, *pp;
Eric Andersen96700832000-09-04 15:15:55 +0000555
Eric Andersen79757c92001-04-05 21:45:54 +0000556 if (strncmp(url, "http://", 7) == 0) {
Glenn L McGrath036dbaa2004-01-17 05:03:31 +0000557 h->port = bb_lookup_port("http", "tcp", 80);
Eric Andersen79757c92001-04-05 21:45:54 +0000558 h->host = url + 7;
559 h->is_ftp = 0;
560 } else if (strncmp(url, "ftp://", 6) == 0) {
Glenn L McGrath036dbaa2004-01-17 05:03:31 +0000561 h->port = bb_lookup_port("ftp", "tfp", 21);
Eric Andersen79757c92001-04-05 21:45:54 +0000562 h->host = url + 6;
563 h->is_ftp = 1;
564 } else
Manuel Novoa III cad53642003-03-19 09:13:01 +0000565 bb_error_msg_and_die("not an http or ftp url: %s", url);
Eric Andersen96700832000-09-04 15:15:55 +0000566
Eric Andersen79757c92001-04-05 21:45:54 +0000567 sp = strchr(h->host, '/');
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000568 if (sp) {
Matt Kraaia9711a52001-01-03 16:15:15 +0000569 *sp++ = '\0';
Eric Andersen79757c92001-04-05 21:45:54 +0000570 h->path = sp;
Matt Kraaia9711a52001-01-03 16:15:15 +0000571 } else
Manuel Novoa III cad53642003-03-19 09:13:01 +0000572 h->path = bb_xstrdup("");
Eric Andersen79757c92001-04-05 21:45:54 +0000573
574 up = strrchr(h->host, '@');
575 if (up != NULL) {
576 h->user = h->host;
577 *up++ = '\0';
578 h->host = up;
579 } else
580 h->user = NULL;
581
Glenn L McGrathcc20ebc2003-09-10 23:52:15 +0000582 pp = h->host;
583
584#ifdef CONFIG_FEATURE_WGET_IP6_LITERAL
585 if (h->host[0] == '[') {
586 char *ep;
587
588 ep = h->host + 1;
Eric Andersen6231f092003-09-11 08:25:11 +0000589 while (*ep == ':' || isxdigit (*ep))
Glenn L McGrathcc20ebc2003-09-10 23:52:15 +0000590 ep++;
591 if (*ep == ']') {
592 h->host++;
593 *ep = '\0';
594 pp = ep + 1;
595 }
596 }
597#endif
598
599 cp = strchr(pp, ':');
Eric Andersen79757c92001-04-05 21:45:54 +0000600 if (cp != NULL) {
601 *cp++ = '\0';
Glenn L McGrathf980bd52003-12-27 00:21:47 +0000602 h->port = htons(atoi(cp));
Eric Andersen79757c92001-04-05 21:45:54 +0000603 }
Eric Andersen96700832000-09-04 15:15:55 +0000604}
605
606
Glenn L McGrathffccf6e2003-12-20 01:47:18 +0000607FILE *open_socket(struct sockaddr_in *s_in)
Eric Andersen96700832000-09-04 15:15:55 +0000608{
Eric Andersen96700832000-09-04 15:15:55 +0000609 FILE *fp;
610
Glenn L McGrathffccf6e2003-12-20 01:47:18 +0000611 fp = fdopen(xconnect(s_in), "r+");
612 if (fp == NULL)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000613 bb_perror_msg_and_die("fdopen()");
Eric Andersen96700832000-09-04 15:15:55 +0000614
615 return fp;
616}
617
618
619char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc)
620{
621 char *s, *hdrval;
622 int c;
623
624 *istrunc = 0;
625
626 /* retrieve header line */
627 if (fgets(buf, bufsiz, fp) == NULL)
628 return NULL;
629
630 /* see if we are at the end of the headers */
631 for (s = buf ; *s == '\r' ; ++s)
632 ;
633 if (s[0] == '\n')
634 return NULL;
635
636 /* convert the header name to lower case */
637 for (s = buf ; isalnum(*s) || *s == '-' ; ++s)
638 *s = tolower(*s);
639
640 /* verify we are at the end of the header name */
641 if (*s != ':')
Manuel Novoa III cad53642003-03-19 09:13:01 +0000642 bb_error_msg_and_die("bad header line: %s", buf);
Eric Andersen96700832000-09-04 15:15:55 +0000643
644 /* locate the start of the header value */
645 for (*s++ = '\0' ; *s == ' ' || *s == '\t' ; ++s)
646 ;
647 hdrval = s;
648
649 /* locate the end of header */
650 while (*s != '\0' && *s != '\r' && *s != '\n')
651 ++s;
652
653 /* end of header found */
654 if (*s != '\0') {
655 *s = '\0';
656 return hdrval;
657 }
658
Eric Andersen5d638842000-09-14 21:46:30 +0000659 /* Rats! The buffer isn't big enough to hold the entire header value. */
Eric Andersen96700832000-09-04 15:15:55 +0000660 while (c = getc(fp), c != EOF && c != '\n')
661 ;
662 *istrunc = 1;
663 return hdrval;
664}
665
Eric Andersen79757c92001-04-05 21:45:54 +0000666static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf)
667{
Eric Andersen79757c92001-04-05 21:45:54 +0000668 if (s1) {
669 if (!s2) s2="";
Eric Andersen3f1cf452003-03-11 18:03:39 +0000670 fprintf(fp, "%s%s\r\n", s1, s2);
Eric Andersen79757c92001-04-05 21:45:54 +0000671 fflush(fp);
672 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000673
Eric Andersen79757c92001-04-05 21:45:54 +0000674 do {
Glenn L McGrath32da8852004-04-08 10:27:11 +0000675 char *buf_ptr;
676
677 if (fgets(buf, 510, fp) == NULL) {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000678 bb_perror_msg_and_die("fgets()");
Glenn L McGrath32da8852004-04-08 10:27:11 +0000679 }
680 buf_ptr = strstr(buf, "\r\n");
681 if (buf_ptr) {
682 *buf_ptr = '\0';
683 }
Eric Andersen79757c92001-04-05 21:45:54 +0000684 } while (! isdigit(buf[0]) || buf[3] != ' ');
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000685
Eric Andersen79757c92001-04-05 21:45:54 +0000686 return atoi(buf);
687}
688
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000689#ifdef CONFIG_FEATURE_WGET_STATUSBAR
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000690/* Stuff below is from BSD rcp util.c, as added to openshh.
Eric Andersen4e573f42000-11-14 23:29:24 +0000691 * Original copyright notice is retained at the end of this file.
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000692 *
693 */
Eric Andersenb520e082000-10-03 00:21:45 +0000694
695
Eric Andersen3e6ff902001-03-09 21:24:12 +0000696static int
Eric Andersenb520e082000-10-03 00:21:45 +0000697getttywidth(void)
698{
Eric Andersen8efe9672003-09-15 08:33:45 +0000699 int width=0;
700 get_terminal_width_height(0, &width, NULL);
701 return (width);
Eric Andersenb520e082000-10-03 00:21:45 +0000702}
703
Eric Andersen3e6ff902001-03-09 21:24:12 +0000704static void
Eric Andersenb520e082000-10-03 00:21:45 +0000705updateprogressmeter(int ignore)
706{
707 int save_errno = errno;
708
709 progressmeter(0);
710 errno = save_errno;
711}
712
Eric Andersen3e6ff902001-03-09 21:24:12 +0000713static void
Eric Andersenb520e082000-10-03 00:21:45 +0000714alarmtimer(int wait)
715{
716 struct itimerval itv;
717
718 itv.it_value.tv_sec = wait;
719 itv.it_value.tv_usec = 0;
720 itv.it_interval = itv.it_value;
721 setitimer(ITIMER_REAL, &itv, NULL);
722}
723
724
Eric Andersen3e6ff902001-03-09 21:24:12 +0000725static void
Eric Andersenb520e082000-10-03 00:21:45 +0000726progressmeter(int flag)
727{
728 static const char prefixes[] = " KMGTP";
729 static struct timeval lastupdate;
Mark Whitley30ac01c2001-04-17 18:13:16 +0000730 static off_t lastsize, totalsize;
Eric Andersenb520e082000-10-03 00:21:45 +0000731 struct timeval now, td, wait;
732 off_t cursize, abbrevsize;
733 double elapsed;
734 int ratio, barlength, i, remaining;
735 char buf[256];
736
737 if (flag == -1) {
738 (void) gettimeofday(&start, (struct timezone *) 0);
739 lastupdate = start;
740 lastsize = 0;
Mark Whitley30ac01c2001-04-17 18:13:16 +0000741 totalsize = filesize; /* as filesize changes.. */
Eric Andersenb520e082000-10-03 00:21:45 +0000742 }
743
744 (void) gettimeofday(&now, (struct timezone *) 0);
745 cursize = statbytes;
Mark Whitley30ac01c2001-04-17 18:13:16 +0000746 if (totalsize != 0 && !chunked) {
747 ratio = 100.0 * cursize / totalsize;
Eric Andersenb520e082000-10-03 00:21:45 +0000748 ratio = MAX(ratio, 0);
749 ratio = MIN(ratio, 100);
750 } else
751 ratio = 100;
752
753 snprintf(buf, sizeof(buf), "\r%-20.20s %3d%% ", curfile, ratio);
754
755 barlength = getttywidth() - 51;
756 if (barlength > 0) {
757 i = barlength * ratio / 100;
758 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
759 "|%.*s%*s|", i,
760 "*****************************************************************************"
761 "*****************************************************************************",
762 barlength - i, "");
763 }
764 i = 0;
765 abbrevsize = cursize;
766 while (abbrevsize >= 100000 && i < sizeof(prefixes)) {
767 i++;
768 abbrevsize >>= 10;
769 }
770 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %5d %c%c ",
771 (int) abbrevsize, prefixes[i], prefixes[i] == ' ' ? ' ' :
772 'B');
773
774 timersub(&now, &lastupdate, &wait);
775 if (cursize > lastsize) {
776 lastupdate = now;
777 lastsize = cursize;
778 if (wait.tv_sec >= STALLTIME) {
779 start.tv_sec += wait.tv_sec;
780 start.tv_usec += wait.tv_usec;
781 }
782 wait.tv_sec = 0;
783 }
784 timersub(&now, &start, &td);
785 elapsed = td.tv_sec + (td.tv_usec / 1000000.0);
786
Mark Whitley30ac01c2001-04-17 18:13:16 +0000787 if (wait.tv_sec >= STALLTIME) {
Eric Andersenb520e082000-10-03 00:21:45 +0000788 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
789 " - stalled -");
Mark Whitley30ac01c2001-04-17 18:13:16 +0000790 } else if (statbytes <= 0 || elapsed <= 0.0 || cursize > totalsize || chunked) {
791 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
792 " --:-- ETA");
Eric Andersenb520e082000-10-03 00:21:45 +0000793 } else {
Mark Whitley30ac01c2001-04-17 18:13:16 +0000794 remaining = (int) (totalsize / (statbytes / elapsed) - elapsed);
Eric Andersenb520e082000-10-03 00:21:45 +0000795 i = remaining / 3600;
796 if (i)
797 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
798 "%2d:", i);
799 else
800 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
801 " ");
802 i = remaining % 3600;
803 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
804 "%02d:%02d ETA", i / 60, i % 60);
805 }
Eric Andersen70060d22004-03-27 10:02:48 +0000806 write(STDERR_FILENO, buf, strlen(buf));
Eric Andersenb520e082000-10-03 00:21:45 +0000807
808 if (flag == -1) {
809 struct sigaction sa;
810 sa.sa_handler = updateprogressmeter;
811 sigemptyset(&sa.sa_mask);
812 sa.sa_flags = SA_RESTART;
813 sigaction(SIGALRM, &sa, NULL);
814 alarmtimer(1);
815 } else if (flag == 1) {
816 alarmtimer(0);
817 statbytes = 0;
Mark Whitley30ac01c2001-04-17 18:13:16 +0000818 putc('\n', stderr);
Eric Andersenb520e082000-10-03 00:21:45 +0000819 }
820}
821#endif
Eric Andersen4e573f42000-11-14 23:29:24 +0000822
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000823/* Original copyright notice which applies to the CONFIG_FEATURE_WGET_STATUSBAR stuff,
Eric Andersenaff114c2004-04-14 17:51:38 +0000824 * much of which was blatantly stolen from openssh. */
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000825
Eric Andersen4e573f42000-11-14 23:29:24 +0000826/*-
827 * Copyright (c) 1992, 1993
828 * The Regents of the University of California. All rights reserved.
829 *
830 * Redistribution and use in source and binary forms, with or without
831 * modification, are permitted provided that the following conditions
832 * are met:
833 * 1. Redistributions of source code must retain the above copyright
834 * notice, this list of conditions and the following disclaimer.
835 * 2. Redistributions in binary form must reproduce the above copyright
836 * notice, this list of conditions and the following disclaimer in the
837 * documentation and/or other materials provided with the distribution.
838 *
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000839 * 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change
840 * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change>
Eric Andersen4e573f42000-11-14 23:29:24 +0000841 *
842 * 4. Neither the name of the University nor the names of its contributors
843 * may be used to endorse or promote products derived from this software
844 * without specific prior written permission.
845 *
846 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
847 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
848 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
849 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
850 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
851 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
852 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
853 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
854 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
855 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
856 * SUCH DAMAGE.
857 *
Eric Andersen751750e2004-10-08 08:27:40 +0000858 * $Id: wget.c,v 1.75 2004/10/08 08:27:40 andersen Exp $
Eric Andersen4e573f42000-11-14 23:29:24 +0000859 */