1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2012, 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 {"*a", "random-file", TRUE},
77 {"*b", "egd-file", TRUE},
78 {"*c", "connect-timeout", TRUE},
79 {"*d", "ciphers", TRUE},
80 {"*e", "disable-epsv", FALSE},
81 {"*E", "epsv", FALSE},
82 /* 'epsv' made like this to make --no-epsv and --epsv to work
83 although --disable-epsv is the documented option */
84 #ifdef USE_ENVIRONMENT
85 {"*f", "environment", FALSE},
87 {"*g", "trace", TRUE},
88 {"*h", "trace-ascii", TRUE},
89 {"*i", "limit-rate", TRUE},
90 {"*j", "compressed", FALSE},
91 {"*J", "tr-encoding", FALSE},
92 {"*k", "digest", FALSE},
93 {"*l", "negotiate", FALSE},
94 {"*m", "ntlm", FALSE},
95 {"*M", "ntlm-wb", FALSE},
96 {"*n", "basic", FALSE},
97 {"*o", "anyauth", FALSE},
99 {"*p", "wdebug", FALSE},
101 {"*q", "ftp-create-dirs", FALSE},
102 {"*r", "create-dirs", FALSE},
103 {"*s", "max-redirs", TRUE},
104 {"*t", "proxy-ntlm", FALSE},
105 {"*u", "crlf", FALSE},
106 {"*v", "stderr", TRUE},
107 {"*w", "interface", TRUE},
108 {"*x", "krb" , TRUE},
109 {"*x", "krb4" , TRUE},
110 /* 'krb4' is the previous name */
111 {"*y", "max-filesize", TRUE},
112 {"*z", "disable-eprt", FALSE},
113 {"*Z", "eprt", FALSE},
114 /* 'eprt' made like this to make --no-eprt and --eprt to work
115 although --disable-eprt is the documented option */
116 {"$a", "ftp-ssl", FALSE},
117 /* 'ftp-ssl' deprecated name since 7.20.0 */
118 {"$a", "ssl", FALSE},
119 /* 'ssl' new option name in 7.20.0, previously this was ftp-ssl */
120 {"$b", "ftp-pasv", FALSE},
121 {"$c", "socks5", TRUE},
122 {"$c", "socks", TRUE},
123 /* 'socks' is how the option once was documented but we prefer
124 the --socks5 version for explicit version */
125 {"$d", "tcp-nodelay", FALSE},
126 {"$e", "proxy-digest", FALSE},
127 {"$f", "proxy-basic", FALSE},
128 {"$g", "retry", TRUE},
129 {"$h", "retry-delay", TRUE},
130 {"$i", "retry-max-time", TRUE},
131 {"$k", "proxy-negotiate", FALSE},
132 {"$m", "ftp-account", TRUE},
133 {"$n", "proxy-anyauth", FALSE},
134 {"$o", "trace-time", FALSE},
135 {"$p", "ignore-content-length", FALSE},
136 {"$q", "ftp-skip-pasv-ip", FALSE},
137 {"$r", "ftp-method", TRUE},
138 {"$s", "local-port", TRUE},
139 {"$t", "socks4", TRUE},
140 {"$T", "socks4a", TRUE},
141 {"$u", "ftp-alternative-to-user", TRUE},
142 {"$v", "ftp-ssl-reqd", FALSE},
143 /* 'ftp-ssl-reqd' deprecated name since 7.20.0 */
144 {"$v", "ssl-reqd", FALSE},
145 /* 'ssl-reqd' new in 7.20.0, previously this was ftp-ssl-reqd */
146 {"$w", "sessionid", FALSE},
147 /* ¡sessionid' listed as --no-sessionid in the help */
148 {"$x", "ftp-ssl-control", FALSE},
149 {"$y", "ftp-ssl-ccc", FALSE},
150 {"$j", "ftp-ssl-ccc-mode", TRUE},
151 {"$z", "libcurl", TRUE},
152 {"$#", "raw", FALSE},
153 {"$0", "post301", FALSE},
154 {"$1", "keepalive", FALSE},
155 /* 'keepalive' listed as --no-keepalive in the help */
156 {"$2", "socks5-hostname", TRUE},
157 {"$3", "keepalive-time", TRUE},
158 {"$4", "post302", FALSE},
159 {"$5", "noproxy", TRUE},
160 #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
161 {"$6", "socks5-gssapi-service", TRUE},
162 {"$7", "socks5-gssapi-nec", FALSE},
164 {"$8", "proxy1.0", TRUE},
165 {"$9", "tftp-blksize", TRUE},
166 {"$A", "mail-from", TRUE},
167 {"$B", "mail-rcpt", TRUE},
168 {"$C", "ftp-pret", FALSE},
169 {"$D", "proto", TRUE},
170 {"$E", "proto-redir", TRUE},
171 {"$F", "resolve", TRUE},
172 {"$G", "delegation", TRUE},
173 {"$H", "mail-auth", TRUE},
174 {"$I", "post303", FALSE},
175 {"$J", "metalink", FALSE},
176 {"$K", "sasl-ir", FALSE},
177 {"0", "http1.0", FALSE},
178 {"1", "tlsv1", FALSE},
179 {"2", "sslv2", FALSE},
180 {"3", "sslv3", FALSE},
181 {"4", "ipv4", FALSE},
182 {"6", "ipv6", FALSE},
183 {"a", "append", FALSE},
184 {"A", "user-agent", TRUE},
185 {"b", "cookie", TRUE},
186 {"B", "use-ascii", FALSE},
187 {"c", "cookie-jar", TRUE},
188 {"C", "continue-at", TRUE},
190 {"da", "data-ascii", TRUE},
191 {"db", "data-binary", TRUE},
192 {"de", "data-urlencode", TRUE},
193 {"D", "dump-header", TRUE},
194 {"e", "referer", TRUE},
196 {"Ea", "cacert", TRUE},
197 {"Eb", "cert-type", TRUE},
199 {"Ed", "key-type", TRUE},
200 {"Ee", "pass", TRUE},
201 {"Ef", "engine", TRUE},
202 {"Eg", "capath ", TRUE},
203 {"Eh", "pubkey", TRUE},
204 {"Ei", "hostpubmd5", TRUE},
205 {"Ej", "crlfile", TRUE},
206 {"Ek", "tlsuser", TRUE},
207 {"El", "tlspassword", TRUE},
208 {"Em", "tlsauthtype", TRUE},
209 {"En", "ssl-allow-beast", FALSE},
210 {"f", "fail", FALSE},
212 {"Fs", "form-string", TRUE},
213 {"g", "globoff", FALSE},
215 {"h", "help", FALSE},
216 {"H", "header", TRUE},
217 {"i", "include", FALSE},
218 {"I", "head", FALSE},
219 {"j", "junk-session-cookies", FALSE},
220 {"J", "remote-header-name", FALSE},
221 {"k", "insecure", FALSE},
222 {"K", "config", TRUE},
223 {"l", "list-only", FALSE},
224 {"L", "location", FALSE},
225 {"Lt", "location-trusted", FALSE},
226 {"m", "max-time", TRUE},
227 {"M", "manual", FALSE},
228 {"n", "netrc", FALSE},
229 {"no", "netrc-optional", FALSE},
230 {"ne", "netrc-file", TRUE},
231 {"N", "buffer", FALSE},
232 /* 'buffer' listed as --no-buffer in the help */
233 {"o", "output", TRUE},
234 {"O", "remote-name", FALSE},
235 {"Oa", "remote-name-all", FALSE},
236 {"p", "proxytunnel", FALSE},
237 {"P", "ftpport", TRUE},
238 /* 'ftpport' old version */
239 {"P", "ftp-port", TRUE},
240 {"q", "disable", FALSE},
241 {"Q", "quote", TRUE},
242 {"r", "range", TRUE},
243 {"R", "remote-time", FALSE},
244 {"s", "silent", FALSE},
245 {"S", "show-error", FALSE},
246 {"t", "telnet-options", TRUE},
247 /* 'telnet-options' documented as telnet-option */
248 {"T", "upload-file", TRUE},
250 {"U", "proxy-user", TRUE},
251 {"v", "verbose", FALSE},
252 {"V", "version", FALSE},
253 {"w", "write-out", TRUE},
254 {"x", "proxy", TRUE},
255 {"X", "request", TRUE},
256 {"X", "http-request", TRUE},
257 /* 'http-request' OBSOLETE VERSION */
258 {"Y", "speed-limit", TRUE},
259 {"y", "speed-time", TRUE},
260 {"z", "time-cond", TRUE},
261 {"#", "progress-bar", FALSE},
262 {"~", "xattr", FALSE},
270 static const struct feat feats[] = {
271 {"AsynchDNS", CURL_VERSION_ASYNCHDNS},
272 {"Debug", CURL_VERSION_DEBUG},
273 {"TrackMemory", CURL_VERSION_CURLDEBUG},
274 {"GSS-Negotiate", CURL_VERSION_GSSNEGOTIATE},
275 {"IDN", CURL_VERSION_IDN},
276 {"IPv6", CURL_VERSION_IPV6},
277 {"Largefile", CURL_VERSION_LARGEFILE},
278 {"NTLM", CURL_VERSION_NTLM},
279 {"NTLM_WB", CURL_VERSION_NTLM_WB},
280 {"SPNEGO", CURL_VERSION_SPNEGO},
281 {"SSL", CURL_VERSION_SSL},
282 {"SSPI", CURL_VERSION_SSPI},
283 {"krb4", CURL_VERSION_KERBEROS4},
284 {"libz", CURL_VERSION_LIBZ},
285 {"CharConv", CURL_VERSION_CONV},
286 {"TLS-SRP", CURL_VERSION_TLSAUTH_SRP}
289 ParameterError getparameter(char *flag, /* f or -long-flag */
290 char *nextarg, /* NULL if unset */
291 bool *usedarg, /* set to TRUE if the arg
293 struct Configurable *config)
296 char subletter = '\0'; /* subletters can only occur on long options */
298 const char *parse = NULL;
302 bool longopt = FALSE;
303 bool singleopt = FALSE; /* when true means '-o foo' used '-ofoo' */
305 bool toggle = TRUE; /* how to switch boolean options, on or off. Controlled
306 by using --OPTION or --no-OPTION */
309 if(('-' != flag[0]) ||
310 (('-' == flag[0]) && ('-' == flag[1]))) {
311 /* this should be a long name */
312 char *word = ('-' == flag[0]) ? flag+2 : flag;
313 size_t fnam = strlen(word);
316 if(!strncmp(word, "no-", 3)) {
317 /* disable this option but ignore the "no-" part when looking for it */
322 for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) {
323 if(curlx_strnequal(aliases[j].lname, word, fnam)) {
326 if(curlx_raw_equal(aliases[j].lname, word)) {
327 parse = aliases[j].letter;
329 numhits = 1; /* a single unique hit */
332 parse = aliases[j].letter;
337 /* this is at least the second match! */
338 return PARAM_OPTION_AMBIGUOUS;
341 return PARAM_OPTION_UNKNOWN;
345 flag++; /* prefixed with one dash, pass it */
351 /* we can loop here if we have multiple single-letters */
355 letter = (char)*parse;
364 subletter = parse[1];
366 *usedarg = FALSE; /* default is that we don't use the arg */
369 for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) {
370 if(letter == aliases[j].letter[0]) {
376 return PARAM_OPTION_UNKNOWN;
380 if(aliases[hit].extraparam) {
381 /* this option requires an extra parameter */
382 if(!longopt && parse[1]) {
383 nextarg = (char *)&parse[1]; /* this is the actual extra parameter */
384 singleopt = TRUE; /* don't loop anymore after this */
387 return PARAM_REQUIRES_PARAMETER;
389 *usedarg = TRUE; /* mark it as used */
393 case '*': /* options without a short option */
395 case 'a': /* random-file */
396 GetStr(&config->random_file, nextarg);
398 case 'b': /* egd-file */
399 GetStr(&config->egd_file, nextarg);
401 case 'c': /* connect-timeout */
402 err = str2unum(&config->connecttimeout, nextarg);
406 case 'd': /* ciphers */
407 GetStr(&config->cipher_list, nextarg);
409 case 'e': /* --disable-epsv */
410 config->disable_epsv = toggle;
412 case 'E': /* --epsv */
413 config->disable_epsv = (!toggle)?TRUE:FALSE;
415 #ifdef USE_ENVIRONMENT
417 config->writeenv = toggle;
420 case 'g': /* --trace */
421 GetStr(&config->trace_dump, nextarg);
422 if(config->tracetype && (config->tracetype != TRACE_BIN))
423 warnf(config, "--trace overrides an earlier trace/verbose option\n");
424 config->tracetype = TRACE_BIN;
426 case 'h': /* --trace-ascii */
427 GetStr(&config->trace_dump, nextarg);
428 if(config->tracetype && (config->tracetype != TRACE_ASCII))
430 "--trace-ascii overrides an earlier trace/verbose option\n");
431 config->tracetype = TRACE_ASCII;
433 case 'i': /* --limit-rate */
435 /* We support G, M, K too */
437 curl_off_t value = curlx_strtoofft(nextarg, &unit, 0);
441 else if(strlen(unit) > 1)
442 unit = (char *)"w"; /* unsupported */
447 value *= 1024*1024*1024;
459 /* for plain bytes, leave as-is */
462 warnf(config, "unsupported rate unit. Use G, M, K or B!\n");
463 return PARAM_BAD_USE;
465 config->recvpersecond = value;
466 config->sendpersecond = value;
470 case 'j': /* --compressed */
471 if(toggle && !(curlinfo->features & CURL_VERSION_LIBZ))
472 return PARAM_LIBCURL_DOESNT_SUPPORT;
473 config->encoding = toggle;
476 case 'J': /* --tr-encoding */
477 config->tr_encoding = toggle;
480 case 'k': /* --digest */
482 config->authtype |= CURLAUTH_DIGEST;
484 config->authtype &= ~CURLAUTH_DIGEST;
487 case 'l': /* --negotiate */
489 if(curlinfo->features & CURL_VERSION_GSSNEGOTIATE)
490 config->authtype |= CURLAUTH_GSSNEGOTIATE;
492 return PARAM_LIBCURL_DOESNT_SUPPORT;
495 config->authtype &= ~CURLAUTH_GSSNEGOTIATE;
498 case 'm': /* --ntlm */
500 if(curlinfo->features & CURL_VERSION_NTLM)
501 config->authtype |= CURLAUTH_NTLM;
503 return PARAM_LIBCURL_DOESNT_SUPPORT;
506 config->authtype &= ~CURLAUTH_NTLM;
509 case 'M': /* --ntlm-wb */
511 if(curlinfo->features & CURL_VERSION_NTLM_WB)
512 config->authtype |= CURLAUTH_NTLM_WB;
514 return PARAM_LIBCURL_DOESNT_SUPPORT;
517 config->authtype &= ~CURLAUTH_NTLM_WB;
520 case 'n': /* --basic for completeness */
522 config->authtype |= CURLAUTH_BASIC;
524 config->authtype &= ~CURLAUTH_BASIC;
527 case 'o': /* --anyauth, let libcurl pick it */
529 config->authtype = CURLAUTH_ANY;
530 /* --no-anyauth simply doesn't touch it */
534 case 'p': /* --wdebug */
538 case 'q': /* --ftp-create-dirs */
539 config->ftp_create_dirs = toggle;
542 case 'r': /* --create-dirs */
543 config->create_dirs = TRUE;
546 case 's': /* --max-redirs */
547 /* specified max no of redirects (http(s)), this accepts -1 as a
549 err = str2num(&config->maxredirs, nextarg);
552 if(config->maxredirs < -1)
553 return PARAM_BAD_NUMERIC;
556 case 't': /* --proxy-ntlm */
557 if(curlinfo->features & CURL_VERSION_NTLM)
558 config->proxyntlm = toggle;
560 return PARAM_LIBCURL_DOESNT_SUPPORT;
563 case 'u': /* --crlf */
564 /* LF -> CRLF conversion? */
568 case 'v': /* --stderr */
569 if(strcmp(nextarg, "-")) {
570 FILE *newfile = fopen(nextarg, "wt");
572 warnf(config, "Failed to open %s!\n", nextarg);
574 if(config->errors_fopened)
575 fclose(config->errors);
576 config->errors = newfile;
577 config->errors_fopened = TRUE;
581 config->errors = stdout;
583 case 'w': /* --interface */
585 GetStr(&config->iface, nextarg);
587 case 'x': /* --krb */
588 /* kerberos level string */
589 if(curlinfo->features & (CURL_VERSION_KERBEROS4 |
590 CURL_VERSION_GSSNEGOTIATE))
591 GetStr(&config->krblevel, nextarg);
593 return PARAM_LIBCURL_DOESNT_SUPPORT;
595 case 'y': /* --max-filesize */
596 err = str2offset(&config->max_filesize, nextarg);
600 case 'z': /* --disable-eprt */
601 config->disable_eprt = toggle;
603 case 'Z': /* --eprt */
604 config->disable_eprt = (!toggle)?TRUE:FALSE;
607 default: /* the URL! */
610 if(config->url_get || ((config->url_get = config->url_list) != NULL)) {
611 /* there's a node here, if it already is filled-in continue to find
613 while(config->url_get && (config->url_get->flags & GETOUT_URL))
614 config->url_get = config->url_get->next;
617 /* now there might or might not be an available node to fill in! */
621 url = config->url_get;
623 /* there was no free node, create one! */
624 url = new_getout(config);
629 /* fill in the URL */
630 GetStr(&url->url, nextarg);
631 url->flags |= GETOUT_URL;
636 case '$': /* more options without a short option */
638 case 'a': /* --ftp-ssl */
639 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
640 return PARAM_LIBCURL_DOESNT_SUPPORT;
641 config->ftp_ssl = toggle;
643 case 'b': /* --ftp-pasv */
644 Curl_safefree(config->ftpport);
646 case 'c': /* --socks5 specifies a socks5 proxy to use, and resolves
647 the name locally and passes on the resolved address */
648 GetStr(&config->socksproxy, nextarg);
649 config->socksver = CURLPROXY_SOCKS5;
651 case 't': /* --socks4 specifies a socks4 proxy to use */
652 GetStr(&config->socksproxy, nextarg);
653 config->socksver = CURLPROXY_SOCKS4;
655 case 'T': /* --socks4a specifies a socks4a proxy to use */
656 GetStr(&config->socksproxy, nextarg);
657 config->socksver = CURLPROXY_SOCKS4A;
659 case '2': /* --socks5-hostname specifies a socks5 proxy and enables name
660 resolving with the proxy */
661 GetStr(&config->socksproxy, nextarg);
662 config->socksver = CURLPROXY_SOCKS5_HOSTNAME;
664 case 'd': /* --tcp-nodelay option */
665 config->tcp_nodelay = toggle;
667 case 'e': /* --proxy-digest */
668 config->proxydigest = toggle;
670 case 'f': /* --proxy-basic */
671 config->proxybasic = toggle;
673 case 'g': /* --retry */
674 err = str2unum(&config->req_retry, nextarg);
678 case 'h': /* --retry-delay */
679 err = str2unum(&config->retry_delay, nextarg);
683 case 'i': /* --retry-max-time */
684 err = str2unum(&config->retry_maxtime, nextarg);
689 case 'k': /* --proxy-negotiate */
690 if(curlinfo->features & CURL_VERSION_GSSNEGOTIATE)
691 config->proxynegotiate = toggle;
693 return PARAM_LIBCURL_DOESNT_SUPPORT;
695 case 'm': /* --ftp-account */
696 GetStr(&config->ftp_account, nextarg);
698 case 'n': /* --proxy-anyauth */
699 config->proxyanyauth = toggle;
701 case 'o': /* --trace-time */
702 config->tracetime = toggle;
704 case 'p': /* --ignore-content-length */
705 config->ignorecl = toggle;
707 case 'q': /* --ftp-skip-pasv-ip */
708 config->ftp_skip_ip = toggle;
710 case 'r': /* --ftp-method (undocumented at this point) */
711 config->ftp_filemethod = ftpfilemethod(config, nextarg);
713 case 's': /* --local-port */
714 rc = sscanf(nextarg, "%d - %d",
716 &config->localportrange);
718 return PARAM_BAD_USE;
720 config->localportrange = 1; /* default number of ports to try */
722 config->localportrange -= config->localport;
723 if(config->localportrange < 1) {
724 warnf(config, "bad range input\n");
725 return PARAM_BAD_USE;
729 case 'u': /* --ftp-alternative-to-user */
730 GetStr(&config->ftp_alternative_to_user, nextarg);
732 case 'v': /* --ftp-ssl-reqd */
733 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
734 return PARAM_LIBCURL_DOESNT_SUPPORT;
735 config->ftp_ssl_reqd = toggle;
737 case 'w': /* --no-sessionid */
738 config->disable_sessionid = (!toggle)?TRUE:FALSE;
740 case 'x': /* --ftp-ssl-control */
741 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
742 return PARAM_LIBCURL_DOESNT_SUPPORT;
743 config->ftp_ssl_control = toggle;
745 case 'y': /* --ftp-ssl-ccc */
746 config->ftp_ssl_ccc = toggle;
747 if(!config->ftp_ssl_ccc_mode)
748 config->ftp_ssl_ccc_mode = CURLFTPSSL_CCC_PASSIVE;
750 case 'j': /* --ftp-ssl-ccc-mode */
751 config->ftp_ssl_ccc = TRUE;
752 config->ftp_ssl_ccc_mode = ftpcccmethod(config, nextarg);
754 case 'z': /* --libcurl */
755 #ifdef CURL_DISABLE_LIBCURL_OPTION
757 "--libcurl option was disabled at build-time!\n");
758 return PARAM_OPTION_UNKNOWN;
760 GetStr(&config->libcurl, nextarg);
763 case '#': /* --raw */
764 config->raw = toggle;
766 case '0': /* --post301 */
767 config->post301 = toggle;
769 case '1': /* --no-keepalive */
770 config->nokeepalive = (!toggle)?TRUE:FALSE;
772 case '3': /* --keepalive-time */
773 err = str2unum(&config->alivetime, nextarg);
777 case '4': /* --post302 */
778 config->post302 = toggle;
780 case 'I': /* --post303 */
781 config->post303 = toggle;
783 case '5': /* --noproxy */
784 /* This specifies the noproxy list */
785 GetStr(&config->noproxy, nextarg);
787 #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
788 case '6': /* --socks5-gssapi-service */
789 GetStr(&config->socks5_gssapi_service, nextarg);
791 case '7': /* --socks5-gssapi-nec*/
792 config->socks5_gssapi_nec = TRUE;
795 case '8': /* --proxy1.0 */
797 GetStr(&config->proxy, nextarg);
798 config->proxyver = CURLPROXY_HTTP_1_0;
800 case '9': /* --tftp-blksize */
801 err = str2unum(&config->tftp_blksize, nextarg);
805 case 'A': /* --mail-from */
806 GetStr(&config->mail_from, nextarg);
808 case 'B': /* --mail-rcpt */
809 /* append receiver to a list */
810 err = add2list(&config->mail_rcpt, nextarg);
814 case 'C': /* --ftp-pret */
815 config->ftp_pret = toggle;
817 case 'D': /* --proto */
818 config->proto_present = TRUE;
819 if(proto2num(config, &config->proto, nextarg))
820 return PARAM_BAD_USE;
822 case 'E': /* --proto-redir */
823 config->proto_redir_present = TRUE;
824 if(proto2num(config, &config->proto_redir, nextarg))
825 return PARAM_BAD_USE;
827 case 'F': /* --resolve */
828 err = add2list(&config->resolve, nextarg);
832 case 'G': /* --delegation LEVEL */
833 config->gssapi_delegation = delegation(config, nextarg);
835 case 'H': /* --mail-auth */
836 GetStr(&config->mail_auth, nextarg);
838 case 'J': /* --metalink */
841 int mlmaj, mlmin, mlpatch;
842 metalink_get_version(&mlmaj, &mlmin, &mlpatch);
843 if((mlmaj*10000)+(mlmin*100)+mlpatch < CURL_REQ_LIBMETALINK_VERS) {
845 "--metalink option cannot be used because the version of "
846 "the linked libmetalink library is too old. "
847 "Required: %d.%d.%d, found %d.%d.%d\n",
848 CURL_REQ_LIBMETALINK_MAJOR,
849 CURL_REQ_LIBMETALINK_MINOR,
850 CURL_REQ_LIBMETALINK_PATCH,
851 mlmaj, mlmin, mlpatch);
852 return PARAM_BAD_USE;
855 config->use_metalink = toggle;
857 warnf(config, "--metalink option is ignored because the binary is "
858 "built without the Metalink support.\n");
862 case 'K': /* --sasl-ir */
863 config->sasl_ir = TRUE;
867 case '#': /* --progress-bar */
869 config->progressmode = CURL_PROGRESS_BAR;
871 config->progressmode = CURL_PROGRESS_STATS;
873 case '~': /* --xattr */
874 config->xattr = toggle;
877 /* HTTP version 1.0 */
878 config->httpversion = CURL_HTTP_VERSION_1_0;
882 config->ssl_version = CURL_SSLVERSION_TLSv1;
886 config->ssl_version = CURL_SSLVERSION_SSLv2;
890 config->ssl_version = CURL_SSLVERSION_SSLv3;
894 config->ip_version = 4;
898 config->ip_version = 6;
901 /* This makes the FTP sessions use APPE instead of STOR */
902 config->ftp_append = toggle;
905 /* This specifies the User-Agent name */
906 GetStr(&config->useragent, nextarg);
908 case 'b': /* cookie string coming up: */
909 if(nextarg[0] == '@') {
912 else if(strchr(nextarg, '=')) {
913 /* A cookie string must have a =-letter */
914 GetStr(&config->cookie, nextarg);
917 /* We have a cookie file to read from! */
918 GetStr(&config->cookiefile, nextarg);
921 /* use ASCII/text when transferring */
922 config->use_ascii = toggle;
925 /* get the file name to dump all cookies in */
926 GetStr(&config->cookiejar, nextarg);
929 /* This makes us continue an ftp transfer at given position */
930 if(!curlx_strequal(nextarg, "-")) {
931 err = str2offset(&config->resume_from, nextarg);
934 config->resume_from_current = FALSE;
937 config->resume_from_current = TRUE;
938 config->resume_from = 0;
940 config->use_resume=TRUE;
945 char *postdata = NULL;
949 if(subletter == 'e') { /* --data-urlencode*/
950 /* [name]=[content], we encode the content part only
953 * Case 2: we first load the file using that name and then encode
956 const char *p = strchr(nextarg, '=');
960 /* there was no '=' letter, check for a '@' instead */
961 p = strchr(nextarg, '@');
963 nlen = p - nextarg; /* length of the name part */
964 is_file = *p++; /* pass the separator */
967 /* neither @ nor =, so no name and it isn't a file */
972 /* a '@' letter, it means that a file name or - (stdin) follows */
974 if(curlx_strequal("-", p)) {
979 file = fopen(p, "rb");
982 "Couldn't read data from file \"%s\", this makes "
983 "an empty POST.\n", nextarg);
986 err = file2memory(&postdata, &size, file);
988 if(file && (file != stdin))
994 GetStr(&postdata, p);
996 size = strlen(postdata);
1000 /* no data from the file, point to a zero byte string to make this
1001 get sent as a POST anyway */
1002 postdata = strdup("");
1004 return PARAM_NO_MEM;
1008 char *enc = curl_easy_escape(config->easy, postdata, (int)size);
1009 Curl_safefree(postdata); /* no matter if it worked or not */
1011 /* now make a string with the name from above and append the
1013 size_t outlen = nlen + strlen(enc) + 2;
1014 char *n = malloc(outlen);
1017 return PARAM_NO_MEM;
1019 if(nlen > 0) { /* only append '=' if we have a name */
1020 snprintf(n, outlen, "%.*s=%s", nlen, nextarg, enc);
1025 size = outlen-2; /* since no '=' was inserted */
1031 return PARAM_NO_MEM;
1034 else if('@' == *nextarg) {
1035 /* the data begins with a '@' letter, it means that a file name
1036 or - (stdin) follows */
1037 nextarg++; /* pass the @ */
1039 if(curlx_strequal("-", nextarg)) {
1041 if(subletter == 'b') /* forced data-binary */
1045 file = fopen(nextarg, "rb");
1047 warnf(config, "Couldn't read data from file \"%s\", this makes "
1048 "an empty POST.\n", nextarg);
1051 if(subletter == 'b')
1053 err = file2memory(&postdata, &size, file);
1055 err = file2string(&postdata, file);
1057 size = strlen(postdata);
1060 if(file && (file != stdin))
1066 /* no data from the file, point to a zero byte string to make this
1067 get sent as a POST anyway */
1068 postdata = strdup("");
1070 return PARAM_NO_MEM;
1074 GetStr(&postdata, nextarg);
1076 size = strlen(postdata);
1079 #ifdef CURL_DOES_CONVERSIONS
1080 if(subletter != 'b') {
1081 /* NOT forced binary, convert to ASCII */
1082 if(convert_to_network(postdata, strlen(postdata))) {
1083 Curl_safefree(postdata);
1084 return PARAM_NO_MEM;
1089 if(config->postfields) {
1090 /* we already have a string, we append this one with a separating
1092 char *oldpost = config->postfields;
1093 curl_off_t oldlen = config->postfieldsize;
1094 curl_off_t newlen = oldlen + size + 2;
1095 config->postfields = malloc((size_t)newlen);
1096 if(!config->postfields) {
1097 Curl_safefree(oldpost);
1098 Curl_safefree(postdata);
1099 return PARAM_NO_MEM;
1101 memcpy(config->postfields, oldpost, (size_t)oldlen);
1102 /* use byte value 0x26 for '&' to accommodate non-ASCII platforms */
1103 config->postfields[oldlen] = '\x26';
1104 memcpy(&config->postfields[oldlen+1], postdata, size);
1105 config->postfields[oldlen+1+size] = '\0';
1106 Curl_safefree(oldpost);
1107 Curl_safefree(postdata);
1108 config->postfieldsize += size+1;
1111 config->postfields = postdata;
1112 config->postfieldsize = size;
1116 We can't set the request type here, as this data might be used in
1117 a simple GET if -G is used. Already or soon.
1119 if(SetHTTPrequest(HTTPREQ_SIMPLEPOST, &config->httpreq)) {
1120 Curl_safefree(postdata);
1121 return PARAM_BAD_USE;
1126 /* dump-header to given file name */
1127 GetStr(&config->headerfile, nextarg);
1131 char *ptr = strstr(nextarg, ";auto");
1133 /* Automatic referer requested, this may be combined with a
1135 config->autoreferer = TRUE;
1136 *ptr = 0; /* zero terminate here */
1139 config->autoreferer = FALSE;
1140 GetStr(&config->referer, nextarg);
1145 case 'a': /* CA info PEM file */
1146 /* CA info PEM file */
1147 GetStr(&config->cacert, nextarg);
1149 case 'b': /* cert file type */
1150 GetStr(&config->cert_type, nextarg);
1152 case 'c': /* private key file */
1153 GetStr(&config->key, nextarg);
1155 case 'd': /* private key file type */
1156 GetStr(&config->key_type, nextarg);
1158 case 'e': /* private key passphrase */
1159 GetStr(&config->key_passwd, nextarg);
1162 case 'f': /* crypto engine */
1163 GetStr(&config->engine, nextarg);
1164 if(config->engine && curlx_raw_equal(config->engine,"list"))
1165 config->list_engines = TRUE;
1167 case 'g': /* CA info PEM file */
1168 /* CA cert directory */
1169 GetStr(&config->capath, nextarg);
1171 case 'h': /* --pubkey public key file */
1172 GetStr(&config->pubkey, nextarg);
1174 case 'i': /* --hostpubmd5 md5 of the host public key */
1175 GetStr(&config->hostpubmd5, nextarg);
1176 if(!config->hostpubmd5 || strlen(config->hostpubmd5) != 32)
1177 return PARAM_BAD_USE;
1179 case 'j': /* CRL info PEM file */
1181 GetStr(&config->crlfile, nextarg);
1183 case 'k': /* TLS username */
1184 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)
1185 GetStr(&config->tls_username, nextarg);
1187 return PARAM_LIBCURL_DOESNT_SUPPORT;
1189 case 'l': /* TLS password */
1190 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)
1191 GetStr(&config->tls_password, nextarg);
1193 return PARAM_LIBCURL_DOESNT_SUPPORT;
1195 case 'm': /* TLS authentication type */
1196 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP) {
1197 GetStr(&config->tls_authtype, nextarg);
1198 if(!strequal(config->tls_authtype, "SRP"))
1199 return PARAM_LIBCURL_DOESNT_SUPPORT; /* only support TLS-SRP */
1202 return PARAM_LIBCURL_DOESNT_SUPPORT;
1204 case 'n': /* no empty SSL fragments */
1205 if(curlinfo->features & CURL_VERSION_SSL)
1206 config->ssl_allow_beast = toggle;
1208 default: /* certificate file */
1210 char *ptr = strchr(nextarg, ':');
1211 /* Since we live in a world of weirdness and confusion, the win32
1212 dudes can use : when using drive letters and thus
1213 c:\file:password needs to work. In order not to break
1214 compatibility, we still use : as separator, but we try to detect
1215 when it is used for a file name! On windows. */
1218 (ptr == &nextarg[1]) &&
1219 (nextarg[2] == '\\' || nextarg[2] == '/') &&
1220 (ISALPHA(nextarg[0])) )
1221 /* colon in the second column, followed by a backslash, and the
1222 first character is an alphabetic letter:
1224 this is a drive letter colon */
1225 ptr = strchr(&nextarg[3], ':'); /* find the next one instead */
1228 /* we have a password too */
1231 GetStr(&config->key_passwd, ptr);
1233 GetStr(&config->cert, nextarg);
1239 /* fail hard on errors */
1240 config->failonerror = toggle;
1243 /* "form data" simulation, this is a little advanced so lets do our best
1244 to sort this out slowly and carefully */
1245 if(formparse(config,
1249 (subletter=='s')?TRUE:FALSE)) /* 's' means literal string */
1250 return PARAM_BAD_USE;
1251 if(SetHTTPrequest(config, HTTPREQ_POST, &config->httpreq))
1252 return PARAM_BAD_USE;
1255 case 'g': /* g disables URLglobbing */
1256 config->globoff = toggle;
1259 case 'G': /* HTTP GET */
1260 config->use_httpget = TRUE;
1263 case 'h': /* h for help */
1266 return PARAM_HELP_REQUESTED;
1268 /* we now actually support --no-help too! */
1271 /* A custom header to append to a list */
1272 err = add2list(&config->headers, nextarg);
1277 config->include_headers = toggle; /* include the headers as well in the
1278 general output stream */
1281 config->cookiesession = toggle;
1285 * no_body will imply include_headers later on
1287 config->no_body = toggle;
1288 if(SetHTTPrequest(config,
1289 (config->no_body)?HTTPREQ_HEAD:HTTPREQ_GET,
1291 return PARAM_BAD_USE;
1293 case 'J': /* --remote-header-name */
1294 if(config->include_headers) {
1296 "--include and --remote-header-name cannot be combined.\n");
1297 return PARAM_BAD_USE;
1299 config->content_disposition = toggle;
1301 case 'k': /* allow insecure SSL connects */
1302 config->insecure_ok = toggle;
1304 case 'K': /* parse config file */
1305 if(parseconfig(nextarg, config))
1306 warnf(config, "error trying read config from the '%s' file\n",
1310 config->dirlistonly = toggle; /* only list the names of the FTP dir */
1313 config->followlocation = toggle; /* Follow Location: HTTP headers */
1314 switch (subletter) {
1316 /* Continue to send authentication (user+password) when following
1317 * locations, even when hostname changed */
1318 config->unrestricted_auth = toggle;
1323 /* specified max time */
1324 err = str2unum(&config->timeout, nextarg);
1328 case 'M': /* M for manual, huge help */
1329 if(toggle) { /* --no-manual shows no manual... */
1332 return PARAM_HELP_REQUESTED;
1335 "built-in manual was disabled at build-time!\n");
1336 return PARAM_OPTION_UNKNOWN;
1342 case 'o': /* CA info PEM file */
1343 /* use .netrc or URL */
1344 config->netrc_opt = toggle;
1346 case 'e': /* netrc-file */
1347 GetStr(&config->netrc_file, nextarg);
1350 /* pick info from .netrc, if this is used for http, curl will
1351 automatically enfore user+password with the request */
1352 config->netrc = toggle;
1357 /* disable the output I/O buffering. note that the option is called
1358 --buffer but is mostly used in the negative form: --no-buffer */
1360 config->nobuffer = (!toggle)?TRUE:FALSE;
1362 config->nobuffer = toggle;
1364 case 'O': /* --remote-name */
1365 if(subletter == 'a') { /* --remote-name-all */
1366 config->default_node_flags = toggle?GETOUT_USEREMOTE:0;
1370 case 'o': /* --output */
1374 if(config->url_out || ((config->url_out = config->url_list) != NULL)) {
1375 /* there's a node here, if it already is filled-in continue to find
1377 while(config->url_out && (config->url_out->flags & GETOUT_OUTFILE))
1378 config->url_out = config->url_out->next;
1381 /* now there might or might not be an available node to fill in! */
1385 url = config->url_out;
1387 /* there was no free node, create one! */
1388 url = new_getout(config);
1391 return PARAM_NO_MEM;
1393 /* fill in the outfile */
1395 GetStr(&url->outfile, nextarg);
1396 url->flags &= ~GETOUT_USEREMOTE; /* switch off */
1399 url->outfile = NULL; /* leave it */
1401 url->flags |= GETOUT_USEREMOTE; /* switch on */
1403 url->flags &= ~GETOUT_USEREMOTE; /* switch off */
1405 url->flags |= GETOUT_OUTFILE;
1410 /* This makes the FTP sessions use PORT instead of PASV */
1411 /* use <eth0> or <192.168.10.10> style addresses. Anything except
1412 this will make us try to get the "default" address.
1413 NOTE: this is a changed behaviour since the released 4.1!
1415 GetStr(&config->ftpport, nextarg);
1418 /* proxy tunnel for non-http protocols */
1419 config->proxytunnel = toggle;
1422 case 'q': /* if used first, already taken care of, we do it like
1423 this so we don't cause an error! */
1426 /* QUOTE command to send to FTP server */
1427 switch(nextarg[0]) {
1429 /* prefixed with a dash makes it a POST TRANSFER one */
1431 err = add2list(&config->postquote, nextarg);
1434 /* prefixed with a plus makes it a just-before-transfer one */
1436 err = add2list(&config->prequote, nextarg);
1439 err = add2list(&config->quote, nextarg);
1446 /* Specifying a range WITHOUT A DASH will create an illegal HTTP range
1447 (and won't actually be range by definition). The man page previously
1448 claimed that to be a good way, why this code is added to work-around
1450 if(ISDIGIT(*nextarg) && !strchr(nextarg, '-')) {
1454 "A specified range MUST include at least one dash (-). "
1455 "Appending one for you!\n");
1456 off = curlx_strtoofft(nextarg, NULL, 10);
1457 snprintf(buffer, sizeof(buffer), "%" CURL_FORMAT_CURL_OFF_T "-", off);
1458 Curl_safefree(config->range);
1459 config->range = strdup(buffer);
1461 return PARAM_NO_MEM;
1464 /* byte range requested */
1466 tmp_range = nextarg;
1467 while(*tmp_range != '\0') {
1468 if(!ISDIGIT(*tmp_range) && *tmp_range != '-' && *tmp_range != ',') {
1469 warnf(config,"Invalid character is found in given range. "
1470 "A specified range MUST have only digits in "
1471 "\'start\'-\'stop\'. The server's response to this "
1472 "request is uncertain.\n");
1477 /* byte range requested */
1478 GetStr(&config->range, nextarg);
1482 /* use remote file's time */
1483 config->remote_time = toggle;
1486 /* don't show progress meter, don't show errors : */
1488 config->mute = config->noprogress = TRUE;
1490 config->mute = config->noprogress = FALSE;
1491 if(config->showerror < 0)
1492 /* if still on the default value, set showerror to the reverse of
1493 toggle. This is to allow -S and -s to be used in an independent
1494 order but still have the same effect. */
1495 config->showerror = (!toggle)?TRUE:FALSE; /* toggle off */
1499 config->showerror = toggle?1:0; /* toggle on if used with -s */
1502 /* Telnet options */
1503 err = add2list(&config->telnet_options, nextarg);
1508 /* we are uploading */
1511 if(config->url_out || ((config->url_out = config->url_list) != NULL)) {
1512 /* there's a node here, if it already is filled-in continue to find
1514 while(config->url_out && (config->url_out->flags & GETOUT_UPLOAD))
1515 config->url_out = config->url_out->next;
1518 /* now there might or might not be an available node to fill in! */
1522 url = config->url_out;
1524 /* there was no free node, create one! */
1525 url = new_getout(config);
1528 return PARAM_NO_MEM;
1530 url->flags |= GETOUT_UPLOAD; /* mark -T used */
1532 url->flags |= GETOUT_NOUPLOAD;
1534 /* "-" equals stdin, but keep the string around for now */
1535 GetStr(&url->infile, nextarg);
1542 GetStr(&config->userpwd, nextarg);
1544 err = checkpasswd("host", &config->userpwd);
1549 /* Proxy user:password */
1550 GetStr(&config->proxyuserpwd, nextarg);
1552 err = checkpasswd("proxy", &config->proxyuserpwd);
1558 /* the '%' thing here will cause the trace get sent to stderr */
1559 Curl_safefree(config->trace_dump);
1560 config->trace_dump = strdup("%");
1561 if(!config->trace_dump)
1562 return PARAM_NO_MEM;
1563 if(config->tracetype && (config->tracetype != TRACE_PLAIN))
1565 "-v, --verbose overrides an earlier trace/verbose option\n");
1566 config->tracetype = TRACE_PLAIN;
1569 /* verbose is disabled here */
1570 config->tracetype = TRACE_NONE;
1574 const char *const *proto;
1577 /* --no-version yields no output! */
1580 printf(CURL_ID "%s\n", curl_version());
1581 if(curlinfo->protocols) {
1582 printf("Protocols: ");
1583 for(proto = curlinfo->protocols; *proto; ++proto) {
1584 printf("%s ", *proto);
1586 puts(""); /* newline */
1588 if(curlinfo->features) {
1590 printf("Features: ");
1591 for(i = 0; i < sizeof(feats)/sizeof(feats[0]); i++) {
1592 if(curlinfo->features & feats[i].bitmask)
1593 printf("%s ", feats[i].name);
1596 printf("Metalink ");
1598 puts(""); /* newline */
1601 return PARAM_HELP_REQUESTED;
1603 /* get the output string */
1604 if('@' == *nextarg) {
1605 /* the data begins with a '@' letter, it means that a file name
1606 or - (stdin) follows */
1609 nextarg++; /* pass the @ */
1610 if(curlx_strequal("-", nextarg)) {
1616 file = fopen(nextarg, "r");
1618 err = file2string(&config->writeout, file);
1619 if(file && (file != stdin))
1623 if(!config->writeout)
1624 warnf(config, "Failed to read %s", fname);
1627 GetStr(&config->writeout, nextarg);
1631 GetStr(&config->proxy, nextarg);
1632 config->proxyver = CURLPROXY_HTTP;
1635 /* set custom request */
1636 GetStr(&config->customrequest, nextarg);
1639 /* low speed time */
1640 err = str2unum(&config->low_speed_time, nextarg);
1643 if(!config->low_speed_limit)
1644 config->low_speed_limit = 1;
1647 /* low speed limit */
1648 err = str2unum(&config->low_speed_limit, nextarg);
1651 if(!config->low_speed_time)
1652 config->low_speed_time = 30;
1654 case 'z': /* time condition coming up */
1659 /* If-Modified-Since: (section 14.28 in RFC2068) */
1660 config->timecond = CURL_TIMECOND_IFMODSINCE;
1663 /* If-Unmodified-Since: (section 14.24 in RFC2068) */
1664 config->timecond = CURL_TIMECOND_IFUNMODSINCE;
1668 /* Last-Modified: (section 14.29 in RFC2068) */
1669 config->timecond = CURL_TIMECOND_LASTMOD;
1674 config->condtime=curl_getdate(nextarg, &now);
1675 if(-1 == (int)config->condtime) {
1676 /* now let's see if it is a file name to get the time from instead! */
1677 struct_stat statbuf;
1678 if(-1 == stat(nextarg, &statbuf)) {
1679 /* failed, remove time condition */
1680 config->timecond = CURL_TIMECOND_NONE;
1682 "Illegal date format for -z, --timecond (and not "
1683 "a file name). Disabling time condition. "
1684 "See curl_getdate(3) for valid date syntax.\n");
1687 /* pull the time out from the file */
1688 config->condtime = statbuf.st_mtime;
1692 default: /* unknown flag */
1693 return PARAM_OPTION_UNKNOWN;
1697 } while(!longopt && !singleopt && *++parse && !*usedarg);