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 */
31 # include "tool_hugehelp.h"
34 #include "tool_binmode.h"
35 #include "tool_cfgable.h"
36 #include "tool_cb_prg.h"
37 #include "tool_formparse.h"
38 #include "tool_getparam.h"
39 #include "tool_help.h"
40 #include "tool_helpers.h"
41 #include "tool_libinfo.h"
42 #include "tool_metalink.h"
43 #include "tool_msgs.h"
44 #include "tool_paramhlp.h"
45 #include "tool_parsecfg.h"
46 #include "tool_version.h"
48 #include "memdebug.h" /* keep this as LAST include */
54 #define GetStr(str,val) do { \
60 *(str) = strdup((val)); \
62 return PARAM_NO_MEM; \
67 const char *letter; /* short name option */
68 const char *lname; /* long name option */
69 bool extraparam; /* whether it takes an additional argument */
72 static const struct LongShort aliases[]= {
73 /* all these ones, starting with "*" or "$" as a short-option have *no*
74 short option to mention. */
76 {"*4", "dns-ipv4-addr", TRUE},
77 {"*6", "dns-ipv6-addr", TRUE},
78 {"*a", "random-file", TRUE},
79 {"*b", "egd-file", TRUE},
80 {"*B", "oauth2-bearer", TRUE},
81 {"*c", "connect-timeout", TRUE},
82 {"*d", "ciphers", TRUE},
83 {"*D", "dns-interface", TRUE},
84 {"*e", "disable-epsv", FALSE},
85 {"*E", "epsv", FALSE},
86 /* 'epsv' made like this to make --no-epsv and --epsv to work
87 although --disable-epsv is the documented option */
88 #ifdef USE_ENVIRONMENT
89 {"*f", "environment", FALSE},
91 {"*F", "dns-servers", TRUE},
92 {"*g", "trace", TRUE},
94 {"*h", "trace-ascii", TRUE},
95 {"*H", "alpn", FALSE},
96 {"*i", "limit-rate", TRUE},
97 {"*j", "compressed", FALSE},
98 {"*J", "tr-encoding", FALSE},
99 {"*k", "digest", FALSE},
100 {"*l", "negotiate", FALSE},
101 {"*m", "ntlm", FALSE},
102 {"*M", "ntlm-wb", FALSE},
103 {"*n", "basic", FALSE},
104 {"*o", "anyauth", FALSE},
106 {"*p", "wdebug", FALSE},
108 {"*q", "ftp-create-dirs", FALSE},
109 {"*r", "create-dirs", FALSE},
110 {"*s", "max-redirs", TRUE},
111 {"*t", "proxy-ntlm", FALSE},
112 {"*u", "crlf", FALSE},
113 {"*v", "stderr", TRUE},
114 {"*w", "interface", TRUE},
115 {"*x", "krb" , TRUE},
116 {"*x", "krb4" , TRUE},
117 /* 'krb4' is the previous name */
118 {"*y", "max-filesize", TRUE},
119 {"*z", "disable-eprt", FALSE},
120 {"*Z", "eprt", FALSE},
121 /* 'eprt' made like this to make --no-eprt and --eprt to work
122 although --disable-eprt is the documented option */
123 {"$a", "ftp-ssl", FALSE},
124 /* 'ftp-ssl' deprecated name since 7.20.0 */
125 {"$a", "ssl", FALSE},
126 /* 'ssl' new option name in 7.20.0, previously this was ftp-ssl */
127 {"$b", "ftp-pasv", FALSE},
128 {"$c", "socks5", TRUE},
129 {"$c", "socks", TRUE},
130 /* 'socks' is how the option once was documented but we prefer
131 the --socks5 version for explicit version */
132 {"$d", "tcp-nodelay", FALSE},
133 {"$e", "proxy-digest", FALSE},
134 {"$f", "proxy-basic", FALSE},
135 {"$g", "retry", TRUE},
136 {"$h", "retry-delay", TRUE},
137 {"$i", "retry-max-time", TRUE},
138 {"$k", "proxy-negotiate", FALSE},
139 {"$m", "ftp-account", TRUE},
140 {"$n", "proxy-anyauth", FALSE},
141 {"$o", "trace-time", FALSE},
142 {"$p", "ignore-content-length", FALSE},
143 {"$q", "ftp-skip-pasv-ip", FALSE},
144 {"$r", "ftp-method", TRUE},
145 {"$s", "local-port", TRUE},
146 {"$t", "socks4", TRUE},
147 {"$T", "socks4a", TRUE},
148 {"$u", "ftp-alternative-to-user", TRUE},
149 {"$v", "ftp-ssl-reqd", FALSE},
150 /* 'ftp-ssl-reqd' deprecated name since 7.20.0 */
151 {"$v", "ssl-reqd", FALSE},
152 /* 'ssl-reqd' new in 7.20.0, previously this was ftp-ssl-reqd */
153 {"$w", "sessionid", FALSE},
154 /* ¡sessionid' listed as --no-sessionid in the help */
155 {"$x", "ftp-ssl-control", FALSE},
156 {"$y", "ftp-ssl-ccc", FALSE},
157 {"$j", "ftp-ssl-ccc-mode", TRUE},
158 {"$z", "libcurl", TRUE},
159 {"$#", "raw", FALSE},
160 {"$0", "post301", FALSE},
161 {"$1", "keepalive", FALSE},
162 /* 'keepalive' listed as --no-keepalive in the help */
163 {"$2", "socks5-hostname", TRUE},
164 {"$3", "keepalive-time", TRUE},
165 {"$4", "post302", FALSE},
166 {"$5", "noproxy", TRUE},
167 #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
168 {"$6", "socks5-gssapi-service", TRUE},
169 {"$7", "socks5-gssapi-nec", FALSE},
171 {"$8", "proxy1.0", TRUE},
172 {"$9", "tftp-blksize", TRUE},
173 {"$A", "mail-from", TRUE},
174 {"$B", "mail-rcpt", TRUE},
175 {"$C", "ftp-pret", FALSE},
176 {"$D", "proto", TRUE},
177 {"$E", "proto-redir", TRUE},
178 {"$F", "resolve", TRUE},
179 {"$G", "delegation", TRUE},
180 {"$H", "mail-auth", TRUE},
181 {"$I", "post303", FALSE},
182 {"$J", "metalink", FALSE},
183 {"$K", "sasl-ir", FALSE},
184 {"$L", "test-event", FALSE},
185 {"0", "http1.0", FALSE},
186 {"01", "http1.1", FALSE},
187 {"02", "http2", FALSE},
188 {"1", "tlsv1", FALSE},
189 {"10", "tlsv1.0", FALSE},
190 {"11", "tlsv1.1", FALSE},
191 {"12", "tlsv1.2", FALSE},
192 {"2", "sslv2", FALSE},
193 {"3", "sslv3", FALSE},
194 {"4", "ipv4", FALSE},
195 {"6", "ipv6", FALSE},
196 {"a", "append", FALSE},
197 {"A", "user-agent", TRUE},
198 {"b", "cookie", TRUE},
199 {"B", "use-ascii", FALSE},
200 {"c", "cookie-jar", TRUE},
201 {"C", "continue-at", TRUE},
203 {"da", "data-ascii", TRUE},
204 {"db", "data-binary", TRUE},
205 {"de", "data-urlencode", TRUE},
206 {"D", "dump-header", TRUE},
207 {"e", "referer", TRUE},
209 {"Ea", "cacert", TRUE},
210 {"Eb", "cert-type", TRUE},
212 {"Ed", "key-type", TRUE},
213 {"Ee", "pass", TRUE},
214 {"Ef", "engine", TRUE},
215 {"Eg", "capath ", TRUE},
216 {"Eh", "pubkey", TRUE},
217 {"Ei", "hostpubmd5", TRUE},
218 {"Ej", "crlfile", TRUE},
219 {"Ek", "tlsuser", TRUE},
220 {"El", "tlspassword", TRUE},
221 {"Em", "tlsauthtype", TRUE},
222 {"En", "ssl-allow-beast", FALSE},
223 {"Eo", "login-options", TRUE},
224 {"f", "fail", FALSE},
226 {"Fs", "form-string", TRUE},
227 {"g", "globoff", FALSE},
229 {"h", "help", FALSE},
230 {"H", "header", TRUE},
231 {"i", "include", FALSE},
232 {"I", "head", FALSE},
233 {"j", "junk-session-cookies", FALSE},
234 {"J", "remote-header-name", FALSE},
235 {"k", "insecure", FALSE},
236 {"K", "config", TRUE},
237 {"l", "list-only", FALSE},
238 {"L", "location", FALSE},
239 {"Lt", "location-trusted", FALSE},
240 {"m", "max-time", TRUE},
241 {"M", "manual", FALSE},
242 {"n", "netrc", FALSE},
243 {"no", "netrc-optional", FALSE},
244 {"ne", "netrc-file", TRUE},
245 {"N", "buffer", FALSE},
246 /* 'buffer' listed as --no-buffer in the help */
247 {"o", "output", TRUE},
248 {"O", "remote-name", FALSE},
249 {"Oa", "remote-name-all", FALSE},
250 {"p", "proxytunnel", FALSE},
251 {"P", "ftpport", TRUE},
252 /* 'ftpport' old version */
253 {"P", "ftp-port", TRUE},
254 {"q", "disable", FALSE},
255 {"Q", "quote", TRUE},
256 {"r", "range", TRUE},
257 {"R", "remote-time", FALSE},
258 {"s", "silent", FALSE},
259 {"S", "show-error", FALSE},
260 {"t", "telnet-options", TRUE},
261 /* 'telnet-options' documented as telnet-option */
262 {"T", "upload-file", TRUE},
264 {"U", "proxy-user", TRUE},
265 {"v", "verbose", FALSE},
266 {"V", "version", FALSE},
267 {"w", "write-out", TRUE},
268 {"x", "proxy", TRUE},
269 {"X", "request", TRUE},
270 {"X", "http-request", TRUE},
271 /* 'http-request' OBSOLETE VERSION */
272 {"Y", "speed-limit", TRUE},
273 {"y", "speed-time", TRUE},
274 {"z", "time-cond", TRUE},
275 {"#", "progress-bar", FALSE},
276 {"~", "xattr", FALSE},
284 static const struct feat feats[] = {
285 {"AsynchDNS", CURL_VERSION_ASYNCHDNS},
286 {"Debug", CURL_VERSION_DEBUG},
287 {"TrackMemory", CURL_VERSION_CURLDEBUG},
288 {"GSS-Negotiate", CURL_VERSION_GSSNEGOTIATE},
289 {"IDN", CURL_VERSION_IDN},
290 {"IPv6", CURL_VERSION_IPV6},
291 {"Largefile", CURL_VERSION_LARGEFILE},
292 {"NTLM", CURL_VERSION_NTLM},
293 {"NTLM_WB", CURL_VERSION_NTLM_WB},
294 {"SPNEGO", CURL_VERSION_SPNEGO},
295 {"SSL", CURL_VERSION_SSL},
296 {"SSPI", CURL_VERSION_SSPI},
297 {"krb4", CURL_VERSION_KERBEROS4},
298 {"libz", CURL_VERSION_LIBZ},
299 {"CharConv", CURL_VERSION_CONV},
300 {"TLS-SRP", CURL_VERSION_TLSAUTH_SRP},
301 {"HTTP2", CURL_VERSION_HTTP2}
304 /* Split the argument of -E to 'certname' and 'passphrase' separated by colon.
305 * We allow ':' and '\' to be escaped by '\' so that we can use certificate
306 * nicknames containing ':'. See <https://sourceforge.net/p/curl/bugs/1196/>
311 void parse_cert_parameter(const char *cert_parameter,
315 size_t param_length = strlen(cert_parameter);
317 const char *param_place = NULL;
318 char *certname_place = NULL;
322 /* most trivial assumption: cert_parameter is empty */
323 if(param_length == 0)
326 /* next less trivial: cert_parameter contains no colon nor backslash; this
327 * means no passphrase was given and no characters escaped */
328 if(!strpbrk(cert_parameter, ":\\")) {
329 *certname = strdup(cert_parameter);
332 /* deal with escaped chars; find unescaped colon if it exists */
333 certname_place = malloc(param_length + 1);
337 *certname = certname_place;
338 param_place = cert_parameter;
339 while(*param_place) {
340 span = strcspn(param_place, ":\\");
341 strncpy(certname_place, param_place, span);
343 certname_place += span;
344 /* we just ate all the non-special chars. now we're on either a special
345 * char or the end of the string. */
346 switch(*param_place) {
351 switch(*param_place) {
353 *certname_place++ = '\\';
356 *certname_place++ = '\\';
360 *certname_place++ = ':';
364 *certname_place++ = '\\';
365 *certname_place++ = *param_place;
371 /* Since we live in a world of weirdness and confusion, the win32
372 dudes can use : when using drive letters and thus c:\file:password
373 needs to work. In order not to break compatibility, we still use : as
374 separator, but we try to detect when it is used for a file name! On
378 (param_place == &cert_parameter[1]) &&
379 (cert_parameter[2] == '\\' || cert_parameter[2] == '/') &&
380 (ISALPHA(cert_parameter[0])) ) {
381 /* colon in the second column, followed by a backslash, and the
382 first character is an alphabetic letter:
384 this is a drive letter colon */
385 *certname_place++ = ':';
390 /* escaped colons and Windows drive letter colons were handled
391 * above; if we're still here, this is a separating colon */
393 if(strlen(param_place) > 0) {
394 *passphrase = strdup(param_place);
400 *certname_place = '\0';
403 ParameterError getparameter(char *flag, /* f or -long-flag */
404 char *nextarg, /* NULL if unset */
405 bool *usedarg, /* set to TRUE if the arg
407 struct Configurable *config)
410 char subletter = '\0'; /* subletters can only occur on long options */
412 const char *parse = NULL;
416 bool longopt = FALSE;
417 bool singleopt = FALSE; /* when true means '-o foo' used '-ofoo' */
419 bool toggle = TRUE; /* how to switch boolean options, on or off. Controlled
420 by using --OPTION or --no-OPTION */
423 if(('-' != flag[0]) ||
424 (('-' == flag[0]) && ('-' == flag[1]))) {
425 /* this should be a long name */
426 char *word = ('-' == flag[0]) ? flag+2 : flag;
427 size_t fnam = strlen(word);
430 if(!strncmp(word, "no-", 3)) {
431 /* disable this option but ignore the "no-" part when looking for it */
436 for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) {
437 if(curlx_strnequal(aliases[j].lname, word, fnam)) {
440 if(curlx_raw_equal(aliases[j].lname, word)) {
441 parse = aliases[j].letter;
443 numhits = 1; /* a single unique hit */
446 parse = aliases[j].letter;
451 /* this is at least the second match! */
452 return PARAM_OPTION_AMBIGUOUS;
455 return PARAM_OPTION_UNKNOWN;
459 flag++; /* prefixed with one dash, pass it */
465 /* we can loop here if we have multiple single-letters */
469 letter = (char)*parse;
478 subletter = parse[1];
480 *usedarg = FALSE; /* default is that we don't use the arg */
483 for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) {
484 if(letter == aliases[j].letter[0]) {
490 return PARAM_OPTION_UNKNOWN;
494 if(aliases[hit].extraparam) {
495 /* this option requires an extra parameter */
496 if(!longopt && parse[1]) {
497 nextarg = (char *)&parse[1]; /* this is the actual extra parameter */
498 singleopt = TRUE; /* don't loop anymore after this */
501 return PARAM_REQUIRES_PARAMETER;
503 *usedarg = TRUE; /* mark it as used */
507 case '*': /* options without a short option */
509 case '4': /* --dns-ipv4-addr */
510 /* addr in dot notation */
511 GetStr(&config->dns_ipv4_addr, nextarg);
513 case '6': /* --dns-ipv6-addr */
514 /* addr in dot notation */
515 GetStr(&config->dns_ipv6_addr, nextarg);
517 case 'a': /* random-file */
518 GetStr(&config->random_file, nextarg);
520 case 'b': /* egd-file */
521 GetStr(&config->egd_file, nextarg);
523 case 'B': /* XOAUTH2 Bearer */
524 GetStr(&config->xoauth2_bearer, nextarg);
526 case 'c': /* connect-timeout */
527 err = str2udouble(&config->connecttimeout, nextarg);
531 case 'd': /* ciphers */
532 GetStr(&config->cipher_list, nextarg);
534 case 'D': /* --dns-interface */
536 GetStr(&config->dns_interface, nextarg);
538 case 'e': /* --disable-epsv */
539 config->disable_epsv = toggle;
541 case 'E': /* --epsv */
542 config->disable_epsv = (!toggle)?TRUE:FALSE;
544 #ifdef USE_ENVIRONMENT
546 config->writeenv = toggle;
549 case 'F': /* --dns-servers */
550 /* IP addrs of DNS servers */
551 GetStr(&config->dns_servers, nextarg);
553 case 'g': /* --trace */
554 GetStr(&config->trace_dump, nextarg);
555 if(config->tracetype && (config->tracetype != TRACE_BIN))
556 warnf(config, "--trace overrides an earlier trace/verbose option\n");
557 config->tracetype = TRACE_BIN;
559 case 'G': /* --npn */
560 config->nonpn = (!toggle)?TRUE:FALSE;
562 case 'h': /* --trace-ascii */
563 GetStr(&config->trace_dump, nextarg);
564 if(config->tracetype && (config->tracetype != TRACE_ASCII))
566 "--trace-ascii overrides an earlier trace/verbose option\n");
567 config->tracetype = TRACE_ASCII;
569 case 'H': /* --alpn */
570 config->noalpn = (!toggle)?TRUE:FALSE;
572 case 'i': /* --limit-rate */
574 /* We support G, M, K too */
576 curl_off_t value = curlx_strtoofft(nextarg, &unit, 0);
580 else if(strlen(unit) > 1)
581 unit = (char *)"w"; /* unsupported */
586 value *= 1024*1024*1024;
598 /* for plain bytes, leave as-is */
601 warnf(config, "unsupported rate unit. Use G, M, K or B!\n");
602 return PARAM_BAD_USE;
604 config->recvpersecond = value;
605 config->sendpersecond = value;
609 case 'j': /* --compressed */
610 if(toggle && !(curlinfo->features & CURL_VERSION_LIBZ))
611 return PARAM_LIBCURL_DOESNT_SUPPORT;
612 config->encoding = toggle;
615 case 'J': /* --tr-encoding */
616 config->tr_encoding = toggle;
619 case 'k': /* --digest */
621 config->authtype |= CURLAUTH_DIGEST;
623 config->authtype &= ~CURLAUTH_DIGEST;
626 case 'l': /* --negotiate */
628 if(curlinfo->features & CURL_VERSION_GSSNEGOTIATE)
629 config->authtype |= CURLAUTH_GSSNEGOTIATE;
631 return PARAM_LIBCURL_DOESNT_SUPPORT;
634 config->authtype &= ~CURLAUTH_GSSNEGOTIATE;
637 case 'm': /* --ntlm */
639 if(curlinfo->features & CURL_VERSION_NTLM)
640 config->authtype |= CURLAUTH_NTLM;
642 return PARAM_LIBCURL_DOESNT_SUPPORT;
645 config->authtype &= ~CURLAUTH_NTLM;
648 case 'M': /* --ntlm-wb */
650 if(curlinfo->features & CURL_VERSION_NTLM_WB)
651 config->authtype |= CURLAUTH_NTLM_WB;
653 return PARAM_LIBCURL_DOESNT_SUPPORT;
656 config->authtype &= ~CURLAUTH_NTLM_WB;
659 case 'n': /* --basic for completeness */
661 config->authtype |= CURLAUTH_BASIC;
663 config->authtype &= ~CURLAUTH_BASIC;
666 case 'o': /* --anyauth, let libcurl pick it */
668 config->authtype = CURLAUTH_ANY;
669 /* --no-anyauth simply doesn't touch it */
673 case 'p': /* --wdebug */
677 case 'q': /* --ftp-create-dirs */
678 config->ftp_create_dirs = toggle;
681 case 'r': /* --create-dirs */
682 config->create_dirs = toggle;
685 case 's': /* --max-redirs */
686 /* specified max no of redirects (http(s)), this accepts -1 as a
688 err = str2num(&config->maxredirs, nextarg);
691 if(config->maxredirs < -1)
692 return PARAM_BAD_NUMERIC;
695 case 't': /* --proxy-ntlm */
696 if(curlinfo->features & CURL_VERSION_NTLM)
697 config->proxyntlm = toggle;
699 return PARAM_LIBCURL_DOESNT_SUPPORT;
702 case 'u': /* --crlf */
703 /* LF -> CRLF conversion? */
704 config->crlf = toggle;
707 case 'v': /* --stderr */
708 if(strcmp(nextarg, "-")) {
709 FILE *newfile = fopen(nextarg, "wt");
711 warnf(config, "Failed to open %s!\n", nextarg);
713 if(config->errors_fopened)
714 fclose(config->errors);
715 config->errors = newfile;
716 config->errors_fopened = TRUE;
720 config->errors = stdout;
722 case 'w': /* --interface */
724 GetStr(&config->iface, nextarg);
726 case 'x': /* --krb */
727 /* kerberos level string */
728 if(curlinfo->features & (CURL_VERSION_KERBEROS4 |
729 CURL_VERSION_GSSNEGOTIATE))
730 GetStr(&config->krblevel, nextarg);
732 return PARAM_LIBCURL_DOESNT_SUPPORT;
734 case 'y': /* --max-filesize */
735 err = str2offset(&config->max_filesize, nextarg);
739 case 'z': /* --disable-eprt */
740 config->disable_eprt = toggle;
742 case 'Z': /* --eprt */
743 config->disable_eprt = (!toggle)?TRUE:FALSE;
746 default: /* the URL! */
749 if(config->url_get || ((config->url_get = config->url_list) != NULL)) {
750 /* there's a node here, if it already is filled-in continue to find
752 while(config->url_get && (config->url_get->flags & GETOUT_URL))
753 config->url_get = config->url_get->next;
756 /* now there might or might not be an available node to fill in! */
760 url = config->url_get;
762 /* there was no free node, create one! */
763 url = new_getout(config);
768 /* fill in the URL */
769 GetStr(&url->url, nextarg);
770 url->flags |= GETOUT_URL;
775 case '$': /* more options without a short option */
777 case 'a': /* --ftp-ssl */
778 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
779 return PARAM_LIBCURL_DOESNT_SUPPORT;
780 config->ftp_ssl = toggle;
782 case 'b': /* --ftp-pasv */
783 Curl_safefree(config->ftpport);
785 case 'c': /* --socks5 specifies a socks5 proxy to use, and resolves
786 the name locally and passes on the resolved address */
787 GetStr(&config->socksproxy, nextarg);
788 config->socksver = CURLPROXY_SOCKS5;
790 case 't': /* --socks4 specifies a socks4 proxy to use */
791 GetStr(&config->socksproxy, nextarg);
792 config->socksver = CURLPROXY_SOCKS4;
794 case 'T': /* --socks4a specifies a socks4a proxy to use */
795 GetStr(&config->socksproxy, nextarg);
796 config->socksver = CURLPROXY_SOCKS4A;
798 case '2': /* --socks5-hostname specifies a socks5 proxy and enables name
799 resolving with the proxy */
800 GetStr(&config->socksproxy, nextarg);
801 config->socksver = CURLPROXY_SOCKS5_HOSTNAME;
803 case 'd': /* --tcp-nodelay option */
804 config->tcp_nodelay = toggle;
806 case 'e': /* --proxy-digest */
807 config->proxydigest = toggle;
809 case 'f': /* --proxy-basic */
810 config->proxybasic = toggle;
812 case 'g': /* --retry */
813 err = str2unum(&config->req_retry, nextarg);
817 case 'h': /* --retry-delay */
818 err = str2unum(&config->retry_delay, nextarg);
822 case 'i': /* --retry-max-time */
823 err = str2unum(&config->retry_maxtime, nextarg);
828 case 'k': /* --proxy-negotiate */
829 if(curlinfo->features & CURL_VERSION_GSSNEGOTIATE)
830 config->proxynegotiate = toggle;
832 return PARAM_LIBCURL_DOESNT_SUPPORT;
834 case 'm': /* --ftp-account */
835 GetStr(&config->ftp_account, nextarg);
837 case 'n': /* --proxy-anyauth */
838 config->proxyanyauth = toggle;
840 case 'o': /* --trace-time */
841 config->tracetime = toggle;
843 case 'p': /* --ignore-content-length */
844 config->ignorecl = toggle;
846 case 'q': /* --ftp-skip-pasv-ip */
847 config->ftp_skip_ip = toggle;
849 case 'r': /* --ftp-method (undocumented at this point) */
850 config->ftp_filemethod = ftpfilemethod(config, nextarg);
852 case 's': /* --local-port */
853 rc = sscanf(nextarg, "%d - %d",
855 &config->localportrange);
857 return PARAM_BAD_USE;
859 config->localportrange = 1; /* default number of ports to try */
861 config->localportrange -= config->localport;
862 if(config->localportrange < 1) {
863 warnf(config, "bad range input\n");
864 return PARAM_BAD_USE;
868 case 'u': /* --ftp-alternative-to-user */
869 GetStr(&config->ftp_alternative_to_user, nextarg);
871 case 'v': /* --ftp-ssl-reqd */
872 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
873 return PARAM_LIBCURL_DOESNT_SUPPORT;
874 config->ftp_ssl_reqd = toggle;
876 case 'w': /* --no-sessionid */
877 config->disable_sessionid = (!toggle)?TRUE:FALSE;
879 case 'x': /* --ftp-ssl-control */
880 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
881 return PARAM_LIBCURL_DOESNT_SUPPORT;
882 config->ftp_ssl_control = toggle;
884 case 'y': /* --ftp-ssl-ccc */
885 config->ftp_ssl_ccc = toggle;
886 if(!config->ftp_ssl_ccc_mode)
887 config->ftp_ssl_ccc_mode = CURLFTPSSL_CCC_PASSIVE;
889 case 'j': /* --ftp-ssl-ccc-mode */
890 config->ftp_ssl_ccc = TRUE;
891 config->ftp_ssl_ccc_mode = ftpcccmethod(config, nextarg);
893 case 'z': /* --libcurl */
894 #ifdef CURL_DISABLE_LIBCURL_OPTION
896 "--libcurl option was disabled at build-time!\n");
897 return PARAM_OPTION_UNKNOWN;
899 GetStr(&config->libcurl, nextarg);
902 case '#': /* --raw */
903 config->raw = toggle;
905 case '0': /* --post301 */
906 config->post301 = toggle;
908 case '1': /* --no-keepalive */
909 config->nokeepalive = (!toggle)?TRUE:FALSE;
911 case '3': /* --keepalive-time */
912 err = str2unum(&config->alivetime, nextarg);
916 case '4': /* --post302 */
917 config->post302 = toggle;
919 case 'I': /* --post303 */
920 config->post303 = toggle;
922 case '5': /* --noproxy */
923 /* This specifies the noproxy list */
924 GetStr(&config->noproxy, nextarg);
926 #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
927 case '6': /* --socks5-gssapi-service */
928 GetStr(&config->socks5_gssapi_service, nextarg);
930 case '7': /* --socks5-gssapi-nec*/
931 config->socks5_gssapi_nec = toggle;
934 case '8': /* --proxy1.0 */
936 GetStr(&config->proxy, nextarg);
937 config->proxyver = CURLPROXY_HTTP_1_0;
939 case '9': /* --tftp-blksize */
940 err = str2unum(&config->tftp_blksize, nextarg);
944 case 'A': /* --mail-from */
945 GetStr(&config->mail_from, nextarg);
947 case 'B': /* --mail-rcpt */
948 /* append receiver to a list */
949 err = add2list(&config->mail_rcpt, nextarg);
953 case 'C': /* --ftp-pret */
954 config->ftp_pret = toggle;
956 case 'D': /* --proto */
957 config->proto_present = TRUE;
958 if(proto2num(config, &config->proto, nextarg))
959 return PARAM_BAD_USE;
961 case 'E': /* --proto-redir */
962 config->proto_redir_present = TRUE;
963 if(proto2num(config, &config->proto_redir, nextarg))
964 return PARAM_BAD_USE;
966 case 'F': /* --resolve */
967 err = add2list(&config->resolve, nextarg);
971 case 'G': /* --delegation LEVEL */
972 config->gssapi_delegation = delegation(config, nextarg);
974 case 'H': /* --mail-auth */
975 GetStr(&config->mail_auth, nextarg);
977 case 'J': /* --metalink */
980 int mlmaj, mlmin, mlpatch;
981 metalink_get_version(&mlmaj, &mlmin, &mlpatch);
982 if((mlmaj*10000)+(mlmin*100)+mlpatch < CURL_REQ_LIBMETALINK_VERS) {
984 "--metalink option cannot be used because the version of "
985 "the linked libmetalink library is too old. "
986 "Required: %d.%d.%d, found %d.%d.%d\n",
987 CURL_REQ_LIBMETALINK_MAJOR,
988 CURL_REQ_LIBMETALINK_MINOR,
989 CURL_REQ_LIBMETALINK_PATCH,
990 mlmaj, mlmin, mlpatch);
991 return PARAM_BAD_USE;
994 config->use_metalink = toggle;
996 warnf(config, "--metalink option is ignored because the binary is "
997 "built without the Metalink support.\n");
1001 case 'K': /* --sasl-ir */
1002 config->sasl_ir = toggle;
1004 case 'L': /* --test-event */
1006 config->test_event_based = toggle;
1008 warnf(config, "--test-event is ignored unless a debug build!\n");
1013 case '#': /* --progress-bar */
1015 config->progressmode = CURL_PROGRESS_BAR;
1017 config->progressmode = CURL_PROGRESS_STATS;
1019 case '~': /* --xattr */
1020 config->xattr = toggle;
1022 case '0': /* --http* options */
1025 /* HTTP version 1.0 */
1026 config->httpversion = CURL_HTTP_VERSION_1_0;
1029 /* HTTP version 1.1 */
1030 config->httpversion = CURL_HTTP_VERSION_1_1;
1033 /* HTTP version 2.0 */
1034 config->httpversion = CURL_HTTP_VERSION_2_0;
1038 case '1': /* --tlsv1* options */
1041 /* TLS version 1.x */
1042 config->ssl_version = CURL_SSLVERSION_TLSv1;
1045 /* TLS version 1.0 */
1046 config->ssl_version = CURL_SSLVERSION_TLSv1_0;
1049 /* TLS version 1.1 */
1050 config->ssl_version = CURL_SSLVERSION_TLSv1_1;
1053 /* TLS version 1.2 */
1054 config->ssl_version = CURL_SSLVERSION_TLSv1_2;
1060 config->ssl_version = CURL_SSLVERSION_SSLv2;
1064 config->ssl_version = CURL_SSLVERSION_SSLv3;
1068 config->ip_version = 4;
1072 config->ip_version = 6;
1075 /* This makes the FTP sessions use APPE instead of STOR */
1076 config->ftp_append = toggle;
1079 /* This specifies the User-Agent name */
1080 GetStr(&config->useragent, nextarg);
1082 case 'b': /* cookie string coming up: */
1083 if(nextarg[0] == '@') {
1086 else if(strchr(nextarg, '=')) {
1087 /* A cookie string must have a =-letter */
1088 GetStr(&config->cookie, nextarg);
1091 /* We have a cookie file to read from! */
1092 GetStr(&config->cookiefile, nextarg);
1095 /* use ASCII/text when transferring */
1096 config->use_ascii = toggle;
1099 /* get the file name to dump all cookies in */
1100 GetStr(&config->cookiejar, nextarg);
1103 /* This makes us continue an ftp transfer at given position */
1104 if(!curlx_strequal(nextarg, "-")) {
1105 err = str2offset(&config->resume_from, nextarg);
1108 config->resume_from_current = FALSE;
1111 config->resume_from_current = TRUE;
1112 config->resume_from = 0;
1114 config->use_resume=TRUE;
1117 /* postfield data */
1119 char *postdata = NULL;
1123 if(subletter == 'e') { /* --data-urlencode*/
1124 /* [name]=[content], we encode the content part only
1125 * [name]@[file name]
1127 * Case 2: we first load the file using that name and then encode
1130 const char *p = strchr(nextarg, '=');
1134 /* there was no '=' letter, check for a '@' instead */
1135 p = strchr(nextarg, '@');
1137 nlen = p - nextarg; /* length of the name part */
1138 is_file = *p++; /* pass the separator */
1141 /* neither @ nor =, so no name and it isn't a file */
1145 if('@' == is_file) {
1146 /* a '@' letter, it means that a file name or - (stdin) follows */
1148 if(curlx_strequal("-", p)) {
1153 file = fopen(p, "rb");
1156 "Couldn't read data from file \"%s\", this makes "
1157 "an empty POST.\n", nextarg);
1160 err = file2memory(&postdata, &size, file);
1162 if(file && (file != stdin))
1168 GetStr(&postdata, p);
1170 size = strlen(postdata);
1174 /* no data from the file, point to a zero byte string to make this
1175 get sent as a POST anyway */
1176 postdata = strdup("");
1178 return PARAM_NO_MEM;
1182 char *enc = curl_easy_escape(config->easy, postdata, (int)size);
1183 Curl_safefree(postdata); /* no matter if it worked or not */
1185 /* now make a string with the name from above and append the
1187 size_t outlen = nlen + strlen(enc) + 2;
1188 char *n = malloc(outlen);
1191 return PARAM_NO_MEM;
1193 if(nlen > 0) { /* only append '=' if we have a name */
1194 snprintf(n, outlen, "%.*s=%s", nlen, nextarg, enc);
1199 size = outlen-2; /* since no '=' was inserted */
1205 return PARAM_NO_MEM;
1208 else if('@' == *nextarg) {
1209 /* the data begins with a '@' letter, it means that a file name
1210 or - (stdin) follows */
1211 nextarg++; /* pass the @ */
1213 if(curlx_strequal("-", nextarg)) {
1215 if(subletter == 'b') /* forced data-binary */
1219 file = fopen(nextarg, "rb");
1221 warnf(config, "Couldn't read data from file \"%s\", this makes "
1222 "an empty POST.\n", nextarg);
1225 if(subletter == 'b')
1227 err = file2memory(&postdata, &size, file);
1229 err = file2string(&postdata, file);
1231 size = strlen(postdata);
1234 if(file && (file != stdin))
1240 /* no data from the file, point to a zero byte string to make this
1241 get sent as a POST anyway */
1242 postdata = strdup("");
1244 return PARAM_NO_MEM;
1248 GetStr(&postdata, nextarg);
1250 size = strlen(postdata);
1253 #ifdef CURL_DOES_CONVERSIONS
1254 if(subletter != 'b') {
1255 /* NOT forced binary, convert to ASCII */
1256 if(convert_to_network(postdata, strlen(postdata))) {
1257 Curl_safefree(postdata);
1258 return PARAM_NO_MEM;
1263 if(config->postfields) {
1264 /* we already have a string, we append this one with a separating
1266 char *oldpost = config->postfields;
1267 curl_off_t oldlen = config->postfieldsize;
1268 curl_off_t newlen = oldlen + size + 2;
1269 config->postfields = malloc((size_t)newlen);
1270 if(!config->postfields) {
1271 Curl_safefree(oldpost);
1272 Curl_safefree(postdata);
1273 return PARAM_NO_MEM;
1275 memcpy(config->postfields, oldpost, (size_t)oldlen);
1276 /* use byte value 0x26 for '&' to accommodate non-ASCII platforms */
1277 config->postfields[oldlen] = '\x26';
1278 memcpy(&config->postfields[oldlen+1], postdata, size);
1279 config->postfields[oldlen+1+size] = '\0';
1280 Curl_safefree(oldpost);
1281 Curl_safefree(postdata);
1282 config->postfieldsize += size+1;
1285 config->postfields = postdata;
1286 config->postfieldsize = size;
1290 We can't set the request type here, as this data might be used in
1291 a simple GET if -G is used. Already or soon.
1293 if(SetHTTPrequest(HTTPREQ_SIMPLEPOST, &config->httpreq)) {
1294 Curl_safefree(postdata);
1295 return PARAM_BAD_USE;
1300 /* dump-header to given file name */
1301 GetStr(&config->headerfile, nextarg);
1305 char *ptr = strstr(nextarg, ";auto");
1307 /* Automatic referer requested, this may be combined with a
1309 config->autoreferer = TRUE;
1310 *ptr = 0; /* zero terminate here */
1313 config->autoreferer = FALSE;
1314 GetStr(&config->referer, nextarg);
1319 case 'a': /* CA info PEM file */
1320 /* CA info PEM file */
1321 GetStr(&config->cacert, nextarg);
1323 case 'b': /* cert file type */
1324 GetStr(&config->cert_type, nextarg);
1326 case 'c': /* private key file */
1327 GetStr(&config->key, nextarg);
1329 case 'd': /* private key file type */
1330 GetStr(&config->key_type, nextarg);
1332 case 'e': /* private key passphrase */
1333 GetStr(&config->key_passwd, nextarg);
1336 case 'f': /* crypto engine */
1337 GetStr(&config->engine, nextarg);
1338 if(config->engine && curlx_raw_equal(config->engine,"list"))
1339 config->list_engines = TRUE;
1341 case 'g': /* CA info PEM file */
1342 /* CA cert directory */
1343 GetStr(&config->capath, nextarg);
1345 case 'h': /* --pubkey public key file */
1346 GetStr(&config->pubkey, nextarg);
1348 case 'i': /* --hostpubmd5 md5 of the host public key */
1349 GetStr(&config->hostpubmd5, nextarg);
1350 if(!config->hostpubmd5 || strlen(config->hostpubmd5) != 32)
1351 return PARAM_BAD_USE;
1353 case 'j': /* CRL info PEM file */
1355 GetStr(&config->crlfile, nextarg);
1357 case 'k': /* TLS username */
1358 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)
1359 GetStr(&config->tls_username, nextarg);
1361 return PARAM_LIBCURL_DOESNT_SUPPORT;
1363 case 'l': /* TLS password */
1364 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)
1365 GetStr(&config->tls_password, nextarg);
1367 return PARAM_LIBCURL_DOESNT_SUPPORT;
1369 case 'm': /* TLS authentication type */
1370 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP) {
1371 GetStr(&config->tls_authtype, nextarg);
1372 if(!strequal(config->tls_authtype, "SRP"))
1373 return PARAM_LIBCURL_DOESNT_SUPPORT; /* only support TLS-SRP */
1376 return PARAM_LIBCURL_DOESNT_SUPPORT;
1378 case 'n': /* no empty SSL fragments, --ssl-allow-beast */
1379 if(curlinfo->features & CURL_VERSION_SSL)
1380 config->ssl_allow_beast = toggle;
1383 case 'o': /* --login-options */
1384 GetStr(&config->login_options, nextarg);
1387 default: /* certificate file */
1389 char *certname, *passphrase;
1390 parse_cert_parameter(nextarg, &certname, &passphrase);
1391 Curl_safefree(config->cert);
1392 config->cert = certname;
1394 Curl_safefree(config->key_passwd);
1395 config->key_passwd = passphrase;
1402 /* fail hard on errors */
1403 config->failonerror = toggle;
1406 /* "form data" simulation, this is a little advanced so lets do our best
1407 to sort this out slowly and carefully */
1408 if(formparse(config,
1412 (subletter=='s')?TRUE:FALSE)) /* 's' means literal string */
1413 return PARAM_BAD_USE;
1414 if(SetHTTPrequest(config, HTTPREQ_POST, &config->httpreq))
1415 return PARAM_BAD_USE;
1418 case 'g': /* g disables URLglobbing */
1419 config->globoff = toggle;
1422 case 'G': /* HTTP GET */
1423 config->use_httpget = TRUE;
1426 case 'h': /* h for help */
1429 return PARAM_HELP_REQUESTED;
1431 /* we now actually support --no-help too! */
1434 /* A custom header to append to a list */
1435 err = add2list(&config->headers, nextarg);
1440 config->include_headers = toggle; /* include the headers as well in the
1441 general output stream */
1444 config->cookiesession = toggle;
1448 * no_body will imply include_headers later on
1450 config->no_body = toggle;
1451 if(SetHTTPrequest(config,
1452 (config->no_body)?HTTPREQ_HEAD:HTTPREQ_GET,
1454 return PARAM_BAD_USE;
1456 case 'J': /* --remote-header-name */
1457 if(config->include_headers) {
1459 "--include and --remote-header-name cannot be combined.\n");
1460 return PARAM_BAD_USE;
1462 config->content_disposition = toggle;
1464 case 'k': /* allow insecure SSL connects */
1465 config->insecure_ok = toggle;
1467 case 'K': /* parse config file */
1468 if(parseconfig(nextarg, config))
1469 warnf(config, "error trying read config from the '%s' file\n",
1473 config->dirlistonly = toggle; /* only list the names of the FTP dir */
1476 config->followlocation = toggle; /* Follow Location: HTTP headers */
1477 switch (subletter) {
1479 /* Continue to send authentication (user+password) when following
1480 * locations, even when hostname changed */
1481 config->unrestricted_auth = toggle;
1486 /* specified max time */
1487 err = str2udouble(&config->timeout, nextarg);
1491 case 'M': /* M for manual, huge help */
1492 if(toggle) { /* --no-manual shows no manual... */
1495 return PARAM_HELP_REQUESTED;
1498 "built-in manual was disabled at build-time!\n");
1499 return PARAM_OPTION_UNKNOWN;
1505 case 'o': /* CA info PEM file */
1506 /* use .netrc or URL */
1507 config->netrc_opt = toggle;
1509 case 'e': /* netrc-file */
1510 GetStr(&config->netrc_file, nextarg);
1513 /* pick info from .netrc, if this is used for http, curl will
1514 automatically enfore user+password with the request */
1515 config->netrc = toggle;
1520 /* disable the output I/O buffering. note that the option is called
1521 --buffer but is mostly used in the negative form: --no-buffer */
1523 config->nobuffer = (!toggle)?TRUE:FALSE;
1525 config->nobuffer = toggle;
1527 case 'O': /* --remote-name */
1528 if(subletter == 'a') { /* --remote-name-all */
1529 config->default_node_flags = toggle?GETOUT_USEREMOTE:0;
1533 case 'o': /* --output */
1537 if(config->url_out || ((config->url_out = config->url_list) != NULL)) {
1538 /* there's a node here, if it already is filled-in continue to find
1540 while(config->url_out && (config->url_out->flags & GETOUT_OUTFILE))
1541 config->url_out = config->url_out->next;
1544 /* now there might or might not be an available node to fill in! */
1548 url = config->url_out;
1550 /* there was no free node, create one! */
1551 url = new_getout(config);
1554 return PARAM_NO_MEM;
1556 /* fill in the outfile */
1558 GetStr(&url->outfile, nextarg);
1559 url->flags &= ~GETOUT_USEREMOTE; /* switch off */
1562 url->outfile = NULL; /* leave it */
1564 url->flags |= GETOUT_USEREMOTE; /* switch on */
1566 url->flags &= ~GETOUT_USEREMOTE; /* switch off */
1568 url->flags |= GETOUT_OUTFILE;
1573 /* This makes the FTP sessions use PORT instead of PASV */
1574 /* use <eth0> or <192.168.10.10> style addresses. Anything except
1575 this will make us try to get the "default" address.
1576 NOTE: this is a changed behaviour since the released 4.1!
1578 GetStr(&config->ftpport, nextarg);
1581 /* proxy tunnel for non-http protocols */
1582 config->proxytunnel = toggle;
1585 case 'q': /* if used first, already taken care of, we do it like
1586 this so we don't cause an error! */
1589 /* QUOTE command to send to FTP server */
1590 switch(nextarg[0]) {
1592 /* prefixed with a dash makes it a POST TRANSFER one */
1594 err = add2list(&config->postquote, nextarg);
1597 /* prefixed with a plus makes it a just-before-transfer one */
1599 err = add2list(&config->prequote, nextarg);
1602 err = add2list(&config->quote, nextarg);
1609 /* Specifying a range WITHOUT A DASH will create an illegal HTTP range
1610 (and won't actually be range by definition). The man page previously
1611 claimed that to be a good way, why this code is added to work-around
1613 if(ISDIGIT(*nextarg) && !strchr(nextarg, '-')) {
1617 "A specified range MUST include at least one dash (-). "
1618 "Appending one for you!\n");
1619 off = curlx_strtoofft(nextarg, NULL, 10);
1620 snprintf(buffer, sizeof(buffer), "%" CURL_FORMAT_CURL_OFF_T "-", off);
1621 Curl_safefree(config->range);
1622 config->range = strdup(buffer);
1624 return PARAM_NO_MEM;
1627 /* byte range requested */
1629 tmp_range = nextarg;
1630 while(*tmp_range != '\0') {
1631 if(!ISDIGIT(*tmp_range) && *tmp_range != '-' && *tmp_range != ',') {
1632 warnf(config,"Invalid character is found in given range. "
1633 "A specified range MUST have only digits in "
1634 "\'start\'-\'stop\'. The server's response to this "
1635 "request is uncertain.\n");
1640 /* byte range requested */
1641 GetStr(&config->range, nextarg);
1645 /* use remote file's time */
1646 config->remote_time = toggle;
1649 /* don't show progress meter, don't show errors : */
1651 config->mute = config->noprogress = TRUE;
1653 config->mute = config->noprogress = FALSE;
1654 if(config->showerror < 0)
1655 /* if still on the default value, set showerror to the reverse of
1656 toggle. This is to allow -S and -s to be used in an independent
1657 order but still have the same effect. */
1658 config->showerror = (!toggle)?TRUE:FALSE; /* toggle off */
1662 config->showerror = toggle?1:0; /* toggle on if used with -s */
1665 /* Telnet options */
1666 err = add2list(&config->telnet_options, nextarg);
1671 /* we are uploading */
1674 if(config->url_out || ((config->url_out = config->url_list) != NULL)) {
1675 /* there's a node here, if it already is filled-in continue to find
1677 while(config->url_out && (config->url_out->flags & GETOUT_UPLOAD))
1678 config->url_out = config->url_out->next;
1681 /* now there might or might not be an available node to fill in! */
1685 url = config->url_out;
1687 /* there was no free node, create one! */
1688 url = new_getout(config);
1691 return PARAM_NO_MEM;
1693 url->flags |= GETOUT_UPLOAD; /* mark -T used */
1695 url->flags |= GETOUT_NOUPLOAD;
1697 /* "-" equals stdin, but keep the string around for now */
1698 GetStr(&url->infile, nextarg);
1705 GetStr(&config->userpwd, nextarg);
1709 /* Proxy user:password */
1710 GetStr(&config->proxyuserpwd, nextarg);
1715 /* the '%' thing here will cause the trace get sent to stderr */
1716 Curl_safefree(config->trace_dump);
1717 config->trace_dump = strdup("%");
1718 if(!config->trace_dump)
1719 return PARAM_NO_MEM;
1720 if(config->tracetype && (config->tracetype != TRACE_PLAIN))
1722 "-v, --verbose overrides an earlier trace/verbose option\n");
1723 config->tracetype = TRACE_PLAIN;
1726 /* verbose is disabled here */
1727 config->tracetype = TRACE_NONE;
1731 const char *const *proto;
1734 /* --no-version yields no output! */
1737 printf(CURL_ID "%s\n", curl_version());
1738 if(curlinfo->protocols) {
1739 printf("Protocols: ");
1740 for(proto = curlinfo->protocols; *proto; ++proto) {
1741 printf("%s ", *proto);
1743 puts(""); /* newline */
1745 if(curlinfo->features) {
1747 printf("Features: ");
1748 for(i = 0; i < sizeof(feats)/sizeof(feats[0]); i++) {
1749 if(curlinfo->features & feats[i].bitmask)
1750 printf("%s ", feats[i].name);
1753 printf("Metalink ");
1755 puts(""); /* newline */
1758 return PARAM_HELP_REQUESTED;
1760 /* get the output string */
1761 if('@' == *nextarg) {
1762 /* the data begins with a '@' letter, it means that a file name
1763 or - (stdin) follows */
1766 nextarg++; /* pass the @ */
1767 if(curlx_strequal("-", nextarg)) {
1773 file = fopen(nextarg, "r");
1775 err = file2string(&config->writeout, file);
1776 if(file && (file != stdin))
1780 if(!config->writeout)
1781 warnf(config, "Failed to read %s", fname);
1784 GetStr(&config->writeout, nextarg);
1788 GetStr(&config->proxy, nextarg);
1789 config->proxyver = CURLPROXY_HTTP;
1792 /* set custom request */
1793 GetStr(&config->customrequest, nextarg);
1796 /* low speed time */
1797 err = str2unum(&config->low_speed_time, nextarg);
1800 if(!config->low_speed_limit)
1801 config->low_speed_limit = 1;
1804 /* low speed limit */
1805 err = str2unum(&config->low_speed_limit, nextarg);
1808 if(!config->low_speed_time)
1809 config->low_speed_time = 30;
1811 case 'z': /* time condition coming up */
1816 /* If-Modified-Since: (section 14.28 in RFC2068) */
1817 config->timecond = CURL_TIMECOND_IFMODSINCE;
1820 /* If-Unmodified-Since: (section 14.24 in RFC2068) */
1821 config->timecond = CURL_TIMECOND_IFUNMODSINCE;
1825 /* Last-Modified: (section 14.29 in RFC2068) */
1826 config->timecond = CURL_TIMECOND_LASTMOD;
1831 config->condtime=curl_getdate(nextarg, &now);
1832 if(-1 == (int)config->condtime) {
1833 /* now let's see if it is a file name to get the time from instead! */
1834 struct_stat statbuf;
1835 if(-1 == stat(nextarg, &statbuf)) {
1836 /* failed, remove time condition */
1837 config->timecond = CURL_TIMECOND_NONE;
1839 "Illegal date format for -z, --timecond (and not "
1840 "a file name). Disabling time condition. "
1841 "See curl_getdate(3) for valid date syntax.\n");
1844 /* pull the time out from the file */
1845 config->condtime = statbuf.st_mtime;
1849 default: /* unknown flag */
1850 return PARAM_OPTION_UNKNOWN;
1854 } while(!longopt && !singleopt && *++parse && !*usedarg);
1859 ParameterError parse_args(struct Configurable *config, int argc,
1865 ParameterError result = PARAM_OK;
1867 for(i = 1, stillflags = TRUE; i < argc && !result; i++) {
1870 if(curlx_strequal(":", argv[i]) &&
1871 ((config->url_list && config->url_list->url) || config->list_engines)) {
1873 /* Allocate the next config */
1874 config->next = malloc(sizeof(struct Configurable));
1876 /* Initialise the newly created config */
1877 config_init(config->next);
1879 /* Copy the easy handle */
1880 config->next->easy = config->easy;
1882 /* Move onto the new config */
1883 config->next->prev = config;
1884 config = config->next;
1886 /* Reset the flag indicator */
1890 result = PARAM_NO_MEM;
1892 else if(stillflags && ('-' == argv[i][0])) {
1895 char *flag = argv[i];
1897 if(curlx_strequal("--", argv[i]))
1898 /* This indicates the end of the flags and thus enables the
1899 following (URL) argument to start with -. */
1902 nextarg = (i < (argc - 1)) ? argv[i + 1] : NULL;
1904 result = getparameter(flag, nextarg, &passarg, config);
1905 if(!result && passarg)
1906 i++; /* we're supposed to skip this */
1912 /* Just add the URL please */
1913 result = getparameter((char *)"--url", argv[i], &used, config);
1917 if(result && result != PARAM_HELP_REQUESTED) {
1918 const char *reason = param2text(result);
1920 if(!curlx_strequal(":", orig_opt))
1921 helpf(config->errors, "option %s: %s\n", orig_opt, reason);
1923 helpf(config->errors, "%s\n", reason);