1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2016, 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_formparse.h"
34 #include "tool_getparam.h"
35 #include "tool_helpers.h"
36 #include "tool_libinfo.h"
37 #include "tool_metalink.h"
38 #include "tool_msgs.h"
39 #include "tool_paramhlp.h"
40 #include "tool_parsecfg.h"
42 #include "memdebug.h" /* keep this as LAST include */
48 #define GetStr(str,val) do { \
54 *(str) = strdup((val)); \
56 return PARAM_NO_MEM; \
61 const char *letter; /* short name option */
62 const char *lname; /* long name option */
63 bool extraparam; /* whether it takes an additional argument */
66 static const struct LongShort aliases[]= {
67 /* 'letter' strings with more than one character have *no* short option to
70 {"*4", "dns-ipv4-addr", TRUE},
71 {"*6", "dns-ipv6-addr", TRUE},
72 {"*a", "random-file", TRUE},
73 {"*b", "egd-file", TRUE},
74 {"*B", "oauth2-bearer", TRUE},
75 {"*c", "connect-timeout", TRUE},
76 {"*d", "ciphers", TRUE},
77 {"*D", "dns-interface", TRUE},
78 {"*e", "disable-epsv", FALSE},
79 {"*E", "epsv", FALSE},
80 /* 'epsv' made like this to make --no-epsv and --epsv to work
81 although --disable-epsv is the documented option */
82 #ifdef USE_ENVIRONMENT
83 {"*f", "environment", FALSE},
85 {"*F", "dns-servers", TRUE},
86 {"*g", "trace", TRUE},
88 {"*h", "trace-ascii", TRUE},
89 {"*H", "alpn", FALSE},
90 {"*i", "limit-rate", TRUE},
91 {"*j", "compressed", FALSE},
92 {"*J", "tr-encoding", FALSE},
93 {"*k", "digest", FALSE},
94 {"*l", "negotiate", FALSE},
95 {"*m", "ntlm", FALSE},
96 {"*M", "ntlm-wb", FALSE},
97 {"*n", "basic", FALSE},
98 {"*o", "anyauth", FALSE},
100 {"*p", "wdebug", FALSE},
102 {"*q", "ftp-create-dirs", FALSE},
103 {"*r", "create-dirs", FALSE},
104 {"*s", "max-redirs", TRUE},
105 {"*t", "proxy-ntlm", FALSE},
106 {"*u", "crlf", FALSE},
107 {"*v", "stderr", TRUE},
108 {"*w", "interface", TRUE},
110 {"*x", "krb4", TRUE},
111 /* 'krb4' is the previous name */
112 {"*y", "max-filesize", TRUE},
113 {"*z", "disable-eprt", FALSE},
114 {"*Z", "eprt", FALSE},
115 /* 'eprt' made like this to make --no-eprt and --eprt to work
116 although --disable-eprt is the documented option */
117 {"*~", "xattr", FALSE},
118 {"$a", "ftp-ssl", FALSE},
119 /* 'ftp-ssl' deprecated name since 7.20.0 */
120 {"$a", "ssl", FALSE},
121 /* 'ssl' new option name in 7.20.0, previously this was ftp-ssl */
122 {"$b", "ftp-pasv", FALSE},
123 {"$c", "socks5", TRUE},
124 {"$d", "tcp-nodelay", FALSE},
125 {"$e", "proxy-digest", FALSE},
126 {"$f", "proxy-basic", FALSE},
127 {"$g", "retry", TRUE},
128 {"$V", "retry-connrefused", FALSE},
129 {"$h", "retry-delay", TRUE},
130 {"$i", "retry-max-time", TRUE},
131 {"$k", "proxy-negotiate", FALSE},
132 {"$m", "ftp-account", TRUE},
133 {"$n", "proxy-anyauth", FALSE},
134 {"$o", "trace-time", FALSE},
135 {"$p", "ignore-content-length", FALSE},
136 {"$q", "ftp-skip-pasv-ip", FALSE},
137 {"$r", "ftp-method", TRUE},
138 {"$s", "local-port", TRUE},
139 {"$t", "socks4", TRUE},
140 {"$T", "socks4a", TRUE},
141 {"$u", "ftp-alternative-to-user", TRUE},
142 {"$v", "ftp-ssl-reqd", FALSE},
143 /* 'ftp-ssl-reqd' deprecated name since 7.20.0 */
144 {"$v", "ssl-reqd", FALSE},
145 /* 'ssl-reqd' new in 7.20.0, previously this was ftp-ssl-reqd */
146 {"$w", "sessionid", FALSE},
147 /* 'sessionid' listed as --no-sessionid in the help */
148 {"$x", "ftp-ssl-control", FALSE},
149 {"$y", "ftp-ssl-ccc", FALSE},
150 {"$j", "ftp-ssl-ccc-mode", TRUE},
151 {"$z", "libcurl", TRUE},
152 {"$#", "raw", FALSE},
153 {"$0", "post301", FALSE},
154 {"$1", "keepalive", FALSE},
155 /* 'keepalive' listed as --no-keepalive in the help */
156 {"$2", "socks5-hostname", TRUE},
157 {"$3", "keepalive-time", TRUE},
158 {"$4", "post302", FALSE},
159 {"$5", "noproxy", TRUE},
160 {"$7", "socks5-gssapi-nec", FALSE},
161 {"$8", "proxy1.0", TRUE},
162 {"$9", "tftp-blksize", TRUE},
163 {"$A", "mail-from", TRUE},
164 {"$B", "mail-rcpt", TRUE},
165 {"$C", "ftp-pret", FALSE},
166 {"$D", "proto", TRUE},
167 {"$E", "proto-redir", TRUE},
168 {"$F", "resolve", TRUE},
169 {"$G", "delegation", TRUE},
170 {"$H", "mail-auth", TRUE},
171 {"$I", "post303", FALSE},
172 {"$J", "metalink", FALSE},
173 {"$K", "sasl-ir", FALSE},
174 {"$L", "test-event", FALSE},
175 {"$M", "unix-socket", TRUE},
176 {"$N", "path-as-is", FALSE},
177 {"$O", "socks5-gssapi-service", TRUE},
178 /* 'socks5-gssapi-service' merged with'proxy-service-name' and
179 deprecated since 7.49.0 */
180 {"$O", "proxy-service-name", TRUE},
181 {"$P", "service-name", TRUE},
182 {"$Q", "proto-default", TRUE},
183 {"$R", "expect100-timeout", TRUE},
184 {"$S", "tftp-no-options", FALSE},
185 {"$U", "connect-to", TRUE},
186 {"$W", "abstract-unix-socket", TRUE},
187 {"0", "http1.0", FALSE},
188 {"01", "http1.1", FALSE},
189 {"02", "http2", FALSE},
190 {"03", "http2-prior-knowledge", FALSE},
191 {"1", "tlsv1", FALSE},
192 {"10", "tlsv1.0", FALSE},
193 {"11", "tlsv1.1", FALSE},
194 {"12", "tlsv1.2", FALSE},
195 {"13", "tlsv1.3", FALSE},
196 {"2", "sslv2", FALSE},
197 {"3", "sslv3", FALSE},
198 {"4", "ipv4", FALSE},
199 {"6", "ipv6", FALSE},
200 {"a", "append", FALSE},
201 {"A", "user-agent", TRUE},
202 {"b", "cookie", TRUE},
203 {"B", "use-ascii", FALSE},
204 {"c", "cookie-jar", TRUE},
205 {"C", "continue-at", TRUE},
207 {"dr", "data-raw", TRUE},
208 {"da", "data-ascii", TRUE},
209 {"db", "data-binary", TRUE},
210 {"de", "data-urlencode", TRUE},
211 {"D", "dump-header", TRUE},
212 {"e", "referer", TRUE},
214 {"Ea", "cacert", TRUE},
215 {"Eb", "cert-type", TRUE},
217 {"Ed", "key-type", TRUE},
218 {"Ee", "pass", TRUE},
219 {"Ef", "engine", TRUE},
220 {"Eg", "capath", TRUE},
221 {"Eh", "pubkey", TRUE},
222 {"Ei", "hostpubmd5", TRUE},
223 {"Ej", "crlfile", TRUE},
224 {"Ek", "tlsuser", TRUE},
225 {"El", "tlspassword", TRUE},
226 {"Em", "tlsauthtype", TRUE},
227 {"En", "ssl-allow-beast", FALSE},
228 {"Eo", "login-options", TRUE},
229 {"Ep", "pinnedpubkey", TRUE},
230 {"Eq", "cert-status", FALSE},
231 {"Er", "false-start", FALSE},
232 {"Es", "ssl-no-revoke", FALSE},
233 {"Et", "tcp-fastopen", FALSE},
234 {"Eu", "proxy-tlsuser", TRUE},
235 {"Ev", "proxy-tlspassword", TRUE},
236 {"Ew", "proxy-tlsauthtype", TRUE},
237 {"Ex", "proxy-cert", TRUE},
238 {"Ey", "proxy-cert-type", TRUE},
239 {"Ez", "proxy-key", TRUE},
240 {"E0", "proxy-key-type", TRUE},
241 {"E1", "proxy-pass", TRUE},
242 {"E2", "proxy-ciphers", TRUE},
243 {"E3", "proxy-crlfile", TRUE},
244 {"E4", "proxy-ssl-allow-beast", FALSE},
245 {"E5", "login-options", TRUE},
246 {"E6", "proxy-cacert", TRUE},
247 {"E7", "proxy-capath", TRUE},
248 {"E8", "proxy-insecure", FALSE},
249 {"E9", "proxy-tlsv1", FALSE},
250 {"f", "fail", FALSE},
251 {"fa", "fail-early", FALSE},
253 {"Fs", "form-string", TRUE},
254 {"g", "globoff", FALSE},
256 {"h", "help", FALSE},
257 {"H", "header", TRUE},
258 {"Hp", "proxy-header", TRUE},
259 {"i", "include", FALSE},
260 {"I", "head", FALSE},
261 {"j", "junk-session-cookies", FALSE},
262 {"J", "remote-header-name", FALSE},
263 {"k", "insecure", FALSE},
264 {"K", "config", TRUE},
265 {"l", "list-only", FALSE},
266 {"L", "location", FALSE},
267 {"Lt", "location-trusted", FALSE},
268 {"m", "max-time", TRUE},
269 {"M", "manual", FALSE},
270 {"n", "netrc", FALSE},
271 {"no", "netrc-optional", FALSE},
272 {"ne", "netrc-file", TRUE},
273 {"N", "buffer", FALSE},
274 /* 'buffer' listed as --no-buffer in the help */
275 {"o", "output", TRUE},
276 {"O", "remote-name", FALSE},
277 {"Oa", "remote-name-all", FALSE},
278 {"p", "proxytunnel", FALSE},
279 {"P", "ftp-port", TRUE},
280 {"q", "disable", FALSE},
281 {"Q", "quote", TRUE},
282 {"r", "range", TRUE},
283 {"R", "remote-time", FALSE},
284 {"s", "silent", FALSE},
285 {"S", "show-error", FALSE},
286 {"t", "telnet-option", TRUE},
287 {"T", "upload-file", TRUE},
289 {"U", "proxy-user", TRUE},
290 {"v", "verbose", FALSE},
291 {"V", "version", FALSE},
292 {"w", "write-out", TRUE},
293 {"x", "proxy", TRUE},
294 {"xa", "preproxy", TRUE},
295 {"X", "request", TRUE},
296 {"Y", "speed-limit", TRUE},
297 {"y", "speed-time", TRUE},
298 {"z", "time-cond", TRUE},
299 {"#", "progress-bar", FALSE},
300 {":", "next", FALSE},
303 /* Split the argument of -E to 'certname' and 'passphrase' separated by colon.
304 * We allow ':' and '\' to be escaped by '\' so that we can use certificate
305 * nicknames containing ':'. See <https://sourceforge.net/p/curl/bugs/1196/>
310 void parse_cert_parameter(const char *cert_parameter,
314 size_t param_length = strlen(cert_parameter);
316 const char *param_place = NULL;
317 char *certname_place = NULL;
321 /* most trivial assumption: cert_parameter is empty */
322 if(param_length == 0)
325 /* next less trivial: cert_parameter starts 'pkcs11:' and thus
326 * looks like a RFC7512 PKCS#11 URI which can be used as-is.
327 * Also if cert_parameter contains no colon nor backslash, this
328 * means no passphrase was given and no characters escaped */
329 if(!strncmp(cert_parameter, "pkcs11:", 7) ||
330 !strpbrk(cert_parameter, ":\\")) {
331 *certname = strdup(cert_parameter);
334 /* deal with escaped chars; find unescaped colon if it exists */
335 certname_place = malloc(param_length + 1);
339 *certname = certname_place;
340 param_place = cert_parameter;
341 while(*param_place) {
342 span = strcspn(param_place, ":\\");
343 strncpy(certname_place, param_place, span);
345 certname_place += span;
346 /* we just ate all the non-special chars. now we're on either a special
347 * char or the end of the string. */
348 switch(*param_place) {
353 switch(*param_place) {
355 *certname_place++ = '\\';
358 *certname_place++ = '\\';
362 *certname_place++ = ':';
366 *certname_place++ = '\\';
367 *certname_place++ = *param_place;
373 /* Since we live in a world of weirdness and confusion, the win32
374 dudes can use : when using drive letters and thus c:\file:password
375 needs to work. In order not to break compatibility, we still use : as
376 separator, but we try to detect when it is used for a file name! On
380 (param_place == &cert_parameter[1]) &&
381 (cert_parameter[2] == '\\' || cert_parameter[2] == '/') &&
382 (ISALPHA(cert_parameter[0])) ) {
383 /* colon in the second column, followed by a backslash, and the
384 first character is an alphabetic letter:
386 this is a drive letter colon */
387 *certname_place++ = ':';
392 /* escaped colons and Windows drive letter colons were handled
393 * above; if we're still here, this is a separating colon */
395 if(strlen(param_place) > 0) {
396 *passphrase = strdup(param_place);
402 *certname_place = '\0';
406 GetFileAndPassword(char *nextarg, char **file, char **password)
408 char *certname, *passphrase;
409 parse_cert_parameter(nextarg, &certname, &passphrase);
410 Curl_safefree(*file);
413 Curl_safefree(*password);
414 *password = passphrase;
419 ParameterError getparameter(char *flag, /* f or -long-flag */
420 char *nextarg, /* NULL if unset */
421 bool *usedarg, /* set to TRUE if the arg
423 struct GlobalConfig *global,
424 struct OperationConfig *config)
427 char subletter = '\0'; /* subletters can only occur on long options */
429 const char *parse = NULL;
433 bool longopt = FALSE;
434 bool singleopt = FALSE; /* when true means '-o foo' used '-ofoo' */
436 bool toggle = TRUE; /* how to switch boolean options, on or off. Controlled
437 by using --OPTION or --no-OPTION */
440 if(('-' != flag[0]) ||
441 (('-' == flag[0]) && ('-' == flag[1]))) {
442 /* this should be a long name */
443 char *word = ('-' == flag[0]) ? flag+2 : flag;
444 size_t fnam = strlen(word);
447 if(!strncmp(word, "no-", 3)) {
448 /* disable this option but ignore the "no-" part when looking for it */
453 for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) {
454 if(curl_strnequal(aliases[j].lname, word, fnam)) {
457 if(curl_strequal(aliases[j].lname, word)) {
458 parse = aliases[j].letter;
460 numhits = 1; /* a single unique hit */
463 parse = aliases[j].letter;
468 /* this is at least the second match! */
469 return PARAM_OPTION_AMBIGUOUS;
472 return PARAM_OPTION_UNKNOWN;
476 flag++; /* prefixed with one dash, pass it */
482 /* we can loop here if we have multiple single-letters */
485 letter = (char)*parse;
490 subletter = parse[1];
492 *usedarg = FALSE; /* default is that we don't use the arg */
495 for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) {
496 if(letter == aliases[j].letter[0]) {
502 return PARAM_OPTION_UNKNOWN;
506 if(aliases[hit].extraparam) {
507 /* this option requires an extra parameter */
508 if(!longopt && parse[1]) {
509 nextarg = (char *)&parse[1]; /* this is the actual extra parameter */
510 singleopt = TRUE; /* don't loop anymore after this */
513 return PARAM_REQUIRES_PARAMETER;
515 *usedarg = TRUE; /* mark it as used */
519 case '*': /* options without a short option */
521 case '4': /* --dns-ipv4-addr */
522 /* addr in dot notation */
523 GetStr(&config->dns_ipv4_addr, nextarg);
525 case '6': /* --dns-ipv6-addr */
526 /* addr in dot notation */
527 GetStr(&config->dns_ipv6_addr, nextarg);
529 case 'a': /* random-file */
530 GetStr(&config->random_file, nextarg);
532 case 'b': /* egd-file */
533 GetStr(&config->egd_file, nextarg);
535 case 'B': /* OAuth 2.0 bearer token */
536 GetStr(&config->oauth_bearer, nextarg);
538 case 'c': /* connect-timeout */
539 err = str2udouble(&config->connecttimeout, nextarg);
543 case 'd': /* ciphers */
544 GetStr(&config->cipher_list, nextarg);
546 case 'D': /* --dns-interface */
548 GetStr(&config->dns_interface, nextarg);
550 case 'e': /* --disable-epsv */
551 config->disable_epsv = toggle;
553 case 'E': /* --epsv */
554 config->disable_epsv = (!toggle)?TRUE:FALSE;
556 #ifdef USE_ENVIRONMENT
558 config->writeenv = toggle;
561 case 'F': /* --dns-servers */
562 /* IP addrs of DNS servers */
563 GetStr(&config->dns_servers, nextarg);
565 case 'g': /* --trace */
566 GetStr(&global->trace_dump, nextarg);
567 if(global->tracetype && (global->tracetype != TRACE_BIN))
568 warnf(global, "--trace overrides an earlier trace/verbose option\n");
569 global->tracetype = TRACE_BIN;
571 case 'G': /* --npn */
572 config->nonpn = (!toggle)?TRUE:FALSE;
574 case 'h': /* --trace-ascii */
575 GetStr(&global->trace_dump, nextarg);
576 if(global->tracetype && (global->tracetype != TRACE_ASCII))
578 "--trace-ascii overrides an earlier trace/verbose option\n");
579 global->tracetype = TRACE_ASCII;
581 case 'H': /* --alpn */
582 config->noalpn = (!toggle)?TRUE:FALSE;
584 case 'i': /* --limit-rate */
586 /* We support G, M, K too */
588 curl_off_t value = curlx_strtoofft(nextarg, &unit, 0);
592 else if(strlen(unit) > 1)
593 unit = (char *)"w"; /* unsupported */
598 value *= 1024*1024*1024;
610 /* for plain bytes, leave as-is */
613 warnf(global, "unsupported rate unit. Use G, M, K or B!\n");
614 return PARAM_BAD_USE;
616 config->recvpersecond = value;
617 config->sendpersecond = value;
621 case 'j': /* --compressed */
622 if(toggle && !(curlinfo->features & CURL_VERSION_LIBZ))
623 return PARAM_LIBCURL_DOESNT_SUPPORT;
624 config->encoding = toggle;
627 case 'J': /* --tr-encoding */
628 config->tr_encoding = toggle;
631 case 'k': /* --digest */
633 config->authtype |= CURLAUTH_DIGEST;
635 config->authtype &= ~CURLAUTH_DIGEST;
638 case 'l': /* --negotiate */
640 if(curlinfo->features & CURL_VERSION_SPNEGO)
641 config->authtype |= CURLAUTH_NEGOTIATE;
643 return PARAM_LIBCURL_DOESNT_SUPPORT;
646 config->authtype &= ~CURLAUTH_NEGOTIATE;
649 case 'm': /* --ntlm */
651 if(curlinfo->features & CURL_VERSION_NTLM)
652 config->authtype |= CURLAUTH_NTLM;
654 return PARAM_LIBCURL_DOESNT_SUPPORT;
657 config->authtype &= ~CURLAUTH_NTLM;
660 case 'M': /* --ntlm-wb */
662 if(curlinfo->features & CURL_VERSION_NTLM_WB)
663 config->authtype |= CURLAUTH_NTLM_WB;
665 return PARAM_LIBCURL_DOESNT_SUPPORT;
668 config->authtype &= ~CURLAUTH_NTLM_WB;
671 case 'n': /* --basic for completeness */
673 config->authtype |= CURLAUTH_BASIC;
675 config->authtype &= ~CURLAUTH_BASIC;
678 case 'o': /* --anyauth, let libcurl pick it */
680 config->authtype = CURLAUTH_ANY;
681 /* --no-anyauth simply doesn't touch it */
685 case 'p': /* --wdebug */
689 case 'q': /* --ftp-create-dirs */
690 config->ftp_create_dirs = toggle;
693 case 'r': /* --create-dirs */
694 config->create_dirs = toggle;
697 case 's': /* --max-redirs */
698 /* specified max no of redirects (http(s)), this accepts -1 as a
700 err = str2num(&config->maxredirs, nextarg);
703 if(config->maxredirs < -1)
704 return PARAM_BAD_NUMERIC;
707 case 't': /* --proxy-ntlm */
708 if(curlinfo->features & CURL_VERSION_NTLM)
709 config->proxyntlm = toggle;
711 return PARAM_LIBCURL_DOESNT_SUPPORT;
714 case 'u': /* --crlf */
715 /* LF -> CRLF conversion? */
716 config->crlf = toggle;
719 case 'v': /* --stderr */
720 if(strcmp(nextarg, "-")) {
721 FILE *newfile = fopen(nextarg, FOPEN_WRITETEXT);
723 warnf(global, "Failed to open %s!\n", nextarg);
725 if(global->errors_fopened)
726 fclose(global->errors);
727 global->errors = newfile;
728 global->errors_fopened = TRUE;
732 global->errors = stdout;
734 case 'w': /* --interface */
736 GetStr(&config->iface, nextarg);
738 case 'x': /* --krb */
739 /* kerberos level string */
740 if(curlinfo->features & CURL_VERSION_KERBEROS4)
741 GetStr(&config->krblevel, nextarg);
743 return PARAM_LIBCURL_DOESNT_SUPPORT;
745 case 'y': /* --max-filesize */
746 err = str2offset(&config->max_filesize, nextarg);
750 case 'z': /* --disable-eprt */
751 config->disable_eprt = toggle;
753 case 'Z': /* --eprt */
754 config->disable_eprt = (!toggle)?TRUE:FALSE;
756 case '~': /* --xattr */
757 config->xattr = toggle;
759 case '@': /* the URL! */
764 config->url_get = config->url_list;
766 if(config->url_get) {
767 /* there's a node here, if it already is filled-in continue to find
769 while(config->url_get && (config->url_get->flags & GETOUT_URL))
770 config->url_get = config->url_get->next;
773 /* now there might or might not be an available node to fill in! */
777 url = config->url_get;
779 /* there was no free node, create one! */
780 url = new_getout(config);
785 /* fill in the URL */
786 GetStr(&url->url, nextarg);
787 url->flags |= GETOUT_URL;
792 case '$': /* more options without a short option */
794 case 'a': /* --ssl */
795 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
796 return PARAM_LIBCURL_DOESNT_SUPPORT;
797 config->ftp_ssl = toggle;
799 case 'b': /* --ftp-pasv */
800 Curl_safefree(config->ftpport);
802 case 'c': /* --socks5 specifies a socks5 proxy to use, and resolves
803 the name locally and passes on the resolved address */
804 GetStr(&config->proxy, nextarg);
805 config->proxyver = CURLPROXY_SOCKS5;
807 case 't': /* --socks4 specifies a socks4 proxy to use */
808 GetStr(&config->proxy, nextarg);
809 config->proxyver = CURLPROXY_SOCKS4;
811 case 'T': /* --socks4a specifies a socks4a proxy to use */
812 GetStr(&config->proxy, nextarg);
813 config->proxyver = CURLPROXY_SOCKS4A;
815 case '2': /* --socks5-hostname specifies a socks5 proxy and enables name
816 resolving with the proxy */
817 GetStr(&config->proxy, nextarg);
818 config->proxyver = CURLPROXY_SOCKS5_HOSTNAME;
820 case 'd': /* --tcp-nodelay option */
821 config->tcp_nodelay = toggle;
823 case 'e': /* --proxy-digest */
824 config->proxydigest = toggle;
826 case 'f': /* --proxy-basic */
827 config->proxybasic = toggle;
829 case 'g': /* --retry */
830 err = str2unum(&config->req_retry, nextarg);
834 case 'V': /* --retry-connrefused */
835 config->retry_connrefused = toggle;
837 case 'h': /* --retry-delay */
838 err = str2unum(&config->retry_delay, nextarg);
842 case 'i': /* --retry-max-time */
843 err = str2unum(&config->retry_maxtime, nextarg);
848 case 'k': /* --proxy-negotiate */
849 if(curlinfo->features & CURL_VERSION_SPNEGO)
850 config->proxynegotiate = toggle;
852 return PARAM_LIBCURL_DOESNT_SUPPORT;
855 case 'm': /* --ftp-account */
856 GetStr(&config->ftp_account, nextarg);
858 case 'n': /* --proxy-anyauth */
859 config->proxyanyauth = toggle;
861 case 'o': /* --trace-time */
862 global->tracetime = toggle;
864 case 'p': /* --ignore-content-length */
865 config->ignorecl = toggle;
867 case 'q': /* --ftp-skip-pasv-ip */
868 config->ftp_skip_ip = toggle;
870 case 'r': /* --ftp-method (undocumented at this point) */
871 config->ftp_filemethod = ftpfilemethod(config, nextarg);
873 case 's': /* --local-port */
874 rc = sscanf(nextarg, "%d - %d",
876 &config->localportrange);
878 return PARAM_BAD_USE;
880 config->localportrange = 1; /* default number of ports to try */
882 config->localportrange -= config->localport;
883 if(config->localportrange < 1) {
884 warnf(global, "bad range input\n");
885 return PARAM_BAD_USE;
889 case 'u': /* --ftp-alternative-to-user */
890 GetStr(&config->ftp_alternative_to_user, nextarg);
892 case 'v': /* --ssl-reqd */
893 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
894 return PARAM_LIBCURL_DOESNT_SUPPORT;
895 config->ftp_ssl_reqd = toggle;
897 case 'w': /* --no-sessionid */
898 config->disable_sessionid = (!toggle)?TRUE:FALSE;
900 case 'x': /* --ftp-ssl-control */
901 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
902 return PARAM_LIBCURL_DOESNT_SUPPORT;
903 config->ftp_ssl_control = toggle;
905 case 'y': /* --ftp-ssl-ccc */
906 config->ftp_ssl_ccc = toggle;
907 if(!config->ftp_ssl_ccc_mode)
908 config->ftp_ssl_ccc_mode = CURLFTPSSL_CCC_PASSIVE;
910 case 'j': /* --ftp-ssl-ccc-mode */
911 config->ftp_ssl_ccc = TRUE;
912 config->ftp_ssl_ccc_mode = ftpcccmethod(config, nextarg);
914 case 'z': /* --libcurl */
915 #ifdef CURL_DISABLE_LIBCURL_OPTION
917 "--libcurl option was disabled at build-time!\n");
918 return PARAM_OPTION_UNKNOWN;
920 GetStr(&global->libcurl, nextarg);
923 case '#': /* --raw */
924 config->raw = toggle;
926 case '0': /* --post301 */
927 config->post301 = toggle;
929 case '1': /* --no-keepalive */
930 config->nokeepalive = (!toggle)?TRUE:FALSE;
932 case '3': /* --keepalive-time */
933 err = str2unum(&config->alivetime, nextarg);
937 case '4': /* --post302 */
938 config->post302 = toggle;
940 case 'I': /* --post303 */
941 config->post303 = toggle;
943 case '5': /* --noproxy */
944 /* This specifies the noproxy list */
945 GetStr(&config->noproxy, nextarg);
947 case '7': /* --socks5-gssapi-nec*/
948 config->socks5_gssapi_nec = toggle;
950 case '8': /* --proxy1.0 */
952 GetStr(&config->proxy, nextarg);
953 config->proxyver = CURLPROXY_HTTP_1_0;
955 case '9': /* --tftp-blksize */
956 err = str2unum(&config->tftp_blksize, nextarg);
960 case 'A': /* --mail-from */
961 GetStr(&config->mail_from, nextarg);
963 case 'B': /* --mail-rcpt */
964 /* append receiver to a list */
965 err = add2list(&config->mail_rcpt, nextarg);
969 case 'C': /* --ftp-pret */
970 config->ftp_pret = toggle;
972 case 'D': /* --proto */
973 config->proto_present = TRUE;
974 if(proto2num(config, &config->proto, nextarg))
975 return PARAM_BAD_USE;
977 case 'E': /* --proto-redir */
978 config->proto_redir_present = TRUE;
979 if(proto2num(config, &config->proto_redir, nextarg))
980 return PARAM_BAD_USE;
982 case 'F': /* --resolve */
983 err = add2list(&config->resolve, nextarg);
987 case 'G': /* --delegation LEVEL */
988 config->gssapi_delegation = delegation(config, nextarg);
990 case 'H': /* --mail-auth */
991 GetStr(&config->mail_auth, nextarg);
993 case 'J': /* --metalink */
996 int mlmaj, mlmin, mlpatch;
997 metalink_get_version(&mlmaj, &mlmin, &mlpatch);
998 if((mlmaj*10000)+(mlmin*100)+mlpatch < CURL_REQ_LIBMETALINK_VERS) {
1000 "--metalink option cannot be used because the version of "
1001 "the linked libmetalink library is too old. "
1002 "Required: %d.%d.%d, found %d.%d.%d\n",
1003 CURL_REQ_LIBMETALINK_MAJOR,
1004 CURL_REQ_LIBMETALINK_MINOR,
1005 CURL_REQ_LIBMETALINK_PATCH,
1006 mlmaj, mlmin, mlpatch);
1007 return PARAM_BAD_USE;
1010 config->use_metalink = toggle;
1012 warnf(global, "--metalink option is ignored because the binary is "
1013 "built without the Metalink support.\n");
1017 case 'K': /* --sasl-ir */
1018 config->sasl_ir = toggle;
1020 case 'L': /* --test-event */
1022 config->test_event_based = toggle;
1024 warnf(global, "--test-event is ignored unless a debug build!\n");
1027 case 'M': /* --unix-socket */
1028 config->abstract_unix_socket = FALSE;
1029 GetStr(&config->unix_socket_path, nextarg);
1031 case 'N': /* --path-as-is */
1032 config->path_as_is = toggle;
1034 case 'O': /* --proxy-service-name */
1035 GetStr(&config->proxy_service_name, nextarg);
1037 case 'P': /* --service-name */
1038 GetStr(&config->service_name, nextarg);
1040 case 'Q': /* --proto-default */
1041 GetStr(&config->proto_default, nextarg);
1042 err = check_protocol(config->proto_default);
1046 case 'R': /* --expect100-timeout */
1047 err = str2udouble(&config->expect100timeout, nextarg);
1051 case 'S': /* --tftp-no-options */
1052 config->tftp_no_options = toggle;
1054 case 'U': /* --connect-to */
1055 err = add2list(&config->connect_to, nextarg);
1059 case 'W': /* --abstract-unix-socket */
1060 config->abstract_unix_socket = TRUE;
1061 GetStr(&config->unix_socket_path, nextarg);
1065 case '#': /* --progress-bar */
1067 global->progressmode = CURL_PROGRESS_BAR;
1069 global->progressmode = CURL_PROGRESS_STATS;
1071 case ':': /* --next */
1072 return PARAM_NEXT_OPERATION;
1073 case '0': /* --http* options */
1076 /* HTTP version 1.0 */
1077 config->httpversion = CURL_HTTP_VERSION_1_0;
1080 /* HTTP version 1.1 */
1081 config->httpversion = CURL_HTTP_VERSION_1_1;
1084 /* HTTP version 2.0 */
1085 config->httpversion = CURL_HTTP_VERSION_2_0;
1088 /* HTTP version 2.0 over clean TCP*/
1089 config->httpversion = CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE;
1093 case '1': /* --tlsv1* options */
1096 /* TLS version 1.x */
1097 config->ssl_version = CURL_SSLVERSION_TLSv1;
1100 /* TLS version 1.0 */
1101 config->ssl_version = CURL_SSLVERSION_TLSv1_0;
1104 /* TLS version 1.1 */
1105 config->ssl_version = CURL_SSLVERSION_TLSv1_1;
1108 /* TLS version 1.2 */
1109 config->ssl_version = CURL_SSLVERSION_TLSv1_2;
1112 /* TLS version 1.3 */
1113 config->ssl_version = CURL_SSLVERSION_TLSv1_3;
1119 config->ssl_version = CURL_SSLVERSION_SSLv2;
1123 config->ssl_version = CURL_SSLVERSION_SSLv3;
1127 config->ip_version = 4;
1131 config->ip_version = 6;
1134 /* This makes the FTP sessions use APPE instead of STOR */
1135 config->ftp_append = toggle;
1138 /* This specifies the User-Agent name */
1139 GetStr(&config->useragent, nextarg);
1141 case 'b': /* cookie string coming up: */
1142 if(nextarg[0] == '@') {
1145 else if(strchr(nextarg, '=')) {
1146 /* A cookie string must have a =-letter */
1147 GetStr(&config->cookie, nextarg);
1150 /* We have a cookie file to read from! */
1151 GetStr(&config->cookiefile, nextarg);
1154 /* use ASCII/text when transferring */
1155 config->use_ascii = toggle;
1158 /* get the file name to dump all cookies in */
1159 GetStr(&config->cookiejar, nextarg);
1162 /* This makes us continue an ftp transfer at given position */
1163 if(strcmp(nextarg, "-")) {
1164 err = str2offset(&config->resume_from, nextarg);
1167 config->resume_from_current = FALSE;
1170 config->resume_from_current = TRUE;
1171 config->resume_from = 0;
1173 config->use_resume=TRUE;
1176 /* postfield data */
1178 char *postdata = NULL;
1181 bool raw_mode = (subletter == 'r');
1183 if(subletter == 'e') { /* --data-urlencode*/
1184 /* [name]=[content], we encode the content part only
1185 * [name]@[file name]
1187 * Case 2: we first load the file using that name and then encode
1190 const char *p = strchr(nextarg, '=');
1194 /* there was no '=' letter, check for a '@' instead */
1195 p = strchr(nextarg, '@');
1197 nlen = p - nextarg; /* length of the name part */
1198 is_file = *p++; /* pass the separator */
1201 /* neither @ nor =, so no name and it isn't a file */
1205 if('@' == is_file) {
1206 /* a '@' letter, it means that a file name or - (stdin) follows */
1207 if(!strcmp("-", p)) {
1212 file = fopen(p, "rb");
1215 "Couldn't read data from file \"%s\", this makes "
1216 "an empty POST.\n", nextarg);
1219 err = file2memory(&postdata, &size, file);
1221 if(file && (file != stdin))
1227 GetStr(&postdata, p);
1229 size = strlen(postdata);
1233 /* no data from the file, point to a zero byte string to make this
1234 get sent as a POST anyway */
1235 postdata = strdup("");
1237 return PARAM_NO_MEM;
1241 char *enc = curl_easy_escape(config->easy, postdata, (int)size);
1242 Curl_safefree(postdata); /* no matter if it worked or not */
1244 /* now make a string with the name from above and append the
1246 size_t outlen = nlen + strlen(enc) + 2;
1247 char *n = malloc(outlen);
1250 return PARAM_NO_MEM;
1252 if(nlen > 0) { /* only append '=' if we have a name */
1253 snprintf(n, outlen, "%.*s=%s", nlen, nextarg, enc);
1258 size = outlen-2; /* since no '=' was inserted */
1264 return PARAM_NO_MEM;
1267 else if('@' == *nextarg && !raw_mode) {
1268 /* the data begins with a '@' letter, it means that a file name
1269 or - (stdin) follows */
1270 nextarg++; /* pass the @ */
1272 if(!strcmp("-", nextarg)) {
1274 if(subletter == 'b') /* forced data-binary */
1278 file = fopen(nextarg, "rb");
1280 warnf(global, "Couldn't read data from file \"%s\", this makes "
1281 "an empty POST.\n", nextarg);
1284 if(subletter == 'b')
1286 err = file2memory(&postdata, &size, file);
1288 err = file2string(&postdata, file);
1290 size = strlen(postdata);
1293 if(file && (file != stdin))
1299 /* no data from the file, point to a zero byte string to make this
1300 get sent as a POST anyway */
1301 postdata = strdup("");
1303 return PARAM_NO_MEM;
1307 GetStr(&postdata, nextarg);
1309 size = strlen(postdata);
1312 #ifdef CURL_DOES_CONVERSIONS
1313 if(subletter != 'b') {
1314 /* NOT forced binary, convert to ASCII */
1315 if(convert_to_network(postdata, strlen(postdata))) {
1316 Curl_safefree(postdata);
1317 return PARAM_NO_MEM;
1322 if(config->postfields) {
1323 /* we already have a string, we append this one with a separating
1325 char *oldpost = config->postfields;
1326 curl_off_t oldlen = config->postfieldsize;
1327 curl_off_t newlen = oldlen + curlx_uztoso(size) + 2;
1328 config->postfields = malloc((size_t)newlen);
1329 if(!config->postfields) {
1330 Curl_safefree(oldpost);
1331 Curl_safefree(postdata);
1332 return PARAM_NO_MEM;
1334 memcpy(config->postfields, oldpost, (size_t)oldlen);
1335 /* use byte value 0x26 for '&' to accommodate non-ASCII platforms */
1336 config->postfields[oldlen] = '\x26';
1337 memcpy(&config->postfields[oldlen+1], postdata, size);
1338 config->postfields[oldlen+1+size] = '\0';
1339 Curl_safefree(oldpost);
1340 Curl_safefree(postdata);
1341 config->postfieldsize += size+1;
1344 config->postfields = postdata;
1345 config->postfieldsize = curlx_uztoso(size);
1349 We can't set the request type here, as this data might be used in
1350 a simple GET if -G is used. Already or soon.
1352 if(SetHTTPrequest(HTTPREQ_SIMPLEPOST, &config->httpreq)) {
1353 Curl_safefree(postdata);
1354 return PARAM_BAD_USE;
1359 /* dump-header to given file name */
1360 GetStr(&config->headerfile, nextarg);
1364 char *ptr = strstr(nextarg, ";auto");
1366 /* Automatic referer requested, this may be combined with a
1368 config->autoreferer = TRUE;
1369 *ptr = 0; /* zero terminate here */
1372 config->autoreferer = FALSE;
1373 GetStr(&config->referer, nextarg);
1378 case '\0': /* certificate file */
1379 GetFileAndPassword(nextarg, &config->cert, &config->key_passwd);
1381 case 'a': /* CA info PEM file */
1382 /* CA info PEM file */
1383 GetStr(&config->cacert, nextarg);
1385 case 'b': /* cert file type */
1386 GetStr(&config->cert_type, nextarg);
1388 case 'c': /* private key file */
1389 GetStr(&config->key, nextarg);
1391 case 'd': /* private key file type */
1392 GetStr(&config->key_type, nextarg);
1394 case 'e': /* private key passphrase */
1395 GetStr(&config->key_passwd, nextarg);
1398 case 'f': /* crypto engine */
1399 GetStr(&config->engine, nextarg);
1400 if(config->engine && curl_strequal(config->engine, "list"))
1401 return PARAM_ENGINES_REQUESTED;
1403 case 'g': /* CA info PEM file */
1404 /* CA cert directory */
1405 GetStr(&config->capath, nextarg);
1407 case 'h': /* --pubkey public key file */
1408 GetStr(&config->pubkey, nextarg);
1410 case 'i': /* --hostpubmd5 md5 of the host public key */
1411 GetStr(&config->hostpubmd5, nextarg);
1412 if(!config->hostpubmd5 || strlen(config->hostpubmd5) != 32)
1413 return PARAM_BAD_USE;
1415 case 'j': /* CRL info PEM file */
1417 GetStr(&config->crlfile, nextarg);
1419 case 'k': /* TLS username */
1420 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)
1421 GetStr(&config->tls_username, nextarg);
1423 return PARAM_LIBCURL_DOESNT_SUPPORT;
1425 case 'l': /* TLS password */
1426 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)
1427 GetStr(&config->tls_password, nextarg);
1429 return PARAM_LIBCURL_DOESNT_SUPPORT;
1431 case 'm': /* TLS authentication type */
1432 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP) {
1433 GetStr(&config->tls_authtype, nextarg);
1434 if(!curl_strequal(config->tls_authtype, "SRP"))
1435 return PARAM_LIBCURL_DOESNT_SUPPORT; /* only support TLS-SRP */
1438 return PARAM_LIBCURL_DOESNT_SUPPORT;
1440 case 'n': /* no empty SSL fragments, --ssl-allow-beast */
1441 if(curlinfo->features & CURL_VERSION_SSL)
1442 config->ssl_allow_beast = toggle;
1445 case 'o': /* --login-options */
1446 GetStr(&config->login_options, nextarg);
1449 case 'p': /* Pinned public key DER file */
1450 /* Pinned public key DER file */
1451 GetStr(&config->pinnedpubkey, nextarg);
1454 case 'q': /* --cert-status */
1455 config->verifystatus = TRUE;
1458 case 'r': /* --false-start */
1459 config->falsestart = TRUE;
1462 case 's': /* --ssl-no-revoke */
1463 if(curlinfo->features & CURL_VERSION_SSL)
1464 config->ssl_no_revoke = TRUE;
1467 case 't': /* --tcp-fastopen */
1468 config->tcp_fastopen = TRUE;
1471 case 'u': /* TLS username for proxy */
1472 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)
1473 GetStr(&config->proxy_tls_username, nextarg);
1475 return PARAM_LIBCURL_DOESNT_SUPPORT;
1478 case 'v': /* TLS password for proxy */
1479 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)
1480 GetStr(&config->proxy_tls_password, nextarg);
1482 return PARAM_LIBCURL_DOESNT_SUPPORT;
1485 case 'w': /* TLS authentication type for proxy */
1486 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP) {
1487 GetStr(&config->proxy_tls_authtype, nextarg);
1488 if(!curl_strequal(config->proxy_tls_authtype, "SRP"))
1489 return PARAM_LIBCURL_DOESNT_SUPPORT; /* only support TLS-SRP */
1492 return PARAM_LIBCURL_DOESNT_SUPPORT;
1495 case 'x': /* certificate file for proxy */
1496 GetFileAndPassword(nextarg, &config->proxy_cert,
1497 &config->proxy_key_passwd);
1500 case 'y': /* cert file type for proxy */
1501 GetStr(&config->proxy_cert_type, nextarg);
1504 case 'z': /* private key file for proxy */
1505 GetStr(&config->proxy_key, nextarg);
1508 case '0': /* private key file type for proxy */
1509 GetStr(&config->proxy_key_type, nextarg);
1512 case '1': /* private key passphrase for proxy */
1513 GetStr(&config->proxy_key_passwd, nextarg);
1517 case '2': /* ciphers for proxy */
1518 GetStr(&config->proxy_cipher_list, nextarg);
1521 case '3': /* CRL info PEM file for proxy */
1523 GetStr(&config->proxy_crlfile, nextarg);
1526 case '4': /* no empty SSL fragments for proxy */
1527 if(curlinfo->features & CURL_VERSION_SSL)
1528 config->proxy_ssl_allow_beast = toggle;
1531 case '5': /* --login-options */
1532 GetStr(&config->login_options, nextarg);
1535 case '6': /* CA info PEM file for proxy */
1536 /* CA info PEM file */
1537 GetStr(&config->proxy_cacert, nextarg);
1540 case '7': /* CA info PEM file for proxy */
1541 /* CA cert directory */
1542 GetStr(&config->proxy_capath, nextarg);
1545 case '8': /* allow insecure SSL connects for proxy */
1546 config->proxy_insecure_ok = toggle;
1550 /* TLS version 1 for proxy */
1551 config->proxy_ssl_version = CURL_SSLVERSION_TLSv1;
1554 default: /* unknown flag */
1555 return PARAM_OPTION_UNKNOWN;
1560 case 'a': /* --fail-early */
1561 global->fail_early = toggle;
1564 /* fail hard on errors */
1565 config->failonerror = toggle;
1569 /* "form data" simulation, this is a little advanced so lets do our best
1570 to sort this out slowly and carefully */
1571 if(formparse(config,
1575 (subletter=='s')?TRUE:FALSE)) /* 's' means literal string */
1576 return PARAM_BAD_USE;
1577 if(SetHTTPrequest(config, HTTPREQ_FORMPOST, &config->httpreq))
1578 return PARAM_BAD_USE;
1581 case 'g': /* g disables URLglobbing */
1582 config->globoff = toggle;
1585 case 'G': /* HTTP GET */
1586 config->use_httpget = TRUE;
1589 case 'h': /* h for help */
1591 return PARAM_HELP_REQUESTED;
1593 /* we now actually support --no-help too! */
1596 /* A custom header to append to a list */
1597 if(subletter == 'p') /* --proxy-header */
1598 err = add2list(&config->proxyheaders, nextarg);
1600 err = add2list(&config->headers, nextarg);
1605 config->include_headers = toggle; /* include the headers as well in the
1606 general output stream */
1609 config->cookiesession = toggle;
1613 * no_body will imply include_headers later on
1615 config->no_body = toggle;
1616 if(SetHTTPrequest(config,
1617 (config->no_body)?HTTPREQ_HEAD:HTTPREQ_GET,
1619 return PARAM_BAD_USE;
1621 case 'J': /* --remote-header-name */
1622 if(config->include_headers) {
1624 "--include and --remote-header-name cannot be combined.\n");
1625 return PARAM_BAD_USE;
1627 config->content_disposition = toggle;
1629 case 'k': /* allow insecure SSL connects */
1630 config->insecure_ok = toggle;
1632 case 'K': /* parse config file */
1633 if(parseconfig(nextarg, global))
1634 warnf(global, "error trying read config from the '%s' file\n",
1638 config->dirlistonly = toggle; /* only list the names of the FTP dir */
1641 config->followlocation = toggle; /* Follow Location: HTTP headers */
1644 /* Continue to send authentication (user+password) when following
1645 * locations, even when hostname changed */
1646 config->unrestricted_auth = toggle;
1651 /* specified max time */
1652 err = str2udouble(&config->timeout, nextarg);
1656 case 'M': /* M for manual, huge help */
1657 if(toggle) { /* --no-manual shows no manual... */
1659 return PARAM_MANUAL_REQUESTED;
1662 "built-in manual was disabled at build-time!\n");
1663 return PARAM_OPTION_UNKNOWN;
1669 case 'o': /* CA info PEM file */
1670 /* use .netrc or URL */
1671 config->netrc_opt = toggle;
1673 case 'e': /* netrc-file */
1674 GetStr(&config->netrc_file, nextarg);
1677 /* pick info from .netrc, if this is used for http, curl will
1678 automatically enfore user+password with the request */
1679 config->netrc = toggle;
1684 /* disable the output I/O buffering. note that the option is called
1685 --buffer but is mostly used in the negative form: --no-buffer */
1687 config->nobuffer = (!toggle)?TRUE:FALSE;
1689 config->nobuffer = toggle;
1691 case 'O': /* --remote-name */
1692 if(subletter == 'a') { /* --remote-name-all */
1693 config->default_node_flags = toggle?GETOUT_USEREMOTE:0;
1697 case 'o': /* --output */
1701 if(!config->url_out)
1702 config->url_out = config->url_list;
1703 if(config->url_out) {
1704 /* there's a node here, if it already is filled-in continue to find
1706 while(config->url_out && (config->url_out->flags & GETOUT_OUTFILE))
1707 config->url_out = config->url_out->next;
1710 /* now there might or might not be an available node to fill in! */
1714 url = config->url_out;
1716 /* there was no free node, create one! */
1717 url = new_getout(config);
1720 return PARAM_NO_MEM;
1722 /* fill in the outfile */
1724 GetStr(&url->outfile, nextarg);
1725 url->flags &= ~GETOUT_USEREMOTE; /* switch off */
1728 url->outfile = NULL; /* leave it */
1730 url->flags |= GETOUT_USEREMOTE; /* switch on */
1732 url->flags &= ~GETOUT_USEREMOTE; /* switch off */
1734 url->flags |= GETOUT_OUTFILE;
1739 /* This makes the FTP sessions use PORT instead of PASV */
1740 /* use <eth0> or <192.168.10.10> style addresses. Anything except
1741 this will make us try to get the "default" address.
1742 NOTE: this is a changed behaviour since the released 4.1!
1744 GetStr(&config->ftpport, nextarg);
1747 /* proxy tunnel for non-http protocols */
1748 config->proxytunnel = toggle;
1751 case 'q': /* if used first, already taken care of, we do it like
1752 this so we don't cause an error! */
1755 /* QUOTE command to send to FTP server */
1756 switch(nextarg[0]) {
1758 /* prefixed with a dash makes it a POST TRANSFER one */
1760 err = add2list(&config->postquote, nextarg);
1763 /* prefixed with a plus makes it a just-before-transfer one */
1765 err = add2list(&config->prequote, nextarg);
1768 err = add2list(&config->quote, nextarg);
1775 /* Specifying a range WITHOUT A DASH will create an illegal HTTP range
1776 (and won't actually be range by definition). The man page previously
1777 claimed that to be a good way, why this code is added to work-around
1779 if(ISDIGIT(*nextarg) && !strchr(nextarg, '-')) {
1783 "A specified range MUST include at least one dash (-). "
1784 "Appending one for you!\n");
1785 off = curlx_strtoofft(nextarg, NULL, 10);
1786 snprintf(buffer, sizeof(buffer), "%" CURL_FORMAT_CURL_OFF_T "-", off);
1787 Curl_safefree(config->range);
1788 config->range = strdup(buffer);
1790 return PARAM_NO_MEM;
1793 /* byte range requested */
1795 tmp_range = nextarg;
1796 while(*tmp_range != '\0') {
1797 if(!ISDIGIT(*tmp_range) && *tmp_range != '-' && *tmp_range != ',') {
1798 warnf(global, "Invalid character is found in given range. "
1799 "A specified range MUST have only digits in "
1800 "\'start\'-\'stop\'. The server's response to this "
1801 "request is uncertain.\n");
1806 /* byte range requested */
1807 GetStr(&config->range, nextarg);
1811 /* use remote file's time */
1812 config->remote_time = toggle;
1815 /* don't show progress meter, don't show errors : */
1817 global->mute = global->noprogress = TRUE;
1819 global->mute = global->noprogress = FALSE;
1820 if(global->showerror < 0)
1821 /* if still on the default value, set showerror to the reverse of
1822 toggle. This is to allow -S and -s to be used in an independent
1823 order but still have the same effect. */
1824 global->showerror = (!toggle)?TRUE:FALSE; /* toggle off */
1828 global->showerror = toggle?1:0; /* toggle on if used with -s */
1831 /* Telnet options */
1832 err = add2list(&config->telnet_options, nextarg);
1837 /* we are uploading */
1840 if(!config->url_out)
1841 config->url_out = config->url_list;
1842 if(config->url_out) {
1843 /* there's a node here, if it already is filled-in continue to find
1845 while(config->url_out && (config->url_out->flags & GETOUT_UPLOAD))
1846 config->url_out = config->url_out->next;
1849 /* now there might or might not be an available node to fill in! */
1853 url = config->url_out;
1855 /* there was no free node, create one! */
1856 url = new_getout(config);
1859 return PARAM_NO_MEM;
1861 url->flags |= GETOUT_UPLOAD; /* mark -T used */
1863 url->flags |= GETOUT_NOUPLOAD;
1865 /* "-" equals stdin, but keep the string around for now */
1866 GetStr(&url->infile, nextarg);
1873 GetStr(&config->userpwd, nextarg);
1877 /* Proxy user:password */
1878 GetStr(&config->proxyuserpwd, nextarg);
1883 /* the '%' thing here will cause the trace get sent to stderr */
1884 Curl_safefree(global->trace_dump);
1885 global->trace_dump = strdup("%");
1886 if(!global->trace_dump)
1887 return PARAM_NO_MEM;
1888 if(global->tracetype && (global->tracetype != TRACE_PLAIN))
1890 "-v, --verbose overrides an earlier trace/verbose option\n");
1891 global->tracetype = TRACE_PLAIN;
1894 /* verbose is disabled here */
1895 global->tracetype = TRACE_NONE;
1898 if(toggle) /* --no-version yields no output! */
1899 return PARAM_VERSION_INFO_REQUESTED;
1903 /* get the output string */
1904 if('@' == *nextarg) {
1905 /* the data begins with a '@' letter, it means that a file name
1906 or - (stdin) follows */
1909 nextarg++; /* pass the @ */
1910 if(!strcmp("-", nextarg)) {
1916 file = fopen(nextarg, FOPEN_READTEXT);
1918 err = file2string(&config->writeout, file);
1919 if(file && (file != stdin))
1923 if(!config->writeout)
1924 warnf(global, "Failed to read %s", fname);
1927 GetStr(&config->writeout, nextarg);
1931 case 'a': /* --preproxy */
1932 GetStr(&config->preproxy, nextarg);
1936 GetStr(&config->proxy, nextarg);
1937 config->proxyver = CURLPROXY_HTTP;
1942 /* set custom request */
1943 GetStr(&config->customrequest, nextarg);
1946 /* low speed time */
1947 err = str2unum(&config->low_speed_time, nextarg);
1950 if(!config->low_speed_limit)
1951 config->low_speed_limit = 1;
1954 /* low speed limit */
1955 err = str2unum(&config->low_speed_limit, nextarg);
1958 if(!config->low_speed_time)
1959 config->low_speed_time = 30;
1961 case 'z': /* time condition coming up */
1967 /* If-Modified-Since: (section 14.28 in RFC2068) */
1968 config->timecond = CURL_TIMECOND_IFMODSINCE;
1971 /* If-Unmodified-Since: (section 14.24 in RFC2068) */
1972 config->timecond = CURL_TIMECOND_IFUNMODSINCE;
1976 /* Last-Modified: (section 14.29 in RFC2068) */
1977 config->timecond = CURL_TIMECOND_LASTMOD;
1982 config->condtime=curl_getdate(nextarg, &now);
1983 if(-1 == (int)config->condtime) {
1984 /* now let's see if it is a file name to get the time from instead! */
1985 struct_stat statbuf;
1986 if(-1 == stat(nextarg, &statbuf)) {
1987 /* failed, remove time condition */
1988 config->timecond = CURL_TIMECOND_NONE;
1990 "Illegal date format for -z, --time-cond (and not "
1991 "a file name). Disabling time condition. "
1992 "See curl_getdate(3) for valid date syntax.\n");
1995 /* pull the time out from the file */
1996 config->condtime = statbuf.st_mtime;
2000 default: /* unknown flag */
2001 return PARAM_OPTION_UNKNOWN;
2005 } while(!longopt && !singleopt && *++parse && !*usedarg);
2010 ParameterError parse_args(struct GlobalConfig *config, int argc,
2015 char *orig_opt = NULL;
2016 ParameterError result = PARAM_OK;
2017 struct OperationConfig *operation = config->first;
2019 for(i = 1, stillflags = TRUE; i < argc && !result; i++) {
2022 if(stillflags && ('-' == argv[i][0])) {
2025 char *flag = argv[i];
2027 if(!strcmp("--", argv[i]))
2028 /* This indicates the end of the flags and thus enables the
2029 following (URL) argument to start with -. */
2032 nextarg = (i < (argc - 1)) ? argv[i + 1] : NULL;
2034 result = getparameter(flag, nextarg, &passarg, config, operation);
2035 if(result == PARAM_NEXT_OPERATION) {
2036 /* Reset result as PARAM_NEXT_OPERATION is only used here and not
2037 returned from this function */
2040 if(operation->url_list && operation->url_list->url) {
2041 /* Allocate the next config */
2042 operation->next = malloc(sizeof(struct OperationConfig));
2043 if(operation->next) {
2044 /* Initialise the newly created config */
2045 config_init(operation->next);
2047 /* Copy the easy handle */
2048 operation->next->easy = config->easy;
2050 /* Set the global config pointer */
2051 operation->next->global = config;
2053 /* Update the last operation pointer */
2054 config->last = operation->next;
2056 /* Move onto the new config */
2057 operation->next->prev = operation;
2058 operation = operation->next;
2061 result = PARAM_NO_MEM;
2064 else if(!result && passarg)
2065 i++; /* we're supposed to skip this */
2071 /* Just add the URL please */
2072 result = getparameter((char *)"--url", argv[i], &used, config,
2077 if(result && result != PARAM_HELP_REQUESTED &&
2078 result != PARAM_MANUAL_REQUESTED &&
2079 result != PARAM_VERSION_INFO_REQUESTED &&
2080 result != PARAM_ENGINES_REQUESTED) {
2081 const char *reason = param2text(result);
2083 if(orig_opt && strcmp(":", orig_opt))
2084 helpf(config->errors, "option %s: %s\n", orig_opt, reason);
2086 helpf(config->errors, "%s\n", reason);