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