blob: 6efa3bf217d5c33d9a0ac484b18a141506cb0db9 [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
Eric Andersenb520e082000-10-03 00:21:45 +000020#include <sys/time.h>
Eric Andersen96700832000-09-04 15:15:55 +000021#include <sys/types.h>
22#include <sys/stat.h>
23#include <sys/socket.h>
24#include <netinet/in.h>
25#include <arpa/inet.h>
26#include <netdb.h>
27
Eric Andersen50ae3102001-05-15 17:51:37 +000028#include <getopt.h>
29
Eric Andersencbe31da2001-02-20 06:14:08 +000030#include "busybox.h"
31
Eric Andersen79757c92001-04-05 21:45:54 +000032struct host_info {
33 char *host;
34 int port;
35 char *path;
36 int is_ftp;
37 char *user;
38};
39
40static void parse_url(char *url, struct host_info *h);
Glenn L McGrathffccf6e2003-12-20 01:47:18 +000041static FILE *open_socket(struct sockaddr_in *s_in);
Eric Andersen3e6ff902001-03-09 21:24:12 +000042static char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc);
Eric Andersen79757c92001-04-05 21:45:54 +000043static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf);
Eric Andersen96700832000-09-04 15:15:55 +000044
Eric Andersenb520e082000-10-03 00:21:45 +000045/* Globals (can be accessed from signal handlers */
46static off_t filesize = 0; /* content-length of the file */
Eric Andersen6d7fa432001-04-10 18:17:05 +000047static int chunked = 0; /* chunked transfer encoding */
Eric Andersenbdfd0d72001-10-24 05:00:29 +000048#ifdef CONFIG_FEATURE_WGET_STATUSBAR
Eric Andersen20aab262001-07-19 22:28:02 +000049static void progressmeter(int flag);
Eric Andersenb520e082000-10-03 00:21:45 +000050static char *curfile; /* Name of current file being transferred. */
51static struct timeval start; /* Time a transfer started. */
Mark Whitley30ac01c2001-04-17 18:13:16 +000052static volatile unsigned long statbytes = 0; /* Number of bytes transferred so far. */
Eric Andersenb520e082000-10-03 00:21:45 +000053/* For progressmeter() -- number of seconds before xfer considered "stalled" */
Mark Whitley59ab0252001-01-23 22:30:04 +000054static const int STALLTIME = 5;
Eric Andersenb520e082000-10-03 00:21:45 +000055#endif
Eric Andersenc7bda1c2004-03-15 08:29:22 +000056
Eric Andersen3e6ff902001-03-09 21:24:12 +000057static void close_and_delete_outfile(FILE* output, char *fname_out, int do_continue)
Eric Andersen7d697012001-01-24 20:28:35 +000058{
59 if (output != stdout && do_continue==0) {
60 fclose(output);
61 unlink(fname_out);
62 }
63}
Eric Andersen96700832000-09-04 15:15:55 +000064
Matt Kraai854125f2001-05-09 19:15:46 +000065/* Read NMEMB elements of SIZE bytes into PTR from STREAM. Returns the
66 * number of elements read, and a short count if an eof or non-interrupt
67 * error is encountered. */
68static size_t safe_fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
69{
70 size_t ret = 0;
71
72 do {
73 clearerr(stream);
74 ret += fread((char *)ptr + (ret * size), size, nmemb - ret, stream);
75 } while (ret < nmemb && ferror(stream) && errno == EINTR);
76
77 return ret;
78}
79
80/* Write NMEMB elements of SIZE bytes from PTR to STREAM. Returns the
81 * number of elements written, and a short count if an eof or non-interrupt
82 * error is encountered. */
83static size_t safe_fwrite(void *ptr, size_t size, size_t nmemb, FILE *stream)
84{
85 size_t ret = 0;
86
87 do {
88 clearerr(stream);
89 ret += fwrite((char *)ptr + (ret * size), size, nmemb - ret, stream);
90 } while (ret < nmemb && ferror(stream) && errno == EINTR);
91
92 return ret;
93}
94
95/* Read a line or SIZE - 1 bytes into S, whichever is less, from STREAM.
96 * Returns S, or NULL if an eof or non-interrupt error is encountered. */
97static char *safe_fgets(char *s, int size, FILE *stream)
98{
99 char *ret;
100
101 do {
102 clearerr(stream);
103 ret = fgets(s, size, stream);
104 } while (ret == NULL && ferror(stream) && errno == EINTR);
105
106 return ret;
107}
108
Eric Andersen79757c92001-04-05 21:45:54 +0000109#define close_delete_and_die(s...) { \
110 close_and_delete_outfile(output, fname_out, do_continue); \
Manuel Novoa III cad53642003-03-19 09:13:01 +0000111 bb_error_msg_and_die(s); }
Eric Andersen79757c92001-04-05 21:45:54 +0000112
113
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000114#ifdef CONFIG_FEATURE_WGET_AUTHENTICATION
Eric Andersen79757c92001-04-05 21:45:54 +0000115/*
116 * Base64-encode character string
117 * oops... isn't something similar in uuencode.c?
Eric Andersen14f5c8d2005-04-16 19:39:00 +0000118 * XXX: It would be better to use already existing code
Eric Andersen79757c92001-04-05 21:45:54 +0000119 */
Eric Andersen14f5c8d2005-04-16 19:39:00 +0000120static char *base64enc(unsigned char *p, char *buf, int len) {
Eric Andersen79757c92001-04-05 21:45:54 +0000121
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000122 char al[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
123 "0123456789+/";
Eric Andersen79757c92001-04-05 21:45:54 +0000124 char *s = buf;
125
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000126 while(*p) {
Eric Andersen79757c92001-04-05 21:45:54 +0000127 if (s >= buf+len-4)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000128 bb_error_msg_and_die("buffer overflow");
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000129 *(s++) = al[(*p >> 2) & 0x3F];
130 *(s++) = al[((*p << 4) & 0x30) | ((*(p+1) >> 4) & 0x0F)];
131 *s = *(s+1) = '=';
132 *(s+2) = 0;
133 if (! *(++p)) break;
134 *(s++) = al[((*p << 2) & 0x3C) | ((*(p+1) >> 6) & 0x03)];
135 if (! *(++p)) break;
136 *(s++) = al[*(p++) & 0x3F];
137 }
Eric Andersen79757c92001-04-05 21:45:54 +0000138
139 return buf;
140}
141#endif
142
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000143#define WGET_OPT_CONTINUE 1
144#define WGET_OPT_QUIET 2
145#define WGET_OPT_PASSIVE 4
146#define WGET_OPT_OUTNAME 8
147#define WGET_OPT_HEADER 16
148#define WGET_OPT_PREFIX 32
149#define WGET_OPT_PROXY 64
150
151static 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};
161
Eric Andersen96700832000-09-04 15:15:55 +0000162int wget_main(int argc, char **argv)
163{
Eric Andersen79757c92001-04-05 21:45:54 +0000164 int n, try=5, status;
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000165 unsigned long opt;
Eric Andersen79757c92001-04-05 21:45:54 +0000166 int port;
Robert Griebld7760112002-05-14 23:36:45 +0000167 char *proxy = 0;
Eric Andersen8071c022001-06-21 19:45:06 +0000168 char *dir_prefix=NULL;
Eric Andersen29edd002000-12-09 16:55:35 +0000169 char *s, buf[512];
170 struct stat sbuf;
Eric Andersen50ae3102001-05-15 17:51:37 +0000171 char extra_headers[1024];
172 char *extra_headers_ptr = extra_headers;
173 int extra_headers_left = sizeof(extra_headers);
Eric Andersen79757c92001-04-05 21:45:54 +0000174 struct host_info server, target;
Eric Andersene6dc4392003-10-31 09:31:46 +0000175 struct sockaddr_in s_in;
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000176 llist_t *headers_llist = NULL;
Eric Andersen79757c92001-04-05 21:45:54 +0000177
"Vladimir N. Oleynik"f704b272005-10-14 09:56:52 +0000178 FILE *sfp = NULL; /* socket to web/ftp server */
179 FILE *dfp = NULL; /* socket to ftp server (data) */
180 char *fname_out = NULL; /* where to direct output (-O) */
181 int do_continue = 0; /* continue a prev transfer (-c) */
182 long beg_range = 0L; /* range at which continue begins */
183 int got_clen = 0; /* got content-length: from server */
184 FILE *output; /* socket to web server */
185 int quiet_flag = FALSE; /* Be verry, verry quiet... */
186 int use_proxy = 1; /* Use proxies if env vars are set */
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000187 char *proxy_flag = "on"; /* Use proxies if env vars are set */
Eric Andersen29edd002000-12-09 16:55:35 +0000188
Eric Andersen96700832000-09-04 15:15:55 +0000189 /*
190 * Crack command line.
191 */
"Vladimir N. Oleynik"f704b272005-10-14 09:56:52 +0000192 bb_opt_complementally = "-1:\203::";
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000193 bb_applet_long_options = wget_long_options;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000194 opt = bb_getopt_ulflags(argc, argv, "cq\213O:\203:P:Y:",
195 &fname_out, &headers_llist,
"Vladimir N. Oleynik"f704b272005-10-14 09:56:52 +0000196 &dir_prefix, &proxy_flag);
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000197 if (opt & WGET_OPT_CONTINUE) {
198 ++do_continue;
199 }
200 if (opt & WGET_OPT_QUIET) {
201 quiet_flag = TRUE;
202 }
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000203 if (strcmp(proxy_flag, "off") == 0) {
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000204 /* Use the proxy if necessary. */
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000205 use_proxy = 0;
Glenn L McGrath514aeab2003-12-19 12:08:56 +0000206 }
207 if (opt & WGET_OPT_HEADER) {
208 while (headers_llist) {
209 int arglen = strlen(headers_llist->data);
210 if (extra_headers_left - arglen - 2 <= 0)
211 bb_error_msg_and_die("extra_headers buffer too small(need %i)", extra_headers_left - arglen);
212 strcpy(extra_headers_ptr, headers_llist->data);
213 extra_headers_ptr += arglen;
214 extra_headers_left -= ( arglen + 2 );
215 *extra_headers_ptr++ = '\r';
216 *extra_headers_ptr++ = '\n';
217 *(extra_headers_ptr + 1) = 0;
218 headers_llist = headers_llist->link;
Eric Andersen96700832000-09-04 15:15:55 +0000219 }
220 }
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000221
Eric Andersen79757c92001-04-05 21:45:54 +0000222 parse_url(argv[optind], &target);
223 server.host = target.host;
224 server.port = target.port;
225
Eric Andersen96700832000-09-04 15:15:55 +0000226 /*
Eric Andersenf3b2b522000-12-07 22:42:11 +0000227 * Use the proxy if necessary.
Eric Andersen96700832000-09-04 15:15:55 +0000228 */
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000229 if (use_proxy) {
Robert Griebld7760112002-05-14 23:36:45 +0000230 proxy = getenv(target.is_ftp ? "ftp_proxy" : "http_proxy");
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000231 if (proxy && *proxy) {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000232 parse_url(bb_xstrdup(proxy), &server);
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000233 } else {
234 use_proxy = 0;
235 }
Robert Griebld7760112002-05-14 23:36:45 +0000236 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000237
Eric Andersen29edd002000-12-09 16:55:35 +0000238 /* Guess an output filename */
239 if (!fname_out) {
Eric Andersen751750e2004-10-08 08:27:40 +0000240 // Dirty hack. Needed because bb_get_last_path_component
241 // will destroy trailing / by storing '\0' in last byte!
Rob Landley6f2a0b22006-02-21 18:34:54 +0000242 if(*target.path && target.path[strlen(target.path)-1]!='/') {
Eric Andersen751750e2004-10-08 08:27:40 +0000243 fname_out =
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000244#ifdef CONFIG_FEATURE_WGET_STATUSBAR
Eric Andersen751750e2004-10-08 08:27:40 +0000245 curfile =
Eric Andersen29edd002000-12-09 16:55:35 +0000246#endif
Eric Andersen751750e2004-10-08 08:27:40 +0000247 bb_get_last_path_component(target.path);
248 }
Eric Andersen29edd002000-12-09 16:55:35 +0000249 if (fname_out==NULL || strlen(fname_out)<1) {
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000250 fname_out =
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000251#ifdef CONFIG_FEATURE_WGET_STATUSBAR
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000252 curfile =
Eric Andersen29edd002000-12-09 16:55:35 +0000253#endif
254 "index.html";
255 }
Matt Kraai0382eb82001-07-19 19:13:55 +0000256 if (dir_prefix != NULL)
257 fname_out = concat_path_file(dir_prefix, fname_out);
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000258#ifdef CONFIG_FEATURE_WGET_STATUSBAR
Eric Andersen29edd002000-12-09 16:55:35 +0000259 } else {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000260 curfile = bb_get_last_path_component(fname_out);
Eric Andersen29edd002000-12-09 16:55:35 +0000261#endif
262 }
Eric Andersen7d697012001-01-24 20:28:35 +0000263 if (do_continue && !fname_out)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000264 bb_error_msg_and_die("cannot specify continue (-c) without a filename (-O)");
Eric Andersen29edd002000-12-09 16:55:35 +0000265
Eric Andersen96700832000-09-04 15:15:55 +0000266
267 /*
Eric Andersen29edd002000-12-09 16:55:35 +0000268 * Open the output file stream.
Eric Andersen96700832000-09-04 15:15:55 +0000269 */
Matt Kraai65317ea2001-04-11 20:03:01 +0000270 if (strcmp(fname_out, "-") == 0) {
Randolph Chung02553a22000-12-07 03:53:47 +0000271 output = stdout;
Eric Andersen95a349f2001-05-13 00:55:54 +0000272 quiet_flag = TRUE;
Matt Kraai65317ea2001-04-11 20:03:01 +0000273 } else {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000274 output = bb_xfopen(fname_out, (do_continue ? "a" : "w"));
Eric Andersen96700832000-09-04 15:15:55 +0000275 }
276
277 /*
278 * Determine where to start transfer.
279 */
280 if (do_continue) {
Eric Andersenb520e082000-10-03 00:21:45 +0000281 if (fstat(fileno(output), &sbuf) < 0)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000282 bb_perror_msg_and_die("fstat()");
Eric Andersen96700832000-09-04 15:15:55 +0000283 if (sbuf.st_size > 0)
284 beg_range = sbuf.st_size;
285 else
286 do_continue = 0;
287 }
288
Eric Andersene6dc4392003-10-31 09:31:46 +0000289 /* We want to do exactly _one_ DNS lookup, since some
290 * sites (i.e. ftp.us.debian.org) use round-robin DNS
291 * and we want to connect to only one IP... */
Glenn L McGrathffccf6e2003-12-20 01:47:18 +0000292 bb_lookup_host(&s_in, server.host);
293 s_in.sin_port = server.port;
Eric Andersene6dc4392003-10-31 09:31:46 +0000294 if (quiet_flag==FALSE) {
295 fprintf(stdout, "Connecting to %s[%s]:%d\n",
Glenn L McGrathffccf6e2003-12-20 01:47:18 +0000296 server.host, inet_ntoa(s_in.sin_addr), ntohs(server.port));
Eric Andersene6dc4392003-10-31 09:31:46 +0000297 }
298
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000299 if (use_proxy || !target.is_ftp) {
Eric Andersen79757c92001-04-05 21:45:54 +0000300 /*
301 * HTTP session
302 */
303 do {
Glenn L McGrathe7bdfcc2003-08-28 22:03:19 +0000304 got_clen = chunked = 0;
305
Eric Andersen79757c92001-04-05 21:45:54 +0000306 if (! --try)
307 close_delete_and_die("too many redirections");
Eric Andersen7d697012001-01-24 20:28:35 +0000308
Eric Andersen79757c92001-04-05 21:45:54 +0000309 /*
310 * Open socket to http server
311 */
312 if (sfp) fclose(sfp);
Glenn L McGrathffccf6e2003-12-20 01:47:18 +0000313 sfp = open_socket(&s_in);
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000314
Eric Andersen79757c92001-04-05 21:45:54 +0000315 /*
316 * Send HTTP request.
317 */
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000318 if (use_proxy) {
Glenn L McGrathcc20ebc2003-09-10 23:52:15 +0000319 const char *format = "GET %stp://%s:%d/%s HTTP/1.1\r\n";
320#ifdef CONFIG_FEATURE_WGET_IP6_LITERAL
321 if (strchr (target.host, ':'))
322 format = "GET %stp://[%s]:%d/%s HTTP/1.1\r\n";
323#endif
324 fprintf(sfp, format,
Eric Andersen79757c92001-04-05 21:45:54 +0000325 target.is_ftp ? "f" : "ht", target.host,
Glenn L McGrath24cb17f2004-01-31 08:08:57 +0000326 ntohs(target.port), target.path);
Eric Andersen79757c92001-04-05 21:45:54 +0000327 } else {
Eric Andersen6d7fa432001-04-10 18:17:05 +0000328 fprintf(sfp, "GET /%s HTTP/1.1\r\n", target.path);
Eric Andersen79757c92001-04-05 21:45:54 +0000329 }
Eric Andersen96700832000-09-04 15:15:55 +0000330
Eric Andersen79757c92001-04-05 21:45:54 +0000331 fprintf(sfp, "Host: %s\r\nUser-Agent: Wget\r\n", target.host);
332
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000333#ifdef CONFIG_FEATURE_WGET_AUTHENTICATION
Eric Andersen79757c92001-04-05 21:45:54 +0000334 if (target.user) {
335 fprintf(sfp, "Authorization: Basic %s\r\n",
Eric Andersen0cb6f352006-01-30 22:30:41 +0000336 base64enc((unsigned char*)target.user, buf, sizeof(buf)));
Eric Andersen79757c92001-04-05 21:45:54 +0000337 }
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000338 if (use_proxy && server.user) {
Eric Andersen79757c92001-04-05 21:45:54 +0000339 fprintf(sfp, "Proxy-Authorization: Basic %s\r\n",
Eric Andersen0cb6f352006-01-30 22:30:41 +0000340 base64enc((unsigned char*)server.user, buf, sizeof(buf)));
Eric Andersen79757c92001-04-05 21:45:54 +0000341 }
342#endif
343
Eric Andersenb520e082000-10-03 00:21:45 +0000344 if (do_continue)
Eric Andersen79757c92001-04-05 21:45:54 +0000345 fprintf(sfp, "Range: bytes=%ld-\r\n", beg_range);
Eric Andersen50ae3102001-05-15 17:51:37 +0000346 if(extra_headers_left < sizeof(extra_headers))
Eric Andersen9abfe852001-05-15 20:11:49 +0000347 fputs(extra_headers,sfp);
Eric Andersen79757c92001-04-05 21:45:54 +0000348 fprintf(sfp,"Connection: close\r\n\r\n");
349
350 /*
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000351 * Retrieve HTTP response line and check for "200" status code.
352 */
Glenn L McGrathe7bdfcc2003-08-28 22:03:19 +0000353read_response:
354 if (fgets(buf, sizeof(buf), sfp) == NULL)
Eric Andersen79757c92001-04-05 21:45:54 +0000355 close_delete_and_die("no response from server");
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000356
Eric Andersen79757c92001-04-05 21:45:54 +0000357 for (s = buf ; *s != '\0' && !isspace(*s) ; ++s)
358 ;
359 for ( ; isspace(*s) ; ++s)
360 ;
361 switch (status = atoi(s)) {
362 case 0:
Eric Andersen6d7fa432001-04-10 18:17:05 +0000363 case 100:
364 while (gethdr(buf, sizeof(buf), sfp, &n) != NULL);
365 goto read_response;
Eric Andersen79757c92001-04-05 21:45:54 +0000366 case 200:
367 if (do_continue && output != stdout)
368 output = freopen(fname_out, "w", output);
369 do_continue = 0;
370 break;
371 case 300: /* redirection */
372 case 301:
373 case 302:
374 case 303:
375 break;
376 case 206:
377 if (do_continue)
378 break;
379 /*FALLTHRU*/
380 default:
381 chomp(buf);
382 close_delete_and_die("server returned error %d: %s", atoi(s), buf);
383 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000384
Eric Andersen79757c92001-04-05 21:45:54 +0000385 /*
386 * Retrieve HTTP headers.
387 */
388 while ((s = gethdr(buf, sizeof(buf), sfp, &n)) != NULL) {
389 if (strcasecmp(buf, "content-length") == 0) {
Eric Andersen24794452004-03-06 22:11:45 +0000390 unsigned long value;
391 if (safe_strtoul(s, &value)) {
392 close_delete_and_die("content-length %s is garbage", s);
393 }
394 filesize = value;
Eric Andersen79757c92001-04-05 21:45:54 +0000395 got_clen = 1;
396 continue;
397 }
Eric Andersen6d7fa432001-04-10 18:17:05 +0000398 if (strcasecmp(buf, "transfer-encoding") == 0) {
399 if (strcasecmp(s, "chunked") == 0) {
400 chunked = got_clen = 1;
401 } else {
Eric Andersen79757c92001-04-05 21:45:54 +0000402 close_delete_and_die("server wants to do %s transfer encoding", s);
Eric Andersen6d7fa432001-04-10 18:17:05 +0000403 }
404 }
Eric Andersen79757c92001-04-05 21:45:54 +0000405 if (strcasecmp(buf, "location") == 0) {
406 if (s[0] == '/')
Manuel Novoa III cad53642003-03-19 09:13:01 +0000407 target.path = bb_xstrdup(s+1);
Eric Andersen79757c92001-04-05 21:45:54 +0000408 else {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000409 parse_url(bb_xstrdup(s), &target);
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000410 if (use_proxy == 0) {
Eric Andersen79757c92001-04-05 21:45:54 +0000411 server.host = target.host;
412 server.port = target.port;
413 }
Glenn L McGrath58a2e0e2004-01-17 23:07:14 +0000414 bb_lookup_host(&s_in, server.host);
415 s_in.sin_port = server.port;
416 break;
Eric Andersen79757c92001-04-05 21:45:54 +0000417 }
418 }
419 }
420 } while(status >= 300);
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000421
Eric Andersen79757c92001-04-05 21:45:54 +0000422 dfp = sfp;
423 }
424 else
425 {
426 /*
427 * FTP session
428 */
429 if (! target.user)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000430 target.user = bb_xstrdup("anonymous:busybox@");
Eric Andersen79757c92001-04-05 21:45:54 +0000431
Glenn L McGrathffccf6e2003-12-20 01:47:18 +0000432 sfp = open_socket(&s_in);
Eric Andersen79757c92001-04-05 21:45:54 +0000433 if (ftpcmd(NULL, NULL, sfp, buf) != 220)
434 close_delete_and_die("%s", buf+4);
435
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000436 /*
Eric Andersen79757c92001-04-05 21:45:54 +0000437 * Splitting username:password pair,
438 * trying to log in
439 */
440 s = strchr(target.user, ':');
441 if (s)
442 *(s++) = '\0';
443 switch(ftpcmd("USER ", target.user, sfp, buf)) {
444 case 230:
Eric Andersenb520e082000-10-03 00:21:45 +0000445 break;
Eric Andersen79757c92001-04-05 21:45:54 +0000446 case 331:
447 if (ftpcmd("PASS ", s, sfp, buf) == 230)
448 break;
449 /* FALLTHRU (failed login) */
450 default:
451 close_delete_and_die("ftp login: %s", buf+4);
452 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000453
Eric Andersen79757c92001-04-05 21:45:54 +0000454 ftpcmd("CDUP", NULL, sfp, buf);
455 ftpcmd("TYPE I", NULL, sfp, buf);
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000456
Eric Andersen79757c92001-04-05 21:45:54 +0000457 /*
458 * Querying file size
459 */
460 if (ftpcmd("SIZE /", target.path, sfp, buf) == 213) {
Eric Andersen24794452004-03-06 22:11:45 +0000461 unsigned long value;
462 if (safe_strtoul(buf+4, &value)) {
463 close_delete_and_die("SIZE value is garbage");
464 }
465 filesize = value;
Eric Andersen96700832000-09-04 15:15:55 +0000466 got_clen = 1;
Eric Andersen96700832000-09-04 15:15:55 +0000467 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000468
Eric Andersen79757c92001-04-05 21:45:54 +0000469 /*
470 * Entering passive mode
471 */
472 if (ftpcmd("PASV", NULL, sfp, buf) != 227)
473 close_delete_and_die("PASV: %s", buf+4);
474 s = strrchr(buf, ',');
475 *s = 0;
476 port = atoi(s+1);
477 s = strrchr(buf, ',');
478 port += atoi(s+1) * 256;
Glenn L McGrathffccf6e2003-12-20 01:47:18 +0000479 s_in.sin_port = htons(port);
480 dfp = open_socket(&s_in);
Eric Andersen79757c92001-04-05 21:45:54 +0000481
482 if (do_continue) {
483 sprintf(buf, "REST %ld", beg_range);
484 if (ftpcmd(buf, NULL, sfp, buf) != 350) {
485 if (output != stdout)
486 output = freopen(fname_out, "w", output);
487 do_continue = 0;
488 } else
489 filesize -= beg_range;
Eric Andersen96700832000-09-04 15:15:55 +0000490 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000491
Eric Andersen79757c92001-04-05 21:45:54 +0000492 if (ftpcmd("RETR /", target.path, sfp, buf) > 150)
493 close_delete_and_die("RETR: %s", buf+4);
494
Eric Andersen96700832000-09-04 15:15:55 +0000495 }
496
Eric Andersen79757c92001-04-05 21:45:54 +0000497
Eric Andersen96700832000-09-04 15:15:55 +0000498 /*
Eric Andersen79757c92001-04-05 21:45:54 +0000499 * Retrieve file
Eric Andersen96700832000-09-04 15:15:55 +0000500 */
Eric Andersen6d7fa432001-04-10 18:17:05 +0000501 if (chunked) {
502 fgets(buf, sizeof(buf), dfp);
503 filesize = strtol(buf, (char **) NULL, 16);
504 }
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000505#ifdef CONFIG_FEATURE_WGET_STATUSBAR
Glenn L McGrath1bca5ed2000-12-09 08:12:06 +0000506 if (quiet_flag==FALSE)
507 progressmeter(-1);
Eric Andersenb520e082000-10-03 00:21:45 +0000508#endif
Mark Whitley30ac01c2001-04-17 18:13:16 +0000509 do {
Glenn L McGrath23365972003-08-29 06:25:04 +0000510 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 +0000511 if (safe_fwrite(buf, 1, n, output) != n) {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000512 bb_perror_msg_and_die("write error");
Glenn L McGrath83e4a5b2003-08-28 21:55:22 +0000513 }
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000514#ifdef CONFIG_FEATURE_WGET_STATUSBAR
Glenn L McGrath83e4a5b2003-08-28 21:55:22 +0000515 statbytes+=n;
Eric Andersenb520e082000-10-03 00:21:45 +0000516#endif
Glenn L McGrath83e4a5b2003-08-28 21:55:22 +0000517 if (got_clen) {
518 filesize -= n;
519 }
520 }
Eric Andersen79757c92001-04-05 21:45:54 +0000521
Eric Andersen6d7fa432001-04-10 18:17:05 +0000522 if (chunked) {
Matt Kraai854125f2001-05-09 19:15:46 +0000523 safe_fgets(buf, sizeof(buf), dfp); /* This is a newline */
524 safe_fgets(buf, sizeof(buf), dfp);
Eric Andersen6d7fa432001-04-10 18:17:05 +0000525 filesize = strtol(buf, (char **) NULL, 16);
Glenn L McGrath83e4a5b2003-08-28 21:55:22 +0000526 if (filesize==0) {
527 chunked = 0; /* all done! */
528 }
Eric Andersen6d7fa432001-04-10 18:17:05 +0000529 }
530
Glenn L McGrath83e4a5b2003-08-28 21:55:22 +0000531 if (n == 0 && ferror(dfp)) {
532 bb_perror_msg_and_die("network read error");
533 }
Eric Andersen6d7fa432001-04-10 18:17:05 +0000534 } while (chunked);
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000535#ifdef CONFIG_FEATURE_WGET_STATUSBAR
Mark Whitley30ac01c2001-04-17 18:13:16 +0000536 if (quiet_flag==FALSE)
537 progressmeter(1);
538#endif
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000539 if ((use_proxy == 0) && target.is_ftp) {
Eric Andersen79757c92001-04-05 21:45:54 +0000540 fclose(dfp);
541 if (ftpcmd(NULL, NULL, sfp, buf) != 226)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000542 bb_error_msg_and_die("ftp error: %s", buf+4);
Eric Andersen79757c92001-04-05 21:45:54 +0000543 ftpcmd("QUIT", NULL, sfp, buf);
544 }
Eric Andersen79757c92001-04-05 21:45:54 +0000545 exit(EXIT_SUCCESS);
Eric Andersen96700832000-09-04 15:15:55 +0000546}
547
548
Eric Andersen79757c92001-04-05 21:45:54 +0000549void parse_url(char *url, struct host_info *h)
Eric Andersen96700832000-09-04 15:15:55 +0000550{
Glenn L McGrathcc20ebc2003-09-10 23:52:15 +0000551 char *cp, *sp, *up, *pp;
Eric Andersen96700832000-09-04 15:15:55 +0000552
Eric Andersen79757c92001-04-05 21:45:54 +0000553 if (strncmp(url, "http://", 7) == 0) {
Glenn L McGrath036dbaa2004-01-17 05:03:31 +0000554 h->port = bb_lookup_port("http", "tcp", 80);
Eric Andersen79757c92001-04-05 21:45:54 +0000555 h->host = url + 7;
556 h->is_ftp = 0;
557 } else if (strncmp(url, "ftp://", 6) == 0) {
Glenn L McGrath036dbaa2004-01-17 05:03:31 +0000558 h->port = bb_lookup_port("ftp", "tfp", 21);
Eric Andersen79757c92001-04-05 21:45:54 +0000559 h->host = url + 6;
560 h->is_ftp = 1;
561 } else
Manuel Novoa III cad53642003-03-19 09:13:01 +0000562 bb_error_msg_and_die("not an http or ftp url: %s", url);
Eric Andersen96700832000-09-04 15:15:55 +0000563
Eric Andersen79757c92001-04-05 21:45:54 +0000564 sp = strchr(h->host, '/');
Glenn L McGrathf1c4b112004-02-22 00:27:34 +0000565 if (sp) {
Matt Kraaia9711a52001-01-03 16:15:15 +0000566 *sp++ = '\0';
Eric Andersen79757c92001-04-05 21:45:54 +0000567 h->path = sp;
Matt Kraaia9711a52001-01-03 16:15:15 +0000568 } else
Manuel Novoa III cad53642003-03-19 09:13:01 +0000569 h->path = bb_xstrdup("");
Eric Andersen79757c92001-04-05 21:45:54 +0000570
571 up = strrchr(h->host, '@');
572 if (up != NULL) {
573 h->user = h->host;
574 *up++ = '\0';
575 h->host = up;
576 } else
577 h->user = NULL;
578
Glenn L McGrathcc20ebc2003-09-10 23:52:15 +0000579 pp = h->host;
580
581#ifdef CONFIG_FEATURE_WGET_IP6_LITERAL
582 if (h->host[0] == '[') {
583 char *ep;
584
585 ep = h->host + 1;
Eric Andersen6231f092003-09-11 08:25:11 +0000586 while (*ep == ':' || isxdigit (*ep))
Glenn L McGrathcc20ebc2003-09-10 23:52:15 +0000587 ep++;
588 if (*ep == ']') {
589 h->host++;
590 *ep = '\0';
591 pp = ep + 1;
592 }
593 }
594#endif
595
596 cp = strchr(pp, ':');
Eric Andersen79757c92001-04-05 21:45:54 +0000597 if (cp != NULL) {
598 *cp++ = '\0';
Glenn L McGrathf980bd52003-12-27 00:21:47 +0000599 h->port = htons(atoi(cp));
Eric Andersen79757c92001-04-05 21:45:54 +0000600 }
Eric Andersen96700832000-09-04 15:15:55 +0000601}
602
603
Glenn L McGrathffccf6e2003-12-20 01:47:18 +0000604FILE *open_socket(struct sockaddr_in *s_in)
Eric Andersen96700832000-09-04 15:15:55 +0000605{
Eric Andersen96700832000-09-04 15:15:55 +0000606 FILE *fp;
607
Glenn L McGrathffccf6e2003-12-20 01:47:18 +0000608 fp = fdopen(xconnect(s_in), "r+");
609 if (fp == NULL)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000610 bb_perror_msg_and_die("fdopen()");
Eric Andersen96700832000-09-04 15:15:55 +0000611
612 return fp;
613}
614
615
616char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc)
617{
618 char *s, *hdrval;
619 int c;
620
621 *istrunc = 0;
622
623 /* retrieve header line */
624 if (fgets(buf, bufsiz, fp) == NULL)
625 return NULL;
626
627 /* see if we are at the end of the headers */
628 for (s = buf ; *s == '\r' ; ++s)
629 ;
630 if (s[0] == '\n')
631 return NULL;
632
633 /* convert the header name to lower case */
634 for (s = buf ; isalnum(*s) || *s == '-' ; ++s)
635 *s = tolower(*s);
636
637 /* verify we are at the end of the header name */
638 if (*s != ':')
Manuel Novoa III cad53642003-03-19 09:13:01 +0000639 bb_error_msg_and_die("bad header line: %s", buf);
Eric Andersen96700832000-09-04 15:15:55 +0000640
641 /* locate the start of the header value */
642 for (*s++ = '\0' ; *s == ' ' || *s == '\t' ; ++s)
643 ;
644 hdrval = s;
645
646 /* locate the end of header */
647 while (*s != '\0' && *s != '\r' && *s != '\n')
648 ++s;
649
650 /* end of header found */
651 if (*s != '\0') {
652 *s = '\0';
653 return hdrval;
654 }
655
Eric Andersen5d638842000-09-14 21:46:30 +0000656 /* Rats! The buffer isn't big enough to hold the entire header value. */
Eric Andersen96700832000-09-04 15:15:55 +0000657 while (c = getc(fp), c != EOF && c != '\n')
658 ;
659 *istrunc = 1;
660 return hdrval;
661}
662
Eric Andersen79757c92001-04-05 21:45:54 +0000663static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf)
664{
Eric Andersen79757c92001-04-05 21:45:54 +0000665 if (s1) {
666 if (!s2) s2="";
Eric Andersen3f1cf452003-03-11 18:03:39 +0000667 fprintf(fp, "%s%s\r\n", s1, s2);
Eric Andersen79757c92001-04-05 21:45:54 +0000668 fflush(fp);
669 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000670
Eric Andersen79757c92001-04-05 21:45:54 +0000671 do {
Glenn L McGrath32da8852004-04-08 10:27:11 +0000672 char *buf_ptr;
673
674 if (fgets(buf, 510, fp) == NULL) {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000675 bb_perror_msg_and_die("fgets()");
Glenn L McGrath32da8852004-04-08 10:27:11 +0000676 }
677 buf_ptr = strstr(buf, "\r\n");
678 if (buf_ptr) {
679 *buf_ptr = '\0';
680 }
Eric Andersen79757c92001-04-05 21:45:54 +0000681 } while (! isdigit(buf[0]) || buf[3] != ' ');
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000682
Eric Andersen79757c92001-04-05 21:45:54 +0000683 return atoi(buf);
684}
685
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000686#ifdef CONFIG_FEATURE_WGET_STATUSBAR
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000687/* Stuff below is from BSD rcp util.c, as added to openshh.
Eric Andersen4e573f42000-11-14 23:29:24 +0000688 * Original copyright notice is retained at the end of this file.
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000689 *
690 */
Eric Andersenb520e082000-10-03 00:21:45 +0000691
692
Eric Andersen3e6ff902001-03-09 21:24:12 +0000693static int
Eric Andersenb520e082000-10-03 00:21:45 +0000694getttywidth(void)
695{
Eric Andersen8efe9672003-09-15 08:33:45 +0000696 int width=0;
697 get_terminal_width_height(0, &width, NULL);
698 return (width);
Eric Andersenb520e082000-10-03 00:21:45 +0000699}
700
Eric Andersen3e6ff902001-03-09 21:24:12 +0000701static void
Eric Andersenb520e082000-10-03 00:21:45 +0000702updateprogressmeter(int ignore)
703{
704 int save_errno = errno;
705
706 progressmeter(0);
707 errno = save_errno;
708}
709
Eric Andersen3e6ff902001-03-09 21:24:12 +0000710static void
Eric Andersenb520e082000-10-03 00:21:45 +0000711alarmtimer(int wait)
712{
713 struct itimerval itv;
714
715 itv.it_value.tv_sec = wait;
716 itv.it_value.tv_usec = 0;
717 itv.it_interval = itv.it_value;
718 setitimer(ITIMER_REAL, &itv, NULL);
719}
720
721
Eric Andersen3e6ff902001-03-09 21:24:12 +0000722static void
Eric Andersenb520e082000-10-03 00:21:45 +0000723progressmeter(int flag)
724{
725 static const char prefixes[] = " KMGTP";
726 static struct timeval lastupdate;
Mark Whitley30ac01c2001-04-17 18:13:16 +0000727 static off_t lastsize, totalsize;
Eric Andersenb520e082000-10-03 00:21:45 +0000728 struct timeval now, td, wait;
729 off_t cursize, abbrevsize;
730 double elapsed;
731 int ratio, barlength, i, remaining;
732 char buf[256];
733
734 if (flag == -1) {
735 (void) gettimeofday(&start, (struct timezone *) 0);
736 lastupdate = start;
737 lastsize = 0;
Mark Whitley30ac01c2001-04-17 18:13:16 +0000738 totalsize = filesize; /* as filesize changes.. */
Eric Andersenb520e082000-10-03 00:21:45 +0000739 }
740
741 (void) gettimeofday(&now, (struct timezone *) 0);
742 cursize = statbytes;
Mark Whitley30ac01c2001-04-17 18:13:16 +0000743 if (totalsize != 0 && !chunked) {
744 ratio = 100.0 * cursize / totalsize;
Eric Andersenb520e082000-10-03 00:21:45 +0000745 ratio = MAX(ratio, 0);
746 ratio = MIN(ratio, 100);
747 } else
748 ratio = 100;
749
750 snprintf(buf, sizeof(buf), "\r%-20.20s %3d%% ", curfile, ratio);
751
752 barlength = getttywidth() - 51;
753 if (barlength > 0) {
754 i = barlength * ratio / 100;
755 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
756 "|%.*s%*s|", i,
757 "*****************************************************************************"
758 "*****************************************************************************",
759 barlength - i, "");
760 }
761 i = 0;
762 abbrevsize = cursize;
763 while (abbrevsize >= 100000 && i < sizeof(prefixes)) {
764 i++;
765 abbrevsize >>= 10;
766 }
767 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %5d %c%c ",
768 (int) abbrevsize, prefixes[i], prefixes[i] == ' ' ? ' ' :
769 'B');
770
771 timersub(&now, &lastupdate, &wait);
772 if (cursize > lastsize) {
773 lastupdate = now;
774 lastsize = cursize;
775 if (wait.tv_sec >= STALLTIME) {
776 start.tv_sec += wait.tv_sec;
777 start.tv_usec += wait.tv_usec;
778 }
779 wait.tv_sec = 0;
780 }
781 timersub(&now, &start, &td);
782 elapsed = td.tv_sec + (td.tv_usec / 1000000.0);
783
Mark Whitley30ac01c2001-04-17 18:13:16 +0000784 if (wait.tv_sec >= STALLTIME) {
Eric Andersenb520e082000-10-03 00:21:45 +0000785 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
786 " - stalled -");
Mark Whitley30ac01c2001-04-17 18:13:16 +0000787 } else if (statbytes <= 0 || elapsed <= 0.0 || cursize > totalsize || chunked) {
788 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
789 " --:-- ETA");
Eric Andersenb520e082000-10-03 00:21:45 +0000790 } else {
Mark Whitley30ac01c2001-04-17 18:13:16 +0000791 remaining = (int) (totalsize / (statbytes / elapsed) - elapsed);
Eric Andersenb520e082000-10-03 00:21:45 +0000792 i = remaining / 3600;
793 if (i)
794 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
795 "%2d:", i);
796 else
797 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
798 " ");
799 i = remaining % 3600;
800 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
801 "%02d:%02d ETA", i / 60, i % 60);
802 }
Eric Andersen70060d22004-03-27 10:02:48 +0000803 write(STDERR_FILENO, buf, strlen(buf));
Eric Andersenb520e082000-10-03 00:21:45 +0000804
805 if (flag == -1) {
806 struct sigaction sa;
807 sa.sa_handler = updateprogressmeter;
808 sigemptyset(&sa.sa_mask);
809 sa.sa_flags = SA_RESTART;
810 sigaction(SIGALRM, &sa, NULL);
811 alarmtimer(1);
812 } else if (flag == 1) {
813 alarmtimer(0);
814 statbytes = 0;
Mark Whitley30ac01c2001-04-17 18:13:16 +0000815 putc('\n', stderr);
Eric Andersenb520e082000-10-03 00:21:45 +0000816 }
817}
818#endif
Eric Andersen4e573f42000-11-14 23:29:24 +0000819
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000820/* Original copyright notice which applies to the CONFIG_FEATURE_WGET_STATUSBAR stuff,
Eric Andersenaff114c2004-04-14 17:51:38 +0000821 * much of which was blatantly stolen from openssh. */
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000822
Eric Andersen4e573f42000-11-14 23:29:24 +0000823/*-
824 * Copyright (c) 1992, 1993
825 * The Regents of the University of California. All rights reserved.
826 *
827 * Redistribution and use in source and binary forms, with or without
828 * modification, are permitted provided that the following conditions
829 * are met:
830 * 1. Redistributions of source code must retain the above copyright
831 * notice, this list of conditions and the following disclaimer.
832 * 2. Redistributions in binary form must reproduce the above copyright
833 * notice, this list of conditions and the following disclaimer in the
834 * documentation and/or other materials provided with the distribution.
835 *
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000836 * 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change
837 * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change>
Eric Andersen4e573f42000-11-14 23:29:24 +0000838 *
839 * 4. Neither the name of the University nor the names of its contributors
840 * may be used to endorse or promote products derived from this software
841 * without specific prior written permission.
842 *
843 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
844 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
845 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
846 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
847 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
848 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
849 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
850 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
851 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
852 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
853 * SUCH DAMAGE.
854 *
Eric Andersen751750e2004-10-08 08:27:40 +0000855 * $Id: wget.c,v 1.75 2004/10/08 08:27:40 andersen Exp $
Eric Andersen4e573f42000-11-14 23:29:24 +0000856 */
857
858
859
Eric Andersen96700832000-09-04 15:15:55 +0000860/*
861Local Variables:
862c-file-style: "linux"
863c-basic-offset: 4
864tab-width: 4
865End:
866*/