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