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 {"$6", "socks5-gssapi-service", TRUE},
162 {"$7", "socks5-gssapi-nec", FALSE},
163 {"$O", "proxy-service-name", TRUE},
164 {"$P", "service-name", TRUE},
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 {"$N", "path-as-is", FALSE},
181 {"0", "http1.0", FALSE},
182 {"01", "http1.1", FALSE},
183 {"02", "http2", FALSE},
184 {"1", "tlsv1", FALSE},
185 {"10", "tlsv1.0", FALSE},
186 {"11", "tlsv1.1", FALSE},
187 {"12", "tlsv1.2", FALSE},
188 {"2", "sslv2", FALSE},
189 {"3", "sslv3", FALSE},
190 {"4", "ipv4", FALSE},
191 {"6", "ipv6", FALSE},
192 {"a", "append", FALSE},
193 {"A", "user-agent", TRUE},
194 {"b", "cookie", TRUE},
195 {"B", "use-ascii", FALSE},
196 {"c", "cookie-jar", TRUE},
197 {"C", "continue-at", TRUE},
199 {"dr", "data-raw", TRUE},
200 {"da", "data-ascii", TRUE},
201 {"db", "data-binary", TRUE},
202 {"de", "data-urlencode", TRUE},
203 {"D", "dump-header", TRUE},
204 {"e", "referer", TRUE},
206 {"Ea", "cacert", TRUE},
207 {"Eb", "cert-type", TRUE},
209 {"Ed", "key-type", TRUE},
210 {"Ee", "pass", TRUE},
211 {"Ef", "engine", TRUE},
212 {"Eg", "capath ", TRUE},
213 {"Eh", "pubkey", TRUE},
214 {"Ei", "hostpubmd5", TRUE},
215 {"Ej", "crlfile", TRUE},
216 {"Ek", "tlsuser", TRUE},
217 {"El", "tlspassword", TRUE},
218 {"Em", "tlsauthtype", TRUE},
219 {"En", "ssl-allow-beast", FALSE},
220 {"Eo", "login-options", TRUE},
221 {"Ep", "pinnedpubkey", TRUE},
222 {"Eq", "cert-status", FALSE},
223 {"Er", "false-start", FALSE},
224 {"Es", "ssl-no-revoke", FALSE},
225 {"f", "fail", FALSE},
227 {"Fs", "form-string", TRUE},
228 {"g", "globoff", FALSE},
230 {"h", "help", FALSE},
231 {"H", "header", TRUE},
232 {"Hp", "proxy-header", TRUE},
233 {"i", "include", FALSE},
234 {"I", "head", FALSE},
235 {"j", "junk-session-cookies", FALSE},
236 {"J", "remote-header-name", FALSE},
237 {"k", "insecure", FALSE},
238 {"K", "config", TRUE},
239 {"l", "list-only", FALSE},
240 {"L", "location", FALSE},
241 {"Lt", "location-trusted", FALSE},
242 {"m", "max-time", TRUE},
243 {"M", "manual", FALSE},
244 {"n", "netrc", FALSE},
245 {"no", "netrc-optional", FALSE},
246 {"ne", "netrc-file", TRUE},
247 {"N", "buffer", FALSE},
248 /* 'buffer' listed as --no-buffer in the help */
249 {"o", "output", TRUE},
250 {"O", "remote-name", FALSE},
251 {"Oa", "remote-name-all", FALSE},
252 {"p", "proxytunnel", FALSE},
253 {"P", "ftpport", TRUE},
254 /* 'ftpport' old version */
255 {"P", "ftp-port", TRUE},
256 {"q", "disable", FALSE},
257 {"Q", "quote", TRUE},
258 {"r", "range", TRUE},
259 {"R", "remote-time", FALSE},
260 {"s", "silent", FALSE},
261 {"S", "show-error", FALSE},
262 {"t", "telnet-options", TRUE},
263 /* 'telnet-options' documented as telnet-option */
264 {"T", "upload-file", TRUE},
266 {"U", "proxy-user", TRUE},
267 {"v", "verbose", FALSE},
268 {"V", "version", FALSE},
269 {"w", "write-out", TRUE},
270 {"x", "proxy", TRUE},
271 {"X", "request", TRUE},
272 {"X", "http-request", TRUE},
273 /* 'http-request' OBSOLETE VERSION */
274 {"Y", "speed-limit", TRUE},
275 {"y", "speed-time", TRUE},
276 {"z", "time-cond", TRUE},
277 {"#", "progress-bar", FALSE},
278 {":", "next", FALSE},
279 {"~", "xattr", FALSE},
282 /* Split the argument of -E to 'certname' and 'passphrase' separated by colon.
283 * We allow ':' and '\' to be escaped by '\' so that we can use certificate
284 * nicknames containing ':'. See <https://sourceforge.net/p/curl/bugs/1196/>
289 void parse_cert_parameter(const char *cert_parameter,
293 size_t param_length = strlen(cert_parameter);
295 const char *param_place = NULL;
296 char *certname_place = NULL;
300 /* most trivial assumption: cert_parameter is empty */
301 if(param_length == 0)
304 /* next less trivial: cert_parameter contains no colon nor backslash; this
305 * means no passphrase was given and no characters escaped */
306 if(!strpbrk(cert_parameter, ":\\")) {
307 *certname = strdup(cert_parameter);
310 /* deal with escaped chars; find unescaped colon if it exists */
311 certname_place = malloc(param_length + 1);
315 *certname = certname_place;
316 param_place = cert_parameter;
317 while(*param_place) {
318 span = strcspn(param_place, ":\\");
319 strncpy(certname_place, param_place, span);
321 certname_place += span;
322 /* we just ate all the non-special chars. now we're on either a special
323 * char or the end of the string. */
324 switch(*param_place) {
329 switch(*param_place) {
331 *certname_place++ = '\\';
334 *certname_place++ = '\\';
338 *certname_place++ = ':';
342 *certname_place++ = '\\';
343 *certname_place++ = *param_place;
349 /* Since we live in a world of weirdness and confusion, the win32
350 dudes can use : when using drive letters and thus c:\file:password
351 needs to work. In order not to break compatibility, we still use : as
352 separator, but we try to detect when it is used for a file name! On
356 (param_place == &cert_parameter[1]) &&
357 (cert_parameter[2] == '\\' || cert_parameter[2] == '/') &&
358 (ISALPHA(cert_parameter[0])) ) {
359 /* colon in the second column, followed by a backslash, and the
360 first character is an alphabetic letter:
362 this is a drive letter colon */
363 *certname_place++ = ':';
368 /* escaped colons and Windows drive letter colons were handled
369 * above; if we're still here, this is a separating colon */
371 if(strlen(param_place) > 0) {
372 *passphrase = strdup(param_place);
378 *certname_place = '\0';
381 ParameterError getparameter(char *flag, /* f or -long-flag */
382 char *nextarg, /* NULL if unset */
383 bool *usedarg, /* set to TRUE if the arg
385 struct GlobalConfig *global,
386 struct OperationConfig *config)
389 char subletter = '\0'; /* subletters can only occur on long options */
391 const char *parse = NULL;
395 bool longopt = FALSE;
396 bool singleopt = FALSE; /* when true means '-o foo' used '-ofoo' */
398 bool toggle = TRUE; /* how to switch boolean options, on or off. Controlled
399 by using --OPTION or --no-OPTION */
402 if(('-' != flag[0]) ||
403 (('-' == flag[0]) && ('-' == flag[1]))) {
404 /* this should be a long name */
405 char *word = ('-' == flag[0]) ? flag+2 : flag;
406 size_t fnam = strlen(word);
409 if(!strncmp(word, "no-", 3)) {
410 /* disable this option but ignore the "no-" part when looking for it */
415 for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) {
416 if(curlx_strnequal(aliases[j].lname, word, fnam)) {
419 if(curlx_raw_equal(aliases[j].lname, word)) {
420 parse = aliases[j].letter;
422 numhits = 1; /* a single unique hit */
425 parse = aliases[j].letter;
430 /* this is at least the second match! */
431 return PARAM_OPTION_AMBIGUOUS;
434 return PARAM_OPTION_UNKNOWN;
438 flag++; /* prefixed with one dash, pass it */
444 /* we can loop here if we have multiple single-letters */
447 letter = (char)*parse;
452 subletter = parse[1];
454 *usedarg = FALSE; /* default is that we don't use the arg */
457 for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) {
458 if(letter == aliases[j].letter[0]) {
464 return PARAM_OPTION_UNKNOWN;
468 if(aliases[hit].extraparam) {
469 /* this option requires an extra parameter */
470 if(!longopt && parse[1]) {
471 nextarg = (char *)&parse[1]; /* this is the actual extra parameter */
472 singleopt = TRUE; /* don't loop anymore after this */
475 return PARAM_REQUIRES_PARAMETER;
477 *usedarg = TRUE; /* mark it as used */
481 case '*': /* options without a short option */
483 case '4': /* --dns-ipv4-addr */
484 /* addr in dot notation */
485 GetStr(&config->dns_ipv4_addr, nextarg);
487 case '6': /* --dns-ipv6-addr */
488 /* addr in dot notation */
489 GetStr(&config->dns_ipv6_addr, nextarg);
491 case 'a': /* random-file */
492 GetStr(&config->random_file, nextarg);
494 case 'b': /* egd-file */
495 GetStr(&config->egd_file, nextarg);
497 case 'B': /* XOAUTH2 Bearer */
498 GetStr(&config->xoauth2_bearer, nextarg);
500 case 'c': /* connect-timeout */
501 err = str2udouble(&config->connecttimeout, nextarg);
505 case 'd': /* ciphers */
506 GetStr(&config->cipher_list, nextarg);
508 case 'D': /* --dns-interface */
510 GetStr(&config->dns_interface, nextarg);
512 case 'e': /* --disable-epsv */
513 config->disable_epsv = toggle;
515 case 'E': /* --epsv */
516 config->disable_epsv = (!toggle)?TRUE:FALSE;
518 #ifdef USE_ENVIRONMENT
520 config->writeenv = toggle;
523 case 'F': /* --dns-servers */
524 /* IP addrs of DNS servers */
525 GetStr(&config->dns_servers, nextarg);
527 case 'g': /* --trace */
528 GetStr(&global->trace_dump, nextarg);
529 if(global->tracetype && (global->tracetype != TRACE_BIN))
530 warnf(global, "--trace overrides an earlier trace/verbose option\n");
531 global->tracetype = TRACE_BIN;
533 case 'G': /* --npn */
534 config->nonpn = (!toggle)?TRUE:FALSE;
536 case 'h': /* --trace-ascii */
537 GetStr(&global->trace_dump, nextarg);
538 if(global->tracetype && (global->tracetype != TRACE_ASCII))
540 "--trace-ascii overrides an earlier trace/verbose option\n");
541 global->tracetype = TRACE_ASCII;
543 case 'H': /* --alpn */
544 config->noalpn = (!toggle)?TRUE:FALSE;
546 case 'i': /* --limit-rate */
548 /* We support G, M, K too */
550 curl_off_t value = curlx_strtoofft(nextarg, &unit, 0);
554 else if(strlen(unit) > 1)
555 unit = (char *)"w"; /* unsupported */
560 value *= 1024*1024*1024;
572 /* for plain bytes, leave as-is */
575 warnf(global, "unsupported rate unit. Use G, M, K or B!\n");
576 return PARAM_BAD_USE;
578 config->recvpersecond = value;
579 config->sendpersecond = value;
583 case 'j': /* --compressed */
584 if(toggle && !(curlinfo->features & CURL_VERSION_LIBZ))
585 return PARAM_LIBCURL_DOESNT_SUPPORT;
586 config->encoding = toggle;
589 case 'J': /* --tr-encoding */
590 config->tr_encoding = toggle;
593 case 'k': /* --digest */
595 config->authtype |= CURLAUTH_DIGEST;
597 config->authtype &= ~CURLAUTH_DIGEST;
600 case 'l': /* --negotiate */
602 if(curlinfo->features & CURL_VERSION_SPNEGO)
603 config->authtype |= CURLAUTH_NEGOTIATE;
605 return PARAM_LIBCURL_DOESNT_SUPPORT;
608 config->authtype &= ~CURLAUTH_NEGOTIATE;
611 case 'm': /* --ntlm */
613 if(curlinfo->features & CURL_VERSION_NTLM)
614 config->authtype |= CURLAUTH_NTLM;
616 return PARAM_LIBCURL_DOESNT_SUPPORT;
619 config->authtype &= ~CURLAUTH_NTLM;
622 case 'M': /* --ntlm-wb */
624 if(curlinfo->features & CURL_VERSION_NTLM_WB)
625 config->authtype |= CURLAUTH_NTLM_WB;
627 return PARAM_LIBCURL_DOESNT_SUPPORT;
630 config->authtype &= ~CURLAUTH_NTLM_WB;
633 case 'n': /* --basic for completeness */
635 config->authtype |= CURLAUTH_BASIC;
637 config->authtype &= ~CURLAUTH_BASIC;
640 case 'o': /* --anyauth, let libcurl pick it */
642 config->authtype = CURLAUTH_ANY;
643 /* --no-anyauth simply doesn't touch it */
647 case 'p': /* --wdebug */
651 case 'q': /* --ftp-create-dirs */
652 config->ftp_create_dirs = toggle;
655 case 'r': /* --create-dirs */
656 config->create_dirs = toggle;
659 case 's': /* --max-redirs */
660 /* specified max no of redirects (http(s)), this accepts -1 as a
662 err = str2num(&config->maxredirs, nextarg);
665 if(config->maxredirs < -1)
666 return PARAM_BAD_NUMERIC;
669 case 't': /* --proxy-ntlm */
670 if(curlinfo->features & CURL_VERSION_NTLM)
671 config->proxyntlm = toggle;
673 return PARAM_LIBCURL_DOESNT_SUPPORT;
676 case 'u': /* --crlf */
677 /* LF -> CRLF conversion? */
678 config->crlf = toggle;
681 case 'v': /* --stderr */
682 if(strcmp(nextarg, "-")) {
683 FILE *newfile = fopen(nextarg, FOPEN_WRITETEXT);
685 warnf(global, "Failed to open %s!\n", nextarg);
687 if(global->errors_fopened)
688 fclose(global->errors);
689 global->errors = newfile;
690 global->errors_fopened = TRUE;
694 global->errors = stdout;
696 case 'w': /* --interface */
698 GetStr(&config->iface, nextarg);
700 case 'x': /* --krb */
701 /* kerberos level string */
702 if(curlinfo->features & CURL_VERSION_KERBEROS4)
703 GetStr(&config->krblevel, nextarg);
705 return PARAM_LIBCURL_DOESNT_SUPPORT;
707 case 'y': /* --max-filesize */
708 err = str2offset(&config->max_filesize, nextarg);
712 case 'z': /* --disable-eprt */
713 config->disable_eprt = toggle;
715 case 'Z': /* --eprt */
716 config->disable_eprt = (!toggle)?TRUE:FALSE;
719 default: /* the URL! */
722 if(config->url_get || ((config->url_get = config->url_list) != NULL)) {
723 /* there's a node here, if it already is filled-in continue to find
725 while(config->url_get && (config->url_get->flags & GETOUT_URL))
726 config->url_get = config->url_get->next;
729 /* now there might or might not be an available node to fill in! */
733 url = config->url_get;
735 /* there was no free node, create one! */
736 url = new_getout(config);
741 /* fill in the URL */
742 GetStr(&url->url, nextarg);
743 url->flags |= GETOUT_URL;
748 case '$': /* more options without a short option */
750 case 'a': /* --ftp-ssl */
751 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
752 return PARAM_LIBCURL_DOESNT_SUPPORT;
753 config->ftp_ssl = toggle;
755 case 'b': /* --ftp-pasv */
756 Curl_safefree(config->ftpport);
758 case 'c': /* --socks5 specifies a socks5 proxy to use, and resolves
759 the name locally and passes on the resolved address */
760 GetStr(&config->socksproxy, nextarg);
761 config->socksver = CURLPROXY_SOCKS5;
763 case 't': /* --socks4 specifies a socks4 proxy to use */
764 GetStr(&config->socksproxy, nextarg);
765 config->socksver = CURLPROXY_SOCKS4;
767 case 'T': /* --socks4a specifies a socks4a proxy to use */
768 GetStr(&config->socksproxy, nextarg);
769 config->socksver = CURLPROXY_SOCKS4A;
771 case '2': /* --socks5-hostname specifies a socks5 proxy and enables name
772 resolving with the proxy */
773 GetStr(&config->socksproxy, nextarg);
774 config->socksver = CURLPROXY_SOCKS5_HOSTNAME;
776 case 'd': /* --tcp-nodelay option */
777 config->tcp_nodelay = toggle;
779 case 'e': /* --proxy-digest */
780 config->proxydigest = toggle;
782 case 'f': /* --proxy-basic */
783 config->proxybasic = toggle;
785 case 'g': /* --retry */
786 err = str2unum(&config->req_retry, nextarg);
790 case 'h': /* --retry-delay */
791 err = str2unum(&config->retry_delay, nextarg);
795 case 'i': /* --retry-max-time */
796 err = str2unum(&config->retry_maxtime, nextarg);
801 case 'k': /* --proxy-negotiate */
802 if(curlinfo->features & CURL_VERSION_SPNEGO)
803 config->proxynegotiate = toggle;
805 return PARAM_LIBCURL_DOESNT_SUPPORT;
808 case 'm': /* --ftp-account */
809 GetStr(&config->ftp_account, nextarg);
811 case 'n': /* --proxy-anyauth */
812 config->proxyanyauth = toggle;
814 case 'o': /* --trace-time */
815 global->tracetime = toggle;
817 case 'p': /* --ignore-content-length */
818 config->ignorecl = toggle;
820 case 'q': /* --ftp-skip-pasv-ip */
821 config->ftp_skip_ip = toggle;
823 case 'r': /* --ftp-method (undocumented at this point) */
824 config->ftp_filemethod = ftpfilemethod(config, nextarg);
826 case 's': /* --local-port */
827 rc = sscanf(nextarg, "%d - %d",
829 &config->localportrange);
831 return PARAM_BAD_USE;
833 config->localportrange = 1; /* default number of ports to try */
835 config->localportrange -= config->localport;
836 if(config->localportrange < 1) {
837 warnf(global, "bad range input\n");
838 return PARAM_BAD_USE;
842 case 'u': /* --ftp-alternative-to-user */
843 GetStr(&config->ftp_alternative_to_user, nextarg);
845 case 'v': /* --ftp-ssl-reqd */
846 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
847 return PARAM_LIBCURL_DOESNT_SUPPORT;
848 config->ftp_ssl_reqd = toggle;
850 case 'w': /* --no-sessionid */
851 config->disable_sessionid = (!toggle)?TRUE:FALSE;
853 case 'x': /* --ftp-ssl-control */
854 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
855 return PARAM_LIBCURL_DOESNT_SUPPORT;
856 config->ftp_ssl_control = toggle;
858 case 'y': /* --ftp-ssl-ccc */
859 config->ftp_ssl_ccc = toggle;
860 if(!config->ftp_ssl_ccc_mode)
861 config->ftp_ssl_ccc_mode = CURLFTPSSL_CCC_PASSIVE;
863 case 'j': /* --ftp-ssl-ccc-mode */
864 config->ftp_ssl_ccc = TRUE;
865 config->ftp_ssl_ccc_mode = ftpcccmethod(config, nextarg);
867 case 'z': /* --libcurl */
868 #ifdef CURL_DISABLE_LIBCURL_OPTION
870 "--libcurl option was disabled at build-time!\n");
871 return PARAM_OPTION_UNKNOWN;
873 GetStr(&global->libcurl, nextarg);
876 case '#': /* --raw */
877 config->raw = toggle;
879 case '0': /* --post301 */
880 config->post301 = toggle;
882 case '1': /* --no-keepalive */
883 config->nokeepalive = (!toggle)?TRUE:FALSE;
885 case '3': /* --keepalive-time */
886 err = str2unum(&config->alivetime, nextarg);
890 case '4': /* --post302 */
891 config->post302 = toggle;
893 case 'I': /* --post303 */
894 config->post303 = toggle;
896 case '5': /* --noproxy */
897 /* This specifies the noproxy list */
898 GetStr(&config->noproxy, nextarg);
900 case '6': /* --socks5-gssapi-service */
901 GetStr(&config->socks5_gssapi_service, nextarg);
903 case '7': /* --socks5-gssapi-nec*/
904 config->socks5_gssapi_nec = toggle;
906 case 'O': /* --proxy-service-name */
907 GetStr(&config->proxy_service_name, nextarg);
909 case 'P': /* --service-name */
910 GetStr(&config->service_name, nextarg);
912 case '8': /* --proxy1.0 */
914 GetStr(&config->proxy, nextarg);
915 config->proxyver = CURLPROXY_HTTP_1_0;
917 case '9': /* --tftp-blksize */
918 err = str2unum(&config->tftp_blksize, nextarg);
922 case 'A': /* --mail-from */
923 GetStr(&config->mail_from, nextarg);
925 case 'B': /* --mail-rcpt */
926 /* append receiver to a list */
927 err = add2list(&config->mail_rcpt, nextarg);
931 case 'C': /* --ftp-pret */
932 config->ftp_pret = toggle;
934 case 'D': /* --proto */
935 config->proto_present = TRUE;
936 if(proto2num(config, &config->proto, nextarg))
937 return PARAM_BAD_USE;
939 case 'E': /* --proto-redir */
940 config->proto_redir_present = TRUE;
941 if(proto2num(config, &config->proto_redir, nextarg))
942 return PARAM_BAD_USE;
944 case 'F': /* --resolve */
945 err = add2list(&config->resolve, nextarg);
949 case 'G': /* --delegation LEVEL */
950 config->gssapi_delegation = delegation(config, nextarg);
952 case 'H': /* --mail-auth */
953 GetStr(&config->mail_auth, nextarg);
955 case 'J': /* --metalink */
958 int mlmaj, mlmin, mlpatch;
959 metalink_get_version(&mlmaj, &mlmin, &mlpatch);
960 if((mlmaj*10000)+(mlmin*100)+mlpatch < CURL_REQ_LIBMETALINK_VERS) {
962 "--metalink option cannot be used because the version of "
963 "the linked libmetalink library is too old. "
964 "Required: %d.%d.%d, found %d.%d.%d\n",
965 CURL_REQ_LIBMETALINK_MAJOR,
966 CURL_REQ_LIBMETALINK_MINOR,
967 CURL_REQ_LIBMETALINK_PATCH,
968 mlmaj, mlmin, mlpatch);
969 return PARAM_BAD_USE;
972 config->use_metalink = toggle;
974 warnf(global, "--metalink option is ignored because the binary is "
975 "built without the Metalink support.\n");
979 case 'K': /* --sasl-ir */
980 config->sasl_ir = toggle;
982 case 'L': /* --test-event */
984 config->test_event_based = toggle;
986 warnf(global, "--test-event is ignored unless a debug build!\n");
989 case 'M': /* --unix-socket */
990 GetStr(&config->unix_socket_path, nextarg);
992 case 'N': /* --path-as-is */
993 config->path_as_is = toggle;
997 case '#': /* --progress-bar */
999 global->progressmode = CURL_PROGRESS_BAR;
1001 global->progressmode = CURL_PROGRESS_STATS;
1003 case ':': /* --next */
1004 return PARAM_NEXT_OPERATION;
1005 case '~': /* --xattr */
1006 config->xattr = toggle;
1008 case '0': /* --http* options */
1011 /* HTTP version 1.0 */
1012 config->httpversion = CURL_HTTP_VERSION_1_0;
1015 /* HTTP version 1.1 */
1016 config->httpversion = CURL_HTTP_VERSION_1_1;
1019 /* HTTP version 2.0 */
1020 config->httpversion = CURL_HTTP_VERSION_2_0;
1024 case '1': /* --tlsv1* options */
1027 /* TLS version 1.x */
1028 config->ssl_version = CURL_SSLVERSION_TLSv1;
1031 /* TLS version 1.0 */
1032 config->ssl_version = CURL_SSLVERSION_TLSv1_0;
1035 /* TLS version 1.1 */
1036 config->ssl_version = CURL_SSLVERSION_TLSv1_1;
1039 /* TLS version 1.2 */
1040 config->ssl_version = CURL_SSLVERSION_TLSv1_2;
1046 config->ssl_version = CURL_SSLVERSION_SSLv2;
1050 config->ssl_version = CURL_SSLVERSION_SSLv3;
1054 config->ip_version = 4;
1058 config->ip_version = 6;
1061 /* This makes the FTP sessions use APPE instead of STOR */
1062 config->ftp_append = toggle;
1065 /* This specifies the User-Agent name */
1066 GetStr(&config->useragent, nextarg);
1068 case 'b': /* cookie string coming up: */
1069 if(nextarg[0] == '@') {
1072 else if(strchr(nextarg, '=')) {
1073 /* A cookie string must have a =-letter */
1074 GetStr(&config->cookie, nextarg);
1077 /* We have a cookie file to read from! */
1078 GetStr(&config->cookiefile, nextarg);
1081 /* use ASCII/text when transferring */
1082 config->use_ascii = toggle;
1085 /* get the file name to dump all cookies in */
1086 GetStr(&config->cookiejar, nextarg);
1089 /* This makes us continue an ftp transfer at given position */
1090 if(!curlx_strequal(nextarg, "-")) {
1091 err = str2offset(&config->resume_from, nextarg);
1094 config->resume_from_current = FALSE;
1097 config->resume_from_current = TRUE;
1098 config->resume_from = 0;
1100 config->use_resume=TRUE;
1103 /* postfield data */
1105 char *postdata = NULL;
1108 bool raw_mode = (subletter == 'r');
1110 if(subletter == 'e') { /* --data-urlencode*/
1111 /* [name]=[content], we encode the content part only
1112 * [name]@[file name]
1114 * Case 2: we first load the file using that name and then encode
1117 const char *p = strchr(nextarg, '=');
1121 /* there was no '=' letter, check for a '@' instead */
1122 p = strchr(nextarg, '@');
1124 nlen = p - nextarg; /* length of the name part */
1125 is_file = *p++; /* pass the separator */
1128 /* neither @ nor =, so no name and it isn't a file */
1132 if('@' == is_file) {
1133 /* a '@' letter, it means that a file name or - (stdin) follows */
1134 if(curlx_strequal("-", p)) {
1139 file = fopen(p, "rb");
1142 "Couldn't read data from file \"%s\", this makes "
1143 "an empty POST.\n", nextarg);
1146 err = file2memory(&postdata, &size, file);
1148 if(file && (file != stdin))
1154 GetStr(&postdata, p);
1156 size = strlen(postdata);
1160 /* no data from the file, point to a zero byte string to make this
1161 get sent as a POST anyway */
1162 postdata = strdup("");
1164 return PARAM_NO_MEM;
1168 char *enc = curl_easy_escape(config->easy, postdata, (int)size);
1169 Curl_safefree(postdata); /* no matter if it worked or not */
1171 /* now make a string with the name from above and append the
1173 size_t outlen = nlen + strlen(enc) + 2;
1174 char *n = malloc(outlen);
1177 return PARAM_NO_MEM;
1179 if(nlen > 0) { /* only append '=' if we have a name */
1180 snprintf(n, outlen, "%.*s=%s", nlen, nextarg, enc);
1185 size = outlen-2; /* since no '=' was inserted */
1191 return PARAM_NO_MEM;
1194 else if('@' == *nextarg && !raw_mode) {
1195 /* the data begins with a '@' letter, it means that a file name
1196 or - (stdin) follows */
1197 nextarg++; /* pass the @ */
1199 if(curlx_strequal("-", nextarg)) {
1201 if(subletter == 'b') /* forced data-binary */
1205 file = fopen(nextarg, "rb");
1207 warnf(global, "Couldn't read data from file \"%s\", this makes "
1208 "an empty POST.\n", nextarg);
1211 if(subletter == 'b')
1213 err = file2memory(&postdata, &size, file);
1215 err = file2string(&postdata, file);
1217 size = strlen(postdata);
1220 if(file && (file != stdin))
1226 /* no data from the file, point to a zero byte string to make this
1227 get sent as a POST anyway */
1228 postdata = strdup("");
1230 return PARAM_NO_MEM;
1234 GetStr(&postdata, nextarg);
1236 size = strlen(postdata);
1239 #ifdef CURL_DOES_CONVERSIONS
1240 if(subletter != 'b') {
1241 /* NOT forced binary, convert to ASCII */
1242 if(convert_to_network(postdata, strlen(postdata))) {
1243 Curl_safefree(postdata);
1244 return PARAM_NO_MEM;
1249 if(config->postfields) {
1250 /* we already have a string, we append this one with a separating
1252 char *oldpost = config->postfields;
1253 curl_off_t oldlen = config->postfieldsize;
1254 curl_off_t newlen = oldlen + curlx_uztoso(size) + 2;
1255 config->postfields = malloc((size_t)newlen);
1256 if(!config->postfields) {
1257 Curl_safefree(oldpost);
1258 Curl_safefree(postdata);
1259 return PARAM_NO_MEM;
1261 memcpy(config->postfields, oldpost, (size_t)oldlen);
1262 /* use byte value 0x26 for '&' to accommodate non-ASCII platforms */
1263 config->postfields[oldlen] = '\x26';
1264 memcpy(&config->postfields[oldlen+1], postdata, size);
1265 config->postfields[oldlen+1+size] = '\0';
1266 Curl_safefree(oldpost);
1267 Curl_safefree(postdata);
1268 config->postfieldsize += size+1;
1271 config->postfields = postdata;
1272 config->postfieldsize = curlx_uztoso(size);
1276 We can't set the request type here, as this data might be used in
1277 a simple GET if -G is used. Already or soon.
1279 if(SetHTTPrequest(HTTPREQ_SIMPLEPOST, &config->httpreq)) {
1280 Curl_safefree(postdata);
1281 return PARAM_BAD_USE;
1286 /* dump-header to given file name */
1287 GetStr(&config->headerfile, nextarg);
1291 char *ptr = strstr(nextarg, ";auto");
1293 /* Automatic referer requested, this may be combined with a
1295 config->autoreferer = TRUE;
1296 *ptr = 0; /* zero terminate here */
1299 config->autoreferer = FALSE;
1300 GetStr(&config->referer, nextarg);
1305 case 'a': /* CA info PEM file */
1306 /* CA info PEM file */
1307 GetStr(&config->cacert, nextarg);
1309 case 'b': /* cert file type */
1310 GetStr(&config->cert_type, nextarg);
1312 case 'c': /* private key file */
1313 GetStr(&config->key, nextarg);
1315 case 'd': /* private key file type */
1316 GetStr(&config->key_type, nextarg);
1318 case 'e': /* private key passphrase */
1319 GetStr(&config->key_passwd, nextarg);
1322 case 'f': /* crypto engine */
1323 GetStr(&config->engine, nextarg);
1324 if(config->engine && curlx_raw_equal(config->engine, "list"))
1325 return PARAM_ENGINES_REQUESTED;
1327 case 'g': /* CA info PEM file */
1328 /* CA cert directory */
1329 GetStr(&config->capath, nextarg);
1331 case 'h': /* --pubkey public key file */
1332 GetStr(&config->pubkey, nextarg);
1334 case 'i': /* --hostpubmd5 md5 of the host public key */
1335 GetStr(&config->hostpubmd5, nextarg);
1336 if(!config->hostpubmd5 || strlen(config->hostpubmd5) != 32)
1337 return PARAM_BAD_USE;
1339 case 'j': /* CRL info PEM file */
1341 GetStr(&config->crlfile, nextarg);
1343 case 'k': /* TLS username */
1344 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)
1345 GetStr(&config->tls_username, nextarg);
1347 return PARAM_LIBCURL_DOESNT_SUPPORT;
1349 case 'l': /* TLS password */
1350 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)
1351 GetStr(&config->tls_password, nextarg);
1353 return PARAM_LIBCURL_DOESNT_SUPPORT;
1355 case 'm': /* TLS authentication type */
1356 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP) {
1357 GetStr(&config->tls_authtype, nextarg);
1358 if(!strequal(config->tls_authtype, "SRP"))
1359 return PARAM_LIBCURL_DOESNT_SUPPORT; /* only support TLS-SRP */
1362 return PARAM_LIBCURL_DOESNT_SUPPORT;
1364 case 'n': /* no empty SSL fragments, --ssl-allow-beast */
1365 if(curlinfo->features & CURL_VERSION_SSL)
1366 config->ssl_allow_beast = toggle;
1369 case 'o': /* --login-options */
1370 GetStr(&config->login_options, nextarg);
1373 case 'p': /* Pinned public key DER file */
1374 /* Pinned public key DER file */
1375 GetStr(&config->pinnedpubkey, nextarg);
1378 case 'q': /* --cert-status */
1379 config->verifystatus = TRUE;
1382 case 'r': /* --false-start */
1383 config->falsestart = TRUE;
1386 case 's': /* --ssl-no-revoke */
1387 if(curlinfo->features & CURL_VERSION_SSL)
1388 config->ssl_no_revoke = TRUE;
1391 default: /* certificate file */
1393 char *certname, *passphrase;
1394 parse_cert_parameter(nextarg, &certname, &passphrase);
1395 Curl_safefree(config->cert);
1396 config->cert = certname;
1398 Curl_safefree(config->key_passwd);
1399 config->key_passwd = passphrase;
1406 /* fail hard on errors */
1407 config->failonerror = toggle;
1410 /* "form data" simulation, this is a little advanced so lets do our best
1411 to sort this out slowly and carefully */
1412 if(formparse(config,
1416 (subletter=='s')?TRUE:FALSE)) /* 's' means literal string */
1417 return PARAM_BAD_USE;
1418 if(SetHTTPrequest(config, HTTPREQ_POST, &config->httpreq))
1419 return PARAM_BAD_USE;
1422 case 'g': /* g disables URLglobbing */
1423 config->globoff = toggle;
1426 case 'G': /* HTTP GET */
1427 config->use_httpget = TRUE;
1430 case 'h': /* h for help */
1432 return PARAM_HELP_REQUESTED;
1434 /* we now actually support --no-help too! */
1437 /* A custom header to append to a list */
1438 if(subletter == 'p') /* --proxy-header */
1439 err = add2list(&config->proxyheaders, nextarg);
1441 err = add2list(&config->headers, nextarg);
1446 config->include_headers = toggle; /* include the headers as well in the
1447 general output stream */
1450 config->cookiesession = toggle;
1454 * no_body will imply include_headers later on
1456 config->no_body = toggle;
1457 if(SetHTTPrequest(config,
1458 (config->no_body)?HTTPREQ_HEAD:HTTPREQ_GET,
1460 return PARAM_BAD_USE;
1462 case 'J': /* --remote-header-name */
1463 if(config->include_headers) {
1465 "--include and --remote-header-name cannot be combined.\n");
1466 return PARAM_BAD_USE;
1468 config->content_disposition = toggle;
1470 case 'k': /* allow insecure SSL connects */
1471 config->insecure_ok = toggle;
1473 case 'K': /* parse config file */
1474 if(parseconfig(nextarg, global))
1475 warnf(global, "error trying read config from the '%s' file\n",
1479 config->dirlistonly = toggle; /* only list the names of the FTP dir */
1482 config->followlocation = toggle; /* Follow Location: HTTP headers */
1483 switch (subletter) {
1485 /* Continue to send authentication (user+password) when following
1486 * locations, even when hostname changed */
1487 config->unrestricted_auth = toggle;
1492 /* specified max time */
1493 err = str2udouble(&config->timeout, nextarg);
1497 case 'M': /* M for manual, huge help */
1498 if(toggle) { /* --no-manual shows no manual... */
1500 return PARAM_MANUAL_REQUESTED;
1503 "built-in manual was disabled at build-time!\n");
1504 return PARAM_OPTION_UNKNOWN;
1510 case 'o': /* CA info PEM file */
1511 /* use .netrc or URL */
1512 config->netrc_opt = toggle;
1514 case 'e': /* netrc-file */
1515 GetStr(&config->netrc_file, nextarg);
1518 /* pick info from .netrc, if this is used for http, curl will
1519 automatically enfore user+password with the request */
1520 config->netrc = toggle;
1525 /* disable the output I/O buffering. note that the option is called
1526 --buffer but is mostly used in the negative form: --no-buffer */
1528 config->nobuffer = (!toggle)?TRUE:FALSE;
1530 config->nobuffer = toggle;
1532 case 'O': /* --remote-name */
1533 if(subletter == 'a') { /* --remote-name-all */
1534 config->default_node_flags = toggle?GETOUT_USEREMOTE:0;
1538 case 'o': /* --output */
1542 if(config->url_out || ((config->url_out = config->url_list) != NULL)) {
1543 /* there's a node here, if it already is filled-in continue to find
1545 while(config->url_out && (config->url_out->flags & GETOUT_OUTFILE))
1546 config->url_out = config->url_out->next;
1549 /* now there might or might not be an available node to fill in! */
1553 url = config->url_out;
1555 /* there was no free node, create one! */
1556 url = new_getout(config);
1559 return PARAM_NO_MEM;
1561 /* fill in the outfile */
1563 GetStr(&url->outfile, nextarg);
1564 url->flags &= ~GETOUT_USEREMOTE; /* switch off */
1567 url->outfile = NULL; /* leave it */
1569 url->flags |= GETOUT_USEREMOTE; /* switch on */
1571 url->flags &= ~GETOUT_USEREMOTE; /* switch off */
1573 url->flags |= GETOUT_OUTFILE;
1578 /* This makes the FTP sessions use PORT instead of PASV */
1579 /* use <eth0> or <192.168.10.10> style addresses. Anything except
1580 this will make us try to get the "default" address.
1581 NOTE: this is a changed behaviour since the released 4.1!
1583 GetStr(&config->ftpport, nextarg);
1586 /* proxy tunnel for non-http protocols */
1587 config->proxytunnel = toggle;
1590 case 'q': /* if used first, already taken care of, we do it like
1591 this so we don't cause an error! */
1594 /* QUOTE command to send to FTP server */
1595 switch(nextarg[0]) {
1597 /* prefixed with a dash makes it a POST TRANSFER one */
1599 err = add2list(&config->postquote, nextarg);
1602 /* prefixed with a plus makes it a just-before-transfer one */
1604 err = add2list(&config->prequote, nextarg);
1607 err = add2list(&config->quote, nextarg);
1614 /* Specifying a range WITHOUT A DASH will create an illegal HTTP range
1615 (and won't actually be range by definition). The man page previously
1616 claimed that to be a good way, why this code is added to work-around
1618 if(ISDIGIT(*nextarg) && !strchr(nextarg, '-')) {
1622 "A specified range MUST include at least one dash (-). "
1623 "Appending one for you!\n");
1624 off = curlx_strtoofft(nextarg, NULL, 10);
1625 snprintf(buffer, sizeof(buffer), "%" CURL_FORMAT_CURL_OFF_T "-", off);
1626 Curl_safefree(config->range);
1627 config->range = strdup(buffer);
1629 return PARAM_NO_MEM;
1632 /* byte range requested */
1634 tmp_range = nextarg;
1635 while(*tmp_range != '\0') {
1636 if(!ISDIGIT(*tmp_range) && *tmp_range != '-' && *tmp_range != ',') {
1637 warnf(global, "Invalid character is found in given range. "
1638 "A specified range MUST have only digits in "
1639 "\'start\'-\'stop\'. The server's response to this "
1640 "request is uncertain.\n");
1645 /* byte range requested */
1646 GetStr(&config->range, nextarg);
1650 /* use remote file's time */
1651 config->remote_time = toggle;
1654 /* don't show progress meter, don't show errors : */
1656 global->mute = global->noprogress = TRUE;
1658 global->mute = global->noprogress = FALSE;
1659 if(global->showerror < 0)
1660 /* if still on the default value, set showerror to the reverse of
1661 toggle. This is to allow -S and -s to be used in an independent
1662 order but still have the same effect. */
1663 global->showerror = (!toggle)?TRUE:FALSE; /* toggle off */
1667 global->showerror = toggle?1:0; /* toggle on if used with -s */
1670 /* Telnet options */
1671 err = add2list(&config->telnet_options, nextarg);
1676 /* we are uploading */
1679 if(config->url_out || ((config->url_out = config->url_list) != NULL)) {
1680 /* there's a node here, if it already is filled-in continue to find
1682 while(config->url_out && (config->url_out->flags & GETOUT_UPLOAD))
1683 config->url_out = config->url_out->next;
1686 /* now there might or might not be an available node to fill in! */
1690 url = config->url_out;
1692 /* there was no free node, create one! */
1693 url = new_getout(config);
1696 return PARAM_NO_MEM;
1698 url->flags |= GETOUT_UPLOAD; /* mark -T used */
1700 url->flags |= GETOUT_NOUPLOAD;
1702 /* "-" equals stdin, but keep the string around for now */
1703 GetStr(&url->infile, nextarg);
1710 GetStr(&config->userpwd, nextarg);
1714 /* Proxy user:password */
1715 GetStr(&config->proxyuserpwd, nextarg);
1720 /* the '%' thing here will cause the trace get sent to stderr */
1721 Curl_safefree(global->trace_dump);
1722 global->trace_dump = strdup("%");
1723 if(!global->trace_dump)
1724 return PARAM_NO_MEM;
1725 if(global->tracetype && (global->tracetype != TRACE_PLAIN))
1727 "-v, --verbose overrides an earlier trace/verbose option\n");
1728 global->tracetype = TRACE_PLAIN;
1731 /* verbose is disabled here */
1732 global->tracetype = TRACE_NONE;
1735 if(toggle) /* --no-version yields no output! */
1736 return PARAM_VERSION_INFO_REQUESTED;
1740 /* get the output string */
1741 if('@' == *nextarg) {
1742 /* the data begins with a '@' letter, it means that a file name
1743 or - (stdin) follows */
1746 nextarg++; /* pass the @ */
1747 if(curlx_strequal("-", nextarg)) {
1753 file = fopen(nextarg, FOPEN_READTEXT);
1755 err = file2string(&config->writeout, file);
1756 if(file && (file != stdin))
1760 if(!config->writeout)
1761 warnf(global, "Failed to read %s", fname);
1764 GetStr(&config->writeout, nextarg);
1768 GetStr(&config->proxy, nextarg);
1769 config->proxyver = CURLPROXY_HTTP;
1772 /* set custom request */
1773 GetStr(&config->customrequest, nextarg);
1776 /* low speed time */
1777 err = str2unum(&config->low_speed_time, nextarg);
1780 if(!config->low_speed_limit)
1781 config->low_speed_limit = 1;
1784 /* low speed limit */
1785 err = str2unum(&config->low_speed_limit, nextarg);
1788 if(!config->low_speed_time)
1789 config->low_speed_time = 30;
1791 case 'z': /* time condition coming up */
1797 /* If-Modified-Since: (section 14.28 in RFC2068) */
1798 config->timecond = CURL_TIMECOND_IFMODSINCE;
1801 /* If-Unmodified-Since: (section 14.24 in RFC2068) */
1802 config->timecond = CURL_TIMECOND_IFUNMODSINCE;
1806 /* Last-Modified: (section 14.29 in RFC2068) */
1807 config->timecond = CURL_TIMECOND_LASTMOD;
1812 config->condtime=curl_getdate(nextarg, &now);
1813 if(-1 == (int)config->condtime) {
1814 /* now let's see if it is a file name to get the time from instead! */
1815 struct_stat statbuf;
1816 if(-1 == stat(nextarg, &statbuf)) {
1817 /* failed, remove time condition */
1818 config->timecond = CURL_TIMECOND_NONE;
1820 "Illegal date format for -z, --timecond (and not "
1821 "a file name). Disabling time condition. "
1822 "See curl_getdate(3) for valid date syntax.\n");
1825 /* pull the time out from the file */
1826 config->condtime = statbuf.st_mtime;
1830 default: /* unknown flag */
1831 return PARAM_OPTION_UNKNOWN;
1835 } while(!longopt && !singleopt && *++parse && !*usedarg);
1840 ParameterError parse_args(struct GlobalConfig *config, int argc,
1845 char *orig_opt = NULL;
1846 ParameterError result = PARAM_OK;
1847 struct OperationConfig *operation = config->first;
1849 for(i = 1, stillflags = TRUE; i < argc && !result; i++) {
1852 if(stillflags && ('-' == argv[i][0])) {
1855 char *flag = argv[i];
1857 if(curlx_strequal("--", argv[i]))
1858 /* This indicates the end of the flags and thus enables the
1859 following (URL) argument to start with -. */
1862 nextarg = (i < (argc - 1)) ? argv[i + 1] : NULL;
1864 result = getparameter(flag, nextarg, &passarg, config, operation);
1865 if(result == PARAM_NEXT_OPERATION) {
1866 /* Reset result as PARAM_NEXT_OPERATION is only used here and not
1867 returned from this function */
1870 if(operation->url_list && operation->url_list->url) {
1871 /* Allocate the next config */
1872 operation->next = malloc(sizeof(struct OperationConfig));
1873 if(operation->next) {
1874 /* Initialise the newly created config */
1875 config_init(operation->next);
1877 /* Copy the easy handle */
1878 operation->next->easy = config->easy;
1880 /* Set the global config pointer */
1881 operation->next->global = config;
1883 /* Update the last operation pointer */
1884 config->last = operation->next;
1886 /* Move onto the new config */
1887 operation->next->prev = operation;
1888 operation = operation->next;
1891 result = PARAM_NO_MEM;
1894 else if(!result && passarg)
1895 i++; /* we're supposed to skip this */
1901 /* Just add the URL please */
1902 result = getparameter((char *)"--url", argv[i], &used, config,
1907 if(result && result != PARAM_HELP_REQUESTED &&
1908 result != PARAM_MANUAL_REQUESTED &&
1909 result != PARAM_VERSION_INFO_REQUESTED &&
1910 result != PARAM_ENGINES_REQUESTED) {
1911 const char *reason = param2text(result);
1913 if(orig_opt && !curlx_strequal(":", orig_opt))
1914 helpf(config->errors, "option %s: %s\n", orig_opt, reason);
1916 helpf(config->errors, "%s\n", reason);