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 "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_msgs.h"
43 #include "tool_paramhlp.h"
44 #include "tool_parsecfg.h"
45 #include "tool_version.h"
46 #include "tool_metalink.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; \
66 const char *letter; /* short name option */
67 const char *lname; /* long name option */
68 bool extraparam; /* whether it takes an additional argument */
71 static const struct LongShort aliases[]= {
72 /* all these ones, starting with "*" or "$" as a short-option have *no*
73 short option to mention. */
75 {"*a", "random-file", TRUE},
76 {"*b", "egd-file", TRUE},
77 {"*c", "connect-timeout", TRUE},
78 {"*d", "ciphers", TRUE},
79 {"*e", "disable-epsv", FALSE},
80 {"*E", "epsv", FALSE},
81 /* 'epsv' made like this to make --no-epsv and --epsv to work
82 although --disable-epsv is the documented option */
83 #ifdef USE_ENVIRONMENT
84 {"*f", "environment", FALSE},
86 {"*g", "trace", TRUE},
87 {"*h", "trace-ascii", TRUE},
88 {"*i", "limit-rate", TRUE},
89 {"*j", "compressed", FALSE},
90 {"*J", "tr-encoding", FALSE},
91 {"*k", "digest", FALSE},
92 {"*l", "negotiate", FALSE},
93 {"*m", "ntlm", FALSE},
94 {"*M", "ntlm-wb", FALSE},
95 {"*n", "basic", FALSE},
96 {"*o", "anyauth", FALSE},
98 {"*p", "wdebug", FALSE},
100 {"*q", "ftp-create-dirs", FALSE},
101 {"*r", "create-dirs", FALSE},
102 {"*s", "max-redirs", TRUE},
103 {"*t", "proxy-ntlm", FALSE},
104 {"*u", "crlf", FALSE},
105 {"*v", "stderr", TRUE},
106 {"*w", "interface", TRUE},
107 {"*x", "krb" , TRUE},
108 {"*x", "krb4" , TRUE},
109 /* 'krb4' is the previous name */
110 {"*y", "max-filesize", TRUE},
111 {"*z", "disable-eprt", FALSE},
112 {"*Z", "eprt", FALSE},
113 /* 'eprt' made like this to make --no-eprt and --eprt to work
114 although --disable-eprt is the documented option */
115 {"$a", "ftp-ssl", FALSE},
116 /* 'ftp-ssl' deprecated name since 7.20.0 */
117 {"$a", "ssl", FALSE},
118 /* 'ssl' new option name in 7.20.0, previously this was ftp-ssl */
119 {"$b", "ftp-pasv", FALSE},
120 {"$c", "socks5", TRUE},
121 {"$c", "socks", TRUE},
122 /* 'socks' is how the option once was documented but we prefer
123 the --socks5 version for explicit version */
124 {"$d", "tcp-nodelay", FALSE},
125 {"$e", "proxy-digest", FALSE},
126 {"$f", "proxy-basic", FALSE},
127 {"$g", "retry", TRUE},
128 {"$h", "retry-delay", TRUE},
129 {"$i", "retry-max-time", TRUE},
130 {"$k", "proxy-negotiate", FALSE},
131 {"$m", "ftp-account", TRUE},
132 {"$n", "proxy-anyauth", FALSE},
133 {"$o", "trace-time", FALSE},
134 {"$p", "ignore-content-length", FALSE},
135 {"$q", "ftp-skip-pasv-ip", FALSE},
136 {"$r", "ftp-method", TRUE},
137 {"$s", "local-port", TRUE},
138 {"$t", "socks4", TRUE},
139 {"$T", "socks4a", TRUE},
140 {"$u", "ftp-alternative-to-user", TRUE},
141 {"$v", "ftp-ssl-reqd", FALSE},
142 /* 'ftp-ssl-reqd' deprecated name since 7.20.0 */
143 {"$v", "ssl-reqd", FALSE},
144 /* 'ssl-reqd' new in 7.20.0, previously this was ftp-ssl-reqd */
145 {"$w", "sessionid", FALSE},
146 /* ¡sessionid' listed as --no-sessionid in the help */
147 {"$x", "ftp-ssl-control", FALSE},
148 {"$y", "ftp-ssl-ccc", FALSE},
149 {"$j", "ftp-ssl-ccc-mode", TRUE},
150 {"$z", "libcurl", TRUE},
151 {"$#", "raw", FALSE},
152 {"$0", "post301", FALSE},
153 {"$1", "keepalive", FALSE},
154 /* 'keepalive' listed as --no-keepalive in the help */
155 {"$2", "socks5-hostname", TRUE},
156 {"$3", "keepalive-time", TRUE},
157 {"$4", "post302", FALSE},
158 {"$5", "noproxy", TRUE},
159 #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
160 {"$6", "socks5-gssapi-service", TRUE},
161 {"$7", "socks5-gssapi-nec", FALSE},
163 {"$8", "proxy1.0", TRUE},
164 {"$9", "tftp-blksize", TRUE},
165 {"$A", "mail-from", TRUE},
166 {"$B", "mail-rcpt", TRUE},
167 {"$C", "ftp-pret", FALSE},
168 {"$D", "proto", TRUE},
169 {"$E", "proto-redir", TRUE},
170 {"$F", "resolve", TRUE},
171 {"$G", "delegation", TRUE},
172 {"$H", "mail-auth", TRUE},
173 {"$I", "post303", FALSE},
174 {"$J", "metalink", TRUE},
175 {"0", "http1.0", FALSE},
176 {"1", "tlsv1", FALSE},
177 {"2", "sslv2", FALSE},
178 {"3", "sslv3", FALSE},
179 {"4", "ipv4", FALSE},
180 {"6", "ipv6", FALSE},
181 {"a", "append", FALSE},
182 {"A", "user-agent", TRUE},
183 {"b", "cookie", TRUE},
184 {"B", "use-ascii", FALSE},
185 {"c", "cookie-jar", TRUE},
186 {"C", "continue-at", TRUE},
188 {"da", "data-ascii", TRUE},
189 {"db", "data-binary", TRUE},
190 {"de", "data-urlencode", TRUE},
191 {"D", "dump-header", TRUE},
192 {"e", "referer", TRUE},
194 {"Ea", "cacert", TRUE},
195 {"Eb", "cert-type", TRUE},
197 {"Ed", "key-type", TRUE},
198 {"Ee", "pass", TRUE},
199 {"Ef", "engine", TRUE},
200 {"Eg", "capath ", TRUE},
201 {"Eh", "pubkey", TRUE},
202 {"Ei", "hostpubmd5", TRUE},
203 {"Ej", "crlfile", TRUE},
204 {"Ek", "tlsuser", TRUE},
205 {"El", "tlspassword", TRUE},
206 {"Em", "tlsauthtype", TRUE},
207 {"En", "ssl-allow-beast", FALSE},
208 {"f", "fail", FALSE},
210 {"Fs", "form-string", TRUE},
211 {"g", "globoff", FALSE},
213 {"h", "help", FALSE},
214 {"H", "header", TRUE},
215 {"i", "include", FALSE},
216 {"I", "head", FALSE},
217 {"j", "junk-session-cookies", FALSE},
218 {"J", "remote-header-name", FALSE},
219 {"k", "insecure", FALSE},
220 {"K", "config", TRUE},
221 {"l", "list-only", FALSE},
222 {"L", "location", FALSE},
223 {"Lt", "location-trusted", FALSE},
224 {"m", "max-time", TRUE},
225 {"M", "manual", FALSE},
226 {"n", "netrc", FALSE},
227 {"no", "netrc-optional", FALSE},
228 {"ne", "netrc-file", TRUE},
229 {"N", "buffer", FALSE},
230 /* 'buffer' listed as --no-buffer in the help */
231 {"o", "output", TRUE},
232 {"O", "remote-name", FALSE},
233 {"Oa", "remote-name-all", FALSE},
234 {"p", "proxytunnel", FALSE},
235 {"P", "ftpport", TRUE},
236 /* 'ftpport' old version */
237 {"P", "ftp-port", TRUE},
238 {"q", "disable", FALSE},
239 {"Q", "quote", TRUE},
240 {"r", "range", TRUE},
241 {"R", "remote-time", FALSE},
242 {"s", "silent", FALSE},
243 {"S", "show-error", FALSE},
244 {"t", "telnet-options", TRUE},
245 /* 'telnet-options' documented as telnet-option */
246 {"T", "upload-file", TRUE},
248 {"U", "proxy-user", TRUE},
249 {"v", "verbose", FALSE},
250 {"V", "version", FALSE},
251 {"w", "write-out", TRUE},
252 {"x", "proxy", TRUE},
253 {"X", "request", TRUE},
254 {"X", "http-request", TRUE},
255 /* 'http-request' OBSOLETE VERSION */
256 {"Y", "speed-limit", TRUE},
257 {"y", "speed-time", TRUE},
258 {"z", "time-cond", TRUE},
259 {"#", "progress-bar", FALSE},
260 {"~", "xattr", FALSE},
268 static const struct feat feats[] = {
269 {"AsynchDNS", CURL_VERSION_ASYNCHDNS},
270 {"Debug", CURL_VERSION_DEBUG},
271 {"TrackMemory", CURL_VERSION_CURLDEBUG},
272 {"GSS-Negotiate", CURL_VERSION_GSSNEGOTIATE},
273 {"IDN", CURL_VERSION_IDN},
274 {"IPv6", CURL_VERSION_IPV6},
275 {"Largefile", CURL_VERSION_LARGEFILE},
276 {"NTLM", CURL_VERSION_NTLM},
277 {"NTLM_WB", CURL_VERSION_NTLM_WB},
278 {"SPNEGO", CURL_VERSION_SPNEGO},
279 {"SSL", CURL_VERSION_SSL},
280 {"SSPI", CURL_VERSION_SSPI},
281 {"krb4", CURL_VERSION_KERBEROS4},
282 {"libz", CURL_VERSION_LIBZ},
283 {"CharConv", CURL_VERSION_CONV},
284 {"TLS-SRP", CURL_VERSION_TLSAUTH_SRP}
287 ParameterError getparameter(char *flag, /* f or -long-flag */
288 char *nextarg, /* NULL if unset */
289 bool *usedarg, /* set to TRUE if the arg
291 struct Configurable *config)
294 char subletter = '\0'; /* subletters can only occur on long options */
296 const char *parse = NULL;
300 bool longopt = FALSE;
301 bool singleopt = FALSE; /* when true means '-o foo' used '-ofoo' */
303 bool toggle = TRUE; /* how to switch boolean options, on or off. Controlled
304 by using --OPTION or --no-OPTION */
307 if(('-' != flag[0]) ||
308 (('-' == flag[0]) && ('-' == flag[1]))) {
309 /* this should be a long name */
310 char *word = ('-' == flag[0]) ? flag+2 : flag;
311 size_t fnam = strlen(word);
314 if(!strncmp(word, "no-", 3)) {
315 /* disable this option but ignore the "no-" part when looking for it */
320 for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) {
321 if(curlx_strnequal(aliases[j].lname, word, fnam)) {
324 if(curlx_raw_equal(aliases[j].lname, word)) {
325 parse = aliases[j].letter;
327 numhits = 1; /* a single unique hit */
330 parse = aliases[j].letter;
335 /* this is at least the second match! */
336 return PARAM_OPTION_AMBIGUOUS;
339 return PARAM_OPTION_UNKNOWN;
343 flag++; /* prefixed with one dash, pass it */
349 /* we can loop here if we have multiple single-letters */
353 letter = (char)*parse;
362 subletter = parse[1];
364 *usedarg = FALSE; /* default is that we don't use the arg */
367 for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) {
368 if(letter == aliases[j].letter[0]) {
374 return PARAM_OPTION_UNKNOWN;
378 if(aliases[hit].extraparam) {
379 /* this option requires an extra parameter */
380 if(!longopt && parse[1]) {
381 nextarg = (char *)&parse[1]; /* this is the actual extra parameter */
382 singleopt = TRUE; /* don't loop anymore after this */
385 return PARAM_REQUIRES_PARAMETER;
387 *usedarg = TRUE; /* mark it as used */
391 case '*': /* options without a short option */
393 case 'a': /* random-file */
394 GetStr(&config->random_file, nextarg);
396 case 'b': /* egd-file */
397 GetStr(&config->egd_file, nextarg);
399 case 'c': /* connect-timeout */
400 if(str2num(&config->connecttimeout, nextarg))
401 return PARAM_BAD_NUMERIC;
403 case 'd': /* ciphers */
404 GetStr(&config->cipher_list, nextarg);
406 case 'e': /* --disable-epsv */
407 config->disable_epsv = toggle;
409 case 'E': /* --epsv */
410 config->disable_epsv = (!toggle)?TRUE:FALSE;
412 #ifdef USE_ENVIRONMENT
414 config->writeenv = toggle;
417 case 'g': /* --trace */
418 GetStr(&config->trace_dump, nextarg);
419 if(config->tracetype && (config->tracetype != TRACE_BIN))
420 warnf(config, "--trace overrides an earlier trace/verbose option\n");
421 config->tracetype = TRACE_BIN;
423 case 'h': /* --trace-ascii */
424 GetStr(&config->trace_dump, nextarg);
425 if(config->tracetype && (config->tracetype != TRACE_ASCII))
427 "--trace-ascii overrides an earlier trace/verbose option\n");
428 config->tracetype = TRACE_ASCII;
430 case 'i': /* --limit-rate */
432 /* We support G, M, K too */
434 curl_off_t value = curlx_strtoofft(nextarg, &unit, 0);
438 else if(strlen(unit) > 1)
439 unit = (char *)"w"; /* unsupported */
444 value *= 1024*1024*1024;
456 /* for plain bytes, leave as-is */
459 warnf(config, "unsupported rate unit. Use G, M, K or B!\n");
460 return PARAM_BAD_USE;
462 config->recvpersecond = value;
463 config->sendpersecond = value;
467 case 'j': /* --compressed */
468 if(toggle && !(curlinfo->features & CURL_VERSION_LIBZ))
469 return PARAM_LIBCURL_DOESNT_SUPPORT;
470 config->encoding = toggle;
473 case 'J': /* --tr-encoding */
474 config->tr_encoding = toggle;
477 case 'k': /* --digest */
479 config->authtype |= CURLAUTH_DIGEST;
481 config->authtype &= ~CURLAUTH_DIGEST;
484 case 'l': /* --negotiate */
486 if(curlinfo->features & CURL_VERSION_GSSNEGOTIATE)
487 config->authtype |= CURLAUTH_GSSNEGOTIATE;
489 return PARAM_LIBCURL_DOESNT_SUPPORT;
492 config->authtype &= ~CURLAUTH_GSSNEGOTIATE;
495 case 'm': /* --ntlm */
497 if(curlinfo->features & CURL_VERSION_NTLM)
498 config->authtype |= CURLAUTH_NTLM;
500 return PARAM_LIBCURL_DOESNT_SUPPORT;
503 config->authtype &= ~CURLAUTH_NTLM;
506 case 'M': /* --ntlm-wb */
508 if(curlinfo->features & CURL_VERSION_NTLM_WB)
509 config->authtype |= CURLAUTH_NTLM_WB;
511 return PARAM_LIBCURL_DOESNT_SUPPORT;
514 config->authtype &= ~CURLAUTH_NTLM_WB;
517 case 'n': /* --basic for completeness */
519 config->authtype |= CURLAUTH_BASIC;
521 config->authtype &= ~CURLAUTH_BASIC;
524 case 'o': /* --anyauth, let libcurl pick it */
526 config->authtype = CURLAUTH_ANY;
527 /* --no-anyauth simply doesn't touch it */
531 case 'p': /* --wdebug */
535 case 'q': /* --ftp-create-dirs */
536 config->ftp_create_dirs = toggle;
539 case 'r': /* --create-dirs */
540 config->create_dirs = TRUE;
543 case 's': /* --max-redirs */
544 /* specified max no of redirects (http(s)) */
545 if(str2num(&config->maxredirs, nextarg))
546 return PARAM_BAD_NUMERIC;
549 case 't': /* --proxy-ntlm */
550 if(curlinfo->features & CURL_VERSION_NTLM)
551 config->proxyntlm = toggle;
553 return PARAM_LIBCURL_DOESNT_SUPPORT;
556 case 'u': /* --crlf */
557 /* LF -> CRLF conversion? */
561 case 'v': /* --stderr */
562 if(strcmp(nextarg, "-")) {
563 FILE *newfile = fopen(nextarg, "wt");
565 warnf(config, "Failed to open %s!\n", nextarg);
567 if(config->errors_fopened)
568 fclose(config->errors);
569 config->errors = newfile;
570 config->errors_fopened = TRUE;
574 config->errors = stdout;
576 case 'w': /* --interface */
578 GetStr(&config->iface, nextarg);
580 case 'x': /* --krb */
581 /* kerberos level string */
582 if(curlinfo->features & (CURL_VERSION_KERBEROS4 |
583 CURL_VERSION_GSSNEGOTIATE))
584 GetStr(&config->krblevel, nextarg);
586 return PARAM_LIBCURL_DOESNT_SUPPORT;
588 case 'y': /* --max-filesize */
589 if(str2offset(&config->max_filesize, nextarg))
590 return PARAM_BAD_NUMERIC;
592 case 'z': /* --disable-eprt */
593 config->disable_eprt = toggle;
595 case 'Z': /* --eprt */
596 config->disable_eprt = (!toggle)?TRUE:FALSE;
599 default: /* the URL! */
602 if(config->url_get || ((config->url_get = config->url_list) != NULL)) {
603 /* there's a node here, if it already is filled-in continue to find
605 while(config->url_get && (config->url_get->flags & GETOUT_URL))
606 config->url_get = config->url_get->next;
609 /* now there might or might not be an available node to fill in! */
613 url = config->url_get;
615 /* there was no free node, create one! */
616 url = new_getout(config);
621 /* fill in the URL */
622 GetStr(&url->url, nextarg);
623 url->flags |= GETOUT_URL;
628 case '$': /* more options without a short option */
630 case 'a': /* --ftp-ssl */
631 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
632 return PARAM_LIBCURL_DOESNT_SUPPORT;
633 config->ftp_ssl = toggle;
635 case 'b': /* --ftp-pasv */
636 Curl_safefree(config->ftpport);
638 case 'c': /* --socks5 specifies a socks5 proxy to use, and resolves
639 the name locally and passes on the resolved address */
640 GetStr(&config->socksproxy, nextarg);
641 config->socksver = CURLPROXY_SOCKS5;
643 case 't': /* --socks4 specifies a socks4 proxy to use */
644 GetStr(&config->socksproxy, nextarg);
645 config->socksver = CURLPROXY_SOCKS4;
647 case 'T': /* --socks4a specifies a socks4a proxy to use */
648 GetStr(&config->socksproxy, nextarg);
649 config->socksver = CURLPROXY_SOCKS4A;
651 case '2': /* --socks5-hostname specifies a socks5 proxy and enables name
652 resolving with the proxy */
653 GetStr(&config->socksproxy, nextarg);
654 config->socksver = CURLPROXY_SOCKS5_HOSTNAME;
656 case 'd': /* --tcp-nodelay option */
657 config->tcp_nodelay = toggle;
659 case 'e': /* --proxy-digest */
660 config->proxydigest = toggle;
662 case 'f': /* --proxy-basic */
663 config->proxybasic = toggle;
665 case 'g': /* --retry */
666 if(str2num(&config->req_retry, nextarg))
667 return PARAM_BAD_NUMERIC;
669 case 'h': /* --retry-delay */
670 if(str2num(&config->retry_delay, nextarg))
671 return PARAM_BAD_NUMERIC;
673 case 'i': /* --retry-max-time */
674 if(str2num(&config->retry_maxtime, nextarg))
675 return PARAM_BAD_NUMERIC;
678 case 'k': /* --proxy-negotiate */
679 if(curlinfo->features & CURL_VERSION_GSSNEGOTIATE)
680 config->proxynegotiate = toggle;
682 return PARAM_LIBCURL_DOESNT_SUPPORT;
684 case 'm': /* --ftp-account */
685 GetStr(&config->ftp_account, nextarg);
687 case 'n': /* --proxy-anyauth */
688 config->proxyanyauth = toggle;
690 case 'o': /* --trace-time */
691 config->tracetime = toggle;
693 case 'p': /* --ignore-content-length */
694 config->ignorecl = toggle;
696 case 'q': /* --ftp-skip-pasv-ip */
697 config->ftp_skip_ip = toggle;
699 case 'r': /* --ftp-method (undocumented at this point) */
700 config->ftp_filemethod = ftpfilemethod(config, nextarg);
702 case 's': /* --local-port */
703 rc = sscanf(nextarg, "%d - %d",
705 &config->localportrange);
707 return PARAM_BAD_USE;
709 config->localportrange = 1; /* default number of ports to try */
711 config->localportrange -= config->localport;
712 if(config->localportrange < 1) {
713 warnf(config, "bad range input\n");
714 return PARAM_BAD_USE;
718 case 'u': /* --ftp-alternative-to-user */
719 GetStr(&config->ftp_alternative_to_user, nextarg);
721 case 'v': /* --ftp-ssl-reqd */
722 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
723 return PARAM_LIBCURL_DOESNT_SUPPORT;
724 config->ftp_ssl_reqd = toggle;
726 case 'w': /* --no-sessionid */
727 config->disable_sessionid = (!toggle)?TRUE:FALSE;
729 case 'x': /* --ftp-ssl-control */
730 if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
731 return PARAM_LIBCURL_DOESNT_SUPPORT;
732 config->ftp_ssl_control = toggle;
734 case 'y': /* --ftp-ssl-ccc */
735 config->ftp_ssl_ccc = toggle;
736 if(!config->ftp_ssl_ccc_mode)
737 config->ftp_ssl_ccc_mode = CURLFTPSSL_CCC_PASSIVE;
739 case 'j': /* --ftp-ssl-ccc-mode */
740 config->ftp_ssl_ccc = TRUE;
741 config->ftp_ssl_ccc_mode = ftpcccmethod(config, nextarg);
743 case 'z': /* --libcurl */
744 #ifdef CURL_DISABLE_LIBCURL_OPTION
746 "--libcurl option was disabled at build-time!\n");
747 return PARAM_OPTION_UNKNOWN;
749 GetStr(&config->libcurl, nextarg);
752 case '#': /* --raw */
753 config->raw = toggle;
755 case '0': /* --post301 */
756 config->post301 = toggle;
758 case '1': /* --no-keepalive */
759 config->nokeepalive = (!toggle)?TRUE:FALSE;
761 case '3': /* --keepalive-time */
762 if(str2num(&config->alivetime, nextarg))
763 return PARAM_BAD_NUMERIC;
765 case '4': /* --post302 */
766 config->post302 = toggle;
768 case 'I': /* --post303 */
769 config->post303 = toggle;
771 case '5': /* --noproxy */
772 /* This specifies the noproxy list */
773 GetStr(&config->noproxy, nextarg);
775 #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
776 case '6': /* --socks5-gssapi-service */
777 GetStr(&config->socks5_gssapi_service, nextarg);
779 case '7': /* --socks5-gssapi-nec*/
780 config->socks5_gssapi_nec = TRUE;
783 case '8': /* --proxy1.0 */
785 GetStr(&config->proxy, nextarg);
786 config->proxyver = CURLPROXY_HTTP_1_0;
788 case '9': /* --tftp-blksize */
789 str2num(&config->tftp_blksize, nextarg);
791 case 'A': /* --mail-from */
792 GetStr(&config->mail_from, nextarg);
794 case 'B': /* --mail-rcpt */
795 /* append receiver to a list */
796 err = add2list(&config->mail_rcpt, nextarg);
800 case 'C': /* --ftp-pret */
801 config->ftp_pret = toggle;
803 case 'D': /* --proto */
804 config->proto_present = TRUE;
805 if(proto2num(config, &config->proto, nextarg))
806 return PARAM_BAD_USE;
808 case 'E': /* --proto-redir */
809 config->proto_redir_present = TRUE;
810 if(proto2num(config, &config->proto_redir, nextarg))
811 return PARAM_BAD_USE;
813 case 'F': /* --resolve */
814 err = add2list(&config->resolve, nextarg);
818 case 'G': /* --delegation LEVEL */
819 config->gssapi_delegation = delegation(config, nextarg);
821 case 'H': /* --mail-auth */
822 GetStr(&config->mail_auth, nextarg);
824 case 'J': /* --metalink */
827 if(parse_metalink(config, nextarg) == -1) {
828 warnf(config, "Could not parse Metalink file: %s\n", nextarg);
829 /* TODO Is PARAM_BAD_USE appropriate here? */
830 return PARAM_BAD_USE;
833 warnf(config, "--metalink option is ignored because the binary is "
834 "built without the Metalink support.\n");
840 case '#': /* --progress-bar */
842 config->progressmode = CURL_PROGRESS_BAR;
844 config->progressmode = CURL_PROGRESS_STATS;
846 case '~': /* --xattr */
847 config->xattr = toggle;
850 /* HTTP version 1.0 */
851 config->httpversion = CURL_HTTP_VERSION_1_0;
855 config->ssl_version = CURL_SSLVERSION_TLSv1;
859 config->ssl_version = CURL_SSLVERSION_SSLv2;
863 config->ssl_version = CURL_SSLVERSION_SSLv3;
867 config->ip_version = 4;
871 config->ip_version = 6;
874 /* This makes the FTP sessions use APPE instead of STOR */
875 config->ftp_append = toggle;
878 /* This specifies the User-Agent name */
879 GetStr(&config->useragent, nextarg);
881 case 'b': /* cookie string coming up: */
882 if(nextarg[0] == '@') {
885 else if(strchr(nextarg, '=')) {
886 /* A cookie string must have a =-letter */
887 GetStr(&config->cookie, nextarg);
890 /* We have a cookie file to read from! */
891 GetStr(&config->cookiefile, nextarg);
894 /* use ASCII/text when transferring */
895 config->use_ascii = toggle;
898 /* get the file name to dump all cookies in */
899 GetStr(&config->cookiejar, nextarg);
902 /* This makes us continue an ftp transfer at given position */
903 if(!curlx_strequal(nextarg, "-")) {
904 if(str2offset(&config->resume_from, nextarg))
905 return PARAM_BAD_NUMERIC;
906 config->resume_from_current = FALSE;
909 config->resume_from_current = TRUE;
910 config->resume_from = 0;
912 config->use_resume=TRUE;
917 char *postdata = NULL;
921 if(subletter == 'e') { /* --data-urlencode*/
922 /* [name]=[content], we encode the content part only
925 * Case 2: we first load the file using that name and then encode
928 const char *p = strchr(nextarg, '=');
932 /* there was no '=' letter, check for a '@' instead */
933 p = strchr(nextarg, '@');
935 nlen = p - nextarg; /* length of the name part */
936 is_file = *p++; /* pass the separator */
939 /* neither @ nor =, so no name and it isn't a file */
944 /* a '@' letter, it means that a file name or - (stdin) follows */
946 if(curlx_strequal("-", p)) {
951 file = fopen(p, "rb");
954 "Couldn't read data from file \"%s\", this makes "
955 "an empty POST.\n", nextarg);
958 err = file2memory(&postdata, &size, file);
960 if(file && (file != stdin))
966 GetStr(&postdata, p);
968 size = strlen(postdata);
972 /* no data from the file, point to a zero byte string to make this
973 get sent as a POST anyway */
974 postdata = strdup("");
980 char *enc = curl_easy_escape(config->easy, postdata, (int)size);
981 Curl_safefree(postdata); /* no matter if it worked or not */
983 /* now make a string with the name from above and append the
985 size_t outlen = nlen + strlen(enc) + 2;
986 char *n = malloc(outlen);
991 if(nlen > 0) { /* only append '=' if we have a name */
992 snprintf(n, outlen, "%.*s=%s", nlen, nextarg, enc);
997 size = outlen-2; /* since no '=' was inserted */
1003 return PARAM_NO_MEM;
1006 else if('@' == *nextarg) {
1007 /* the data begins with a '@' letter, it means that a file name
1008 or - (stdin) follows */
1009 nextarg++; /* pass the @ */
1011 if(curlx_strequal("-", nextarg)) {
1013 if(subletter == 'b') /* forced data-binary */
1017 file = fopen(nextarg, "rb");
1019 warnf(config, "Couldn't read data from file \"%s\", this makes "
1020 "an empty POST.\n", nextarg);
1023 if(subletter == 'b')
1025 err = file2memory(&postdata, &size, file);
1027 err = file2string(&postdata, file);
1029 size = strlen(postdata);
1032 if(file && (file != stdin))
1038 /* no data from the file, point to a zero byte string to make this
1039 get sent as a POST anyway */
1040 postdata = strdup("");
1042 return PARAM_NO_MEM;
1046 GetStr(&postdata, nextarg);
1048 size = strlen(postdata);
1051 #ifdef CURL_DOES_CONVERSIONS
1052 if(subletter != 'b') {
1053 /* NOT forced binary, convert to ASCII */
1054 if(convert_to_network(postdata, strlen(postdata))) {
1055 Curl_safefree(postdata);
1056 return PARAM_NO_MEM;
1061 if(config->postfields) {
1062 /* we already have a string, we append this one with a separating
1064 char *oldpost = config->postfields;
1065 curl_off_t oldlen = config->postfieldsize;
1066 curl_off_t newlen = oldlen + size + 2;
1067 config->postfields = malloc((size_t)newlen);
1068 if(!config->postfields) {
1069 Curl_safefree(oldpost);
1070 Curl_safefree(postdata);
1071 return PARAM_NO_MEM;
1073 memcpy(config->postfields, oldpost, (size_t)oldlen);
1074 /* use byte value 0x26 for '&' to accommodate non-ASCII platforms */
1075 config->postfields[oldlen] = '\x26';
1076 memcpy(&config->postfields[oldlen+1], postdata, size);
1077 config->postfields[oldlen+1+size] = '\0';
1078 Curl_safefree(oldpost);
1079 Curl_safefree(postdata);
1080 config->postfieldsize += size+1;
1083 config->postfields = postdata;
1084 config->postfieldsize = size;
1088 We can't set the request type here, as this data might be used in
1089 a simple GET if -G is used. Already or soon.
1091 if(SetHTTPrequest(HTTPREQ_SIMPLEPOST, &config->httpreq)) {
1092 Curl_safefree(postdata);
1093 return PARAM_BAD_USE;
1098 /* dump-header to given file name */
1099 GetStr(&config->headerfile, nextarg);
1103 char *ptr = strstr(nextarg, ";auto");
1105 /* Automatic referer requested, this may be combined with a
1107 config->autoreferer = TRUE;
1108 *ptr = 0; /* zero terminate here */
1111 config->autoreferer = FALSE;
1112 GetStr(&config->referer, nextarg);
1117 case 'a': /* CA info PEM file */
1118 /* CA info PEM file */
1119 GetStr(&config->cacert, nextarg);
1121 case 'b': /* cert file type */
1122 GetStr(&config->cert_type, nextarg);
1124 case 'c': /* private key file */
1125 GetStr(&config->key, nextarg);
1127 case 'd': /* private key file type */
1128 GetStr(&config->key_type, nextarg);
1130 case 'e': /* private key passphrase */
1131 GetStr(&config->key_passwd, nextarg);
1134 case 'f': /* crypto engine */
1135 GetStr(&config->engine, nextarg);
1136 if(config->engine && curlx_raw_equal(config->engine,"list"))
1137 config->list_engines = TRUE;
1139 case 'g': /* CA info PEM file */
1140 /* CA cert directory */
1141 GetStr(&config->capath, nextarg);
1143 case 'h': /* --pubkey public key file */
1144 GetStr(&config->pubkey, nextarg);
1146 case 'i': /* --hostpubmd5 md5 of the host public key */
1147 GetStr(&config->hostpubmd5, nextarg);
1148 if(!config->hostpubmd5 || strlen(config->hostpubmd5) != 32)
1149 return PARAM_BAD_USE;
1151 case 'j': /* CRL info PEM file */
1153 GetStr(&config->crlfile, nextarg);
1155 case 'k': /* TLS username */
1156 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)
1157 GetStr(&config->tls_username, nextarg);
1159 return PARAM_LIBCURL_DOESNT_SUPPORT;
1161 case 'l': /* TLS password */
1162 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)
1163 GetStr(&config->tls_password, nextarg);
1165 return PARAM_LIBCURL_DOESNT_SUPPORT;
1167 case 'm': /* TLS authentication type */
1168 if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP) {
1169 GetStr(&config->tls_authtype, nextarg);
1170 if(!strequal(config->tls_authtype, "SRP"))
1171 return PARAM_LIBCURL_DOESNT_SUPPORT; /* only support TLS-SRP */
1174 return PARAM_LIBCURL_DOESNT_SUPPORT;
1176 case 'n': /* no empty SSL fragments */
1177 if(curlinfo->features & CURL_VERSION_SSL)
1178 config->ssl_allow_beast = toggle;
1180 default: /* certificate file */
1182 char *ptr = strchr(nextarg, ':');
1183 /* Since we live in a world of weirdness and confusion, the win32
1184 dudes can use : when using drive letters and thus
1185 c:\file:password needs to work. In order not to break
1186 compatibility, we still use : as separator, but we try to detect
1187 when it is used for a file name! On windows. */
1190 (ptr == &nextarg[1]) &&
1191 (nextarg[2] == '\\' || nextarg[2] == '/') &&
1192 (ISALPHA(nextarg[0])) )
1193 /* colon in the second column, followed by a backslash, and the
1194 first character is an alphabetic letter:
1196 this is a drive letter colon */
1197 ptr = strchr(&nextarg[3], ':'); /* find the next one instead */
1200 /* we have a password too */
1203 GetStr(&config->key_passwd, ptr);
1205 GetStr(&config->cert, nextarg);
1211 /* fail hard on errors */
1212 config->failonerror = toggle;
1215 /* "form data" simulation, this is a little advanced so lets do our best
1216 to sort this out slowly and carefully */
1217 if(formparse(config,
1221 (subletter=='s')?TRUE:FALSE)) /* 's' means literal string */
1222 return PARAM_BAD_USE;
1223 if(SetHTTPrequest(config, HTTPREQ_POST, &config->httpreq))
1224 return PARAM_BAD_USE;
1227 case 'g': /* g disables URLglobbing */
1228 config->globoff = toggle;
1231 case 'G': /* HTTP GET */
1232 config->use_httpget = TRUE;
1235 case 'h': /* h for help */
1238 return PARAM_HELP_REQUESTED;
1240 /* we now actually support --no-help too! */
1243 /* A custom header to append to a list */
1244 err = add2list(&config->headers, nextarg);
1249 config->include_headers = toggle; /* include the headers as well in the
1250 general output stream */
1253 config->cookiesession = toggle;
1257 * no_body will imply include_headers later on
1259 config->no_body = toggle;
1260 if(SetHTTPrequest(config,
1261 (config->no_body)?HTTPREQ_HEAD:HTTPREQ_GET,
1263 return PARAM_BAD_USE;
1265 case 'J': /* --remote-header-name */
1266 if(config->include_headers) {
1268 "--include and --remote-header-name cannot be combined.\n");
1269 return PARAM_BAD_USE;
1271 config->content_disposition = toggle;
1273 case 'k': /* allow insecure SSL connects */
1274 config->insecure_ok = toggle;
1276 case 'K': /* parse config file */
1277 if(parseconfig(nextarg, config))
1278 warnf(config, "error trying read config from the '%s' file\n",
1282 config->dirlistonly = toggle; /* only list the names of the FTP dir */
1285 config->followlocation = toggle; /* Follow Location: HTTP headers */
1286 switch (subletter) {
1288 /* Continue to send authentication (user+password) when following
1289 * locations, even when hostname changed */
1290 config->unrestricted_auth = toggle;
1295 /* specified max time */
1296 if(str2num(&config->timeout, nextarg))
1297 return PARAM_BAD_NUMERIC;
1299 case 'M': /* M for manual, huge help */
1300 if(toggle) { /* --no-manual shows no manual... */
1303 return PARAM_HELP_REQUESTED;
1306 "built-in manual was disabled at build-time!\n");
1307 return PARAM_OPTION_UNKNOWN;
1313 case 'o': /* CA info PEM file */
1314 /* use .netrc or URL */
1315 config->netrc_opt = toggle;
1317 case 'e': /* netrc-file */
1318 GetStr(&config->netrc_file, nextarg);
1321 /* pick info from .netrc, if this is used for http, curl will
1322 automatically enfore user+password with the request */
1323 config->netrc = toggle;
1328 /* disable the output I/O buffering. note that the option is called
1329 --buffer but is mostly used in the negative form: --no-buffer */
1331 config->nobuffer = (!toggle)?TRUE:FALSE;
1333 config->nobuffer = toggle;
1335 case 'O': /* --remote-name */
1336 if(subletter == 'a') { /* --remote-name-all */
1337 config->default_node_flags = toggle?GETOUT_USEREMOTE:0;
1341 case 'o': /* --output */
1345 if(config->url_out || ((config->url_out = config->url_list) != NULL)) {
1346 /* there's a node here, if it already is filled-in continue to find
1348 while(config->url_out && (config->url_out->flags & GETOUT_OUTFILE))
1349 config->url_out = config->url_out->next;
1352 /* now there might or might not be an available node to fill in! */
1356 url = config->url_out;
1358 /* there was no free node, create one! */
1359 url = new_getout(config);
1362 return PARAM_NO_MEM;
1364 /* fill in the outfile */
1366 GetStr(&url->outfile, nextarg);
1367 url->flags &= ~GETOUT_USEREMOTE; /* switch off */
1370 url->outfile = NULL; /* leave it */
1372 url->flags |= GETOUT_USEREMOTE; /* switch on */
1374 url->flags &= ~GETOUT_USEREMOTE; /* switch off */
1376 url->flags |= GETOUT_OUTFILE;
1381 /* This makes the FTP sessions use PORT instead of PASV */
1382 /* use <eth0> or <192.168.10.10> style addresses. Anything except
1383 this will make us try to get the "default" address.
1384 NOTE: this is a changed behaviour since the released 4.1!
1386 GetStr(&config->ftpport, nextarg);
1389 /* proxy tunnel for non-http protocols */
1390 config->proxytunnel = toggle;
1393 case 'q': /* if used first, already taken care of, we do it like
1394 this so we don't cause an error! */
1397 /* QUOTE command to send to FTP server */
1398 switch(nextarg[0]) {
1400 /* prefixed with a dash makes it a POST TRANSFER one */
1402 err = add2list(&config->postquote, nextarg);
1405 /* prefixed with a plus makes it a just-before-transfer one */
1407 err = add2list(&config->prequote, nextarg);
1410 err = add2list(&config->quote, nextarg);
1417 /* Specifying a range WITHOUT A DASH will create an illegal HTTP range
1418 (and won't actually be range by definition). The man page previously
1419 claimed that to be a good way, why this code is added to work-around
1421 if(ISDIGIT(*nextarg) && !strchr(nextarg, '-')) {
1425 "A specified range MUST include at least one dash (-). "
1426 "Appending one for you!\n");
1427 off = curlx_strtoofft(nextarg, NULL, 10);
1428 snprintf(buffer, sizeof(buffer), "%" CURL_FORMAT_CURL_OFF_T "-", off);
1429 Curl_safefree(config->range);
1430 config->range = strdup(buffer);
1432 return PARAM_NO_MEM;
1435 /* byte range requested */
1437 tmp_range = nextarg;
1438 while(*tmp_range != '\0') {
1439 if(!ISDIGIT(*tmp_range) && *tmp_range != '-' && *tmp_range != ',') {
1440 warnf(config,"Invalid character is found in given range. "
1441 "A specified range MUST have only digits in "
1442 "\'start\'-\'stop\'. The server's response to this "
1443 "request is uncertain.\n");
1448 /* byte range requested */
1449 GetStr(&config->range, nextarg);
1453 /* use remote file's time */
1454 config->remote_time = toggle;
1457 /* don't show progress meter, don't show errors : */
1459 config->mute = config->noprogress = TRUE;
1461 config->mute = config->noprogress = FALSE;
1462 if(config->showerror < 0)
1463 /* if still on the default value, set showerror to the reverse of
1464 toggle. This is to allow -S and -s to be used in an independent
1465 order but still have the same effect. */
1466 config->showerror = (!toggle)?TRUE:FALSE; /* toggle off */
1470 config->showerror = toggle?1:0; /* toggle on if used with -s */
1473 /* Telnet options */
1474 err = add2list(&config->telnet_options, nextarg);
1479 /* we are uploading */
1482 if(config->url_out || ((config->url_out = config->url_list) != NULL)) {
1483 /* there's a node here, if it already is filled-in continue to find
1485 while(config->url_out && (config->url_out->flags & GETOUT_UPLOAD))
1486 config->url_out = config->url_out->next;
1489 /* now there might or might not be an available node to fill in! */
1493 url = config->url_out;
1495 /* there was no free node, create one! */
1496 url = new_getout(config);
1499 return PARAM_NO_MEM;
1501 url->flags |= GETOUT_UPLOAD; /* mark -T used */
1503 url->flags |= GETOUT_NOUPLOAD;
1505 /* "-" equals stdin, but keep the string around for now */
1506 GetStr(&url->infile, nextarg);
1513 GetStr(&config->userpwd, nextarg);
1515 err = checkpasswd("host", &config->userpwd);
1520 /* Proxy user:password */
1521 GetStr(&config->proxyuserpwd, nextarg);
1523 err = checkpasswd("proxy", &config->proxyuserpwd);
1529 /* the '%' thing here will cause the trace get sent to stderr */
1530 Curl_safefree(config->trace_dump);
1531 config->trace_dump = strdup("%");
1532 if(!config->trace_dump)
1533 return PARAM_NO_MEM;
1534 if(config->tracetype && (config->tracetype != TRACE_PLAIN))
1536 "-v, --verbose overrides an earlier trace/verbose option\n");
1537 config->tracetype = TRACE_PLAIN;
1540 /* verbose is disabled here */
1541 config->tracetype = TRACE_NONE;
1545 const char *const *proto;
1548 /* --no-version yields no output! */
1551 printf(CURL_ID "%s\n", curl_version());
1552 if(curlinfo->protocols) {
1553 printf("Protocols: ");
1554 for(proto = curlinfo->protocols; *proto; ++proto) {
1555 printf("%s ", *proto);
1557 puts(""); /* newline */
1559 if(curlinfo->features) {
1561 printf("Features: ");
1562 for(i = 0; i < sizeof(feats)/sizeof(feats[0]); i++) {
1563 if(curlinfo->features & feats[i].bitmask)
1564 printf("%s ", feats[i].name);
1567 printf("Metalink ");
1569 puts(""); /* newline */
1572 return PARAM_HELP_REQUESTED;
1574 /* get the output string */
1575 if('@' == *nextarg) {
1576 /* the data begins with a '@' letter, it means that a file name
1577 or - (stdin) follows */
1580 nextarg++; /* pass the @ */
1581 if(curlx_strequal("-", nextarg)) {
1587 file = fopen(nextarg, "r");
1589 err = file2string(&config->writeout, file);
1590 if(file && (file != stdin))
1594 if(!config->writeout)
1595 warnf(config, "Failed to read %s", fname);
1598 GetStr(&config->writeout, nextarg);
1602 GetStr(&config->proxy, nextarg);
1603 config->proxyver = CURLPROXY_HTTP;
1606 /* set custom request */
1607 GetStr(&config->customrequest, nextarg);
1610 /* low speed time */
1611 if(str2num(&config->low_speed_time, nextarg))
1612 return PARAM_BAD_NUMERIC;
1613 if(!config->low_speed_limit)
1614 config->low_speed_limit = 1;
1617 /* low speed limit */
1618 if(str2num(&config->low_speed_limit, nextarg))
1619 return PARAM_BAD_NUMERIC;
1620 if(!config->low_speed_time)
1621 config->low_speed_time = 30;
1623 case 'z': /* time condition coming up */
1628 /* If-Modified-Since: (section 14.28 in RFC2068) */
1629 config->timecond = CURL_TIMECOND_IFMODSINCE;
1632 /* If-Unmodified-Since: (section 14.24 in RFC2068) */
1633 config->timecond = CURL_TIMECOND_IFUNMODSINCE;
1637 /* Last-Modified: (section 14.29 in RFC2068) */
1638 config->timecond = CURL_TIMECOND_LASTMOD;
1643 config->condtime=curl_getdate(nextarg, &now);
1644 if(-1 == (int)config->condtime) {
1645 /* now let's see if it is a file name to get the time from instead! */
1646 struct_stat statbuf;
1647 if(-1 == stat(nextarg, &statbuf)) {
1648 /* failed, remove time condition */
1649 config->timecond = CURL_TIMECOND_NONE;
1651 "Illegal date format for -z, --timecond (and not "
1652 "a file name). Disabling time condition. "
1653 "See curl_getdate(3) for valid date syntax.\n");
1656 /* pull the time out from the file */
1657 config->condtime = statbuf.st_mtime;
1661 default: /* unknown flag */
1662 return PARAM_OPTION_UNKNOWN;
1666 } while(!longopt && !singleopt && *++parse && !*usedarg);