1 #ifndef HEADER_CURL_TOOL_SETOPT_H 2 #define HEADER_CURL_TOOL_SETOPT_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 #include "tool_formparse.h" 29 30 /* 31 * Macros used in operate() 32 */ 33 34 #define SETOPT_CHECK(v,opt) do { \ 35 result = (v); \ 36 } while(0) 37 38 #ifndef CURL_DISABLE_LIBCURL_OPTION 39 40 /* Associate symbolic names with option values */ 41 struct NameValue { 42 const char *name; 43 long value; 44 }; 45 46 struct NameValueUnsigned { 47 const char *name; 48 unsigned long value; 49 }; 50 51 extern const struct NameValue setopt_nv_CURLPROXY[]; 52 extern const struct NameValue setopt_nv_CURL_SOCKS_PROXY[]; 53 extern const struct NameValue setopt_nv_CURL_HTTP_VERSION[]; 54 extern const struct NameValue setopt_nv_CURL_SSLVERSION[]; 55 extern const struct NameValue setopt_nv_CURL_SSLVERSION_MAX[]; 56 extern const struct NameValue setopt_nv_CURL_TIMECOND[]; 57 extern const struct NameValue setopt_nv_CURLFTPSSL_CCC[]; 58 extern const struct NameValue setopt_nv_CURLUSESSL[]; 59 extern const struct NameValueUnsigned setopt_nv_CURLSSLOPT[]; 60 extern const struct NameValue setopt_nv_CURL_NETRC[]; 61 extern const struct NameValueUnsigned setopt_nv_CURLAUTH[]; 62 extern const struct NameValueUnsigned setopt_nv_CURLHSTS[]; 63 64 /* Map options to NameValue sets */ 65 #define setopt_nv_CURLOPT_HSTS_CTRL setopt_nv_CURLHSTS 66 #define setopt_nv_CURLOPT_HTTP_VERSION setopt_nv_CURL_HTTP_VERSION 67 #define setopt_nv_CURLOPT_HTTPAUTH setopt_nv_CURLAUTH 68 #define setopt_nv_CURLOPT_SSLVERSION setopt_nv_CURL_SSLVERSION 69 #define setopt_nv_CURLOPT_PROXY_SSLVERSION setopt_nv_CURL_SSLVERSION 70 #define setopt_nv_CURLOPT_TIMECONDITION setopt_nv_CURL_TIMECOND 71 #define setopt_nv_CURLOPT_FTP_SSL_CCC setopt_nv_CURLFTPSSL_CCC 72 #define setopt_nv_CURLOPT_USE_SSL setopt_nv_CURLUSESSL 73 #define setopt_nv_CURLOPT_SSL_OPTIONS setopt_nv_CURLSSLOPT 74 #define setopt_nv_CURLOPT_PROXY_SSL_OPTIONS setopt_nv_CURLSSLOPT 75 #define setopt_nv_CURLOPT_NETRC setopt_nv_CURL_NETRC 76 #define setopt_nv_CURLOPT_PROXYTYPE setopt_nv_CURLPROXY 77 #define setopt_nv_CURLOPT_PROXYAUTH setopt_nv_CURLAUTH 78 #define setopt_nv_CURLOPT_SOCKS5_AUTH setopt_nv_CURLAUTH 79 80 /* Intercept setopt calls for --libcurl */ 81 82 CURLcode tool_setopt_enum(CURL *curl, struct GlobalConfig *config, 83 const char *name, CURLoption tag, 84 const struct NameValue *nv, long lval); 85 CURLcode tool_setopt_SSLVERSION(CURL *curl, struct GlobalConfig *config, 86 const char *name, CURLoption tag, 87 long lval); 88 CURLcode tool_setopt_flags(CURL *curl, struct GlobalConfig *config, 89 const char *name, CURLoption tag, 90 const struct NameValue *nv, long lval); 91 CURLcode tool_setopt_bitmask(CURL *curl, struct GlobalConfig *config, 92 const char *name, CURLoption tag, 93 const struct NameValueUnsigned *nv, long lval); 94 CURLcode tool_setopt_mimepost(CURL *curl, struct GlobalConfig *config, 95 const char *name, CURLoption tag, 96 curl_mime *mimepost); 97 CURLcode tool_setopt_slist(CURL *curl, struct GlobalConfig *config, 98 const char *name, CURLoption tag, 99 struct curl_slist *list); 100 CURLcode tool_setopt(CURL *curl, bool str, struct GlobalConfig *global, 101 struct OperationConfig *config, 102 const char *name, CURLoption tag, ...); 103 104 #define my_setopt(x,y,z) \ 105 SETOPT_CHECK(tool_setopt(x, FALSE, global, config, #y, y, z), y) 106 107 #define my_setopt_str(x,y,z) \ 108 SETOPT_CHECK(tool_setopt(x, TRUE, global, config, #y, y, z), y) 109 110 #define my_setopt_enum(x,y,z) \ 111 SETOPT_CHECK(tool_setopt_enum(x, global, #y, y, setopt_nv_ ## y, z), y) 112 113 #define my_setopt_SSLVERSION(x,y,z) \ 114 SETOPT_CHECK(tool_setopt_SSLVERSION(x, global, #y, y, z), y) 115 116 #define my_setopt_bitmask(x,y,z) \ 117 SETOPT_CHECK(tool_setopt_bitmask(x, global, #y, y, setopt_nv_ ## y, z), y) 118 119 #define my_setopt_mimepost(x,y,z) \ 120 SETOPT_CHECK(tool_setopt_mimepost(x, global, #y, y, z), y) 121 122 #define my_setopt_slist(x,y,z) \ 123 SETOPT_CHECK(tool_setopt_slist(x, global, #y, y, z), y) 124 125 #define res_setopt(x,y,z) tool_setopt(x, FALSE, global, config, #y, y, z) 126 127 #define res_setopt_str(x,y,z) tool_setopt(x, TRUE, global, config, #y, y, z) 128 129 #else /* CURL_DISABLE_LIBCURL_OPTION */ 130 131 /* No --libcurl, so pass options directly to library */ 132 133 #define my_setopt(x,y,z) \ 134 SETOPT_CHECK(curl_easy_setopt(x, y, z), y) 135 136 #define my_setopt_str(x,y,z) \ 137 SETOPT_CHECK(curl_easy_setopt(x, y, z), y) 138 139 #define my_setopt_enum(x,y,z) \ 140 SETOPT_CHECK(curl_easy_setopt(x, y, z), y) 141 142 #define my_setopt_SSLVERSION(x,y,z) \ 143 SETOPT_CHECK(curl_easy_setopt(x, y, z), y) 144 145 #define my_setopt_bitmask(x,y,z) \ 146 SETOPT_CHECK(curl_easy_setopt(x, y, z), y) 147 148 #define my_setopt_mimepost(x,y,z) \ 149 SETOPT_CHECK(curl_easy_setopt(x, y, z), y) 150 151 #define my_setopt_slist(x,y,z) \ 152 SETOPT_CHECK(curl_easy_setopt(x, y, z), y) 153 154 #define res_setopt(x,y,z) curl_easy_setopt(x,y,z) 155 156 #define res_setopt_str(x,y,z) curl_easy_setopt(x,y,z) 157 158 #endif /* CURL_DISABLE_LIBCURL_OPTION */ 159 160 #endif /* HEADER_CURL_TOOL_SETOPT_H */ 161