projects
/
oweals
/
busybox.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
start-stop-deamon is done
[oweals/busybox.git]
/
networking
/
wget.c
diff --git
a/networking/wget.c
b/networking/wget.c
index dfe97f5c58402be12ae389f86c15b01af8acb52d..41b4e30af69952e86681b60d8506e7e30f96b0ec 100644
(file)
--- a/
networking/wget.c
+++ b/
networking/wget.c
@@
-24,6
+24,11
@@
#include <arpa/inet.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <netdb.h>
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#include <getopt.h>
+
#include "busybox.h"
/* Stupid libc5 doesn't define this... */
#include "busybox.h"
/* Stupid libc5 doesn't define this... */
@@
-51,12
+56,12
@@
static void parse_url(char *url, struct host_info *h);
static FILE *open_socket(char *host, int port);
static char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc);
static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf);
static FILE *open_socket(char *host, int port);
static char *gethdr(char *buf, size_t bufsiz, FILE *fp, int *istrunc);
static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf);
-static void progressmeter(int flag);
/* Globals (can be accessed from signal handlers */
static off_t filesize = 0; /* content-length of the file */
static int chunked = 0; /* chunked transfer encoding */
/* Globals (can be accessed from signal handlers */
static off_t filesize = 0; /* content-length of the file */
static int chunked = 0; /* chunked transfer encoding */
-#ifdef BB_FEATURE_WGET_STATUSBAR
+#ifdef CONFIG_FEATURE_WGET_STATUSBAR
+static void progressmeter(int flag);
static char *curfile; /* Name of current file being transferred. */
static struct timeval start; /* Time a transfer started. */
static volatile unsigned long statbytes = 0; /* Number of bytes transferred so far. */
static char *curfile; /* Name of current file being transferred. */
static struct timeval start; /* Time a transfer started. */
static volatile unsigned long statbytes = 0; /* Number of bytes transferred so far. */
@@
-121,7
+126,7
@@
static char *safe_fgets(char *s, int size, FILE *stream)
error_msg_and_die(s); }
error_msg_and_die(s); }
-#ifdef
BB
_FEATURE_WGET_AUTHENTICATION
+#ifdef
CONFIG
_FEATURE_WGET_AUTHENTICATION
/*
* Base64-encode character string
* oops... isn't something similar in uuencode.c?
/*
* Base64-encode character string
* oops... isn't something similar in uuencode.c?
@@
-155,9
+160,13
@@
int wget_main(int argc, char **argv)
int n, try=5, status;
int port;
char *proxy;
int n, try=5, status;
int port;
char *proxy;
+ char *dir_prefix=NULL;
char *s, buf[512];
struct stat sbuf;
char *s, buf[512];
struct stat sbuf;
-
+ char extra_headers[1024];
+ char *extra_headers_ptr = extra_headers;
+ int extra_headers_left = sizeof(extra_headers);
+ int which_long_opt = 0, option_index = -1;
struct host_info server, target;
FILE *sfp = NULL; /* socket to web/ftp server */
struct host_info server, target;
FILE *sfp = NULL; /* socket to web/ftp server */
@@
-169,14
+178,25
@@
int wget_main(int argc, char **argv)
FILE *output; /* socket to web server */
int quiet_flag = FALSE; /* Be verry, verry quiet... */
FILE *output; /* socket to web server */
int quiet_flag = FALSE; /* Be verry, verry quiet... */
+#define LONG_HEADER 1
+ struct option long_options[] = {
+ { "continue", 0, NULL, 'c' },
+ { "quiet", 0, NULL, 'q' },
+ { "output-document", 1, NULL, 'O' },
+ { "header", 1, &which_long_opt, LONG_HEADER },
+ { 0, 0, 0, 0 }
+ };
/*
* Crack command line.
*/
/*
* Crack command line.
*/
- while ((n = getopt
(argc, argv, "cqO:"
)) != EOF) {
+ while ((n = getopt
_long(argc, argv, "cqO:P:", long_options, &option_index
)) != EOF) {
switch (n) {
case 'c':
++do_continue;
break;
switch (n) {
case 'c':
++do_continue;
break;
+ case 'P':
+ dir_prefix = optarg;
+ break;
case 'q':
quiet_flag = TRUE;
break;
case 'q':
quiet_flag = TRUE;
break;
@@
-187,6
+207,22
@@
int wget_main(int argc, char **argv)
*/
fname_out = optarg;
break;
*/
fname_out = optarg;
break;
+ case 0:
+ switch (which_long_opt) {
+ case LONG_HEADER: {
+ int arglen = strlen(optarg);
+ if(extra_headers_left - arglen - 2 <= 0)
+ error_msg_and_die("extra_headers buffer too small(need %i)", extra_headers_left - arglen);
+ strcpy(extra_headers_ptr, optarg);
+ extra_headers_ptr += arglen;
+ extra_headers_left -= ( arglen + 2 );
+ *extra_headers_ptr++ = '\r';
+ *extra_headers_ptr++ = '\n';
+ *(extra_headers_ptr + 1) = 0;
+ break;
+ }
+ }
+ break;
default:
show_usage();
}
default:
show_usage();
}
@@
-209,18
+245,20
@@
int wget_main(int argc, char **argv)
/* Guess an output filename */
if (!fname_out) {
fname_out =
/* Guess an output filename */
if (!fname_out) {
fname_out =
-#ifdef
BB
_FEATURE_WGET_STATUSBAR
+#ifdef
CONFIG
_FEATURE_WGET_STATUSBAR
curfile =
#endif
get_last_path_component(target.path);
if (fname_out==NULL || strlen(fname_out)<1) {
fname_out =
curfile =
#endif
get_last_path_component(target.path);
if (fname_out==NULL || strlen(fname_out)<1) {
fname_out =
-#ifdef
BB
_FEATURE_WGET_STATUSBAR
+#ifdef
CONFIG
_FEATURE_WGET_STATUSBAR
curfile =
#endif
"index.html";
}
curfile =
#endif
"index.html";
}
-#ifdef BB_FEATURE_WGET_STATUSBAR
+ if (dir_prefix != NULL)
+ fname_out = concat_path_file(dir_prefix, fname_out);
+#ifdef CONFIG_FEATURE_WGET_STATUSBAR
} else {
curfile = get_last_path_component(fname_out);
#endif
} else {
curfile = get_last_path_component(fname_out);
#endif
@@
-278,7
+316,7
@@
int wget_main(int argc, char **argv)
fprintf(sfp, "Host: %s\r\nUser-Agent: Wget\r\n", target.host);
fprintf(sfp, "Host: %s\r\nUser-Agent: Wget\r\n", target.host);
-#ifdef
BB
_FEATURE_WGET_AUTHENTICATION
+#ifdef
CONFIG
_FEATURE_WGET_AUTHENTICATION
if (target.user) {
fprintf(sfp, "Authorization: Basic %s\r\n",
base64enc(target.user, buf, sizeof(buf)));
if (target.user) {
fprintf(sfp, "Authorization: Basic %s\r\n",
base64enc(target.user, buf, sizeof(buf)));
@@
-291,6
+329,8
@@
int wget_main(int argc, char **argv)
if (do_continue)
fprintf(sfp, "Range: bytes=%ld-\r\n", beg_range);
if (do_continue)
fprintf(sfp, "Range: bytes=%ld-\r\n", beg_range);
+ if(extra_headers_left < sizeof(extra_headers))
+ fputs(extra_headers,sfp);
fprintf(sfp,"Connection: close\r\n\r\n");
/*
fprintf(sfp,"Connection: close\r\n\r\n");
/*
@@
-435,14
+475,14
@@
read_response: if (fgets(buf, sizeof(buf), sfp) == NULL)
fgets(buf, sizeof(buf), dfp);
filesize = strtol(buf, (char **) NULL, 16);
}
fgets(buf, sizeof(buf), dfp);
filesize = strtol(buf, (char **) NULL, 16);
}
-#ifdef
BB
_FEATURE_WGET_STATUSBAR
+#ifdef
CONFIG
_FEATURE_WGET_STATUSBAR
if (quiet_flag==FALSE)
progressmeter(-1);
#endif
do {
while ((filesize > 0 || !got_clen) && (n = safe_fread(buf, 1, chunked ? (filesize > sizeof(buf) ? sizeof(buf) : filesize) : sizeof(buf), dfp)) > 0) {
safe_fwrite(buf, 1, n, output);
if (quiet_flag==FALSE)
progressmeter(-1);
#endif
do {
while ((filesize > 0 || !got_clen) && (n = safe_fread(buf, 1, chunked ? (filesize > sizeof(buf) ? sizeof(buf) : filesize) : sizeof(buf), dfp)) > 0) {
safe_fwrite(buf, 1, n, output);
-#ifdef
BB
_FEATURE_WGET_STATUSBAR
+#ifdef
CONFIG
_FEATURE_WGET_STATUSBAR
statbytes+=n;
#endif
if (got_clen)
statbytes+=n;
#endif
if (got_clen)
@@
-459,7
+499,7
@@
read_response: if (fgets(buf, sizeof(buf), sfp) == NULL)
if (n == 0 && ferror(dfp))
perror_msg_and_die("network read error");
} while (chunked);
if (n == 0 && ferror(dfp))
perror_msg_and_die("network read error");
} while (chunked);
-#ifdef
BB
_FEATURE_WGET_STATUSBAR
+#ifdef
CONFIG
_FEATURE_WGET_STATUSBAR
if (quiet_flag==FALSE)
progressmeter(1);
#endif
if (quiet_flag==FALSE)
progressmeter(1);
#endif
@@
-521,8
+561,7
@@
FILE *open_socket(char *host, int port)
memset(&s_in, 0, sizeof(s_in));
s_in.sin_family = AF_INET;
memset(&s_in, 0, sizeof(s_in));
s_in.sin_family = AF_INET;
- if ((hp = (struct hostent *) gethostbyname(host)) == NULL)
- error_msg_and_die("cannot resolve %s", host);
+ hp = xgethostbyname(host);
memcpy(&s_in.sin_addr, hp->h_addr_list[0], hp->h_length);
s_in.sin_port = htons(port);
memcpy(&s_in.sin_addr, hp->h_addr_list[0], hp->h_length);
s_in.sin_port = htons(port);
@@
-606,7
+645,7
@@
static int ftpcmd(char *s1, char *s2, FILE *fp, char *buf)
return atoi(buf);
}
return atoi(buf);
}
-#ifdef
BB
_FEATURE_WGET_STATUSBAR
+#ifdef
CONFIG
_FEATURE_WGET_STATUSBAR
/* Stuff below is from BSD rcp util.c, as added to openshh.
* Original copyright notice is retained at the end of this file.
*
/* Stuff below is from BSD rcp util.c, as added to openshh.
* Original copyright notice is retained at the end of this file.
*
@@
-743,7
+782,7
@@
progressmeter(int flag)
}
#endif
}
#endif
-/* Original copyright notice which applies to the
BB
_FEATURE_WGET_STATUSBAR stuff,
+/* Original copyright notice which applies to the
CONFIG
_FEATURE_WGET_STATUSBAR stuff,
* much of which was blatently stolen from openssh. */
/*-
* much of which was blatently stolen from openssh. */
/*-
@@
-778,7
+817,7
@@
progressmeter(int flag)
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: wget.c,v 1.
38 2001/05/13 00:55:54
andersen Exp $
+ * $Id: wget.c,v 1.
46 2001/10/24 04:59:56
andersen Exp $
*/
*/