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