1 /***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24 #include "tool_setup.h"
25
26 #include "strcase.h"
27
28 #define ENABLE_CURLX_PRINTF
29 /* use our own printf() functions */
30 #include "curlx.h"
31
32 #include "tool_binmode.h"
33 #include "tool_cfgable.h"
34 #include "tool_cb_prg.h"
35 #include "tool_filetime.h"
36 #include "tool_formparse.h"
37 #include "tool_getparam.h"
38 #include "tool_helpers.h"
39 #include "tool_libinfo.h"
40 #include "tool_msgs.h"
41 #include "tool_paramhlp.h"
42 #include "tool_parsecfg.h"
43 #include "tool_main.h"
44 #include "dynbuf.h"
45 #include "tool_stderr.h"
46 #include "var.h"
47
48 #include "memdebug.h" /* keep this as LAST include */
49
50 #ifdef MSDOS
51 # define USE_WATT32
52 #endif
53
54 #define GetStr(str,val) do { \
55 if(*(str)) { \
56 free(*(str)); \
57 *(str) = NULL; \
58 } \
59 if((val)) { \
60 *(str) = strdup((val)); \
61 if(!(*(str))) { \
62 err = PARAM_NO_MEM; \
63 goto error; \
64 } \
65 } \
66 } while(0)
67
68 struct LongShort {
69 const char *letter; /* short name option */
70 const char *lname; /* long name option */
71 enum {
72 ARG_NONE, /* stand-alone but not a boolean */
73 ARG_BOOL, /* accepts a --no-[name] prefix */
74 ARG_STRING, /* requires an argument */
75 ARG_FILENAME /* requires an argument, usually a file name */
76 } desc;
77 };
78
79 static const struct LongShort aliases[]= {
80 /* 'letter' strings with more than one character have *no* short option to
81 mention. */
82 {"*@", "url", ARG_STRING},
83 {"*4", "dns-ipv4-addr", ARG_STRING},
84 {"*6", "dns-ipv6-addr", ARG_STRING},
85 {"*a", "random-file", ARG_FILENAME},
86 {"*b", "egd-file", ARG_STRING},
87 {"*B", "oauth2-bearer", ARG_STRING},
88 {"*c", "connect-timeout", ARG_STRING},
89 {"*C", "doh-url" , ARG_STRING},
90 {"*d", "ciphers", ARG_STRING},
91 {"*D", "dns-interface", ARG_STRING},
92 {"*e", "disable-epsv", ARG_BOOL},
93 {"*f", "disallow-username-in-url", ARG_BOOL},
94 {"*E", "epsv", ARG_BOOL},
95 /* 'epsv' made like this to make --no-epsv and --epsv to work
96 although --disable-epsv is the documented option */
97 {"*F", "dns-servers", ARG_STRING},
98 {"*g", "trace", ARG_FILENAME},
99 {"*G", "npn", ARG_BOOL},
100 {"*h", "trace-ascii", ARG_FILENAME},
101 {"*H", "alpn", ARG_BOOL},
102 {"*i", "limit-rate", ARG_STRING},
103 {"*I", "rate", ARG_STRING},
104 {"*j", "compressed", ARG_BOOL},
105 {"*J", "tr-encoding", ARG_BOOL},
106 {"*k", "digest", ARG_BOOL},
107 {"*l", "negotiate", ARG_BOOL},
108 {"*m", "ntlm", ARG_BOOL},
109 {"*M", "ntlm-wb", ARG_BOOL},
110 {"*n", "basic", ARG_BOOL},
111 {"*o", "anyauth", ARG_BOOL},
112 #ifdef USE_WATT32
113 {"*p", "wdebug", ARG_BOOL},
114 #endif
115 {"*q", "ftp-create-dirs", ARG_BOOL},
116 {"*r", "create-dirs", ARG_BOOL},
117 {"*R", "create-file-mode", ARG_STRING},
118 {"*s", "max-redirs", ARG_STRING},
119 {"*S", "ipfs-gateway", ARG_STRING},
120 {"*t", "proxy-ntlm", ARG_BOOL},
121 {"*u", "crlf", ARG_BOOL},
122 {"*v", "stderr", ARG_FILENAME},
123 {"*V", "aws-sigv4", ARG_STRING},
124 {"*w", "interface", ARG_STRING},
125 {"*x", "krb", ARG_STRING},
126 {"*x", "krb4", ARG_STRING},
127 /* 'krb4' is the previous name */
128 {"*X", "haproxy-protocol", ARG_BOOL},
129 {"*P", "haproxy-clientip", ARG_STRING},
130 {"*y", "max-filesize", ARG_STRING},
131 {"*z", "disable-eprt", ARG_BOOL},
132 {"*Z", "eprt", ARG_BOOL},
133 /* 'eprt' made like this to make --no-eprt and --eprt to work
134 although --disable-eprt is the documented option */
135 {"*~", "xattr", ARG_BOOL},
136 {"$a", "ftp-ssl", ARG_BOOL},
137 /* 'ftp-ssl' deprecated name since 7.20.0 */
138 {"$a", "ssl", ARG_BOOL},
139 /* 'ssl' new option name in 7.20.0, previously this was ftp-ssl */
140 {"$b", "ftp-pasv", ARG_BOOL},
141 {"$c", "socks5", ARG_STRING},
142 {"$d", "tcp-nodelay", ARG_BOOL},
143 {"$e", "proxy-digest", ARG_BOOL},
144 {"$f", "proxy-basic", ARG_BOOL},
145 {"$g", "retry", ARG_STRING},
146 {"$V", "retry-connrefused", ARG_BOOL},
147 {"$h", "retry-delay", ARG_STRING},
148 {"$i", "retry-max-time", ARG_STRING},
149 {"$k", "proxy-negotiate", ARG_BOOL},
150 {"$l", "form-escape", ARG_BOOL},
151 {"$m", "ftp-account", ARG_STRING},
152 {"$n", "proxy-anyauth", ARG_BOOL},
153 {"$o", "trace-time", ARG_BOOL},
154 {"$p", "ignore-content-length", ARG_BOOL},
155 {"$q", "ftp-skip-pasv-ip", ARG_BOOL},
156 {"$r", "ftp-method", ARG_STRING},
157 {"$s", "local-port", ARG_STRING},
158 {"$t", "socks4", ARG_STRING},
159 {"$T", "socks4a", ARG_STRING},
160 {"$u", "ftp-alternative-to-user", ARG_STRING},
161 {"$v", "ftp-ssl-reqd", ARG_BOOL},
162 /* 'ftp-ssl-reqd' deprecated name since 7.20.0 */
163 {"$v", "ssl-reqd", ARG_BOOL},
164 /* 'ssl-reqd' new in 7.20.0, previously this was ftp-ssl-reqd */
165 {"$w", "sessionid", ARG_BOOL},
166 /* 'sessionid' listed as --no-sessionid in the help */
167 {"$x", "ftp-ssl-control", ARG_BOOL},
168 {"$y", "ftp-ssl-ccc", ARG_BOOL},
169 {"$j", "ftp-ssl-ccc-mode", ARG_STRING},
170 {"$z", "libcurl", ARG_STRING},
171 {"$#", "raw", ARG_BOOL},
172 {"$0", "post301", ARG_BOOL},
173 {"$1", "keepalive", ARG_BOOL},
174 /* 'keepalive' listed as --no-keepalive in the help */
175 {"$2", "socks5-hostname", ARG_STRING},
176 {"$3", "keepalive-time", ARG_STRING},
177 {"$4", "post302", ARG_BOOL},
178 {"$5", "noproxy", ARG_STRING},
179 {"$7", "socks5-gssapi-nec", ARG_BOOL},
180 {"$8", "proxy1.0", ARG_STRING},
181 {"$9", "tftp-blksize", ARG_STRING},
182 {"$A", "mail-from", ARG_STRING},
183 {"$B", "mail-rcpt", ARG_STRING},
184 {"$C", "ftp-pret", ARG_BOOL},
185 {"$D", "proto", ARG_STRING},
186 {"$E", "proto-redir", ARG_STRING},
187 {"$F", "resolve", ARG_STRING},
188 {"$G", "delegation", ARG_STRING},
189 {"$H", "mail-auth", ARG_STRING},
190 {"$I", "post303", ARG_BOOL},
191 {"$J", "metalink", ARG_BOOL},
192 {"$6", "sasl-authzid", ARG_STRING},
193 {"$K", "sasl-ir", ARG_BOOL },
194 {"$L", "test-event", ARG_BOOL},
195 {"$M", "unix-socket", ARG_FILENAME},
196 {"$N", "path-as-is", ARG_BOOL},
197 {"$O", "socks5-gssapi-service", ARG_STRING},
198 /* 'socks5-gssapi-service' merged with'proxy-service-name' and
199 deprecated since 7.49.0 */
200 {"$O", "proxy-service-name", ARG_STRING},
201 {"$P", "service-name", ARG_STRING},
202 {"$Q", "proto-default", ARG_STRING},
203 {"$R", "expect100-timeout", ARG_STRING},
204 {"$S", "tftp-no-options", ARG_BOOL},
205 {"$U", "connect-to", ARG_STRING},
206 {"$W", "abstract-unix-socket", ARG_FILENAME},
207 {"$X", "tls-max", ARG_STRING},
208 {"$Y", "suppress-connect-headers", ARG_BOOL},
209 {"$Z", "compressed-ssh", ARG_BOOL},
210 {"$~", "happy-eyeballs-timeout-ms", ARG_STRING},
211 {"$!", "retry-all-errors", ARG_BOOL},
212 {"$%", "trace-ids", ARG_BOOL},
213 {"$&", "trace-config", ARG_STRING},
214 {"0", "http1.0", ARG_NONE},
215 {"01", "http1.1", ARG_NONE},
216 {"02", "http2", ARG_NONE},
217 {"03", "http2-prior-knowledge", ARG_NONE},
218 {"04", "http3", ARG_NONE},
219 {"05", "http3-only", ARG_NONE},
220 {"09", "http0.9", ARG_BOOL},
221 {"0a", "proxy-http2", ARG_BOOL},
222 {"1", "tlsv1", ARG_NONE},
223 {"10", "tlsv1.0", ARG_NONE},
224 {"11", "tlsv1.1", ARG_NONE},
225 {"12", "tlsv1.2", ARG_NONE},
226 {"13", "tlsv1.3", ARG_NONE},
227 {"1A", "tls13-ciphers", ARG_STRING},
228 {"1B", "proxy-tls13-ciphers", ARG_STRING},
229 {"2", "sslv2", ARG_NONE},
230 {"3", "sslv3", ARG_NONE},
231 {"4", "ipv4", ARG_NONE},
232 {"6", "ipv6", ARG_NONE},
233 {"a", "append", ARG_BOOL},
234 {"A", "user-agent", ARG_STRING},
235 {"b", "cookie", ARG_STRING},
236 {"ba", "alt-svc", ARG_STRING},
237 {"bb", "hsts", ARG_STRING},
238 {"B", "use-ascii", ARG_BOOL},
239 {"c", "cookie-jar", ARG_STRING},
240 {"C", "continue-at", ARG_STRING},
241 {"d", "data", ARG_STRING},
242 {"dr", "data-raw", ARG_STRING},
243 {"da", "data-ascii", ARG_STRING},
244 {"db", "data-binary", ARG_STRING},
245 {"de", "data-urlencode", ARG_STRING},
246 {"df", "json", ARG_STRING},
247 {"dg", "url-query", ARG_STRING},
248 {"D", "dump-header", ARG_FILENAME},
249 {"e", "referer", ARG_STRING},
250 {"E", "cert", ARG_FILENAME},
251 {"Ea", "cacert", ARG_FILENAME},
252 {"Eb", "cert-type", ARG_STRING},
253 {"Ec", "key", ARG_FILENAME},
254 {"Ed", "key-type", ARG_STRING},
255 {"Ee", "pass", ARG_STRING},
256 {"Ef", "engine", ARG_STRING},
257 {"EG", "ca-native", ARG_BOOL},
258 {"EH", "proxy-ca-native", ARG_BOOL},
259 {"Eg", "capath", ARG_FILENAME},
260 {"Eh", "pubkey", ARG_STRING},
261 {"Ei", "hostpubmd5", ARG_STRING},
262 {"EF", "hostpubsha256", ARG_STRING},
263 {"Ej", "crlfile", ARG_FILENAME},
264 {"Ek", "tlsuser", ARG_STRING},
265 {"El", "tlspassword", ARG_STRING},
266 {"Em", "tlsauthtype", ARG_STRING},
267 {"En", "ssl-allow-beast", ARG_BOOL},
268 {"Eo", "ssl-auto-client-cert", ARG_BOOL},
269 {"EO", "proxy-ssl-auto-client-cert", ARG_BOOL},
270 {"Ep", "pinnedpubkey", ARG_STRING},
271 {"EP", "proxy-pinnedpubkey", ARG_STRING},
272 {"Eq", "cert-status", ARG_BOOL},
273 {"EQ", "doh-cert-status", ARG_BOOL},
274 {"Er", "false-start", ARG_BOOL},
275 {"Es", "ssl-no-revoke", ARG_BOOL},
276 {"ES", "ssl-revoke-best-effort", ARG_BOOL},
277 {"Et", "tcp-fastopen", ARG_BOOL},
278 {"Eu", "proxy-tlsuser", ARG_STRING},
279 {"Ev", "proxy-tlspassword", ARG_STRING},
280 {"Ew", "proxy-tlsauthtype", ARG_STRING},
281 {"Ex", "proxy-cert", ARG_FILENAME},
282 {"Ey", "proxy-cert-type", ARG_STRING},
283 {"Ez", "proxy-key", ARG_FILENAME},
284 {"E0", "proxy-key-type", ARG_STRING},
285 {"E1", "proxy-pass", ARG_STRING},
286 {"E2", "proxy-ciphers", ARG_STRING},
287 {"E3", "proxy-crlfile", ARG_FILENAME},
288 {"E4", "proxy-ssl-allow-beast", ARG_BOOL},
289 {"E5", "login-options", ARG_STRING},
290 {"E6", "proxy-cacert", ARG_FILENAME},
291 {"E7", "proxy-capath", ARG_FILENAME},
292 {"E8", "proxy-insecure", ARG_BOOL},
293 {"E9", "proxy-tlsv1", ARG_NONE},
294 {"EA", "socks5-basic", ARG_BOOL},
295 {"EB", "socks5-gssapi", ARG_BOOL},
296 {"EC", "etag-save", ARG_FILENAME},
297 {"ED", "etag-compare", ARG_FILENAME},
298 {"EE", "curves", ARG_STRING},
299 {"f", "fail", ARG_BOOL},
300 {"fa", "fail-early", ARG_BOOL},
301 {"fb", "styled-output", ARG_BOOL},
302 {"fc", "mail-rcpt-allowfails", ARG_BOOL},
303 {"fd", "fail-with-body", ARG_BOOL},
304 {"fe", "remove-on-error", ARG_BOOL},
305 {"F", "form", ARG_STRING},
306 {"Fs", "form-string", ARG_STRING},
307 {"g", "globoff", ARG_BOOL},
308 {"G", "get", ARG_BOOL},
309 {"Ga", "request-target", ARG_STRING},
310 {"h", "help", ARG_BOOL},
311 {"H", "header", ARG_STRING},
312 {"Hp", "proxy-header", ARG_STRING},
313 {"i", "include", ARG_BOOL},
314 {"I", "head", ARG_BOOL},
315 {"j", "junk-session-cookies", ARG_BOOL},
316 {"J", "remote-header-name", ARG_BOOL},
317 {"k", "insecure", ARG_BOOL},
318 {"kd", "doh-insecure", ARG_BOOL},
319 {"K", "config", ARG_FILENAME},
320 {"l", "list-only", ARG_BOOL},
321 {"L", "location", ARG_BOOL},
322 {"Lt", "location-trusted", ARG_BOOL},
323 {"m", "max-time", ARG_STRING},
324 {"M", "manual", ARG_BOOL},
325 {"n", "netrc", ARG_BOOL},
326 {"no", "netrc-optional", ARG_BOOL},
327 {"ne", "netrc-file", ARG_FILENAME},
328 {"N", "buffer", ARG_BOOL},
329 /* 'buffer' listed as --no-buffer in the help */
330 {"o", "output", ARG_FILENAME},
331 {"O", "remote-name", ARG_BOOL},
332 {"Oa", "remote-name-all", ARG_BOOL},
333 {"Ob", "output-dir", ARG_STRING},
334 {"Oc", "clobber", ARG_BOOL},
335 {"p", "proxytunnel", ARG_BOOL},
336 {"P", "ftp-port", ARG_STRING},
337 {"q", "disable", ARG_BOOL},
338 {"Q", "quote", ARG_STRING},
339 {"r", "range", ARG_STRING},
340 {"R", "remote-time", ARG_BOOL},
341 {"s", "silent", ARG_BOOL},
342 {"S", "show-error", ARG_BOOL},
343 {"t", "telnet-option", ARG_STRING},
344 {"T", "upload-file", ARG_FILENAME},
345 {"u", "user", ARG_STRING},
346 {"U", "proxy-user", ARG_STRING},
347 {"v", "verbose", ARG_BOOL},
348 {"V", "version", ARG_BOOL},
349 {"w", "write-out", ARG_STRING},
350 {"x", "proxy", ARG_STRING},
351 {"xa", "preproxy", ARG_STRING},
352 {"X", "request", ARG_STRING},
353 {"Y", "speed-limit", ARG_STRING},
354 {"y", "speed-time", ARG_STRING},
355 {"z", "time-cond", ARG_STRING},
356 {"Z", "parallel", ARG_BOOL},
357 {"Zb", "parallel-max", ARG_STRING},
358 {"Zc", "parallel-immediate", ARG_BOOL},
359 {"#", "progress-bar", ARG_BOOL},
360 {"#m", "progress-meter", ARG_BOOL},
361 {":", "next", ARG_NONE},
362 {":a", "variable", ARG_STRING},
363 };
364
365 /* Split the argument of -E to 'certname' and 'passphrase' separated by colon.
366 * We allow ':' and '\' to be escaped by '\' so that we can use certificate
367 * nicknames containing ':'. See <https://sourceforge.net/p/curl/bugs/1196/>
368 * for details. */
369 #ifndef UNITTESTS
370 static
371 #endif
parse_cert_parameter(const char * cert_parameter,char ** certname,char ** passphrase)372 void parse_cert_parameter(const char *cert_parameter,
373 char **certname,
374 char **passphrase)
375 {
376 size_t param_length = strlen(cert_parameter);
377 size_t span;
378 const char *param_place = NULL;
379 char *certname_place = NULL;
380 *certname = NULL;
381 *passphrase = NULL;
382
383 /* most trivial assumption: cert_parameter is empty */
384 if(param_length == 0)
385 return;
386
387 /* next less trivial: cert_parameter starts 'pkcs11:' and thus
388 * looks like a RFC7512 PKCS#11 URI which can be used as-is.
389 * Also if cert_parameter contains no colon nor backslash, this
390 * means no passphrase was given and no characters escaped */
391 if(curl_strnequal(cert_parameter, "pkcs11:", 7) ||
392 !strpbrk(cert_parameter, ":\\")) {
393 *certname = strdup(cert_parameter);
394 return;
395 }
396 /* deal with escaped chars; find unescaped colon if it exists */
397 certname_place = malloc(param_length + 1);
398 if(!certname_place)
399 return;
400
401 *certname = certname_place;
402 param_place = cert_parameter;
403 while(*param_place) {
404 span = strcspn(param_place, ":\\");
405 strncpy(certname_place, param_place, span);
406 param_place += span;
407 certname_place += span;
408 /* we just ate all the non-special chars. now we're on either a special
409 * char or the end of the string. */
410 switch(*param_place) {
411 case '\0':
412 break;
413 case '\\':
414 param_place++;
415 switch(*param_place) {
416 case '\0':
417 *certname_place++ = '\\';
418 break;
419 case '\\':
420 *certname_place++ = '\\';
421 param_place++;
422 break;
423 case ':':
424 *certname_place++ = ':';
425 param_place++;
426 break;
427 default:
428 *certname_place++ = '\\';
429 *certname_place++ = *param_place;
430 param_place++;
431 break;
432 }
433 break;
434 case ':':
435 /* Since we live in a world of weirdness and confusion, the win32
436 dudes can use : when using drive letters and thus c:\file:password
437 needs to work. In order not to break compatibility, we still use : as
438 separator, but we try to detect when it is used for a file name! On
439 windows. */
440 #ifdef WIN32
441 if((param_place == &cert_parameter[1]) &&
442 (cert_parameter[2] == '\\' || cert_parameter[2] == '/') &&
443 (ISALPHA(cert_parameter[0])) ) {
444 /* colon in the second column, followed by a backslash, and the
445 first character is an alphabetic letter:
446
447 this is a drive letter colon */
448 *certname_place++ = ':';
449 param_place++;
450 break;
451 }
452 #endif
453 /* escaped colons and Windows drive letter colons were handled
454 * above; if we're still here, this is a separating colon */
455 param_place++;
456 if(*param_place) {
457 *passphrase = strdup(param_place);
458 }
459 goto done;
460 }
461 }
462 done:
463 *certname_place = '\0';
464 }
465
466 /* Replace (in-place) '%20' by '+' according to RFC1866 */
replace_url_encoded_space_by_plus(char * url)467 static size_t replace_url_encoded_space_by_plus(char *url)
468 {
469 size_t orig_len = strlen(url);
470 size_t orig_index = 0;
471 size_t new_index = 0;
472
473 while(orig_index < orig_len) {
474 if((url[orig_index] == '%') &&
475 (url[orig_index + 1] == '2') &&
476 (url[orig_index + 2] == '0')) {
477 url[new_index] = '+';
478 orig_index += 3;
479 }
480 else{
481 if(new_index != orig_index) {
482 url[new_index] = url[orig_index];
483 }
484 orig_index++;
485 }
486 new_index++;
487 }
488
489 url[new_index] = 0; /* terminate string */
490
491 return new_index; /* new size */
492 }
493
494 static void
GetFileAndPassword(char * nextarg,char ** file,char ** password)495 GetFileAndPassword(char *nextarg, char **file, char **password)
496 {
497 char *certname, *passphrase;
498 parse_cert_parameter(nextarg, &certname, &passphrase);
499 Curl_safefree(*file);
500 *file = certname;
501 if(passphrase) {
502 Curl_safefree(*password);
503 *password = passphrase;
504 }
505 }
506
507 /* Get a size parameter for '--limit-rate' or '--max-filesize'.
508 * We support a 'G', 'M' or 'K' suffix too.
509 */
GetSizeParameter(struct GlobalConfig * global,const char * arg,const char * which,curl_off_t * value_out)510 static ParameterError GetSizeParameter(struct GlobalConfig *global,
511 const char *arg,
512 const char *which,
513 curl_off_t *value_out)
514 {
515 char *unit;
516 curl_off_t value;
517
518 if(curlx_strtoofft(arg, &unit, 10, &value)) {
519 warnf(global, "invalid number specified for %s", which);
520 return PARAM_BAD_USE;
521 }
522
523 if(!*unit)
524 unit = (char *)"b";
525 else if(strlen(unit) > 1)
526 unit = (char *)"w"; /* unsupported */
527
528 switch(*unit) {
529 case 'G':
530 case 'g':
531 if(value > (CURL_OFF_T_MAX / (1024*1024*1024)))
532 return PARAM_NUMBER_TOO_LARGE;
533 value *= 1024*1024*1024;
534 break;
535 case 'M':
536 case 'm':
537 if(value > (CURL_OFF_T_MAX / (1024*1024)))
538 return PARAM_NUMBER_TOO_LARGE;
539 value *= 1024*1024;
540 break;
541 case 'K':
542 case 'k':
543 if(value > (CURL_OFF_T_MAX / 1024))
544 return PARAM_NUMBER_TOO_LARGE;
545 value *= 1024;
546 break;
547 case 'b':
548 case 'B':
549 /* for plain bytes, leave as-is */
550 break;
551 default:
552 warnf(global, "unsupported %s unit. Use G, M, K or B", which);
553 return PARAM_BAD_USE;
554 }
555 *value_out = value;
556 return PARAM_OK;
557 }
558
559 #ifdef HAVE_WRITABLE_ARGV
cleanarg(argv_item_t str)560 static void cleanarg(argv_item_t str)
561 {
562 /* now that GetStr has copied the contents of nextarg, wipe the next
563 * argument out so that the username:password isn't displayed in the
564 * system process list */
565 if(str) {
566 size_t len = strlen(str);
567 memset(str, ' ', len);
568 }
569 }
570 #else
571 #define cleanarg(x)
572 #endif
573
574 /* --data-urlencode */
data_urlencode(struct GlobalConfig * global,char * nextarg,char ** postp,size_t * lenp)575 static ParameterError data_urlencode(struct GlobalConfig *global,
576 char *nextarg,
577 char **postp,
578 size_t *lenp)
579 {
580 /* [name]=[content], we encode the content part only
581 * [name]@[file name]
582 *
583 * Case 2: we first load the file using that name and then encode
584 * the content.
585 */
586 ParameterError err;
587 const char *p = strchr(nextarg, '=');
588 size_t nlen;
589 char is_file;
590 char *postdata = NULL;
591 size_t size = 0;
592 if(!p)
593 /* there was no '=' letter, check for a '@' instead */
594 p = strchr(nextarg, '@');
595 if(p) {
596 nlen = p - nextarg; /* length of the name part */
597 is_file = *p++; /* pass the separator */
598 }
599 else {
600 /* neither @ nor =, so no name and it isn't a file */
601 nlen = is_file = 0;
602 p = nextarg;
603 }
604 if('@' == is_file) {
605 FILE *file;
606 /* a '@' letter, it means that a file name or - (stdin) follows */
607 if(!strcmp("-", p)) {
608 file = stdin;
609 set_binmode(stdin);
610 }
611 else {
612 file = fopen(p, "rb");
613 if(!file) {
614 errorf(global, "Failed to open %s", p);
615 return PARAM_READ_ERROR;
616 }
617 }
618
619 err = file2memory(&postdata, &size, file);
620
621 if(file && (file != stdin))
622 fclose(file);
623 if(err)
624 return err;
625 }
626 else {
627 GetStr(&postdata, p);
628 if(postdata)
629 size = strlen(postdata);
630 }
631
632 if(!postdata) {
633 /* no data from the file, point to a zero byte string to make this
634 get sent as a POST anyway */
635 postdata = strdup("");
636 if(!postdata)
637 return PARAM_NO_MEM;
638 size = 0;
639 }
640 else {
641 char *enc = curl_easy_escape(NULL, postdata, (int)size);
642 Curl_safefree(postdata); /* no matter if it worked or not */
643 if(enc) {
644 /* replace (in-place) '%20' by '+' according to RFC1866 */
645 size_t enclen = replace_url_encoded_space_by_plus(enc);
646 /* now make a string with the name from above and append the
647 encoded string */
648 size_t outlen = nlen + enclen + 2;
649 char *n = malloc(outlen);
650 if(!n) {
651 curl_free(enc);
652 return PARAM_NO_MEM;
653 }
654 if(nlen > 0) { /* only append '=' if we have a name */
655 msnprintf(n, outlen, "%.*s=%s", (int)nlen, nextarg, enc);
656 size = outlen-1;
657 }
658 else {
659 strcpy(n, enc);
660 size = outlen-2; /* since no '=' was inserted */
661 }
662 curl_free(enc);
663 postdata = n;
664 }
665 else
666 return PARAM_NO_MEM;
667 }
668 *postp = postdata;
669 *lenp = size;
670 return PARAM_OK;
671 error:
672 return err;
673 }
674
sethttpver(struct GlobalConfig * global,struct OperationConfig * config,long httpversion)675 static void sethttpver(struct GlobalConfig *global,
676 struct OperationConfig *config,
677 long httpversion)
678 {
679 if(config->httpversion &&
680 (config->httpversion != httpversion))
681 warnf(global, "Overrides previous HTTP version option");
682
683 config->httpversion = httpversion;
684 }
685
set_trace_config(struct GlobalConfig * global,const char * config)686 static CURLcode set_trace_config(struct GlobalConfig *global,
687 const char *config)
688 {
689 CURLcode result = CURLE_OK;
690 char *token, *tmp, *name;
691 bool toggle;
692
693 tmp = strdup(config);
694 if(!tmp)
695 return CURLE_OUT_OF_MEMORY;
696
697 /* Allow strtok() here since this isn't used threaded */
698 /* !checksrc! disable BANNEDFUNC 2 */
699 token = strtok(tmp, ", ");
700 while(token) {
701 switch(*token) {
702 case '-':
703 toggle = FALSE;
704 name = token + 1;
705 break;
706 case '+':
707 toggle = TRUE;
708 name = token + 1;
709 break;
710 default:
711 toggle = TRUE;
712 name = token;
713 break;
714 }
715
716 if(strcasecompare(name, "all")) {
717 global->traceids = toggle;
718 global->tracetime = toggle;
719 result = curl_global_trace(token);
720 if(result)
721 goto out;
722 }
723 else if(strcasecompare(name, "ids")) {
724 global->traceids = toggle;
725 }
726 else if(strcasecompare(name, "time")) {
727 global->tracetime = toggle;
728 }
729 else {
730 result = curl_global_trace(token);
731 if(result)
732 goto out;
733 }
734 token = strtok(NULL, ", ");
735 }
736 out:
737 free(tmp);
738 return result;
739 }
740
getparameter(const char * flag,char * nextarg,argv_item_t cleararg,bool * usedarg,struct GlobalConfig * global,struct OperationConfig * config)741 ParameterError getparameter(const char *flag, /* f or -long-flag */
742 char *nextarg, /* NULL if unset */
743 argv_item_t cleararg,
744 bool *usedarg, /* set to TRUE if the arg
745 has been used */
746 struct GlobalConfig *global,
747 struct OperationConfig *config)
748 {
749 char letter;
750 char subletter = '\0'; /* subletters can only occur on long options */
751 int rc;
752 const char *parse = NULL;
753 unsigned int j;
754 time_t now;
755 int hit = -1;
756 bool longopt = FALSE;
757 bool singleopt = FALSE; /* when true means '-o foo' used '-ofoo' */
758 ParameterError err = PARAM_OK;
759 bool toggle = TRUE; /* how to switch boolean options, on or off. Controlled
760 by using --OPTION or --no-OPTION */
761 bool nextalloc = FALSE; /* if nextarg is allocated */
762 static const char *redir_protos[] = {
763 "http",
764 "https",
765 "ftp",
766 "ftps",
767 NULL
768 };
769 #ifdef HAVE_WRITABLE_ARGV
770 argv_item_t clearthis = NULL;
771 #else
772 (void)cleararg;
773 #endif
774
775 *usedarg = FALSE; /* default is that we don't use the arg */
776
777 if(('-' != flag[0]) || ('-' == flag[1])) {
778 /* this should be a long name */
779 const char *word = ('-' == flag[0]) ? flag + 2 : flag;
780 size_t fnam = strlen(word);
781 int numhits = 0;
782 bool noflagged = FALSE;
783 bool expand = FALSE;
784
785 if(!strncmp(word, "no-", 3)) {
786 /* disable this option but ignore the "no-" part when looking for it */
787 word += 3;
788 toggle = FALSE;
789 noflagged = TRUE;
790 }
791 else if(!strncmp(word, "expand-", 7)) {
792 /* variable expansions is to be done on the argument */
793 word += 7;
794 expand = TRUE;
795 }
796
797 for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) {
798 if(curl_strnequal(aliases[j].lname, word, fnam)) {
799 longopt = TRUE;
800 numhits++;
801 if(curl_strequal(aliases[j].lname, word)) {
802 parse = aliases[j].letter;
803 hit = j;
804 numhits = 1; /* a single unique hit */
805 break;
806 }
807 parse = aliases[j].letter;
808 hit = j;
809 }
810 }
811 if(numhits > 1) {
812 /* this is at least the second match! */
813 err = PARAM_OPTION_AMBIGUOUS;
814 goto error;
815 }
816 else if(hit < 0) {
817 err = PARAM_OPTION_UNKNOWN;
818 goto error;
819 }
820 else if(noflagged && (aliases[hit].desc != ARG_BOOL)) {
821 /* --no- prefixed an option that isn't boolean! */
822 err = PARAM_NO_NOT_BOOLEAN;
823 goto error;
824 }
825 else if(expand) {
826 struct curlx_dynbuf nbuf;
827 bool replaced;
828
829 if((aliases[hit].desc != ARG_STRING) &&
830 (aliases[hit].desc != ARG_FILENAME)) {
831 /* --expand on an option that isn't a string or a filename */
832 err = PARAM_EXPAND_ERROR;
833 goto error;
834 }
835 err = varexpand(global, nextarg, &nbuf, &replaced);
836 if(err) {
837 curlx_dyn_free(&nbuf);
838 goto error;
839 }
840 if(replaced) {
841 nextarg = curlx_dyn_ptr(&nbuf);
842 nextalloc = TRUE;
843 }
844 }
845 }
846 else {
847 flag++; /* prefixed with one dash, pass it */
848 hit = -1;
849 parse = flag;
850 }
851
852 do {
853 /* we can loop here if we have multiple single-letters */
854
855 if(!longopt) {
856 letter = (char)*parse;
857 subletter = '\0';
858 }
859 else {
860 letter = parse[0];
861 subletter = parse[1];
862 }
863
864 if(hit < 0) {
865 for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) {
866 if(letter == aliases[j].letter[0]) {
867 hit = j;
868 break;
869 }
870 }
871 if(hit < 0) {
872 err = PARAM_OPTION_UNKNOWN;
873 break;
874 }
875 }
876
877 if(aliases[hit].desc >= ARG_STRING) {
878 /* this option requires an extra parameter */
879 if(!longopt && parse[1]) {
880 nextarg = (char *)&parse[1]; /* this is the actual extra parameter */
881 singleopt = TRUE; /* don't loop anymore after this */
882 }
883 else if(!nextarg) {
884 err = PARAM_REQUIRES_PARAMETER;
885 break;
886 }
887 else {
888 #ifdef HAVE_WRITABLE_ARGV
889 clearthis = cleararg;
890 #endif
891 *usedarg = TRUE; /* mark it as used */
892 }
893
894 if((aliases[hit].desc == ARG_FILENAME) &&
895 (nextarg[0] == '-') && nextarg[1]) {
896 /* if the file name looks like a command line option */
897 warnf(global, "The file name argument '%s' looks like a flag.",
898 nextarg);
899 }
900 }
901 else if((aliases[hit].desc == ARG_NONE) && !toggle) {
902 err = PARAM_NO_PREFIX;
903 break;
904 }
905
906 switch(letter) {
907 case '*': /* options without a short option */
908 switch(subletter) {
909 case '4': /* --dns-ipv4-addr */
910 if(!curlinfo->ares_num) { /* c-ares is needed for this */
911 err = PARAM_LIBCURL_DOESNT_SUPPORT;
912 break;
913 }
914 /* addr in dot notation */
915 GetStr(&config->dns_ipv4_addr, nextarg);
916 break;
917 case '6': /* --dns-ipv6-addr */
918 if(!curlinfo->ares_num) { /* c-ares is needed for this */
919 err = PARAM_LIBCURL_DOESNT_SUPPORT;
920 break;
921 }
922 /* addr in dot notation */
923 GetStr(&config->dns_ipv6_addr, nextarg);
924 break;
925 case 'a': /* random-file */
926 break;
927 case 'b': /* egd-file */
928 break;
929 case 'B': /* OAuth 2.0 bearer token */
930 GetStr(&config->oauth_bearer, nextarg);
931 cleanarg(clearthis);
932 config->authtype |= CURLAUTH_BEARER;
933 break;
934 case 'c': /* connect-timeout */
935 err = secs2ms(&config->connecttimeout_ms, nextarg);
936 break;
937 case 'C': /* doh-url */
938 GetStr(&config->doh_url, nextarg);
939 if(config->doh_url && !config->doh_url[0])
940 /* if given a blank string, we make it NULL again */
941 Curl_safefree(config->doh_url);
942 break;
943 case 'd': /* ciphers */
944 GetStr(&config->cipher_list, nextarg);
945 break;
946 case 'D': /* --dns-interface */
947 if(!curlinfo->ares_num) /* c-ares is needed for this */
948 err = PARAM_LIBCURL_DOESNT_SUPPORT;
949 else
950 /* interface name */
951 GetStr(&config->dns_interface, nextarg);
952 break;
953 case 'e': /* --disable-epsv */
954 config->disable_epsv = toggle;
955 break;
956 case 'f': /* --disallow-username-in-url */
957 config->disallow_username_in_url = toggle;
958 break;
959 case 'E': /* --epsv */
960 config->disable_epsv = (!toggle)?TRUE:FALSE;
961 break;
962 case 'F': /* --dns-servers */
963 if(!curlinfo->ares_num) /* c-ares is needed for this */
964 err = PARAM_LIBCURL_DOESNT_SUPPORT;
965 else
966 /* IP addrs of DNS servers */
967 GetStr(&config->dns_servers, nextarg);
968 break;
969 case 'g': /* --trace */
970 GetStr(&global->trace_dump, nextarg);
971 if(global->tracetype && (global->tracetype != TRACE_BIN))
972 warnf(global, "--trace overrides an earlier trace/verbose option");
973 global->tracetype = TRACE_BIN;
974 break;
975 case 'G': /* --npn */
976 warnf(global, "--npn is no longer supported");
977 break;
978 case 'h': /* --trace-ascii */
979 GetStr(&global->trace_dump, nextarg);
980 if(global->tracetype && (global->tracetype != TRACE_ASCII))
981 warnf(global,
982 "--trace-ascii overrides an earlier trace/verbose option");
983 global->tracetype = TRACE_ASCII;
984 break;
985 case 'H': /* --alpn */
986 config->noalpn = (!toggle)?TRUE:FALSE;
987 break;
988 case 'i': /* --limit-rate */
989 {
990 curl_off_t value;
991 err = GetSizeParameter(global, nextarg, "rate", &value);
992 if(err)
993 break;
994 config->recvpersecond = value;
995 config->sendpersecond = value;
996 }
997 break;
998 case 'I': /* --rate (request rate) */
999 {
1000 /* support a few different suffixes, extract the suffix first, then
1001 get the number and convert to per hour.
1002 /s == per second
1003 /m == per minute
1004 /h == per hour (default)
1005 /d == per day (24 hours)
1006 */
1007 char *div = strchr(nextarg, '/');
1008 char number[26];
1009 long denominator;
1010 long numerator = 60*60*1000; /* default per hour */
1011 size_t numlen = div ? (size_t)(div - nextarg) : strlen(nextarg);
1012 if(numlen > sizeof(number)-1) {
1013 err = PARAM_NUMBER_TOO_LARGE;
1014 break;
1015 }
1016 strncpy(number, nextarg, numlen);
1017 number[numlen] = 0;
1018 err = str2unum(&denominator, number);
1019 if(err)
1020 break;
1021
1022 if(denominator < 1) {
1023 err = PARAM_BAD_USE;
1024 break;
1025 }
1026 if(div) {
1027 char unit = div[1];
1028 switch(unit) {
1029 case 's': /* per second */
1030 numerator = 1000;
1031 break;
1032 case 'm': /* per minute */
1033 numerator = 60*1000;
1034 break;
1035 case 'h': /* per hour */
1036 break;
1037 case 'd': /* per day */
1038 numerator = 24*60*60*1000;
1039 break;
1040 default:
1041 errorf(global, "unsupported --rate unit");
1042 err = PARAM_BAD_USE;
1043 break;
1044 }
1045 }
1046 global->ms_per_transfer = numerator/denominator;
1047 }
1048 break;
1049
1050 case 'j': /* --compressed */
1051 if(toggle && !(feature_libz || feature_brotli || feature_zstd)) {
1052 err = PARAM_LIBCURL_DOESNT_SUPPORT;
1053 break;
1054 }
1055 config->encoding = toggle;
1056 break;
1057
1058 case 'J': /* --tr-encoding */
1059 config->tr_encoding = toggle;
1060 break;
1061
1062 case 'k': /* --digest */
1063 if(toggle)
1064 config->authtype |= CURLAUTH_DIGEST;
1065 else
1066 config->authtype &= ~CURLAUTH_DIGEST;
1067 break;
1068
1069 case 'l': /* --negotiate */
1070 if(!toggle)
1071 config->authtype &= ~CURLAUTH_NEGOTIATE;
1072 else if(feature_spnego)
1073 config->authtype |= CURLAUTH_NEGOTIATE;
1074 else {
1075 err = PARAM_LIBCURL_DOESNT_SUPPORT;
1076 break;
1077 }
1078 break;
1079
1080 case 'm': /* --ntlm */
1081 if(!toggle)
1082 config->authtype &= ~CURLAUTH_NTLM;
1083 else if(feature_ntlm)
1084 config->authtype |= CURLAUTH_NTLM;
1085 else {
1086 err = PARAM_LIBCURL_DOESNT_SUPPORT;
1087 break;
1088 }
1089 break;
1090
1091 case 'M': /* --ntlm-wb */
1092 if(!toggle)
1093 config->authtype &= ~CURLAUTH_NTLM_WB;
1094 else if(feature_ntlm_wb)
1095 config->authtype |= CURLAUTH_NTLM_WB;
1096 else {
1097 err = PARAM_LIBCURL_DOESNT_SUPPORT;
1098 break;
1099 }
1100 break;
1101
1102 case 'n': /* --basic for completeness */
1103 if(toggle)
1104 config->authtype |= CURLAUTH_BASIC;
1105 else
1106 config->authtype &= ~CURLAUTH_BASIC;
1107 break;
1108
1109 case 'o': /* --anyauth, let libcurl pick it */
1110 if(toggle)
1111 config->authtype = CURLAUTH_ANY;
1112 /* --no-anyauth simply doesn't touch it */
1113 break;
1114
1115 #ifdef USE_WATT32
1116 case 'p': /* --wdebug */
1117 dbug_init();
1118 break;
1119 #endif
1120 case 'q': /* --ftp-create-dirs */
1121 config->ftp_create_dirs = toggle;
1122 break;
1123
1124 case 'r': /* --create-dirs */
1125 config->create_dirs = toggle;
1126 break;
1127
1128 case 'R': /* --create-file-mode */
1129 err = oct2nummax(&config->create_file_mode, nextarg, 0777);
1130 break;
1131
1132 case 's': /* --max-redirs */
1133 /* specified max no of redirects (http(s)), this accepts -1 as a
1134 special condition */
1135 err = str2num(&config->maxredirs, nextarg);
1136 if(err)
1137 break;
1138 if(config->maxredirs < -1)
1139 err = PARAM_BAD_NUMERIC;
1140 break;
1141
1142 case 'S': /* ipfs gateway url */
1143 GetStr(&config->ipfs_gateway, nextarg);
1144 break;
1145
1146 case 't': /* --proxy-ntlm */
1147 if(!feature_ntlm) {
1148 err = PARAM_LIBCURL_DOESNT_SUPPORT;
1149 break;
1150 }
1151 config->proxyntlm = toggle;
1152 break;
1153
1154 case 'u': /* --crlf */
1155 /* LF -> CRLF conversion? */
1156 config->crlf = toggle;
1157 break;
1158
1159 case 'V': /* --aws-sigv4 */
1160 config->authtype |= CURLAUTH_AWS_SIGV4;
1161 GetStr(&config->aws_sigv4, nextarg);
1162 break;
1163
1164 case 'v': /* --stderr */
1165 tool_set_stderr_file(global, nextarg);
1166 break;
1167 case 'w': /* --interface */
1168 /* interface */
1169 GetStr(&config->iface, nextarg);
1170 break;
1171 case 'x': /* --krb */
1172 /* kerberos level string */
1173 if(!feature_spnego) {
1174 err = PARAM_LIBCURL_DOESNT_SUPPORT;
1175 break;
1176 }
1177 GetStr(&config->krblevel, nextarg);
1178 break;
1179 case 'X': /* --haproxy-protocol */
1180 config->haproxy_protocol = toggle;
1181 break;
1182 case 'P': /* --haproxy-clientip */
1183 GetStr(&config->haproxy_clientip, nextarg);
1184 break;
1185 case 'y': /* --max-filesize */
1186 {
1187 curl_off_t value;
1188 err =
1189 GetSizeParameter(global, nextarg, "max-filesize", &value);
1190 if(err)
1191 break;
1192 config->max_filesize = value;
1193 }
1194 break;
1195 case 'z': /* --disable-eprt */
1196 config->disable_eprt = toggle;
1197 break;
1198 case 'Z': /* --eprt */
1199 config->disable_eprt = (!toggle)?TRUE:FALSE;
1200 break;
1201 case '~': /* --xattr */
1202 config->xattr = toggle;
1203 break;
1204 case '@': /* the URL! */
1205 {
1206 struct getout *url;
1207
1208 if(!config->url_get)
1209 config->url_get = config->url_list;
1210
1211 if(config->url_get) {
1212 /* there's a node here, if it already is filled-in continue to find
1213 an "empty" node */
1214 while(config->url_get && (config->url_get->flags & GETOUT_URL))
1215 config->url_get = config->url_get->next;
1216 }
1217
1218 /* now there might or might not be an available node to fill in! */
1219
1220 if(config->url_get)
1221 /* existing node */
1222 url = config->url_get;
1223 else
1224 /* there was no free node, create one! */
1225 config->url_get = url = new_getout(config);
1226
1227 if(!url) {
1228 err = PARAM_NO_MEM;
1229 break;
1230 }
1231
1232 /* fill in the URL */
1233 GetStr(&url->url, nextarg);
1234 url->flags |= GETOUT_URL;
1235 }
1236 }
1237 break;
1238 case '$': /* more options without a short option */
1239 switch(subletter) {
1240 case 'a': /* --ssl */
1241 if(toggle && !feature_ssl) {
1242 err = PARAM_LIBCURL_DOESNT_SUPPORT;
1243 break;
1244 }
1245 config->ftp_ssl = toggle;
1246 if(config->ftp_ssl)
1247 warnf(global,
1248 "--ssl is an insecure option, consider --ssl-reqd instead");
1249 break;
1250 case 'b': /* --ftp-pasv */
1251 Curl_safefree(config->ftpport);
1252 break;
1253 case 'c': /* --socks5 specifies a socks5 proxy to use, and resolves
1254 the name locally and passes on the resolved address */
1255 GetStr(&config->proxy, nextarg);
1256 config->proxyver = CURLPROXY_SOCKS5;
1257 break;
1258 case 't': /* --socks4 specifies a socks4 proxy to use */
1259 GetStr(&config->proxy, nextarg);
1260 config->proxyver = CURLPROXY_SOCKS4;
1261 break;
1262 case 'T': /* --socks4a specifies a socks4a proxy to use */
1263 GetStr(&config->proxy, nextarg);
1264 config->proxyver = CURLPROXY_SOCKS4A;
1265 break;
1266 case '2': /* --socks5-hostname specifies a socks5 proxy and enables name
1267 resolving with the proxy */
1268 GetStr(&config->proxy, nextarg);
1269 config->proxyver = CURLPROXY_SOCKS5_HOSTNAME;
1270 break;
1271 case 'd': /* --tcp-nodelay option */
1272 config->tcp_nodelay = toggle;
1273 break;
1274 case 'e': /* --proxy-digest */
1275 config->proxydigest = toggle;
1276 break;
1277 case 'f': /* --proxy-basic */
1278 config->proxybasic = toggle;
1279 break;
1280 case 'g': /* --retry */
1281 err = str2unum(&config->req_retry, nextarg);
1282 break;
1283 case 'V': /* --retry-connrefused */
1284 config->retry_connrefused = toggle;
1285 break;
1286 case 'h': /* --retry-delay */
1287 err = str2unummax(&config->retry_delay, nextarg, LONG_MAX/1000);
1288 break;
1289 case 'i': /* --retry-max-time */
1290 err = str2unummax(&config->retry_maxtime, nextarg, LONG_MAX/1000);
1291 break;
1292 case '!': /* --retry-all-errors */
1293 config->retry_all_errors = toggle;
1294 break;
1295
1296 case 'k': /* --proxy-negotiate */
1297 if(!feature_spnego) {
1298 err = PARAM_LIBCURL_DOESNT_SUPPORT;
1299 break;
1300 }
1301 config->proxynegotiate = toggle;
1302 break;
1303
1304 case 'l': /* --form-escape */
1305 config->mime_options &= ~CURLMIMEOPT_FORMESCAPE;
1306 if(toggle)
1307 config->mime_options |= CURLMIMEOPT_FORMESCAPE;
1308 break;
1309
1310 case 'm': /* --ftp-account */
1311 GetStr(&config->ftp_account, nextarg);
1312 break;
1313 case 'n': /* --proxy-anyauth */
1314 config->proxyanyauth = toggle;
1315 break;
1316 case 'o': /* --trace-time */
1317 global->tracetime = toggle;
1318 break;
1319 case 'p': /* --ignore-content-length */
1320 config->ignorecl = toggle;
1321 break;
1322 case 'q': /* --ftp-skip-pasv-ip */
1323 config->ftp_skip_ip = toggle;
1324 break;
1325 case 'r': /* --ftp-method (undocumented at this point) */
1326 config->ftp_filemethod = ftpfilemethod(config, nextarg);
1327 break;
1328 case 's': { /* --local-port */
1329 /* 16bit base 10 is 5 digits, but we allow 6 so that this catches
1330 overflows, not just truncates */
1331 char lrange[7]="";
1332 char *p = nextarg;
1333 while(ISDIGIT(*p))
1334 p++;
1335 if(*p) {
1336 /* if there's anything more than a plain decimal number */
1337 rc = sscanf(p, " - %6s", lrange);
1338 *p = 0; /* null-terminate to make str2unum() work below */
1339 }
1340 else
1341 rc = 0;
1342
1343 err = str2unum(&config->localport, nextarg);
1344 if(err || (config->localport > 65535)) {
1345 err = PARAM_BAD_USE;
1346 break;
1347 }
1348 if(!rc)
1349 config->localportrange = 1; /* default number of ports to try */
1350 else {
1351 err = str2unum(&config->localportrange, lrange);
1352 if(err || (config->localportrange > 65535))
1353 err = PARAM_BAD_USE;
1354 else {
1355 config->localportrange -= (config->localport-1);
1356 if(config->localportrange < 1)
1357 err = PARAM_BAD_USE;
1358 }
1359 }
1360 break;
1361 }
1362 case 'u': /* --ftp-alternative-to-user */
1363 GetStr(&config->ftp_alternative_to_user, nextarg);
1364 break;
1365 case 'v': /* --ssl-reqd */
1366 if(toggle && !feature_ssl) {
1367 err = PARAM_LIBCURL_DOESNT_SUPPORT;
1368 break;
1369 }
1370 config->ftp_ssl_reqd = toggle;
1371 break;
1372 case 'w': /* --no-sessionid */
1373 config->disable_sessionid = (!toggle)?TRUE:FALSE;
1374 break;
1375 case 'x': /* --ftp-ssl-control */
1376 if(toggle && !feature_ssl) {
1377 err = PARAM_LIBCURL_DOESNT_SUPPORT;
1378 break;
1379 }
1380 config->ftp_ssl_control = toggle;
1381 break;
1382 case 'y': /* --ftp-ssl-ccc */
1383 config->ftp_ssl_ccc = toggle;
1384 if(!config->ftp_ssl_ccc_mode)
1385 config->ftp_ssl_ccc_mode = CURLFTPSSL_CCC_PASSIVE;
1386 break;
1387 case 'j': /* --ftp-ssl-ccc-mode */
1388 config->ftp_ssl_ccc = TRUE;
1389 config->ftp_ssl_ccc_mode = ftpcccmethod(config, nextarg);
1390 break;
1391 case 'z': /* --libcurl */
1392 #ifdef CURL_DISABLE_LIBCURL_OPTION
1393 warnf(global,
1394 "--libcurl option was disabled at build-time");
1395 err = PARAM_OPTION_UNKNOWN;
1396 break;
1397 #else
1398 GetStr(&global->libcurl, nextarg);
1399 break;
1400 #endif
1401 case '#': /* --raw */
1402 config->raw = toggle;
1403 break;
1404 case '0': /* --post301 */
1405 config->post301 = toggle;
1406 break;
1407 case '1': /* --no-keepalive */
1408 config->nokeepalive = (!toggle)?TRUE:FALSE;
1409 break;
1410 case '3': /* --keepalive-time */
1411 err = str2unum(&config->alivetime, nextarg);
1412 break;
1413 case '4': /* --post302 */
1414 config->post302 = toggle;
1415 break;
1416 case 'I': /* --post303 */
1417 config->post303 = toggle;
1418 break;
1419 case '5': /* --noproxy */
1420 /* This specifies the noproxy list */
1421 GetStr(&config->noproxy, nextarg);
1422 break;
1423 case '7': /* --socks5-gssapi-nec */
1424 config->socks5_gssapi_nec = toggle;
1425 break;
1426 case '8': /* --proxy1.0 */
1427 /* http 1.0 proxy */
1428 GetStr(&config->proxy, nextarg);
1429 config->proxyver = CURLPROXY_HTTP_1_0;
1430 break;
1431 case '9': /* --tftp-blksize */
1432 err = str2unum(&config->tftp_blksize, nextarg);
1433 break;
1434 case 'A': /* --mail-from */
1435 GetStr(&config->mail_from, nextarg);
1436 break;
1437 case 'B': /* --mail-rcpt */
1438 /* append receiver to a list */
1439 err = add2list(&config->mail_rcpt, nextarg);
1440 break;
1441 case 'C': /* --ftp-pret */
1442 config->ftp_pret = toggle;
1443 break;
1444 case 'D': /* --proto */
1445 config->proto_present = TRUE;
1446 err = proto2num(config, built_in_protos, &config->proto_str, nextarg);
1447 break;
1448 case 'E': /* --proto-redir */
1449 config->proto_redir_present = TRUE;
1450 if(proto2num(config, redir_protos, &config->proto_redir_str,
1451 nextarg)) {
1452 err = PARAM_BAD_USE;
1453 break;
1454 }
1455 break;
1456 case 'F': /* --resolve */
1457 err = add2list(&config->resolve, nextarg);
1458 break;
1459 case 'G': /* --delegation LEVEL */
1460 config->gssapi_delegation = delegation(config, nextarg);
1461 break;
1462 case 'H': /* --mail-auth */
1463 GetStr(&config->mail_auth, nextarg);
1464 break;
1465 case 'J': /* --metalink */
1466 errorf(global, "--metalink is disabled");
1467 err = PARAM_BAD_USE;
1468 break;
1469 case '6': /* --sasl-authzid */
1470 GetStr(&config->sasl_authzid, nextarg);
1471 break;
1472 case 'K': /* --sasl-ir */
1473 config->sasl_ir = toggle;
1474 break;
1475 case 'L': /* --test-event */
1476 #ifdef CURLDEBUG
1477 global->test_event_based = toggle;
1478 #else
1479 warnf(global, "--test-event is ignored unless a debug build");
1480 #endif
1481 break;
1482 case 'M': /* --unix-socket */
1483 config->abstract_unix_socket = FALSE;
1484 GetStr(&config->unix_socket_path, nextarg);
1485 break;
1486 case 'N': /* --path-as-is */
1487 config->path_as_is = toggle;
1488 break;
1489 case 'O': /* --proxy-service-name */
1490 GetStr(&config->proxy_service_name, nextarg);
1491 break;
1492 case 'P': /* --service-name */
1493 GetStr(&config->service_name, nextarg);
1494 break;
1495 case 'Q': /* --proto-default */
1496 GetStr(&config->proto_default, nextarg);
1497 err = check_protocol(config->proto_default);
1498 break;
1499 case 'R': /* --expect100-timeout */
1500 err = secs2ms(&config->expect100timeout_ms, nextarg);
1501 break;
1502 case 'S': /* --tftp-no-options */
1503 config->tftp_no_options = toggle;
1504 break;
1505 case 'U': /* --connect-to */
1506 err = add2list(&config->connect_to, nextarg);
1507 break;
1508 case 'W': /* --abstract-unix-socket */
1509 config->abstract_unix_socket = TRUE;
1510 GetStr(&config->unix_socket_path, nextarg);
1511 break;
1512 case 'X': /* --tls-max */
1513 err = str2tls_max(&config->ssl_version_max, nextarg);
1514 break;
1515 case 'Y': /* --suppress-connect-headers */
1516 config->suppress_connect_headers = toggle;
1517 break;
1518 case 'Z': /* --compressed-ssh */
1519 config->ssh_compression = toggle;
1520 break;
1521 case '~': /* --happy-eyeballs-timeout-ms */
1522 err = str2unum(&config->happy_eyeballs_timeout_ms, nextarg);
1523 /* 0 is a valid value for this timeout */
1524 break;
1525 case '%': /* --trace-ids */
1526 global->traceids = toggle;
1527 break;
1528 case '&': /* --trace-config */
1529 if(set_trace_config(global, nextarg)) {
1530 err = PARAM_NO_MEM;
1531 }
1532 break;
1533 }
1534 break;
1535 case '#':
1536 switch(subletter) {
1537 case 'm': /* --progress-meter */
1538 global->noprogress = !toggle;
1539 break;
1540 default: /* --progress-bar */
1541 global->progressmode =
1542 toggle ? CURL_PROGRESS_BAR : CURL_PROGRESS_STATS;
1543 break;
1544 }
1545 break;
1546 case ':':
1547 switch(subletter) {
1548 case 'a': /* --variable */
1549 err = setvariable(global, nextarg);
1550 break;
1551 default: /* --next */
1552 err = PARAM_NEXT_OPERATION;
1553 break;
1554 }
1555 break;
1556 case '0': /* --http* options */
1557 switch(subletter) {
1558 case '\0':
1559 /* HTTP version 1.0 */
1560 sethttpver(global, config, CURL_HTTP_VERSION_1_0);
1561 break;
1562 case '1':
1563 /* HTTP version 1.1 */
1564 sethttpver(global, config, CURL_HTTP_VERSION_1_1);
1565 break;
1566 case '2':
1567 /* HTTP version 2.0 */
1568 if(!feature_http2)
1569 return PARAM_LIBCURL_DOESNT_SUPPORT;
1570 sethttpver(global, config, CURL_HTTP_VERSION_2_0);
1571 break;
1572 case '3': /* --http2-prior-knowledge */
1573 /* HTTP version 2.0 over clean TCP */
1574 if(!feature_http2)
1575 return PARAM_LIBCURL_DOESNT_SUPPORT;
1576 sethttpver(global, config, CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE);
1577 break;
1578 case '4': /* --http3 */
1579 /* Try HTTP/3, allow fallback */
1580 if(!feature_http3) {
1581 err = PARAM_LIBCURL_DOESNT_SUPPORT;
1582 break;
1583 }
1584 sethttpver(global, config, CURL_HTTP_VERSION_3);
1585 break;
1586 case '5': /* --http3-only */
1587 /* Try HTTP/3 without fallback */
1588 if(!feature_http3) {
1589 err = PARAM_LIBCURL_DOESNT_SUPPORT;
1590 break;
1591 }
1592 sethttpver(global, config, CURL_HTTP_VERSION_3ONLY);
1593 break;
1594 case '9':
1595 /* Allow HTTP/0.9 responses! */
1596 config->http09_allowed = toggle;
1597 break;
1598 case 'a':
1599 /* --proxy-http2 */
1600 if(!feature_httpsproxy || !feature_http2)
1601 return PARAM_LIBCURL_DOESNT_SUPPORT;
1602 config->proxyver = CURLPROXY_HTTPS2;
1603 break;
1604 }
1605 break;
1606 case '1': /* --tlsv1* options */
1607 switch(subletter) {
1608 case '\0':
1609 /* TLS version 1.x */
1610 config->ssl_version = CURL_SSLVERSION_TLSv1;
1611 break;
1612 case '0':
1613 /* TLS version 1.0 */
1614 config->ssl_version = CURL_SSLVERSION_TLSv1_0;
1615 break;
1616 case '1':
1617 /* TLS version 1.1 */
1618 config->ssl_version = CURL_SSLVERSION_TLSv1_1;
1619 break;
1620 case '2':
1621 /* TLS version 1.2 */
1622 config->ssl_version = CURL_SSLVERSION_TLSv1_2;
1623 break;
1624 case '3':
1625 /* TLS version 1.3 */
1626 config->ssl_version = CURL_SSLVERSION_TLSv1_3;
1627 break;
1628 case 'A': /* --tls13-ciphers */
1629 GetStr(&config->cipher13_list, nextarg);
1630 break;
1631 case 'B': /* --proxy-tls13-ciphers */
1632 GetStr(&config->proxy_cipher13_list, nextarg);
1633 break;
1634 }
1635 break;
1636 case '2':
1637 /* SSL version 2 */
1638 warnf(global, "Ignores instruction to use SSLv2");
1639 break;
1640 case '3':
1641 /* SSL version 3 */
1642 warnf(global, "Ignores instruction to use SSLv3");
1643 break;
1644 case '4':
1645 /* IPv4 */
1646 config->ip_version = CURL_IPRESOLVE_V4;
1647 break;
1648 case '6':
1649 /* IPv6 */
1650 config->ip_version = CURL_IPRESOLVE_V6;
1651 break;
1652 case 'a':
1653 /* This makes the FTP sessions use APPE instead of STOR */
1654 config->ftp_append = toggle;
1655 break;
1656 case 'A':
1657 /* This specifies the User-Agent name */
1658 GetStr(&config->useragent, nextarg);
1659 break;
1660 case 'b':
1661 switch(subletter) {
1662 case 'a': /* --alt-svc */
1663 if(!feature_altsvc)
1664 err = PARAM_LIBCURL_DOESNT_SUPPORT;
1665 else
1666 GetStr(&config->altsvc, nextarg);
1667 break;
1668 case 'b': /* --hsts */
1669 if(!feature_hsts)
1670 err = PARAM_LIBCURL_DOESNT_SUPPORT;
1671 else
1672 GetStr(&config->hsts, nextarg);
1673 break;
1674 default: /* --cookie string coming up: */
1675 if(nextarg[0] == '@') {
1676 nextarg++;
1677 }
1678 else if(strchr(nextarg, '=')) {
1679 /* A cookie string must have a =-letter */
1680 err = add2list(&config->cookies, nextarg);
1681 break;
1682 }
1683 /* We have a cookie file to read from! */
1684 err = add2list(&config->cookiefiles, nextarg);
1685 }
1686 break;
1687 case 'B':
1688 /* use ASCII/text when transferring */
1689 config->use_ascii = toggle;
1690 break;
1691 case 'c':
1692 /* get the file name to dump all cookies in */
1693 GetStr(&config->cookiejar, nextarg);
1694 break;
1695 case 'C':
1696 /* This makes us continue an ftp transfer at given position */
1697 if(strcmp(nextarg, "-")) {
1698 err = str2offset(&config->resume_from, nextarg);
1699 if(err)
1700 break;
1701 config->resume_from_current = FALSE;
1702 }
1703 else {
1704 config->resume_from_current = TRUE;
1705 config->resume_from = 0;
1706 }
1707 config->use_resume = TRUE;
1708 break;
1709 case 'd':
1710 /* postfield data */
1711 {
1712 char *postdata = NULL;
1713 FILE *file;
1714 size_t size = 0;
1715 bool raw_mode = (subletter == 'r');
1716
1717 if(subletter == 'g') { /* --url-query */
1718 #define MAX_QUERY_LEN 100000 /* larger is not likely to ever work */
1719 char *query;
1720 struct curlx_dynbuf dyn;
1721 curlx_dyn_init(&dyn, MAX_QUERY_LEN);
1722
1723 if(*nextarg == '+') {
1724 /* use without encoding */
1725 query = strdup(&nextarg[1]);
1726 if(!query) {
1727 err = PARAM_NO_MEM;
1728 break;
1729 }
1730 }
1731 else {
1732 err = data_urlencode(global, nextarg, &query, &size);
1733 if(err)
1734 break;
1735 }
1736
1737 if(config->query) {
1738 CURLcode result =
1739 curlx_dyn_addf(&dyn, "%s&%s", config->query, query);
1740 free(query);
1741 if(result) {
1742 err = PARAM_NO_MEM;
1743 break;
1744 }
1745 free(config->query);
1746 config->query = curlx_dyn_ptr(&dyn);
1747 }
1748 else
1749 config->query = query;
1750
1751 break; /* this is not a POST argument at all */
1752 }
1753 else if(subletter == 'e') { /* --data-urlencode */
1754 err = data_urlencode(global, nextarg, &postdata, &size);
1755 if(err)
1756 break;
1757 }
1758 else if('@' == *nextarg && !raw_mode) {
1759 /* the data begins with a '@' letter, it means that a file name
1760 or - (stdin) follows */
1761 nextarg++; /* pass the @ */
1762
1763 if(!strcmp("-", nextarg)) {
1764 file = stdin;
1765 if(subletter == 'b') /* forced data-binary */
1766 set_binmode(stdin);
1767 }
1768 else {
1769 file = fopen(nextarg, "rb");
1770 if(!file) {
1771 errorf(global, "Failed to open %s", nextarg);
1772 err = PARAM_READ_ERROR;
1773 break;
1774 }
1775 }
1776
1777 if((subletter == 'b') || /* --data-binary */
1778 (subletter == 'f') /* --json */)
1779 /* forced binary */
1780 err = file2memory(&postdata, &size, file);
1781 else {
1782 err = file2string(&postdata, file);
1783 if(postdata)
1784 size = strlen(postdata);
1785 }
1786
1787 if(file && (file != stdin))
1788 fclose(file);
1789 if(err)
1790 break;
1791
1792 if(!postdata) {
1793 /* no data from the file, point to a zero byte string to make this
1794 get sent as a POST anyway */
1795 postdata = strdup("");
1796 if(!postdata) {
1797 err = PARAM_NO_MEM;
1798 break;
1799 }
1800 }
1801 }
1802 else {
1803 GetStr(&postdata, nextarg);
1804 if(postdata)
1805 size = strlen(postdata);
1806 }
1807 if(subletter == 'f')
1808 config->jsoned = TRUE;
1809
1810 if(config->postfields) {
1811 /* we already have a string, we append this one with a separating
1812 &-letter */
1813 char *oldpost = config->postfields;
1814 curl_off_t oldlen = config->postfieldsize;
1815 curl_off_t newlen = oldlen + curlx_uztoso(size) + 2;
1816 config->postfields = malloc((size_t)newlen);
1817 if(!config->postfields) {
1818 Curl_safefree(oldpost);
1819 Curl_safefree(postdata);
1820 err = PARAM_NO_MEM;
1821 break;
1822 }
1823 memcpy(config->postfields, oldpost, (size_t)oldlen);
1824 if(subletter != 'f') {
1825 /* skip this treatment for --json */
1826 /* use byte value 0x26 for '&' to accommodate non-ASCII platforms */
1827 config->postfields[oldlen] = '\x26';
1828 memcpy(&config->postfields[oldlen + 1], postdata, size);
1829 config->postfields[oldlen + 1 + size] = '\0';
1830 config->postfieldsize += size + 1;
1831 }
1832 else {
1833 memcpy(&config->postfields[oldlen], postdata, size);
1834 config->postfields[oldlen + size] = '\0';
1835 config->postfieldsize += size;
1836 }
1837 Curl_safefree(oldpost);
1838 Curl_safefree(postdata);
1839 }
1840 else {
1841 config->postfields = postdata;
1842 config->postfieldsize = curlx_uztoso(size);
1843 }
1844 }
1845 /*
1846 We can't set the request type here, as this data might be used in
1847 a simple GET if -G is used. Already or soon.
1848
1849 if(SetHTTPrequest(HTTPREQ_SIMPLEPOST, &config->httpreq)) {
1850 Curl_safefree(postdata);
1851 return PARAM_BAD_USE;
1852 }
1853 */
1854 break;
1855 case 'D':
1856 /* dump-header to given file name */
1857 GetStr(&config->headerfile, nextarg);
1858 break;
1859 case 'e':
1860 {
1861 char *ptr = strstr(nextarg, ";auto");
1862 if(ptr) {
1863 /* Automatic referer requested, this may be combined with a
1864 set initial one */
1865 config->autoreferer = TRUE;
1866 *ptr = 0; /* null-terminate here */
1867 }
1868 else
1869 config->autoreferer = FALSE;
1870 ptr = *nextarg ? nextarg : NULL;
1871 GetStr(&config->referer, ptr);
1872 }
1873 break;
1874 case 'E':
1875 switch(subletter) {
1876 case '\0': /* certificate file */
1877 cleanarg(clearthis);
1878 GetFileAndPassword(nextarg, &config->cert, &config->key_passwd);
1879 break;
1880 case 'a': /* --cacert CA info PEM file */
1881 GetStr(&config->cacert, nextarg);
1882 break;
1883 case 'G': /* --ca-native */
1884 config->native_ca_store = toggle;
1885 break;
1886 case 'H': /* --proxy-ca-native */
1887 config->proxy_native_ca_store = toggle;
1888 break;
1889 case 'b': /* cert file type */
1890 GetStr(&config->cert_type, nextarg);
1891 break;
1892 case 'c': /* private key file */
1893 GetStr(&config->key, nextarg);
1894 break;
1895 case 'd': /* private key file type */
1896 GetStr(&config->key_type, nextarg);
1897 break;
1898 case 'e': /* private key passphrase */
1899 GetStr(&config->key_passwd, nextarg);
1900 cleanarg(clearthis);
1901 break;
1902 case 'f': /* crypto engine */
1903 GetStr(&config->engine, nextarg);
1904 if(config->engine && curl_strequal(config->engine, "list")) {
1905 err = PARAM_ENGINES_REQUESTED;
1906 break;
1907 }
1908 break;
1909 case 'g': /* CA cert directory */
1910 GetStr(&config->capath, nextarg);
1911 break;
1912 case 'h': /* --pubkey public key file */
1913 GetStr(&config->pubkey, nextarg);
1914 break;
1915 case 'i': /* --hostpubmd5 md5 of the host public key */
1916 GetStr(&config->hostpubmd5, nextarg);
1917 if(!config->hostpubmd5 || strlen(config->hostpubmd5) != 32) {
1918 err = PARAM_BAD_USE;
1919 break;
1920 }
1921 break;
1922 case 'F': /* --hostpubsha256 sha256 of the host public key */
1923 GetStr(&config->hostpubsha256, nextarg);
1924 break;
1925 case 'j': /* CRL file */
1926 GetStr(&config->crlfile, nextarg);
1927 break;
1928 case 'k': /* TLS username */
1929 if(!feature_tls_srp) {
1930 cleanarg(clearthis);
1931 err = PARAM_LIBCURL_DOESNT_SUPPORT;
1932 break;
1933 }
1934 GetStr(&config->tls_username, nextarg);
1935 cleanarg(clearthis);
1936 break;
1937 case 'l': /* TLS password */
1938 if(!feature_tls_srp) {
1939 cleanarg(clearthis);
1940 err = PARAM_LIBCURL_DOESNT_SUPPORT;
1941 break;
1942 }
1943 GetStr(&config->tls_password, nextarg);
1944 cleanarg(clearthis);
1945 break;
1946 case 'm': /* TLS authentication type */
1947 if(!feature_tls_srp) {
1948 err = PARAM_LIBCURL_DOESNT_SUPPORT;
1949 break;
1950 }
1951 GetStr(&config->tls_authtype, nextarg);
1952 if(!curl_strequal(config->tls_authtype, "SRP")) {
1953 err = PARAM_LIBCURL_DOESNT_SUPPORT; /* only support TLS-SRP */
1954 break;
1955 }
1956 break;
1957 case 'n': /* no empty SSL fragments, --ssl-allow-beast */
1958 if(feature_ssl)
1959 config->ssl_allow_beast = toggle;
1960 break;
1961
1962 case 'o': /* --ssl-auto-client-cert */
1963 if(feature_ssl)
1964 config->ssl_auto_client_cert = toggle;
1965 break;
1966
1967 case 'O': /* --proxy-ssl-auto-client-cert */
1968 if(feature_ssl)
1969 config->proxy_ssl_auto_client_cert = toggle;
1970 break;
1971
1972 case 'p': /* Pinned public key DER file */
1973 GetStr(&config->pinnedpubkey, nextarg);
1974 break;
1975
1976 case 'P': /* proxy pinned public key */
1977 GetStr(&config->proxy_pinnedpubkey, nextarg);
1978 break;
1979
1980 case 'q': /* --cert-status */
1981 config->verifystatus = TRUE;
1982 break;
1983
1984 case 'Q': /* --doh-cert-status */
1985 config->doh_verifystatus = TRUE;
1986 break;
1987
1988 case 'r': /* --false-start */
1989 config->falsestart = TRUE;
1990 break;
1991
1992 case 's': /* --ssl-no-revoke */
1993 if(feature_ssl)
1994 config->ssl_no_revoke = TRUE;
1995 break;
1996
1997 case 'S': /* --ssl-revoke-best-effort */
1998 if(feature_ssl)
1999 config->ssl_revoke_best_effort = TRUE;
2000 break;
2001
2002 case 't': /* --tcp-fastopen */
2003 config->tcp_fastopen = TRUE;
2004 break;
2005
2006 case 'u': /* TLS username for proxy */
2007 cleanarg(clearthis);
2008 if(!feature_tls_srp) {
2009 err = PARAM_LIBCURL_DOESNT_SUPPORT;
2010 break;
2011 }
2012 GetStr(&config->proxy_tls_username, nextarg);
2013 break;
2014
2015 case 'v': /* TLS password for proxy */
2016 cleanarg(clearthis);
2017 if(!feature_tls_srp) {
2018 err = PARAM_LIBCURL_DOESNT_SUPPORT;
2019 break;
2020 }
2021 GetStr(&config->proxy_tls_password, nextarg);
2022 break;
2023
2024 case 'w': /* TLS authentication type for proxy */
2025 if(!feature_tls_srp) {
2026 err = PARAM_LIBCURL_DOESNT_SUPPORT;
2027 break;
2028 }
2029 GetStr(&config->proxy_tls_authtype, nextarg);
2030 if(!curl_strequal(config->proxy_tls_authtype, "SRP")) {
2031 err = PARAM_LIBCURL_DOESNT_SUPPORT; /* only support TLS-SRP */
2032 break;
2033 }
2034 break;
2035
2036 case 'x': /* certificate file for proxy */
2037 cleanarg(clearthis);
2038 GetFileAndPassword(nextarg, &config->proxy_cert,
2039 &config->proxy_key_passwd);
2040 break;
2041
2042 case 'y': /* cert file type for proxy */
2043 GetStr(&config->proxy_cert_type, nextarg);
2044 break;
2045
2046 case 'z': /* private key file for proxy */
2047 GetStr(&config->proxy_key, nextarg);
2048 break;
2049
2050 case '0': /* private key file type for proxy */
2051 GetStr(&config->proxy_key_type, nextarg);
2052 break;
2053
2054 case '1': /* private key passphrase for proxy */
2055 GetStr(&config->proxy_key_passwd, nextarg);
2056 cleanarg(clearthis);
2057 break;
2058
2059 case '2': /* ciphers for proxy */
2060 GetStr(&config->proxy_cipher_list, nextarg);
2061 break;
2062
2063 case '3': /* CRL file for proxy */
2064 GetStr(&config->proxy_crlfile, nextarg);
2065 break;
2066
2067 case '4': /* no empty SSL fragments for proxy */
2068 if(feature_ssl)
2069 config->proxy_ssl_allow_beast = toggle;
2070 break;
2071
2072 case '5': /* --login-options */
2073 GetStr(&config->login_options, nextarg);
2074 break;
2075
2076 case '6': /* CA info PEM file for proxy */
2077 GetStr(&config->proxy_cacert, nextarg);
2078 break;
2079
2080 case '7': /* CA cert directory for proxy */
2081 GetStr(&config->proxy_capath, nextarg);
2082 break;
2083
2084 case '8': /* allow insecure SSL connects for proxy */
2085 config->proxy_insecure_ok = toggle;
2086 break;
2087
2088 case '9': /* --proxy-tlsv1 */
2089 /* TLS version 1 for proxy */
2090 config->proxy_ssl_version = CURL_SSLVERSION_TLSv1;
2091 break;
2092
2093 case 'A':
2094 /* --socks5-basic */
2095 if(toggle)
2096 config->socks5_auth |= CURLAUTH_BASIC;
2097 else
2098 config->socks5_auth &= ~CURLAUTH_BASIC;
2099 break;
2100
2101 case 'B':
2102 /* --socks5-gssapi */
2103 if(toggle)
2104 config->socks5_auth |= CURLAUTH_GSSAPI;
2105 else
2106 config->socks5_auth &= ~CURLAUTH_GSSAPI;
2107 break;
2108
2109 case 'C':
2110 GetStr(&config->etag_save_file, nextarg);
2111 break;
2112
2113 case 'D':
2114 GetStr(&config->etag_compare_file, nextarg);
2115 break;
2116
2117 case 'E':
2118 GetStr(&config->ssl_ec_curves, nextarg);
2119 break;
2120
2121 default: /* unknown flag */
2122 err = PARAM_OPTION_UNKNOWN;
2123 break;
2124 }
2125 break;
2126 case 'f':
2127 switch(subletter) {
2128 case 'a': /* --fail-early */
2129 global->fail_early = toggle;
2130 break;
2131 case 'b': /* --styled-output */
2132 global->styled_output = toggle;
2133 break;
2134 case 'c': /* --mail-rcpt-allowfails */
2135 config->mail_rcpt_allowfails = toggle;
2136 break;
2137 case 'd': /* --fail-with-body */
2138 config->failwithbody = toggle;
2139 break;
2140 case 'e': /* --remove-on-error */
2141 config->rm_partial = toggle;
2142 break;
2143 default: /* --fail (hard on errors) */
2144 config->failonerror = toggle;
2145 break;
2146 }
2147 if(config->failonerror && config->failwithbody) {
2148 errorf(config->global, "You must select either --fail or "
2149 "--fail-with-body, not both.");
2150 err = PARAM_BAD_USE;
2151 break;
2152 }
2153 break;
2154 case 'F':
2155 /* "form data" simulation, this is a little advanced so lets do our best
2156 to sort this out slowly and carefully */
2157 if(formparse(config,
2158 nextarg,
2159 &config->mimeroot,
2160 &config->mimecurrent,
2161 (subletter == 's')?TRUE:FALSE)) { /* 's' is literal
2162 string */
2163 err = PARAM_BAD_USE;
2164 break;
2165 }
2166 if(SetHTTPrequest(config, HTTPREQ_MIMEPOST, &config->httpreq)) {
2167 err = PARAM_BAD_USE;
2168 break;
2169 }
2170 break;
2171
2172 case 'g': /* g disables URLglobbing */
2173 config->globoff = toggle;
2174 break;
2175
2176 case 'G': /* HTTP GET */
2177 if(subletter == 'a') { /* --request-target */
2178 GetStr(&config->request_target, nextarg);
2179 }
2180 else
2181 config->use_httpget = toggle;
2182 break;
2183
2184 case 'h': /* h for help */
2185 if(toggle) {
2186 if(nextarg) {
2187 global->help_category = strdup(nextarg);
2188 if(!global->help_category) {
2189 err = PARAM_NO_MEM;
2190 break;
2191 }
2192 }
2193 err = PARAM_HELP_REQUESTED;
2194 break;
2195 }
2196 /* we now actually support --no-help too! */
2197 break;
2198 case 'H':
2199 /* A custom header to append to a list */
2200 if(nextarg[0] == '@') {
2201 /* read many headers from a file or stdin */
2202 char *string;
2203 size_t len;
2204 bool use_stdin = !strcmp(&nextarg[1], "-");
2205 FILE *file = use_stdin?stdin:fopen(&nextarg[1], FOPEN_READTEXT);
2206 if(!file) {
2207 errorf(global, "Failed to open %s", &nextarg[1]);
2208 err = PARAM_READ_ERROR;
2209 break;
2210 }
2211 else {
2212 err = file2memory(&string, &len, file);
2213 if(!err && string) {
2214 /* Allow strtok() here since this isn't used threaded */
2215 /* !checksrc! disable BANNEDFUNC 2 */
2216 char *h = strtok(string, "\r\n");
2217 while(h) {
2218 if(subletter == 'p') /* --proxy-header */
2219 err = add2list(&config->proxyheaders, h);
2220 else
2221 err = add2list(&config->headers, h);
2222 if(err)
2223 break;
2224 h = strtok(NULL, "\r\n");
2225 }
2226 free(string);
2227 }
2228 if(!use_stdin)
2229 fclose(file);
2230 if(err)
2231 break;
2232 }
2233 }
2234 else {
2235 if(subletter == 'p') /* --proxy-header */
2236 err = add2list(&config->proxyheaders, nextarg);
2237 else
2238 err = add2list(&config->headers, nextarg);
2239 }
2240 break;
2241 case 'i':
2242 config->show_headers = toggle; /* show the headers as well in the
2243 general output stream */
2244 break;
2245 case 'j':
2246 config->cookiesession = toggle;
2247 break;
2248 case 'I': /* --head */
2249 config->no_body = toggle;
2250 config->show_headers = toggle;
2251 if(SetHTTPrequest(config,
2252 (config->no_body)?HTTPREQ_HEAD:HTTPREQ_GET,
2253 &config->httpreq)) {
2254 err = PARAM_BAD_USE;
2255 break;
2256 }
2257 break;
2258 case 'J': /* --remote-header-name */
2259 config->content_disposition = toggle;
2260 break;
2261 case 'k': /* allow insecure SSL connects */
2262 if(subletter == 'd') /* --doh-insecure */
2263 config->doh_insecure_ok = toggle;
2264 else
2265 config->insecure_ok = toggle;
2266 break;
2267 case 'K': /* parse config file */
2268 if(parseconfig(nextarg, global)) {
2269 errorf(global, "cannot read config from '%s'", nextarg);
2270 err = PARAM_READ_ERROR;
2271 break;
2272 }
2273 break;
2274 case 'l':
2275 config->dirlistonly = toggle; /* only list the names of the FTP dir */
2276 break;
2277 case 'L':
2278 config->followlocation = toggle; /* Follow Location: HTTP headers */
2279 switch(subletter) {
2280 case 't':
2281 /* Continue to send authentication (user+password) when following
2282 * locations, even when hostname changed */
2283 config->unrestricted_auth = toggle;
2284 break;
2285 }
2286 break;
2287 case 'm':
2288 /* specified max time */
2289 err = secs2ms(&config->timeout_ms, nextarg);
2290 break;
2291 case 'M': /* M for manual, huge help */
2292 if(toggle) { /* --no-manual shows no manual... */
2293 #ifndef USE_MANUAL
2294 warnf(global,
2295 "built-in manual was disabled at build-time");
2296 #endif
2297 err = PARAM_MANUAL_REQUESTED;
2298 break;
2299 }
2300 break;
2301 case 'n':
2302 switch(subletter) {
2303 case 'o': /* use .netrc or URL */
2304 config->netrc_opt = toggle;
2305 break;
2306 case 'e': /* netrc-file */
2307 GetStr(&config->netrc_file, nextarg);
2308 break;
2309 default:
2310 /* pick info from .netrc, if this is used for http, curl will
2311 automatically enforce user+password with the request */
2312 config->netrc = toggle;
2313 break;
2314 }
2315 break;
2316 case 'N':
2317 /* disable the output I/O buffering. note that the option is called
2318 --buffer but is mostly used in the negative form: --no-buffer */
2319 config->nobuffer = longopt ? !toggle : TRUE;
2320 break;
2321 case 'O': /* --remote-name */
2322 if(subletter == 'a') { /* --remote-name-all */
2323 config->default_node_flags = toggle?GETOUT_USEREMOTE:0;
2324 break;
2325 }
2326 else if(subletter == 'b') { /* --output-dir */
2327 GetStr(&config->output_dir, nextarg);
2328 break;
2329 }
2330 else if(subletter == 'c') { /* --clobber / --no-clobber */
2331 config->file_clobber_mode = toggle ? CLOBBER_ALWAYS : CLOBBER_NEVER;
2332 break;
2333 }
2334 /* FALLTHROUGH */
2335 case 'o': /* --output */
2336 /* output file */
2337 {
2338 struct getout *url;
2339 if(!config->url_out)
2340 config->url_out = config->url_list;
2341 if(config->url_out) {
2342 /* there's a node here, if it already is filled-in continue to find
2343 an "empty" node */
2344 while(config->url_out && (config->url_out->flags & GETOUT_OUTFILE))
2345 config->url_out = config->url_out->next;
2346 }
2347
2348 /* now there might or might not be an available node to fill in! */
2349
2350 if(config->url_out)
2351 /* existing node */
2352 url = config->url_out;
2353 else {
2354 if(!toggle && !config->default_node_flags)
2355 break;
2356 /* there was no free node, create one! */
2357 config->url_out = url = new_getout(config);
2358 }
2359
2360 if(!url) {
2361 err = PARAM_NO_MEM;
2362 break;
2363 }
2364
2365 /* fill in the outfile */
2366 if('o' == letter) {
2367 if(!*nextarg) {
2368 warnf(global, "output file name has no length");
2369 err = PARAM_BAD_USE;
2370 break;
2371 }
2372 GetStr(&url->outfile, nextarg);
2373 url->flags &= ~GETOUT_USEREMOTE; /* switch off */
2374 }
2375 else {
2376 url->outfile = NULL; /* leave it */
2377 if(toggle)
2378 url->flags |= GETOUT_USEREMOTE; /* switch on */
2379 else
2380 url->flags &= ~GETOUT_USEREMOTE; /* switch off */
2381 }
2382 url->flags |= GETOUT_OUTFILE;
2383 }
2384 break;
2385 case 'P':
2386 /* This makes the FTP sessions use PORT instead of PASV */
2387 /* use <eth0> or <192.168.10.10> style addresses. Anything except
2388 this will make us try to get the "default" address.
2389 NOTE: this is a changed behavior since the released 4.1!
2390 */
2391 GetStr(&config->ftpport, nextarg);
2392 break;
2393 case 'p':
2394 /* proxy tunnel for non-http protocols */
2395 config->proxytunnel = toggle;
2396 break;
2397
2398 case 'q': /* if used first, already taken care of, we do it like
2399 this so we don't cause an error! */
2400 break;
2401 case 'Q':
2402 /* QUOTE command to send to FTP server */
2403 switch(nextarg[0]) {
2404 case '-':
2405 /* prefixed with a dash makes it a POST TRANSFER one */
2406 nextarg++;
2407 err = add2list(&config->postquote, nextarg);
2408 break;
2409 case '+':
2410 /* prefixed with a plus makes it a just-before-transfer one */
2411 nextarg++;
2412 err = add2list(&config->prequote, nextarg);
2413 break;
2414 default:
2415 err = add2list(&config->quote, nextarg);
2416 break;
2417 }
2418 break;
2419 case 'r':
2420 /* Specifying a range WITHOUT A DASH will create an illegal HTTP range
2421 (and won't actually be range by definition). The man page previously
2422 claimed that to be a good way, why this code is added to work-around
2423 it. */
2424 if(ISDIGIT(*nextarg) && !strchr(nextarg, '-')) {
2425 char buffer[32];
2426 curl_off_t off;
2427 if(curlx_strtoofft(nextarg, NULL, 10, &off)) {
2428 warnf(global, "unsupported range point");
2429 err = PARAM_BAD_USE;
2430 break;
2431 }
2432 warnf(global,
2433 "A specified range MUST include at least one dash (-). "
2434 "Appending one for you");
2435 msnprintf(buffer, sizeof(buffer), "%" CURL_FORMAT_CURL_OFF_T "-", off);
2436 Curl_safefree(config->range);
2437 config->range = strdup(buffer);
2438 if(!config->range) {
2439 err = PARAM_NO_MEM;
2440 break;
2441 }
2442 }
2443 else {
2444 /* byte range requested */
2445 const char *tmp_range = nextarg;
2446 while(*tmp_range != '\0') {
2447 if(!ISDIGIT(*tmp_range) && *tmp_range != '-' && *tmp_range != ',') {
2448 warnf(global, "Invalid character is found in given range. "
2449 "A specified range MUST have only digits in "
2450 "\'start\'-\'stop\'. The server's response to this "
2451 "request is uncertain.");
2452 break;
2453 }
2454 tmp_range++;
2455 }
2456 GetStr(&config->range, nextarg);
2457 }
2458 break;
2459 case 'R':
2460 /* use remote file's time */
2461 config->remote_time = toggle;
2462 break;
2463 case 's': /* --silent */
2464 global->silent = toggle;
2465 break;
2466 case 'S': /* --show-error */
2467 global->showerror = toggle;
2468 break;
2469 case 't':
2470 /* Telnet options */
2471 err = add2list(&config->telnet_options, nextarg);
2472 break;
2473 case 'T':
2474 /* we are uploading */
2475 {
2476 struct getout *url;
2477 if(!config->url_ul)
2478 config->url_ul = config->url_list;
2479 if(config->url_ul) {
2480 /* there's a node here, if it already is filled-in continue to find
2481 an "empty" node */
2482 while(config->url_ul && (config->url_ul->flags & GETOUT_UPLOAD))
2483 config->url_ul = config->url_ul->next;
2484 }
2485
2486 /* now there might or might not be an available node to fill in! */
2487
2488 if(config->url_ul)
2489 /* existing node */
2490 url = config->url_ul;
2491 else
2492 /* there was no free node, create one! */
2493 config->url_ul = url = new_getout(config);
2494
2495 if(!url) {
2496 err = PARAM_NO_MEM;
2497 break;
2498 }
2499
2500 url->flags |= GETOUT_UPLOAD; /* mark -T used */
2501 if(!*nextarg)
2502 url->flags |= GETOUT_NOUPLOAD;
2503 else {
2504 /* "-" equals stdin, but keep the string around for now */
2505 GetStr(&url->infile, nextarg);
2506 }
2507 }
2508 break;
2509 case 'u':
2510 /* user:password */
2511 GetStr(&config->userpwd, nextarg);
2512 cleanarg(clearthis);
2513 break;
2514 case 'U':
2515 /* Proxy user:password */
2516 GetStr(&config->proxyuserpwd, nextarg);
2517 cleanarg(clearthis);
2518 break;
2519 case 'v':
2520 if(toggle) {
2521 /* the '%' thing here will cause the trace get sent to stderr */
2522 Curl_safefree(global->trace_dump);
2523 global->trace_dump = strdup("%");
2524 if(!global->trace_dump) {
2525 err = PARAM_NO_MEM;
2526 break;
2527 }
2528 if(global->tracetype && (global->tracetype != TRACE_PLAIN))
2529 warnf(global,
2530 "-v, --verbose overrides an earlier trace/verbose option");
2531 global->tracetype = TRACE_PLAIN;
2532 }
2533 else
2534 /* verbose is disabled here */
2535 global->tracetype = TRACE_NONE;
2536 break;
2537 case 'V':
2538 if(toggle) { /* --no-version yields no output! */
2539 err = PARAM_VERSION_INFO_REQUESTED;
2540 break;
2541 }
2542 break;
2543
2544 case 'w':
2545 /* get the output string */
2546 if('@' == *nextarg) {
2547 /* the data begins with a '@' letter, it means that a file name
2548 or - (stdin) follows */
2549 FILE *file;
2550 const char *fname;
2551 nextarg++; /* pass the @ */
2552 if(!strcmp("-", nextarg)) {
2553 fname = "<stdin>";
2554 file = stdin;
2555 }
2556 else {
2557 fname = nextarg;
2558 file = fopen(fname, FOPEN_READTEXT);
2559 if(!file) {
2560 errorf(global, "Failed to open %s", fname);
2561 err = PARAM_READ_ERROR;
2562 break;
2563 }
2564 }
2565 Curl_safefree(config->writeout);
2566 err = file2string(&config->writeout, file);
2567 if(file && (file != stdin))
2568 fclose(file);
2569 if(err)
2570 break;
2571 if(!config->writeout)
2572 warnf(global, "Failed to read %s", fname);
2573 }
2574 else
2575 GetStr(&config->writeout, nextarg);
2576 break;
2577 case 'x':
2578 switch(subletter) {
2579 case 'a': /* --preproxy */
2580 GetStr(&config->preproxy, nextarg);
2581 break;
2582 default:
2583 /* --proxy */
2584 GetStr(&config->proxy, nextarg);
2585 if(config->proxyver != CURLPROXY_HTTPS2)
2586 config->proxyver = CURLPROXY_HTTP;
2587 break;
2588 }
2589 break;
2590 case 'X':
2591 /* set custom request */
2592 GetStr(&config->customrequest, nextarg);
2593 break;
2594 case 'y':
2595 /* low speed time */
2596 err = str2unum(&config->low_speed_time, nextarg);
2597 if(err)
2598 break;
2599 if(!config->low_speed_limit)
2600 config->low_speed_limit = 1;
2601 break;
2602 case 'Y':
2603 /* low speed limit */
2604 err = str2unum(&config->low_speed_limit, nextarg);
2605 if(err)
2606 break;
2607 if(!config->low_speed_time)
2608 config->low_speed_time = 30;
2609 break;
2610 case 'Z':
2611 switch(subletter) {
2612 case '\0': /* --parallel */
2613 global->parallel = toggle;
2614 break;
2615 case 'b': { /* --parallel-max */
2616 long val;
2617 err = str2unum(&val, nextarg);
2618 if(err)
2619 break;
2620 if(val > MAX_PARALLEL)
2621 global->parallel_max = MAX_PARALLEL;
2622 else if(val < 1)
2623 global->parallel_max = PARALLEL_DEFAULT;
2624 else
2625 global->parallel_max = (unsigned short)val;
2626 break;
2627 }
2628 case 'c': /* --parallel-immediate */
2629 global->parallel_connect = toggle;
2630 break;
2631 }
2632 break;
2633 case 'z': /* time condition coming up */
2634 switch(*nextarg) {
2635 case '+':
2636 nextarg++;
2637 /* FALLTHROUGH */
2638 default:
2639 /* If-Modified-Since: (section 14.28 in RFC2068) */
2640 config->timecond = CURL_TIMECOND_IFMODSINCE;
2641 break;
2642 case '-':
2643 /* If-Unmodified-Since: (section 14.24 in RFC2068) */
2644 config->timecond = CURL_TIMECOND_IFUNMODSINCE;
2645 nextarg++;
2646 break;
2647 case '=':
2648 /* Last-Modified: (section 14.29 in RFC2068) */
2649 config->timecond = CURL_TIMECOND_LASTMOD;
2650 nextarg++;
2651 break;
2652 }
2653 now = time(NULL);
2654 config->condtime = (curl_off_t)curl_getdate(nextarg, &now);
2655 if(-1 == config->condtime) {
2656 /* now let's see if it is a file name to get the time from instead! */
2657 curl_off_t filetime;
2658 rc = getfiletime(nextarg, global, &filetime);
2659 if(!rc)
2660 /* pull the time out from the file */
2661 config->condtime = filetime;
2662 else {
2663 /* failed, remove time condition */
2664 config->timecond = CURL_TIMECOND_NONE;
2665 warnf(global,
2666 "Illegal date format for -z, --time-cond (and not "
2667 "a file name). Disabling time condition. "
2668 "See curl_getdate(3) for valid date syntax.");
2669 }
2670 }
2671 break;
2672 default: /* unknown flag */
2673 err = PARAM_OPTION_UNKNOWN;
2674 break;
2675 }
2676 hit = -1;
2677
2678 } while(!longopt && !singleopt && *++parse && !*usedarg && !err);
2679
2680 error:
2681 if(nextalloc)
2682 free(nextarg);
2683 return err;
2684 }
2685
parse_args(struct GlobalConfig * global,int argc,argv_item_t argv[])2686 ParameterError parse_args(struct GlobalConfig *global, int argc,
2687 argv_item_t argv[])
2688 {
2689 int i;
2690 bool stillflags;
2691 char *orig_opt = NULL;
2692 ParameterError result = PARAM_OK;
2693 struct OperationConfig *config = global->first;
2694
2695 for(i = 1, stillflags = TRUE; i < argc && !result; i++) {
2696 orig_opt = curlx_convert_tchar_to_UTF8(argv[i]);
2697 if(!orig_opt)
2698 return PARAM_NO_MEM;
2699
2700 if(stillflags && ('-' == orig_opt[0])) {
2701 bool passarg;
2702
2703 if(!strcmp("--", orig_opt))
2704 /* This indicates the end of the flags and thus enables the
2705 following (URL) argument to start with -. */
2706 stillflags = FALSE;
2707 else {
2708 char *nextarg = NULL;
2709 if(i < (argc - 1)) {
2710 nextarg = curlx_convert_tchar_to_UTF8(argv[i + 1]);
2711 if(!nextarg) {
2712 curlx_unicodefree(orig_opt);
2713 return PARAM_NO_MEM;
2714 }
2715 }
2716
2717 result = getparameter(orig_opt, nextarg, argv[i + 1], &passarg,
2718 global, config);
2719
2720 curlx_unicodefree(nextarg);
2721 config = global->last;
2722 if(result == PARAM_NEXT_OPERATION) {
2723 /* Reset result as PARAM_NEXT_OPERATION is only used here and not
2724 returned from this function */
2725 result = PARAM_OK;
2726
2727 if(config->url_list && config->url_list->url) {
2728 /* Allocate the next config */
2729 config->next = malloc(sizeof(struct OperationConfig));
2730 if(config->next) {
2731 /* Initialise the newly created config */
2732 config_init(config->next);
2733
2734 /* Set the global config pointer */
2735 config->next->global = global;
2736
2737 /* Update the last config pointer */
2738 global->last = config->next;
2739
2740 /* Move onto the new config */
2741 config->next->prev = config;
2742 config = config->next;
2743 }
2744 else
2745 result = PARAM_NO_MEM;
2746 }
2747 else {
2748 errorf(global, "missing URL before --next");
2749 result = PARAM_BAD_USE;
2750 }
2751 }
2752 else if(!result && passarg)
2753 i++; /* we're supposed to skip this */
2754 }
2755 }
2756 else {
2757 bool used;
2758
2759 /* Just add the URL please */
2760 result = getparameter("--url", orig_opt, argv[i], &used, global, config);
2761 }
2762
2763 if(!result)
2764 curlx_unicodefree(orig_opt);
2765 }
2766
2767 if(!result && config->content_disposition) {
2768 if(config->show_headers)
2769 result = PARAM_CONTDISP_SHOW_HEADER;
2770 else if(config->resume_from_current)
2771 result = PARAM_CONTDISP_RESUME_FROM;
2772 }
2773
2774 if(result && result != PARAM_HELP_REQUESTED &&
2775 result != PARAM_MANUAL_REQUESTED &&
2776 result != PARAM_VERSION_INFO_REQUESTED &&
2777 result != PARAM_ENGINES_REQUESTED) {
2778 const char *reason = param2text(result);
2779
2780 if(orig_opt && strcmp(":", orig_opt))
2781 helpf(tool_stderr, "option %s: %s", orig_opt, reason);
2782 else
2783 helpf(tool_stderr, "%s", reason);
2784 }
2785
2786 curlx_unicodefree(orig_opt);
2787 return result;
2788 }
2789