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