aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-05-15 17:51:37 +0000
committerEric Andersen <andersen@codepoet.org>2001-05-15 17:51:37 +0000
commit50ae3102fb2b7fa718d2977d9fe81bae8bdbca4d (patch)
tree3598ece64206a19c4ac61a11b96db27e66552041
parent55f9872616f0c42f3fb712cfb7f9d0bb52c8afcb (diff)
downloadbusybox-50ae3102fb2b7fa718d2977d9fe81bae8bdbca4d.tar.gz
Patch from Adam Heath <doogie@debian.org> to add arbitrary header support
to wget, so it can now do funky interactive things with cgi scripts.
-rw-r--r--applets/usage.h2
-rw-r--r--include/usage.h2
-rw-r--r--networking/wget.c41
-rw-r--r--usage.h2
-rw-r--r--wget.c41
5 files changed, 79 insertions, 9 deletions
diff --git a/applets/usage.h b/applets/usage.h
index 78ee628ab..604661f78 100644
--- a/applets/usage.h
+++ b/applets/usage.h
@@ -1725,7 +1725,7 @@
" 31 46 1365 /etc/passwd\n"
#define wget_trivial_usage \
- "[-c] [-q] [-O file] url"
+ "[-c|--continue] [-q|--quiet] [-O|--output-document file] [--header 'header: value'] url"
#define wget_full_usage \
"wget retrieves files via HTTP or FTP\n\n" \
"Options:\n" \
diff --git a/include/usage.h b/include/usage.h
index 78ee628ab..604661f78 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -1725,7 +1725,7 @@
" 31 46 1365 /etc/passwd\n"
#define wget_trivial_usage \
- "[-c] [-q] [-O file] url"
+ "[-c|--continue] [-q|--quiet] [-O|--output-document file] [--header 'header: value'] url"
#define wget_full_usage \
"wget retrieves files via HTTP or FTP\n\n" \
"Options:\n" \
diff --git a/networking/wget.c b/networking/wget.c
index dfe97f5c5..e561ae287 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -24,6 +24,11 @@
#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... */
@@ -157,7 +162,10 @@ int wget_main(int argc, char **argv)
char *proxy;
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 */
@@ -169,10 +177,18 @@ int wget_main(int argc, char **argv)
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.
*/
- while ((n = getopt(argc, argv, "cqO:")) != EOF) {
+ while ((n = getopt_long(argc, argv, "cqO:", long_options, &option_index)) != EOF) {
switch (n) {
case 'c':
++do_continue;
@@ -187,11 +203,28 @@ int wget_main(int argc, char **argv)
*/
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();
}
}
+ fprintf(stderr, "extra_headers='%s'\n", extra_headers);
if (argc - optind != 1)
show_usage();
@@ -291,6 +324,8 @@ int wget_main(int argc, char **argv)
if (do_continue)
fprintf(sfp, "Range: bytes=%ld-\r\n", beg_range);
+ if(extra_headers_left < sizeof(extra_headers))
+ fprintf(sfp,extra_headers);
fprintf(sfp,"Connection: close\r\n\r\n");
/*
@@ -778,7 +813,7 @@ progressmeter(int flag)
* 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.39 2001/05/15 17:51:37 andersen Exp $
*/
diff --git a/usage.h b/usage.h
index 78ee628ab..604661f78 100644
--- a/usage.h
+++ b/usage.h
@@ -1725,7 +1725,7 @@
" 31 46 1365 /etc/passwd\n"
#define wget_trivial_usage \
- "[-c] [-q] [-O file] url"
+ "[-c|--continue] [-q|--quiet] [-O|--output-document file] [--header 'header: value'] url"
#define wget_full_usage \
"wget retrieves files via HTTP or FTP\n\n" \
"Options:\n" \
diff --git a/wget.c b/wget.c
index dfe97f5c5..e561ae287 100644
--- a/wget.c
+++ b/wget.c
@@ -24,6 +24,11 @@
#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... */
@@ -157,7 +162,10 @@ int wget_main(int argc, char **argv)
char *proxy;
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 */
@@ -169,10 +177,18 @@ int wget_main(int argc, char **argv)
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.
*/
- while ((n = getopt(argc, argv, "cqO:")) != EOF) {
+ while ((n = getopt_long(argc, argv, "cqO:", long_options, &option_index)) != EOF) {
switch (n) {
case 'c':
++do_continue;
@@ -187,11 +203,28 @@ int wget_main(int argc, char **argv)
*/
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();
}
}
+ fprintf(stderr, "extra_headers='%s'\n", extra_headers);
if (argc - optind != 1)
show_usage();
@@ -291,6 +324,8 @@ int wget_main(int argc, char **argv)
if (do_continue)
fprintf(sfp, "Range: bytes=%ld-\r\n", beg_range);
+ if(extra_headers_left < sizeof(extra_headers))
+ fprintf(sfp,extra_headers);
fprintf(sfp,"Connection: close\r\n\r\n");
/*
@@ -778,7 +813,7 @@ progressmeter(int flag)
* 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.39 2001/05/15 17:51:37 andersen Exp $
*/