diff options
| author | Eric Andersen <andersen@codepoet.org> | 2001-05-15 17:51:37 +0000 |
|---|---|---|
| committer | Eric Andersen <andersen@codepoet.org> | 2001-05-15 17:51:37 +0000 |
| commit | 50ae3102fb2b7fa718d2977d9fe81bae8bdbca4d (patch) | |
| tree | 3598ece64206a19c4ac61a11b96db27e66552041 | |
| parent | 55f9872616f0c42f3fb712cfb7f9d0bb52c8afcb (diff) | |
| download | busybox-w32-50ae3102fb2b7fa718d2977d9fe81bae8bdbca4d.tar.gz busybox-w32-50ae3102fb2b7fa718d2977d9fe81bae8bdbca4d.tar.bz2 busybox-w32-50ae3102fb2b7fa718d2977d9fe81bae8bdbca4d.zip | |
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.h | 2 | ||||
| -rw-r--r-- | include/usage.h | 2 | ||||
| -rw-r--r-- | networking/wget.c | 41 | ||||
| -rw-r--r-- | usage.h | 2 | ||||
| -rw-r--r-- | wget.c | 41 |
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 @@ | |||
| 1725 | " 31 46 1365 /etc/passwd\n" | 1725 | " 31 46 1365 /etc/passwd\n" |
| 1726 | 1726 | ||
| 1727 | #define wget_trivial_usage \ | 1727 | #define wget_trivial_usage \ |
| 1728 | "[-c] [-q] [-O file] url" | 1728 | "[-c|--continue] [-q|--quiet] [-O|--output-document file] [--header 'header: value'] url" |
| 1729 | #define wget_full_usage \ | 1729 | #define wget_full_usage \ |
| 1730 | "wget retrieves files via HTTP or FTP\n\n" \ | 1730 | "wget retrieves files via HTTP or FTP\n\n" \ |
| 1731 | "Options:\n" \ | 1731 | "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 @@ | |||
| 1725 | " 31 46 1365 /etc/passwd\n" | 1725 | " 31 46 1365 /etc/passwd\n" |
| 1726 | 1726 | ||
| 1727 | #define wget_trivial_usage \ | 1727 | #define wget_trivial_usage \ |
| 1728 | "[-c] [-q] [-O file] url" | 1728 | "[-c|--continue] [-q|--quiet] [-O|--output-document file] [--header 'header: value'] url" |
| 1729 | #define wget_full_usage \ | 1729 | #define wget_full_usage \ |
| 1730 | "wget retrieves files via HTTP or FTP\n\n" \ | 1730 | "wget retrieves files via HTTP or FTP\n\n" \ |
| 1731 | "Options:\n" \ | 1731 | "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 @@ | |||
| 24 | #include <arpa/inet.h> | 24 | #include <arpa/inet.h> |
| 25 | #include <netdb.h> | 25 | #include <netdb.h> |
| 26 | 26 | ||
| 27 | #ifndef _GNU_SOURCE | ||
| 28 | #define _GNU_SOURCE | ||
| 29 | #endif | ||
| 30 | #include <getopt.h> | ||
| 31 | |||
| 27 | #include "busybox.h" | 32 | #include "busybox.h" |
| 28 | 33 | ||
| 29 | /* Stupid libc5 doesn't define this... */ | 34 | /* Stupid libc5 doesn't define this... */ |
| @@ -157,7 +162,10 @@ int wget_main(int argc, char **argv) | |||
| 157 | char *proxy; | 162 | char *proxy; |
| 158 | char *s, buf[512]; | 163 | char *s, buf[512]; |
| 159 | struct stat sbuf; | 164 | struct stat sbuf; |
| 160 | 165 | char extra_headers[1024]; | |
| 166 | char *extra_headers_ptr = extra_headers; | ||
| 167 | int extra_headers_left = sizeof(extra_headers); | ||
| 168 | int which_long_opt = 0, option_index = -1; | ||
| 161 | struct host_info server, target; | 169 | struct host_info server, target; |
| 162 | 170 | ||
| 163 | FILE *sfp = NULL; /* socket to web/ftp server */ | 171 | FILE *sfp = NULL; /* socket to web/ftp server */ |
| @@ -169,10 +177,18 @@ int wget_main(int argc, char **argv) | |||
| 169 | FILE *output; /* socket to web server */ | 177 | FILE *output; /* socket to web server */ |
| 170 | int quiet_flag = FALSE; /* Be verry, verry quiet... */ | 178 | int quiet_flag = FALSE; /* Be verry, verry quiet... */ |
| 171 | 179 | ||
| 180 | #define LONG_HEADER 1 | ||
| 181 | struct option long_options[] = { | ||
| 182 | { "continue", 0, NULL, 'c' }, | ||
| 183 | { "quiet", 0, NULL, 'q' }, | ||
| 184 | { "output-document", 1, NULL, 'O' }, | ||
| 185 | { "header", 1, &which_long_opt, LONG_HEADER }, | ||
| 186 | { 0, 0, 0, 0 } | ||
| 187 | }; | ||
| 172 | /* | 188 | /* |
| 173 | * Crack command line. | 189 | * Crack command line. |
| 174 | */ | 190 | */ |
| 175 | while ((n = getopt(argc, argv, "cqO:")) != EOF) { | 191 | while ((n = getopt_long(argc, argv, "cqO:", long_options, &option_index)) != EOF) { |
| 176 | switch (n) { | 192 | switch (n) { |
| 177 | case 'c': | 193 | case 'c': |
| 178 | ++do_continue; | 194 | ++do_continue; |
| @@ -187,11 +203,28 @@ int wget_main(int argc, char **argv) | |||
| 187 | */ | 203 | */ |
| 188 | fname_out = optarg; | 204 | fname_out = optarg; |
| 189 | break; | 205 | break; |
| 206 | case 0: | ||
| 207 | switch (which_long_opt) { | ||
| 208 | case LONG_HEADER: { | ||
| 209 | int arglen = strlen(optarg); | ||
| 210 | if(extra_headers_left - arglen - 2 <= 0) | ||
| 211 | error_msg_and_die("extra_headers buffer too small(need %i)", extra_headers_left - arglen); | ||
| 212 | strcpy(extra_headers_ptr, optarg); | ||
| 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 | break; | ||
| 219 | } | ||
| 220 | } | ||
| 221 | break; | ||
| 190 | default: | 222 | default: |
| 191 | show_usage(); | 223 | show_usage(); |
| 192 | } | 224 | } |
| 193 | } | 225 | } |
| 194 | 226 | ||
| 227 | fprintf(stderr, "extra_headers='%s'\n", extra_headers); | ||
| 195 | if (argc - optind != 1) | 228 | if (argc - optind != 1) |
| 196 | show_usage(); | 229 | show_usage(); |
| 197 | 230 | ||
| @@ -291,6 +324,8 @@ int wget_main(int argc, char **argv) | |||
| 291 | 324 | ||
| 292 | if (do_continue) | 325 | if (do_continue) |
| 293 | fprintf(sfp, "Range: bytes=%ld-\r\n", beg_range); | 326 | fprintf(sfp, "Range: bytes=%ld-\r\n", beg_range); |
| 327 | if(extra_headers_left < sizeof(extra_headers)) | ||
| 328 | fprintf(sfp,extra_headers); | ||
| 294 | fprintf(sfp,"Connection: close\r\n\r\n"); | 329 | fprintf(sfp,"Connection: close\r\n\r\n"); |
| 295 | 330 | ||
| 296 | /* | 331 | /* |
| @@ -778,7 +813,7 @@ progressmeter(int flag) | |||
| 778 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 813 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 779 | * SUCH DAMAGE. | 814 | * SUCH DAMAGE. |
| 780 | * | 815 | * |
| 781 | * $Id: wget.c,v 1.38 2001/05/13 00:55:54 andersen Exp $ | 816 | * $Id: wget.c,v 1.39 2001/05/15 17:51:37 andersen Exp $ |
| 782 | */ | 817 | */ |
| 783 | 818 | ||
| 784 | 819 | ||
| @@ -1725,7 +1725,7 @@ | |||
| 1725 | " 31 46 1365 /etc/passwd\n" | 1725 | " 31 46 1365 /etc/passwd\n" |
| 1726 | 1726 | ||
| 1727 | #define wget_trivial_usage \ | 1727 | #define wget_trivial_usage \ |
| 1728 | "[-c] [-q] [-O file] url" | 1728 | "[-c|--continue] [-q|--quiet] [-O|--output-document file] [--header 'header: value'] url" |
| 1729 | #define wget_full_usage \ | 1729 | #define wget_full_usage \ |
| 1730 | "wget retrieves files via HTTP or FTP\n\n" \ | 1730 | "wget retrieves files via HTTP or FTP\n\n" \ |
| 1731 | "Options:\n" \ | 1731 | "Options:\n" \ |
| @@ -24,6 +24,11 @@ | |||
| 24 | #include <arpa/inet.h> | 24 | #include <arpa/inet.h> |
| 25 | #include <netdb.h> | 25 | #include <netdb.h> |
| 26 | 26 | ||
| 27 | #ifndef _GNU_SOURCE | ||
| 28 | #define _GNU_SOURCE | ||
| 29 | #endif | ||
| 30 | #include <getopt.h> | ||
| 31 | |||
| 27 | #include "busybox.h" | 32 | #include "busybox.h" |
| 28 | 33 | ||
| 29 | /* Stupid libc5 doesn't define this... */ | 34 | /* Stupid libc5 doesn't define this... */ |
| @@ -157,7 +162,10 @@ int wget_main(int argc, char **argv) | |||
| 157 | char *proxy; | 162 | char *proxy; |
| 158 | char *s, buf[512]; | 163 | char *s, buf[512]; |
| 159 | struct stat sbuf; | 164 | struct stat sbuf; |
| 160 | 165 | char extra_headers[1024]; | |
| 166 | char *extra_headers_ptr = extra_headers; | ||
| 167 | int extra_headers_left = sizeof(extra_headers); | ||
| 168 | int which_long_opt = 0, option_index = -1; | ||
| 161 | struct host_info server, target; | 169 | struct host_info server, target; |
| 162 | 170 | ||
| 163 | FILE *sfp = NULL; /* socket to web/ftp server */ | 171 | FILE *sfp = NULL; /* socket to web/ftp server */ |
| @@ -169,10 +177,18 @@ int wget_main(int argc, char **argv) | |||
| 169 | FILE *output; /* socket to web server */ | 177 | FILE *output; /* socket to web server */ |
| 170 | int quiet_flag = FALSE; /* Be verry, verry quiet... */ | 178 | int quiet_flag = FALSE; /* Be verry, verry quiet... */ |
| 171 | 179 | ||
| 180 | #define LONG_HEADER 1 | ||
| 181 | struct option long_options[] = { | ||
| 182 | { "continue", 0, NULL, 'c' }, | ||
| 183 | { "quiet", 0, NULL, 'q' }, | ||
| 184 | { "output-document", 1, NULL, 'O' }, | ||
| 185 | { "header", 1, &which_long_opt, LONG_HEADER }, | ||
| 186 | { 0, 0, 0, 0 } | ||
| 187 | }; | ||
| 172 | /* | 188 | /* |
| 173 | * Crack command line. | 189 | * Crack command line. |
| 174 | */ | 190 | */ |
| 175 | while ((n = getopt(argc, argv, "cqO:")) != EOF) { | 191 | while ((n = getopt_long(argc, argv, "cqO:", long_options, &option_index)) != EOF) { |
| 176 | switch (n) { | 192 | switch (n) { |
| 177 | case 'c': | 193 | case 'c': |
| 178 | ++do_continue; | 194 | ++do_continue; |
| @@ -187,11 +203,28 @@ int wget_main(int argc, char **argv) | |||
| 187 | */ | 203 | */ |
| 188 | fname_out = optarg; | 204 | fname_out = optarg; |
| 189 | break; | 205 | break; |
| 206 | case 0: | ||
| 207 | switch (which_long_opt) { | ||
| 208 | case LONG_HEADER: { | ||
| 209 | int arglen = strlen(optarg); | ||
| 210 | if(extra_headers_left - arglen - 2 <= 0) | ||
| 211 | error_msg_and_die("extra_headers buffer too small(need %i)", extra_headers_left - arglen); | ||
| 212 | strcpy(extra_headers_ptr, optarg); | ||
| 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 | break; | ||
| 219 | } | ||
| 220 | } | ||
| 221 | break; | ||
| 190 | default: | 222 | default: |
| 191 | show_usage(); | 223 | show_usage(); |
| 192 | } | 224 | } |
| 193 | } | 225 | } |
| 194 | 226 | ||
| 227 | fprintf(stderr, "extra_headers='%s'\n", extra_headers); | ||
| 195 | if (argc - optind != 1) | 228 | if (argc - optind != 1) |
| 196 | show_usage(); | 229 | show_usage(); |
| 197 | 230 | ||
| @@ -291,6 +324,8 @@ int wget_main(int argc, char **argv) | |||
| 291 | 324 | ||
| 292 | if (do_continue) | 325 | if (do_continue) |
| 293 | fprintf(sfp, "Range: bytes=%ld-\r\n", beg_range); | 326 | fprintf(sfp, "Range: bytes=%ld-\r\n", beg_range); |
| 327 | if(extra_headers_left < sizeof(extra_headers)) | ||
| 328 | fprintf(sfp,extra_headers); | ||
| 294 | fprintf(sfp,"Connection: close\r\n\r\n"); | 329 | fprintf(sfp,"Connection: close\r\n\r\n"); |
| 295 | 330 | ||
| 296 | /* | 331 | /* |
| @@ -778,7 +813,7 @@ progressmeter(int flag) | |||
| 778 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 813 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 779 | * SUCH DAMAGE. | 814 | * SUCH DAMAGE. |
| 780 | * | 815 | * |
| 781 | * $Id: wget.c,v 1.38 2001/05/13 00:55:54 andersen Exp $ | 816 | * $Id: wget.c,v 1.39 2001/05/15 17:51:37 andersen Exp $ |
| 782 | */ | 817 | */ |
| 783 | 818 | ||
| 784 | 819 | ||
