login options: remove the ;[options] support from CURLOPT_USERPWD
[platform/upstream/curl.git] / src / tool_getparam.c
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
9  *
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.
13  *
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.
17  *
18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19  * KIND, either express or implied.
20  *
21  ***************************************************************************/
22 #include "tool_setup.h"
23
24 #include "rawstr.h"
25
26 #define ENABLE_CURLX_PRINTF
27 /* use our own printf() functions */
28 #include "curlx.h"
29
30 #ifdef USE_MANUAL
31 #  include "tool_hugehelp.h"
32 #endif
33
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"
47
48 #include "memdebug.h" /* keep this as LAST include */
49
50 #ifdef MSDOS
51 #  define USE_WATT32
52 #endif
53
54 #define GetStr(str,val) do { \
55   if(*(str)) { \
56     free(*(str)); \
57     *(str) = NULL; \
58   } \
59   if((val)) {              \
60     *(str) = strdup((val)); \
61     if(!(*(str)))          \
62       return PARAM_NO_MEM; \
63   } \
64 } WHILE_FALSE
65
66 struct LongShort {
67   const char *letter; /* short name option */
68   const char *lname;  /* long name option */
69   bool extraparam;    /* whether it takes an additional argument */
70 };
71
72 static const struct LongShort aliases[]= {
73   /* all these ones, starting with "*" or "$" as a short-option have *no*
74      short option to mention. */
75   {"*",  "url",                      TRUE},
76   {"*4", "dns-ipv4-addr",            TRUE},
77   {"*6", "dns-ipv6-addr",            TRUE},
78   {"*a", "random-file",              TRUE},
79   {"*b", "egd-file",                 TRUE},
80   {"*B", "oauth2-bearer",             TRUE},
81   {"*c", "connect-timeout",          TRUE},
82   {"*d", "ciphers",                  TRUE},
83   {"*D", "dns-interface",            TRUE},
84   {"*e", "disable-epsv",             FALSE},
85   {"*E", "epsv",                     FALSE},
86          /* 'epsv' made like this to make --no-epsv and --epsv to work
87              although --disable-epsv is the documented option */
88 #ifdef USE_ENVIRONMENT
89   {"*f", "environment",              FALSE},
90 #endif
91   {"*F", "dns-servers",              TRUE},
92   {"*g", "trace",                    TRUE},
93   {"*h", "trace-ascii",              TRUE},
94   {"*i", "limit-rate",               TRUE},
95   {"*j", "compressed",               FALSE},
96   {"*J", "tr-encoding",              FALSE},
97   {"*k", "digest",                   FALSE},
98   {"*l", "negotiate",                FALSE},
99   {"*m", "ntlm",                     FALSE},
100   {"*M", "ntlm-wb",                  FALSE},
101   {"*n", "basic",                    FALSE},
102   {"*o", "anyauth",                  FALSE},
103 #ifdef USE_WATT32
104   {"*p", "wdebug",                   FALSE},
105 #endif
106   {"*q", "ftp-create-dirs",          FALSE},
107   {"*r", "create-dirs",              FALSE},
108   {"*s", "max-redirs",               TRUE},
109   {"*t", "proxy-ntlm",               FALSE},
110   {"*u", "crlf",                     FALSE},
111   {"*v", "stderr",                   TRUE},
112   {"*w", "interface",                TRUE},
113   {"*x", "krb" ,                     TRUE},
114   {"*x", "krb4" ,                    TRUE},
115          /* 'krb4' is the previous name */
116   {"*y", "max-filesize",             TRUE},
117   {"*z", "disable-eprt",             FALSE},
118   {"*Z", "eprt",                     FALSE},
119          /* 'eprt' made like this to make --no-eprt and --eprt to work
120              although --disable-eprt is the documented option */
121   {"$a", "ftp-ssl",                  FALSE},
122          /* 'ftp-ssl' deprecated name since 7.20.0 */
123   {"$a", "ssl",                      FALSE},
124          /* 'ssl' new option name in 7.20.0, previously this was ftp-ssl */
125   {"$b", "ftp-pasv",                 FALSE},
126   {"$c", "socks5",                   TRUE},
127   {"$c", "socks",                    TRUE},
128          /* 'socks' is how the option once was documented but we prefer
129             the --socks5 version for explicit version */
130   {"$d", "tcp-nodelay",              FALSE},
131   {"$e", "proxy-digest",             FALSE},
132   {"$f", "proxy-basic",              FALSE},
133   {"$g", "retry",                    TRUE},
134   {"$h", "retry-delay",              TRUE},
135   {"$i", "retry-max-time",           TRUE},
136   {"$k", "proxy-negotiate",          FALSE},
137   {"$m", "ftp-account",              TRUE},
138   {"$n", "proxy-anyauth",            FALSE},
139   {"$o", "trace-time",               FALSE},
140   {"$p", "ignore-content-length",    FALSE},
141   {"$q", "ftp-skip-pasv-ip",         FALSE},
142   {"$r", "ftp-method",               TRUE},
143   {"$s", "local-port",               TRUE},
144   {"$t", "socks4",                   TRUE},
145   {"$T", "socks4a",                  TRUE},
146   {"$u", "ftp-alternative-to-user",  TRUE},
147   {"$v", "ftp-ssl-reqd",             FALSE},
148          /* 'ftp-ssl-reqd' deprecated name since 7.20.0 */
149   {"$v", "ssl-reqd",                 FALSE},
150          /* 'ssl-reqd' new in 7.20.0, previously this was ftp-ssl-reqd */
151   {"$w", "sessionid",                FALSE},
152          /* ¡sessionid' listed as --no-sessionid in the help */
153   {"$x", "ftp-ssl-control",          FALSE},
154   {"$y", "ftp-ssl-ccc",              FALSE},
155   {"$j", "ftp-ssl-ccc-mode",         TRUE},
156   {"$z", "libcurl",                  TRUE},
157   {"$#", "raw",                      FALSE},
158   {"$0", "post301",                  FALSE},
159   {"$1", "keepalive",                FALSE},
160          /* 'keepalive' listed as --no-keepalive in the help */
161   {"$2", "socks5-hostname",          TRUE},
162   {"$3", "keepalive-time",           TRUE},
163   {"$4", "post302",                  FALSE},
164   {"$5", "noproxy",                  TRUE},
165 #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
166   {"$6", "socks5-gssapi-service",    TRUE},
167   {"$7", "socks5-gssapi-nec",        FALSE},
168 #endif
169   {"$8", "proxy1.0",                 TRUE},
170   {"$9", "tftp-blksize",             TRUE},
171   {"$A", "mail-from",                TRUE},
172   {"$B", "mail-rcpt",                TRUE},
173   {"$C", "ftp-pret",                 FALSE},
174   {"$D", "proto",                    TRUE},
175   {"$E", "proto-redir",              TRUE},
176   {"$F", "resolve",                  TRUE},
177   {"$G", "delegation",               TRUE},
178   {"$H", "mail-auth",                TRUE},
179   {"$I", "post303",                  FALSE},
180   {"$J", "metalink",                 FALSE},
181   {"$K", "sasl-ir",                  FALSE},
182   {"$L", "test-event",               FALSE},
183   {"0",   "http1.0",                 FALSE},
184   {"01",  "http1.1",                 FALSE},
185   {"02",  "http2.0",                 FALSE},
186   {"1",  "tlsv1",                    FALSE},
187   {"10",  "tlsv1.0",                 FALSE},
188   {"11",  "tlsv1.1",                 FALSE},
189   {"12",  "tlsv1.2",                 FALSE},
190   {"2",  "sslv2",                    FALSE},
191   {"3",  "sslv3",                    FALSE},
192   {"4",  "ipv4",                     FALSE},
193   {"6",  "ipv6",                     FALSE},
194   {"a",  "append",                   FALSE},
195   {"A",  "user-agent",               TRUE},
196   {"b",  "cookie",                   TRUE},
197   {"B",  "use-ascii",                FALSE},
198   {"c",  "cookie-jar",               TRUE},
199   {"C",  "continue-at",              TRUE},
200   {"d",  "data",                     TRUE},
201   {"da", "data-ascii",               TRUE},
202   {"db", "data-binary",              TRUE},
203   {"de", "data-urlencode",           TRUE},
204   {"D",  "dump-header",              TRUE},
205   {"e",  "referer",                  TRUE},
206   {"E",  "cert",                     TRUE},
207   {"Ea", "cacert",                   TRUE},
208   {"Eb", "cert-type",                TRUE},
209   {"Ec", "key",                      TRUE},
210   {"Ed", "key-type",                 TRUE},
211   {"Ee", "pass",                     TRUE},
212   {"Ef", "engine",                   TRUE},
213   {"Eg", "capath ",                  TRUE},
214   {"Eh", "pubkey",                   TRUE},
215   {"Ei", "hostpubmd5",               TRUE},
216   {"Ej", "crlfile",                  TRUE},
217   {"Ek", "tlsuser",                  TRUE},
218   {"El", "tlspassword",              TRUE},
219   {"Em", "tlsauthtype",              TRUE},
220   {"En", "ssl-allow-beast",          FALSE},
221   {"Eo", "login-options",            TRUE},
222   {"f",  "fail",                     FALSE},
223   {"F",  "form",                     TRUE},
224   {"Fs", "form-string",              TRUE},
225   {"g",  "globoff",                  FALSE},
226   {"G",  "get",                      FALSE},
227   {"h",  "help",                     FALSE},
228   {"H",  "header",                   TRUE},
229   {"i",  "include",                  FALSE},
230   {"I",  "head",                     FALSE},
231   {"j",  "junk-session-cookies",     FALSE},
232   {"J",  "remote-header-name",       FALSE},
233   {"k",  "insecure",                 FALSE},
234   {"K",  "config",                   TRUE},
235   {"l",  "list-only",                FALSE},
236   {"L",  "location",                 FALSE},
237   {"Lt", "location-trusted",         FALSE},
238   {"m",  "max-time",                 TRUE},
239   {"M",  "manual",                   FALSE},
240   {"n",  "netrc",                    FALSE},
241   {"no", "netrc-optional",           FALSE},
242   {"ne", "netrc-file",               TRUE},
243   {"N",  "buffer",                   FALSE},
244          /* 'buffer' listed as --no-buffer in the help */
245   {"o",  "output",                   TRUE},
246   {"O",  "remote-name",              FALSE},
247   {"Oa", "remote-name-all",          FALSE},
248   {"p",  "proxytunnel",              FALSE},
249   {"P",  "ftpport",                  TRUE},
250          /* 'ftpport' old version */
251   {"P",  "ftp-port",                 TRUE},
252   {"q",  "disable",                  FALSE},
253   {"Q",  "quote",                    TRUE},
254   {"r",  "range",                    TRUE},
255   {"R",  "remote-time",              FALSE},
256   {"s",  "silent",                   FALSE},
257   {"S",  "show-error",               FALSE},
258   {"t",  "telnet-options",           TRUE},
259          /* 'telnet-options' documented as telnet-option */
260   {"T",  "upload-file",              TRUE},
261   {"u",  "user",                     TRUE},
262   {"U",  "proxy-user",               TRUE},
263   {"v",  "verbose",                  FALSE},
264   {"V",  "version",                  FALSE},
265   {"w",  "write-out",                TRUE},
266   {"x",  "proxy",                    TRUE},
267   {"X",  "request",                  TRUE},
268   {"X",  "http-request",             TRUE},
269          /* 'http-request' OBSOLETE VERSION */
270   {"Y",  "speed-limit",              TRUE},
271   {"y",  "speed-time",               TRUE},
272   {"z",  "time-cond",                TRUE},
273   {"#",  "progress-bar",             FALSE},
274   {"~",  "xattr",                    FALSE},
275 };
276
277 struct feat {
278   const char *name;
279   int bitmask;
280 };
281
282 static const struct feat feats[] = {
283   {"AsynchDNS",      CURL_VERSION_ASYNCHDNS},
284   {"Debug",          CURL_VERSION_DEBUG},
285   {"TrackMemory",    CURL_VERSION_CURLDEBUG},
286   {"GSS-Negotiate",  CURL_VERSION_GSSNEGOTIATE},
287   {"IDN",            CURL_VERSION_IDN},
288   {"IPv6",           CURL_VERSION_IPV6},
289   {"Largefile",      CURL_VERSION_LARGEFILE},
290   {"NTLM",           CURL_VERSION_NTLM},
291   {"NTLM_WB",        CURL_VERSION_NTLM_WB},
292   {"SPNEGO",         CURL_VERSION_SPNEGO},
293   {"SSL",            CURL_VERSION_SSL},
294   {"SSPI",           CURL_VERSION_SSPI},
295   {"krb4",           CURL_VERSION_KERBEROS4},
296   {"libz",           CURL_VERSION_LIBZ},
297   {"CharConv",       CURL_VERSION_CONV},
298   {"TLS-SRP",        CURL_VERSION_TLSAUTH_SRP},
299   {"HTTP2",          CURL_VERSION_HTTP2}
300 };
301
302 /* Split the argument of -E to 'certname' and 'passphrase' separated by colon.
303  * We allow ':' and '\' to be escaped by '\' so that we can use certificate
304  * nicknames containing ':'.  See <https://sourceforge.net/p/curl/bugs/1196/>
305  * for details. */
306 #ifndef UNITTESTS
307 static
308 #endif
309 void parse_cert_parameter(const char *cert_parameter,
310                           char **certname,
311                           char **passphrase)
312 {
313   size_t param_length = strlen(cert_parameter);
314   size_t span;
315   const char *param_place = NULL;
316   char *certname_place = NULL;
317   *certname = NULL;
318   *passphrase = NULL;
319
320   /* most trivial assumption: cert_parameter is empty */
321   if(param_length == 0)
322     return;
323
324   /* next less trivial: cert_parameter contains no colon nor backslash; this
325    * means no passphrase was given and no characters escaped */
326   if(!strpbrk(cert_parameter, ":\\")) {
327     *certname = strdup(cert_parameter);
328     return;
329   }
330   /* deal with escaped chars; find unescaped colon if it exists */
331   certname_place = malloc(param_length + 1);
332   if(!certname_place)
333     return;
334
335   *certname = certname_place;
336   param_place = cert_parameter;
337   while(*param_place) {
338     span = strcspn(param_place, ":\\");
339     strncpy(certname_place, param_place, span);
340     param_place += span;
341     certname_place += span;
342     /* we just ate all the non-special chars. now we're on either a special
343      * char or the end of the string. */
344     switch(*param_place) {
345     case '\0':
346       break;
347     case '\\':
348       param_place++;
349       switch(*param_place) {
350         case '\0':
351           *certname_place++ = '\\';
352           break;
353         case '\\':
354           *certname_place++ = '\\';
355           param_place++;
356           break;
357         case ':':
358           *certname_place++ = ':';
359           param_place++;
360           break;
361         default:
362           *certname_place++ = '\\';
363           *certname_place++ = *param_place;
364           param_place++;
365           break;
366       }
367       break;
368     case ':':
369       /* Since we live in a world of weirdness and confusion, the win32
370          dudes can use : when using drive letters and thus c:\file:password
371          needs to work. In order not to break compatibility, we still use : as
372          separator, but we try to detect when it is used for a file name! On
373          windows. */
374 #ifdef WIN32
375       if(param_place &&
376           (param_place == &cert_parameter[1]) &&
377           (cert_parameter[2] == '\\' || cert_parameter[2] == '/') &&
378           (ISALPHA(cert_parameter[0])) ) {
379         /* colon in the second column, followed by a backslash, and the
380            first character is an alphabetic letter:
381
382            this is a drive letter colon */
383         *certname_place++ = ':';
384         param_place++;
385         break;
386       }
387 #endif
388       /* escaped colons and Windows drive letter colons were handled
389        * above; if we're still here, this is a separating colon */
390       param_place++;
391       if(strlen(param_place) > 0) {
392         *passphrase = strdup(param_place);
393       }
394       goto done;
395     }
396   }
397 done:
398   *certname_place = '\0';
399 }
400
401 ParameterError getparameter(char *flag,    /* f or -long-flag */
402                             char *nextarg, /* NULL if unset */
403                             bool *usedarg, /* set to TRUE if the arg
404                                               has been used */
405                             struct Configurable *config)
406 {
407   char letter;
408   char subletter = '\0'; /* subletters can only occur on long options */
409   int rc;
410   const char *parse = NULL;
411   unsigned int j;
412   time_t now;
413   int hit = -1;
414   bool longopt = FALSE;
415   bool singleopt = FALSE; /* when true means '-o foo' used '-ofoo' */
416   ParameterError err;
417   bool toggle = TRUE; /* how to switch boolean options, on or off. Controlled
418                          by using --OPTION or --no-OPTION */
419
420
421   if(('-' != flag[0]) ||
422      (('-' == flag[0]) && ('-' == flag[1]))) {
423     /* this should be a long name */
424     char *word = ('-' == flag[0]) ? flag+2 : flag;
425     size_t fnam = strlen(word);
426     int numhits = 0;
427
428     if(!strncmp(word, "no-", 3)) {
429       /* disable this option but ignore the "no-" part when looking for it */
430       word += 3;
431       toggle = FALSE;
432     }
433
434     for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) {
435       if(curlx_strnequal(aliases[j].lname, word, fnam)) {
436         longopt = TRUE;
437         numhits++;
438         if(curlx_raw_equal(aliases[j].lname, word)) {
439           parse = aliases[j].letter;
440           hit = j;
441           numhits = 1; /* a single unique hit */
442           break;
443         }
444         parse = aliases[j].letter;
445         hit = j;
446       }
447     }
448     if(numhits > 1) {
449       /* this is at least the second match! */
450       return PARAM_OPTION_AMBIGUOUS;
451     }
452     if(hit < 0) {
453       return PARAM_OPTION_UNKNOWN;
454     }
455   }
456   else {
457     flag++; /* prefixed with one dash, pass it */
458     hit = -1;
459     parse = flag;
460   }
461
462   do {
463     /* we can loop here if we have multiple single-letters */
464
465     if(!longopt) {
466       if(NULL != parse) {
467         letter = (char)*parse;
468       }
469       else {
470         letter = '\0';
471       }
472       subletter='\0';
473     }
474     else {
475       letter = parse[0];
476       subletter = parse[1];
477     }
478     *usedarg = FALSE; /* default is that we don't use the arg */
479
480     if(hit < 0) {
481       for(j = 0; j < sizeof(aliases)/sizeof(aliases[0]); j++) {
482         if(letter == aliases[j].letter[0]) {
483           hit = j;
484           break;
485         }
486       }
487       if(hit < 0) {
488         return PARAM_OPTION_UNKNOWN;
489       }
490     }
491
492     if(aliases[hit].extraparam) {
493       /* this option requires an extra parameter */
494       if(!longopt && parse[1]) {
495         nextarg = (char *)&parse[1]; /* this is the actual extra parameter */
496         singleopt = TRUE;   /* don't loop anymore after this */
497       }
498       else if(!nextarg)
499         return PARAM_REQUIRES_PARAMETER;
500       else
501         *usedarg = TRUE; /* mark it as used */
502     }
503
504     switch(letter) {
505     case '*': /* options without a short option */
506       switch(subletter) {
507       case '4': /* --dns-ipv4-addr */
508         /* addr in dot notation */
509         GetStr(&config->dns_ipv4_addr, nextarg);
510         break;
511       case '6': /* --dns-ipv6-addr */
512         /* addr in dot notation */
513         GetStr(&config->dns_ipv6_addr, nextarg);
514         break;
515       case 'a': /* random-file */
516         GetStr(&config->random_file, nextarg);
517         break;
518       case 'b': /* egd-file */
519         GetStr(&config->egd_file, nextarg);
520         break;
521       case 'B': /* XOAUTH2 Bearer */
522         GetStr(&config->xoauth2_bearer, nextarg);
523         break;
524       case 'c': /* connect-timeout */
525         err = str2udouble(&config->connecttimeout, nextarg);
526         if(err)
527           return err;
528         break;
529       case 'd': /* ciphers */
530         GetStr(&config->cipher_list, nextarg);
531         break;
532       case 'D': /* --dns-interface */
533         /* interface name */
534         GetStr(&config->dns_interface, nextarg);
535         break;
536       case 'e': /* --disable-epsv */
537         config->disable_epsv = toggle;
538         break;
539       case 'E': /* --epsv */
540         config->disable_epsv = (!toggle)?TRUE:FALSE;
541         break;
542 #ifdef USE_ENVIRONMENT
543       case 'f':
544         config->writeenv = toggle;
545         break;
546 #endif
547       case 'F': /* --dns-servers */
548         /* IP addrs of DNS servers */
549         GetStr(&config->dns_servers, nextarg);
550         break;
551       case 'g': /* --trace */
552         GetStr(&config->trace_dump, nextarg);
553         if(config->tracetype && (config->tracetype != TRACE_BIN))
554           warnf(config, "--trace overrides an earlier trace/verbose option\n");
555         config->tracetype = TRACE_BIN;
556         break;
557       case 'h': /* --trace-ascii */
558         GetStr(&config->trace_dump, nextarg);
559         if(config->tracetype && (config->tracetype != TRACE_ASCII))
560           warnf(config,
561                 "--trace-ascii overrides an earlier trace/verbose option\n");
562         config->tracetype = TRACE_ASCII;
563         break;
564       case 'i': /* --limit-rate */
565       {
566         /* We support G, M, K too */
567         char *unit;
568         curl_off_t value = curlx_strtoofft(nextarg, &unit, 0);
569
570         if(!*unit)
571           unit = (char *)"b";
572         else if(strlen(unit) > 1)
573           unit = (char *)"w"; /* unsupported */
574
575         switch(*unit) {
576         case 'G':
577         case 'g':
578           value *= 1024*1024*1024;
579           break;
580         case 'M':
581         case 'm':
582           value *= 1024*1024;
583           break;
584         case 'K':
585         case 'k':
586           value *= 1024;
587           break;
588         case 'b':
589         case 'B':
590           /* for plain bytes, leave as-is */
591           break;
592         default:
593           warnf(config, "unsupported rate unit. Use G, M, K or B!\n");
594           return PARAM_BAD_USE;
595         }
596         config->recvpersecond = value;
597         config->sendpersecond = value;
598       }
599       break;
600
601       case 'j': /* --compressed */
602         if(toggle && !(curlinfo->features & CURL_VERSION_LIBZ))
603           return PARAM_LIBCURL_DOESNT_SUPPORT;
604         config->encoding = toggle;
605         break;
606
607       case 'J': /* --tr-encoding */
608         config->tr_encoding = toggle;
609         break;
610
611       case 'k': /* --digest */
612         if(toggle)
613           config->authtype |= CURLAUTH_DIGEST;
614         else
615           config->authtype &= ~CURLAUTH_DIGEST;
616         break;
617
618       case 'l': /* --negotiate */
619         if(toggle) {
620           if(curlinfo->features & CURL_VERSION_GSSNEGOTIATE)
621             config->authtype |= CURLAUTH_GSSNEGOTIATE;
622           else
623             return PARAM_LIBCURL_DOESNT_SUPPORT;
624         }
625         else
626           config->authtype &= ~CURLAUTH_GSSNEGOTIATE;
627         break;
628
629       case 'm': /* --ntlm */
630         if(toggle) {
631           if(curlinfo->features & CURL_VERSION_NTLM)
632             config->authtype |= CURLAUTH_NTLM;
633           else
634             return PARAM_LIBCURL_DOESNT_SUPPORT;
635         }
636         else
637           config->authtype &= ~CURLAUTH_NTLM;
638         break;
639
640       case 'M': /* --ntlm-wb */
641         if(toggle) {
642           if(curlinfo->features & CURL_VERSION_NTLM_WB)
643             config->authtype |= CURLAUTH_NTLM_WB;
644           else
645             return PARAM_LIBCURL_DOESNT_SUPPORT;
646         }
647         else
648           config->authtype &= ~CURLAUTH_NTLM_WB;
649         break;
650
651       case 'n': /* --basic for completeness */
652         if(toggle)
653           config->authtype |= CURLAUTH_BASIC;
654         else
655           config->authtype &= ~CURLAUTH_BASIC;
656         break;
657
658       case 'o': /* --anyauth, let libcurl pick it */
659         if(toggle)
660           config->authtype = CURLAUTH_ANY;
661         /* --no-anyauth simply doesn't touch it */
662         break;
663
664 #ifdef USE_WATT32
665       case 'p': /* --wdebug */
666         dbug_init();
667         break;
668 #endif
669       case 'q': /* --ftp-create-dirs */
670         config->ftp_create_dirs = toggle;
671         break;
672
673       case 'r': /* --create-dirs */
674         config->create_dirs = toggle;
675         break;
676
677       case 's': /* --max-redirs */
678         /* specified max no of redirects (http(s)), this accepts -1 as a
679            special condition */
680         err = str2num(&config->maxredirs, nextarg);
681         if(err)
682           return err;
683         if(config->maxredirs < -1)
684           return PARAM_BAD_NUMERIC;
685         break;
686
687       case 't': /* --proxy-ntlm */
688         if(curlinfo->features & CURL_VERSION_NTLM)
689           config->proxyntlm = toggle;
690         else
691           return PARAM_LIBCURL_DOESNT_SUPPORT;
692         break;
693
694       case 'u': /* --crlf */
695         /* LF -> CRLF conversion? */
696         config->crlf = toggle;
697         break;
698
699       case 'v': /* --stderr */
700         if(strcmp(nextarg, "-")) {
701           FILE *newfile = fopen(nextarg, "wt");
702           if(!newfile)
703             warnf(config, "Failed to open %s!\n", nextarg);
704           else {
705             if(config->errors_fopened)
706               fclose(config->errors);
707             config->errors = newfile;
708             config->errors_fopened = TRUE;
709           }
710         }
711         else
712           config->errors = stdout;
713         break;
714       case 'w': /* --interface */
715         /* interface */
716         GetStr(&config->iface, nextarg);
717         break;
718       case 'x': /* --krb */
719         /* kerberos level string */
720         if(curlinfo->features & (CURL_VERSION_KERBEROS4 |
721                                  CURL_VERSION_GSSNEGOTIATE))
722           GetStr(&config->krblevel, nextarg);
723         else
724           return PARAM_LIBCURL_DOESNT_SUPPORT;
725         break;
726       case 'y': /* --max-filesize */
727         err = str2offset(&config->max_filesize, nextarg);
728         if(err)
729           return err;
730         break;
731       case 'z': /* --disable-eprt */
732         config->disable_eprt = toggle;
733         break;
734       case 'Z': /* --eprt */
735         config->disable_eprt = (!toggle)?TRUE:FALSE;
736         break;
737
738       default: /* the URL! */
739       {
740         struct getout *url;
741         if(config->url_get || ((config->url_get = config->url_list) != NULL)) {
742           /* there's a node here, if it already is filled-in continue to find
743              an "empty" node */
744           while(config->url_get && (config->url_get->flags & GETOUT_URL))
745             config->url_get = config->url_get->next;
746         }
747
748         /* now there might or might not be an available node to fill in! */
749
750         if(config->url_get)
751           /* existing node */
752           url = config->url_get;
753         else
754           /* there was no free node, create one! */
755           url = new_getout(config);
756
757         if(!url)
758           return PARAM_NO_MEM;
759         else {
760           /* fill in the URL */
761           GetStr(&url->url, nextarg);
762           url->flags |= GETOUT_URL;
763         }
764       }
765       }
766       break;
767     case '$': /* more options without a short option */
768       switch(subletter) {
769       case 'a': /* --ftp-ssl */
770         if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
771           return PARAM_LIBCURL_DOESNT_SUPPORT;
772         config->ftp_ssl = toggle;
773         break;
774       case 'b': /* --ftp-pasv */
775         Curl_safefree(config->ftpport);
776         break;
777       case 'c': /* --socks5 specifies a socks5 proxy to use, and resolves
778                    the name locally and passes on the resolved address */
779         GetStr(&config->socksproxy, nextarg);
780         config->socksver = CURLPROXY_SOCKS5;
781         break;
782       case 't': /* --socks4 specifies a socks4 proxy to use */
783         GetStr(&config->socksproxy, nextarg);
784         config->socksver = CURLPROXY_SOCKS4;
785         break;
786       case 'T': /* --socks4a specifies a socks4a proxy to use */
787         GetStr(&config->socksproxy, nextarg);
788         config->socksver = CURLPROXY_SOCKS4A;
789         break;
790       case '2': /* --socks5-hostname specifies a socks5 proxy and enables name
791                    resolving with the proxy */
792         GetStr(&config->socksproxy, nextarg);
793         config->socksver = CURLPROXY_SOCKS5_HOSTNAME;
794         break;
795       case 'd': /* --tcp-nodelay option */
796         config->tcp_nodelay = toggle;
797         break;
798       case 'e': /* --proxy-digest */
799         config->proxydigest = toggle;
800         break;
801       case 'f': /* --proxy-basic */
802         config->proxybasic = toggle;
803         break;
804       case 'g': /* --retry */
805         err = str2unum(&config->req_retry, nextarg);
806         if(err)
807           return err;
808         break;
809       case 'h': /* --retry-delay */
810         err = str2unum(&config->retry_delay, nextarg);
811         if(err)
812           return err;
813         break;
814       case 'i': /* --retry-max-time */
815         err = str2unum(&config->retry_maxtime, nextarg);
816         if(err)
817           return err;
818         break;
819
820       case 'k': /* --proxy-negotiate */
821         if(curlinfo->features & CURL_VERSION_GSSNEGOTIATE)
822           config->proxynegotiate = toggle;
823         else
824           return PARAM_LIBCURL_DOESNT_SUPPORT;
825         break;
826       case 'm': /* --ftp-account */
827         GetStr(&config->ftp_account, nextarg);
828         break;
829       case 'n': /* --proxy-anyauth */
830         config->proxyanyauth = toggle;
831         break;
832       case 'o': /* --trace-time */
833         config->tracetime = toggle;
834         break;
835       case 'p': /* --ignore-content-length */
836         config->ignorecl = toggle;
837         break;
838       case 'q': /* --ftp-skip-pasv-ip */
839         config->ftp_skip_ip = toggle;
840         break;
841       case 'r': /* --ftp-method (undocumented at this point) */
842         config->ftp_filemethod = ftpfilemethod(config, nextarg);
843         break;
844       case 's': /* --local-port */
845         rc = sscanf(nextarg, "%d - %d",
846                     &config->localport,
847                     &config->localportrange);
848         if(!rc)
849           return PARAM_BAD_USE;
850         else if(rc == 1)
851           config->localportrange = 1; /* default number of ports to try */
852         else {
853           config->localportrange -= config->localport;
854           if(config->localportrange < 1) {
855             warnf(config, "bad range input\n");
856             return PARAM_BAD_USE;
857           }
858         }
859         break;
860       case 'u': /* --ftp-alternative-to-user */
861         GetStr(&config->ftp_alternative_to_user, nextarg);
862         break;
863       case 'v': /* --ftp-ssl-reqd */
864         if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
865           return PARAM_LIBCURL_DOESNT_SUPPORT;
866         config->ftp_ssl_reqd = toggle;
867         break;
868       case 'w': /* --no-sessionid */
869         config->disable_sessionid = (!toggle)?TRUE:FALSE;
870         break;
871       case 'x': /* --ftp-ssl-control */
872         if(toggle && !(curlinfo->features & CURL_VERSION_SSL))
873           return PARAM_LIBCURL_DOESNT_SUPPORT;
874         config->ftp_ssl_control = toggle;
875         break;
876       case 'y': /* --ftp-ssl-ccc */
877         config->ftp_ssl_ccc = toggle;
878         if(!config->ftp_ssl_ccc_mode)
879           config->ftp_ssl_ccc_mode = CURLFTPSSL_CCC_PASSIVE;
880         break;
881       case 'j': /* --ftp-ssl-ccc-mode */
882         config->ftp_ssl_ccc = TRUE;
883         config->ftp_ssl_ccc_mode = ftpcccmethod(config, nextarg);
884         break;
885       case 'z': /* --libcurl */
886 #ifdef CURL_DISABLE_LIBCURL_OPTION
887         warnf(config,
888               "--libcurl option was disabled at build-time!\n");
889         return PARAM_OPTION_UNKNOWN;
890 #else
891         GetStr(&config->libcurl, nextarg);
892         break;
893 #endif
894       case '#': /* --raw */
895         config->raw = toggle;
896         break;
897       case '0': /* --post301 */
898         config->post301 = toggle;
899         break;
900       case '1': /* --no-keepalive */
901         config->nokeepalive = (!toggle)?TRUE:FALSE;
902         break;
903       case '3': /* --keepalive-time */
904         err = str2unum(&config->alivetime, nextarg);
905         if(err)
906           return err;
907         break;
908       case '4': /* --post302 */
909         config->post302 = toggle;
910         break;
911       case 'I': /* --post303 */
912         config->post303 = toggle;
913         break;
914       case '5': /* --noproxy */
915         /* This specifies the noproxy list */
916         GetStr(&config->noproxy, nextarg);
917         break;
918 #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
919       case '6': /* --socks5-gssapi-service */
920         GetStr(&config->socks5_gssapi_service, nextarg);
921         break;
922       case '7': /* --socks5-gssapi-nec*/
923         config->socks5_gssapi_nec = toggle;
924         break;
925 #endif
926       case '8': /* --proxy1.0 */
927         /* http 1.0 proxy */
928         GetStr(&config->proxy, nextarg);
929         config->proxyver = CURLPROXY_HTTP_1_0;
930         break;
931       case '9': /* --tftp-blksize */
932         err = str2unum(&config->tftp_blksize, nextarg);
933         if(err)
934           return err;
935         break;
936       case 'A': /* --mail-from */
937         GetStr(&config->mail_from, nextarg);
938         break;
939       case 'B': /* --mail-rcpt */
940         /* append receiver to a list */
941         err = add2list(&config->mail_rcpt, nextarg);
942         if(err)
943           return err;
944         break;
945       case 'C': /* --ftp-pret */
946         config->ftp_pret = toggle;
947         break;
948       case 'D': /* --proto */
949         config->proto_present = TRUE;
950         if(proto2num(config, &config->proto, nextarg))
951           return PARAM_BAD_USE;
952         break;
953       case 'E': /* --proto-redir */
954         config->proto_redir_present = TRUE;
955         if(proto2num(config, &config->proto_redir, nextarg))
956           return PARAM_BAD_USE;
957         break;
958       case 'F': /* --resolve */
959         err = add2list(&config->resolve, nextarg);
960         if(err)
961           return err;
962         break;
963       case 'G': /* --delegation LEVEL */
964         config->gssapi_delegation = delegation(config, nextarg);
965         break;
966       case 'H': /* --mail-auth */
967         GetStr(&config->mail_auth, nextarg);
968         break;
969       case 'J': /* --metalink */
970         {
971 #ifdef USE_METALINK
972           int mlmaj, mlmin, mlpatch;
973           metalink_get_version(&mlmaj, &mlmin, &mlpatch);
974           if((mlmaj*10000)+(mlmin*100)+mlpatch < CURL_REQ_LIBMETALINK_VERS) {
975             warnf(config,
976                   "--metalink option cannot be used because the version of "
977                   "the linked libmetalink library is too old. "
978                   "Required: %d.%d.%d, found %d.%d.%d\n",
979                   CURL_REQ_LIBMETALINK_MAJOR,
980                   CURL_REQ_LIBMETALINK_MINOR,
981                   CURL_REQ_LIBMETALINK_PATCH,
982                   mlmaj, mlmin, mlpatch);
983             return PARAM_BAD_USE;
984           }
985           else
986             config->use_metalink = toggle;
987 #else
988           warnf(config, "--metalink option is ignored because the binary is "
989                 "built without the Metalink support.\n");
990 #endif
991           break;
992         }
993       case 'K': /* --sasl-ir */
994         config->sasl_ir = toggle;
995         break;
996       case 'L': /* --test-event */
997 #ifdef CURLDEBUG
998         config->test_event_based = toggle;
999 #else
1000         warnf(config, "--test-event is ignored unless a debug build!\n");
1001 #endif
1002         break;
1003       }
1004       break;
1005     case '#': /* --progress-bar */
1006       if(toggle)
1007         config->progressmode = CURL_PROGRESS_BAR;
1008       else
1009         config->progressmode = CURL_PROGRESS_STATS;
1010       break;
1011     case '~': /* --xattr */
1012       config->xattr = toggle;
1013       break;
1014     case '0': /* --http* options */
1015       switch(subletter) {
1016       case '\0':
1017         /* HTTP version 1.0 */
1018         config->httpversion = CURL_HTTP_VERSION_1_0;
1019         break;
1020       case '1':
1021         /* HTTP version 1.1 */
1022         config->httpversion = CURL_HTTP_VERSION_1_1;
1023         break;
1024       case '2':
1025         /* HTTP version 2.0 */
1026         config->httpversion = CURL_HTTP_VERSION_2_0;
1027         break;
1028       }
1029       break;
1030     case '1': /* --tlsv1* options */
1031       switch(subletter) {
1032       case '\0':
1033         /* TLS version 1.x */
1034         config->ssl_version = CURL_SSLVERSION_TLSv1;
1035         break;
1036       case '0':
1037         /* TLS version 1.0 */
1038         config->ssl_version = CURL_SSLVERSION_TLSv1_0;
1039         break;
1040       case '1':
1041         /* TLS version 1.1 */
1042         config->ssl_version = CURL_SSLVERSION_TLSv1_1;
1043         break;
1044       case '2':
1045         /* TLS version 1.2 */
1046         config->ssl_version = CURL_SSLVERSION_TLSv1_2;
1047         break;
1048       }
1049       break;
1050     case '2':
1051       /* SSL version 2 */
1052       config->ssl_version = CURL_SSLVERSION_SSLv2;
1053       break;
1054     case '3':
1055       /* SSL version 3 */
1056       config->ssl_version = CURL_SSLVERSION_SSLv3;
1057       break;
1058     case '4':
1059       /* IPv4 */
1060       config->ip_version = 4;
1061       break;
1062     case '6':
1063       /* IPv6 */
1064       config->ip_version = 6;
1065       break;
1066     case 'a':
1067       /* This makes the FTP sessions use APPE instead of STOR */
1068       config->ftp_append = toggle;
1069       break;
1070     case 'A':
1071       /* This specifies the User-Agent name */
1072       GetStr(&config->useragent, nextarg);
1073       break;
1074     case 'b': /* cookie string coming up: */
1075       if(nextarg[0] == '@') {
1076         nextarg++;
1077       }
1078       else if(strchr(nextarg, '=')) {
1079         /* A cookie string must have a =-letter */
1080         GetStr(&config->cookie, nextarg);
1081         break;
1082       }
1083       /* We have a cookie file to read from! */
1084       GetStr(&config->cookiefile, nextarg);
1085       break;
1086     case 'B':
1087       /* use ASCII/text when transferring */
1088       config->use_ascii = toggle;
1089       break;
1090     case 'c':
1091       /* get the file name to dump all cookies in */
1092       GetStr(&config->cookiejar, nextarg);
1093       break;
1094     case 'C':
1095       /* This makes us continue an ftp transfer at given position */
1096       if(!curlx_strequal(nextarg, "-")) {
1097         err = str2offset(&config->resume_from, nextarg);
1098         if(err)
1099           return err;
1100         config->resume_from_current = FALSE;
1101       }
1102       else {
1103         config->resume_from_current = TRUE;
1104         config->resume_from = 0;
1105       }
1106       config->use_resume=TRUE;
1107       break;
1108     case 'd':
1109       /* postfield data */
1110     {
1111       char *postdata = NULL;
1112       FILE *file;
1113       size_t size = 0;
1114
1115       if(subletter == 'e') { /* --data-urlencode*/
1116         /* [name]=[content], we encode the content part only
1117          * [name]@[file name]
1118          *
1119          * Case 2: we first load the file using that name and then encode
1120          * the content.
1121          */
1122         const char *p = strchr(nextarg, '=');
1123         size_t nlen;
1124         char is_file;
1125         if(!p)
1126           /* there was no '=' letter, check for a '@' instead */
1127           p = strchr(nextarg, '@');
1128         if(p) {
1129           nlen = p - nextarg; /* length of the name part */
1130           is_file = *p++; /* pass the separator */
1131         }
1132         else {
1133           /* neither @ nor =, so no name and it isn't a file */
1134           nlen = is_file = 0;
1135           p = nextarg;
1136         }
1137         if('@' == is_file) {
1138           /* a '@' letter, it means that a file name or - (stdin) follows */
1139
1140           if(curlx_strequal("-", p)) {
1141             file = stdin;
1142             set_binmode(stdin);
1143           }
1144           else {
1145             file = fopen(p, "rb");
1146             if(!file)
1147               warnf(config,
1148                     "Couldn't read data from file \"%s\", this makes "
1149                     "an empty POST.\n", nextarg);
1150           }
1151
1152           err = file2memory(&postdata, &size, file);
1153
1154           if(file && (file != stdin))
1155             fclose(file);
1156           if(err)
1157             return err;
1158         }
1159         else {
1160           GetStr(&postdata, p);
1161           if(postdata)
1162             size = strlen(postdata);
1163         }
1164
1165         if(!postdata) {
1166           /* no data from the file, point to a zero byte string to make this
1167              get sent as a POST anyway */
1168           postdata = strdup("");
1169           if(!postdata)
1170             return PARAM_NO_MEM;
1171           size = 0;
1172         }
1173         else {
1174           char *enc = curl_easy_escape(config->easy, postdata, (int)size);
1175           Curl_safefree(postdata); /* no matter if it worked or not */
1176           if(enc) {
1177             /* now make a string with the name from above and append the
1178                encoded string */
1179             size_t outlen = nlen + strlen(enc) + 2;
1180             char *n = malloc(outlen);
1181             if(!n) {
1182               curl_free(enc);
1183               return PARAM_NO_MEM;
1184             }
1185             if(nlen > 0) { /* only append '=' if we have a name */
1186               snprintf(n, outlen, "%.*s=%s", nlen, nextarg, enc);
1187               size = outlen-1;
1188             }
1189             else {
1190               strcpy(n, enc);
1191               size = outlen-2; /* since no '=' was inserted */
1192             }
1193             curl_free(enc);
1194             postdata = n;
1195           }
1196           else
1197             return PARAM_NO_MEM;
1198         }
1199       }
1200       else if('@' == *nextarg) {
1201         /* the data begins with a '@' letter, it means that a file name
1202            or - (stdin) follows */
1203         nextarg++; /* pass the @ */
1204
1205         if(curlx_strequal("-", nextarg)) {
1206           file = stdin;
1207           if(subletter == 'b') /* forced data-binary */
1208             set_binmode(stdin);
1209         }
1210         else {
1211           file = fopen(nextarg, "rb");
1212           if(!file)
1213             warnf(config, "Couldn't read data from file \"%s\", this makes "
1214                   "an empty POST.\n", nextarg);
1215         }
1216
1217         if(subletter == 'b')
1218           /* forced binary */
1219           err = file2memory(&postdata, &size, file);
1220         else {
1221           err = file2string(&postdata, file);
1222           if(postdata)
1223             size = strlen(postdata);
1224         }
1225
1226         if(file && (file != stdin))
1227           fclose(file);
1228         if(err)
1229           return err;
1230
1231         if(!postdata) {
1232           /* no data from the file, point to a zero byte string to make this
1233              get sent as a POST anyway */
1234           postdata = strdup("");
1235           if(!postdata)
1236             return PARAM_NO_MEM;
1237         }
1238       }
1239       else {
1240         GetStr(&postdata, nextarg);
1241         if(postdata)
1242           size = strlen(postdata);
1243       }
1244
1245 #ifdef CURL_DOES_CONVERSIONS
1246       if(subletter != 'b') {
1247         /* NOT forced binary, convert to ASCII */
1248         if(convert_to_network(postdata, strlen(postdata))) {
1249           Curl_safefree(postdata);
1250           return PARAM_NO_MEM;
1251         }
1252       }
1253 #endif
1254
1255       if(config->postfields) {
1256         /* we already have a string, we append this one with a separating
1257            &-letter */
1258         char *oldpost = config->postfields;
1259         curl_off_t oldlen = config->postfieldsize;
1260         curl_off_t newlen = oldlen + size + 2;
1261         config->postfields = malloc((size_t)newlen);
1262         if(!config->postfields) {
1263           Curl_safefree(oldpost);
1264           Curl_safefree(postdata);
1265           return PARAM_NO_MEM;
1266         }
1267         memcpy(config->postfields, oldpost, (size_t)oldlen);
1268         /* use byte value 0x26 for '&' to accommodate non-ASCII platforms */
1269         config->postfields[oldlen] = '\x26';
1270         memcpy(&config->postfields[oldlen+1], postdata, size);
1271         config->postfields[oldlen+1+size] = '\0';
1272         Curl_safefree(oldpost);
1273         Curl_safefree(postdata);
1274         config->postfieldsize += size+1;
1275       }
1276       else {
1277         config->postfields = postdata;
1278         config->postfieldsize = size;
1279       }
1280     }
1281     /*
1282       We can't set the request type here, as this data might be used in
1283       a simple GET if -G is used. Already or soon.
1284
1285       if(SetHTTPrequest(HTTPREQ_SIMPLEPOST, &config->httpreq)) {
1286         Curl_safefree(postdata);
1287         return PARAM_BAD_USE;
1288       }
1289     */
1290     break;
1291     case 'D':
1292       /* dump-header to given file name */
1293       GetStr(&config->headerfile, nextarg);
1294       break;
1295     case 'e':
1296     {
1297       char *ptr = strstr(nextarg, ";auto");
1298       if(ptr) {
1299         /* Automatic referer requested, this may be combined with a
1300            set initial one */
1301         config->autoreferer = TRUE;
1302         *ptr = 0; /* zero terminate here */
1303       }
1304       else
1305         config->autoreferer = FALSE;
1306       GetStr(&config->referer, nextarg);
1307     }
1308     break;
1309     case 'E':
1310       switch(subletter) {
1311       case 'a': /* CA info PEM file */
1312         /* CA info PEM file */
1313         GetStr(&config->cacert, nextarg);
1314         break;
1315       case 'b': /* cert file type */
1316         GetStr(&config->cert_type, nextarg);
1317         break;
1318       case 'c': /* private key file */
1319         GetStr(&config->key, nextarg);
1320         break;
1321       case 'd': /* private key file type */
1322         GetStr(&config->key_type, nextarg);
1323         break;
1324       case 'e': /* private key passphrase */
1325         GetStr(&config->key_passwd, nextarg);
1326         cleanarg(nextarg);
1327         break;
1328       case 'f': /* crypto engine */
1329         GetStr(&config->engine, nextarg);
1330         if(config->engine && curlx_raw_equal(config->engine,"list"))
1331           config->list_engines = TRUE;
1332         break;
1333       case 'g': /* CA info PEM file */
1334         /* CA cert directory */
1335         GetStr(&config->capath, nextarg);
1336         break;
1337       case 'h': /* --pubkey public key file */
1338         GetStr(&config->pubkey, nextarg);
1339         break;
1340       case 'i': /* --hostpubmd5 md5 of the host public key */
1341         GetStr(&config->hostpubmd5, nextarg);
1342         if(!config->hostpubmd5 || strlen(config->hostpubmd5) != 32)
1343           return PARAM_BAD_USE;
1344         break;
1345       case 'j': /* CRL info PEM file */
1346         /* CRL file */
1347         GetStr(&config->crlfile, nextarg);
1348         break;
1349       case 'k': /* TLS username */
1350         if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)
1351           GetStr(&config->tls_username, nextarg);
1352         else
1353           return PARAM_LIBCURL_DOESNT_SUPPORT;
1354         break;
1355       case 'l': /* TLS password */
1356         if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP)
1357           GetStr(&config->tls_password, nextarg);
1358         else
1359           return PARAM_LIBCURL_DOESNT_SUPPORT;
1360         break;
1361       case 'm': /* TLS authentication type */
1362         if(curlinfo->features & CURL_VERSION_TLSAUTH_SRP) {
1363           GetStr(&config->tls_authtype, nextarg);
1364           if(!strequal(config->tls_authtype, "SRP"))
1365             return PARAM_LIBCURL_DOESNT_SUPPORT; /* only support TLS-SRP */
1366         }
1367         else
1368           return PARAM_LIBCURL_DOESNT_SUPPORT;
1369         break;
1370       case 'n': /* no empty SSL fragments, --ssl-allow-beast */
1371         if(curlinfo->features & CURL_VERSION_SSL)
1372           config->ssl_allow_beast = toggle;
1373         break;
1374
1375       case 'o': /* --login-options */
1376         GetStr(&config->login_options, nextarg);
1377         break;
1378
1379       default: /* certificate file */
1380       {
1381         char *certname, *passphrase;
1382         parse_cert_parameter(nextarg, &certname, &passphrase);
1383         Curl_safefree(config->cert);
1384         config->cert = certname;
1385         if(passphrase) {
1386           Curl_safefree(config->key_passwd);
1387           config->key_passwd = passphrase;
1388         }
1389         cleanarg(nextarg);
1390       }
1391       }
1392       break;
1393     case 'f':
1394       /* fail hard on errors  */
1395       config->failonerror = toggle;
1396       break;
1397     case 'F':
1398       /* "form data" simulation, this is a little advanced so lets do our best
1399          to sort this out slowly and carefully */
1400       if(formparse(config,
1401                    nextarg,
1402                    &config->httppost,
1403                    &config->last_post,
1404                    (subletter=='s')?TRUE:FALSE)) /* 's' means literal string */
1405         return PARAM_BAD_USE;
1406       if(SetHTTPrequest(config, HTTPREQ_POST, &config->httpreq))
1407         return PARAM_BAD_USE;
1408       break;
1409
1410     case 'g': /* g disables URLglobbing */
1411       config->globoff = toggle;
1412       break;
1413
1414     case 'G': /* HTTP GET */
1415       config->use_httpget = TRUE;
1416       break;
1417
1418     case 'h': /* h for help */
1419       if(toggle) {
1420         tool_help();
1421         return PARAM_HELP_REQUESTED;
1422       }
1423       /* we now actually support --no-help too! */
1424       break;
1425     case 'H':
1426       /* A custom header to append to a list */
1427       err = add2list(&config->headers, nextarg);
1428       if(err)
1429         return err;
1430       break;
1431     case 'i':
1432       config->include_headers = toggle; /* include the headers as well in the
1433                                            general output stream */
1434       break;
1435     case 'j':
1436       config->cookiesession = toggle;
1437       break;
1438     case 'I':
1439       /*
1440        * no_body will imply include_headers later on
1441        */
1442       config->no_body = toggle;
1443       if(SetHTTPrequest(config,
1444                         (config->no_body)?HTTPREQ_HEAD:HTTPREQ_GET,
1445                         &config->httpreq))
1446         return PARAM_BAD_USE;
1447       break;
1448     case 'J': /* --remote-header-name */
1449       if(config->include_headers) {
1450         warnf(config,
1451               "--include and --remote-header-name cannot be combined.\n");
1452         return PARAM_BAD_USE;
1453       }
1454       config->content_disposition = toggle;
1455       break;
1456     case 'k': /* allow insecure SSL connects */
1457       config->insecure_ok = toggle;
1458       break;
1459     case 'K': /* parse config file */
1460       if(parseconfig(nextarg, config))
1461         warnf(config, "error trying read config from the '%s' file\n",
1462               nextarg);
1463       break;
1464     case 'l':
1465       config->dirlistonly = toggle; /* only list the names of the FTP dir */
1466       break;
1467     case 'L':
1468       config->followlocation = toggle; /* Follow Location: HTTP headers */
1469       switch (subletter) {
1470       case 't':
1471         /* Continue to send authentication (user+password) when following
1472          * locations, even when hostname changed */
1473         config->unrestricted_auth = toggle;
1474         break;
1475       }
1476       break;
1477     case 'm':
1478       /* specified max time */
1479       err = str2udouble(&config->timeout, nextarg);
1480       if(err)
1481         return err;
1482       break;
1483     case 'M': /* M for manual, huge help */
1484       if(toggle) { /* --no-manual shows no manual... */
1485 #ifdef USE_MANUAL
1486         hugehelp();
1487         return PARAM_HELP_REQUESTED;
1488 #else
1489         warnf(config,
1490               "built-in manual was disabled at build-time!\n");
1491         return PARAM_OPTION_UNKNOWN;
1492 #endif
1493       }
1494       break;
1495     case 'n':
1496       switch(subletter) {
1497       case 'o': /* CA info PEM file */
1498         /* use .netrc or URL */
1499         config->netrc_opt = toggle;
1500         break;
1501       case 'e': /* netrc-file */
1502         GetStr(&config->netrc_file, nextarg);
1503         break;
1504       default:
1505         /* pick info from .netrc, if this is used for http, curl will
1506            automatically enfore user+password with the request */
1507         config->netrc = toggle;
1508         break;
1509       }
1510       break;
1511     case 'N':
1512       /* disable the output I/O buffering. note that the option is called
1513          --buffer but is mostly used in the negative form: --no-buffer */
1514       if(longopt)
1515         config->nobuffer = (!toggle)?TRUE:FALSE;
1516       else
1517         config->nobuffer = toggle;
1518       break;
1519     case 'O': /* --remote-name */
1520       if(subletter == 'a') { /* --remote-name-all */
1521         config->default_node_flags = toggle?GETOUT_USEREMOTE:0;
1522         break;
1523       }
1524       /* fall-through! */
1525     case 'o': /* --output */
1526       /* output file */
1527     {
1528       struct getout *url;
1529       if(config->url_out || ((config->url_out = config->url_list) != NULL)) {
1530         /* there's a node here, if it already is filled-in continue to find
1531            an "empty" node */
1532         while(config->url_out && (config->url_out->flags & GETOUT_OUTFILE))
1533           config->url_out = config->url_out->next;
1534       }
1535
1536       /* now there might or might not be an available node to fill in! */
1537
1538       if(config->url_out)
1539         /* existing node */
1540         url = config->url_out;
1541       else
1542         /* there was no free node, create one! */
1543         url = new_getout(config);
1544
1545       if(!url)
1546         return PARAM_NO_MEM;
1547       else {
1548         /* fill in the outfile */
1549         if('o' == letter) {
1550           GetStr(&url->outfile, nextarg);
1551           url->flags &= ~GETOUT_USEREMOTE; /* switch off */
1552         }
1553         else {
1554           url->outfile = NULL; /* leave it */
1555           if(toggle)
1556             url->flags |= GETOUT_USEREMOTE;  /* switch on */
1557           else
1558             url->flags &= ~GETOUT_USEREMOTE; /* switch off */
1559         }
1560         url->flags |= GETOUT_OUTFILE;
1561       }
1562     }
1563     break;
1564     case 'P':
1565       /* This makes the FTP sessions use PORT instead of PASV */
1566       /* use <eth0> or <192.168.10.10> style addresses. Anything except
1567          this will make us try to get the "default" address.
1568          NOTE: this is a changed behaviour since the released 4.1!
1569       */
1570       GetStr(&config->ftpport, nextarg);
1571       break;
1572     case 'p':
1573       /* proxy tunnel for non-http protocols */
1574       config->proxytunnel = toggle;
1575       break;
1576
1577     case 'q': /* if used first, already taken care of, we do it like
1578                  this so we don't cause an error! */
1579       break;
1580     case 'Q':
1581       /* QUOTE command to send to FTP server */
1582       switch(nextarg[0]) {
1583       case '-':
1584         /* prefixed with a dash makes it a POST TRANSFER one */
1585         nextarg++;
1586         err = add2list(&config->postquote, nextarg);
1587         break;
1588       case '+':
1589         /* prefixed with a plus makes it a just-before-transfer one */
1590         nextarg++;
1591         err = add2list(&config->prequote, nextarg);
1592         break;
1593       default:
1594         err = add2list(&config->quote, nextarg);
1595         break;
1596       }
1597       if(err)
1598         return err;
1599       break;
1600     case 'r':
1601       /* Specifying a range WITHOUT A DASH will create an illegal HTTP range
1602          (and won't actually be range by definition). The man page previously
1603          claimed that to be a good way, why this code is added to work-around
1604          it. */
1605       if(ISDIGIT(*nextarg) && !strchr(nextarg, '-')) {
1606         char buffer[32];
1607         curl_off_t off;
1608         warnf(config,
1609               "A specified range MUST include at least one dash (-). "
1610               "Appending one for you!\n");
1611         off = curlx_strtoofft(nextarg, NULL, 10);
1612         snprintf(buffer, sizeof(buffer), "%" CURL_FORMAT_CURL_OFF_T "-", off);
1613         Curl_safefree(config->range);
1614         config->range = strdup(buffer);
1615         if(!config->range)
1616           return PARAM_NO_MEM;
1617       }
1618       {
1619         /* byte range requested */
1620         char *tmp_range;
1621         tmp_range = nextarg;
1622         while(*tmp_range != '\0') {
1623           if(!ISDIGIT(*tmp_range) && *tmp_range != '-' && *tmp_range != ',') {
1624             warnf(config,"Invalid character is found in given range. "
1625                   "A specified range MUST have only digits in "
1626                   "\'start\'-\'stop\'. The server's response to this "
1627                   "request is uncertain.\n");
1628             break;
1629           }
1630           tmp_range++;
1631         }
1632         /* byte range requested */
1633         GetStr(&config->range, nextarg);
1634       }
1635       break;
1636     case 'R':
1637       /* use remote file's time */
1638       config->remote_time = toggle;
1639       break;
1640     case 's':
1641       /* don't show progress meter, don't show errors : */
1642       if(toggle)
1643         config->mute = config->noprogress = TRUE;
1644       else
1645         config->mute = config->noprogress = FALSE;
1646       if(config->showerror < 0)
1647         /* if still on the default value, set showerror to the reverse of
1648            toggle. This is to allow -S and -s to be used in an independent
1649            order but still have the same effect. */
1650         config->showerror = (!toggle)?TRUE:FALSE; /* toggle off */
1651       break;
1652     case 'S':
1653       /* show errors */
1654       config->showerror = toggle?1:0; /* toggle on if used with -s */
1655       break;
1656     case 't':
1657       /* Telnet options */
1658       err = add2list(&config->telnet_options, nextarg);
1659       if(err)
1660         return err;
1661       break;
1662     case 'T':
1663       /* we are uploading */
1664     {
1665       struct getout *url;
1666       if(config->url_out || ((config->url_out = config->url_list) != NULL)) {
1667         /* there's a node here, if it already is filled-in continue to find
1668            an "empty" node */
1669         while(config->url_out && (config->url_out->flags & GETOUT_UPLOAD))
1670           config->url_out = config->url_out->next;
1671       }
1672
1673       /* now there might or might not be an available node to fill in! */
1674
1675       if(config->url_out)
1676         /* existing node */
1677         url = config->url_out;
1678       else
1679         /* there was no free node, create one! */
1680         url = new_getout(config);
1681
1682       if(!url)
1683         return PARAM_NO_MEM;
1684       else {
1685         url->flags |= GETOUT_UPLOAD; /* mark -T used */
1686         if(!*nextarg)
1687           url->flags |= GETOUT_NOUPLOAD;
1688         else {
1689           /* "-" equals stdin, but keep the string around for now */
1690           GetStr(&url->infile, nextarg);
1691         }
1692       }
1693     }
1694     break;
1695     case 'u':
1696       /* user:password  */
1697       GetStr(&config->userpwd, nextarg);
1698       cleanarg(nextarg);
1699       break;
1700     case 'U':
1701       /* Proxy user:password  */
1702       GetStr(&config->proxyuserpwd, nextarg);
1703       cleanarg(nextarg);
1704       break;
1705     case 'v':
1706       if(toggle) {
1707         /* the '%' thing here will cause the trace get sent to stderr */
1708         Curl_safefree(config->trace_dump);
1709         config->trace_dump = strdup("%");
1710         if(!config->trace_dump)
1711           return PARAM_NO_MEM;
1712         if(config->tracetype && (config->tracetype != TRACE_PLAIN))
1713           warnf(config,
1714                 "-v, --verbose overrides an earlier trace/verbose option\n");
1715         config->tracetype = TRACE_PLAIN;
1716       }
1717       else
1718         /* verbose is disabled here */
1719         config->tracetype = TRACE_NONE;
1720       break;
1721     case 'V':
1722     {
1723       const char *const *proto;
1724
1725       if(!toggle)
1726         /* --no-version yields no output! */
1727         break;
1728
1729       printf(CURL_ID "%s\n", curl_version());
1730       if(curlinfo->protocols) {
1731         printf("Protocols: ");
1732         for(proto = curlinfo->protocols; *proto; ++proto) {
1733           printf("%s ", *proto);
1734         }
1735         puts(""); /* newline */
1736       }
1737       if(curlinfo->features) {
1738         unsigned int i;
1739         printf("Features: ");
1740         for(i = 0; i < sizeof(feats)/sizeof(feats[0]); i++) {
1741           if(curlinfo->features & feats[i].bitmask)
1742             printf("%s ", feats[i].name);
1743         }
1744 #ifdef USE_METALINK
1745         printf("Metalink ");
1746 #endif
1747         puts(""); /* newline */
1748       }
1749     }
1750     return PARAM_HELP_REQUESTED;
1751     case 'w':
1752       /* get the output string */
1753       if('@' == *nextarg) {
1754         /* the data begins with a '@' letter, it means that a file name
1755            or - (stdin) follows */
1756         FILE *file;
1757         const char *fname;
1758         nextarg++; /* pass the @ */
1759         if(curlx_strequal("-", nextarg)) {
1760           fname = "<stdin>";
1761           file = stdin;
1762         }
1763         else {
1764           fname = nextarg;
1765           file = fopen(nextarg, "r");
1766         }
1767         err = file2string(&config->writeout, file);
1768         if(file && (file != stdin))
1769           fclose(file);
1770         if(err)
1771           return err;
1772         if(!config->writeout)
1773           warnf(config, "Failed to read %s", fname);
1774       }
1775       else
1776         GetStr(&config->writeout, nextarg);
1777       break;
1778     case 'x':
1779       /* proxy */
1780       GetStr(&config->proxy, nextarg);
1781       config->proxyver = CURLPROXY_HTTP;
1782       break;
1783     case 'X':
1784       /* set custom request */
1785       GetStr(&config->customrequest, nextarg);
1786       break;
1787     case 'y':
1788       /* low speed time */
1789       err = str2unum(&config->low_speed_time, nextarg);
1790       if(err)
1791         return err;
1792       if(!config->low_speed_limit)
1793         config->low_speed_limit = 1;
1794       break;
1795     case 'Y':
1796       /* low speed limit */
1797       err = str2unum(&config->low_speed_limit, nextarg);
1798       if(err)
1799         return err;
1800       if(!config->low_speed_time)
1801         config->low_speed_time = 30;
1802       break;
1803     case 'z': /* time condition coming up */
1804       switch(*nextarg) {
1805       case '+':
1806         nextarg++;
1807       default:
1808         /* If-Modified-Since: (section 14.28 in RFC2068) */
1809         config->timecond = CURL_TIMECOND_IFMODSINCE;
1810         break;
1811       case '-':
1812         /* If-Unmodified-Since:  (section 14.24 in RFC2068) */
1813         config->timecond = CURL_TIMECOND_IFUNMODSINCE;
1814         nextarg++;
1815         break;
1816       case '=':
1817         /* Last-Modified:  (section 14.29 in RFC2068) */
1818         config->timecond = CURL_TIMECOND_LASTMOD;
1819         nextarg++;
1820         break;
1821       }
1822       now = time(NULL);
1823       config->condtime=curl_getdate(nextarg, &now);
1824       if(-1 == (int)config->condtime) {
1825         /* now let's see if it is a file name to get the time from instead! */
1826         struct_stat statbuf;
1827         if(-1 == stat(nextarg, &statbuf)) {
1828           /* failed, remove time condition */
1829           config->timecond = CURL_TIMECOND_NONE;
1830           warnf(config,
1831                 "Illegal date format for -z, --timecond (and not "
1832                 "a file name). Disabling time condition. "
1833                 "See curl_getdate(3) for valid date syntax.\n");
1834         }
1835         else {
1836           /* pull the time out from the file */
1837           config->condtime = statbuf.st_mtime;
1838         }
1839       }
1840       break;
1841     default: /* unknown flag */
1842       return PARAM_OPTION_UNKNOWN;
1843     }
1844     hit = -1;
1845
1846   } while(!longopt && !singleopt && *++parse && !*usedarg);
1847
1848   return PARAM_OK;
1849 }