summaryrefslogtreecommitdiff
path: root/networking/wget.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-10-25 00:33:44 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-10-25 00:33:44 +0000
commitc8400a216206a848f6c4b83b668df37f6fb546ee (patch)
tree4aa28c4440e6c150a31188f1910b6a945176c27c /networking/wget.c
parent44c7917cab43713a034622bfb6e464de92cf8f1c (diff)
downloadbusybox-w32-c8400a216206a848f6c4b83b668df37f6fb546ee.tar.gz
busybox-w32-c8400a216206a848f6c4b83b668df37f6fb546ee.tar.bz2
busybox-w32-c8400a216206a848f6c4b83b668df37f6fb546ee.zip
wget: wget $'-\207' ... should not be allowed to work. ever. :)
So fix wget & getopt32. Also fix multiple --header options order: add and use rev_llist.
Diffstat (limited to 'networking/wget.c')
-rw-r--r--networking/wget.c72
1 files changed, 40 insertions, 32 deletions
diff --git a/networking/wget.c b/networking/wget.c
index 91e5e655a..a0d3e15e8 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -86,42 +86,22 @@ static char *base64enc(unsigned char *p, char *buf, int len)
86} 86}
87#endif 87#endif
88 88
89#define WGET_OPT_CONTINUE 1
90#define WGET_OPT_QUIET 2
91#define WGET_OPT_PASSIVE 4
92#define WGET_OPT_OUTNAME 8
93#define WGET_OPT_HEADER 16
94#define WGET_OPT_PREFIX 32
95#define WGET_OPT_PROXY 64
96#define WGET_OPT_USER_AGENT 128
97
98#if ENABLE_FEATURE_WGET_LONG_OPTIONS
99static const struct option wget_long_options[] = {
100 { "continue", 0, NULL, 'c' },
101 { "quiet", 0, NULL, 'q' },
102 { "passive-ftp", 0, NULL, 139 }, /* FIXME: what is this - 139?? */
103 { "output-document", 1, NULL, 'O' },
104 { "header", 1, NULL, 131 },
105 { "directory-prefix",1, NULL, 'P' },
106 { "proxy", 1, NULL, 'Y' },
107 { "user-agent", 1, NULL, 'U' },
108 { 0, 0, 0, 0 }
109};
110#endif
111
112int wget_main(int argc, char **argv) 89int wget_main(int argc, char **argv)
113{ 90{
91 char buf[512];
92 struct host_info server, target;
93 struct sockaddr_in s_in;
114 int n, status; 94 int n, status;
115 int try = 5;
116 int port; 95 int port;
96 int try = 5;
117 unsigned opt; 97 unsigned opt;
98 char *s;
118 char *proxy = 0; 99 char *proxy = 0;
119 char *dir_prefix = NULL; 100 char *dir_prefix = NULL;
120 char *s, buf[512]; 101#if ENABLE_FEATURE_WGET_LONG_OPTIONS
121 char *extra_headers = NULL; 102 char *extra_headers = NULL;
122 struct host_info server, target;
123 struct sockaddr_in s_in;
124 llist_t *headers_llist = NULL; 103 llist_t *headers_llist = NULL;
104#endif
125 105
126 /* server.allocated = target.allocated = NULL; */ 106 /* server.allocated = target.allocated = NULL; */
127 107
@@ -137,21 +117,46 @@ int wget_main(int argc, char **argv)
137 /* 117 /*
138 * Crack command line. 118 * Crack command line.
139 */ 119 */
140 opt_complementary = "-1:\203::"; 120 enum {
121 WGET_OPT_CONTINUE = 0x1,
122 WGET_OPT_QUIET = 0x2,
123 WGET_OPT_OUTNAME = 0x4,
124 WGET_OPT_PREFIX = 0x8,
125 WGET_OPT_PROXY = 0x10,
126 WGET_OPT_USER_AGENT = 0x20,
127 WGET_OPT_PASSIVE = 0x40,
128 WGET_OPT_HEADER = 0x80,
129 };
141#if ENABLE_FEATURE_WGET_LONG_OPTIONS 130#if ENABLE_FEATURE_WGET_LONG_OPTIONS
131 static const struct option wget_long_options[] = {
132 // name, has_arg, flag, val
133 { "continue", no_argument, NULL, 'c' },
134 { "quiet", no_argument, NULL, 'q' },
135 { "output-document", required_argument, NULL, 'O' },
136 { "directory-prefix", required_argument, NULL, 'P' },
137 { "proxy", required_argument, NULL, 'Y' },
138 { "user-agent", required_argument, NULL, 'U' },
139 { "passive-ftp", no_argument, NULL, 0xff },
140 { "header", required_argument, NULL, 0xfe },
141 { 0, 0, 0, 0 }
142};
142 applet_long_options = wget_long_options; 143 applet_long_options = wget_long_options;
143#endif 144#endif
144 opt = getopt32(argc, argv, "cq\213O:\203:P:Y:U:", 145 opt_complementary = "-1" USE_FEATURE_WGET_LONG_OPTIONS(":\xfe::");
145 &fname_out, &headers_llist, 146 opt = getopt32(argc, argv, "cqO:P:Y:U:",
146 &dir_prefix, &proxy_flag, &user_agent); 147 &fname_out, &dir_prefix,
148 &proxy_flag, &user_agent
149 USE_FEATURE_WGET_LONG_OPTIONS(, &headers_llist)
150 );
147 if (strcmp(proxy_flag, "off") == 0) { 151 if (strcmp(proxy_flag, "off") == 0) {
148 /* Use the proxy if necessary. */ 152 /* Use the proxy if necessary. */
149 use_proxy = 0; 153 use_proxy = 0;
150 } 154 }
155#if ENABLE_FEATURE_WGET_LONG_OPTIONS
151 if (headers_llist) { 156 if (headers_llist) {
152 int size = 1; 157 int size = 1;
153 char *cp; 158 char *cp;
154 llist_t *ll = headers_llist; 159 llist_t *ll = headers_llist = rev_llist(headers_llist);
155 while (ll) { 160 while (ll) {
156 size += strlen(ll->data) + 2; 161 size += strlen(ll->data) + 2;
157 ll = ll->link; 162 ll = ll->link;
@@ -162,6 +167,7 @@ int wget_main(int argc, char **argv)
162 headers_llist = headers_llist->link; 167 headers_llist = headers_llist->link;
163 } 168 }
164 } 169 }
170#endif
165 171
166 parse_url(argv[optind], &target); 172 parse_url(argv[optind], &target);
167 server.host = target.host; 173 server.host = target.host;
@@ -281,8 +287,10 @@ int wget_main(int argc, char **argv)
281 287
282 if (beg_range) 288 if (beg_range)
283 fprintf(sfp, "Range: bytes="OFF_FMT"-\r\n", beg_range); 289 fprintf(sfp, "Range: bytes="OFF_FMT"-\r\n", beg_range);
290#if ENABLE_FEATURE_WGET_LONG_OPTIONS
284 if (extra_headers) 291 if (extra_headers)
285 fputs(extra_headers, sfp); 292 fputs(extra_headers, sfp);
293#endif
286 fprintf(sfp, "Connection: close\r\n\r\n"); 294 fprintf(sfp, "Connection: close\r\n\r\n");
287 295
288 /* 296 /*