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