1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2014, 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 http://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 /* all these ones, starting with "*" or "$" as a short-option have *no*
68 short option to mention. */
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},
109 {"*x", "krb" , 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 {"$a", "ftp-ssl", FALSE},
118 /* 'ftp-ssl' deprecated name since 7.20.0 */
119 {"$a", "ssl", FALSE},
120 /* 'ssl' new option name in 7.20.0, previously this was ftp-ssl */
121 {"$b", "ftp-pasv", FALSE},
122 {"$c", "socks5", TRUE},
123 {"$c", "socks", TRUE},
124 /* 'socks' is how the option once was documented but we prefer
125 the --socks5 version for explicit version */
126 {"$d", "tcp-nodelay", FALSE},
127 {"$e", "proxy-digest", FALSE},
128 {"$f", "proxy-basic", FALSE},
129 {"$g", "retry", TRUE},
130 {"$h", "retry-delay", TRUE},
131 {"$i", "retry-max-time", TRUE},
132 {"$k", "proxy-negotiate", FALSE},
133 {"$m", "ftp-account", TRUE},
134 {"$n", "proxy-anyauth", FALSE},
135 {"$o", "trace-time", FALSE},
136 {"$p", "ignore-content-length", FALSE},
137 {"$q", "ftp-skip-pasv-ip", FALSE},
138 {"$r", "ftp-method", TRUE},
139 {"$s", "local-port", TRUE},
140 {"$t", "socks4", TRUE},
141 {"$T", "socks4a", TRUE},
142 {"$u", "ftp-alternative-to-user", TRUE},
143 {"$v", "ftp-ssl-reqd", FALSE},
144 /* 'ftp-ssl-reqd' deprecated name since 7.20.0 */
145 {"$v", "ssl-reqd", FALSE},
146 /* 'ssl-reqd' new in 7.20.0, previously this was ftp-ssl-reqd */
147 {"$w", "sessionid", FALSE},
148 /* ¡sessionid' listed as --no-sessionid in the help */
149 {"$x", "ftp-ssl-control", FALSE},
150 {"$y", "ftp-ssl-ccc", FALSE},
151 {"$j", "ftp-ssl-ccc-mode", TRUE},
152 {"$z", "libcurl", TRUE},
153 {"$#", "raw", FALSE},
154 {"$0", "post301", FALSE},
155 {"$1", "keepalive", FALSE},
156 /* 'keepalive' listed as --no-keepalive in the help */
157 {"$2", "socks5-hostname", TRUE},
158 {"$3", "keepalive-time", TRUE},
159 {"$4", "post302", FALSE},
160 {"$5", "noproxy", TRUE},
161 #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
162 {"$6", "socks5-gssapi-service", TRUE},
163 {"$7", "socks5-gssapi-nec", FALSE},
165 {"$8", "proxy1.0", TRUE},
166 {"$9", "tftp-blksize", TRUE},
167 {"$A", "mail-from", TRUE},
168 {"$B", "mail-rcpt", TRUE},
169 {"$C", "ftp-pret", FALSE},
170 {"$D", "proto", TRUE},
171 {"$E", "proto-redir", TRUE},
172 {"$F", "resolve", TRUE},
173 {"$G", "delegation", TRUE},
174 {"$H", "mail-auth", TRUE},
175 {"$I", "post303", FALSE},
176 {"$J", "metalink", FALSE},
177 {"$K", "sasl-ir", FALSE},
178 {"$L", "test-event", FALSE},
179 {"0", "http1.0", FALSE},
180 {"01", "http1.1", FALSE},
181 {"02", "http2", FALSE},
182 {"1", "tlsv1", FALSE},
183 {"10", "tlsv1.0", FALSE},
184 {"11", "tlsv1.1", FALSE},
185 {"12", "tlsv1.2", FALSE},
186 {"2", "sslv2", FALSE},
187 {"3", "sslv3", FALSE},
188 {"4", "ipv4", FALSE},
189 {"6", "ipv6", FALSE},
190 {"a", "append", FALSE},
191 {"A", "user-agent", TRUE},
192 {"b", "cookie", TRUE},
193 {"B", "use-ascii", FALSE},
194 {"c", "cookie-jar", TRUE},
195 {"C", "continue-at", TRUE},
197 {"da", "data-ascii", TRUE},
198 {"db", "data-binary", TRUE},
199 {"de", "data-urlencode", TRUE},
200 {"D", "dump-header", TRUE},
201 {"e", "referer", TRUE},
203 {"Ea", "cacert", TRUE},
204 {"Eb", "cert-type", TRUE},
206 {"Ed", "key-type", TRUE},
207 {"Ee", "pass", TRUE},
208 {"Ef", "engine", TRUE},
209 {"Eg", "capath ", TRUE},
210 {"Eh", "pubkey", TRUE},
211 {"Ei", "hostpubmd5", TRUE},
212 {"Ej", "crlfile", TRUE},
213 {"Ek", "tlsuser", TRUE},
214 {"El", "tlspassword", TRUE},
215 {"Em", "tlsauthtype", TRUE},
216 {"En", "ssl-allow-beast", FALSE},
217 {"Eo", "login-options", TRUE},
218 {"f", "fail", FALSE},
220 {"Fs", "form-string", TRUE},
221 {"g", "globoff", FALSE},
223 {"h", "help", FALSE},
224 {"H", "header", TRUE},
225 {"i", "include", FALSE},
226 {"I", "head", FALSE},
227 {"j", "junk-session-cookies", FALSE},
228 {"J", "remote-header-name", FALSE},
229 {"k", "insecure", FALSE},
230 {"K", "config", TRUE},
231 {"l", "list-only", FALSE},
232 {"L", "location", FALSE},
233 {"Lt", "location-trusted", FALSE},
234 {"m", "max-time", TRUE},
235 {"M", "manual", FALSE},
236 {"n", "netrc", FALSE},
237 {"no", "netrc-optional", FALSE},
238 {"ne", "netrc-file", TRUE},
239 {"N", "buffer", FALSE},
240 /* 'buffer' listed as --no-buffer in the help */
241 {"o", "output", TRUE},
242 {"O", "remote-name", FALSE},
243 {"Oa", "remote-name-all", FALSE},
244 {"p", "proxytunnel", FALSE},
245 {"P", "ftpport", TRUE},
246 /* 'ftpport' old version */
247 {"P", "ftp-port", TRUE},
248 {"q", "disable", FALSE},
249 {"Q", "quote", TRUE},
250 {"r", "range", TRUE},
251 {"R", "remote-time", FALSE},
252 {"s", "silent", FALSE},
253 {"S", "show-error", FALSE},
254 {"t", "telnet-options", TRUE},
255 /* 'telnet-options' documented as telnet-option */
256 {"T", "upload-file", TRUE},
258 {"U", "proxy-user", TRUE},
259 {"v", "verbose", FALSE},
260 {"V", "version", FALSE},
261 {"w", "write-out", TRUE},
262 {"x", "proxy", TRUE},
263 {"X", "request", TRUE},
264 {"X", "http-request", TRUE},
265 /* 'http-request' OBSOLETE VERSION */
266 {"Y", "speed-limit", TRUE},
267 {"y", "speed-time", TRUE},
268 {"z", "time-cond", TRUE},
269 {"#", "progress-bar", FALSE},
270 {":", "next", FALSE},
271 {"~", "xattr", FALSE},
274 /* Split the argument of -E to 'certname' and 'passphrase' separated by colon.
275 * We allow ':' and '\' to be escaped by '\' so that we can use certificate
276 * nicknames containing ':'. See <https://sourceforge.net/p/curl/bugs/1196/>
281 void parse_cert_parameter(const char *cert_parameter,
285 size_t param_length = strlen(cert_parameter);
287 const char *param_place = NULL;
288 char *certname_place = NULL;
292 /* most trivial assumption: cert_parameter is empty */
293 if(param_length == 0)
296 /* next less trivial: cert_parameter contains no colon nor backslash; this
297 * means no passphrase was given and no characters escaped */
298 if(!strpbrk(cert_parameter, ":\\")) {
299 *certname = strdup(cert_parameter);
302 /* deal with escaped chars; find unescaped colon if it exists */
303 certname_place = malloc(param_length + 1);
307 *certname = certname_place;
308 param_place = cert_parameter;
309 while(*param_place) {
310 span = strcspn(param_place, ":\\");
311 strncpy(certname_place, param_place, span);
313 certname_place += span;
314 /* we just ate all the non-special chars. now we're on either a special
315 * char or the end of the string. */
316 switch(*param_place) {
321 switch(*param_place) {
323 *certname_place++ = '\\';
326 *certname_place++ = '\\';
330 *certname_place++ = ':';
334 *certname_place++ = '\\';
335 *certname_place++ = *param_place;
341 /* Since we live in a world of weirdness and confusion, the win32
342 dudes can use : when using drive letters and thus c:\file:password
343 needs to work. In order not to break compatibility, we still use : as
344 separator, but we try to detect when it is used for a file name! On
348 (param_place == &cert_parameter[1]) &&
349 (cert_parameter[2] == '\\' || cert_parameter[2] == '/') &&
350 (ISALPHA(cert_parameter[0])) ) {
351 /* colon in the second column, followed by a backslash, and the
352 first character is an alphabetic letter:
354 this is a drive letter colon */
355 *certname_place++ = ':';
360 /* escaped colons and Windows drive letter colons were handled
361 * above; if we're still here, this is a separating colon */
363 if(strlen(param_place) > 0) {
364 *passphrase = strdup(param_place);
370 *certname_place = '\0';
373 ParameterError getparameter(char *flag, /* f or -long-flag */
374 char *nextarg, /* NULL if unset */
375 bool *usedarg, /* set to TRUE if the arg
377 struct GlobalConfig *global,
378 struct OperationConfig *config)
381 char subletter = '\0'; /* subletters can only occur on long options */
383 const char *parse = NULL;
387 bool longopt = FALSE;
388 bool singleopt = FALSE; /* when true means '-o foo' used '-ofoo' */
390 bool toggle = TRUE; /* how to switch boolean options, on or off. Controlled
391 by using --OPTION or --no-OPTION */
394 if(('-' != flag[0]) ||
395 (('-' == flag[0]) && ('-' == flag[1]))) {
396 /* this should be a long name */
397 char *word = ('-' == flag[0]) ? flag+2 : flag;
398 size_t fnam = strlen(word);
401 if(!strncmp(word, "no-", 3)) {
402 /* disable this option but ignore the "no-" part when looking for it */
407 for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) {
408 if(curlx_strnequal(aliases[j].lname, word, fnam)) {
411 if(curlx_raw_equal(aliases[j].lname, word)) {
412 parse = aliases[j].letter;
414 numhits = 1; /* a single unique hit */
417 parse = aliases[j].letter;
422 /* this is at least the second match! */
423 return PARAM_OPTION_AMBIGUOUS;
426 return PARAM_OPTION_UNKNOWN;
430 flag++; /* prefixed with one dash, pass it */
436 /* we can loop here if we have multiple single-letters */
440 letter = (char)*parse;
449 subletter = parse[1];
451 *usedarg = FALSE; /* default is that we don't use the arg */
454 for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) {
455 if(letter == aliases[j].letter[0]) {
461 return PARAM_OPTION_UNKNOWN;
465 if(aliases[hit].extraparam) {
466 /* this option requires an extra parameter */
467 if(!longopt && parse[1]) {
468 nextarg = (char *)&parse[1]; /* this is the actual extra parameter */
469 singleopt = TRUE; /* don't loop anymore after this */
472 return PARAM_REQUIRES_PARAMETER;
474 *usedarg = TRUE; /* mark it as used */
478 case '*': /* options without a short option */
480 case '4': /* --dns-ipv4-addr */
481 /* addr in dot notation */
482 GetStr(&config->dns_ipv4_addr, nextarg);
484 case '6': /* --dns-ipv6-addr */
485 /* addr in dot notation */
486 GetStr(&config->dns_ipv6_addr, nextarg);
488 case 'a': /* random-file */
489 GetStr(&config->random_file, nextarg);
491 case 'b': /* egd-file */
492 GetStr(&config->egd_file, nextarg);
494 case 'B': /* XOAUTH2 Bearer */
495 GetStr(&config->xoauth2_bearer, nextarg);
497 case 'c': /* connect-timeout */
498 err = str2udouble(&config->connecttimeout, nextarg);
502 case 'd': /* ciphers */
503 GetStr(&config->cipher_list, nextarg);
505 case 'D': /* --dns-interface */
507 GetStr(&config->dns_interface, nextarg);
509 case 'e': /* --disable-epsv */
510 config->disable_epsv = toggle;
512 case 'E': /* --epsv */
513 config->disable_epsv = (!toggle)?TRUE:FALSE;
515 #ifdef USE_ENVIRONMENT
517 config->writeenv = toggle;
520 case 'F': /* --dns-servers */
521 /* IP addrs of DNS servers */
522 GetStr(&config->dns_servers, nextarg);
524 case 'g': /* --trace */
525 GetStr(&config->trace_dump, nextarg);
526 if(config->tracetype && (config->tracetype != TRACE_BIN))
527 warnf(config, "--trace overrides an earlier trace/verbose option\n");
528 config->tracetype = TRACE_BIN;
530 case 'G': /* --npn */
531 config->nonpn = (!toggle)?TRUE:FALSE;
533 case 'h': /* --trace-ascii */
534 GetStr(&config->trace_dump, nextarg);
535 if(config->tracetype && (config->tracetype != TRACE_ASCII))
537 "--trace-ascii overrides an earlier trace/verbose option\n");
538 config->tracetype = TRACE_ASCII;
540 case 'H': /* --alpn */
541 config->noalpn = (!toggle)?TRUE:FALSE;
543 case 'i': /* --limit-rate */
545 /* We support G, M, K too */
547 curl_off_t value = curlx_strtoofft(nextarg, &unit, 0);
551 else if(strlen(unit) > 1)
552 unit = (char *)"w"; /* unsupported */
557 value *= 1024*1024*1024;
569 /* for plain bytes, leave as-is */
572 warnf(config, "unsupported rate unit. Use G, M, K or B!\n");
573 return PARAM_BAD_USE;
575 config->recvpersecond = value;
576 config->sendpersecond = value;
580 case 'j': /* --compressed */
581 if(toggle && !(curlinfo->features & CURL_VERSION_LIBZ))
582 return PARAM_LIBCURL_DOESNT_SUPPORT;
583 config->encoding = toggle;
586 case 'J': /* --tr-encoding */
587 config->tr_encoding = toggle;
590 case 'k': /* --digest */
592 config->authtype |= CURLAUTH_DIGEST;
594 config->authtype &= ~CURLAUTH_DIGEST;
597 case 'l': /* --negotiate */
599 if(curlinfo->features & CURL_VERSION_GSSNEGOTIATE)
600 config->authtype |= CURLAUTH_GSSNEGOTIATE;
602 return PARAM_LIBCURL_DOESNT_SUPPORT;
605 config->authtype &= ~CURLAUTH_GSSNEGOTIATE;
608 case 'm': /* --ntlm */
610 if(curlinfo->features & CURL_VERSION_NTLM)
611 config->authtype |= CURLAUTH_NTLM;
613 return PARAM_LIBCURL_DOESNT_SUPPORT;
616 config->authtype &= ~CURLAUTH_NTLM;
619 case 'M': /* --ntlm-wb */
621 if(curlinfo->features & CURL_VERSION_NTLM_WB)
622 config->authtype |= CURLAUTH_NTLM_WB;
624 return PARAM_LIBCURL_DOESNT_SUPPORT;
627 config->authtype &= ~CURLAUTH_NTLM_WB;
630 case 'n': /* --basic for completeness */
632 config->authtype |= CURLAUTH_BASIC;
634 config->authtype &= ~CURLAUTH_BASIC;
637 case 'o': /* --anyauth, let libcurl pick it */
639 config->authtype = CURLAUTH_ANY;
640 /* --no-anyauth simply doesn't touch it */
644 case 'p': /* --wdebug */
648 case 'q': /* --ftp-create-dirs */
649 config->ftp_create_dirs = toggle;
652 case 'r': /* --create-dirs */
653 config->create_dirs = toggle;
656 case 's': /* --max-redirs */
657 /* specified max no of redirects (http(s)), this accepts -1 as a
659 err = str2num(&config->maxredirs, nextarg);
662 if(config->maxredirs < -1)
663 return PARAM_BAD_NUMERIC;
666 case 't': /* --proxy-ntlm */
667 if(curlinfo->features & CURL_VERSION_NTLM)
668 config->proxyntlm = toggle;
670 return PARAM_LIBCURL_DOESNT_SUPPORT;
673 case 'u': /* --crlf */
674 /* LF -> CRLF conversion? */
675 config->crlf = toggle;
678 case 'v': /* --stderr */
679 if(strcmp(nextarg, "-")) {
680 FILE *newfile = fopen(nextarg, "wt");
682 warnf(config, "Failed to open %s!\n", nextarg);
684 if(config->errors_fopened)
685 fclose(config->errors);
686 config->errors = newfile;
687 config->errors_fopened = TRUE;
691 config->errors = stdout;
693 case 'w': /* --interface */
695 GetStr(&config->iface, nextarg);
697 case 'x': /* --krb */
698 /* kerberos level string */
699 if(curlinfo->features & (CURL_VERSION_KERBEROS4 |
700 CURL_VERSION_GSSNEGOTIATE))
701 GetStr(&config->krblevel, nextarg);
703 return PARAM_LIBCURL_DOESNT_SUPPORT;
705 case 'y': /* --max-filesize */
706 err = str2offset(&config->max_filesize, nextarg);
710 case 'z': /* --disable-eprt */
711 config->disable_eprt = toggle;
713 case 'Z': /* --eprt */
714 config->disable_eprt = (!toggle)?TRUE:FALSE;
717 default: /* the URL! */
720 if(config->url_get || ((config->url_get = config->url_list) != NULL)) {
721 /* there's a node here, if it already is filled-in continue to find
723 while(config->url_get && (config->url_get->flags & GETOUT_URL))
724 config->url_get = config->url_get->next;
727 /* now there might or might not be an available node to fill in! */
731 url = config->url_get;
733 /* there was no free node, create one! */
734 url = new_getout(config);
739 /* fill in the URL */
740 GetStr(&url->url, nextarg);
741 url->flags |= GETOUT_URL;
746 case '$': /* more options without a short option */
748 case 'a': /* --ftp-ssl */
749 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
750 return PARAM_LIBCURL_DOESNT_SUPPORT;
751 config->ftp_ssl = toggle;
753 case 'b': /* --ftp-pasv */
754 Curl_safefree(config->ftpport);
756 case 'c': /* --socks5 specifies a socks5 proxy to use, and resolves
757 the name locally and passes on the resolved address */
758 GetStr(&config->socksproxy, nextarg);
759 config->socksver = CURLPROXY_SOCKS5;
761 case 't': /* --socks4 specifies a socks4 proxy to use */
762 GetStr(&config->socksproxy, nextarg);
763 config->socksver = CURLPROXY_SOCKS4;
765 case 'T': /* --socks4a specifies a socks4a proxy to use */
766 GetStr(&config->socksproxy, nextarg);
767 config->socksver = CURLPROXY_SOCKS4A;
769 case '2': /* --socks5-hostname specifies a socks5 proxy and enables name
770 resolving with the proxy */
771 GetStr(&config->socksproxy, nextarg);
772 config->socksver = CURLPROXY_SOCKS5_HOSTNAME;
774 case 'd': /* --tcp-nodelay option */
775 config->tcp_nodelay = toggle;
777 case 'e': /* --proxy-digest */
778 config->proxydigest = toggle;
780 case 'f': /* --proxy-basic */
781 config->proxybasic = toggle;
783 case 'g': /* --retry */
784 err = str2unum(&config->req_retry, nextarg);
788 case 'h': /* --retry-delay */
789 err = str2unum(&config->retry_delay, nextarg);
793 case 'i': /* --retry-max-time */
794 err = str2unum(&config->retry_maxtime, nextarg);
799 case 'k': /* --proxy-negotiate */
800 if(curlinfo->features & CURL_VERSION_GSSNEGOTIATE)
801 config->proxynegotiate = toggle;
803 return PARAM_LIBCURL_DOESNT_SUPPORT;
805 case 'm': /* --ftp-account */
806 GetStr(&config->ftp_account, nextarg);
808 case 'n': /* --proxy-anyauth */
809 config->proxyanyauth = toggle;
811 case 'o': /* --trace-time */
812 config->tracetime = toggle;
814 case 'p': /* --ignore-content-length */
815 config->ignorecl = toggle;
817 case 'q': /* --ftp-skip-pasv-ip */
818 config->ftp_skip_ip = toggle;
820 case 'r': /* --ftp-method (undocumented at this point) */
821 config->ftp_filemethod = ftpfilemethod(config, nextarg);
823 case 's': /* --local-port */
824 rc = sscanf(nextarg, "%d - %d",
826 &config->localportrange);
828 return PARAM_BAD_USE;
830 config->localportrange = 1; /* default number of ports to try */
832 config->localportrange -= config->localport;
833 if(config->localportrange < 1) {
834 warnf(config, "bad range input\n");
835 return PARAM_BAD_USE;
839 case 'u': /* --ftp-alternative-to-user */
840 GetStr(&config->ftp_alternative_to_user, nextarg);
842 case 'v': /* --ftp-ssl-reqd */
843 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
844 return PARAM_LIBCURL_DOESNT_SUPPORT;
845 config->ftp_ssl_reqd = toggle;
847 case 'w': /* --no-sessionid */
848 config->disable_sessionid = (!toggle)?TRUE:FALSE;
850 case 'x': /* --ftp-ssl-control */
851 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
852 return PARAM_LIBCURL_DOESNT_SUPPORT;
853 config->ftp_ssl_control = toggle;
855 case 'y': /* --ftp-ssl-ccc */
856 config->ftp_ssl_ccc = toggle;
857 if(!config->ftp_ssl_ccc_mode)
858 config->ftp_ssl_ccc_mode = CURLFTPSSL_CCC_PASSIVE;
860 case 'j': /* --ftp-ssl-ccc-mode */
861 config->ftp_ssl_ccc = TRUE;
862 config->ftp_ssl_ccc_mode = ftpcccmethod(config, nextarg);
864 case 'z': /* --libcurl */
865 #ifdef CURL_DISABLE_LIBCURL_OPTION
867 "--libcurl option was disabled at build-time!\n");
868 return PARAM_OPTION_UNKNOWN;
870 GetStr(&config->libcurl, nextarg);
873 case '#': /* --raw */
874 config->raw = toggle;
876 case '0': /* --post301 */
877 config->post301 = toggle;
879 case '1': /* --no-keepalive */
880 config->nokeepalive = (!toggle)?TRUE:FALSE;
882 case '3': /* --keepalive-time */
883 err = str2unum(&config->alivetime, nextarg);
887 case '4': /* --post302 */
888 config->post302 = toggle;
890 case 'I': /* --post303 */
891 config->post303 = toggle;
893 case '5': /* --noproxy */
894 /* This specifies the noproxy list */
895 GetStr(&config->noproxy, nextarg);
897 #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
898 case '6': /* --socks5-gssapi-service */
899 GetStr(&config->socks5_gssapi_service, nextarg);
901 case '7': /* --socks5-gssapi-nec*/
902 config->socks5_gssapi_nec = toggle;
905 case '8': /* --proxy1.0 */
907 GetStr(&config->proxy, nextarg);
908 config->proxyver = CURLPROXY_HTTP_1_0;
910 case '9': /* --tftp-blksize */
911 err = str2unum(&config->tftp_blksize, nextarg);
915 case 'A': /* --mail-from */
916 GetStr(&config->mail_from, nextarg);
918 case 'B': /* --mail-rcpt */
919 /* append receiver to a list */
920 err = add2list(&config->mail_rcpt, nextarg);
924 case 'C': /* --ftp-pret */
925 config->ftp_pret = toggle;
927 case 'D': /* --proto */
928 config->proto_present = TRUE;
929 if(proto2num(config, &config->proto, nextarg))
930 return PARAM_BAD_USE;
932 case 'E': /* --proto-redir */
933 config->proto_redir_present = TRUE;
934 if(proto2num(config, &config->proto_redir, nextarg))
935 return PARAM_BAD_USE;
937 case 'F': /* --resolve */
938 err = add2list(&config->resolve, nextarg);
942 case 'G': /* --delegation LEVEL */
943 config->gssapi_delegation = delegation(config, nextarg);
945 case 'H': /* --mail-auth */
946 GetStr(&config->mail_auth, nextarg);
948 case 'J': /* --metalink */
951 int mlmaj, mlmin, mlpatch;
952 metalink_get_version(&mlmaj, &mlmin, &mlpatch);
953 if((mlmaj*10000)+(mlmin*100)+mlpatch < CURL_REQ_LIBMETALINK_VERS) {
955 "--metalink option cannot be used because the version of "
956 "the linked libmetalink library is too old. "
957 "Required: %d.%d.%d, found %d.%d.%d\n",
958 CURL_REQ_LIBMETALINK_MAJOR,
959 CURL_REQ_LIBMETALINK_MINOR,
960 CURL_REQ_LIBMETALINK_PATCH,
961 mlmaj, mlmin, mlpatch);
962 return PARAM_BAD_USE;
965 config->use_metalink = toggle;
967 warnf(config, "--metalink option is ignored because the binary is "
968 "built without the Metalink support.\n");
972 case 'K': /* --sasl-ir */
973 config->sasl_ir = toggle;
975 case 'L': /* --test-event */
977 config->test_event_based = toggle;
979 warnf(config, "--test-event is ignored unless a debug build!\n");
984 case '#': /* --progress-bar */
986 config->progressmode = CURL_PROGRESS_BAR;
988 config->progressmode = CURL_PROGRESS_STATS;
990 case ':': /* --next */
991 return PARAM_NEXT_OPERATION;
992 case '~': /* --xattr */
993 config->xattr = toggle;
995 case '0': /* --http* options */
998 /* HTTP version 1.0 */
999 config->httpversion = CURL_HTTP_VERSION_1_0;
1002 /* HTTP version 1.1 */
1003 config->httpversion = CURL_HTTP_VERSION_1_1;
1006 /* HTTP version 2.0 */
1007 config->httpversion = CURL_HTTP_VERSION_2_0;
1011 case '1': /* --tlsv1* options */
1014 /* TLS version 1.x */
1015 config->ssl_version = CURL_SSLVERSION_TLSv1;
1018 /* TLS version 1.0 */
1019 config->ssl_version = CURL_SSLVERSION_TLSv1_0;
1022 /* TLS version 1.1 */
1023 config->ssl_version = CURL_SSLVERSION_TLSv1_1;
1026 /* TLS version 1.2 */
1027 config->ssl_version = CURL_SSLVERSION_TLSv1_2;
1033 config->ssl_version = CURL_SSLVERSION_SSLv2;
1037 config->ssl_version = CURL_SSLVERSION_SSLv3;
1041 config->ip_version = 4;
1045 config->ip_version = 6;
1048 /* This makes the FTP sessions use APPE instead of STOR */
1049 config->ftp_append = toggle;
1052 /* This specifies the User-Agent name */
1053 GetStr(&config->useragent, nextarg);
1055 case 'b': /* cookie string coming up: */
1056 if(nextarg[0] == '@') {
1059 else if(strchr(nextarg, '=')) {
1060 /* A cookie string must have a =-letter */
1061 GetStr(&config->cookie, nextarg);
1064 /* We have a cookie file to read from! */
1065 GetStr(&config->cookiefile, nextarg);
1068 /* use ASCII/text when transferring */
1069 config->use_ascii = toggle;
1072 /* get the file name to dump all cookies in */
1073 GetStr(&config->cookiejar, nextarg);
1076 /* This makes us continue an ftp transfer at given position */
1077 if(!curlx_strequal(nextarg, "-")) {
1078 err = str2offset(&config->resume_from, nextarg);
1081 config->resume_from_current = FALSE;
1084 config->resume_from_current = TRUE;
1085 config->resume_from = 0;
1087 config->use_resume=TRUE;
1090 /* postfield data */
1092 char *postdata = NULL;
1096 if(subletter == 'e') { /* --data-urlencode*/
1097 /* [name]=[content], we encode the content part only
1098 * [name]@[file name]
1100 * Case 2: we first load the file using that name and then encode
1103 const char *p = strchr(nextarg, '=');
1107 /* there was no '=' letter, check for a '@' instead */
1108 p = strchr(nextarg, '@');
1110 nlen = p - nextarg; /* length of the name part */
1111 is_file = *p++; /* pass the separator */
1114 /* neither @ nor =, so no name and it isn't a file */
1118 if('@' == is_file) {
1119 /* a '@' letter, it means that a file name or - (stdin) follows */
1121 if(curlx_strequal("-", p)) {
1126 file = fopen(p, "rb");
1129 "Couldn't read data from file \"%s\", this makes "
1130 "an empty POST.\n", nextarg);
1133 err = file2memory(&postdata, &size, file);
1135 if(file && (file != stdin))
1141 GetStr(&postdata, p);
1143 size = strlen(postdata);
1147 /* no data from the file, point to a zero byte string to make this
1148 get sent as a POST anyway */
1149 postdata = strdup("");
1151 return PARAM_NO_MEM;
1155 char *enc = curl_easy_escape(config->easy, postdata, (int)size);
1156 Curl_safefree(postdata); /* no matter if it worked or not */
1158 /* now make a string with the name from above and append the
1160 size_t outlen = nlen + strlen(enc) + 2;
1161 char *n = malloc(outlen);
1164 return PARAM_NO_MEM;
1166 if(nlen > 0) { /* only append '=' if we have a name */
1167 snprintf(n, outlen, "%.*s=%s", nlen, nextarg, enc);
1172 size = outlen-2; /* since no '=' was inserted */
1178 return PARAM_NO_MEM;
1181 else if('@' == *nextarg) {
1182 /* the data begins with a '@' letter, it means that a file name
1183 or - (stdin) follows */
1184 nextarg++; /* pass the @ */
1186 if(curlx_strequal("-", nextarg)) {
1188 if(subletter == 'b') /* forced data-binary */
1192 file = fopen(nextarg, "rb");
1194 warnf(config, "Couldn't read data from file \"%s\", this makes "
1195 "an empty POST.\n", nextarg);
1198 if(subletter == 'b')
1200 err = file2memory(&postdata, &size, file);
1202 err = file2string(&postdata, file);
1204 size = strlen(postdata);
1207 if(file && (file != stdin))
1213 /* no data from the file, point to a zero byte string to make this
1214 get sent as a POST anyway */
1215 postdata = strdup("");
1217 return PARAM_NO_MEM;
1221 GetStr(&postdata, nextarg);
1223 size = strlen(postdata);
1226 #ifdef CURL_DOES_CONVERSIONS
1227 if(subletter != 'b') {
1228 /* NOT forced binary, convert to ASCII */
1229 if(convert_to_network(postdata, strlen(postdata))) {
1230 Curl_safefree(postdata);
1231 return PARAM_NO_MEM;
1236 if(config->postfields) {
1237 /* we already have a string, we append this one with a separating
1239 char *oldpost = config->postfields;
1240 curl_off_t oldlen = config->postfieldsize;
1241 curl_off_t newlen = oldlen + size + 2;
1242 config->postfields = malloc((size_t)newlen);
1243 if(!config->postfields) {
1244 Curl_safefree(oldpost);
1245 Curl_safefree(postdata);
1246 return PARAM_NO_MEM;
1248 memcpy(config->postfields, oldpost, (size_t)oldlen);
1249 /* use byte value 0x26 for '&' to accommodate non-ASCII platforms */
1250 config->postfields[oldlen] = '\x26';
1251 memcpy(&config->postfields[oldlen+1], postdata, size);
1252 config->postfields[oldlen+1+size] = '\0';
1253 Curl_safefree(oldpost);
1254 Curl_safefree(postdata);
1255 config->postfieldsize += size+1;
1258 config->postfields = postdata;
1259 config->postfieldsize = size;
1263 We can't set the request type here, as this data might be used in
1264 a simple GET if -G is used. Already or soon.
1266 if(SetHTTPrequest(HTTPREQ_SIMPLEPOST, &config->httpreq)) {
1267 Curl_safefree(postdata);
1268 return PARAM_BAD_USE;
1273 /* dump-header to given file name */
1274 GetStr(&config->headerfile, nextarg);
1278 char *ptr = strstr(nextarg, ";auto");
1280 /* Automatic referer requested, this may be combined with a
1282 config->autoreferer = TRUE;
1283 *ptr = 0; /* zero terminate here */
1286 config->autoreferer = FALSE;
1287 GetStr(&config->referer, nextarg);
1292 case 'a': /* CA info PEM file */
1293 /* CA info PEM file */
1294 GetStr(&config->cacert, nextarg);
1296 case 'b': /* cert file type */
1297 GetStr(&config->cert_type, nextarg);
1299 case 'c': /* private key file */
1300 GetStr(&config->key, nextarg);
1302 case 'd': /* private key file type */
1303 GetStr(&config->key_type, nextarg);
1305 case 'e': /* private key passphrase */
1306 GetStr(&config->key_passwd, nextarg);
1309 case 'f': /* crypto engine */
1310 GetStr(&config->engine, nextarg);
1311 if(config->engine && curlx_raw_equal(config->engine,"list"))
1312 return PARAM_ENGINES_REQUESTED;
1314 case 'g': /* CA info PEM file */
1315 /* CA cert directory */
1316 GetStr(&config->capath, nextarg);
1318 case 'h': /* --pubkey public key file */
1319 GetStr(&config->pubkey, nextarg);
1321 case 'i': /* --hostpubmd5 md5 of the host public key */
1322 GetStr(&config->hostpubmd5, nextarg);
1323 if(!config->hostpubmd5 || strlen(config->hostpubmd5) != 32)
1324 return PARAM_BAD_USE;
1326 case 'j': /* CRL info PEM file */
1328 GetStr(&config->crlfile, nextarg);
1330 case 'k': /* TLS username */
1331 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)
1332 GetStr(&config->tls_username, nextarg);
1334 return PARAM_LIBCURL_DOESNT_SUPPORT;
1336 case 'l': /* TLS password */
1337 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)
1338 GetStr(&config->tls_password, nextarg);
1340 return PARAM_LIBCURL_DOESNT_SUPPORT;
1342 case 'm': /* TLS authentication type */
1343 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP) {
1344 GetStr(&config->tls_authtype, nextarg);
1345 if(!strequal(config->tls_authtype, "SRP"))
1346 return PARAM_LIBCURL_DOESNT_SUPPORT; /* only support TLS-SRP */
1349 return PARAM_LIBCURL_DOESNT_SUPPORT;
1351 case 'n': /* no empty SSL fragments, --ssl-allow-beast */
1352 if(curlinfo->features & CURL_VERSION_SSL)
1353 config->ssl_allow_beast = toggle;
1356 case 'o': /* --login-options */
1357 GetStr(&config->login_options, nextarg);
1360 default: /* certificate file */
1362 char *certname, *passphrase;
1363 parse_cert_parameter(nextarg, &certname, &passphrase);
1364 Curl_safefree(config->cert);
1365 config->cert = certname;
1367 Curl_safefree(config->key_passwd);
1368 config->key_passwd = passphrase;
1375 /* fail hard on errors */
1376 config->failonerror = toggle;
1379 /* "form data" simulation, this is a little advanced so lets do our best
1380 to sort this out slowly and carefully */
1381 if(formparse(config,
1385 (subletter=='s')?TRUE:FALSE)) /* 's' means literal string */
1386 return PARAM_BAD_USE;
1387 if(SetHTTPrequest(config, HTTPREQ_POST, &config->httpreq))
1388 return PARAM_BAD_USE;
1391 case 'g': /* g disables URLglobbing */
1392 config->globoff = toggle;
1395 case 'G': /* HTTP GET */
1396 config->use_httpget = TRUE;
1399 case 'h': /* h for help */
1401 return PARAM_HELP_REQUESTED;
1403 /* we now actually support --no-help too! */
1406 /* A custom header to append to a list */
1407 err = add2list(&config->headers, nextarg);
1412 config->include_headers = toggle; /* include the headers as well in the
1413 general output stream */
1416 config->cookiesession = toggle;
1420 * no_body will imply include_headers later on
1422 config->no_body = toggle;
1423 if(SetHTTPrequest(config,
1424 (config->no_body)?HTTPREQ_HEAD:HTTPREQ_GET,
1426 return PARAM_BAD_USE;
1428 case 'J': /* --remote-header-name */
1429 if(config->include_headers) {
1431 "--include and --remote-header-name cannot be combined.\n");
1432 return PARAM_BAD_USE;
1434 config->content_disposition = toggle;
1436 case 'k': /* allow insecure SSL connects */
1437 config->insecure_ok = toggle;
1439 case 'K': /* parse config file */
1440 if(parseconfig(nextarg, global))
1441 warnf(config, "error trying read config from the '%s' file\n",
1445 config->dirlistonly = toggle; /* only list the names of the FTP dir */
1448 config->followlocation = toggle; /* Follow Location: HTTP headers */
1449 switch (subletter) {
1451 /* Continue to send authentication (user+password) when following
1452 * locations, even when hostname changed */
1453 config->unrestricted_auth = toggle;
1458 /* specified max time */
1459 err = str2udouble(&config->timeout, nextarg);
1463 case 'M': /* M for manual, huge help */
1464 if(toggle) { /* --no-manual shows no manual... */
1466 return PARAM_MANUAL_REQUESTED;
1469 "built-in manual was disabled at build-time!\n");
1470 return PARAM_OPTION_UNKNOWN;
1476 case 'o': /* CA info PEM file */
1477 /* use .netrc or URL */
1478 config->netrc_opt = toggle;
1480 case 'e': /* netrc-file */
1481 GetStr(&config->netrc_file, nextarg);
1484 /* pick info from .netrc, if this is used for http, curl will
1485 automatically enfore user+password with the request */
1486 config->netrc = toggle;
1491 /* disable the output I/O buffering. note that the option is called
1492 --buffer but is mostly used in the negative form: --no-buffer */
1494 config->nobuffer = (!toggle)?TRUE:FALSE;
1496 config->nobuffer = toggle;
1498 case 'O': /* --remote-name */
1499 if(subletter == 'a') { /* --remote-name-all */
1500 config->default_node_flags = toggle?GETOUT_USEREMOTE:0;
1504 case 'o': /* --output */
1508 if(config->url_out || ((config->url_out = config->url_list) != NULL)) {
1509 /* there's a node here, if it already is filled-in continue to find
1511 while(config->url_out && (config->url_out->flags & GETOUT_OUTFILE))
1512 config->url_out = config->url_out->next;
1515 /* now there might or might not be an available node to fill in! */
1519 url = config->url_out;
1521 /* there was no free node, create one! */
1522 url = new_getout(config);
1525 return PARAM_NO_MEM;
1527 /* fill in the outfile */
1529 GetStr(&url->outfile, nextarg);
1530 url->flags &= ~GETOUT_USEREMOTE; /* switch off */
1533 url->outfile = NULL; /* leave it */
1535 url->flags |= GETOUT_USEREMOTE; /* switch on */
1537 url->flags &= ~GETOUT_USEREMOTE; /* switch off */
1539 url->flags |= GETOUT_OUTFILE;
1544 /* This makes the FTP sessions use PORT instead of PASV */
1545 /* use <eth0> or <192.168.10.10> style addresses. Anything except
1546 this will make us try to get the "default" address.
1547 NOTE: this is a changed behaviour since the released 4.1!
1549 GetStr(&config->ftpport, nextarg);
1552 /* proxy tunnel for non-http protocols */
1553 config->proxytunnel = toggle;
1556 case 'q': /* if used first, already taken care of, we do it like
1557 this so we don't cause an error! */
1560 /* QUOTE command to send to FTP server */
1561 switch(nextarg[0]) {
1563 /* prefixed with a dash makes it a POST TRANSFER one */
1565 err = add2list(&config->postquote, nextarg);
1568 /* prefixed with a plus makes it a just-before-transfer one */
1570 err = add2list(&config->prequote, nextarg);
1573 err = add2list(&config->quote, nextarg);
1580 /* Specifying a range WITHOUT A DASH will create an illegal HTTP range
1581 (and won't actually be range by definition). The man page previously
1582 claimed that to be a good way, why this code is added to work-around
1584 if(ISDIGIT(*nextarg) && !strchr(nextarg, '-')) {
1588 "A specified range MUST include at least one dash (-). "
1589 "Appending one for you!\n");
1590 off = curlx_strtoofft(nextarg, NULL, 10);
1591 snprintf(buffer, sizeof(buffer), "%" CURL_FORMAT_CURL_OFF_T "-", off);
1592 Curl_safefree(config->range);
1593 config->range = strdup(buffer);
1595 return PARAM_NO_MEM;
1598 /* byte range requested */
1600 tmp_range = nextarg;
1601 while(*tmp_range != '\0') {
1602 if(!ISDIGIT(*tmp_range) && *tmp_range != '-' && *tmp_range != ',') {
1603 warnf(config,"Invalid character is found in given range. "
1604 "A specified range MUST have only digits in "
1605 "\'start\'-\'stop\'. The server's response to this "
1606 "request is uncertain.\n");
1611 /* byte range requested */
1612 GetStr(&config->range, nextarg);
1616 /* use remote file's time */
1617 config->remote_time = toggle;
1620 /* don't show progress meter, don't show errors : */
1622 config->mute = config->noprogress = TRUE;
1624 config->mute = config->noprogress = FALSE;
1625 if(global->showerror < 0)
1626 /* if still on the default value, set showerror to the reverse of
1627 toggle. This is to allow -S and -s to be used in an independent
1628 order but still have the same effect. */
1629 global->showerror = (!toggle)?TRUE:FALSE; /* toggle off */
1633 global->showerror = toggle?1:0; /* toggle on if used with -s */
1636 /* Telnet options */
1637 err = add2list(&config->telnet_options, nextarg);
1642 /* we are uploading */
1645 if(config->url_out || ((config->url_out = config->url_list) != NULL)) {
1646 /* there's a node here, if it already is filled-in continue to find
1648 while(config->url_out && (config->url_out->flags & GETOUT_UPLOAD))
1649 config->url_out = config->url_out->next;
1652 /* now there might or might not be an available node to fill in! */
1656 url = config->url_out;
1658 /* there was no free node, create one! */
1659 url = new_getout(config);
1662 return PARAM_NO_MEM;
1664 url->flags |= GETOUT_UPLOAD; /* mark -T used */
1666 url->flags |= GETOUT_NOUPLOAD;
1668 /* "-" equals stdin, but keep the string around for now */
1669 GetStr(&url->infile, nextarg);
1676 GetStr(&config->userpwd, nextarg);
1680 /* Proxy user:password */
1681 GetStr(&config->proxyuserpwd, nextarg);
1686 /* the '%' thing here will cause the trace get sent to stderr */
1687 Curl_safefree(config->trace_dump);
1688 config->trace_dump = strdup("%");
1689 if(!config->trace_dump)
1690 return PARAM_NO_MEM;
1691 if(config->tracetype && (config->tracetype != TRACE_PLAIN))
1693 "-v, --verbose overrides an earlier trace/verbose option\n");
1694 config->tracetype = TRACE_PLAIN;
1697 /* verbose is disabled here */
1698 config->tracetype = TRACE_NONE;
1701 if(toggle) /* --no-version yields no output! */
1702 return PARAM_VERSION_INFO_REQUESTED;
1706 /* get the output string */
1707 if('@' == *nextarg) {
1708 /* the data begins with a '@' letter, it means that a file name
1709 or - (stdin) follows */
1712 nextarg++; /* pass the @ */
1713 if(curlx_strequal("-", nextarg)) {
1719 file = fopen(nextarg, "r");
1721 err = file2string(&config->writeout, file);
1722 if(file && (file != stdin))
1726 if(!config->writeout)
1727 warnf(config, "Failed to read %s", fname);
1730 GetStr(&config->writeout, nextarg);
1734 GetStr(&config->proxy, nextarg);
1735 config->proxyver = CURLPROXY_HTTP;
1738 /* set custom request */
1739 GetStr(&config->customrequest, nextarg);
1742 /* low speed time */
1743 err = str2unum(&config->low_speed_time, nextarg);
1746 if(!config->low_speed_limit)
1747 config->low_speed_limit = 1;
1750 /* low speed limit */
1751 err = str2unum(&config->low_speed_limit, nextarg);
1754 if(!config->low_speed_time)
1755 config->low_speed_time = 30;
1757 case 'z': /* time condition coming up */
1762 /* If-Modified-Since: (section 14.28 in RFC2068) */
1763 config->timecond = CURL_TIMECOND_IFMODSINCE;
1766 /* If-Unmodified-Since: (section 14.24 in RFC2068) */
1767 config->timecond = CURL_TIMECOND_IFUNMODSINCE;
1771 /* Last-Modified: (section 14.29 in RFC2068) */
1772 config->timecond = CURL_TIMECOND_LASTMOD;
1777 config->condtime=curl_getdate(nextarg, &now);
1778 if(-1 == (int)config->condtime) {
1779 /* now let's see if it is a file name to get the time from instead! */
1780 struct_stat statbuf;
1781 if(-1 == stat(nextarg, &statbuf)) {
1782 /* failed, remove time condition */
1783 config->timecond = CURL_TIMECOND_NONE;
1785 "Illegal date format for -z, --timecond (and not "
1786 "a file name). Disabling time condition. "
1787 "See curl_getdate(3) for valid date syntax.\n");
1790 /* pull the time out from the file */
1791 config->condtime = statbuf.st_mtime;
1795 default: /* unknown flag */
1796 return PARAM_OPTION_UNKNOWN;
1800 } while(!longopt && !singleopt && *++parse && !*usedarg);
1805 ParameterError parse_args(struct GlobalConfig *config, int argc,
1811 ParameterError result = PARAM_OK;
1812 struct OperationConfig *operation = config->first;
1814 for(i = 1, stillflags = TRUE; i < argc && !result; i++) {
1817 if(stillflags && ('-' == argv[i][0])) {
1820 char *flag = argv[i];
1822 if(curlx_strequal("--", argv[i]))
1823 /* This indicates the end of the flags and thus enables the
1824 following (URL) argument to start with -. */
1827 nextarg = (i < (argc - 1)) ? argv[i + 1] : NULL;
1829 result = getparameter(flag, nextarg, &passarg, config, operation);
1830 if(result == PARAM_NEXT_OPERATION) {
1831 if(operation->url_list && operation->url_list->url) {
1832 /* Allocate the next config */
1833 operation->next = malloc(sizeof(struct OperationConfig));
1834 if(operation->next) {
1835 /* Initialise the newly created config */
1836 config_init(operation->next);
1838 /* Copy the easy handle */
1839 operation->next->easy = config->easy;
1841 /* Update the last operation pointer */
1842 config->last = operation->next;
1844 /* Move onto the new config */
1845 operation->next->prev = operation;
1846 operation = operation->next;
1849 result = PARAM_NO_MEM;
1852 /* Reset result to continue */
1855 else if(!result && passarg)
1856 i++; /* we're supposed to skip this */
1862 /* Just add the URL please */
1863 result = getparameter((char *)"--url", argv[i], &used, config,
1868 if(result && result != PARAM_HELP_REQUESTED &&
1869 result != PARAM_MANUAL_REQUESTED &&
1870 result != PARAM_VERSION_INFO_REQUESTED &&
1871 result != PARAM_ENGINES_REQUESTED) {
1872 const char *reason = param2text(result);
1874 if(!curlx_strequal(":", orig_opt))
1875 helpf(operation->errors, "option %s: %s\n", orig_opt, reason);
1877 helpf(operation->errors, "%s\n", reason);