1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2011, 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 ***************************************************************************/
24 #include <curl/curl.h>
28 #define ENABLE_CURLX_PRINTF
29 /* use our own printf() functions */
33 # include "hugehelp.h"
38 #include "tool_binmode.h"
39 #include "tool_cfgable.h"
40 #include "tool_cb_prg.h"
41 #include "tool_formparse.h"
42 #include "tool_getparam.h"
43 #include "tool_help.h"
44 #include "tool_helpers.h"
45 #include "tool_libinfo.h"
46 #include "tool_msgs.h"
47 #include "tool_paramhlp.h"
48 #include "tool_parsecfg.h"
50 #include "memdebug.h" /* keep this as LAST include */
56 #define GetStr(str,val) do { \
62 *(str) = strdup((val)); \
64 return PARAM_NO_MEM; \
68 const char *letter; /* short name option */
69 const char *lname; /* long name option */
70 bool extraparam; /* whether it takes an additional argument */
73 static const struct LongShort aliases[]= {
74 /* all these ones, starting with "*" or "$" as a short-option have *no*
75 short option to mention. */
77 {"*a", "random-file", TRUE},
78 {"*b", "egd-file", TRUE},
79 {"*c", "connect-timeout", TRUE},
80 {"*d", "ciphers", TRUE},
81 {"*e", "disable-epsv", FALSE},
82 {"*E", "epsv", FALSE},
83 /* 'epsv' made like this to make --no-epsv and --epsv to work
84 although --disable-epsv is the documented option */
85 #ifdef USE_ENVIRONMENT
86 {"*f", "environment", FALSE},
88 {"*g", "trace", TRUE},
89 {"*h", "trace-ascii", TRUE},
90 {"*i", "limit-rate", TRUE},
91 {"*j", "compressed", FALSE},
92 {"*J", "tr-encoding", FALSE},
93 {"*k", "digest", FALSE},
94 {"*l", "negotiate", FALSE},
95 {"*m", "ntlm", FALSE},
96 {"*M", "ntlm-wb", FALSE},
97 {"*n", "basic", FALSE},
98 {"*o", "anyauth", FALSE},
100 {"*p", "wdebug", FALSE},
102 {"*q", "ftp-create-dirs", FALSE},
103 {"*r", "create-dirs", FALSE},
104 {"*s", "max-redirs", TRUE},
105 {"*t", "proxy-ntlm", FALSE},
106 {"*u", "crlf", FALSE},
107 {"*v", "stderr", TRUE},
108 {"*w", "interface", TRUE},
109 {"*x", "krb" , TRUE},
110 {"*x", "krb4" , TRUE},
111 /* 'krb4' is the previous name */
112 {"*y", "max-filesize", TRUE},
113 {"*z", "disable-eprt", FALSE},
114 {"*Z", "eprt", FALSE},
115 /* 'eprt' made like this to make --no-eprt and --eprt to work
116 although --disable-eprt is the documented option */
117 {"$a", "ftp-ssl", FALSE},
118 /* 'ftp-ssl' deprecated name since 7.20.0 */
119 {"$a", "ssl", FALSE},
120 /* 'ssl' new option name in 7.20.0, previously this was ftp-ssl */
121 {"$b", "ftp-pasv", FALSE},
122 {"$c", "socks5", TRUE},
123 {"$c", "socks", TRUE},
124 /* 'socks' is how the option once was documented but we prefer
125 the --socks5 version for explicit version */
126 {"$d", "tcp-nodelay", FALSE},
127 {"$e", "proxy-digest", FALSE},
128 {"$f", "proxy-basic", FALSE},
129 {"$g", "retry", TRUE},
130 {"$h", "retry-delay", TRUE},
131 {"$i", "retry-max-time", TRUE},
132 {"$k", "proxy-negotiate", FALSE},
133 {"$m", "ftp-account", TRUE},
134 {"$n", "proxy-anyauth", FALSE},
135 {"$o", "trace-time", FALSE},
136 {"$p", "ignore-content-length", FALSE},
137 {"$q", "ftp-skip-pasv-ip", FALSE},
138 {"$r", "ftp-method", TRUE},
139 {"$s", "local-port", TRUE},
140 {"$t", "socks4", TRUE},
141 {"$T", "socks4a", TRUE},
142 {"$u", "ftp-alternative-to-user", TRUE},
143 {"$v", "ftp-ssl-reqd", FALSE},
144 /* 'ftp-ssl-reqd' deprecated name since 7.20.0 */
145 {"$v", "ssl-reqd", FALSE},
146 /* 'ssl-reqd' new in 7.20.0, previously this was ftp-ssl-reqd */
147 {"$w", "sessionid", FALSE},
148 /* ¡sessionid' listed as --no-sessionid in the help */
149 {"$x", "ftp-ssl-control", FALSE},
150 {"$y", "ftp-ssl-ccc", FALSE},
151 {"$j", "ftp-ssl-ccc-mode", TRUE},
152 {"$z", "libcurl", TRUE},
153 {"$#", "raw", FALSE},
154 {"$0", "post301", FALSE},
155 {"$1", "keepalive", FALSE},
156 /* 'keepalive' listed as --no-keepalive in the help */
157 {"$2", "socks5-hostname", TRUE},
158 {"$3", "keepalive-time", TRUE},
159 {"$4", "post302", FALSE},
160 {"$5", "noproxy", TRUE},
161 #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
162 {"$6", "socks5-gssapi-service", TRUE},
163 {"$7", "socks5-gssapi-nec", FALSE},
165 {"$8", "proxy1.0", TRUE},
166 {"$9", "tftp-blksize", TRUE},
167 {"$A", "mail-from", TRUE},
168 {"$B", "mail-rcpt", TRUE},
169 {"$C", "ftp-pret", FALSE},
170 {"$D", "proto", TRUE},
171 {"$E", "proto-redir", TRUE},
172 {"$F", "resolve", TRUE},
173 {"$G", "delegation", TRUE},
174 {"0", "http1.0", FALSE},
175 {"1", "tlsv1", FALSE},
176 {"2", "sslv2", FALSE},
177 {"3", "sslv3", FALSE},
178 {"4", "ipv4", FALSE},
179 {"6", "ipv6", FALSE},
180 {"a", "append", FALSE},
181 {"A", "user-agent", TRUE},
182 {"b", "cookie", TRUE},
183 {"B", "use-ascii", FALSE},
184 {"c", "cookie-jar", TRUE},
185 {"C", "continue-at", TRUE},
187 {"da", "data-ascii", TRUE},
188 {"db", "data-binary", TRUE},
189 {"de", "data-urlencode", TRUE},
190 {"D", "dump-header", TRUE},
191 {"e", "referer", TRUE},
193 {"Ea", "cacert", TRUE},
194 {"Eb", "cert-type", TRUE},
196 {"Ed", "key-type", TRUE},
197 {"Ee", "pass", TRUE},
198 {"Ef", "engine", TRUE},
199 {"Eg", "capath ", TRUE},
200 {"Eh", "pubkey", TRUE},
201 {"Ei", "hostpubmd5", TRUE},
202 {"Ej", "crlfile", TRUE},
203 {"Ek", "tlsuser", TRUE},
204 {"El", "tlspassword", TRUE},
205 {"Em", "tlsauthtype", TRUE},
206 {"f", "fail", FALSE},
208 {"Fs", "form-string", TRUE},
209 {"g", "globoff", FALSE},
211 {"h", "help", FALSE},
212 {"H", "header", TRUE},
213 {"i", "include", FALSE},
214 {"I", "head", FALSE},
215 {"j", "junk-session-cookies", FALSE},
216 {"J", "remote-header-name", FALSE},
217 {"k", "insecure", FALSE},
218 {"K", "config", TRUE},
219 {"l", "list-only", FALSE},
220 {"L", "location", FALSE},
221 {"Lt", "location-trusted", FALSE},
222 {"m", "max-time", TRUE},
223 {"M", "manual", FALSE},
224 {"n", "netrc", FALSE},
225 {"no", "netrc-optional", FALSE},
226 {"ne", "netrc-file", TRUE},
227 {"N", "buffer", FALSE},
228 /* 'buffer' listed as --no-buffer in the help */
229 {"o", "output", TRUE},
230 {"O", "remote-name", FALSE},
231 {"Oa", "remote-name-all", FALSE},
232 {"p", "proxytunnel", FALSE},
233 {"P", "ftpport", TRUE},
234 /* 'ftpport' old version */
235 {"P", "ftp-port", TRUE},
236 {"q", "disable", FALSE},
237 {"Q", "quote", TRUE},
238 {"r", "range", TRUE},
239 {"R", "remote-time", FALSE},
240 {"s", "silent", FALSE},
241 {"S", "show-error", FALSE},
242 {"t", "telnet-options", TRUE},
243 /* 'telnet-options' documented as telnet-option */
244 {"T", "upload-file", TRUE},
246 {"U", "proxy-user", TRUE},
247 {"v", "verbose", FALSE},
248 {"V", "version", FALSE},
249 {"w", "write-out", TRUE},
250 {"x", "proxy", TRUE},
251 {"X", "request", TRUE},
252 {"X", "http-request", TRUE},
253 /* 'http-request' OBSOLETE VERSION */
254 {"Y", "speed-limit", TRUE},
255 {"y", "speed-time", TRUE},
256 {"z", "time-cond", TRUE},
257 {"#", "progress-bar", FALSE},
258 {"~", "xattr", FALSE},
266 static const struct feat feats[] = {
267 {"AsynchDNS", CURL_VERSION_ASYNCHDNS},
268 {"Debug", CURL_VERSION_DEBUG},
269 {"TrackMemory", CURL_VERSION_CURLDEBUG},
270 {"GSS-Negotiate", CURL_VERSION_GSSNEGOTIATE},
271 {"IDN", CURL_VERSION_IDN},
272 {"IPv6", CURL_VERSION_IPV6},
273 {"Largefile", CURL_VERSION_LARGEFILE},
274 {"NTLM", CURL_VERSION_NTLM},
275 {"NTLM_WB", CURL_VERSION_NTLM_WB},
276 {"SPNEGO", CURL_VERSION_SPNEGO},
277 {"SSL", CURL_VERSION_SSL},
278 {"SSPI", CURL_VERSION_SSPI},
279 {"krb4", CURL_VERSION_KERBEROS4},
280 {"libz", CURL_VERSION_LIBZ},
281 {"CharConv", CURL_VERSION_CONV},
282 {"TLS-SRP", CURL_VERSION_TLSAUTH_SRP}
285 ParameterError getparameter(char *flag, /* f or -long-flag */
286 char *nextarg, /* NULL if unset */
287 bool *usedarg, /* set to TRUE if the arg
289 struct Configurable *config)
292 char subletter = '\0'; /* subletters can only occur on long options */
294 const char *parse = NULL;
298 bool longopt = FALSE;
299 bool singleopt = FALSE; /* when true means '-o foo' used '-ofoo' */
301 bool toggle = TRUE; /* how to switch boolean options, on or off. Controlled
302 by using --OPTION or --no-OPTION */
305 if(('-' != flag[0]) ||
306 (('-' == flag[0]) && ('-' == flag[1]))) {
307 /* this should be a long name */
308 char *word = ('-' == flag[0]) ? flag+2 : flag;
309 size_t fnam = strlen(word);
312 if(!strncmp(word, "no-", 3)) {
313 /* disable this option but ignore the "no-" part when looking for it */
318 for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) {
319 if(curlx_strnequal(aliases[j].lname, word, fnam)) {
322 if(curlx_raw_equal(aliases[j].lname, word)) {
323 parse = aliases[j].letter;
325 numhits = 1; /* a single unique hit */
328 parse = aliases[j].letter;
333 /* this is at least the second match! */
334 return PARAM_OPTION_AMBIGUOUS;
337 return PARAM_OPTION_UNKNOWN;
341 flag++; /* prefixed with one dash, pass it */
347 /* we can loop here if we have multiple single-letters */
351 letter = (char)*parse;
360 subletter = parse[1];
362 *usedarg = FALSE; /* default is that we don't use the arg */
365 for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) {
366 if(letter == aliases[j].letter[0]) {
372 return PARAM_OPTION_UNKNOWN;
376 if(aliases[hit].extraparam) {
377 /* this option requires an extra parameter */
378 if(!longopt && parse[1]) {
379 nextarg = (char *)&parse[1]; /* this is the actual extra parameter */
380 singleopt = TRUE; /* don't loop anymore after this */
383 return PARAM_REQUIRES_PARAMETER;
385 *usedarg = TRUE; /* mark it as used */
389 case '*': /* options without a short option */
391 case 'a': /* random-file */
392 GetStr(&config->random_file, nextarg);
394 case 'b': /* egd-file */
395 GetStr(&config->egd_file, nextarg);
397 case 'c': /* connect-timeout */
398 if(str2num(&config->connecttimeout, nextarg))
399 return PARAM_BAD_NUMERIC;
401 case 'd': /* ciphers */
402 GetStr(&config->cipher_list, nextarg);
404 case 'e': /* --disable-epsv */
405 config->disable_epsv = toggle;
407 case 'E': /* --epsv */
408 config->disable_epsv = (!toggle)?TRUE:FALSE;
410 #ifdef USE_ENVIRONMENT
412 config->writeenv = toggle;
415 case 'g': /* --trace */
416 GetStr(&config->trace_dump, nextarg);
417 if(config->tracetype && (config->tracetype != TRACE_BIN))
418 warnf(config, "--trace overrides an earlier trace/verbose option\n");
419 config->tracetype = TRACE_BIN;
421 case 'h': /* --trace-ascii */
422 GetStr(&config->trace_dump, nextarg);
423 if(config->tracetype && (config->tracetype != TRACE_ASCII))
425 "--trace-ascii overrides an earlier trace/verbose option\n");
426 config->tracetype = TRACE_ASCII;
428 case 'i': /* --limit-rate */
430 /* We support G, M, K too */
432 curl_off_t value = curlx_strtoofft(nextarg, &unit, 0);
436 else if(strlen(unit) > 1)
437 unit = (char *)"w"; /* unsupported */
442 value *= 1024*1024*1024;
454 /* for plain bytes, leave as-is */
457 warnf(config, "unsupported rate unit. Use G, M, K or B!\n");
458 return PARAM_BAD_USE;
460 config->recvpersecond = value;
461 config->sendpersecond = value;
465 case 'j': /* --compressed */
466 if(toggle && !(curlinfo->features & CURL_VERSION_LIBZ))
467 return PARAM_LIBCURL_DOESNT_SUPPORT;
468 config->encoding = toggle;
471 case 'J': /* --tr-encoding */
472 config->tr_encoding = toggle;
475 case 'k': /* --digest */
477 config->authtype |= CURLAUTH_DIGEST;
479 config->authtype &= ~CURLAUTH_DIGEST;
482 case 'l': /* --negotiate */
484 if(curlinfo->features & CURL_VERSION_GSSNEGOTIATE)
485 config->authtype |= CURLAUTH_GSSNEGOTIATE;
487 return PARAM_LIBCURL_DOESNT_SUPPORT;
490 config->authtype &= ~CURLAUTH_GSSNEGOTIATE;
493 case 'm': /* --ntlm */
495 if(curlinfo->features & CURL_VERSION_NTLM)
496 config->authtype |= CURLAUTH_NTLM;
498 return PARAM_LIBCURL_DOESNT_SUPPORT;
501 config->authtype &= ~CURLAUTH_NTLM;
504 case 'M': /* --ntlm-wb */
506 if(curlinfo->features & CURL_VERSION_NTLM_WB)
507 config->authtype |= CURLAUTH_NTLM_WB;
509 return PARAM_LIBCURL_DOESNT_SUPPORT;
512 config->authtype &= ~CURLAUTH_NTLM_WB;
515 case 'n': /* --basic for completeness */
517 config->authtype |= CURLAUTH_BASIC;
519 config->authtype &= ~CURLAUTH_BASIC;
522 case 'o': /* --anyauth, let libcurl pick it */
524 config->authtype = CURLAUTH_ANY;
525 /* --no-anyauth simply doesn't touch it */
529 case 'p': /* --wdebug */
533 case 'q': /* --ftp-create-dirs */
534 config->ftp_create_dirs = toggle;
537 case 'r': /* --create-dirs */
538 config->create_dirs = TRUE;
541 case 's': /* --max-redirs */
542 /* specified max no of redirects (http(s)) */
543 if(str2num(&config->maxredirs, nextarg))
544 return PARAM_BAD_NUMERIC;
547 case 't': /* --proxy-ntlm */
548 if(curlinfo->features & CURL_VERSION_NTLM)
549 config->proxyntlm = toggle;
551 return PARAM_LIBCURL_DOESNT_SUPPORT;
554 case 'u': /* --crlf */
555 /* LF -> CRLF conversion? */
559 case 'v': /* --stderr */
560 if(strcmp(nextarg, "-")) {
561 FILE *newfile = fopen(nextarg, "wt");
563 warnf(config, "Failed to open %s!\n", nextarg);
565 if(config->errors_fopened)
566 fclose(config->errors);
567 config->errors = newfile;
568 config->errors_fopened = TRUE;
572 config->errors = stdout;
574 case 'w': /* --interface */
576 GetStr(&config->iface, nextarg);
578 case 'x': /* --krb */
579 /* kerberos level string */
580 if(curlinfo->features & (CURL_VERSION_KERBEROS4 |
581 CURL_VERSION_GSSNEGOTIATE))
582 GetStr(&config->krblevel, nextarg);
584 return PARAM_LIBCURL_DOESNT_SUPPORT;
586 case 'y': /* --max-filesize */
587 if(str2offset(&config->max_filesize, nextarg))
588 return PARAM_BAD_NUMERIC;
590 case 'z': /* --disable-eprt */
591 config->disable_eprt = toggle;
593 case 'Z': /* --eprt */
594 config->disable_eprt = (!toggle)?TRUE:FALSE;
597 default: /* the URL! */
600 if(config->url_get || ((config->url_get = config->url_list) != NULL)) {
601 /* there's a node here, if it already is filled-in continue to find
603 while(config->url_get && (config->url_get->flags&GETOUT_URL))
604 config->url_get = config->url_get->next;
607 /* now there might or might not be an available node to fill in! */
611 url = config->url_get;
613 /* there was no free node, create one! */
614 url = new_getout(config);
617 /* fill in the URL */
618 GetStr(&url->url, nextarg);
619 url->flags |= GETOUT_URL;
624 case '$': /* more options without a short option */
626 case 'a': /* --ftp-ssl */
627 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
628 return PARAM_LIBCURL_DOESNT_SUPPORT;
629 config->ftp_ssl = toggle;
631 case 'b': /* --ftp-pasv */
632 Curl_safefree(config->ftpport);
634 case 'c': /* --socks5 specifies a socks5 proxy to use, and resolves
635 the name locally and passes on the resolved address */
636 GetStr(&config->socksproxy, nextarg);
637 config->socksver = CURLPROXY_SOCKS5;
639 case 't': /* --socks4 specifies a socks4 proxy to use */
640 GetStr(&config->socksproxy, nextarg);
641 config->socksver = CURLPROXY_SOCKS4;
643 case 'T': /* --socks4a specifies a socks4a proxy to use */
644 GetStr(&config->socksproxy, nextarg);
645 config->socksver = CURLPROXY_SOCKS4A;
647 case '2': /* --socks5-hostname specifies a socks5 proxy and enables name
648 resolving with the proxy */
649 GetStr(&config->socksproxy, nextarg);
650 config->socksver = CURLPROXY_SOCKS5_HOSTNAME;
652 case 'd': /* --tcp-nodelay option */
653 config->tcp_nodelay = toggle;
655 case 'e': /* --proxy-digest */
656 config->proxydigest = toggle;
658 case 'f': /* --proxy-basic */
659 config->proxybasic = toggle;
661 case 'g': /* --retry */
662 if(str2num(&config->req_retry, nextarg))
663 return PARAM_BAD_NUMERIC;
665 case 'h': /* --retry-delay */
666 if(str2num(&config->retry_delay, nextarg))
667 return PARAM_BAD_NUMERIC;
669 case 'i': /* --retry-max-time */
670 if(str2num(&config->retry_maxtime, nextarg))
671 return PARAM_BAD_NUMERIC;
674 case 'k': /* --proxy-negotiate */
675 if(curlinfo->features & CURL_VERSION_GSSNEGOTIATE)
676 config->proxynegotiate = toggle;
678 return PARAM_LIBCURL_DOESNT_SUPPORT;
680 case 'm': /* --ftp-account */
681 GetStr(&config->ftp_account, nextarg);
683 case 'n': /* --proxy-anyauth */
684 config->proxyanyauth = toggle;
686 case 'o': /* --trace-time */
687 config->tracetime = toggle;
689 case 'p': /* --ignore-content-length */
690 config->ignorecl = toggle;
692 case 'q': /* --ftp-skip-pasv-ip */
693 config->ftp_skip_ip = toggle;
695 case 'r': /* --ftp-method (undocumented at this point) */
696 config->ftp_filemethod = ftpfilemethod(config, nextarg);
698 case 's': /* --local-port */
699 rc = sscanf(nextarg, "%d - %d",
701 &config->localportrange);
703 return PARAM_BAD_USE;
705 config->localportrange = 1; /* default number of ports to try */
707 config->localportrange -= config->localport;
708 if(config->localportrange < 1) {
709 warnf(config, "bad range input\n");
710 return PARAM_BAD_USE;
714 case 'u': /* --ftp-alternative-to-user */
715 GetStr(&config->ftp_alternative_to_user, nextarg);
717 case 'v': /* --ftp-ssl-reqd */
718 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
719 return PARAM_LIBCURL_DOESNT_SUPPORT;
720 config->ftp_ssl_reqd = toggle;
722 case 'w': /* --no-sessionid */
723 config->disable_sessionid = (!toggle)?TRUE:FALSE;
725 case 'x': /* --ftp-ssl-control */
726 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
727 return PARAM_LIBCURL_DOESNT_SUPPORT;
728 config->ftp_ssl_control = toggle;
730 case 'y': /* --ftp-ssl-ccc */
731 config->ftp_ssl_ccc = toggle;
732 if(!config->ftp_ssl_ccc_mode)
733 config->ftp_ssl_ccc_mode = CURLFTPSSL_CCC_PASSIVE;
735 case 'j': /* --ftp-ssl-ccc-mode */
736 config->ftp_ssl_ccc = TRUE;
737 config->ftp_ssl_ccc_mode = ftpcccmethod(config, nextarg);
739 case 'z': /* --libcurl */
740 GetStr(&config->libcurl, nextarg);
742 case '#': /* --raw */
743 config->raw = toggle;
745 case '0': /* --post301 */
746 config->post301 = toggle;
748 case '1': /* --no-keepalive */
749 config->nokeepalive = (!toggle)?TRUE:FALSE;
751 case '3': /* --keepalive-time */
752 if(str2num(&config->alivetime, nextarg))
753 return PARAM_BAD_NUMERIC;
755 case '4': /* --post302 */
756 config->post302 = toggle;
758 case '5': /* --noproxy */
759 /* This specifies the noproxy list */
760 GetStr(&config->noproxy, nextarg);
762 #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
763 case '6': /* --socks5-gssapi-service */
764 GetStr(&config->socks5_gssapi_service, nextarg);
766 case '7': /* --socks5-gssapi-nec*/
767 config->socks5_gssapi_nec = TRUE;
770 case '8': /* --proxy1.0 */
772 GetStr(&config->proxy, nextarg);
773 config->proxyver = CURLPROXY_HTTP_1_0;
775 case '9': /* --tftp-blksize */
776 str2num(&config->tftp_blksize, nextarg);
778 case 'A': /* --mail-from */
779 GetStr(&config->mail_from, nextarg);
781 case 'B': /* --mail-rcpt */
782 /* append receiver to a list */
783 err = add2list(&config->mail_rcpt, nextarg);
787 case 'C': /* --ftp-pret */
788 config->ftp_pret = toggle;
790 case 'D': /* --proto */
791 config->proto_present = TRUE;
792 if(proto2num(config, &config->proto, nextarg))
793 return PARAM_BAD_USE;
795 case 'E': /* --proto-redir */
796 config->proto_redir_present = TRUE;
797 if(proto2num(config, &config->proto_redir, nextarg))
798 return PARAM_BAD_USE;
800 case 'F': /* --resolve */
801 err = add2list(&config->resolve, nextarg);
805 case 'G': /* --delegation LEVEL */
806 config->gssapi_delegation = delegation(config, nextarg);
810 case '#': /* --progress-bar */
812 config->progressmode = CURL_PROGRESS_BAR;
814 config->progressmode = CURL_PROGRESS_STATS;
816 case '~': /* --xattr */
817 config->xattr = toggle;
820 /* HTTP version 1.0 */
821 config->httpversion = CURL_HTTP_VERSION_1_0;
825 config->ssl_version = CURL_SSLVERSION_TLSv1;
829 config->ssl_version = CURL_SSLVERSION_SSLv2;
833 config->ssl_version = CURL_SSLVERSION_SSLv3;
837 config->ip_version = 4;
841 config->ip_version = 6;
844 /* This makes the FTP sessions use APPE instead of STOR */
845 config->ftp_append = toggle;
848 /* This specifies the User-Agent name */
849 GetStr(&config->useragent, nextarg);
851 case 'b': /* cookie string coming up: */
852 if(nextarg[0] == '@') {
855 else if(strchr(nextarg, '=')) {
856 /* A cookie string must have a =-letter */
857 GetStr(&config->cookie, nextarg);
860 /* We have a cookie file to read from! */
861 GetStr(&config->cookiefile, nextarg);
864 /* use ASCII/text when transferring */
865 config->use_ascii = toggle;
868 /* get the file name to dump all cookies in */
869 GetStr(&config->cookiejar, nextarg);
872 /* This makes us continue an ftp transfer at given position */
873 if(!curlx_strequal(nextarg, "-")) {
874 if(str2offset(&config->resume_from, nextarg))
875 return PARAM_BAD_NUMERIC;
876 config->resume_from_current = FALSE;
879 config->resume_from_current = TRUE;
880 config->resume_from = 0;
882 config->use_resume=TRUE;
887 char *postdata = NULL;
891 if(subletter == 'e') { /* --data-urlencode*/
892 /* [name]=[content], we encode the content part only
895 * Case 2: we first load the file using that name and then encode
898 const char *p = strchr(nextarg, '=');
902 /* there was no '=' letter, check for a '@' instead */
903 p = strchr(nextarg, '@');
905 nlen = p - nextarg; /* length of the name part */
906 is_file = *p++; /* pass the separator */
909 /* neither @ nor =, so no name and it isn't a file */
914 /* a '@' letter, it means that a file name or - (stdin) follows */
916 if(curlx_strequal("-", p)) {
921 file = fopen(p, "rb");
924 "Couldn't read data from file \"%s\", this makes "
925 "an empty POST.\n", nextarg);
928 err = file2memory(&postdata, &size, file);
930 if(file && (file != stdin))
936 GetStr(&postdata, p);
937 size = strlen(postdata);
941 /* no data from the file, point to a zero byte string to make this
942 get sent as a POST anyway */
943 postdata = strdup("");
947 char *enc = curl_easy_escape(config->easy, postdata, (int)size);
948 Curl_safefree(postdata); /* no matter if it worked or not */
950 /* now make a string with the name from above and append the
952 size_t outlen = nlen + strlen(enc) + 2;
953 char *n = malloc(outlen);
958 if(nlen > 0) { /* only append '=' if we have a name */
959 snprintf(n, outlen, "%.*s=%s", nlen, nextarg, enc);
964 size = outlen-2; /* since no '=' was inserted */
973 else if('@' == *nextarg) {
974 /* the data begins with a '@' letter, it means that a file name
975 or - (stdin) follows */
976 nextarg++; /* pass the @ */
978 if(curlx_strequal("-", nextarg)) {
980 if(subletter == 'b') /* forced data-binary */
984 file = fopen(nextarg, "rb");
986 warnf(config, "Couldn't read data from file \"%s\", this makes "
987 "an empty POST.\n", nextarg);
992 err = file2memory(&postdata, &size, file);
994 err = file2string(&postdata, file);
996 size = strlen(postdata);
999 if(file && (file != stdin))
1005 /* no data from the file, point to a zero byte string to make this
1006 get sent as a POST anyway */
1007 postdata=strdup("");
1011 GetStr(&postdata, nextarg);
1012 size = strlen(postdata);
1015 #ifdef CURL_DOES_CONVERSIONS
1016 if(subletter != 'b') { /* NOT forced binary, convert to ASCII */
1017 convert_to_network(postdata, strlen(postdata));
1021 if(config->postfields) {
1022 /* we already have a string, we append this one with a separating
1024 char *oldpost = config->postfields;
1025 curl_off_t oldlen = config->postfieldsize;
1026 curl_off_t newlen = oldlen + size + 2;
1027 config->postfields = malloc((size_t)newlen);
1028 if(!config->postfields) {
1029 Curl_safefree(postdata);
1030 return PARAM_NO_MEM;
1032 memcpy(config->postfields, oldpost, (size_t)oldlen);
1033 /* use byte value 0x26 for '&' to accommodate non-ASCII platforms */
1034 config->postfields[oldlen] = '\x26';
1035 memcpy(&config->postfields[oldlen+1], postdata, size);
1036 config->postfields[oldlen+1+size] = '\0';
1037 Curl_safefree(oldpost);
1038 Curl_safefree(postdata);
1039 config->postfieldsize += size+1;
1042 config->postfields = postdata;
1043 config->postfieldsize = size;
1047 We can't set the request type here, as this data might be used in
1048 a simple GET if -G is used. Already or soon.
1050 if(SetHTTPrequest(HTTPREQ_SIMPLEPOST, &config->httpreq))
1051 return PARAM_BAD_USE;
1055 /* dump-header to given file name */
1056 GetStr(&config->headerfile, nextarg);
1060 char *ptr = strstr(nextarg, ";auto");
1062 /* Automatic referer requested, this may be combined with a
1064 config->autoreferer = TRUE;
1065 *ptr = 0; /* zero terminate here */
1068 config->autoreferer = FALSE;
1069 GetStr(&config->referer, nextarg);
1074 case 'a': /* CA info PEM file */
1075 /* CA info PEM file */
1076 GetStr(&config->cacert, nextarg);
1078 case 'b': /* cert file type */
1079 GetStr(&config->cert_type, nextarg);
1081 case 'c': /* private key file */
1082 GetStr(&config->key, nextarg);
1084 case 'd': /* private key file type */
1085 GetStr(&config->key_type, nextarg);
1087 case 'e': /* private key passphrase */
1088 GetStr(&config->key_passwd, nextarg);
1091 case 'f': /* crypto engine */
1092 GetStr(&config->engine, nextarg);
1093 if(config->engine && curlx_raw_equal(config->engine,"list"))
1094 config->list_engines = TRUE;
1096 case 'g': /* CA info PEM file */
1097 /* CA cert directory */
1098 GetStr(&config->capath, nextarg);
1100 case 'h': /* --pubkey public key file */
1101 GetStr(&config->pubkey, nextarg);
1103 case 'i': /* --hostpubmd5 md5 of the host public key */
1104 GetStr(&config->hostpubmd5, nextarg);
1105 if(!config->hostpubmd5 || strlen(config->hostpubmd5) != 32)
1106 return PARAM_BAD_USE;
1108 case 'j': /* CRL info PEM file */
1110 GetStr(&config->crlfile, nextarg);
1112 case 'k': /* TLS username */
1113 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)
1114 GetStr(&config->tls_username, nextarg);
1116 return PARAM_LIBCURL_DOESNT_SUPPORT;
1118 case 'l': /* TLS password */
1119 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)
1120 GetStr(&config->tls_password, nextarg);
1122 return PARAM_LIBCURL_DOESNT_SUPPORT;
1124 case 'm': /* TLS authentication type */
1125 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP) {
1126 GetStr(&config->tls_authtype, nextarg);
1127 if(!strequal(config->tls_authtype, "SRP"))
1128 return PARAM_LIBCURL_DOESNT_SUPPORT; /* only support TLS-SRP */
1131 return PARAM_LIBCURL_DOESNT_SUPPORT;
1133 default: /* certificate file */
1135 char *ptr = strchr(nextarg, ':');
1136 /* Since we live in a world of weirdness and confusion, the win32
1137 dudes can use : when using drive letters and thus
1138 c:\file:password needs to work. In order not to break
1139 compatibility, we still use : as separator, but we try to detect
1140 when it is used for a file name! On windows. */
1143 (ptr == &nextarg[1]) &&
1144 (nextarg[2] == '\\' || nextarg[2] == '/') &&
1145 (ISALPHA(nextarg[0])) )
1146 /* colon in the second column, followed by a backslash, and the
1147 first character is an alphabetic letter:
1149 this is a drive letter colon */
1150 ptr = strchr(&nextarg[3], ':'); /* find the next one instead */
1153 /* we have a password too */
1156 GetStr(&config->key_passwd, ptr);
1158 GetStr(&config->cert, nextarg);
1164 /* fail hard on errors */
1165 config->failonerror = toggle;
1168 /* "form data" simulation, this is a little advanced so lets do our best
1169 to sort this out slowly and carefully */
1170 if(formparse(config,
1174 (subletter=='s')?TRUE:FALSE)) /* 's' means literal string */
1175 return PARAM_BAD_USE;
1176 if(SetHTTPrequest(config, HTTPREQ_POST, &config->httpreq))
1177 return PARAM_BAD_USE;
1180 case 'g': /* g disables URLglobbing */
1181 config->globoff = toggle;
1184 case 'G': /* HTTP GET */
1185 config->use_httpget = TRUE;
1188 case 'h': /* h for help */
1191 return PARAM_HELP_REQUESTED;
1193 /* we now actually support --no-help too! */
1196 /* A custom header to append to a list */
1197 err = add2list(&config->headers, nextarg);
1202 config->include_headers = toggle; /* include the headers as well in the
1203 general output stream */
1206 config->cookiesession = toggle;
1210 * no_body will imply include_headers later on
1212 config->no_body = toggle;
1213 if(SetHTTPrequest(config,
1214 (config->no_body)?HTTPREQ_HEAD:HTTPREQ_GET,
1216 return PARAM_BAD_USE;
1218 case 'J': /* --remote-header-name */
1219 if(config->include_headers) {
1221 "--include and --remote-header-name cannot be combined.\n");
1222 return PARAM_BAD_USE;
1224 config->content_disposition = toggle;
1226 case 'k': /* allow insecure SSL connects */
1227 config->insecure_ok = toggle;
1229 case 'K': /* parse config file */
1230 if(parseconfig(nextarg, config))
1231 warnf(config, "error trying read config from the '%s' file\n",
1235 config->dirlistonly = toggle; /* only list the names of the FTP dir */
1238 config->followlocation = toggle; /* Follow Location: HTTP headers */
1239 switch (subletter) {
1241 /* Continue to send authentication (user+password) when following
1242 * locations, even when hostname changed */
1243 config->unrestricted_auth = toggle;
1248 /* specified max time */
1249 if(str2num(&config->timeout, nextarg))
1250 return PARAM_BAD_NUMERIC;
1252 case 'M': /* M for manual, huge help */
1253 if(toggle) { /* --no-manual shows no manual... */
1256 return PARAM_HELP_REQUESTED;
1259 "built-in manual was disabled at build-time!\n");
1260 return PARAM_OPTION_UNKNOWN;
1266 case 'o': /* CA info PEM file */
1267 /* use .netrc or URL */
1268 config->netrc_opt = toggle;
1270 case 'e': /* netrc-file */
1271 GetStr(&config->netrc_file, nextarg);
1274 /* pick info from .netrc, if this is used for http, curl will
1275 automatically enfore user+password with the request */
1276 config->netrc = toggle;
1281 /* disable the output I/O buffering. note that the option is called
1282 --buffer but is mostly used in the negative form: --no-buffer */
1284 config->nobuffer = (!toggle)?TRUE:FALSE;
1286 config->nobuffer = toggle;
1288 case 'O': /* --remote-name */
1289 if(subletter == 'a') { /* --remote-name-all */
1290 config->default_node_flags = toggle?GETOUT_USEREMOTE:0;
1294 case 'o': /* --output */
1298 if(config->url_out || ((config->url_out = config->url_list) != NULL)) {
1299 /* there's a node here, if it already is filled-in continue to find
1301 while(config->url_out && (config->url_out->flags&GETOUT_OUTFILE))
1302 config->url_out = config->url_out->next;
1305 /* now there might or might not be an available node to fill in! */
1309 url = config->url_out;
1311 /* there was no free node, create one! */
1312 url = new_getout(config);
1315 /* fill in the outfile */
1317 GetStr(&url->outfile, nextarg);
1318 url->flags &= ~GETOUT_USEREMOTE; /* switch off */
1321 url->outfile = NULL; /* leave it */
1323 url->flags |= GETOUT_USEREMOTE; /* switch on */
1325 url->flags &= ~GETOUT_USEREMOTE; /* switch off */
1327 url->flags |= GETOUT_OUTFILE;
1332 /* This makes the FTP sessions use PORT instead of PASV */
1333 /* use <eth0> or <192.168.10.10> style addresses. Anything except
1334 this will make us try to get the "default" address.
1335 NOTE: this is a changed behaviour since the released 4.1!
1337 GetStr(&config->ftpport, nextarg);
1340 /* proxy tunnel for non-http protocols */
1341 config->proxytunnel = toggle;
1344 case 'q': /* if used first, already taken care of, we do it like
1345 this so we don't cause an error! */
1348 /* QUOTE command to send to FTP server */
1349 switch(nextarg[0]) {
1351 /* prefixed with a dash makes it a POST TRANSFER one */
1353 err = add2list(&config->postquote, nextarg);
1356 /* prefixed with a plus makes it a just-before-transfer one */
1358 err = add2list(&config->prequote, nextarg);
1361 err = add2list(&config->quote, nextarg);
1368 /* Specifying a range WITHOUT A DASH will create an illegal HTTP range
1369 (and won't actually be range by definition). The man page previously
1370 claimed that to be a good way, why this code is added to work-around
1372 if(ISDIGIT(*nextarg) && !strchr(nextarg, '-')) {
1376 "A specified range MUST include at least one dash (-). "
1377 "Appending one for you!\n");
1378 off = curlx_strtoofft(nextarg, NULL, 10);
1379 snprintf(buffer, sizeof(buffer), "%" CURL_FORMAT_CURL_OFF_T "-", off);
1380 Curl_safefree(config->range);
1381 config->range = strdup(buffer);
1384 /* byte range requested */
1386 tmp_range = nextarg;
1387 while(*tmp_range != '\0') {
1388 if(!ISDIGIT(*tmp_range) && *tmp_range != '-' && *tmp_range != ',') {
1389 warnf(config,"Invalid character is found in given range. "
1390 "A specified range MUST have only digits in "
1391 "\'start\'-\'stop\'. The server's response to this "
1392 "request is uncertain.\n");
1397 /* byte range requested */
1398 GetStr(&config->range, nextarg);
1402 /* use remote file's time */
1403 config->remote_time = toggle;
1406 /* don't show progress meter, don't show errors : */
1408 config->mute = config->noprogress = TRUE;
1410 config->mute = config->noprogress = FALSE;
1411 config->showerror = (!toggle)?TRUE:FALSE; /* toggle off */
1415 config->showerror = toggle; /* toggle on if used with -s */
1418 /* Telnet options */
1419 err = add2list(&config->telnet_options, nextarg);
1424 /* we are uploading */
1427 if(config->url_out || ((config->url_out = config->url_list) != NULL)) {
1428 /* there's a node here, if it already is filled-in continue to find
1430 while(config->url_out && (config->url_out->flags&GETOUT_UPLOAD))
1431 config->url_out = config->url_out->next;
1434 /* now there might or might not be an available node to fill in! */
1438 url = config->url_out;
1440 /* there was no free node, create one! */
1441 url = new_getout(config);
1444 url->flags |= GETOUT_UPLOAD; /* mark -T used */
1446 url->flags |= GETOUT_NOUPLOAD;
1448 /* "-" equals stdin, but keep the string around for now */
1449 GetStr(&url->infile, nextarg);
1456 GetStr(&config->userpwd, nextarg);
1458 checkpasswd("host", &config->userpwd);
1461 /* Proxy user:password */
1462 GetStr(&config->proxyuserpwd, nextarg);
1464 checkpasswd("proxy", &config->proxyuserpwd);
1468 /* the '%' thing here will cause the trace get sent to stderr */
1469 Curl_safefree(config->trace_dump);
1470 config->trace_dump = strdup("%");
1471 if(config->tracetype && (config->tracetype != TRACE_PLAIN))
1473 "-v, --verbose overrides an earlier trace/verbose option\n");
1474 config->tracetype = TRACE_PLAIN;
1477 /* verbose is disabled here */
1478 config->tracetype = TRACE_NONE;
1482 const char *const *proto;
1485 /* --no-version yields no output! */
1488 printf(CURL_ID "%s\n", curl_version());
1489 if(curlinfo->protocols) {
1490 printf("Protocols: ");
1491 for(proto = curlinfo->protocols; *proto; ++proto) {
1492 printf("%s ", *proto);
1494 puts(""); /* newline */
1496 if(curlinfo->features) {
1498 printf("Features: ");
1499 for(i = 0; i < sizeof(feats)/sizeof(feats[0]); i++) {
1500 if(curlinfo->features & feats[i].bitmask)
1501 printf("%s ", feats[i].name);
1503 puts(""); /* newline */
1506 return PARAM_HELP_REQUESTED;
1508 /* get the output string */
1509 if('@' == *nextarg) {
1510 /* the data begins with a '@' letter, it means that a file name
1511 or - (stdin) follows */
1514 nextarg++; /* pass the @ */
1515 if(curlx_strequal("-", nextarg)) {
1521 file = fopen(nextarg, "r");
1523 err = file2string(&config->writeout, file);
1524 if(file && (file != stdin))
1528 if(!config->writeout)
1529 warnf(config, "Failed to read %s", fname);
1532 GetStr(&config->writeout, nextarg);
1536 GetStr(&config->proxy, nextarg);
1537 config->proxyver = CURLPROXY_HTTP;
1540 /* set custom request */
1541 GetStr(&config->customrequest, nextarg);
1544 /* low speed time */
1545 if(str2num(&config->low_speed_time, nextarg))
1546 return PARAM_BAD_NUMERIC;
1547 if(!config->low_speed_limit)
1548 config->low_speed_limit = 1;
1551 /* low speed limit */
1552 if(str2num(&config->low_speed_limit, nextarg))
1553 return PARAM_BAD_NUMERIC;
1554 if(!config->low_speed_time)
1555 config->low_speed_time = 30;
1557 case 'z': /* time condition coming up */
1562 /* If-Modified-Since: (section 14.28 in RFC2068) */
1563 config->timecond = CURL_TIMECOND_IFMODSINCE;
1566 /* If-Unmodified-Since: (section 14.24 in RFC2068) */
1567 config->timecond = CURL_TIMECOND_IFUNMODSINCE;
1571 /* Last-Modified: (section 14.29 in RFC2068) */
1572 config->timecond = CURL_TIMECOND_LASTMOD;
1577 config->condtime=curl_getdate(nextarg, &now);
1578 if(-1 == (int)config->condtime) {
1579 /* now let's see if it is a file name to get the time from instead! */
1580 struct_stat statbuf;
1581 if(-1 == stat(nextarg, &statbuf)) {
1582 /* failed, remove time condition */
1583 config->timecond = CURL_TIMECOND_NONE;
1585 "Illegal date format for -z, --timecond (and not "
1586 "a file name). Disabling time condition. "
1587 "See curl_getdate(3) for valid date syntax.\n");
1590 /* pull the time out from the file */
1591 config->condtime = statbuf.st_mtime;
1595 default: /* unknown flag */
1596 return PARAM_OPTION_UNKNOWN;
1600 } while(!longopt && !singleopt && *++parse && !*usedarg);