projects
/
oweals
/
busybox.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
This is vodz' latest patch. Sorry it took so long...
[oweals/busybox.git]
/
wget.c
diff --git
a/wget.c
b/wget.c
index cb96e65a388f50648ac38c895ab2a0b78b6701fd..61945b7d1ec641af658a3805da416c3757bbd52c 100644
(file)
--- a/
wget.c
+++ b/
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... */
@@
-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();
}
@@
-234,7
+270,9
@@
int wget_main(int argc, char **argv)
*/
if (strcmp(fname_out, "-") == 0) {
output = stdout;
*/
if (strcmp(fname_out, "-") == 0) {
output = stdout;
+ quiet_flag = TRUE;
} else {
} else {
+ fname_out = concat_path_file(dir_prefix, fname_out);
output = xfopen(fname_out, (do_continue ? "a" : "w"));
}
output = xfopen(fname_out, (do_continue ? "a" : "w"));
}
@@
-290,6
+328,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");
/*
@@
-520,8
+560,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);
@@
-777,7
+816,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.
37 2001/05/09 19:15:46 kraai
Exp $
+ * $Id: wget.c,v 1.
42 2001/06/21 19:45:06 andersen
Exp $
*/
*/