• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef __CURL_TYPECHECK_GCC_H
2 #define __CURL_TYPECHECK_GCC_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 
25 /* wraps curl_easy_setopt() with typechecking */
26 
27 /* To add a new kind of warning, add an
28  *   if(_curl_is_sometype_option(_curl_opt))
29  *     if(!_curl_is_sometype(value))
30  *       _curl_easy_setopt_err_sometype();
31  * block and define _curl_is_sometype_option, _curl_is_sometype and
32  * _curl_easy_setopt_err_sometype below
33  *
34  * NOTE: We use two nested 'if' statements here instead of the && operator, in
35  *       order to work around gcc bug #32061.  It affects only gcc 4.3.x/4.4.x
36  *       when compiling with -Wlogical-op.
37  *
38  * To add an option that uses the same type as an existing option, you'll just
39  * need to extend the appropriate _curl_*_option macro
40  */
41 #define curl_easy_setopt(handle, option, value)                               \
42 __extension__ ({                                                              \
43   __typeof__(option) _curl_opt = option;                                     \
44   if(__builtin_constant_p(_curl_opt)) {                                       \
45     if(_curl_is_long_option(_curl_opt))                                       \
46       if(!_curl_is_long(value))                                               \
47         _curl_easy_setopt_err_long();                                         \
48     if(_curl_is_off_t_option(_curl_opt))                                      \
49       if(!_curl_is_off_t(value))                                              \
50         _curl_easy_setopt_err_curl_off_t();                                   \
51     if(_curl_is_string_option(_curl_opt))                                     \
52       if(!_curl_is_string(value))                                             \
53         _curl_easy_setopt_err_string();                                       \
54     if(_curl_is_write_cb_option(_curl_opt))                                   \
55       if(!_curl_is_write_cb(value))                                           \
56         _curl_easy_setopt_err_write_callback();                               \
57     if((_curl_opt) == CURLOPT_RESOLVER_START_FUNCTION)                        \
58       if(!_curl_is_resolver_start_callback(value))                            \
59         _curl_easy_setopt_err_resolver_start_callback();                      \
60     if((_curl_opt) == CURLOPT_READFUNCTION)                                   \
61       if(!_curl_is_read_cb(value))                                            \
62         _curl_easy_setopt_err_read_cb();                                      \
63     if((_curl_opt) == CURLOPT_IOCTLFUNCTION)                                  \
64       if(!_curl_is_ioctl_cb(value))                                           \
65         _curl_easy_setopt_err_ioctl_cb();                                     \
66     if((_curl_opt) == CURLOPT_SOCKOPTFUNCTION)                                \
67       if(!_curl_is_sockopt_cb(value))                                         \
68         _curl_easy_setopt_err_sockopt_cb();                                   \
69     if((_curl_opt) == CURLOPT_OPENSOCKETFUNCTION)                             \
70       if(!_curl_is_opensocket_cb(value))                                      \
71         _curl_easy_setopt_err_opensocket_cb();                                \
72     if((_curl_opt) == CURLOPT_PROGRESSFUNCTION)                               \
73       if(!_curl_is_progress_cb(value))                                        \
74         _curl_easy_setopt_err_progress_cb();                                  \
75     if((_curl_opt) == CURLOPT_DEBUGFUNCTION)                                  \
76       if(!_curl_is_debug_cb(value))                                           \
77         _curl_easy_setopt_err_debug_cb();                                     \
78     if((_curl_opt) == CURLOPT_SSL_CTX_FUNCTION)                               \
79       if(!_curl_is_ssl_ctx_cb(value))                                         \
80         _curl_easy_setopt_err_ssl_ctx_cb();                                   \
81     if(_curl_is_conv_cb_option(_curl_opt))                                    \
82       if(!_curl_is_conv_cb(value))                                            \
83         _curl_easy_setopt_err_conv_cb();                                      \
84     if((_curl_opt) == CURLOPT_SEEKFUNCTION)                                   \
85       if(!_curl_is_seek_cb(value))                                            \
86         _curl_easy_setopt_err_seek_cb();                                      \
87     if(_curl_is_cb_data_option(_curl_opt))                                    \
88       if(!_curl_is_cb_data(value))                                            \
89         _curl_easy_setopt_err_cb_data();                                      \
90     if((_curl_opt) == CURLOPT_ERRORBUFFER)                                    \
91       if(!_curl_is_error_buffer(value))                                       \
92         _curl_easy_setopt_err_error_buffer();                                 \
93     if((_curl_opt) == CURLOPT_STDERR)                                         \
94       if(!_curl_is_FILE(value))                                               \
95         _curl_easy_setopt_err_FILE();                                         \
96     if(_curl_is_postfields_option(_curl_opt))                                 \
97       if(!_curl_is_postfields(value))                                         \
98         _curl_easy_setopt_err_postfields();                                   \
99     if((_curl_opt) == CURLOPT_HTTPPOST)                                       \
100       if(!_curl_is_arr((value), struct curl_httppost))                        \
101         _curl_easy_setopt_err_curl_httpost();                                 \
102     if((_curl_opt) == CURLOPT_MIMEPOST)                                       \
103       if(!_curl_is_ptr((value), curl_mime))                                   \
104         _curl_easy_setopt_err_curl_mimepost();                                \
105     if(_curl_is_slist_option(_curl_opt))                                      \
106       if(!_curl_is_arr((value), struct curl_slist))                           \
107         _curl_easy_setopt_err_curl_slist();                                   \
108     if((_curl_opt) == CURLOPT_SHARE)                                          \
109       if(!_curl_is_ptr((value), CURLSH))                                      \
110         _curl_easy_setopt_err_CURLSH();                                       \
111   }                                                                           \
112   curl_easy_setopt(handle, _curl_opt, value);                                 \
113 })
114 
115 /* wraps curl_easy_getinfo() with typechecking */
116 /* FIXME: don't allow const pointers */
117 #define curl_easy_getinfo(handle, info, arg)                                  \
118 __extension__ ({                                                              \
119   __typeof__(info) _curl_info = info;                                         \
120   if(__builtin_constant_p(_curl_info)) {                                      \
121     if(_curl_is_string_info(_curl_info))                                      \
122       if(!_curl_is_arr((arg), char *))                                        \
123         _curl_easy_getinfo_err_string();                                      \
124     if(_curl_is_long_info(_curl_info))                                        \
125       if(!_curl_is_arr((arg), long))                                          \
126         _curl_easy_getinfo_err_long();                                        \
127     if(_curl_is_double_info(_curl_info))                                      \
128       if(!_curl_is_arr((arg), double))                                        \
129         _curl_easy_getinfo_err_double();                                      \
130     if(_curl_is_slist_info(_curl_info))                                       \
131       if(!_curl_is_arr((arg), struct curl_slist *))                           \
132         _curl_easy_getinfo_err_curl_slist();                                  \
133     if(_curl_is_tlssessioninfo_info(_curl_info))                              \
134       if(!_curl_is_arr((arg), struct curl_tlssessioninfo *))                  \
135         _curl_easy_getinfo_err_curl_tlssesssioninfo();                        \
136     if(_curl_is_certinfo_info(_curl_info))                                    \
137       if(!_curl_is_arr((arg), struct curl_certinfo *))                        \
138         _curl_easy_getinfo_err_curl_certinfo();                               \
139     if(_curl_is_socket_info(_curl_info))                                      \
140       if(!_curl_is_arr((arg), curl_socket_t))                                 \
141         _curl_easy_getinfo_err_curl_socket();                                 \
142     if(_curl_is_off_t_info(_curl_info))                                       \
143       if(!_curl_is_arr((arg), curl_off_t))                                    \
144         _curl_easy_getinfo_err_curl_off_t();                                  \
145   }                                                                           \
146   curl_easy_getinfo(handle, _curl_info, arg);                                 \
147 })
148 
149 /* TODO: typechecking for curl_share_setopt() and curl_multi_setopt(),
150  * for now just make sure that the functions are called with three
151  * arguments
152  */
153 #define curl_share_setopt(share,opt,param) curl_share_setopt(share,opt,param)
154 #define curl_multi_setopt(handle,opt,param) curl_multi_setopt(handle,opt,param)
155 
156 
157 /* the actual warnings, triggered by calling the _curl_easy_setopt_err*
158  * functions */
159 
160 /* To define a new warning, use _CURL_WARNING(identifier, "message") */
161 #define _CURL_WARNING(id, message)                                            \
162   static void __attribute__((__warning__(message)))                           \
163   __attribute__((__unused__)) __attribute__((__noinline__))                   \
164   id(void) { __asm__(""); }
165 
166 _CURL_WARNING(_curl_easy_setopt_err_long,
167   "curl_easy_setopt expects a long argument for this option")
168 _CURL_WARNING(_curl_easy_setopt_err_curl_off_t,
169   "curl_easy_setopt expects a curl_off_t argument for this option")
170 _CURL_WARNING(_curl_easy_setopt_err_string,
171               "curl_easy_setopt expects a "
172               "string ('char *' or char[]) argument for this option"
173   )
174 _CURL_WARNING(_curl_easy_setopt_err_write_callback,
175   "curl_easy_setopt expects a curl_write_callback argument for this option")
176 _CURL_WARNING(_curl_easy_setopt_err_resolver_start_callback,
177               "curl_easy_setopt expects a "
178               "curl_resolver_start_callback argument for this option"
179   )
180 _CURL_WARNING(_curl_easy_setopt_err_read_cb,
181   "curl_easy_setopt expects a curl_read_callback argument for this option")
182 _CURL_WARNING(_curl_easy_setopt_err_ioctl_cb,
183   "curl_easy_setopt expects a curl_ioctl_callback argument for this option")
184 _CURL_WARNING(_curl_easy_setopt_err_sockopt_cb,
185   "curl_easy_setopt expects a curl_sockopt_callback argument for this option")
186 _CURL_WARNING(_curl_easy_setopt_err_opensocket_cb,
187               "curl_easy_setopt expects a "
188               "curl_opensocket_callback argument for this option"
189   )
190 _CURL_WARNING(_curl_easy_setopt_err_progress_cb,
191   "curl_easy_setopt expects a curl_progress_callback argument for this option")
192 _CURL_WARNING(_curl_easy_setopt_err_debug_cb,
193   "curl_easy_setopt expects a curl_debug_callback argument for this option")
194 _CURL_WARNING(_curl_easy_setopt_err_ssl_ctx_cb,
195   "curl_easy_setopt expects a curl_ssl_ctx_callback argument for this option")
196 _CURL_WARNING(_curl_easy_setopt_err_conv_cb,
197   "curl_easy_setopt expects a curl_conv_callback argument for this option")
198 _CURL_WARNING(_curl_easy_setopt_err_seek_cb,
199   "curl_easy_setopt expects a curl_seek_callback argument for this option")
200 _CURL_WARNING(_curl_easy_setopt_err_cb_data,
201               "curl_easy_setopt expects a "
202               "private data pointer as argument for this option")
203 _CURL_WARNING(_curl_easy_setopt_err_error_buffer,
204               "curl_easy_setopt expects a "
205               "char buffer of CURL_ERROR_SIZE as argument for this option")
206 _CURL_WARNING(_curl_easy_setopt_err_FILE,
207   "curl_easy_setopt expects a 'FILE *' argument for this option")
208 _CURL_WARNING(_curl_easy_setopt_err_postfields,
209   "curl_easy_setopt expects a 'void *' or 'char *' argument for this option")
210 _CURL_WARNING(_curl_easy_setopt_err_curl_httpost,
211               "curl_easy_setopt expects a 'struct curl_httppost *' "
212               "argument for this option")
213 _CURL_WARNING(_curl_easy_setopt_err_curl_mimepost,
214               "curl_easy_setopt expects a 'curl_mime *' "
215               "argument for this option")
216 _CURL_WARNING(_curl_easy_setopt_err_curl_slist,
217   "curl_easy_setopt expects a 'struct curl_slist *' argument for this option")
218 _CURL_WARNING(_curl_easy_setopt_err_CURLSH,
219   "curl_easy_setopt expects a CURLSH* argument for this option")
220 
221 _CURL_WARNING(_curl_easy_getinfo_err_string,
222   "curl_easy_getinfo expects a pointer to 'char *' for this info")
223 _CURL_WARNING(_curl_easy_getinfo_err_long,
224   "curl_easy_getinfo expects a pointer to long for this info")
225 _CURL_WARNING(_curl_easy_getinfo_err_double,
226   "curl_easy_getinfo expects a pointer to double for this info")
227 _CURL_WARNING(_curl_easy_getinfo_err_curl_slist,
228   "curl_easy_getinfo expects a pointer to 'struct curl_slist *' for this info")
229 _CURL_WARNING(_curl_easy_getinfo_err_curl_tlssesssioninfo,
230               "curl_easy_getinfo expects a pointer to "
231               "'struct curl_tlssessioninfo *' for this info")
232 _CURL_WARNING(_curl_easy_getinfo_err_curl_certinfo,
233               "curl_easy_getinfo expects a pointer to "
234               "'struct curl_certinfo *' for this info")
235 _CURL_WARNING(_curl_easy_getinfo_err_curl_socket,
236   "curl_easy_getinfo expects a pointer to curl_socket_t for this info")
237 _CURL_WARNING(_curl_easy_getinfo_err_curl_off_t,
238   "curl_easy_getinfo expects a pointer to curl_off_t for this info")
239 
240 /* groups of curl_easy_setops options that take the same type of argument */
241 
242 /* To add a new option to one of the groups, just add
243  *   (option) == CURLOPT_SOMETHING
244  * to the or-expression. If the option takes a long or curl_off_t, you don't
245  * have to do anything
246  */
247 
248 /* evaluates to true if option takes a long argument */
249 #define _curl_is_long_option(option)                                          \
250   (0 < (option) && (option) < CURLOPTTYPE_OBJECTPOINT)
251 
252 #define _curl_is_off_t_option(option)                                         \
253   ((option) > CURLOPTTYPE_OFF_T)
254 
255 /* evaluates to true if option takes a char* argument */
256 #define _curl_is_string_option(option)                                        \
257   ((option) == CURLOPT_ABSTRACT_UNIX_SOCKET ||                                \
258    (option) == CURLOPT_ACCEPT_ENCODING ||                                     \
259    (option) == CURLOPT_ALTSVC ||                                              \
260    (option) == CURLOPT_CAINFO ||                                              \
261    (option) == CURLOPT_CAPATH ||                                              \
262    (option) == CURLOPT_COOKIE ||                                              \
263    (option) == CURLOPT_COOKIEFILE ||                                          \
264    (option) == CURLOPT_COOKIEJAR ||                                           \
265    (option) == CURLOPT_COOKIELIST ||                                          \
266    (option) == CURLOPT_CRLFILE ||                                             \
267    (option) == CURLOPT_CUSTOMREQUEST ||                                       \
268    (option) == CURLOPT_DEFAULT_PROTOCOL ||                                    \
269    (option) == CURLOPT_DNS_INTERFACE ||                                       \
270    (option) == CURLOPT_DNS_LOCAL_IP4 ||                                       \
271    (option) == CURLOPT_DNS_LOCAL_IP6 ||                                       \
272    (option) == CURLOPT_DNS_SERVERS ||                                         \
273    (option) == CURLOPT_DOH_URL ||                                             \
274    (option) == CURLOPT_EGDSOCKET ||                                           \
275    (option) == CURLOPT_FTPPORT ||                                             \
276    (option) == CURLOPT_FTP_ACCOUNT ||                                         \
277    (option) == CURLOPT_FTP_ALTERNATIVE_TO_USER ||                             \
278    (option) == CURLOPT_INTERFACE ||                                           \
279    (option) == CURLOPT_ISSUERCERT ||                                          \
280    (option) == CURLOPT_KEYPASSWD ||                                           \
281    (option) == CURLOPT_KRBLEVEL ||                                            \
282    (option) == CURLOPT_LOGIN_OPTIONS ||                                       \
283    (option) == CURLOPT_MAIL_AUTH ||                                           \
284    (option) == CURLOPT_MAIL_FROM ||                                           \
285    (option) == CURLOPT_NETRC_FILE ||                                          \
286    (option) == CURLOPT_NOPROXY ||                                             \
287    (option) == CURLOPT_PASSWORD ||                                            \
288    (option) == CURLOPT_PINNEDPUBLICKEY ||                                     \
289    (option) == CURLOPT_PRE_PROXY ||                                           \
290    (option) == CURLOPT_PROXY ||                                               \
291    (option) == CURLOPT_PROXYPASSWORD ||                                       \
292    (option) == CURLOPT_PROXYUSERNAME ||                                       \
293    (option) == CURLOPT_PROXYUSERPWD ||                                        \
294    (option) == CURLOPT_PROXY_CAINFO ||                                        \
295    (option) == CURLOPT_PROXY_CAPATH ||                                        \
296    (option) == CURLOPT_PROXY_CRLFILE ||                                       \
297    (option) == CURLOPT_PROXY_KEYPASSWD ||                                     \
298    (option) == CURLOPT_PROXY_PINNEDPUBLICKEY ||                               \
299    (option) == CURLOPT_PROXY_SERVICE_NAME ||                                  \
300    (option) == CURLOPT_PROXY_SSLCERT ||                                       \
301    (option) == CURLOPT_PROXY_SSLCERTTYPE ||                                   \
302    (option) == CURLOPT_PROXY_SSLKEY ||                                        \
303    (option) == CURLOPT_PROXY_SSLKEYTYPE ||                                    \
304    (option) == CURLOPT_PROXY_SSL_CIPHER_LIST ||                               \
305    (option) == CURLOPT_PROXY_TLSAUTH_PASSWORD ||                              \
306    (option) == CURLOPT_PROXY_TLSAUTH_USERNAME ||                              \
307    (option) == CURLOPT_PROXY_TLSAUTH_TYPE ||                                  \
308    (option) == CURLOPT_RANDOM_FILE ||                                         \
309    (option) == CURLOPT_RANGE ||                                               \
310    (option) == CURLOPT_REFERER ||                                             \
311    (option) == CURLOPT_RTSP_SESSION_ID ||                                     \
312    (option) == CURLOPT_RTSP_STREAM_URI ||                                     \
313    (option) == CURLOPT_RTSP_TRANSPORT ||                                      \
314    (option) == CURLOPT_SERVICE_NAME ||                                        \
315    (option) == CURLOPT_SOCKS5_GSSAPI_SERVICE ||                               \
316    (option) == CURLOPT_SSH_HOST_PUBLIC_KEY_MD5 ||                             \
317    (option) == CURLOPT_SSH_KNOWNHOSTS ||                                      \
318    (option) == CURLOPT_SSH_PRIVATE_KEYFILE ||                                 \
319    (option) == CURLOPT_SSH_PUBLIC_KEYFILE ||                                  \
320    (option) == CURLOPT_SSLCERT ||                                             \
321    (option) == CURLOPT_SSLCERTTYPE ||                                         \
322    (option) == CURLOPT_SSLENGINE ||                                           \
323    (option) == CURLOPT_SSLKEY ||                                              \
324    (option) == CURLOPT_SSLKEYTYPE ||                                          \
325    (option) == CURLOPT_SSL_CIPHER_LIST ||                                     \
326    (option) == CURLOPT_TLSAUTH_PASSWORD ||                                    \
327    (option) == CURLOPT_TLSAUTH_TYPE ||                                        \
328    (option) == CURLOPT_TLSAUTH_USERNAME ||                                    \
329    (option) == CURLOPT_UNIX_SOCKET_PATH ||                                    \
330    (option) == CURLOPT_URL ||                                                 \
331    (option) == CURLOPT_USERAGENT ||                                           \
332    (option) == CURLOPT_USERNAME ||                                            \
333    (option) == CURLOPT_USERPWD ||                                             \
334    (option) == CURLOPT_XOAUTH2_BEARER ||                                      \
335    0)
336 
337 /* evaluates to true if option takes a curl_write_callback argument */
338 #define _curl_is_write_cb_option(option)                                      \
339   ((option) == CURLOPT_HEADERFUNCTION ||                                      \
340    (option) == CURLOPT_WRITEFUNCTION)
341 
342 /* evaluates to true if option takes a curl_conv_callback argument */
343 #define _curl_is_conv_cb_option(option)                                       \
344   ((option) == CURLOPT_CONV_TO_NETWORK_FUNCTION ||                            \
345    (option) == CURLOPT_CONV_FROM_NETWORK_FUNCTION ||                          \
346    (option) == CURLOPT_CONV_FROM_UTF8_FUNCTION)
347 
348 /* evaluates to true if option takes a data argument to pass to a callback */
349 #define _curl_is_cb_data_option(option)                                       \
350   ((option) == CURLOPT_CHUNK_DATA ||                                          \
351    (option) == CURLOPT_CLOSESOCKETDATA ||                                     \
352    (option) == CURLOPT_DEBUGDATA ||                                           \
353    (option) == CURLOPT_FNMATCH_DATA ||                                        \
354    (option) == CURLOPT_HEADERDATA ||                                          \
355    (option) == CURLOPT_INTERLEAVEDATA ||                                      \
356    (option) == CURLOPT_IOCTLDATA ||                                           \
357    (option) == CURLOPT_OPENSOCKETDATA ||                                      \
358    (option) == CURLOPT_PRIVATE ||                                             \
359    (option) == CURLOPT_PROGRESSDATA ||                                        \
360    (option) == CURLOPT_READDATA ||                                            \
361    (option) == CURLOPT_SEEKDATA ||                                            \
362    (option) == CURLOPT_SOCKOPTDATA ||                                         \
363    (option) == CURLOPT_SSH_KEYDATA ||                                         \
364    (option) == CURLOPT_SSL_CTX_DATA ||                                        \
365    (option) == CURLOPT_WRITEDATA ||                                           \
366    (option) == CURLOPT_RESOLVER_START_DATA ||                                 \
367    (option) == CURLOPT_CURLU ||                                               \
368    0)
369 
370 /* evaluates to true if option takes a POST data argument (void* or char*) */
371 #define _curl_is_postfields_option(option)                                    \
372   ((option) == CURLOPT_POSTFIELDS ||                                          \
373    (option) == CURLOPT_COPYPOSTFIELDS ||                                      \
374    0)
375 
376 /* evaluates to true if option takes a struct curl_slist * argument */
377 #define _curl_is_slist_option(option)                                         \
378   ((option) == CURLOPT_HTTP200ALIASES ||                                      \
379    (option) == CURLOPT_HTTPHEADER ||                                          \
380    (option) == CURLOPT_MAIL_RCPT ||                                           \
381    (option) == CURLOPT_POSTQUOTE ||                                           \
382    (option) == CURLOPT_PREQUOTE ||                                            \
383    (option) == CURLOPT_PROXYHEADER ||                                         \
384    (option) == CURLOPT_QUOTE ||                                               \
385    (option) == CURLOPT_RESOLVE ||                                             \
386    (option) == CURLOPT_TELNETOPTIONS ||                                       \
387    0)
388 
389 /* groups of curl_easy_getinfo infos that take the same type of argument */
390 
391 /* evaluates to true if info expects a pointer to char * argument */
392 #define _curl_is_string_info(info)                                            \
393   (CURLINFO_STRING < (info) && (info) < CURLINFO_LONG)
394 
395 /* evaluates to true if info expects a pointer to long argument */
396 #define _curl_is_long_info(info)                                              \
397   (CURLINFO_LONG < (info) && (info) < CURLINFO_DOUBLE)
398 
399 /* evaluates to true if info expects a pointer to double argument */
400 #define _curl_is_double_info(info)                                            \
401   (CURLINFO_DOUBLE < (info) && (info) < CURLINFO_SLIST)
402 
403 /* true if info expects a pointer to struct curl_slist * argument */
404 #define _curl_is_slist_info(info)                                       \
405   (((info) == CURLINFO_SSL_ENGINES) || ((info) == CURLINFO_COOKIELIST))
406 
407 /* true if info expects a pointer to struct curl_tlssessioninfo * argument */
408 #define _curl_is_tlssessioninfo_info(info)                              \
409   (((info) == CURLINFO_TLS_SSL_PTR) || ((info) == CURLINFO_TLS_SESSION))
410 
411 /* true if info expects a pointer to struct curl_certinfo * argument */
412 #define _curl_is_certinfo_info(info) ((info) == CURLINFO_CERTINFO)
413 
414 /* true if info expects a pointer to struct curl_socket_t argument */
415 #define _curl_is_socket_info(info)                                            \
416   (CURLINFO_SOCKET < (info) && (info) < CURLINFO_OFF_T)
417 
418 /* true if info expects a pointer to curl_off_t argument */
419 #define _curl_is_off_t_info(info)                                             \
420   (CURLINFO_OFF_T < (info))
421 
422 
423 /* typecheck helpers -- check whether given expression has requested type*/
424 
425 /* For pointers, you can use the _curl_is_ptr/_curl_is_arr macros,
426  * otherwise define a new macro. Search for __builtin_types_compatible_p
427  * in the GCC manual.
428  * NOTE: these macros MUST NOT EVALUATE their arguments! The argument is
429  * the actual expression passed to the curl_easy_setopt macro. This
430  * means that you can only apply the sizeof and __typeof__ operators, no
431  * == or whatsoever.
432  */
433 
434 /* XXX: should evaluate to true if expr is a pointer */
435 #define _curl_is_any_ptr(expr)                                                \
436   (sizeof(expr) == sizeof(void *))
437 
438 /* evaluates to true if expr is NULL */
439 /* XXX: must not evaluate expr, so this check is not accurate */
440 #define _curl_is_NULL(expr)                                                   \
441   (__builtin_types_compatible_p(__typeof__(expr), __typeof__(NULL)))
442 
443 /* evaluates to true if expr is type*, const type* or NULL */
444 #define _curl_is_ptr(expr, type)                                              \
445   (_curl_is_NULL(expr) ||                                                     \
446    __builtin_types_compatible_p(__typeof__(expr), type *) ||                  \
447    __builtin_types_compatible_p(__typeof__(expr), const type *))
448 
449 /* evaluates to true if expr is one of type[], type*, NULL or const type* */
450 #define _curl_is_arr(expr, type)                                              \
451   (_curl_is_ptr((expr), type) ||                                              \
452    __builtin_types_compatible_p(__typeof__(expr), type []))
453 
454 /* evaluates to true if expr is a string */
455 #define _curl_is_string(expr)                                                 \
456   (_curl_is_arr((expr), char) ||                                              \
457    _curl_is_arr((expr), signed char) ||                                       \
458    _curl_is_arr((expr), unsigned char))
459 
460 /* evaluates to true if expr is a long (no matter the signedness)
461  * XXX: for now, int is also accepted (and therefore short and char, which
462  * are promoted to int when passed to a variadic function) */
463 #define _curl_is_long(expr)                                                   \
464   (__builtin_types_compatible_p(__typeof__(expr), long) ||                    \
465    __builtin_types_compatible_p(__typeof__(expr), signed long) ||             \
466    __builtin_types_compatible_p(__typeof__(expr), unsigned long) ||           \
467    __builtin_types_compatible_p(__typeof__(expr), int) ||                     \
468    __builtin_types_compatible_p(__typeof__(expr), signed int) ||              \
469    __builtin_types_compatible_p(__typeof__(expr), unsigned int) ||            \
470    __builtin_types_compatible_p(__typeof__(expr), short) ||                   \
471    __builtin_types_compatible_p(__typeof__(expr), signed short) ||            \
472    __builtin_types_compatible_p(__typeof__(expr), unsigned short) ||          \
473    __builtin_types_compatible_p(__typeof__(expr), char) ||                    \
474    __builtin_types_compatible_p(__typeof__(expr), signed char) ||             \
475    __builtin_types_compatible_p(__typeof__(expr), unsigned char))
476 
477 /* evaluates to true if expr is of type curl_off_t */
478 #define _curl_is_off_t(expr)                                                  \
479   (__builtin_types_compatible_p(__typeof__(expr), curl_off_t))
480 
481 /* evaluates to true if expr is abuffer suitable for CURLOPT_ERRORBUFFER */
482 /* XXX: also check size of an char[] array? */
483 #define _curl_is_error_buffer(expr)                                           \
484   (_curl_is_NULL(expr) ||                                                     \
485    __builtin_types_compatible_p(__typeof__(expr), char *) ||                  \
486    __builtin_types_compatible_p(__typeof__(expr), char[]))
487 
488 /* evaluates to true if expr is of type (const) void* or (const) FILE* */
489 #if 0
490 #define _curl_is_cb_data(expr)                                                \
491   (_curl_is_ptr((expr), void) ||                                              \
492    _curl_is_ptr((expr), FILE))
493 #else /* be less strict */
494 #define _curl_is_cb_data(expr)                                                \
495   _curl_is_any_ptr(expr)
496 #endif
497 
498 /* evaluates to true if expr is of type FILE* */
499 #define _curl_is_FILE(expr)                                             \
500   (_curl_is_NULL(expr) ||                                              \
501    (__builtin_types_compatible_p(__typeof__(expr), FILE *)))
502 
503 /* evaluates to true if expr can be passed as POST data (void* or char*) */
504 #define _curl_is_postfields(expr)                                             \
505   (_curl_is_ptr((expr), void) ||                                              \
506    _curl_is_arr((expr), char) ||                                              \
507    _curl_is_arr((expr), unsigned char))
508 
509 /* FIXME: the whole callback checking is messy...
510  * The idea is to tolerate char vs. void and const vs. not const
511  * pointers in arguments at least
512  */
513 /* helper: __builtin_types_compatible_p distinguishes between functions and
514  * function pointers, hide it */
515 #define _curl_callback_compatible(func, type)                                 \
516   (__builtin_types_compatible_p(__typeof__(func), type) ||                    \
517    __builtin_types_compatible_p(__typeof__(func) *, type))
518 
519 /* evaluates to true if expr is of type curl_resolver_start_callback */
520 #define _curl_is_resolver_start_callback(expr)       \
521   (_curl_is_NULL(expr) || \
522    _curl_callback_compatible((expr), curl_resolver_start_callback))
523 
524 /* evaluates to true if expr is of type curl_read_callback or "similar" */
525 #define _curl_is_read_cb(expr)                                          \
526   (_curl_is_NULL(expr) ||                                                     \
527    _curl_callback_compatible((expr), __typeof__(fread) *) ||                  \
528    _curl_callback_compatible((expr), curl_read_callback) ||                   \
529    _curl_callback_compatible((expr), _curl_read_callback1) ||                 \
530    _curl_callback_compatible((expr), _curl_read_callback2) ||                 \
531    _curl_callback_compatible((expr), _curl_read_callback3) ||                 \
532    _curl_callback_compatible((expr), _curl_read_callback4) ||                 \
533    _curl_callback_compatible((expr), _curl_read_callback5) ||                 \
534    _curl_callback_compatible((expr), _curl_read_callback6))
535 typedef size_t (*_curl_read_callback1)(char *, size_t, size_t, void *);
536 typedef size_t (*_curl_read_callback2)(char *, size_t, size_t, const void *);
537 typedef size_t (*_curl_read_callback3)(char *, size_t, size_t, FILE *);
538 typedef size_t (*_curl_read_callback4)(void *, size_t, size_t, void *);
539 typedef size_t (*_curl_read_callback5)(void *, size_t, size_t, const void *);
540 typedef size_t (*_curl_read_callback6)(void *, size_t, size_t, FILE *);
541 
542 /* evaluates to true if expr is of type curl_write_callback or "similar" */
543 #define _curl_is_write_cb(expr)                                               \
544   (_curl_is_read_cb(expr) ||                                            \
545    _curl_callback_compatible((expr), __typeof__(fwrite) *) ||                 \
546    _curl_callback_compatible((expr), curl_write_callback) ||                  \
547    _curl_callback_compatible((expr), _curl_write_callback1) ||                \
548    _curl_callback_compatible((expr), _curl_write_callback2) ||                \
549    _curl_callback_compatible((expr), _curl_write_callback3) ||                \
550    _curl_callback_compatible((expr), _curl_write_callback4) ||                \
551    _curl_callback_compatible((expr), _curl_write_callback5) ||                \
552    _curl_callback_compatible((expr), _curl_write_callback6))
553 typedef size_t (*_curl_write_callback1)(const char *, size_t, size_t, void *);
554 typedef size_t (*_curl_write_callback2)(const char *, size_t, size_t,
555                                        const void *);
556 typedef size_t (*_curl_write_callback3)(const char *, size_t, size_t, FILE *);
557 typedef size_t (*_curl_write_callback4)(const void *, size_t, size_t, void *);
558 typedef size_t (*_curl_write_callback5)(const void *, size_t, size_t,
559                                        const void *);
560 typedef size_t (*_curl_write_callback6)(const void *, size_t, size_t, FILE *);
561 
562 /* evaluates to true if expr is of type curl_ioctl_callback or "similar" */
563 #define _curl_is_ioctl_cb(expr)                                         \
564   (_curl_is_NULL(expr) ||                                                     \
565    _curl_callback_compatible((expr), curl_ioctl_callback) ||                  \
566    _curl_callback_compatible((expr), _curl_ioctl_callback1) ||                \
567    _curl_callback_compatible((expr), _curl_ioctl_callback2) ||                \
568    _curl_callback_compatible((expr), _curl_ioctl_callback3) ||                \
569    _curl_callback_compatible((expr), _curl_ioctl_callback4))
570 typedef curlioerr (*_curl_ioctl_callback1)(CURL *, int, void *);
571 typedef curlioerr (*_curl_ioctl_callback2)(CURL *, int, const void *);
572 typedef curlioerr (*_curl_ioctl_callback3)(CURL *, curliocmd, void *);
573 typedef curlioerr (*_curl_ioctl_callback4)(CURL *, curliocmd, const void *);
574 
575 /* evaluates to true if expr is of type curl_sockopt_callback or "similar" */
576 #define _curl_is_sockopt_cb(expr)                                       \
577   (_curl_is_NULL(expr) ||                                                     \
578    _curl_callback_compatible((expr), curl_sockopt_callback) ||                \
579    _curl_callback_compatible((expr), _curl_sockopt_callback1) ||              \
580    _curl_callback_compatible((expr), _curl_sockopt_callback2))
581 typedef int (*_curl_sockopt_callback1)(void *, curl_socket_t, curlsocktype);
582 typedef int (*_curl_sockopt_callback2)(const void *, curl_socket_t,
583                                       curlsocktype);
584 
585 /* evaluates to true if expr is of type curl_opensocket_callback or
586    "similar" */
587 #define _curl_is_opensocket_cb(expr)                                    \
588   (_curl_is_NULL(expr) ||                                                     \
589    _curl_callback_compatible((expr), curl_opensocket_callback) ||             \
590    _curl_callback_compatible((expr), _curl_opensocket_callback1) ||           \
591    _curl_callback_compatible((expr), _curl_opensocket_callback2) ||           \
592    _curl_callback_compatible((expr), _curl_opensocket_callback3) ||           \
593    _curl_callback_compatible((expr), _curl_opensocket_callback4))
594 typedef curl_socket_t (*_curl_opensocket_callback1)
595   (void *, curlsocktype, struct curl_sockaddr *);
596 typedef curl_socket_t (*_curl_opensocket_callback2)
597   (void *, curlsocktype, const struct curl_sockaddr *);
598 typedef curl_socket_t (*_curl_opensocket_callback3)
599   (const void *, curlsocktype, struct curl_sockaddr *);
600 typedef curl_socket_t (*_curl_opensocket_callback4)
601   (const void *, curlsocktype, const struct curl_sockaddr *);
602 
603 /* evaluates to true if expr is of type curl_progress_callback or "similar" */
604 #define _curl_is_progress_cb(expr)                                      \
605   (_curl_is_NULL(expr) ||                                                     \
606    _curl_callback_compatible((expr), curl_progress_callback) ||               \
607    _curl_callback_compatible((expr), _curl_progress_callback1) ||             \
608    _curl_callback_compatible((expr), _curl_progress_callback2))
609 typedef int (*_curl_progress_callback1)(void *,
610     double, double, double, double);
611 typedef int (*_curl_progress_callback2)(const void *,
612     double, double, double, double);
613 
614 /* evaluates to true if expr is of type curl_debug_callback or "similar" */
615 #define _curl_is_debug_cb(expr)                                         \
616   (_curl_is_NULL(expr) ||                                                     \
617    _curl_callback_compatible((expr), curl_debug_callback) ||                  \
618    _curl_callback_compatible((expr), _curl_debug_callback1) ||                \
619    _curl_callback_compatible((expr), _curl_debug_callback2) ||                \
620    _curl_callback_compatible((expr), _curl_debug_callback3) ||                \
621    _curl_callback_compatible((expr), _curl_debug_callback4) ||                \
622    _curl_callback_compatible((expr), _curl_debug_callback5) ||                \
623    _curl_callback_compatible((expr), _curl_debug_callback6) ||                \
624    _curl_callback_compatible((expr), _curl_debug_callback7) ||                \
625    _curl_callback_compatible((expr), _curl_debug_callback8))
626 typedef int (*_curl_debug_callback1) (CURL *,
627     curl_infotype, char *, size_t, void *);
628 typedef int (*_curl_debug_callback2) (CURL *,
629     curl_infotype, char *, size_t, const void *);
630 typedef int (*_curl_debug_callback3) (CURL *,
631     curl_infotype, const char *, size_t, void *);
632 typedef int (*_curl_debug_callback4) (CURL *,
633     curl_infotype, const char *, size_t, const void *);
634 typedef int (*_curl_debug_callback5) (CURL *,
635     curl_infotype, unsigned char *, size_t, void *);
636 typedef int (*_curl_debug_callback6) (CURL *,
637     curl_infotype, unsigned char *, size_t, const void *);
638 typedef int (*_curl_debug_callback7) (CURL *,
639     curl_infotype, const unsigned char *, size_t, void *);
640 typedef int (*_curl_debug_callback8) (CURL *,
641     curl_infotype, const unsigned char *, size_t, const void *);
642 
643 /* evaluates to true if expr is of type curl_ssl_ctx_callback or "similar" */
644 /* this is getting even messier... */
645 #define _curl_is_ssl_ctx_cb(expr)                                       \
646   (_curl_is_NULL(expr) ||                                                     \
647    _curl_callback_compatible((expr), curl_ssl_ctx_callback) ||                \
648    _curl_callback_compatible((expr), _curl_ssl_ctx_callback1) ||              \
649    _curl_callback_compatible((expr), _curl_ssl_ctx_callback2) ||              \
650    _curl_callback_compatible((expr), _curl_ssl_ctx_callback3) ||              \
651    _curl_callback_compatible((expr), _curl_ssl_ctx_callback4) ||              \
652    _curl_callback_compatible((expr), _curl_ssl_ctx_callback5) ||              \
653    _curl_callback_compatible((expr), _curl_ssl_ctx_callback6) ||              \
654    _curl_callback_compatible((expr), _curl_ssl_ctx_callback7) ||              \
655    _curl_callback_compatible((expr), _curl_ssl_ctx_callback8))
656 typedef CURLcode (*_curl_ssl_ctx_callback1)(CURL *, void *, void *);
657 typedef CURLcode (*_curl_ssl_ctx_callback2)(CURL *, void *, const void *);
658 typedef CURLcode (*_curl_ssl_ctx_callback3)(CURL *, const void *, void *);
659 typedef CURLcode (*_curl_ssl_ctx_callback4)(CURL *, const void *,
660                                             const void *);
661 #ifdef HEADER_SSL_H
662 /* hack: if we included OpenSSL's ssl.h, we know about SSL_CTX
663  * this will of course break if we're included before OpenSSL headers...
664  */
665 typedef CURLcode (*_curl_ssl_ctx_callback5)(CURL *, SSL_CTX, void *);
666 typedef CURLcode (*_curl_ssl_ctx_callback6)(CURL *, SSL_CTX, const void *);
667 typedef CURLcode (*_curl_ssl_ctx_callback7)(CURL *, const SSL_CTX, void *);
668 typedef CURLcode (*_curl_ssl_ctx_callback8)(CURL *, const SSL_CTX,
669                                            const void *);
670 #else
671 typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback5;
672 typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback6;
673 typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback7;
674 typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback8;
675 #endif
676 
677 /* evaluates to true if expr is of type curl_conv_callback or "similar" */
678 #define _curl_is_conv_cb(expr)                                          \
679   (_curl_is_NULL(expr) ||                                                     \
680    _curl_callback_compatible((expr), curl_conv_callback) ||                   \
681    _curl_callback_compatible((expr), _curl_conv_callback1) ||                 \
682    _curl_callback_compatible((expr), _curl_conv_callback2) ||                 \
683    _curl_callback_compatible((expr), _curl_conv_callback3) ||                 \
684    _curl_callback_compatible((expr), _curl_conv_callback4))
685 typedef CURLcode (*_curl_conv_callback1)(char *, size_t length);
686 typedef CURLcode (*_curl_conv_callback2)(const char *, size_t length);
687 typedef CURLcode (*_curl_conv_callback3)(void *, size_t length);
688 typedef CURLcode (*_curl_conv_callback4)(const void *, size_t length);
689 
690 /* evaluates to true if expr is of type curl_seek_callback or "similar" */
691 #define _curl_is_seek_cb(expr)                                          \
692   (_curl_is_NULL(expr) ||                                                     \
693    _curl_callback_compatible((expr), curl_seek_callback) ||                   \
694    _curl_callback_compatible((expr), _curl_seek_callback1) ||                 \
695    _curl_callback_compatible((expr), _curl_seek_callback2))
696 typedef CURLcode (*_curl_seek_callback1)(void *, curl_off_t, int);
697 typedef CURLcode (*_curl_seek_callback2)(const void *, curl_off_t, int);
698 
699 
700 #endif /* __CURL_TYPECHECK_GCC_H */
701