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