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