1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2015, 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 {"Eq", "cert-status", FALSE},
221 {"f", "fail", FALSE},
223 {"Fs", "form-string", TRUE},
224 {"g", "globoff", FALSE},
226 {"h", "help", FALSE},
227 {"H", "header", TRUE},
228 {"Hp", "proxy-header", TRUE},
229 {"i", "include", FALSE},
230 {"I", "head", FALSE},
231 {"j", "junk-session-cookies", FALSE},
232 {"J", "remote-header-name", FALSE},
233 {"k", "insecure", FALSE},
234 {"K", "config", TRUE},
235 {"l", "list-only", FALSE},
236 {"L", "location", FALSE},
237 {"Lt", "location-trusted", FALSE},
238 {"m", "max-time", TRUE},
239 {"M", "manual", FALSE},
240 {"n", "netrc", FALSE},
241 {"no", "netrc-optional", FALSE},
242 {"ne", "netrc-file", TRUE},
243 {"N", "buffer", FALSE},
244 /* 'buffer' listed as --no-buffer in the help */
245 {"o", "output", TRUE},
246 {"O", "remote-name", FALSE},
247 {"Oa", "remote-name-all", FALSE},
248 {"p", "proxytunnel", FALSE},
249 {"P", "ftpport", TRUE},
250 /* 'ftpport' old version */
251 {"P", "ftp-port", TRUE},
252 {"q", "disable", FALSE},
253 {"Q", "quote", TRUE},
254 {"r", "range", TRUE},
255 {"R", "remote-time", FALSE},
256 {"s", "silent", FALSE},
257 {"S", "show-error", FALSE},
258 {"t", "telnet-options", TRUE},
259 /* 'telnet-options' documented as telnet-option */
260 {"T", "upload-file", TRUE},
262 {"U", "proxy-user", TRUE},
263 {"v", "verbose", FALSE},
264 {"V", "version", FALSE},
265 {"w", "write-out", TRUE},
266 {"x", "proxy", TRUE},
267 {"X", "request", TRUE},
268 {"X", "http-request", TRUE},
269 /* 'http-request' OBSOLETE VERSION */
270 {"Y", "speed-limit", TRUE},
271 {"y", "speed-time", TRUE},
272 {"z", "time-cond", TRUE},
273 {"#", "progress-bar", FALSE},
274 {":", "next", FALSE},
275 {"~", "xattr", FALSE},
278 /* Split the argument of -E to 'certname' and 'passphrase' separated by colon.
279 * We allow ':' and '\' to be escaped by '\' so that we can use certificate
280 * nicknames containing ':'. See <https://sourceforge.net/p/curl/bugs/1196/>
285 void parse_cert_parameter(const char *cert_parameter,
289 size_t param_length = strlen(cert_parameter);
291 const char *param_place = NULL;
292 char *certname_place = NULL;
296 /* most trivial assumption: cert_parameter is empty */
297 if(param_length == 0)
300 /* next less trivial: cert_parameter contains no colon nor backslash; this
301 * means no passphrase was given and no characters escaped */
302 if(!strpbrk(cert_parameter, ":\\")) {
303 *certname = strdup(cert_parameter);
306 /* deal with escaped chars; find unescaped colon if it exists */
307 certname_place = malloc(param_length + 1);
311 *certname = certname_place;
312 param_place = cert_parameter;
313 while(*param_place) {
314 span = strcspn(param_place, ":\\");
315 strncpy(certname_place, param_place, span);
317 certname_place += span;
318 /* we just ate all the non-special chars. now we're on either a special
319 * char or the end of the string. */
320 switch(*param_place) {
325 switch(*param_place) {
327 *certname_place++ = '\\';
330 *certname_place++ = '\\';
334 *certname_place++ = ':';
338 *certname_place++ = '\\';
339 *certname_place++ = *param_place;
345 /* Since we live in a world of weirdness and confusion, the win32
346 dudes can use : when using drive letters and thus c:\file:password
347 needs to work. In order not to break compatibility, we still use : as
348 separator, but we try to detect when it is used for a file name! On
352 (param_place == &cert_parameter[1]) &&
353 (cert_parameter[2] == '\\' || cert_parameter[2] == '/') &&
354 (ISALPHA(cert_parameter[0])) ) {
355 /* colon in the second column, followed by a backslash, and the
356 first character is an alphabetic letter:
358 this is a drive letter colon */
359 *certname_place++ = ':';
364 /* escaped colons and Windows drive letter colons were handled
365 * above; if we're still here, this is a separating colon */
367 if(strlen(param_place) > 0) {
368 *passphrase = strdup(param_place);
374 *certname_place = '\0';
377 ParameterError getparameter(char *flag, /* f or -long-flag */
378 char *nextarg, /* NULL if unset */
379 bool *usedarg, /* set to TRUE if the arg
381 struct GlobalConfig *global,
382 struct OperationConfig *config)
385 char subletter = '\0'; /* subletters can only occur on long options */
387 const char *parse = NULL;
391 bool longopt = FALSE;
392 bool singleopt = FALSE; /* when true means '-o foo' used '-ofoo' */
394 bool toggle = TRUE; /* how to switch boolean options, on or off. Controlled
395 by using --OPTION or --no-OPTION */
398 if(('-' != flag[0]) ||
399 (('-' == flag[0]) && ('-' == flag[1]))) {
400 /* this should be a long name */
401 char *word = ('-' == flag[0]) ? flag+2 : flag;
402 size_t fnam = strlen(word);
405 if(!strncmp(word, "no-", 3)) {
406 /* disable this option but ignore the "no-" part when looking for it */
411 for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) {
412 if(curlx_strnequal(aliases[j].lname, word, fnam)) {
415 if(curlx_raw_equal(aliases[j].lname, word)) {
416 parse = aliases[j].letter;
418 numhits = 1; /* a single unique hit */
421 parse = aliases[j].letter;
426 /* this is at least the second match! */
427 return PARAM_OPTION_AMBIGUOUS;
430 return PARAM_OPTION_UNKNOWN;
434 flag++; /* prefixed with one dash, pass it */
440 /* we can loop here if we have multiple single-letters */
443 letter = (char)*parse;
448 subletter = parse[1];
450 *usedarg = FALSE; /* default is that we don't use the arg */
453 for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) {
454 if(letter == aliases[j].letter[0]) {
460 return PARAM_OPTION_UNKNOWN;
464 if(aliases[hit].extraparam) {
465 /* this option requires an extra parameter */
466 if(!longopt && parse[1]) {
467 nextarg = (char *)&parse[1]; /* this is the actual extra parameter */
468 singleopt = TRUE; /* don't loop anymore after this */
471 return PARAM_REQUIRES_PARAMETER;
473 *usedarg = TRUE; /* mark it as used */
477 case '*': /* options without a short option */
479 case '4': /* --dns-ipv4-addr */
480 /* addr in dot notation */
481 GetStr(&config->dns_ipv4_addr, nextarg);
483 case '6': /* --dns-ipv6-addr */
484 /* addr in dot notation */
485 GetStr(&config->dns_ipv6_addr, nextarg);
487 case 'a': /* random-file */
488 GetStr(&config->random_file, nextarg);
490 case 'b': /* egd-file */
491 GetStr(&config->egd_file, nextarg);
493 case 'B': /* XOAUTH2 Bearer */
494 GetStr(&config->xoauth2_bearer, nextarg);
496 case 'c': /* connect-timeout */
497 err = str2udouble(&config->connecttimeout, nextarg);
501 case 'd': /* ciphers */
502 GetStr(&config->cipher_list, nextarg);
504 case 'D': /* --dns-interface */
506 GetStr(&config->dns_interface, nextarg);
508 case 'e': /* --disable-epsv */
509 config->disable_epsv = toggle;
511 case 'E': /* --epsv */
512 config->disable_epsv = (!toggle)?TRUE:FALSE;
514 #ifdef USE_ENVIRONMENT
516 config->writeenv = toggle;
519 case 'F': /* --dns-servers */
520 /* IP addrs of DNS servers */
521 GetStr(&config->dns_servers, nextarg);
523 case 'g': /* --trace */
524 GetStr(&global->trace_dump, nextarg);
525 if(global->tracetype && (global->tracetype != TRACE_BIN))
526 warnf(config, "--trace overrides an earlier trace/verbose option\n");
527 global->tracetype = TRACE_BIN;
529 case 'G': /* --npn */
530 config->nonpn = (!toggle)?TRUE:FALSE;
532 case 'h': /* --trace-ascii */
533 GetStr(&global->trace_dump, nextarg);
534 if(global->tracetype && (global->tracetype != TRACE_ASCII))
536 "--trace-ascii overrides an earlier trace/verbose option\n");
537 global->tracetype = TRACE_ASCII;
539 case 'H': /* --alpn */
540 config->noalpn = (!toggle)?TRUE:FALSE;
542 case 'i': /* --limit-rate */
544 /* We support G, M, K too */
546 curl_off_t value = curlx_strtoofft(nextarg, &unit, 0);
550 else if(strlen(unit) > 1)
551 unit = (char *)"w"; /* unsupported */
556 value *= 1024*1024*1024;
568 /* for plain bytes, leave as-is */
571 warnf(config, "unsupported rate unit. Use G, M, K or B!\n");
572 return PARAM_BAD_USE;
574 config->recvpersecond = value;
575 config->sendpersecond = value;
579 case 'j': /* --compressed */
580 if(toggle && !(curlinfo->features & CURL_VERSION_LIBZ))
581 return PARAM_LIBCURL_DOESNT_SUPPORT;
582 config->encoding = toggle;
585 case 'J': /* --tr-encoding */
586 config->tr_encoding = toggle;
589 case 'k': /* --digest */
591 config->authtype |= CURLAUTH_DIGEST;
593 config->authtype &= ~CURLAUTH_DIGEST;
596 case 'l': /* --negotiate */
598 if(curlinfo->features & CURL_VERSION_SPNEGO)
599 config->authtype |= CURLAUTH_NEGOTIATE;
601 return PARAM_LIBCURL_DOESNT_SUPPORT;
604 config->authtype &= ~CURLAUTH_NEGOTIATE;
607 case 'm': /* --ntlm */
609 if(curlinfo->features & CURL_VERSION_NTLM)
610 config->authtype |= CURLAUTH_NTLM;
612 return PARAM_LIBCURL_DOESNT_SUPPORT;
615 config->authtype &= ~CURLAUTH_NTLM;
618 case 'M': /* --ntlm-wb */
620 if(curlinfo->features & CURL_VERSION_NTLM_WB)
621 config->authtype |= CURLAUTH_NTLM_WB;
623 return PARAM_LIBCURL_DOESNT_SUPPORT;
626 config->authtype &= ~CURLAUTH_NTLM_WB;
629 case 'n': /* --basic for completeness */
631 config->authtype |= CURLAUTH_BASIC;
633 config->authtype &= ~CURLAUTH_BASIC;
636 case 'o': /* --anyauth, let libcurl pick it */
638 config->authtype = CURLAUTH_ANY;
639 /* --no-anyauth simply doesn't touch it */
643 case 'p': /* --wdebug */
647 case 'q': /* --ftp-create-dirs */
648 config->ftp_create_dirs = toggle;
651 case 'r': /* --create-dirs */
652 config->create_dirs = toggle;
655 case 's': /* --max-redirs */
656 /* specified max no of redirects (http(s)), this accepts -1 as a
658 err = str2num(&config->maxredirs, nextarg);
661 if(config->maxredirs < -1)
662 return PARAM_BAD_NUMERIC;
665 case 't': /* --proxy-ntlm */
666 if(curlinfo->features & CURL_VERSION_NTLM)
667 config->proxyntlm = toggle;
669 return PARAM_LIBCURL_DOESNT_SUPPORT;
672 case 'u': /* --crlf */
673 /* LF -> CRLF conversion? */
674 config->crlf = toggle;
677 case 'v': /* --stderr */
678 if(strcmp(nextarg, "-")) {
679 FILE *newfile = fopen(nextarg, "wt");
681 warnf(config, "Failed to open %s!\n", nextarg);
683 if(global->errors_fopened)
684 fclose(global->errors);
685 global->errors = newfile;
686 global->errors_fopened = TRUE;
690 global->errors = stdout;
692 case 'w': /* --interface */
694 GetStr(&config->iface, nextarg);
696 case 'x': /* --krb */
697 /* kerberos level string */
698 if(curlinfo->features & CURL_VERSION_KERBEROS4)
699 GetStr(&config->krblevel, nextarg);
701 return PARAM_LIBCURL_DOESNT_SUPPORT;
703 case 'y': /* --max-filesize */
704 err = str2offset(&config->max_filesize, nextarg);
708 case 'z': /* --disable-eprt */
709 config->disable_eprt = toggle;
711 case 'Z': /* --eprt */
712 config->disable_eprt = (!toggle)?TRUE:FALSE;
715 default: /* the URL! */
718 if(config->url_get || ((config->url_get = config->url_list) != NULL)) {
719 /* there's a node here, if it already is filled-in continue to find
721 while(config->url_get && (config->url_get->flags & GETOUT_URL))
722 config->url_get = config->url_get->next;
725 /* now there might or might not be an available node to fill in! */
729 url = config->url_get;
731 /* there was no free node, create one! */
732 url = new_getout(config);
737 /* fill in the URL */
738 GetStr(&url->url, nextarg);
739 url->flags |= GETOUT_URL;
744 case '$': /* more options without a short option */
746 case 'a': /* --ftp-ssl */
747 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
748 return PARAM_LIBCURL_DOESNT_SUPPORT;
749 config->ftp_ssl = toggle;
751 case 'b': /* --ftp-pasv */
752 Curl_safefree(config->ftpport);
754 case 'c': /* --socks5 specifies a socks5 proxy to use, and resolves
755 the name locally and passes on the resolved address */
756 GetStr(&config->socksproxy, nextarg);
757 config->socksver = CURLPROXY_SOCKS5;
759 case 't': /* --socks4 specifies a socks4 proxy to use */
760 GetStr(&config->socksproxy, nextarg);
761 config->socksver = CURLPROXY_SOCKS4;
763 case 'T': /* --socks4a specifies a socks4a proxy to use */
764 GetStr(&config->socksproxy, nextarg);
765 config->socksver = CURLPROXY_SOCKS4A;
767 case '2': /* --socks5-hostname specifies a socks5 proxy and enables name
768 resolving with the proxy */
769 GetStr(&config->socksproxy, nextarg);
770 config->socksver = CURLPROXY_SOCKS5_HOSTNAME;
772 case 'd': /* --tcp-nodelay option */
773 config->tcp_nodelay = toggle;
775 case 'e': /* --proxy-digest */
776 config->proxydigest = toggle;
778 case 'f': /* --proxy-basic */
779 config->proxybasic = toggle;
781 case 'g': /* --retry */
782 err = str2unum(&config->req_retry, nextarg);
786 case 'h': /* --retry-delay */
787 err = str2unum(&config->retry_delay, nextarg);
791 case 'i': /* --retry-max-time */
792 err = str2unum(&config->retry_maxtime, nextarg);
797 case 'k': /* --proxy-negotiate */
798 if(curlinfo->features & CURL_VERSION_SPNEGO)
799 config->proxynegotiate = toggle;
801 return PARAM_LIBCURL_DOESNT_SUPPORT;
804 case 'm': /* --ftp-account */
805 GetStr(&config->ftp_account, nextarg);
807 case 'n': /* --proxy-anyauth */
808 config->proxyanyauth = toggle;
810 case 'o': /* --trace-time */
811 global->tracetime = toggle;
813 case 'p': /* --ignore-content-length */
814 config->ignorecl = toggle;
816 case 'q': /* --ftp-skip-pasv-ip */
817 config->ftp_skip_ip = toggle;
819 case 'r': /* --ftp-method (undocumented at this point) */
820 config->ftp_filemethod = ftpfilemethod(config, nextarg);
822 case 's': /* --local-port */
823 rc = sscanf(nextarg, "%d - %d",
825 &config->localportrange);
827 return PARAM_BAD_USE;
829 config->localportrange = 1; /* default number of ports to try */
831 config->localportrange -= config->localport;
832 if(config->localportrange < 1) {
833 warnf(config, "bad range input\n");
834 return PARAM_BAD_USE;
838 case 'u': /* --ftp-alternative-to-user */
839 GetStr(&config->ftp_alternative_to_user, nextarg);
841 case 'v': /* --ftp-ssl-reqd */
842 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
843 return PARAM_LIBCURL_DOESNT_SUPPORT;
844 config->ftp_ssl_reqd = toggle;
846 case 'w': /* --no-sessionid */
847 config->disable_sessionid = (!toggle)?TRUE:FALSE;
849 case 'x': /* --ftp-ssl-control */
850 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
851 return PARAM_LIBCURL_DOESNT_SUPPORT;
852 config->ftp_ssl_control = toggle;
854 case 'y': /* --ftp-ssl-ccc */
855 config->ftp_ssl_ccc = toggle;
856 if(!config->ftp_ssl_ccc_mode)
857 config->ftp_ssl_ccc_mode = CURLFTPSSL_CCC_PASSIVE;
859 case 'j': /* --ftp-ssl-ccc-mode */
860 config->ftp_ssl_ccc = TRUE;
861 config->ftp_ssl_ccc_mode = ftpcccmethod(config, nextarg);
863 case 'z': /* --libcurl */
864 #ifdef CURL_DISABLE_LIBCURL_OPTION
866 "--libcurl option was disabled at build-time!\n");
867 return PARAM_OPTION_UNKNOWN;
869 GetStr(&global->libcurl, nextarg);
872 case '#': /* --raw */
873 config->raw = toggle;
875 case '0': /* --post301 */
876 config->post301 = toggle;
878 case '1': /* --no-keepalive */
879 config->nokeepalive = (!toggle)?TRUE:FALSE;
881 case '3': /* --keepalive-time */
882 err = str2unum(&config->alivetime, nextarg);
886 case '4': /* --post302 */
887 config->post302 = toggle;
889 case 'I': /* --post303 */
890 config->post303 = toggle;
892 case '5': /* --noproxy */
893 /* This specifies the noproxy list */
894 GetStr(&config->noproxy, nextarg);
896 #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
897 case '6': /* --socks5-gssapi-service */
898 GetStr(&config->socks5_gssapi_service, nextarg);
900 case '7': /* --socks5-gssapi-nec*/
901 config->socks5_gssapi_nec = toggle;
904 case '8': /* --proxy1.0 */
906 GetStr(&config->proxy, nextarg);
907 config->proxyver = CURLPROXY_HTTP_1_0;
909 case '9': /* --tftp-blksize */
910 err = str2unum(&config->tftp_blksize, nextarg);
914 case 'A': /* --mail-from */
915 GetStr(&config->mail_from, nextarg);
917 case 'B': /* --mail-rcpt */
918 /* append receiver to a list */
919 err = add2list(&config->mail_rcpt, nextarg);
923 case 'C': /* --ftp-pret */
924 config->ftp_pret = toggle;
926 case 'D': /* --proto */
927 config->proto_present = TRUE;
928 if(proto2num(config, &config->proto, nextarg))
929 return PARAM_BAD_USE;
931 case 'E': /* --proto-redir */
932 config->proto_redir_present = TRUE;
933 if(proto2num(config, &config->proto_redir, nextarg))
934 return PARAM_BAD_USE;
936 case 'F': /* --resolve */
937 err = add2list(&config->resolve, nextarg);
941 case 'G': /* --delegation LEVEL */
942 config->gssapi_delegation = delegation(config, nextarg);
944 case 'H': /* --mail-auth */
945 GetStr(&config->mail_auth, nextarg);
947 case 'J': /* --metalink */
950 int mlmaj, mlmin, mlpatch;
951 metalink_get_version(&mlmaj, &mlmin, &mlpatch);
952 if((mlmaj*10000)+(mlmin*100)+mlpatch < CURL_REQ_LIBMETALINK_VERS) {
954 "--metalink option cannot be used because the version of "
955 "the linked libmetalink library is too old. "
956 "Required: %d.%d.%d, found %d.%d.%d\n",
957 CURL_REQ_LIBMETALINK_MAJOR,
958 CURL_REQ_LIBMETALINK_MINOR,
959 CURL_REQ_LIBMETALINK_PATCH,
960 mlmaj, mlmin, mlpatch);
961 return PARAM_BAD_USE;
964 config->use_metalink = toggle;
966 warnf(config, "--metalink option is ignored because the binary is "
967 "built without the Metalink support.\n");
971 case 'K': /* --sasl-ir */
972 config->sasl_ir = toggle;
974 case 'L': /* --test-event */
976 config->test_event_based = toggle;
978 warnf(config, "--test-event is ignored unless a debug build!\n");
981 case 'M': /* --unix-socket */
982 GetStr(&config->unix_socket_path, nextarg);
986 case '#': /* --progress-bar */
988 global->progressmode = CURL_PROGRESS_BAR;
990 global->progressmode = CURL_PROGRESS_STATS;
992 case ':': /* --next */
993 return PARAM_NEXT_OPERATION;
994 case '~': /* --xattr */
995 config->xattr = toggle;
997 case '0': /* --http* options */
1000 /* HTTP version 1.0 */
1001 config->httpversion = CURL_HTTP_VERSION_1_0;
1004 /* HTTP version 1.1 */
1005 config->httpversion = CURL_HTTP_VERSION_1_1;
1008 /* HTTP version 2.0 */
1009 config->httpversion = CURL_HTTP_VERSION_2_0;
1013 case '1': /* --tlsv1* options */
1016 /* TLS version 1.x */
1017 config->ssl_version = CURL_SSLVERSION_TLSv1;
1020 /* TLS version 1.0 */
1021 config->ssl_version = CURL_SSLVERSION_TLSv1_0;
1024 /* TLS version 1.1 */
1025 config->ssl_version = CURL_SSLVERSION_TLSv1_1;
1028 /* TLS version 1.2 */
1029 config->ssl_version = CURL_SSLVERSION_TLSv1_2;
1035 config->ssl_version = CURL_SSLVERSION_SSLv2;
1039 config->ssl_version = CURL_SSLVERSION_SSLv3;
1043 config->ip_version = 4;
1047 config->ip_version = 6;
1050 /* This makes the FTP sessions use APPE instead of STOR */
1051 config->ftp_append = toggle;
1054 /* This specifies the User-Agent name */
1055 GetStr(&config->useragent, nextarg);
1057 case 'b': /* cookie string coming up: */
1058 if(nextarg[0] == '@') {
1061 else if(strchr(nextarg, '=')) {
1062 /* A cookie string must have a =-letter */
1063 GetStr(&config->cookie, nextarg);
1066 /* We have a cookie file to read from! */
1067 GetStr(&config->cookiefile, nextarg);
1070 /* use ASCII/text when transferring */
1071 config->use_ascii = toggle;
1074 /* get the file name to dump all cookies in */
1075 GetStr(&config->cookiejar, nextarg);
1078 /* This makes us continue an ftp transfer at given position */
1079 if(!curlx_strequal(nextarg, "-")) {
1080 err = str2offset(&config->resume_from, nextarg);
1083 config->resume_from_current = FALSE;
1086 config->resume_from_current = TRUE;
1087 config->resume_from = 0;
1089 config->use_resume=TRUE;
1092 /* postfield data */
1094 char *postdata = NULL;
1098 if(subletter == 'e') { /* --data-urlencode*/
1099 /* [name]=[content], we encode the content part only
1100 * [name]@[file name]
1102 * Case 2: we first load the file using that name and then encode
1105 const char *p = strchr(nextarg, '=');
1109 /* there was no '=' letter, check for a '@' instead */
1110 p = strchr(nextarg, '@');
1112 nlen = p - nextarg; /* length of the name part */
1113 is_file = *p++; /* pass the separator */
1116 /* neither @ nor =, so no name and it isn't a file */
1120 if('@' == is_file) {
1121 /* a '@' letter, it means that a file name or - (stdin) follows */
1123 if(curlx_strequal("-", p)) {
1128 file = fopen(p, "rb");
1131 "Couldn't read data from file \"%s\", this makes "
1132 "an empty POST.\n", nextarg);
1135 err = file2memory(&postdata, &size, file);
1137 if(file && (file != stdin))
1143 GetStr(&postdata, p);
1145 size = strlen(postdata);
1149 /* no data from the file, point to a zero byte string to make this
1150 get sent as a POST anyway */
1151 postdata = strdup("");
1153 return PARAM_NO_MEM;
1157 char *enc = curl_easy_escape(config->easy, postdata, (int)size);
1158 Curl_safefree(postdata); /* no matter if it worked or not */
1160 /* now make a string with the name from above and append the
1162 size_t outlen = nlen + strlen(enc) + 2;
1163 char *n = malloc(outlen);
1166 return PARAM_NO_MEM;
1168 if(nlen > 0) { /* only append '=' if we have a name */
1169 snprintf(n, outlen, "%.*s=%s", nlen, nextarg, enc);
1174 size = outlen-2; /* since no '=' was inserted */
1180 return PARAM_NO_MEM;
1183 else if('@' == *nextarg) {
1184 /* the data begins with a '@' letter, it means that a file name
1185 or - (stdin) follows */
1186 nextarg++; /* pass the @ */
1188 if(curlx_strequal("-", nextarg)) {
1190 if(subletter == 'b') /* forced data-binary */
1194 file = fopen(nextarg, "rb");
1196 warnf(config, "Couldn't read data from file \"%s\", this makes "
1197 "an empty POST.\n", nextarg);
1200 if(subletter == 'b')
1202 err = file2memory(&postdata, &size, file);
1204 err = file2string(&postdata, file);
1206 size = strlen(postdata);
1209 if(file && (file != stdin))
1215 /* no data from the file, point to a zero byte string to make this
1216 get sent as a POST anyway */
1217 postdata = strdup("");
1219 return PARAM_NO_MEM;
1223 GetStr(&postdata, nextarg);
1225 size = strlen(postdata);
1228 #ifdef CURL_DOES_CONVERSIONS
1229 if(subletter != 'b') {
1230 /* NOT forced binary, convert to ASCII */
1231 if(convert_to_network(postdata, strlen(postdata))) {
1232 Curl_safefree(postdata);
1233 return PARAM_NO_MEM;
1238 if(config->postfields) {
1239 /* we already have a string, we append this one with a separating
1241 char *oldpost = config->postfields;
1242 curl_off_t oldlen = config->postfieldsize;
1243 curl_off_t newlen = oldlen + curlx_uztoso(size) + 2;
1244 config->postfields = malloc((size_t)newlen);
1245 if(!config->postfields) {
1246 Curl_safefree(oldpost);
1247 Curl_safefree(postdata);
1248 return PARAM_NO_MEM;
1250 memcpy(config->postfields, oldpost, (size_t)oldlen);
1251 /* use byte value 0x26 for '&' to accommodate non-ASCII platforms */
1252 config->postfields[oldlen] = '\x26';
1253 memcpy(&config->postfields[oldlen+1], postdata, size);
1254 config->postfields[oldlen+1+size] = '\0';
1255 Curl_safefree(oldpost);
1256 Curl_safefree(postdata);
1257 config->postfieldsize += size+1;
1260 config->postfields = postdata;
1261 config->postfieldsize = curlx_uztoso(size);
1265 We can't set the request type here, as this data might be used in
1266 a simple GET if -G is used. Already or soon.
1268 if(SetHTTPrequest(HTTPREQ_SIMPLEPOST, &config->httpreq)) {
1269 Curl_safefree(postdata);
1270 return PARAM_BAD_USE;
1275 /* dump-header to given file name */
1276 GetStr(&config->headerfile, nextarg);
1280 char *ptr = strstr(nextarg, ";auto");
1282 /* Automatic referer requested, this may be combined with a
1284 config->autoreferer = TRUE;
1285 *ptr = 0; /* zero terminate here */
1288 config->autoreferer = FALSE;
1289 GetStr(&config->referer, nextarg);
1294 case 'a': /* CA info PEM file */
1295 /* CA info PEM file */
1296 GetStr(&config->cacert, nextarg);
1298 case 'b': /* cert file type */
1299 GetStr(&config->cert_type, nextarg);
1301 case 'c': /* private key file */
1302 GetStr(&config->key, nextarg);
1304 case 'd': /* private key file type */
1305 GetStr(&config->key_type, nextarg);
1307 case 'e': /* private key passphrase */
1308 GetStr(&config->key_passwd, nextarg);
1311 case 'f': /* crypto engine */
1312 GetStr(&config->engine, nextarg);
1313 if(config->engine && curlx_raw_equal(config->engine,"list"))
1314 return PARAM_ENGINES_REQUESTED;
1316 case 'g': /* CA info PEM file */
1317 /* CA cert directory */
1318 GetStr(&config->capath, nextarg);
1320 case 'h': /* --pubkey public key file */
1321 GetStr(&config->pubkey, nextarg);
1323 case 'i': /* --hostpubmd5 md5 of the host public key */
1324 GetStr(&config->hostpubmd5, nextarg);
1325 if(!config->hostpubmd5 || strlen(config->hostpubmd5) != 32)
1326 return PARAM_BAD_USE;
1328 case 'j': /* CRL info PEM file */
1330 GetStr(&config->crlfile, nextarg);
1332 case 'k': /* TLS username */
1333 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)
1334 GetStr(&config->tls_username, nextarg);
1336 return PARAM_LIBCURL_DOESNT_SUPPORT;
1338 case 'l': /* TLS password */
1339 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)
1340 GetStr(&config->tls_password, nextarg);
1342 return PARAM_LIBCURL_DOESNT_SUPPORT;
1344 case 'm': /* TLS authentication type */
1345 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP) {
1346 GetStr(&config->tls_authtype, nextarg);
1347 if(!strequal(config->tls_authtype, "SRP"))
1348 return PARAM_LIBCURL_DOESNT_SUPPORT; /* only support TLS-SRP */
1351 return PARAM_LIBCURL_DOESNT_SUPPORT;
1353 case 'n': /* no empty SSL fragments, --ssl-allow-beast */
1354 if(curlinfo->features & CURL_VERSION_SSL)
1355 config->ssl_allow_beast = toggle;
1358 case 'o': /* --login-options */
1359 GetStr(&config->login_options, nextarg);
1362 case 'p': /* Pinned public key DER file */
1363 /* Pinned public key DER file */
1364 GetStr(&config->pinnedpubkey, nextarg);
1367 case 'q': /* --cert-status */
1368 config->verifystatus = TRUE;
1371 default: /* certificate file */
1373 char *certname, *passphrase;
1374 parse_cert_parameter(nextarg, &certname, &passphrase);
1375 Curl_safefree(config->cert);
1376 config->cert = certname;
1378 Curl_safefree(config->key_passwd);
1379 config->key_passwd = passphrase;
1386 /* fail hard on errors */
1387 config->failonerror = toggle;
1390 /* "form data" simulation, this is a little advanced so lets do our best
1391 to sort this out slowly and carefully */
1392 if(formparse(config,
1396 (subletter=='s')?TRUE:FALSE)) /* 's' means literal string */
1397 return PARAM_BAD_USE;
1398 if(SetHTTPrequest(config, HTTPREQ_POST, &config->httpreq))
1399 return PARAM_BAD_USE;
1402 case 'g': /* g disables URLglobbing */
1403 config->globoff = toggle;
1406 case 'G': /* HTTP GET */
1407 config->use_httpget = TRUE;
1410 case 'h': /* h for help */
1412 return PARAM_HELP_REQUESTED;
1414 /* we now actually support --no-help too! */
1417 /* A custom header to append to a list */
1418 if(subletter == 'p') /* --proxy-header */
1419 err = add2list(&config->proxyheaders, nextarg);
1421 err = add2list(&config->headers, nextarg);
1426 config->include_headers = toggle; /* include the headers as well in the
1427 general output stream */
1430 config->cookiesession = toggle;
1434 * no_body will imply include_headers later on
1436 config->no_body = toggle;
1437 if(SetHTTPrequest(config,
1438 (config->no_body)?HTTPREQ_HEAD:HTTPREQ_GET,
1440 return PARAM_BAD_USE;
1442 case 'J': /* --remote-header-name */
1443 if(config->include_headers) {
1445 "--include and --remote-header-name cannot be combined.\n");
1446 return PARAM_BAD_USE;
1448 config->content_disposition = toggle;
1450 case 'k': /* allow insecure SSL connects */
1451 config->insecure_ok = toggle;
1453 case 'K': /* parse config file */
1454 if(parseconfig(nextarg, global))
1455 warnf(config, "error trying read config from the '%s' file\n",
1459 config->dirlistonly = toggle; /* only list the names of the FTP dir */
1462 config->followlocation = toggle; /* Follow Location: HTTP headers */
1463 switch (subletter) {
1465 /* Continue to send authentication (user+password) when following
1466 * locations, even when hostname changed */
1467 config->unrestricted_auth = toggle;
1472 /* specified max time */
1473 err = str2udouble(&config->timeout, nextarg);
1477 case 'M': /* M for manual, huge help */
1478 if(toggle) { /* --no-manual shows no manual... */
1480 return PARAM_MANUAL_REQUESTED;
1483 "built-in manual was disabled at build-time!\n");
1484 return PARAM_OPTION_UNKNOWN;
1490 case 'o': /* CA info PEM file */
1491 /* use .netrc or URL */
1492 config->netrc_opt = toggle;
1494 case 'e': /* netrc-file */
1495 GetStr(&config->netrc_file, nextarg);
1498 /* pick info from .netrc, if this is used for http, curl will
1499 automatically enfore user+password with the request */
1500 config->netrc = toggle;
1505 /* disable the output I/O buffering. note that the option is called
1506 --buffer but is mostly used in the negative form: --no-buffer */
1508 config->nobuffer = (!toggle)?TRUE:FALSE;
1510 config->nobuffer = toggle;
1512 case 'O': /* --remote-name */
1513 if(subletter == 'a') { /* --remote-name-all */
1514 config->default_node_flags = toggle?GETOUT_USEREMOTE:0;
1518 case 'o': /* --output */
1522 if(config->url_out || ((config->url_out = config->url_list) != NULL)) {
1523 /* there's a node here, if it already is filled-in continue to find
1525 while(config->url_out && (config->url_out->flags & GETOUT_OUTFILE))
1526 config->url_out = config->url_out->next;
1529 /* now there might or might not be an available node to fill in! */
1533 url = config->url_out;
1535 /* there was no free node, create one! */
1536 url = new_getout(config);
1539 return PARAM_NO_MEM;
1541 /* fill in the outfile */
1543 GetStr(&url->outfile, nextarg);
1544 url->flags &= ~GETOUT_USEREMOTE; /* switch off */
1547 url->outfile = NULL; /* leave it */
1549 url->flags |= GETOUT_USEREMOTE; /* switch on */
1551 url->flags &= ~GETOUT_USEREMOTE; /* switch off */
1553 url->flags |= GETOUT_OUTFILE;
1558 /* This makes the FTP sessions use PORT instead of PASV */
1559 /* use <eth0> or <192.168.10.10> style addresses. Anything except
1560 this will make us try to get the "default" address.
1561 NOTE: this is a changed behaviour since the released 4.1!
1563 GetStr(&config->ftpport, nextarg);
1566 /* proxy tunnel for non-http protocols */
1567 config->proxytunnel = toggle;
1570 case 'q': /* if used first, already taken care of, we do it like
1571 this so we don't cause an error! */
1574 /* QUOTE command to send to FTP server */
1575 switch(nextarg[0]) {
1577 /* prefixed with a dash makes it a POST TRANSFER one */
1579 err = add2list(&config->postquote, nextarg);
1582 /* prefixed with a plus makes it a just-before-transfer one */
1584 err = add2list(&config->prequote, nextarg);
1587 err = add2list(&config->quote, nextarg);
1594 /* Specifying a range WITHOUT A DASH will create an illegal HTTP range
1595 (and won't actually be range by definition). The man page previously
1596 claimed that to be a good way, why this code is added to work-around
1598 if(ISDIGIT(*nextarg) && !strchr(nextarg, '-')) {
1602 "A specified range MUST include at least one dash (-). "
1603 "Appending one for you!\n");
1604 off = curlx_strtoofft(nextarg, NULL, 10);
1605 snprintf(buffer, sizeof(buffer), "%" CURL_FORMAT_CURL_OFF_T "-", off);
1606 Curl_safefree(config->range);
1607 config->range = strdup(buffer);
1609 return PARAM_NO_MEM;
1612 /* byte range requested */
1614 tmp_range = nextarg;
1615 while(*tmp_range != '\0') {
1616 if(!ISDIGIT(*tmp_range) && *tmp_range != '-' && *tmp_range != ',') {
1617 warnf(config,"Invalid character is found in given range. "
1618 "A specified range MUST have only digits in "
1619 "\'start\'-\'stop\'. The server's response to this "
1620 "request is uncertain.\n");
1625 /* byte range requested */
1626 GetStr(&config->range, nextarg);
1630 /* use remote file's time */
1631 config->remote_time = toggle;
1634 /* don't show progress meter, don't show errors : */
1636 global->mute = global->noprogress = TRUE;
1638 global->mute = global->noprogress = FALSE;
1639 if(global->showerror < 0)
1640 /* if still on the default value, set showerror to the reverse of
1641 toggle. This is to allow -S and -s to be used in an independent
1642 order but still have the same effect. */
1643 global->showerror = (!toggle)?TRUE:FALSE; /* toggle off */
1647 global->showerror = toggle?1:0; /* toggle on if used with -s */
1650 /* Telnet options */
1651 err = add2list(&config->telnet_options, nextarg);
1656 /* we are uploading */
1659 if(config->url_out || ((config->url_out = config->url_list) != NULL)) {
1660 /* there's a node here, if it already is filled-in continue to find
1662 while(config->url_out && (config->url_out->flags & GETOUT_UPLOAD))
1663 config->url_out = config->url_out->next;
1666 /* now there might or might not be an available node to fill in! */
1670 url = config->url_out;
1672 /* there was no free node, create one! */
1673 url = new_getout(config);
1676 return PARAM_NO_MEM;
1678 url->flags |= GETOUT_UPLOAD; /* mark -T used */
1680 url->flags |= GETOUT_NOUPLOAD;
1682 /* "-" equals stdin, but keep the string around for now */
1683 GetStr(&url->infile, nextarg);
1690 GetStr(&config->userpwd, nextarg);
1694 /* Proxy user:password */
1695 GetStr(&config->proxyuserpwd, nextarg);
1700 /* the '%' thing here will cause the trace get sent to stderr */
1701 Curl_safefree(global->trace_dump);
1702 global->trace_dump = strdup("%");
1703 if(!global->trace_dump)
1704 return PARAM_NO_MEM;
1705 if(global->tracetype && (global->tracetype != TRACE_PLAIN))
1707 "-v, --verbose overrides an earlier trace/verbose option\n");
1708 global->tracetype = TRACE_PLAIN;
1711 /* verbose is disabled here */
1712 global->tracetype = TRACE_NONE;
1715 if(toggle) /* --no-version yields no output! */
1716 return PARAM_VERSION_INFO_REQUESTED;
1720 /* get the output string */
1721 if('@' == *nextarg) {
1722 /* the data begins with a '@' letter, it means that a file name
1723 or - (stdin) follows */
1726 nextarg++; /* pass the @ */
1727 if(curlx_strequal("-", nextarg)) {
1733 file = fopen(nextarg, "r");
1735 err = file2string(&config->writeout, file);
1736 if(file && (file != stdin))
1740 if(!config->writeout)
1741 warnf(config, "Failed to read %s", fname);
1744 GetStr(&config->writeout, nextarg);
1748 GetStr(&config->proxy, nextarg);
1749 config->proxyver = CURLPROXY_HTTP;
1752 /* set custom request */
1753 GetStr(&config->customrequest, nextarg);
1756 /* low speed time */
1757 err = str2unum(&config->low_speed_time, nextarg);
1760 if(!config->low_speed_limit)
1761 config->low_speed_limit = 1;
1764 /* low speed limit */
1765 err = str2unum(&config->low_speed_limit, nextarg);
1768 if(!config->low_speed_time)
1769 config->low_speed_time = 30;
1771 case 'z': /* time condition coming up */
1777 /* If-Modified-Since: (section 14.28 in RFC2068) */
1778 config->timecond = CURL_TIMECOND_IFMODSINCE;
1781 /* If-Unmodified-Since: (section 14.24 in RFC2068) */
1782 config->timecond = CURL_TIMECOND_IFUNMODSINCE;
1786 /* Last-Modified: (section 14.29 in RFC2068) */
1787 config->timecond = CURL_TIMECOND_LASTMOD;
1792 config->condtime=curl_getdate(nextarg, &now);
1793 if(-1 == (int)config->condtime) {
1794 /* now let's see if it is a file name to get the time from instead! */
1795 struct_stat statbuf;
1796 if(-1 == stat(nextarg, &statbuf)) {
1797 /* failed, remove time condition */
1798 config->timecond = CURL_TIMECOND_NONE;
1800 "Illegal date format for -z, --timecond (and not "
1801 "a file name). Disabling time condition. "
1802 "See curl_getdate(3) for valid date syntax.\n");
1805 /* pull the time out from the file */
1806 config->condtime = statbuf.st_mtime;
1810 default: /* unknown flag */
1811 return PARAM_OPTION_UNKNOWN;
1815 } while(!longopt && !singleopt && *++parse && !*usedarg);
1820 ParameterError parse_args(struct GlobalConfig *config, int argc,
1825 char *orig_opt = NULL;
1826 ParameterError result = PARAM_OK;
1827 struct OperationConfig *operation = config->first;
1829 for(i = 1, stillflags = TRUE; i < argc && !result; i++) {
1832 if(stillflags && ('-' == argv[i][0])) {
1835 char *flag = argv[i];
1837 if(curlx_strequal("--", argv[i]))
1838 /* This indicates the end of the flags and thus enables the
1839 following (URL) argument to start with -. */
1842 nextarg = (i < (argc - 1)) ? argv[i + 1] : NULL;
1844 result = getparameter(flag, nextarg, &passarg, config, operation);
1845 if(result == PARAM_NEXT_OPERATION) {
1846 /* Reset result as PARAM_NEXT_OPERATION is only used here and not
1847 returned from this function */
1850 if(operation->url_list && operation->url_list->url) {
1851 /* Allocate the next config */
1852 operation->next = malloc(sizeof(struct OperationConfig));
1853 if(operation->next) {
1854 /* Initialise the newly created config */
1855 config_init(operation->next);
1857 /* Copy the easy handle */
1858 operation->next->easy = config->easy;
1860 /* Set the global config pointer */
1861 operation->next->global = config;
1863 /* Update the last operation pointer */
1864 config->last = operation->next;
1866 /* Move onto the new config */
1867 operation->next->prev = operation;
1868 operation = operation->next;
1871 result = PARAM_NO_MEM;
1874 else if(!result && passarg)
1875 i++; /* we're supposed to skip this */
1881 /* Just add the URL please */
1882 result = getparameter((char *)"--url", argv[i], &used, config,
1887 if(result && result != PARAM_HELP_REQUESTED &&
1888 result != PARAM_MANUAL_REQUESTED &&
1889 result != PARAM_VERSION_INFO_REQUESTED &&
1890 result != PARAM_ENGINES_REQUESTED) {
1891 const char *reason = param2text(result);
1893 if(orig_opt && !curlx_strequal(":", orig_opt))
1894 helpf(config->errors, "option %s: %s\n", orig_opt, reason);
1896 helpf(config->errors, "%s\n", reason);