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 {"$M", "unix-socket", TRUE},
180 {"0", "http1.0", FALSE},
181 {"01", "http1.1", FALSE},
182 {"02", "http2", FALSE},
183 {"1", "tlsv1", FALSE},
184 {"10", "tlsv1.0", FALSE},
185 {"11", "tlsv1.1", FALSE},
186 {"12", "tlsv1.2", FALSE},
187 {"2", "sslv2", FALSE},
188 {"3", "sslv3", FALSE},
189 {"4", "ipv4", FALSE},
190 {"6", "ipv6", FALSE},
191 {"a", "append", FALSE},
192 {"A", "user-agent", TRUE},
193 {"b", "cookie", TRUE},
194 {"B", "use-ascii", FALSE},
195 {"c", "cookie-jar", TRUE},
196 {"C", "continue-at", TRUE},
198 {"da", "data-ascii", TRUE},
199 {"db", "data-binary", TRUE},
200 {"de", "data-urlencode", TRUE},
201 {"D", "dump-header", TRUE},
202 {"e", "referer", TRUE},
204 {"Ea", "cacert", TRUE},
205 {"Eb", "cert-type", TRUE},
207 {"Ed", "key-type", TRUE},
208 {"Ee", "pass", TRUE},
209 {"Ef", "engine", TRUE},
210 {"Eg", "capath ", TRUE},
211 {"Eh", "pubkey", TRUE},
212 {"Ei", "hostpubmd5", TRUE},
213 {"Ej", "crlfile", TRUE},
214 {"Ek", "tlsuser", TRUE},
215 {"El", "tlspassword", TRUE},
216 {"Em", "tlsauthtype", TRUE},
217 {"En", "ssl-allow-beast", FALSE},
218 {"Eo", "login-options", TRUE},
219 {"Ep", "pinnedpubkey", TRUE},
220 {"f", "fail", FALSE},
222 {"Fs", "form-string", TRUE},
223 {"g", "globoff", FALSE},
225 {"h", "help", FALSE},
226 {"H", "header", TRUE},
227 {"Hp", "proxy-header", TRUE},
228 {"i", "include", FALSE},
229 {"I", "head", FALSE},
230 {"j", "junk-session-cookies", FALSE},
231 {"J", "remote-header-name", FALSE},
232 {"k", "insecure", FALSE},
233 {"K", "config", TRUE},
234 {"l", "list-only", FALSE},
235 {"L", "location", FALSE},
236 {"Lt", "location-trusted", FALSE},
237 {"m", "max-time", TRUE},
238 {"M", "manual", FALSE},
239 {"n", "netrc", FALSE},
240 {"no", "netrc-optional", FALSE},
241 {"ne", "netrc-file", TRUE},
242 {"N", "buffer", FALSE},
243 /* 'buffer' listed as --no-buffer in the help */
244 {"o", "output", TRUE},
245 {"O", "remote-name", FALSE},
246 {"Oa", "remote-name-all", FALSE},
247 {"p", "proxytunnel", FALSE},
248 {"P", "ftpport", TRUE},
249 /* 'ftpport' old version */
250 {"P", "ftp-port", TRUE},
251 {"q", "disable", FALSE},
252 {"Q", "quote", TRUE},
253 {"r", "range", TRUE},
254 {"R", "remote-time", FALSE},
255 {"s", "silent", FALSE},
256 {"S", "show-error", FALSE},
257 {"t", "telnet-options", TRUE},
258 /* 'telnet-options' documented as telnet-option */
259 {"T", "upload-file", TRUE},
261 {"U", "proxy-user", TRUE},
262 {"v", "verbose", FALSE},
263 {"V", "version", FALSE},
264 {"w", "write-out", TRUE},
265 {"x", "proxy", TRUE},
266 {"X", "request", TRUE},
267 {"X", "http-request", TRUE},
268 /* 'http-request' OBSOLETE VERSION */
269 {"Y", "speed-limit", TRUE},
270 {"y", "speed-time", TRUE},
271 {"z", "time-cond", TRUE},
272 {"#", "progress-bar", FALSE},
273 {":", "next", FALSE},
274 {"~", "xattr", FALSE},
277 /* Split the argument of -E to 'certname' and 'passphrase' separated by colon.
278 * We allow ':' and '\' to be escaped by '\' so that we can use certificate
279 * nicknames containing ':'. See <https://sourceforge.net/p/curl/bugs/1196/>
284 void parse_cert_parameter(const char *cert_parameter,
288 size_t param_length = strlen(cert_parameter);
290 const char *param_place = NULL;
291 char *certname_place = NULL;
295 /* most trivial assumption: cert_parameter is empty */
296 if(param_length == 0)
299 /* next less trivial: cert_parameter contains no colon nor backslash; this
300 * means no passphrase was given and no characters escaped */
301 if(!strpbrk(cert_parameter, ":\\")) {
302 *certname = strdup(cert_parameter);
305 /* deal with escaped chars; find unescaped colon if it exists */
306 certname_place = malloc(param_length + 1);
310 *certname = certname_place;
311 param_place = cert_parameter;
312 while(*param_place) {
313 span = strcspn(param_place, ":\\");
314 strncpy(certname_place, param_place, span);
316 certname_place += span;
317 /* we just ate all the non-special chars. now we're on either a special
318 * char or the end of the string. */
319 switch(*param_place) {
324 switch(*param_place) {
326 *certname_place++ = '\\';
329 *certname_place++ = '\\';
333 *certname_place++ = ':';
337 *certname_place++ = '\\';
338 *certname_place++ = *param_place;
344 /* Since we live in a world of weirdness and confusion, the win32
345 dudes can use : when using drive letters and thus c:\file:password
346 needs to work. In order not to break compatibility, we still use : as
347 separator, but we try to detect when it is used for a file name! On
351 (param_place == &cert_parameter[1]) &&
352 (cert_parameter[2] == '\\' || cert_parameter[2] == '/') &&
353 (ISALPHA(cert_parameter[0])) ) {
354 /* colon in the second column, followed by a backslash, and the
355 first character is an alphabetic letter:
357 this is a drive letter colon */
358 *certname_place++ = ':';
363 /* escaped colons and Windows drive letter colons were handled
364 * above; if we're still here, this is a separating colon */
366 if(strlen(param_place) > 0) {
367 *passphrase = strdup(param_place);
373 *certname_place = '\0';
376 ParameterError getparameter(char *flag, /* f or -long-flag */
377 char *nextarg, /* NULL if unset */
378 bool *usedarg, /* set to TRUE if the arg
380 struct GlobalConfig *global,
381 struct OperationConfig *config)
384 char subletter = '\0'; /* subletters can only occur on long options */
386 const char *parse = NULL;
390 bool longopt = FALSE;
391 bool singleopt = FALSE; /* when true means '-o foo' used '-ofoo' */
393 bool toggle = TRUE; /* how to switch boolean options, on or off. Controlled
394 by using --OPTION or --no-OPTION */
397 if(('-' != flag[0]) ||
398 (('-' == flag[0]) && ('-' == flag[1]))) {
399 /* this should be a long name */
400 char *word = ('-' == flag[0]) ? flag+2 : flag;
401 size_t fnam = strlen(word);
404 if(!strncmp(word, "no-", 3)) {
405 /* disable this option but ignore the "no-" part when looking for it */
410 for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) {
411 if(curlx_strnequal(aliases[j].lname, word, fnam)) {
414 if(curlx_raw_equal(aliases[j].lname, word)) {
415 parse = aliases[j].letter;
417 numhits = 1; /* a single unique hit */
420 parse = aliases[j].letter;
425 /* this is at least the second match! */
426 return PARAM_OPTION_AMBIGUOUS;
429 return PARAM_OPTION_UNKNOWN;
433 flag++; /* prefixed with one dash, pass it */
439 /* we can loop here if we have multiple single-letters */
442 letter = (char)*parse;
447 subletter = parse[1];
449 *usedarg = FALSE; /* default is that we don't use the arg */
452 for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) {
453 if(letter == aliases[j].letter[0]) {
459 return PARAM_OPTION_UNKNOWN;
463 if(aliases[hit].extraparam) {
464 /* this option requires an extra parameter */
465 if(!longopt && parse[1]) {
466 nextarg = (char *)&parse[1]; /* this is the actual extra parameter */
467 singleopt = TRUE; /* don't loop anymore after this */
470 return PARAM_REQUIRES_PARAMETER;
472 *usedarg = TRUE; /* mark it as used */
476 case '*': /* options without a short option */
478 case '4': /* --dns-ipv4-addr */
479 /* addr in dot notation */
480 GetStr(&config->dns_ipv4_addr, nextarg);
482 case '6': /* --dns-ipv6-addr */
483 /* addr in dot notation */
484 GetStr(&config->dns_ipv6_addr, nextarg);
486 case 'a': /* random-file */
487 GetStr(&config->random_file, nextarg);
489 case 'b': /* egd-file */
490 GetStr(&config->egd_file, nextarg);
492 case 'B': /* XOAUTH2 Bearer */
493 GetStr(&config->xoauth2_bearer, nextarg);
495 case 'c': /* connect-timeout */
496 err = str2udouble(&config->connecttimeout, nextarg);
500 case 'd': /* ciphers */
501 GetStr(&config->cipher_list, nextarg);
503 case 'D': /* --dns-interface */
505 GetStr(&config->dns_interface, nextarg);
507 case 'e': /* --disable-epsv */
508 config->disable_epsv = toggle;
510 case 'E': /* --epsv */
511 config->disable_epsv = (!toggle)?TRUE:FALSE;
513 #ifdef USE_ENVIRONMENT
515 config->writeenv = toggle;
518 case 'F': /* --dns-servers */
519 /* IP addrs of DNS servers */
520 GetStr(&config->dns_servers, nextarg);
522 case 'g': /* --trace */
523 GetStr(&global->trace_dump, nextarg);
524 if(global->tracetype && (global->tracetype != TRACE_BIN))
525 warnf(config, "--trace overrides an earlier trace/verbose option\n");
526 global->tracetype = TRACE_BIN;
528 case 'G': /* --npn */
529 config->nonpn = (!toggle)?TRUE:FALSE;
531 case 'h': /* --trace-ascii */
532 GetStr(&global->trace_dump, nextarg);
533 if(global->tracetype && (global->tracetype != TRACE_ASCII))
535 "--trace-ascii overrides an earlier trace/verbose option\n");
536 global->tracetype = TRACE_ASCII;
538 case 'H': /* --alpn */
539 config->noalpn = (!toggle)?TRUE:FALSE;
541 case 'i': /* --limit-rate */
543 /* We support G, M, K too */
545 curl_off_t value = curlx_strtoofft(nextarg, &unit, 0);
549 else if(strlen(unit) > 1)
550 unit = (char *)"w"; /* unsupported */
555 value *= 1024*1024*1024;
567 /* for plain bytes, leave as-is */
570 warnf(config, "unsupported rate unit. Use G, M, K or B!\n");
571 return PARAM_BAD_USE;
573 config->recvpersecond = value;
574 config->sendpersecond = value;
578 case 'j': /* --compressed */
579 if(toggle && !(curlinfo->features & CURL_VERSION_LIBZ))
580 return PARAM_LIBCURL_DOESNT_SUPPORT;
581 config->encoding = toggle;
584 case 'J': /* --tr-encoding */
585 config->tr_encoding = toggle;
588 case 'k': /* --digest */
590 config->authtype |= CURLAUTH_DIGEST;
592 config->authtype &= ~CURLAUTH_DIGEST;
595 case 'l': /* --negotiate */
597 if(curlinfo->features & CURL_VERSION_SPNEGO)
598 config->authtype |= CURLAUTH_NEGOTIATE;
600 return PARAM_LIBCURL_DOESNT_SUPPORT;
603 config->authtype &= ~CURLAUTH_NEGOTIATE;
606 case 'm': /* --ntlm */
608 if(curlinfo->features & CURL_VERSION_NTLM)
609 config->authtype |= CURLAUTH_NTLM;
611 return PARAM_LIBCURL_DOESNT_SUPPORT;
614 config->authtype &= ~CURLAUTH_NTLM;
617 case 'M': /* --ntlm-wb */
619 if(curlinfo->features & CURL_VERSION_NTLM_WB)
620 config->authtype |= CURLAUTH_NTLM_WB;
622 return PARAM_LIBCURL_DOESNT_SUPPORT;
625 config->authtype &= ~CURLAUTH_NTLM_WB;
628 case 'n': /* --basic for completeness */
630 config->authtype |= CURLAUTH_BASIC;
632 config->authtype &= ~CURLAUTH_BASIC;
635 case 'o': /* --anyauth, let libcurl pick it */
637 config->authtype = CURLAUTH_ANY;
638 /* --no-anyauth simply doesn't touch it */
642 case 'p': /* --wdebug */
646 case 'q': /* --ftp-create-dirs */
647 config->ftp_create_dirs = toggle;
650 case 'r': /* --create-dirs */
651 config->create_dirs = toggle;
654 case 's': /* --max-redirs */
655 /* specified max no of redirects (http(s)), this accepts -1 as a
657 err = str2num(&config->maxredirs, nextarg);
660 if(config->maxredirs < -1)
661 return PARAM_BAD_NUMERIC;
664 case 't': /* --proxy-ntlm */
665 if(curlinfo->features & CURL_VERSION_NTLM)
666 config->proxyntlm = toggle;
668 return PARAM_LIBCURL_DOESNT_SUPPORT;
671 case 'u': /* --crlf */
672 /* LF -> CRLF conversion? */
673 config->crlf = toggle;
676 case 'v': /* --stderr */
677 if(strcmp(nextarg, "-")) {
678 FILE *newfile = fopen(nextarg, "wt");
680 warnf(config, "Failed to open %s!\n", nextarg);
682 if(global->errors_fopened)
683 fclose(global->errors);
684 global->errors = newfile;
685 global->errors_fopened = TRUE;
689 global->errors = stdout;
691 case 'w': /* --interface */
693 GetStr(&config->iface, nextarg);
695 case 'x': /* --krb */
696 /* kerberos level string */
697 if(curlinfo->features & CURL_VERSION_KERBEROS4)
698 GetStr(&config->krblevel, nextarg);
700 return PARAM_LIBCURL_DOESNT_SUPPORT;
702 case 'y': /* --max-filesize */
703 err = str2offset(&config->max_filesize, nextarg);
707 case 'z': /* --disable-eprt */
708 config->disable_eprt = toggle;
710 case 'Z': /* --eprt */
711 config->disable_eprt = (!toggle)?TRUE:FALSE;
714 default: /* the URL! */
717 if(config->url_get || ((config->url_get = config->url_list) != NULL)) {
718 /* there's a node here, if it already is filled-in continue to find
720 while(config->url_get && (config->url_get->flags & GETOUT_URL))
721 config->url_get = config->url_get->next;
724 /* now there might or might not be an available node to fill in! */
728 url = config->url_get;
730 /* there was no free node, create one! */
731 url = new_getout(config);
736 /* fill in the URL */
737 GetStr(&url->url, nextarg);
738 url->flags |= GETOUT_URL;
743 case '$': /* more options without a short option */
745 case 'a': /* --ftp-ssl */
746 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
747 return PARAM_LIBCURL_DOESNT_SUPPORT;
748 config->ftp_ssl = toggle;
750 case 'b': /* --ftp-pasv */
751 Curl_safefree(config->ftpport);
753 case 'c': /* --socks5 specifies a socks5 proxy to use, and resolves
754 the name locally and passes on the resolved address */
755 GetStr(&config->socksproxy, nextarg);
756 config->socksver = CURLPROXY_SOCKS5;
758 case 't': /* --socks4 specifies a socks4 proxy to use */
759 GetStr(&config->socksproxy, nextarg);
760 config->socksver = CURLPROXY_SOCKS4;
762 case 'T': /* --socks4a specifies a socks4a proxy to use */
763 GetStr(&config->socksproxy, nextarg);
764 config->socksver = CURLPROXY_SOCKS4A;
766 case '2': /* --socks5-hostname specifies a socks5 proxy and enables name
767 resolving with the proxy */
768 GetStr(&config->socksproxy, nextarg);
769 config->socksver = CURLPROXY_SOCKS5_HOSTNAME;
771 case 'd': /* --tcp-nodelay option */
772 config->tcp_nodelay = toggle;
774 case 'e': /* --proxy-digest */
775 config->proxydigest = toggle;
777 case 'f': /* --proxy-basic */
778 config->proxybasic = toggle;
780 case 'g': /* --retry */
781 err = str2unum(&config->req_retry, nextarg);
785 case 'h': /* --retry-delay */
786 err = str2unum(&config->retry_delay, nextarg);
790 case 'i': /* --retry-max-time */
791 err = str2unum(&config->retry_maxtime, nextarg);
796 case 'k': /* --proxy-negotiate */
797 if(curlinfo->features & CURL_VERSION_SPNEGO)
798 config->proxynegotiate = toggle;
800 return PARAM_LIBCURL_DOESNT_SUPPORT;
803 case 'm': /* --ftp-account */
804 GetStr(&config->ftp_account, nextarg);
806 case 'n': /* --proxy-anyauth */
807 config->proxyanyauth = toggle;
809 case 'o': /* --trace-time */
810 global->tracetime = toggle;
812 case 'p': /* --ignore-content-length */
813 config->ignorecl = toggle;
815 case 'q': /* --ftp-skip-pasv-ip */
816 config->ftp_skip_ip = toggle;
818 case 'r': /* --ftp-method (undocumented at this point) */
819 config->ftp_filemethod = ftpfilemethod(config, nextarg);
821 case 's': /* --local-port */
822 rc = sscanf(nextarg, "%d - %d",
824 &config->localportrange);
826 return PARAM_BAD_USE;
828 config->localportrange = 1; /* default number of ports to try */
830 config->localportrange -= config->localport;
831 if(config->localportrange < 1) {
832 warnf(config, "bad range input\n");
833 return PARAM_BAD_USE;
837 case 'u': /* --ftp-alternative-to-user */
838 GetStr(&config->ftp_alternative_to_user, nextarg);
840 case 'v': /* --ftp-ssl-reqd */
841 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
842 return PARAM_LIBCURL_DOESNT_SUPPORT;
843 config->ftp_ssl_reqd = toggle;
845 case 'w': /* --no-sessionid */
846 config->disable_sessionid = (!toggle)?TRUE:FALSE;
848 case 'x': /* --ftp-ssl-control */
849 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
850 return PARAM_LIBCURL_DOESNT_SUPPORT;
851 config->ftp_ssl_control = toggle;
853 case 'y': /* --ftp-ssl-ccc */
854 config->ftp_ssl_ccc = toggle;
855 if(!config->ftp_ssl_ccc_mode)
856 config->ftp_ssl_ccc_mode = CURLFTPSSL_CCC_PASSIVE;
858 case 'j': /* --ftp-ssl-ccc-mode */
859 config->ftp_ssl_ccc = TRUE;
860 config->ftp_ssl_ccc_mode = ftpcccmethod(config, nextarg);
862 case 'z': /* --libcurl */
863 #ifdef CURL_DISABLE_LIBCURL_OPTION
865 "--libcurl option was disabled at build-time!\n");
866 return PARAM_OPTION_UNKNOWN;
868 GetStr(&global->libcurl, nextarg);
871 case '#': /* --raw */
872 config->raw = toggle;
874 case '0': /* --post301 */
875 config->post301 = toggle;
877 case '1': /* --no-keepalive */
878 config->nokeepalive = (!toggle)?TRUE:FALSE;
880 case '3': /* --keepalive-time */
881 err = str2unum(&config->alivetime, nextarg);
885 case '4': /* --post302 */
886 config->post302 = toggle;
888 case 'I': /* --post303 */
889 config->post303 = toggle;
891 case '5': /* --noproxy */
892 /* This specifies the noproxy list */
893 GetStr(&config->noproxy, nextarg);
895 #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
896 case '6': /* --socks5-gssapi-service */
897 GetStr(&config->socks5_gssapi_service, nextarg);
899 case '7': /* --socks5-gssapi-nec*/
900 config->socks5_gssapi_nec = toggle;
903 case '8': /* --proxy1.0 */
905 GetStr(&config->proxy, nextarg);
906 config->proxyver = CURLPROXY_HTTP_1_0;
908 case '9': /* --tftp-blksize */
909 err = str2unum(&config->tftp_blksize, nextarg);
913 case 'A': /* --mail-from */
914 GetStr(&config->mail_from, nextarg);
916 case 'B': /* --mail-rcpt */
917 /* append receiver to a list */
918 err = add2list(&config->mail_rcpt, nextarg);
922 case 'C': /* --ftp-pret */
923 config->ftp_pret = toggle;
925 case 'D': /* --proto */
926 config->proto_present = TRUE;
927 if(proto2num(config, &config->proto, nextarg))
928 return PARAM_BAD_USE;
930 case 'E': /* --proto-redir */
931 config->proto_redir_present = TRUE;
932 if(proto2num(config, &config->proto_redir, nextarg))
933 return PARAM_BAD_USE;
935 case 'F': /* --resolve */
936 err = add2list(&config->resolve, nextarg);
940 case 'G': /* --delegation LEVEL */
941 config->gssapi_delegation = delegation(config, nextarg);
943 case 'H': /* --mail-auth */
944 GetStr(&config->mail_auth, nextarg);
946 case 'J': /* --metalink */
949 int mlmaj, mlmin, mlpatch;
950 metalink_get_version(&mlmaj, &mlmin, &mlpatch);
951 if((mlmaj*10000)+(mlmin*100)+mlpatch < CURL_REQ_LIBMETALINK_VERS) {
953 "--metalink option cannot be used because the version of "
954 "the linked libmetalink library is too old. "
955 "Required: %d.%d.%d, found %d.%d.%d\n",
956 CURL_REQ_LIBMETALINK_MAJOR,
957 CURL_REQ_LIBMETALINK_MINOR,
958 CURL_REQ_LIBMETALINK_PATCH,
959 mlmaj, mlmin, mlpatch);
960 return PARAM_BAD_USE;
963 config->use_metalink = toggle;
965 warnf(config, "--metalink option is ignored because the binary is "
966 "built without the Metalink support.\n");
970 case 'K': /* --sasl-ir */
971 config->sasl_ir = toggle;
973 case 'L': /* --test-event */
975 config->test_event_based = toggle;
977 warnf(config, "--test-event is ignored unless a debug build!\n");
980 case 'M': /* --unix-socket */
981 GetStr(&config->unix_socket_path, nextarg);
985 case '#': /* --progress-bar */
987 global->progressmode = CURL_PROGRESS_BAR;
989 global->progressmode = CURL_PROGRESS_STATS;
991 case ':': /* --next */
992 return PARAM_NEXT_OPERATION;
993 case '~': /* --xattr */
994 config->xattr = toggle;
996 case '0': /* --http* options */
999 /* HTTP version 1.0 */
1000 config->httpversion = CURL_HTTP_VERSION_1_0;
1003 /* HTTP version 1.1 */
1004 config->httpversion = CURL_HTTP_VERSION_1_1;
1007 /* HTTP version 2.0 */
1008 config->httpversion = CURL_HTTP_VERSION_2_0;
1012 case '1': /* --tlsv1* options */
1015 /* TLS version 1.x */
1016 config->ssl_version = CURL_SSLVERSION_TLSv1;
1019 /* TLS version 1.0 */
1020 config->ssl_version = CURL_SSLVERSION_TLSv1_0;
1023 /* TLS version 1.1 */
1024 config->ssl_version = CURL_SSLVERSION_TLSv1_1;
1027 /* TLS version 1.2 */
1028 config->ssl_version = CURL_SSLVERSION_TLSv1_2;
1034 config->ssl_version = CURL_SSLVERSION_SSLv2;
1038 config->ssl_version = CURL_SSLVERSION_SSLv3;
1042 config->ip_version = 4;
1046 config->ip_version = 6;
1049 /* This makes the FTP sessions use APPE instead of STOR */
1050 config->ftp_append = toggle;
1053 /* This specifies the User-Agent name */
1054 GetStr(&config->useragent, nextarg);
1056 case 'b': /* cookie string coming up: */
1057 if(nextarg[0] == '@') {
1060 else if(strchr(nextarg, '=')) {
1061 /* A cookie string must have a =-letter */
1062 GetStr(&config->cookie, nextarg);
1065 /* We have a cookie file to read from! */
1066 GetStr(&config->cookiefile, nextarg);
1069 /* use ASCII/text when transferring */
1070 config->use_ascii = toggle;
1073 /* get the file name to dump all cookies in */
1074 GetStr(&config->cookiejar, nextarg);
1077 /* This makes us continue an ftp transfer at given position */
1078 if(!curlx_strequal(nextarg, "-")) {
1079 err = str2offset(&config->resume_from, nextarg);
1082 config->resume_from_current = FALSE;
1085 config->resume_from_current = TRUE;
1086 config->resume_from = 0;
1088 config->use_resume=TRUE;
1091 /* postfield data */
1093 char *postdata = NULL;
1097 if(subletter == 'e') { /* --data-urlencode*/
1098 /* [name]=[content], we encode the content part only
1099 * [name]@[file name]
1101 * Case 2: we first load the file using that name and then encode
1104 const char *p = strchr(nextarg, '=');
1108 /* there was no '=' letter, check for a '@' instead */
1109 p = strchr(nextarg, '@');
1111 nlen = p - nextarg; /* length of the name part */
1112 is_file = *p++; /* pass the separator */
1115 /* neither @ nor =, so no name and it isn't a file */
1119 if('@' == is_file) {
1120 /* a '@' letter, it means that a file name or - (stdin) follows */
1122 if(curlx_strequal("-", p)) {
1127 file = fopen(p, "rb");
1130 "Couldn't read data from file \"%s\", this makes "
1131 "an empty POST.\n", nextarg);
1134 err = file2memory(&postdata, &size, file);
1136 if(file && (file != stdin))
1142 GetStr(&postdata, p);
1144 size = strlen(postdata);
1148 /* no data from the file, point to a zero byte string to make this
1149 get sent as a POST anyway */
1150 postdata = strdup("");
1152 return PARAM_NO_MEM;
1156 char *enc = curl_easy_escape(config->easy, postdata, (int)size);
1157 Curl_safefree(postdata); /* no matter if it worked or not */
1159 /* now make a string with the name from above and append the
1161 size_t outlen = nlen + strlen(enc) + 2;
1162 char *n = malloc(outlen);
1165 return PARAM_NO_MEM;
1167 if(nlen > 0) { /* only append '=' if we have a name */
1168 snprintf(n, outlen, "%.*s=%s", nlen, nextarg, enc);
1173 size = outlen-2; /* since no '=' was inserted */
1179 return PARAM_NO_MEM;
1182 else if('@' == *nextarg) {
1183 /* the data begins with a '@' letter, it means that a file name
1184 or - (stdin) follows */
1185 nextarg++; /* pass the @ */
1187 if(curlx_strequal("-", nextarg)) {
1189 if(subletter == 'b') /* forced data-binary */
1193 file = fopen(nextarg, "rb");
1195 warnf(config, "Couldn't read data from file \"%s\", this makes "
1196 "an empty POST.\n", nextarg);
1199 if(subletter == 'b')
1201 err = file2memory(&postdata, &size, file);
1203 err = file2string(&postdata, file);
1205 size = strlen(postdata);
1208 if(file && (file != stdin))
1214 /* no data from the file, point to a zero byte string to make this
1215 get sent as a POST anyway */
1216 postdata = strdup("");
1218 return PARAM_NO_MEM;
1222 GetStr(&postdata, nextarg);
1224 size = strlen(postdata);
1227 #ifdef CURL_DOES_CONVERSIONS
1228 if(subletter != 'b') {
1229 /* NOT forced binary, convert to ASCII */
1230 if(convert_to_network(postdata, strlen(postdata))) {
1231 Curl_safefree(postdata);
1232 return PARAM_NO_MEM;
1237 if(config->postfields) {
1238 /* we already have a string, we append this one with a separating
1240 char *oldpost = config->postfields;
1241 curl_off_t oldlen = config->postfieldsize;
1242 curl_off_t newlen = oldlen + curlx_uztoso(size) + 2;
1243 config->postfields = malloc((size_t)newlen);
1244 if(!config->postfields) {
1245 Curl_safefree(oldpost);
1246 Curl_safefree(postdata);
1247 return PARAM_NO_MEM;
1249 memcpy(config->postfields, oldpost, (size_t)oldlen);
1250 /* use byte value 0x26 for '&' to accommodate non-ASCII platforms */
1251 config->postfields[oldlen] = '\x26';
1252 memcpy(&config->postfields[oldlen+1], postdata, size);
1253 config->postfields[oldlen+1+size] = '\0';
1254 Curl_safefree(oldpost);
1255 Curl_safefree(postdata);
1256 config->postfieldsize += size+1;
1259 config->postfields = postdata;
1260 config->postfieldsize = curlx_uztoso(size);
1264 We can't set the request type here, as this data might be used in
1265 a simple GET if -G is used. Already or soon.
1267 if(SetHTTPrequest(HTTPREQ_SIMPLEPOST, &config->httpreq)) {
1268 Curl_safefree(postdata);
1269 return PARAM_BAD_USE;
1274 /* dump-header to given file name */
1275 GetStr(&config->headerfile, nextarg);
1279 char *ptr = strstr(nextarg, ";auto");
1281 /* Automatic referer requested, this may be combined with a
1283 config->autoreferer = TRUE;
1284 *ptr = 0; /* zero terminate here */
1287 config->autoreferer = FALSE;
1288 GetStr(&config->referer, nextarg);
1293 case 'a': /* CA info PEM file */
1294 /* CA info PEM file */
1295 GetStr(&config->cacert, nextarg);
1297 case 'b': /* cert file type */
1298 GetStr(&config->cert_type, nextarg);
1300 case 'c': /* private key file */
1301 GetStr(&config->key, nextarg);
1303 case 'd': /* private key file type */
1304 GetStr(&config->key_type, nextarg);
1306 case 'e': /* private key passphrase */
1307 GetStr(&config->key_passwd, nextarg);
1310 case 'f': /* crypto engine */
1311 GetStr(&config->engine, nextarg);
1312 if(config->engine && curlx_raw_equal(config->engine,"list"))
1313 return PARAM_ENGINES_REQUESTED;
1315 case 'g': /* CA info PEM file */
1316 /* CA cert directory */
1317 GetStr(&config->capath, nextarg);
1319 case 'h': /* --pubkey public key file */
1320 GetStr(&config->pubkey, nextarg);
1322 case 'i': /* --hostpubmd5 md5 of the host public key */
1323 GetStr(&config->hostpubmd5, nextarg);
1324 if(!config->hostpubmd5 || strlen(config->hostpubmd5) != 32)
1325 return PARAM_BAD_USE;
1327 case 'j': /* CRL info PEM file */
1329 GetStr(&config->crlfile, nextarg);
1331 case 'k': /* TLS username */
1332 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)
1333 GetStr(&config->tls_username, nextarg);
1335 return PARAM_LIBCURL_DOESNT_SUPPORT;
1337 case 'l': /* TLS password */
1338 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)
1339 GetStr(&config->tls_password, nextarg);
1341 return PARAM_LIBCURL_DOESNT_SUPPORT;
1343 case 'm': /* TLS authentication type */
1344 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP) {
1345 GetStr(&config->tls_authtype, nextarg);
1346 if(!strequal(config->tls_authtype, "SRP"))
1347 return PARAM_LIBCURL_DOESNT_SUPPORT; /* only support TLS-SRP */
1350 return PARAM_LIBCURL_DOESNT_SUPPORT;
1352 case 'n': /* no empty SSL fragments, --ssl-allow-beast */
1353 if(curlinfo->features & CURL_VERSION_SSL)
1354 config->ssl_allow_beast = toggle;
1357 case 'o': /* --login-options */
1358 GetStr(&config->login_options, nextarg);
1361 case 'p': /* Pinned public key DER file */
1362 /* Pinned public key DER file */
1363 GetStr(&config->pinnedpubkey, nextarg);
1366 default: /* certificate file */
1368 char *certname, *passphrase;
1369 parse_cert_parameter(nextarg, &certname, &passphrase);
1370 Curl_safefree(config->cert);
1371 config->cert = certname;
1373 Curl_safefree(config->key_passwd);
1374 config->key_passwd = passphrase;
1381 /* fail hard on errors */
1382 config->failonerror = toggle;
1385 /* "form data" simulation, this is a little advanced so lets do our best
1386 to sort this out slowly and carefully */
1387 if(formparse(config,
1391 (subletter=='s')?TRUE:FALSE)) /* 's' means literal string */
1392 return PARAM_BAD_USE;
1393 if(SetHTTPrequest(config, HTTPREQ_POST, &config->httpreq))
1394 return PARAM_BAD_USE;
1397 case 'g': /* g disables URLglobbing */
1398 config->globoff = toggle;
1401 case 'G': /* HTTP GET */
1402 config->use_httpget = TRUE;
1405 case 'h': /* h for help */
1407 return PARAM_HELP_REQUESTED;
1409 /* we now actually support --no-help too! */
1412 /* A custom header to append to a list */
1413 if(subletter == 'p') /* --proxy-header */
1414 err = add2list(&config->proxyheaders, nextarg);
1416 err = add2list(&config->headers, nextarg);
1421 config->include_headers = toggle; /* include the headers as well in the
1422 general output stream */
1425 config->cookiesession = toggle;
1429 * no_body will imply include_headers later on
1431 config->no_body = toggle;
1432 if(SetHTTPrequest(config,
1433 (config->no_body)?HTTPREQ_HEAD:HTTPREQ_GET,
1435 return PARAM_BAD_USE;
1437 case 'J': /* --remote-header-name */
1438 if(config->include_headers) {
1440 "--include and --remote-header-name cannot be combined.\n");
1441 return PARAM_BAD_USE;
1443 config->content_disposition = toggle;
1445 case 'k': /* allow insecure SSL connects */
1446 config->insecure_ok = toggle;
1448 case 'K': /* parse config file */
1449 if(parseconfig(nextarg, global))
1450 warnf(config, "error trying read config from the '%s' file\n",
1454 config->dirlistonly = toggle; /* only list the names of the FTP dir */
1457 config->followlocation = toggle; /* Follow Location: HTTP headers */
1458 switch (subletter) {
1460 /* Continue to send authentication (user+password) when following
1461 * locations, even when hostname changed */
1462 config->unrestricted_auth = toggle;
1467 /* specified max time */
1468 err = str2udouble(&config->timeout, nextarg);
1472 case 'M': /* M for manual, huge help */
1473 if(toggle) { /* --no-manual shows no manual... */
1475 return PARAM_MANUAL_REQUESTED;
1478 "built-in manual was disabled at build-time!\n");
1479 return PARAM_OPTION_UNKNOWN;
1485 case 'o': /* CA info PEM file */
1486 /* use .netrc or URL */
1487 config->netrc_opt = toggle;
1489 case 'e': /* netrc-file */
1490 GetStr(&config->netrc_file, nextarg);
1493 /* pick info from .netrc, if this is used for http, curl will
1494 automatically enfore user+password with the request */
1495 config->netrc = toggle;
1500 /* disable the output I/O buffering. note that the option is called
1501 --buffer but is mostly used in the negative form: --no-buffer */
1503 config->nobuffer = (!toggle)?TRUE:FALSE;
1505 config->nobuffer = toggle;
1507 case 'O': /* --remote-name */
1508 if(subletter == 'a') { /* --remote-name-all */
1509 config->default_node_flags = toggle?GETOUT_USEREMOTE:0;
1513 case 'o': /* --output */
1517 if(config->url_out || ((config->url_out = config->url_list) != NULL)) {
1518 /* there's a node here, if it already is filled-in continue to find
1520 while(config->url_out && (config->url_out->flags & GETOUT_OUTFILE))
1521 config->url_out = config->url_out->next;
1524 /* now there might or might not be an available node to fill in! */
1528 url = config->url_out;
1530 /* there was no free node, create one! */
1531 url = new_getout(config);
1534 return PARAM_NO_MEM;
1536 /* fill in the outfile */
1538 GetStr(&url->outfile, nextarg);
1539 url->flags &= ~GETOUT_USEREMOTE; /* switch off */
1542 url->outfile = NULL; /* leave it */
1544 url->flags |= GETOUT_USEREMOTE; /* switch on */
1546 url->flags &= ~GETOUT_USEREMOTE; /* switch off */
1548 url->flags |= GETOUT_OUTFILE;
1553 /* This makes the FTP sessions use PORT instead of PASV */
1554 /* use <eth0> or <192.168.10.10> style addresses. Anything except
1555 this will make us try to get the "default" address.
1556 NOTE: this is a changed behaviour since the released 4.1!
1558 GetStr(&config->ftpport, nextarg);
1561 /* proxy tunnel for non-http protocols */
1562 config->proxytunnel = toggle;
1565 case 'q': /* if used first, already taken care of, we do it like
1566 this so we don't cause an error! */
1569 /* QUOTE command to send to FTP server */
1570 switch(nextarg[0]) {
1572 /* prefixed with a dash makes it a POST TRANSFER one */
1574 err = add2list(&config->postquote, nextarg);
1577 /* prefixed with a plus makes it a just-before-transfer one */
1579 err = add2list(&config->prequote, nextarg);
1582 err = add2list(&config->quote, nextarg);
1589 /* Specifying a range WITHOUT A DASH will create an illegal HTTP range
1590 (and won't actually be range by definition). The man page previously
1591 claimed that to be a good way, why this code is added to work-around
1593 if(ISDIGIT(*nextarg) && !strchr(nextarg, '-')) {
1597 "A specified range MUST include at least one dash (-). "
1598 "Appending one for you!\n");
1599 off = curlx_strtoofft(nextarg, NULL, 10);
1600 snprintf(buffer, sizeof(buffer), "%" CURL_FORMAT_CURL_OFF_T "-", off);
1601 Curl_safefree(config->range);
1602 config->range = strdup(buffer);
1604 return PARAM_NO_MEM;
1607 /* byte range requested */
1609 tmp_range = nextarg;
1610 while(*tmp_range != '\0') {
1611 if(!ISDIGIT(*tmp_range) && *tmp_range != '-' && *tmp_range != ',') {
1612 warnf(config,"Invalid character is found in given range. "
1613 "A specified range MUST have only digits in "
1614 "\'start\'-\'stop\'. The server's response to this "
1615 "request is uncertain.\n");
1620 /* byte range requested */
1621 GetStr(&config->range, nextarg);
1625 /* use remote file's time */
1626 config->remote_time = toggle;
1629 /* don't show progress meter, don't show errors : */
1631 global->mute = global->noprogress = TRUE;
1633 global->mute = global->noprogress = FALSE;
1634 if(global->showerror < 0)
1635 /* if still on the default value, set showerror to the reverse of
1636 toggle. This is to allow -S and -s to be used in an independent
1637 order but still have the same effect. */
1638 global->showerror = (!toggle)?TRUE:FALSE; /* toggle off */
1642 global->showerror = toggle?1:0; /* toggle on if used with -s */
1645 /* Telnet options */
1646 err = add2list(&config->telnet_options, nextarg);
1651 /* we are uploading */
1654 if(config->url_out || ((config->url_out = config->url_list) != NULL)) {
1655 /* there's a node here, if it already is filled-in continue to find
1657 while(config->url_out && (config->url_out->flags & GETOUT_UPLOAD))
1658 config->url_out = config->url_out->next;
1661 /* now there might or might not be an available node to fill in! */
1665 url = config->url_out;
1667 /* there was no free node, create one! */
1668 url = new_getout(config);
1671 return PARAM_NO_MEM;
1673 url->flags |= GETOUT_UPLOAD; /* mark -T used */
1675 url->flags |= GETOUT_NOUPLOAD;
1677 /* "-" equals stdin, but keep the string around for now */
1678 GetStr(&url->infile, nextarg);
1685 GetStr(&config->userpwd, nextarg);
1689 /* Proxy user:password */
1690 GetStr(&config->proxyuserpwd, nextarg);
1695 /* the '%' thing here will cause the trace get sent to stderr */
1696 Curl_safefree(global->trace_dump);
1697 global->trace_dump = strdup("%");
1698 if(!global->trace_dump)
1699 return PARAM_NO_MEM;
1700 if(global->tracetype && (global->tracetype != TRACE_PLAIN))
1702 "-v, --verbose overrides an earlier trace/verbose option\n");
1703 global->tracetype = TRACE_PLAIN;
1706 /* verbose is disabled here */
1707 global->tracetype = TRACE_NONE;
1710 if(toggle) /* --no-version yields no output! */
1711 return PARAM_VERSION_INFO_REQUESTED;
1715 /* get the output string */
1716 if('@' == *nextarg) {
1717 /* the data begins with a '@' letter, it means that a file name
1718 or - (stdin) follows */
1721 nextarg++; /* pass the @ */
1722 if(curlx_strequal("-", nextarg)) {
1728 file = fopen(nextarg, "r");
1730 err = file2string(&config->writeout, file);
1731 if(file && (file != stdin))
1735 if(!config->writeout)
1736 warnf(config, "Failed to read %s", fname);
1739 GetStr(&config->writeout, nextarg);
1743 GetStr(&config->proxy, nextarg);
1744 config->proxyver = CURLPROXY_HTTP;
1747 /* set custom request */
1748 GetStr(&config->customrequest, nextarg);
1751 /* low speed time */
1752 err = str2unum(&config->low_speed_time, nextarg);
1755 if(!config->low_speed_limit)
1756 config->low_speed_limit = 1;
1759 /* low speed limit */
1760 err = str2unum(&config->low_speed_limit, nextarg);
1763 if(!config->low_speed_time)
1764 config->low_speed_time = 30;
1766 case 'z': /* time condition coming up */
1772 /* If-Modified-Since: (section 14.28 in RFC2068) */
1773 config->timecond = CURL_TIMECOND_IFMODSINCE;
1776 /* If-Unmodified-Since: (section 14.24 in RFC2068) */
1777 config->timecond = CURL_TIMECOND_IFUNMODSINCE;
1781 /* Last-Modified: (section 14.29 in RFC2068) */
1782 config->timecond = CURL_TIMECOND_LASTMOD;
1787 config->condtime=curl_getdate(nextarg, &now);
1788 if(-1 == (int)config->condtime) {
1789 /* now let's see if it is a file name to get the time from instead! */
1790 struct_stat statbuf;
1791 if(-1 == stat(nextarg, &statbuf)) {
1792 /* failed, remove time condition */
1793 config->timecond = CURL_TIMECOND_NONE;
1795 "Illegal date format for -z, --timecond (and not "
1796 "a file name). Disabling time condition. "
1797 "See curl_getdate(3) for valid date syntax.\n");
1800 /* pull the time out from the file */
1801 config->condtime = statbuf.st_mtime;
1805 default: /* unknown flag */
1806 return PARAM_OPTION_UNKNOWN;
1810 } while(!longopt && !singleopt && *++parse && !*usedarg);
1815 ParameterError parse_args(struct GlobalConfig *config, int argc,
1820 char *orig_opt = NULL;
1821 ParameterError result = PARAM_OK;
1822 struct OperationConfig *operation = config->first;
1824 for(i = 1, stillflags = TRUE; i < argc && !result; i++) {
1827 if(stillflags && ('-' == argv[i][0])) {
1830 char *flag = argv[i];
1832 if(curlx_strequal("--", argv[i]))
1833 /* This indicates the end of the flags and thus enables the
1834 following (URL) argument to start with -. */
1837 nextarg = (i < (argc - 1)) ? argv[i + 1] : NULL;
1839 result = getparameter(flag, nextarg, &passarg, config, operation);
1840 if(result == PARAM_NEXT_OPERATION) {
1841 /* Reset result as PARAM_NEXT_OPERATION is only used here and not
1842 returned from this function */
1845 if(operation->url_list && operation->url_list->url) {
1846 /* Allocate the next config */
1847 operation->next = malloc(sizeof(struct OperationConfig));
1848 if(operation->next) {
1849 /* Initialise the newly created config */
1850 config_init(operation->next);
1852 /* Copy the easy handle */
1853 operation->next->easy = config->easy;
1855 /* Set the global config pointer */
1856 operation->next->global = config;
1858 /* Update the last operation pointer */
1859 config->last = operation->next;
1861 /* Move onto the new config */
1862 operation->next->prev = operation;
1863 operation = operation->next;
1866 result = PARAM_NO_MEM;
1869 else if(!result && passarg)
1870 i++; /* we're supposed to skip this */
1876 /* Just add the URL please */
1877 result = getparameter((char *)"--url", argv[i], &used, config,
1882 if(result && result != PARAM_HELP_REQUESTED &&
1883 result != PARAM_MANUAL_REQUESTED &&
1884 result != PARAM_VERSION_INFO_REQUESTED &&
1885 result != PARAM_ENGINES_REQUESTED) {
1886 const char *reason = param2text(result);
1888 if(orig_opt && !curlx_strequal(":", orig_opt))
1889 helpf(config->errors, "option %s: %s\n", orig_opt, reason);
1891 helpf(config->errors, "%s\n", reason);