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