1 #ifndef HEADER_CURL_TOOL_GETPARAM_H 2 #define HEADER_CURL_TOOL_GETPARAM_H 3 /*************************************************************************** 4 * _ _ ____ _ 5 * Project ___| | | | _ \| | 6 * / __| | | | |_) | | 7 * | (__| |_| | _ <| |___ 8 * \___|\___/|_| \_\_____| 9 * 10 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 11 * 12 * This software is licensed as described in the file COPYING, which 13 * you should have received as part of this distribution. The terms 14 * are also available at https://curl.se/docs/copyright.html. 15 * 16 * You may opt to use, copy, modify, merge, publish, distribute and/or sell 17 * copies of the Software, and permit persons to whom the Software is 18 * furnished to do so, under the terms of the COPYING file. 19 * 20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 21 * KIND, either express or implied. 22 * 23 * SPDX-License-Identifier: curl 24 * 25 ***************************************************************************/ 26 #include "tool_setup.h" 27 28 /* one enum for every command line option. The name is the verbatim long 29 option name, but in uppercase with periods and minuses replaced with 30 underscores using a "C_" prefix. */ 31 typedef enum { 32 C_ABSTRACT_UNIX_SOCKET, 33 C_ALPN, 34 C_ALT_SVC, 35 C_ANYAUTH, 36 C_APPEND, 37 C_AWS_SIGV4, 38 C_BASIC, 39 C_BUFFER, 40 C_CA_NATIVE, 41 C_CACERT, 42 C_CAPATH, 43 C_CERT, 44 C_CERT_STATUS, 45 C_CERT_TYPE, 46 C_CIPHERS, 47 C_CLOBBER, 48 C_COMPRESSED, 49 C_COMPRESSED_SSH, 50 C_CONFIG, 51 C_CONNECT_TIMEOUT, 52 C_CONNECT_TO, 53 C_CONTINUE_AT, 54 C_COOKIE, 55 C_COOKIE_JAR, 56 C_CREATE_DIRS, 57 C_CREATE_FILE_MODE, 58 C_CRLF, 59 C_CRLFILE, 60 C_CURVES, 61 C_DATA, 62 C_DATA_ASCII, 63 C_DATA_BINARY, 64 C_DATA_RAW, 65 C_DATA_URLENCODE, 66 C_DELEGATION, 67 C_DIGEST, 68 C_DISABLE, 69 C_DISABLE_EPRT, 70 C_DISABLE_EPSV, 71 C_DISALLOW_USERNAME_IN_URL, 72 C_DNS_INTERFACE, 73 C_DNS_IPV4_ADDR, 74 C_DNS_IPV6_ADDR, 75 C_DNS_SERVERS, 76 C_DOH_CERT_STATUS, 77 C_DOH_INSECURE, 78 C_DOH_URL, 79 C_DUMP_CA_EMBED, 80 C_DUMP_HEADER, 81 C_ECH, 82 C_EGD_FILE, 83 C_ENGINE, 84 C_EPRT, 85 C_EPSV, 86 C_ETAG_COMPARE, 87 C_ETAG_SAVE, 88 C_EXPECT100_TIMEOUT, 89 C_FAIL, 90 C_FAIL_EARLY, 91 C_FAIL_WITH_BODY, 92 C_FALSE_START, 93 C_FORM, 94 C_FORM_ESCAPE, 95 C_FORM_STRING, 96 C_FTP_ACCOUNT, 97 C_FTP_ALTERNATIVE_TO_USER, 98 C_FTP_CREATE_DIRS, 99 C_FTP_METHOD, 100 C_FTP_PASV, 101 C_FTP_PORT, 102 C_FTP_PRET, 103 C_FTP_SKIP_PASV_IP, 104 C_FTP_SSL, 105 C_FTP_SSL_CCC, 106 C_FTP_SSL_CCC_MODE, 107 C_FTP_SSL_CONTROL, 108 C_FTP_SSL_REQD, 109 C_GET, 110 C_GLOBOFF, 111 C_HAPPY_EYEBALLS_TIMEOUT_MS, 112 C_HAPROXY_CLIENTIP, 113 C_HAPROXY_PROTOCOL, 114 C_HEAD, 115 C_HEADER, 116 C_HELP, 117 C_HOSTPUBMD5, 118 C_HOSTPUBSHA256, 119 C_HSTS, 120 C_HTTP0_9, 121 C_HTTP1_0, 122 C_HTTP1_1, 123 C_HTTP2, 124 C_HTTP2_PRIOR_KNOWLEDGE, 125 C_HTTP3, 126 C_HTTP3_ONLY, 127 C_IGNORE_CONTENT_LENGTH, 128 C_INCLUDE, 129 C_INSECURE, 130 C_INTERFACE, 131 C_IPFS_GATEWAY, 132 C_IPV4, 133 C_IPV6, 134 C_JSON, 135 C_JUNK_SESSION_COOKIES, 136 C_KEEPALIVE, 137 C_KEEPALIVE_CNT, 138 C_KEEPALIVE_TIME, 139 C_KEY, 140 C_KEY_TYPE, 141 C_KRB, 142 C_KRB4, 143 C_LIBCURL, 144 C_LIMIT_RATE, 145 C_LIST_ONLY, 146 C_LOCAL_PORT, 147 C_LOCATION, 148 C_LOCATION_TRUSTED, 149 C_LOGIN_OPTIONS, 150 C_MAIL_AUTH, 151 C_MAIL_FROM, 152 C_MAIL_RCPT, 153 C_MAIL_RCPT_ALLOWFAILS, 154 C_MANUAL, 155 C_MAX_FILESIZE, 156 C_MAX_REDIRS, 157 C_MAX_TIME, 158 C_METALINK, 159 C_MPTCP, 160 C_NEGOTIATE, 161 C_NETRC, 162 C_NETRC_FILE, 163 C_NETRC_OPTIONAL, 164 C_NEXT, 165 C_NOPROXY, 166 C_NPN, 167 C_NTLM, 168 C_NTLM_WB, 169 C_OAUTH2_BEARER, 170 C_OUTPUT, 171 C_OUTPUT_DIR, 172 C_PARALLEL, 173 C_PARALLEL_IMMEDIATE, 174 C_PARALLEL_MAX, 175 C_PASS, 176 C_PATH_AS_IS, 177 C_PINNEDPUBKEY, 178 C_POST301, 179 C_POST302, 180 C_POST303, 181 C_PREPROXY, 182 C_PROGRESS_BAR, 183 C_PROGRESS_METER, 184 C_PROTO, 185 C_PROTO_DEFAULT, 186 C_PROTO_REDIR, 187 C_PROXY, 188 C_PROXY_ANYAUTH, 189 C_PROXY_BASIC, 190 C_PROXY_CA_NATIVE, 191 C_PROXY_CACERT, 192 C_PROXY_CAPATH, 193 C_PROXY_CERT, 194 C_PROXY_CERT_TYPE, 195 C_PROXY_CIPHERS, 196 C_PROXY_CRLFILE, 197 C_PROXY_DIGEST, 198 C_PROXY_HEADER, 199 C_PROXY_HTTP2, 200 C_PROXY_INSECURE, 201 C_PROXY_KEY, 202 C_PROXY_KEY_TYPE, 203 C_PROXY_NEGOTIATE, 204 C_PROXY_NTLM, 205 C_PROXY_PASS, 206 C_PROXY_PINNEDPUBKEY, 207 C_PROXY_SERVICE_NAME, 208 C_PROXY_SSL_ALLOW_BEAST, 209 C_PROXY_SSL_AUTO_CLIENT_CERT, 210 C_PROXY_TLS13_CIPHERS, 211 C_PROXY_TLSAUTHTYPE, 212 C_PROXY_TLSPASSWORD, 213 C_PROXY_TLSUSER, 214 C_PROXY_TLSV1, 215 C_PROXY_USER, 216 C_PROXY1_0, 217 C_PROXYTUNNEL, 218 C_PUBKEY, 219 C_QUOTE, 220 C_RANDOM_FILE, 221 C_RANGE, 222 C_RATE, 223 C_RAW, 224 C_REFERER, 225 C_REMOTE_HEADER_NAME, 226 C_REMOTE_NAME, 227 C_REMOTE_NAME_ALL, 228 C_REMOTE_TIME, 229 C_REMOVE_ON_ERROR, 230 C_REQUEST, 231 C_REQUEST_TARGET, 232 C_RESOLVE, 233 C_RETRY, 234 C_RETRY_ALL_ERRORS, 235 C_RETRY_CONNREFUSED, 236 C_RETRY_DELAY, 237 C_RETRY_MAX_TIME, 238 C_SASL_AUTHZID, 239 C_SASL_IR, 240 C_SERVICE_NAME, 241 C_SESSIONID, 242 C_SHOW_ERROR, 243 C_SHOW_HEADERS, 244 C_SILENT, 245 C_SKIP_EXISTING, 246 C_SOCKS4, 247 C_SOCKS4A, 248 C_SOCKS5, 249 C_SOCKS5_BASIC, 250 C_SOCKS5_GSSAPI, 251 C_SOCKS5_GSSAPI_NEC, 252 C_SOCKS5_GSSAPI_SERVICE, 253 C_SOCKS5_HOSTNAME, 254 C_SPEED_LIMIT, 255 C_SPEED_TIME, 256 C_SSL, 257 C_SSL_ALLOW_BEAST, 258 C_SSL_AUTO_CLIENT_CERT, 259 C_SSL_NO_REVOKE, 260 C_SSL_REQD, 261 C_SSL_REVOKE_BEST_EFFORT, 262 C_SSLV2, 263 C_SSLV3, 264 C_STDERR, 265 C_STYLED_OUTPUT, 266 C_SUPPRESS_CONNECT_HEADERS, 267 C_TCP_FASTOPEN, 268 C_TCP_NODELAY, 269 C_TELNET_OPTION, 270 C_TEST_DUPHANDLE, 271 C_TEST_EVENT, 272 C_TFTP_BLKSIZE, 273 C_TFTP_NO_OPTIONS, 274 C_TIME_COND, 275 C_TLS_EARLYDATA, 276 C_TLS_MAX, 277 C_TLS13_CIPHERS, 278 C_TLSAUTHTYPE, 279 C_TLSPASSWORD, 280 C_TLSUSER, 281 C_TLSV1, 282 C_TLSV1_0, 283 C_TLSV1_1, 284 C_TLSV1_2, 285 C_TLSV1_3, 286 C_TR_ENCODING, 287 C_TRACE, 288 C_TRACE_ASCII, 289 C_TRACE_CONFIG, 290 C_TRACE_IDS, 291 C_TRACE_TIME, 292 C_IP_TOS, 293 C_UNIX_SOCKET, 294 C_UPLOAD_FILE, 295 C_URL, 296 C_URL_QUERY, 297 C_USE_ASCII, 298 C_USER, 299 C_USER_AGENT, 300 C_VARIABLE, 301 C_VERBOSE, 302 C_VERSION, 303 C_VLAN_PRIORITY, 304 C_WDEBUG, 305 C_WRITE_OUT, 306 C_XATTR 307 } cmdline_t; 308 309 #define ARG_NONE 0 /* stand-alone but not a boolean */ 310 #define ARG_BOOL 1 /* accepts a --no-[name] prefix */ 311 #define ARG_STRG 2 /* requires an argument */ 312 #define ARG_FILE 3 /* requires an argument, usually a filename */ 313 314 #define ARG_TYPEMASK 0x03 315 #define ARGTYPE(x) ((x) & ARG_TYPEMASK) 316 317 #define ARG_NO 0x80 /* set if the option is documented as --no-* */ 318 319 struct LongShort { 320 const char *lname; /* long name option */ 321 unsigned char desc; /* type, see ARG_* */ 322 char letter; /* short name option or ' ' */ 323 unsigned short cmd; 324 }; 325 326 typedef enum { 327 PARAM_OK = 0, 328 PARAM_OPTION_AMBIGUOUS, 329 PARAM_OPTION_UNKNOWN, 330 PARAM_REQUIRES_PARAMETER, 331 PARAM_BAD_USE, 332 PARAM_HELP_REQUESTED, 333 PARAM_MANUAL_REQUESTED, 334 PARAM_VERSION_INFO_REQUESTED, 335 PARAM_ENGINES_REQUESTED, 336 PARAM_CA_EMBED_REQUESTED, 337 PARAM_GOT_EXTRA_PARAMETER, 338 PARAM_BAD_NUMERIC, 339 PARAM_NEGATIVE_NUMERIC, 340 PARAM_LIBCURL_DOESNT_SUPPORT, 341 PARAM_LIBCURL_UNSUPPORTED_PROTOCOL, 342 PARAM_NO_MEM, 343 PARAM_NEXT_OPERATION, 344 PARAM_NO_PREFIX, 345 PARAM_NUMBER_TOO_LARGE, 346 PARAM_NO_NOT_BOOLEAN, 347 PARAM_CONTDISP_RESUME_FROM, /* --continue-at and --remote-header-name */ 348 PARAM_READ_ERROR, 349 PARAM_EXPAND_ERROR, /* --expand problem */ 350 PARAM_BLANK_STRING, 351 PARAM_VAR_SYNTAX, /* --variable syntax error */ 352 PARAM_LAST 353 } ParameterError; 354 355 struct GlobalConfig; 356 struct OperationConfig; 357 358 const struct LongShort *findlongopt(const char *opt); 359 const struct LongShort *findshortopt(char letter); 360 361 ParameterError getparameter(const char *flag, char *nextarg, 362 argv_item_t cleararg, 363 bool *usedarg, 364 struct GlobalConfig *global, 365 struct OperationConfig *operation); 366 367 #ifdef UNITTESTS 368 void parse_cert_parameter(const char *cert_parameter, 369 char **certname, 370 char **passphrase); 371 #endif 372 373 ParameterError parse_args(struct GlobalConfig *config, int argc, 374 argv_item_t argv[]); 375 376 #endif /* HEADER_CURL_TOOL_GETPARAM_H */ 377