1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
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.haxx.se/docs/copyright.html.
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.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
22 #include "tool_setup.h"
26 #define ENABLE_CURLX_PRINTF
27 /* use our own printf() functions */
30 #include "tool_binmode.h"
31 #include "tool_cfgable.h"
32 #include "tool_cb_prg.h"
33 #include "tool_convert.h"
34 #include "tool_filetime.h"
35 #include "tool_formparse.h"
36 #include "tool_getparam.h"
37 #include "tool_helpers.h"
38 #include "tool_libinfo.h"
39 #include "tool_metalink.h"
40 #include "tool_msgs.h"
41 #include "tool_paramhlp.h"
42 #include "tool_parsecfg.h"
44 #include "memdebug.h" /* keep this as LAST include */
50 #define GetStr(str,val) do { \
56 *(str) = strdup((val)); \
58 return PARAM_NO_MEM; \
63 const char *letter; /* short name option */
64 const char *lname; /* long name option */
66 ARG_NONE, /* stand-alone but not a boolean */
67 ARG_BOOL, /* accepts a --no-[name] prefix */
68 ARG_STRING /* requires an argument */
72 static const struct LongShort aliases[]= {
73 /* 'letter' strings with more than one character have *no* short option to
75 {"*@", "url", ARG_STRING},
76 {"*4", "dns-ipv4-addr", ARG_STRING},
77 {"*6", "dns-ipv6-addr", ARG_STRING},
78 {"*a", "random-file", ARG_STRING},
79 {"*b", "egd-file", ARG_STRING},
80 {"*B", "oauth2-bearer", ARG_STRING},
81 {"*c", "connect-timeout", ARG_STRING},
82 {"*d", "ciphers", ARG_STRING},
83 {"*D", "dns-interface", ARG_STRING},
84 {"*e", "disable-epsv", ARG_BOOL},
85 {"*E", "epsv", ARG_BOOL},
86 /* 'epsv' made like this to make --no-epsv and --epsv to work
87 although --disable-epsv is the documented option */
88 {"*F", "dns-servers", ARG_STRING},
89 {"*g", "trace", ARG_STRING},
90 {"*G", "npn", ARG_BOOL},
91 {"*h", "trace-ascii", ARG_STRING},
92 {"*H", "alpn", ARG_BOOL},
93 {"*i", "limit-rate", ARG_STRING},
94 {"*j", "compressed", ARG_BOOL},
95 {"*J", "tr-encoding", ARG_BOOL},
96 {"*k", "digest", ARG_BOOL},
97 {"*l", "negotiate", ARG_BOOL},
98 {"*m", "ntlm", ARG_BOOL},
99 {"*M", "ntlm-wb", ARG_BOOL},
100 {"*n", "basic", ARG_BOOL},
101 {"*o", "anyauth", ARG_BOOL},
103 {"*p", "wdebug", ARG_BOOL},
105 {"*q", "ftp-create-dirs", ARG_BOOL},
106 {"*r", "create-dirs", ARG_BOOL},
107 {"*s", "max-redirs", ARG_STRING},
108 {"*t", "proxy-ntlm", ARG_BOOL},
109 {"*u", "crlf", ARG_BOOL},
110 {"*v", "stderr", ARG_STRING},
111 {"*w", "interface", ARG_STRING},
112 {"*x", "krb", ARG_STRING},
113 {"*x", "krb4", ARG_STRING},
114 /* 'krb4' is the previous name */
115 {"*y", "max-filesize", ARG_STRING},
116 {"*z", "disable-eprt", ARG_BOOL},
117 {"*Z", "eprt", ARG_BOOL},
118 /* 'eprt' made like this to make --no-eprt and --eprt to work
119 although --disable-eprt is the documented option */
120 {"*~", "xattr", ARG_BOOL},
121 {"$a", "ftp-ssl", ARG_BOOL},
122 /* 'ftp-ssl' deprecated name since 7.20.0 */
123 {"$a", "ssl", ARG_BOOL},
124 /* 'ssl' new option name in 7.20.0, previously this was ftp-ssl */
125 {"$b", "ftp-pasv", ARG_BOOL},
126 {"$c", "socks5", ARG_STRING},
127 {"$d", "tcp-nodelay", ARG_BOOL},
128 {"$e", "proxy-digest", ARG_BOOL},
129 {"$f", "proxy-basic", ARG_BOOL},
130 {"$g", "retry", ARG_STRING},
131 {"$V", "retry-connrefused", ARG_BOOL},
132 {"$h", "retry-delay", ARG_STRING},
133 {"$i", "retry-max-time", ARG_STRING},
134 {"$k", "proxy-negotiate", ARG_BOOL},
135 {"$m", "ftp-account", ARG_STRING},
136 {"$n", "proxy-anyauth", ARG_BOOL},
137 {"$o", "trace-time", ARG_BOOL},
138 {"$p", "ignore-content-length", ARG_BOOL},
139 {"$q", "ftp-skip-pasv-ip", ARG_BOOL},
140 {"$r", "ftp-method", ARG_STRING},
141 {"$s", "local-port", ARG_STRING},
142 {"$t", "socks4", ARG_STRING},
143 {"$T", "socks4a", ARG_STRING},
144 {"$u", "ftp-alternative-to-user", ARG_STRING},
145 {"$v", "ftp-ssl-reqd", ARG_BOOL},
146 /* 'ftp-ssl-reqd' deprecated name since 7.20.0 */
147 {"$v", "ssl-reqd", ARG_BOOL},
148 /* 'ssl-reqd' new in 7.20.0, previously this was ftp-ssl-reqd */
149 {"$w", "sessionid", ARG_BOOL},
150 /* 'sessionid' listed as --no-sessionid in the help */
151 {"$x", "ftp-ssl-control", ARG_BOOL},
152 {"$y", "ftp-ssl-ccc", ARG_BOOL},
153 {"$j", "ftp-ssl-ccc-mode", ARG_STRING},
154 {"$z", "libcurl", ARG_STRING},
155 {"$#", "raw", ARG_BOOL},
156 {"$0", "post301", ARG_BOOL},
157 {"$1", "keepalive", ARG_BOOL},
158 /* 'keepalive' listed as --no-keepalive in the help */
159 {"$2", "socks5-hostname", ARG_STRING},
160 {"$3", "keepalive-time", ARG_STRING},
161 {"$4", "post302", ARG_BOOL},
162 {"$5", "noproxy", ARG_STRING},
163 {"$7", "socks5-gssapi-nec", ARG_BOOL},
164 {"$8", "proxy1.0", ARG_STRING},
165 {"$9", "tftp-blksize", ARG_STRING},
166 {"$A", "mail-from", ARG_STRING},
167 {"$B", "mail-rcpt", ARG_STRING},
168 {"$C", "ftp-pret", ARG_BOOL},
169 {"$D", "proto", ARG_STRING},
170 {"$E", "proto-redir", ARG_STRING},
171 {"$F", "resolve", ARG_STRING},
172 {"$G", "delegation", ARG_STRING},
173 {"$H", "mail-auth", ARG_STRING},
174 {"$I", "post303", ARG_BOOL},
175 {"$J", "metalink", ARG_BOOL},
176 {"$K", "sasl-ir", ARG_BOOL},
177 {"$L", "test-event", ARG_BOOL},
178 {"$M", "unix-socket", ARG_STRING},
179 {"$N", "path-as-is", ARG_BOOL},
180 {"$O", "socks5-gssapi-service", ARG_STRING},
181 /* 'socks5-gssapi-service' merged with'proxy-service-name' and
182 deprecated since 7.49.0 */
183 {"$O", "proxy-service-name", ARG_STRING},
184 {"$P", "service-name", ARG_STRING},
185 {"$Q", "proto-default", ARG_STRING},
186 {"$R", "expect100-timeout", ARG_STRING},
187 {"$S", "tftp-no-options", ARG_BOOL},
188 {"$U", "connect-to", ARG_STRING},
189 {"$W", "abstract-unix-socket", ARG_STRING},
190 {"$X", "tls-max", ARG_STRING},
191 {"$Y", "suppress-connect-headers", ARG_BOOL},
192 {"$Z", "compressed-ssh", ARG_BOOL},
193 {"$~", "happy-eyeballs-timeout-ms", ARG_STRING},
194 {"0", "http1.0", ARG_NONE},
195 {"01", "http1.1", ARG_NONE},
196 {"02", "http2", ARG_NONE},
197 {"03", "http2-prior-knowledge", ARG_NONE},
198 {"1", "tlsv1", ARG_NONE},
199 {"10", "tlsv1.0", ARG_NONE},
200 {"11", "tlsv1.1", ARG_NONE},
201 {"12", "tlsv1.2", ARG_NONE},
202 {"13", "tlsv1.3", ARG_NONE},
203 {"2", "sslv2", ARG_NONE},
204 {"3", "sslv3", ARG_NONE},
205 {"4", "ipv4", ARG_NONE},
206 {"6", "ipv6", ARG_NONE},
207 {"a", "append", ARG_BOOL},
208 {"A", "user-agent", ARG_STRING},
209 {"b", "cookie", ARG_STRING},
210 {"B", "use-ascii", ARG_BOOL},
211 {"c", "cookie-jar", ARG_STRING},
212 {"C", "continue-at", ARG_STRING},
213 {"d", "data", ARG_STRING},
214 {"dr", "data-raw", ARG_STRING},
215 {"da", "data-ascii", ARG_STRING},
216 {"db", "data-binary", ARG_STRING},
217 {"de", "data-urlencode", ARG_STRING},
218 {"D", "dump-header", ARG_STRING},
219 {"e", "referer", ARG_STRING},
220 {"E", "cert", ARG_STRING},
221 {"Ea", "cacert", ARG_STRING},
222 {"Eb", "cert-type", ARG_STRING},
223 {"Ec", "key", ARG_STRING},
224 {"Ed", "key-type", ARG_STRING},
225 {"Ee", "pass", ARG_STRING},
226 {"Ef", "engine", ARG_STRING},
227 {"Eg", "capath", ARG_STRING},
228 {"Eh", "pubkey", ARG_STRING},
229 {"Ei", "hostpubmd5", ARG_STRING},
230 {"Ej", "crlfile", ARG_STRING},
231 {"Ek", "tlsuser", ARG_STRING},
232 {"El", "tlspassword", ARG_STRING},
233 {"Em", "tlsauthtype", ARG_STRING},
234 {"En", "ssl-allow-beast", ARG_BOOL},
235 {"Eo", "login-options", ARG_STRING},
236 {"Ep", "pinnedpubkey", ARG_STRING},
237 {"EP", "proxy-pinnedpubkey", ARG_STRING},
238 {"Eq", "cert-status", ARG_BOOL},
239 {"Er", "false-start", ARG_BOOL},
240 {"Es", "ssl-no-revoke", ARG_BOOL},
241 {"Et", "tcp-fastopen", ARG_BOOL},
242 {"Eu", "proxy-tlsuser", ARG_STRING},
243 {"Ev", "proxy-tlspassword", ARG_STRING},
244 {"Ew", "proxy-tlsauthtype", ARG_STRING},
245 {"Ex", "proxy-cert", ARG_STRING},
246 {"Ey", "proxy-cert-type", ARG_STRING},
247 {"Ez", "proxy-key", ARG_STRING},
248 {"E0", "proxy-key-type", ARG_STRING},
249 {"E1", "proxy-pass", ARG_STRING},
250 {"E2", "proxy-ciphers", ARG_STRING},
251 {"E3", "proxy-crlfile", ARG_STRING},
252 {"E4", "proxy-ssl-allow-beast", ARG_BOOL},
253 {"E5", "login-options", ARG_STRING},
254 {"E6", "proxy-cacert", ARG_STRING},
255 {"E7", "proxy-capath", ARG_STRING},
256 {"E8", "proxy-insecure", ARG_BOOL},
257 {"E9", "proxy-tlsv1", ARG_NONE},
258 {"EA", "socks5-basic", ARG_BOOL},
259 {"EB", "socks5-gssapi", ARG_BOOL},
260 {"f", "fail", ARG_BOOL},
261 {"fa", "fail-early", ARG_BOOL},
262 {"F", "form", ARG_STRING},
263 {"Fs", "form-string", ARG_STRING},
264 {"g", "globoff", ARG_BOOL},
265 {"G", "get", ARG_NONE},
266 {"Ga", "request-target", ARG_STRING},
267 {"h", "help", ARG_BOOL},
268 {"H", "header", ARG_STRING},
269 {"Hp", "proxy-header", ARG_STRING},
270 {"i", "include", ARG_BOOL},
271 {"I", "head", ARG_BOOL},
272 {"j", "junk-session-cookies", ARG_BOOL},
273 {"J", "remote-header-name", ARG_BOOL},
274 {"k", "insecure", ARG_BOOL},
275 {"K", "config", ARG_STRING},
276 {"l", "list-only", ARG_BOOL},
277 {"L", "location", ARG_BOOL},
278 {"Lt", "location-trusted", ARG_BOOL},
279 {"m", "max-time", ARG_STRING},
280 {"M", "manual", ARG_BOOL},
281 {"n", "netrc", ARG_BOOL},
282 {"no", "netrc-optional", ARG_BOOL},
283 {"ne", "netrc-file", ARG_STRING},
284 {"N", "buffer", ARG_BOOL},
285 /* 'buffer' listed as --no-buffer in the help */
286 {"o", "output", ARG_STRING},
287 {"O", "remote-name", ARG_NONE},
288 {"Oa", "remote-name-all", ARG_BOOL},
289 {"p", "proxytunnel", ARG_BOOL},
290 {"P", "ftp-port", ARG_STRING},
291 {"q", "disable", ARG_BOOL},
292 {"Q", "quote", ARG_STRING},
293 {"r", "range", ARG_STRING},
294 {"R", "remote-time", ARG_BOOL},
295 {"s", "silent", ARG_BOOL},
296 {"S", "show-error", ARG_BOOL},
297 {"t", "telnet-option", ARG_STRING},
298 {"T", "upload-file", ARG_STRING},
299 {"u", "user", ARG_STRING},
300 {"U", "proxy-user", ARG_STRING},
301 {"v", "verbose", ARG_BOOL},
302 {"V", "version", ARG_BOOL},
303 {"w", "write-out", ARG_STRING},
304 {"x", "proxy", ARG_STRING},
305 {"xa", "preproxy", ARG_STRING},
306 {"X", "request", ARG_STRING},
307 {"Y", "speed-limit", ARG_STRING},
308 {"y", "speed-time", ARG_STRING},
309 {"z", "time-cond", ARG_STRING},
310 {"#", "progress-bar", ARG_BOOL},
311 {":", "next", ARG_NONE},
314 /* Split the argument of -E to 'certname' and 'passphrase' separated by colon.
315 * We allow ':' and '\' to be escaped by '\' so that we can use certificate
316 * nicknames containing ':'. See <https://sourceforge.net/p/curl/bugs/1196/>
321 void parse_cert_parameter(const char *cert_parameter,
325 size_t param_length = strlen(cert_parameter);
327 const char *param_place = NULL;
328 char *certname_place = NULL;
332 /* most trivial assumption: cert_parameter is empty */
333 if(param_length == 0)
336 /* next less trivial: cert_parameter starts 'pkcs11:' and thus
337 * looks like a RFC7512 PKCS#11 URI which can be used as-is.
338 * Also if cert_parameter contains no colon nor backslash, this
339 * means no passphrase was given and no characters escaped */
340 if(!strncmp(cert_parameter, "pkcs11:", 7) ||
341 !strpbrk(cert_parameter, ":\\")) {
342 *certname = strdup(cert_parameter);
345 /* deal with escaped chars; find unescaped colon if it exists */
346 certname_place = malloc(param_length + 1);
350 *certname = certname_place;
351 param_place = cert_parameter;
352 while(*param_place) {
353 span = strcspn(param_place, ":\\");
354 strncpy(certname_place, param_place, span);
356 certname_place += span;
357 /* we just ate all the non-special chars. now we're on either a special
358 * char or the end of the string. */
359 switch(*param_place) {
364 switch(*param_place) {
366 *certname_place++ = '\\';
369 *certname_place++ = '\\';
373 *certname_place++ = ':';
377 *certname_place++ = '\\';
378 *certname_place++ = *param_place;
384 /* Since we live in a world of weirdness and confusion, the win32
385 dudes can use : when using drive letters and thus c:\file:password
386 needs to work. In order not to break compatibility, we still use : as
387 separator, but we try to detect when it is used for a file name! On
391 (param_place == &cert_parameter[1]) &&
392 (cert_parameter[2] == '\\' || cert_parameter[2] == '/') &&
393 (ISALPHA(cert_parameter[0])) ) {
394 /* colon in the second column, followed by a backslash, and the
395 first character is an alphabetic letter:
397 this is a drive letter colon */
398 *certname_place++ = ':';
403 /* escaped colons and Windows drive letter colons were handled
404 * above; if we're still here, this is a separating colon */
406 if(strlen(param_place) > 0) {
407 *passphrase = strdup(param_place);
413 *certname_place = '\0';
417 GetFileAndPassword(char *nextarg, char **file, char **password)
419 char *certname, *passphrase;
420 parse_cert_parameter(nextarg, &certname, &passphrase);
421 Curl_safefree(*file);
424 Curl_safefree(*password);
425 *password = passphrase;
430 /* Get a size parameter for '--limit-rate' or '--max-filesize'.
431 * We support a 'G', 'M' or 'K' suffix too.
433 static ParameterError GetSizeParameter(struct GlobalConfig *global,
436 curl_off_t *value_out)
441 if(curlx_strtoofft(arg, &unit, 0, &value)) {
442 warnf(global, "invalid number specified for %s\n", which);
443 return PARAM_BAD_USE;
448 else if(strlen(unit) > 1)
449 unit = (char *)"w"; /* unsupported */
454 if(value > (CURL_OFF_T_MAX / (1024*1024*1024)))
455 return PARAM_NUMBER_TOO_LARGE;
456 value *= 1024*1024*1024;
460 if(value > (CURL_OFF_T_MAX / (1024*1024)))
461 return PARAM_NUMBER_TOO_LARGE;
466 if(value > (CURL_OFF_T_MAX / 1024))
467 return PARAM_NUMBER_TOO_LARGE;
472 /* for plain bytes, leave as-is */
475 warnf(global, "unsupported %s unit. Use G, M, K or B!\n", which);
476 return PARAM_BAD_USE;
482 ParameterError getparameter(const char *flag, /* f or -long-flag */
483 char *nextarg, /* NULL if unset */
484 bool *usedarg, /* set to TRUE if the arg
486 struct GlobalConfig *global,
487 struct OperationConfig *config)
490 char subletter = '\0'; /* subletters can only occur on long options */
492 const char *parse = NULL;
496 bool longopt = FALSE;
497 bool singleopt = FALSE; /* when true means '-o foo' used '-ofoo' */
499 bool toggle = TRUE; /* how to switch boolean options, on or off. Controlled
500 by using --OPTION or --no-OPTION */
502 *usedarg = FALSE; /* default is that we don't use the arg */
504 if(('-' != flag[0]) ||
505 (('-' == flag[0]) && ('-' == flag[1]))) {
506 /* this should be a long name */
507 const char *word = ('-' == flag[0]) ? flag + 2 : flag;
508 size_t fnam = strlen(word);
511 if(!strncmp(word, "no-", 3)) {
512 /* disable this option but ignore the "no-" part when looking for it */
517 for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) {
518 if(curl_strnequal(aliases[j].lname, word, fnam)) {
521 if(curl_strequal(aliases[j].lname, word)) {
522 parse = aliases[j].letter;
524 numhits = 1; /* a single unique hit */
527 parse = aliases[j].letter;
532 /* this is at least the second match! */
533 return PARAM_OPTION_AMBIGUOUS;
536 return PARAM_OPTION_UNKNOWN;
540 flag++; /* prefixed with one dash, pass it */
546 /* we can loop here if we have multiple single-letters */
549 letter = (char)*parse;
554 subletter = parse[1];
558 for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) {
559 if(letter == aliases[j].letter[0]) {
565 return PARAM_OPTION_UNKNOWN;
569 if(aliases[hit].desc == ARG_STRING) {
570 /* this option requires an extra parameter */
571 if(!longopt && parse[1]) {
572 nextarg = (char *)&parse[1]; /* this is the actual extra parameter */
573 singleopt = TRUE; /* don't loop anymore after this */
576 return PARAM_REQUIRES_PARAMETER;
578 *usedarg = TRUE; /* mark it as used */
580 else if((aliases[hit].desc == ARG_NONE) && !toggle)
581 return PARAM_NO_PREFIX;
584 case '*': /* options without a short option */
586 case '4': /* --dns-ipv4-addr */
587 /* addr in dot notation */
588 GetStr(&config->dns_ipv4_addr, nextarg);
590 case '6': /* --dns-ipv6-addr */
591 /* addr in dot notation */
592 GetStr(&config->dns_ipv6_addr, nextarg);
594 case 'a': /* random-file */
595 GetStr(&config->random_file, nextarg);
597 case 'b': /* egd-file */
598 GetStr(&config->egd_file, nextarg);
600 case 'B': /* OAuth 2.0 bearer token */
601 GetStr(&config->oauth_bearer, nextarg);
603 case 'c': /* connect-timeout */
604 err = str2udouble(&config->connecttimeout, nextarg,
609 case 'd': /* ciphers */
610 GetStr(&config->cipher_list, nextarg);
612 case 'D': /* --dns-interface */
614 GetStr(&config->dns_interface, nextarg);
616 case 'e': /* --disable-epsv */
617 config->disable_epsv = toggle;
619 case 'E': /* --epsv */
620 config->disable_epsv = (!toggle)?TRUE:FALSE;
622 case 'F': /* --dns-servers */
623 /* IP addrs of DNS servers */
624 GetStr(&config->dns_servers, nextarg);
626 case 'g': /* --trace */
627 GetStr(&global->trace_dump, nextarg);
628 if(global->tracetype && (global->tracetype != TRACE_BIN))
629 warnf(global, "--trace overrides an earlier trace/verbose option\n");
630 global->tracetype = TRACE_BIN;
632 case 'G': /* --npn */
633 config->nonpn = (!toggle)?TRUE:FALSE;
635 case 'h': /* --trace-ascii */
636 GetStr(&global->trace_dump, nextarg);
637 if(global->tracetype && (global->tracetype != TRACE_ASCII))
639 "--trace-ascii overrides an earlier trace/verbose option\n");
640 global->tracetype = TRACE_ASCII;
642 case 'H': /* --alpn */
643 config->noalpn = (!toggle)?TRUE:FALSE;
645 case 'i': /* --limit-rate */
648 ParameterError pe = GetSizeParameter(global, nextarg, "rate", &value);
652 config->recvpersecond = value;
653 config->sendpersecond = value;
657 case 'j': /* --compressed */
659 !(curlinfo->features & (CURL_VERSION_LIBZ | CURL_VERSION_BROTLI)))
660 return PARAM_LIBCURL_DOESNT_SUPPORT;
661 config->encoding = toggle;
664 case 'J': /* --tr-encoding */
665 config->tr_encoding = toggle;
668 case 'k': /* --digest */
670 config->authtype |= CURLAUTH_DIGEST;
672 config->authtype &= ~CURLAUTH_DIGEST;
675 case 'l': /* --negotiate */
677 if(curlinfo->features & CURL_VERSION_SPNEGO)
678 config->authtype |= CURLAUTH_NEGOTIATE;
680 return PARAM_LIBCURL_DOESNT_SUPPORT;
683 config->authtype &= ~CURLAUTH_NEGOTIATE;
686 case 'm': /* --ntlm */
688 if(curlinfo->features & CURL_VERSION_NTLM)
689 config->authtype |= CURLAUTH_NTLM;
691 return PARAM_LIBCURL_DOESNT_SUPPORT;
694 config->authtype &= ~CURLAUTH_NTLM;
697 case 'M': /* --ntlm-wb */
699 if(curlinfo->features & CURL_VERSION_NTLM_WB)
700 config->authtype |= CURLAUTH_NTLM_WB;
702 return PARAM_LIBCURL_DOESNT_SUPPORT;
705 config->authtype &= ~CURLAUTH_NTLM_WB;
708 case 'n': /* --basic for completeness */
710 config->authtype |= CURLAUTH_BASIC;
712 config->authtype &= ~CURLAUTH_BASIC;
715 case 'o': /* --anyauth, let libcurl pick it */
717 config->authtype = CURLAUTH_ANY;
718 /* --no-anyauth simply doesn't touch it */
722 case 'p': /* --wdebug */
726 case 'q': /* --ftp-create-dirs */
727 config->ftp_create_dirs = toggle;
730 case 'r': /* --create-dirs */
731 config->create_dirs = toggle;
734 case 's': /* --max-redirs */
735 /* specified max no of redirects (http(s)), this accepts -1 as a
737 err = str2num(&config->maxredirs, nextarg);
740 if(config->maxredirs < -1)
741 return PARAM_BAD_NUMERIC;
744 case 't': /* --proxy-ntlm */
745 if(curlinfo->features & CURL_VERSION_NTLM)
746 config->proxyntlm = toggle;
748 return PARAM_LIBCURL_DOESNT_SUPPORT;
751 case 'u': /* --crlf */
752 /* LF -> CRLF conversion? */
753 config->crlf = toggle;
756 case 'v': /* --stderr */
757 if(strcmp(nextarg, "-")) {
758 FILE *newfile = fopen(nextarg, FOPEN_WRITETEXT);
760 warnf(global, "Failed to open %s!\n", nextarg);
762 if(global->errors_fopened)
763 fclose(global->errors);
764 global->errors = newfile;
765 global->errors_fopened = TRUE;
769 global->errors = stdout;
771 case 'w': /* --interface */
773 GetStr(&config->iface, nextarg);
775 case 'x': /* --krb */
776 /* kerberos level string */
777 if(curlinfo->features & CURL_VERSION_KERBEROS4)
778 GetStr(&config->krblevel, nextarg);
780 return PARAM_LIBCURL_DOESNT_SUPPORT;
782 case 'y': /* --max-filesize */
786 GetSizeParameter(global, nextarg, "max-filesize", &value);
790 config->max_filesize = value;
793 case 'z': /* --disable-eprt */
794 config->disable_eprt = toggle;
796 case 'Z': /* --eprt */
797 config->disable_eprt = (!toggle)?TRUE:FALSE;
799 case '~': /* --xattr */
800 config->xattr = toggle;
802 case '@': /* the URL! */
807 config->url_get = config->url_list;
809 if(config->url_get) {
810 /* there's a node here, if it already is filled-in continue to find
812 while(config->url_get && (config->url_get->flags & GETOUT_URL))
813 config->url_get = config->url_get->next;
816 /* now there might or might not be an available node to fill in! */
820 url = config->url_get;
822 /* there was no free node, create one! */
823 config->url_get = url = new_getout(config);
828 /* fill in the URL */
829 GetStr(&url->url, nextarg);
830 url->flags |= GETOUT_URL;
834 case '$': /* more options without a short option */
836 case 'a': /* --ssl */
837 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
838 return PARAM_LIBCURL_DOESNT_SUPPORT;
839 config->ftp_ssl = toggle;
841 case 'b': /* --ftp-pasv */
842 Curl_safefree(config->ftpport);
844 case 'c': /* --socks5 specifies a socks5 proxy to use, and resolves
845 the name locally and passes on the resolved address */
846 GetStr(&config->proxy, nextarg);
847 config->proxyver = CURLPROXY_SOCKS5;
849 case 't': /* --socks4 specifies a socks4 proxy to use */
850 GetStr(&config->proxy, nextarg);
851 config->proxyver = CURLPROXY_SOCKS4;
853 case 'T': /* --socks4a specifies a socks4a proxy to use */
854 GetStr(&config->proxy, nextarg);
855 config->proxyver = CURLPROXY_SOCKS4A;
857 case '2': /* --socks5-hostname specifies a socks5 proxy and enables name
858 resolving with the proxy */
859 GetStr(&config->proxy, nextarg);
860 config->proxyver = CURLPROXY_SOCKS5_HOSTNAME;
862 case 'd': /* --tcp-nodelay option */
863 config->tcp_nodelay = toggle;
865 case 'e': /* --proxy-digest */
866 config->proxydigest = toggle;
868 case 'f': /* --proxy-basic */
869 config->proxybasic = toggle;
871 case 'g': /* --retry */
872 err = str2unum(&config->req_retry, nextarg);
876 case 'V': /* --retry-connrefused */
877 config->retry_connrefused = toggle;
879 case 'h': /* --retry-delay */
880 err = str2unum(&config->retry_delay, nextarg);
884 case 'i': /* --retry-max-time */
885 err = str2unum(&config->retry_maxtime, nextarg);
890 case 'k': /* --proxy-negotiate */
891 if(curlinfo->features & CURL_VERSION_SPNEGO)
892 config->proxynegotiate = toggle;
894 return PARAM_LIBCURL_DOESNT_SUPPORT;
897 case 'm': /* --ftp-account */
898 GetStr(&config->ftp_account, nextarg);
900 case 'n': /* --proxy-anyauth */
901 config->proxyanyauth = toggle;
903 case 'o': /* --trace-time */
904 global->tracetime = toggle;
906 case 'p': /* --ignore-content-length */
907 config->ignorecl = toggle;
909 case 'q': /* --ftp-skip-pasv-ip */
910 config->ftp_skip_ip = toggle;
912 case 'r': /* --ftp-method (undocumented at this point) */
913 config->ftp_filemethod = ftpfilemethod(config, nextarg);
915 case 's': /* --local-port */
916 rc = sscanf(nextarg, "%d - %d",
918 &config->localportrange);
920 return PARAM_BAD_USE;
922 config->localportrange = 1; /* default number of ports to try */
924 config->localportrange -= config->localport;
925 if(config->localportrange < 1) {
926 warnf(global, "bad range input\n");
927 return PARAM_BAD_USE;
931 case 'u': /* --ftp-alternative-to-user */
932 GetStr(&config->ftp_alternative_to_user, nextarg);
934 case 'v': /* --ssl-reqd */
935 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
936 return PARAM_LIBCURL_DOESNT_SUPPORT;
937 config->ftp_ssl_reqd = toggle;
939 case 'w': /* --no-sessionid */
940 config->disable_sessionid = (!toggle)?TRUE:FALSE;
942 case 'x': /* --ftp-ssl-control */
943 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
944 return PARAM_LIBCURL_DOESNT_SUPPORT;
945 config->ftp_ssl_control = toggle;
947 case 'y': /* --ftp-ssl-ccc */
948 config->ftp_ssl_ccc = toggle;
949 if(!config->ftp_ssl_ccc_mode)
950 config->ftp_ssl_ccc_mode = CURLFTPSSL_CCC_PASSIVE;
952 case 'j': /* --ftp-ssl-ccc-mode */
953 config->ftp_ssl_ccc = TRUE;
954 config->ftp_ssl_ccc_mode = ftpcccmethod(config, nextarg);
956 case 'z': /* --libcurl */
957 #ifdef CURL_DISABLE_LIBCURL_OPTION
959 "--libcurl option was disabled at build-time!\n");
960 return PARAM_OPTION_UNKNOWN;
962 GetStr(&global->libcurl, nextarg);
965 case '#': /* --raw */
966 config->raw = toggle;
968 case '0': /* --post301 */
969 config->post301 = toggle;
971 case '1': /* --no-keepalive */
972 config->nokeepalive = (!toggle)?TRUE:FALSE;
974 case '3': /* --keepalive-time */
975 err = str2unum(&config->alivetime, nextarg);
979 case '4': /* --post302 */
980 config->post302 = toggle;
982 case 'I': /* --post303 */
983 config->post303 = toggle;
985 case '5': /* --noproxy */
986 /* This specifies the noproxy list */
987 GetStr(&config->noproxy, nextarg);
989 case '7': /* --socks5-gssapi-nec*/
990 config->socks5_gssapi_nec = toggle;
992 case '8': /* --proxy1.0 */
994 GetStr(&config->proxy, nextarg);
995 config->proxyver = CURLPROXY_HTTP_1_0;
997 case '9': /* --tftp-blksize */
998 err = str2unum(&config->tftp_blksize, nextarg);
1002 case 'A': /* --mail-from */
1003 GetStr(&config->mail_from, nextarg);
1005 case 'B': /* --mail-rcpt */
1006 /* append receiver to a list */
1007 err = add2list(&config->mail_rcpt, nextarg);
1011 case 'C': /* --ftp-pret */
1012 config->ftp_pret = toggle;
1014 case 'D': /* --proto */
1015 config->proto_present = TRUE;
1016 if(proto2num(config, &config->proto, nextarg))
1017 return PARAM_BAD_USE;
1019 case 'E': /* --proto-redir */
1020 config->proto_redir_present = TRUE;
1021 if(proto2num(config, &config->proto_redir, nextarg))
1022 return PARAM_BAD_USE;
1024 case 'F': /* --resolve */
1025 err = add2list(&config->resolve, nextarg);
1029 case 'G': /* --delegation LEVEL */
1030 config->gssapi_delegation = delegation(config, nextarg);
1032 case 'H': /* --mail-auth */
1033 GetStr(&config->mail_auth, nextarg);
1035 case 'J': /* --metalink */
1038 int mlmaj, mlmin, mlpatch;
1039 metalink_get_version(&mlmaj, &mlmin, &mlpatch);
1040 if((mlmaj*10000)+(mlmin*100) + mlpatch < CURL_REQ_LIBMETALINK_VERS) {
1042 "--metalink option cannot be used because the version of "
1043 "the linked libmetalink library is too old. "
1044 "Required: %d.%d.%d, found %d.%d.%d\n",
1045 CURL_REQ_LIBMETALINK_MAJOR,
1046 CURL_REQ_LIBMETALINK_MINOR,
1047 CURL_REQ_LIBMETALINK_PATCH,
1048 mlmaj, mlmin, mlpatch);
1049 return PARAM_BAD_USE;
1052 config->use_metalink = toggle;
1054 warnf(global, "--metalink option is ignored because the binary is "
1055 "built without the Metalink support.\n");
1059 case 'K': /* --sasl-ir */
1060 config->sasl_ir = toggle;
1062 case 'L': /* --test-event */
1064 config->test_event_based = toggle;
1066 warnf(global, "--test-event is ignored unless a debug build!\n");
1069 case 'M': /* --unix-socket */
1070 config->abstract_unix_socket = FALSE;
1071 GetStr(&config->unix_socket_path, nextarg);
1073 case 'N': /* --path-as-is */
1074 config->path_as_is = toggle;
1076 case 'O': /* --proxy-service-name */
1077 GetStr(&config->proxy_service_name, nextarg);
1079 case 'P': /* --service-name */
1080 GetStr(&config->service_name, nextarg);
1082 case 'Q': /* --proto-default */
1083 GetStr(&config->proto_default, nextarg);
1084 err = check_protocol(config->proto_default);
1088 case 'R': /* --expect100-timeout */
1089 err = str2udouble(&config->expect100timeout, nextarg, LONG_MAX/1000);
1093 case 'S': /* --tftp-no-options */
1094 config->tftp_no_options = toggle;
1096 case 'U': /* --connect-to */
1097 err = add2list(&config->connect_to, nextarg);
1101 case 'W': /* --abstract-unix-socket */
1102 config->abstract_unix_socket = TRUE;
1103 GetStr(&config->unix_socket_path, nextarg);
1105 case 'X': /* --tls-max */
1106 err = str2tls_max(&config->ssl_version_max, nextarg);
1110 case 'Y': /* --suppress-connect-headers */
1111 config->suppress_connect_headers = toggle;
1113 case 'Z': /* --compressed-ssh */
1114 config->ssh_compression = toggle;
1116 case '~': /* --happy-eyeballs-timeout-ms */
1117 err = str2unum(&config->happy_eyeballs_timeout_ms, nextarg);
1120 /* 0 is a valid value for this timeout */
1124 case '#': /* --progress-bar */
1126 global->progressmode = CURL_PROGRESS_BAR;
1128 global->progressmode = CURL_PROGRESS_STATS;
1130 case ':': /* --next */
1131 return PARAM_NEXT_OPERATION;
1132 case '0': /* --http* options */
1135 /* HTTP version 1.0 */
1136 config->httpversion = CURL_HTTP_VERSION_1_0;
1139 /* HTTP version 1.1 */
1140 config->httpversion = CURL_HTTP_VERSION_1_1;
1143 /* HTTP version 2.0 */
1144 config->httpversion = CURL_HTTP_VERSION_2_0;
1147 /* HTTP version 2.0 over clean TCP*/
1148 config->httpversion = CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE;
1152 case '1': /* --tlsv1* options */
1155 /* TLS version 1.x */
1156 config->ssl_version = CURL_SSLVERSION_TLSv1;
1159 /* TLS version 1.0 */
1160 config->ssl_version = CURL_SSLVERSION_TLSv1_0;
1163 /* TLS version 1.1 */
1164 config->ssl_version = CURL_SSLVERSION_TLSv1_1;
1167 /* TLS version 1.2 */
1168 config->ssl_version = CURL_SSLVERSION_TLSv1_2;
1171 /* TLS version 1.3 */
1172 config->ssl_version = CURL_SSLVERSION_TLSv1_3;
1178 config->ssl_version = CURL_SSLVERSION_SSLv2;
1182 config->ssl_version = CURL_SSLVERSION_SSLv3;
1186 config->ip_version = 4;
1190 config->ip_version = 6;
1193 /* This makes the FTP sessions use APPE instead of STOR */
1194 config->ftp_append = toggle;
1197 /* This specifies the User-Agent name */
1198 GetStr(&config->useragent, nextarg);
1200 case 'b': /* cookie string coming up: */
1201 if(nextarg[0] == '@') {
1204 else if(strchr(nextarg, '=')) {
1205 /* A cookie string must have a =-letter */
1206 GetStr(&config->cookie, nextarg);
1209 /* We have a cookie file to read from! */
1210 GetStr(&config->cookiefile, nextarg);
1213 /* use ASCII/text when transferring */
1214 config->use_ascii = toggle;
1217 /* get the file name to dump all cookies in */
1218 GetStr(&config->cookiejar, nextarg);
1221 /* This makes us continue an ftp transfer at given position */
1222 if(strcmp(nextarg, "-")) {
1223 err = str2offset(&config->resume_from, nextarg);
1226 config->resume_from_current = FALSE;
1229 config->resume_from_current = TRUE;
1230 config->resume_from = 0;
1232 config->use_resume = TRUE;
1235 /* postfield data */
1237 char *postdata = NULL;
1240 bool raw_mode = (subletter == 'r');
1242 if(subletter == 'e') { /* --data-urlencode*/
1243 /* [name]=[content], we encode the content part only
1244 * [name]@[file name]
1246 * Case 2: we first load the file using that name and then encode
1249 const char *p = strchr(nextarg, '=');
1253 /* there was no '=' letter, check for a '@' instead */
1254 p = strchr(nextarg, '@');
1256 nlen = p - nextarg; /* length of the name part */
1257 is_file = *p++; /* pass the separator */
1260 /* neither @ nor =, so no name and it isn't a file */
1264 if('@' == is_file) {
1265 /* a '@' letter, it means that a file name or - (stdin) follows */
1266 if(!strcmp("-", p)) {
1271 file = fopen(p, "rb");
1274 "Couldn't read data from file \"%s\", this makes "
1275 "an empty POST.\n", nextarg);
1278 err = file2memory(&postdata, &size, file);
1280 if(file && (file != stdin))
1286 GetStr(&postdata, p);
1288 size = strlen(postdata);
1292 /* no data from the file, point to a zero byte string to make this
1293 get sent as a POST anyway */
1294 postdata = strdup("");
1296 return PARAM_NO_MEM;
1300 char *enc = curl_easy_escape(config->easy, postdata, (int)size);
1301 Curl_safefree(postdata); /* no matter if it worked or not */
1303 /* now make a string with the name from above and append the
1305 size_t outlen = nlen + strlen(enc) + 2;
1306 char *n = malloc(outlen);
1309 return PARAM_NO_MEM;
1311 if(nlen > 0) { /* only append '=' if we have a name */
1312 snprintf(n, outlen, "%.*s=%s", nlen, nextarg, enc);
1317 size = outlen-2; /* since no '=' was inserted */
1323 return PARAM_NO_MEM;
1326 else if('@' == *nextarg && !raw_mode) {
1327 /* the data begins with a '@' letter, it means that a file name
1328 or - (stdin) follows */
1329 nextarg++; /* pass the @ */
1331 if(!strcmp("-", nextarg)) {
1333 if(subletter == 'b') /* forced data-binary */
1337 file = fopen(nextarg, "rb");
1339 warnf(global, "Couldn't read data from file \"%s\", this makes "
1340 "an empty POST.\n", nextarg);
1343 if(subletter == 'b')
1345 err = file2memory(&postdata, &size, file);
1347 err = file2string(&postdata, file);
1349 size = strlen(postdata);
1352 if(file && (file != stdin))
1358 /* no data from the file, point to a zero byte string to make this
1359 get sent as a POST anyway */
1360 postdata = strdup("");
1362 return PARAM_NO_MEM;
1366 GetStr(&postdata, nextarg);
1368 size = strlen(postdata);
1371 #ifdef CURL_DOES_CONVERSIONS
1372 if(subletter != 'b') {
1373 /* NOT forced binary, convert to ASCII */
1374 if(convert_to_network(postdata, strlen(postdata))) {
1375 Curl_safefree(postdata);
1376 return PARAM_NO_MEM;
1381 if(config->postfields) {
1382 /* we already have a string, we append this one with a separating
1384 char *oldpost = config->postfields;
1385 curl_off_t oldlen = config->postfieldsize;
1386 curl_off_t newlen = oldlen + curlx_uztoso(size) + 2;
1387 config->postfields = malloc((size_t)newlen);
1388 if(!config->postfields) {
1389 Curl_safefree(oldpost);
1390 Curl_safefree(postdata);
1391 return PARAM_NO_MEM;
1393 memcpy(config->postfields, oldpost, (size_t)oldlen);
1394 /* use byte value 0x26 for '&' to accommodate non-ASCII platforms */
1395 config->postfields[oldlen] = '\x26';
1396 memcpy(&config->postfields[oldlen + 1], postdata, size);
1397 config->postfields[oldlen + 1 + size] = '\0';
1398 Curl_safefree(oldpost);
1399 Curl_safefree(postdata);
1400 config->postfieldsize += size + 1;
1403 config->postfields = postdata;
1404 config->postfieldsize = curlx_uztoso(size);
1408 We can't set the request type here, as this data might be used in
1409 a simple GET if -G is used. Already or soon.
1411 if(SetHTTPrequest(HTTPREQ_SIMPLEPOST, &config->httpreq)) {
1412 Curl_safefree(postdata);
1413 return PARAM_BAD_USE;
1418 /* dump-header to given file name */
1419 GetStr(&config->headerfile, nextarg);
1423 char *ptr = strstr(nextarg, ";auto");
1425 /* Automatic referer requested, this may be combined with a
1427 config->autoreferer = TRUE;
1428 *ptr = 0; /* zero terminate here */
1431 config->autoreferer = FALSE;
1432 GetStr(&config->referer, nextarg);
1437 case '\0': /* certificate file */
1438 GetFileAndPassword(nextarg, &config->cert, &config->key_passwd);
1440 case 'a': /* CA info PEM file */
1441 /* CA info PEM file */
1442 GetStr(&config->cacert, nextarg);
1444 case 'b': /* cert file type */
1445 GetStr(&config->cert_type, nextarg);
1447 case 'c': /* private key file */
1448 GetStr(&config->key, nextarg);
1450 case 'd': /* private key file type */
1451 GetStr(&config->key_type, nextarg);
1453 case 'e': /* private key passphrase */
1454 GetStr(&config->key_passwd, nextarg);
1457 case 'f': /* crypto engine */
1458 GetStr(&config->engine, nextarg);
1459 if(config->engine && curl_strequal(config->engine, "list"))
1460 return PARAM_ENGINES_REQUESTED;
1462 case 'g': /* CA info PEM file */
1463 /* CA cert directory */
1464 GetStr(&config->capath, nextarg);
1466 case 'h': /* --pubkey public key file */
1467 GetStr(&config->pubkey, nextarg);
1469 case 'i': /* --hostpubmd5 md5 of the host public key */
1470 GetStr(&config->hostpubmd5, nextarg);
1471 if(!config->hostpubmd5 || strlen(config->hostpubmd5) != 32)
1472 return PARAM_BAD_USE;
1474 case 'j': /* CRL info PEM file */
1476 GetStr(&config->crlfile, nextarg);
1478 case 'k': /* TLS username */
1479 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)
1480 GetStr(&config->tls_username, nextarg);
1482 return PARAM_LIBCURL_DOESNT_SUPPORT;
1484 case 'l': /* TLS password */
1485 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)
1486 GetStr(&config->tls_password, nextarg);
1488 return PARAM_LIBCURL_DOESNT_SUPPORT;
1490 case 'm': /* TLS authentication type */
1491 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP) {
1492 GetStr(&config->tls_authtype, nextarg);
1493 if(!curl_strequal(config->tls_authtype, "SRP"))
1494 return PARAM_LIBCURL_DOESNT_SUPPORT; /* only support TLS-SRP */
1497 return PARAM_LIBCURL_DOESNT_SUPPORT;
1499 case 'n': /* no empty SSL fragments, --ssl-allow-beast */
1500 if(curlinfo->features & CURL_VERSION_SSL)
1501 config->ssl_allow_beast = toggle;
1504 case 'o': /* --login-options */
1505 GetStr(&config->login_options, nextarg);
1508 case 'p': /* Pinned public key DER file */
1509 /* Pinned public key DER file */
1510 GetStr(&config->pinnedpubkey, nextarg);
1513 case 'P': /* proxy pinned public key */
1514 GetStr(&config->proxy_pinnedpubkey, nextarg);
1517 case 'q': /* --cert-status */
1518 config->verifystatus = TRUE;
1521 case 'r': /* --false-start */
1522 config->falsestart = TRUE;
1525 case 's': /* --ssl-no-revoke */
1526 if(curlinfo->features & CURL_VERSION_SSL)
1527 config->ssl_no_revoke = TRUE;
1530 case 't': /* --tcp-fastopen */
1531 config->tcp_fastopen = TRUE;
1534 case 'u': /* TLS username for proxy */
1535 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)
1536 GetStr(&config->proxy_tls_username, nextarg);
1538 return PARAM_LIBCURL_DOESNT_SUPPORT;
1541 case 'v': /* TLS password for proxy */
1542 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)
1543 GetStr(&config->proxy_tls_password, nextarg);
1545 return PARAM_LIBCURL_DOESNT_SUPPORT;
1548 case 'w': /* TLS authentication type for proxy */
1549 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP) {
1550 GetStr(&config->proxy_tls_authtype, nextarg);
1551 if(!curl_strequal(config->proxy_tls_authtype, "SRP"))
1552 return PARAM_LIBCURL_DOESNT_SUPPORT; /* only support TLS-SRP */
1555 return PARAM_LIBCURL_DOESNT_SUPPORT;
1558 case 'x': /* certificate file for proxy */
1559 GetFileAndPassword(nextarg, &config->proxy_cert,
1560 &config->proxy_key_passwd);
1563 case 'y': /* cert file type for proxy */
1564 GetStr(&config->proxy_cert_type, nextarg);
1567 case 'z': /* private key file for proxy */
1568 GetStr(&config->proxy_key, nextarg);
1571 case '0': /* private key file type for proxy */
1572 GetStr(&config->proxy_key_type, nextarg);
1575 case '1': /* private key passphrase for proxy */
1576 GetStr(&config->proxy_key_passwd, nextarg);
1580 case '2': /* ciphers for proxy */
1581 GetStr(&config->proxy_cipher_list, nextarg);
1584 case '3': /* CRL info PEM file for proxy */
1586 GetStr(&config->proxy_crlfile, nextarg);
1589 case '4': /* no empty SSL fragments for proxy */
1590 if(curlinfo->features & CURL_VERSION_SSL)
1591 config->proxy_ssl_allow_beast = toggle;
1594 case '5': /* --login-options */
1595 GetStr(&config->login_options, nextarg);
1598 case '6': /* CA info PEM file for proxy */
1599 /* CA info PEM file */
1600 GetStr(&config->proxy_cacert, nextarg);
1603 case '7': /* CA info PEM file for proxy */
1604 /* CA cert directory */
1605 GetStr(&config->proxy_capath, nextarg);
1608 case '8': /* allow insecure SSL connects for proxy */
1609 config->proxy_insecure_ok = toggle;
1612 case '9': /* --proxy-tlsv1 */
1613 /* TLS version 1 for proxy */
1614 config->proxy_ssl_version = CURL_SSLVERSION_TLSv1;
1618 /* --socks5-basic */
1620 config->socks5_auth |= CURLAUTH_BASIC;
1622 config->socks5_auth &= ~CURLAUTH_BASIC;
1626 /* --socks5-gssapi */
1628 config->socks5_auth |= CURLAUTH_GSSAPI;
1630 config->socks5_auth &= ~CURLAUTH_GSSAPI;
1633 default: /* unknown flag */
1634 return PARAM_OPTION_UNKNOWN;
1639 case 'a': /* --fail-early */
1640 global->fail_early = toggle;
1643 /* fail hard on errors */
1644 config->failonerror = toggle;
1648 /* "form data" simulation, this is a little advanced so lets do our best
1649 to sort this out slowly and carefully */
1650 if(formparse(config,
1653 &config->mimecurrent,
1654 (subletter == 's')?TRUE:FALSE)) /* 's' is literal string */
1655 return PARAM_BAD_USE;
1656 if(SetHTTPrequest(config, HTTPREQ_MIMEPOST, &config->httpreq))
1657 return PARAM_BAD_USE;
1660 case 'g': /* g disables URLglobbing */
1661 config->globoff = toggle;
1664 case 'G': /* HTTP GET */
1665 if(subletter == 'a') { /* --request-target */
1666 GetStr(&config->request_target, nextarg);
1669 config->use_httpget = TRUE;
1672 case 'h': /* h for help */
1674 return PARAM_HELP_REQUESTED;
1676 /* we now actually support --no-help too! */
1679 /* A custom header to append to a list */
1680 if(nextarg[0] == '@') {
1681 /* read many headers from a file or stdin */
1684 bool use_stdin = !strcmp(&nextarg[1], "-");
1685 FILE *file = use_stdin?stdin:fopen(&nextarg[1], FOPEN_READTEXT);
1687 warnf(global, "Failed to open %s!\n", &nextarg[1]);
1689 err = file2memory(&string, &len, file);
1691 /* Allow strtok() here since this isn't used threaded */
1692 /* !checksrc! disable BANNEDFUNC 2 */
1693 char *h = strtok(string, "\r\n");
1695 if(subletter == 'p') /* --proxy-header */
1696 err = add2list(&config->proxyheaders, h);
1698 err = add2list(&config->headers, h);
1701 h = strtok(NULL, "\r\n");
1712 if(subletter == 'p') /* --proxy-header */
1713 err = add2list(&config->proxyheaders, nextarg);
1715 err = add2list(&config->headers, nextarg);
1721 config->include_headers = toggle; /* include the headers as well in the
1722 general output stream */
1725 config->cookiesession = toggle;
1729 * no_body will imply include_headers later on
1731 config->no_body = toggle;
1732 if(SetHTTPrequest(config,
1733 (config->no_body)?HTTPREQ_HEAD:HTTPREQ_GET,
1735 return PARAM_BAD_USE;
1737 case 'J': /* --remote-header-name */
1738 if(config->include_headers) {
1740 "--include and --remote-header-name cannot be combined.\n");
1741 return PARAM_BAD_USE;
1743 config->content_disposition = toggle;
1745 case 'k': /* allow insecure SSL connects */
1746 config->insecure_ok = toggle;
1748 case 'K': /* parse config file */
1749 if(parseconfig(nextarg, global))
1750 warnf(global, "error trying read config from the '%s' file\n",
1754 config->dirlistonly = toggle; /* only list the names of the FTP dir */
1757 config->followlocation = toggle; /* Follow Location: HTTP headers */
1760 /* Continue to send authentication (user+password) when following
1761 * locations, even when hostname changed */
1762 config->unrestricted_auth = toggle;
1767 /* specified max time */
1768 err = str2udouble(&config->timeout, nextarg, LONG_MAX/1000);
1772 case 'M': /* M for manual, huge help */
1773 if(toggle) { /* --no-manual shows no manual... */
1775 return PARAM_MANUAL_REQUESTED;
1778 "built-in manual was disabled at build-time!\n");
1779 return PARAM_OPTION_UNKNOWN;
1785 case 'o': /* CA info PEM file */
1786 /* use .netrc or URL */
1787 config->netrc_opt = toggle;
1789 case 'e': /* netrc-file */
1790 GetStr(&config->netrc_file, nextarg);
1793 /* pick info from .netrc, if this is used for http, curl will
1794 automatically enfore user+password with the request */
1795 config->netrc = toggle;
1800 /* disable the output I/O buffering. note that the option is called
1801 --buffer but is mostly used in the negative form: --no-buffer */
1803 config->nobuffer = (!toggle)?TRUE:FALSE;
1805 config->nobuffer = toggle;
1807 case 'O': /* --remote-name */
1808 if(subletter == 'a') { /* --remote-name-all */
1809 config->default_node_flags = toggle?GETOUT_USEREMOTE:0;
1813 case 'o': /* --output */
1817 if(!config->url_out)
1818 config->url_out = config->url_list;
1819 if(config->url_out) {
1820 /* there's a node here, if it already is filled-in continue to find
1822 while(config->url_out && (config->url_out->flags & GETOUT_OUTFILE))
1823 config->url_out = config->url_out->next;
1826 /* now there might or might not be an available node to fill in! */
1830 url = config->url_out;
1832 /* there was no free node, create one! */
1833 config->url_out = url = new_getout(config);
1836 return PARAM_NO_MEM;
1838 /* fill in the outfile */
1840 GetStr(&url->outfile, nextarg);
1841 url->flags &= ~GETOUT_USEREMOTE; /* switch off */
1844 url->outfile = NULL; /* leave it */
1846 url->flags |= GETOUT_USEREMOTE; /* switch on */
1848 url->flags &= ~GETOUT_USEREMOTE; /* switch off */
1850 url->flags |= GETOUT_OUTFILE;
1854 /* This makes the FTP sessions use PORT instead of PASV */
1855 /* use <eth0> or <192.168.10.10> style addresses. Anything except
1856 this will make us try to get the "default" address.
1857 NOTE: this is a changed behaviour since the released 4.1!
1859 GetStr(&config->ftpport, nextarg);
1862 /* proxy tunnel for non-http protocols */
1863 config->proxytunnel = toggle;
1866 case 'q': /* if used first, already taken care of, we do it like
1867 this so we don't cause an error! */
1870 /* QUOTE command to send to FTP server */
1871 switch(nextarg[0]) {
1873 /* prefixed with a dash makes it a POST TRANSFER one */
1875 err = add2list(&config->postquote, nextarg);
1878 /* prefixed with a plus makes it a just-before-transfer one */
1880 err = add2list(&config->prequote, nextarg);
1883 err = add2list(&config->quote, nextarg);
1890 /* Specifying a range WITHOUT A DASH will create an illegal HTTP range
1891 (and won't actually be range by definition). The man page previously
1892 claimed that to be a good way, why this code is added to work-around
1894 if(ISDIGIT(*nextarg) && !strchr(nextarg, '-')) {
1897 if(curlx_strtoofft(nextarg, NULL, 10, &off)) {
1898 warnf(global, "unsupported range point\n");
1899 return PARAM_BAD_USE;
1902 "A specified range MUST include at least one dash (-). "
1903 "Appending one for you!\n");
1904 snprintf(buffer, sizeof(buffer), "%" CURL_FORMAT_CURL_OFF_T "-", off);
1905 Curl_safefree(config->range);
1906 config->range = strdup(buffer);
1908 return PARAM_NO_MEM;
1911 /* byte range requested */
1913 tmp_range = nextarg;
1914 while(*tmp_range != '\0') {
1915 if(!ISDIGIT(*tmp_range) && *tmp_range != '-' && *tmp_range != ',') {
1916 warnf(global, "Invalid character is found in given range. "
1917 "A specified range MUST have only digits in "
1918 "\'start\'-\'stop\'. The server's response to this "
1919 "request is uncertain.\n");
1924 /* byte range requested */
1925 GetStr(&config->range, nextarg);
1929 /* use remote file's time */
1930 config->remote_time = toggle;
1933 /* don't show progress meter, don't show errors : */
1935 global->mute = global->noprogress = TRUE;
1937 global->mute = global->noprogress = FALSE;
1938 if(global->showerror < 0)
1939 /* if still on the default value, set showerror to the reverse of
1940 toggle. This is to allow -S and -s to be used in an independent
1941 order but still have the same effect. */
1942 global->showerror = (!toggle)?TRUE:FALSE; /* toggle off */
1946 global->showerror = toggle?1:0; /* toggle on if used with -s */
1949 /* Telnet options */
1950 err = add2list(&config->telnet_options, nextarg);
1955 /* we are uploading */
1959 config->url_ul = config->url_list;
1960 if(config->url_ul) {
1961 /* there's a node here, if it already is filled-in continue to find
1963 while(config->url_ul && (config->url_ul->flags & GETOUT_UPLOAD))
1964 config->url_ul = config->url_ul->next;
1967 /* now there might or might not be an available node to fill in! */
1971 url = config->url_ul;
1973 /* there was no free node, create one! */
1974 config->url_ul = url = new_getout(config);
1977 return PARAM_NO_MEM;
1979 url->flags |= GETOUT_UPLOAD; /* mark -T used */
1981 url->flags |= GETOUT_NOUPLOAD;
1983 /* "-" equals stdin, but keep the string around for now */
1984 GetStr(&url->infile, nextarg);
1990 GetStr(&config->userpwd, nextarg);
1994 /* Proxy user:password */
1995 GetStr(&config->proxyuserpwd, nextarg);
2000 /* the '%' thing here will cause the trace get sent to stderr */
2001 Curl_safefree(global->trace_dump);
2002 global->trace_dump = strdup("%");
2003 if(!global->trace_dump)
2004 return PARAM_NO_MEM;
2005 if(global->tracetype && (global->tracetype != TRACE_PLAIN))
2007 "-v, --verbose overrides an earlier trace/verbose option\n");
2008 global->tracetype = TRACE_PLAIN;
2011 /* verbose is disabled here */
2012 global->tracetype = TRACE_NONE;
2015 if(toggle) /* --no-version yields no output! */
2016 return PARAM_VERSION_INFO_REQUESTED;
2020 /* get the output string */
2021 if('@' == *nextarg) {
2022 /* the data begins with a '@' letter, it means that a file name
2023 or - (stdin) follows */
2026 nextarg++; /* pass the @ */
2027 if(!strcmp("-", nextarg)) {
2033 file = fopen(nextarg, FOPEN_READTEXT);
2035 err = file2string(&config->writeout, file);
2036 if(file && (file != stdin))
2040 if(!config->writeout)
2041 warnf(global, "Failed to read %s", fname);
2044 GetStr(&config->writeout, nextarg);
2048 case 'a': /* --preproxy */
2049 GetStr(&config->preproxy, nextarg);
2053 GetStr(&config->proxy, nextarg);
2054 config->proxyver = CURLPROXY_HTTP;
2059 /* set custom request */
2060 GetStr(&config->customrequest, nextarg);
2063 /* low speed time */
2064 err = str2unum(&config->low_speed_time, nextarg);
2067 if(!config->low_speed_limit)
2068 config->low_speed_limit = 1;
2071 /* low speed limit */
2072 err = str2unum(&config->low_speed_limit, nextarg);
2075 if(!config->low_speed_time)
2076 config->low_speed_time = 30;
2078 case 'z': /* time condition coming up */
2084 /* If-Modified-Since: (section 14.28 in RFC2068) */
2085 config->timecond = CURL_TIMECOND_IFMODSINCE;
2088 /* If-Unmodified-Since: (section 14.24 in RFC2068) */
2089 config->timecond = CURL_TIMECOND_IFUNMODSINCE;
2093 /* Last-Modified: (section 14.29 in RFC2068) */
2094 config->timecond = CURL_TIMECOND_LASTMOD;
2099 config->condtime = (curl_off_t)curl_getdate(nextarg, &now);
2100 if(-1 == config->condtime) {
2101 /* now let's see if it is a file name to get the time from instead! */
2102 curl_off_t filetime = getfiletime(nextarg, config->global->errors);
2104 /* pull the time out from the file */
2105 config->condtime = filetime;
2108 /* failed, remove time condition */
2109 config->timecond = CURL_TIMECOND_NONE;
2111 "Illegal date format for -z, --time-cond (and not "
2112 "a file name). Disabling time condition. "
2113 "See curl_getdate(3) for valid date syntax.\n");
2117 default: /* unknown flag */
2118 return PARAM_OPTION_UNKNOWN;
2122 } while(!longopt && !singleopt && *++parse && !*usedarg);
2127 ParameterError parse_args(struct GlobalConfig *config, int argc,
2132 char *orig_opt = NULL;
2133 ParameterError result = PARAM_OK;
2134 struct OperationConfig *operation = config->first;
2136 for(i = 1, stillflags = TRUE; i < argc && !result; i++) {
2139 if(stillflags && ('-' == argv[i][0])) {
2142 char *flag = argv[i];
2144 if(!strcmp("--", argv[i]))
2145 /* This indicates the end of the flags and thus enables the
2146 following (URL) argument to start with -. */
2149 nextarg = (i < (argc - 1)) ? argv[i + 1] : NULL;
2151 result = getparameter(flag, nextarg, &passarg, config, operation);
2152 if(result == PARAM_NEXT_OPERATION) {
2153 /* Reset result as PARAM_NEXT_OPERATION is only used here and not
2154 returned from this function */
2157 if(operation->url_list && operation->url_list->url) {
2158 /* Allocate the next config */
2159 operation->next = malloc(sizeof(struct OperationConfig));
2160 if(operation->next) {
2161 /* Initialise the newly created config */
2162 config_init(operation->next);
2164 /* Copy the easy handle */
2165 operation->next->easy = config->easy;
2167 /* Set the global config pointer */
2168 operation->next->global = config;
2170 /* Update the last operation pointer */
2171 config->last = operation->next;
2173 /* Move onto the new config */
2174 operation->next->prev = operation;
2175 operation = operation->next;
2178 result = PARAM_NO_MEM;
2181 else if(!result && passarg)
2182 i++; /* we're supposed to skip this */
2188 /* Just add the URL please */
2189 result = getparameter((char *)"--url", argv[i], &used, config,
2194 if(result && result != PARAM_HELP_REQUESTED &&
2195 result != PARAM_MANUAL_REQUESTED &&
2196 result != PARAM_VERSION_INFO_REQUESTED &&
2197 result != PARAM_ENGINES_REQUESTED) {
2198 const char *reason = param2text(result);
2200 if(orig_opt && strcmp(":", orig_opt))
2201 helpf(config->errors, "option %s: %s\n", orig_opt, reason);
2203 helpf(config->errors, "%s\n", reason);