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_ECH || \ 279 (option) == CURLOPT_EGDSOCKET || \ 280 (option) == CURLOPT_FTP_ACCOUNT || \ 281 (option) == CURLOPT_FTP_ALTERNATIVE_TO_USER || \ 282 (option) == CURLOPT_FTPPORT || \ 283 (option) == CURLOPT_HSTS || \ 284 (option) == CURLOPT_HAPROXY_CLIENT_IP || \ 285 (option) == CURLOPT_INTERFACE || \ 286 (option) == CURLOPT_ISSUERCERT || \ 287 (option) == CURLOPT_KEYPASSWD || \ 288 (option) == CURLOPT_KRBLEVEL || \ 289 (option) == CURLOPT_LOGIN_OPTIONS || \ 290 (option) == CURLOPT_MAIL_AUTH || \ 291 (option) == CURLOPT_MAIL_FROM || \ 292 (option) == CURLOPT_NETRC_FILE || \ 293 (option) == CURLOPT_NOPROXY || \ 294 (option) == CURLOPT_PASSWORD || \ 295 (option) == CURLOPT_PINNEDPUBLICKEY || \ 296 (option) == CURLOPT_PRE_PROXY || \ 297 (option) == CURLOPT_PROTOCOLS_STR || \ 298 (option) == CURLOPT_PROXY || \ 299 (option) == CURLOPT_PROXY_CAINFO || \ 300 (option) == CURLOPT_PROXY_CAPATH || \ 301 (option) == CURLOPT_PROXY_CRLFILE || \ 302 (option) == CURLOPT_PROXY_ISSUERCERT || \ 303 (option) == CURLOPT_PROXY_KEYPASSWD || \ 304 (option) == CURLOPT_PROXY_PINNEDPUBLICKEY || \ 305 (option) == CURLOPT_PROXY_SERVICE_NAME || \ 306 (option) == CURLOPT_PROXY_SSL_CIPHER_LIST || \ 307 (option) == CURLOPT_PROXY_SSLCERT || \ 308 (option) == CURLOPT_PROXY_SSLCERTTYPE || \ 309 (option) == CURLOPT_PROXY_SSLKEY || \ 310 (option) == CURLOPT_PROXY_SSLKEYTYPE || \ 311 (option) == CURLOPT_PROXY_TLS13_CIPHERS || \ 312 (option) == CURLOPT_PROXY_TLSAUTH_PASSWORD || \ 313 (option) == CURLOPT_PROXY_TLSAUTH_TYPE || \ 314 (option) == CURLOPT_PROXY_TLSAUTH_USERNAME || \ 315 (option) == CURLOPT_PROXYPASSWORD || \ 316 (option) == CURLOPT_PROXYUSERNAME || \ 317 (option) == CURLOPT_PROXYUSERPWD || \ 318 (option) == CURLOPT_RANDOM_FILE || \ 319 (option) == CURLOPT_RANGE || \ 320 (option) == CURLOPT_REDIR_PROTOCOLS_STR || \ 321 (option) == CURLOPT_REFERER || \ 322 (option) == CURLOPT_REQUEST_TARGET || \ 323 (option) == CURLOPT_RTSP_SESSION_ID || \ 324 (option) == CURLOPT_RTSP_STREAM_URI || \ 325 (option) == CURLOPT_RTSP_TRANSPORT || \ 326 (option) == CURLOPT_SASL_AUTHZID || \ 327 (option) == CURLOPT_SERVICE_NAME || \ 328 (option) == CURLOPT_SOCKS5_GSSAPI_SERVICE || \ 329 (option) == CURLOPT_SSH_HOST_PUBLIC_KEY_MD5 || \ 330 (option) == CURLOPT_SSH_HOST_PUBLIC_KEY_SHA256 || \ 331 (option) == CURLOPT_SSH_KNOWNHOSTS || \ 332 (option) == CURLOPT_SSH_PRIVATE_KEYFILE || \ 333 (option) == CURLOPT_SSH_PUBLIC_KEYFILE || \ 334 (option) == CURLOPT_SSLCERT || \ 335 (option) == CURLOPT_SSLCERTTYPE || \ 336 (option) == CURLOPT_SSLENGINE || \ 337 (option) == CURLOPT_SSLKEY || \ 338 (option) == CURLOPT_SSLKEYTYPE || \ 339 (option) == CURLOPT_SSL_CIPHER_LIST || \ 340 (option) == CURLOPT_TLS13_CIPHERS || \ 341 (option) == CURLOPT_TLSAUTH_PASSWORD || \ 342 (option) == CURLOPT_TLSAUTH_TYPE || \ 343 (option) == CURLOPT_TLSAUTH_USERNAME || \ 344 (option) == CURLOPT_UNIX_SOCKET_PATH || \ 345 (option) == CURLOPT_URL || \ 346 (option) == CURLOPT_USERAGENT || \ 347 (option) == CURLOPT_USERNAME || \ 348 (option) == CURLOPT_AWS_SIGV4 || \ 349 (option) == CURLOPT_USERPWD || \ 350 (option) == CURLOPT_XOAUTH2_BEARER || \ 351 (option) == CURLOPT_SSL_EC_CURVES || \ 352 0) 353 354 /* evaluates to true if option takes a curl_write_callback argument */ 355 #define curlcheck_write_cb_option(option) \ 356 ((option) == CURLOPT_HEADERFUNCTION || \ 357 (option) == CURLOPT_WRITEFUNCTION) 358 359 /* evaluates to true if option takes a curl_conv_callback argument */ 360 #define curlcheck_conv_cb_option(option) \ 361 ((option) == CURLOPT_CONV_TO_NETWORK_FUNCTION || \ 362 (option) == CURLOPT_CONV_FROM_NETWORK_FUNCTION || \ 363 (option) == CURLOPT_CONV_FROM_UTF8_FUNCTION) 364 365 /* evaluates to true if option takes a data argument to pass to a callback */ 366 #define curlcheck_cb_data_option(option) \ 367 ((option) == CURLOPT_CHUNK_DATA || \ 368 (option) == CURLOPT_CLOSESOCKETDATA || \ 369 (option) == CURLOPT_DEBUGDATA || \ 370 (option) == CURLOPT_FNMATCH_DATA || \ 371 (option) == CURLOPT_HEADERDATA || \ 372 (option) == CURLOPT_HSTSREADDATA || \ 373 (option) == CURLOPT_HSTSWRITEDATA || \ 374 (option) == CURLOPT_INTERLEAVEDATA || \ 375 (option) == CURLOPT_IOCTLDATA || \ 376 (option) == CURLOPT_OPENSOCKETDATA || \ 377 (option) == CURLOPT_PREREQDATA || \ 378 (option) == CURLOPT_PROGRESSDATA || \ 379 (option) == CURLOPT_READDATA || \ 380 (option) == CURLOPT_SEEKDATA || \ 381 (option) == CURLOPT_SOCKOPTDATA || \ 382 (option) == CURLOPT_SSH_KEYDATA || \ 383 (option) == CURLOPT_SSL_CTX_DATA || \ 384 (option) == CURLOPT_WRITEDATA || \ 385 (option) == CURLOPT_RESOLVER_START_DATA || \ 386 (option) == CURLOPT_TRAILERDATA || \ 387 (option) == CURLOPT_SSH_HOSTKEYDATA || \ 388 0) 389 390 /* evaluates to true if option takes a POST data argument (void* or char*) */ 391 #define curlcheck_postfields_option(option) \ 392 ((option) == CURLOPT_POSTFIELDS || \ 393 (option) == CURLOPT_COPYPOSTFIELDS || \ 394 0) 395 396 /* evaluates to true if option takes a struct curl_slist * argument */ 397 #define curlcheck_slist_option(option) \ 398 ((option) == CURLOPT_HTTP200ALIASES || \ 399 (option) == CURLOPT_HTTPHEADER || \ 400 (option) == CURLOPT_MAIL_RCPT || \ 401 (option) == CURLOPT_POSTQUOTE || \ 402 (option) == CURLOPT_PREQUOTE || \ 403 (option) == CURLOPT_PROXYHEADER || \ 404 (option) == CURLOPT_QUOTE || \ 405 (option) == CURLOPT_RESOLVE || \ 406 (option) == CURLOPT_TELNETOPTIONS || \ 407 (option) == CURLOPT_CONNECT_TO || \ 408 0) 409 410 /* groups of curl_easy_getinfo infos that take the same type of argument */ 411 412 /* evaluates to true if info expects a pointer to char * argument */ 413 #define curlcheck_string_info(info) \ 414 (CURLINFO_STRING < (info) && (info) < CURLINFO_LONG && \ 415 (info) != CURLINFO_PRIVATE) 416 417 /* evaluates to true if info expects a pointer to long argument */ 418 #define curlcheck_long_info(info) \ 419 (CURLINFO_LONG < (info) && (info) < CURLINFO_DOUBLE) 420 421 /* evaluates to true if info expects a pointer to double argument */ 422 #define curlcheck_double_info(info) \ 423 (CURLINFO_DOUBLE < (info) && (info) < CURLINFO_SLIST) 424 425 /* true if info expects a pointer to struct curl_slist * argument */ 426 #define curlcheck_slist_info(info) \ 427 (((info) == CURLINFO_SSL_ENGINES) || ((info) == CURLINFO_COOKIELIST)) 428 429 /* true if info expects a pointer to struct curl_tlssessioninfo * argument */ 430 #define curlcheck_tlssessioninfo_info(info) \ 431 (((info) == CURLINFO_TLS_SSL_PTR) || ((info) == CURLINFO_TLS_SESSION)) 432 433 /* true if info expects a pointer to struct curl_certinfo * argument */ 434 #define curlcheck_certinfo_info(info) ((info) == CURLINFO_CERTINFO) 435 436 /* true if info expects a pointer to struct curl_socket_t argument */ 437 #define curlcheck_socket_info(info) \ 438 (CURLINFO_SOCKET < (info) && (info) < CURLINFO_OFF_T) 439 440 /* true if info expects a pointer to curl_off_t argument */ 441 #define curlcheck_off_t_info(info) \ 442 (CURLINFO_OFF_T < (info)) 443 444 445 /* typecheck helpers -- check whether given expression has requested type */ 446 447 /* For pointers, you can use the curlcheck_ptr/curlcheck_arr macros, 448 * otherwise define a new macro. Search for __builtin_types_compatible_p 449 * in the GCC manual. 450 * NOTE: these macros MUST NOT EVALUATE their arguments! The argument is 451 * the actual expression passed to the curl_easy_setopt macro. This 452 * means that you can only apply the sizeof and __typeof__ operators, no 453 * == or whatsoever. 454 */ 455 456 /* XXX: should evaluate to true if expr is a pointer */ 457 #define curlcheck_any_ptr(expr) \ 458 (sizeof(expr) == sizeof(void *)) 459 460 /* evaluates to true if expr is NULL */ 461 /* XXX: must not evaluate expr, so this check is not accurate */ 462 #define curlcheck_NULL(expr) \ 463 (__builtin_types_compatible_p(__typeof__(expr), __typeof__(NULL))) 464 465 /* evaluates to true if expr is type*, const type* or NULL */ 466 #define curlcheck_ptr(expr, type) \ 467 (curlcheck_NULL(expr) || \ 468 __builtin_types_compatible_p(__typeof__(expr), type *) || \ 469 __builtin_types_compatible_p(__typeof__(expr), const type *)) 470 471 /* evaluates to true if expr is one of type[], type*, NULL or const type* */ 472 #define curlcheck_arr(expr, type) \ 473 (curlcheck_ptr((expr), type) || \ 474 __builtin_types_compatible_p(__typeof__(expr), type [])) 475 476 /* evaluates to true if expr is a string */ 477 #define curlcheck_string(expr) \ 478 (curlcheck_arr((expr), char) || \ 479 curlcheck_arr((expr), signed char) || \ 480 curlcheck_arr((expr), unsigned char)) 481 482 /* evaluates to true if expr is a long (no matter the signedness) 483 * XXX: for now, int is also accepted (and therefore short and char, which 484 * are promoted to int when passed to a variadic function) */ 485 #define curlcheck_long(expr) \ 486 (__builtin_types_compatible_p(__typeof__(expr), long) || \ 487 __builtin_types_compatible_p(__typeof__(expr), signed long) || \ 488 __builtin_types_compatible_p(__typeof__(expr), unsigned long) || \ 489 __builtin_types_compatible_p(__typeof__(expr), int) || \ 490 __builtin_types_compatible_p(__typeof__(expr), signed int) || \ 491 __builtin_types_compatible_p(__typeof__(expr), unsigned int) || \ 492 __builtin_types_compatible_p(__typeof__(expr), short) || \ 493 __builtin_types_compatible_p(__typeof__(expr), signed short) || \ 494 __builtin_types_compatible_p(__typeof__(expr), unsigned short) || \ 495 __builtin_types_compatible_p(__typeof__(expr), char) || \ 496 __builtin_types_compatible_p(__typeof__(expr), signed char) || \ 497 __builtin_types_compatible_p(__typeof__(expr), unsigned char)) 498 499 /* evaluates to true if expr is of type curl_off_t */ 500 #define curlcheck_off_t(expr) \ 501 (__builtin_types_compatible_p(__typeof__(expr), curl_off_t)) 502 503 /* evaluates to true if expr is abuffer suitable for CURLOPT_ERRORBUFFER */ 504 /* XXX: also check size of an char[] array? */ 505 #define curlcheck_error_buffer(expr) \ 506 (curlcheck_NULL(expr) || \ 507 __builtin_types_compatible_p(__typeof__(expr), char *) || \ 508 __builtin_types_compatible_p(__typeof__(expr), char[])) 509 510 /* evaluates to true if expr is of type (const) void* or (const) FILE* */ 511 #if 0 512 #define curlcheck_cb_data(expr) \ 513 (curlcheck_ptr((expr), void) || \ 514 curlcheck_ptr((expr), FILE)) 515 #else /* be less strict */ 516 #define curlcheck_cb_data(expr) \ 517 curlcheck_any_ptr(expr) 518 #endif 519 520 /* evaluates to true if expr is of type FILE* */ 521 #define curlcheck_FILE(expr) \ 522 (curlcheck_NULL(expr) || \ 523 (__builtin_types_compatible_p(__typeof__(expr), FILE *))) 524 525 /* evaluates to true if expr can be passed as POST data (void* or char*) */ 526 #define curlcheck_postfields(expr) \ 527 (curlcheck_ptr((expr), void) || \ 528 curlcheck_arr((expr), char) || \ 529 curlcheck_arr((expr), unsigned char)) 530 531 /* helper: __builtin_types_compatible_p distinguishes between functions and 532 * function pointers, hide it */ 533 #define curlcheck_cb_compatible(func, type) \ 534 (__builtin_types_compatible_p(__typeof__(func), type) || \ 535 __builtin_types_compatible_p(__typeof__(func) *, type)) 536 537 /* evaluates to true if expr is of type curl_resolver_start_callback */ 538 #define curlcheck_resolver_start_callback(expr) \ 539 (curlcheck_NULL(expr) || \ 540 curlcheck_cb_compatible((expr), curl_resolver_start_callback)) 541 542 /* evaluates to true if expr is of type curl_read_callback or "similar" */ 543 #define curlcheck_read_cb(expr) \ 544 (curlcheck_NULL(expr) || \ 545 curlcheck_cb_compatible((expr), __typeof__(fread) *) || \ 546 curlcheck_cb_compatible((expr), curl_read_callback) || \ 547 curlcheck_cb_compatible((expr), _curl_read_callback1) || \ 548 curlcheck_cb_compatible((expr), _curl_read_callback2) || \ 549 curlcheck_cb_compatible((expr), _curl_read_callback3) || \ 550 curlcheck_cb_compatible((expr), _curl_read_callback4) || \ 551 curlcheck_cb_compatible((expr), _curl_read_callback5) || \ 552 curlcheck_cb_compatible((expr), _curl_read_callback6)) 553 typedef size_t (*_curl_read_callback1)(char *, size_t, size_t, void *); 554 typedef size_t (*_curl_read_callback2)(char *, size_t, size_t, const void *); 555 typedef size_t (*_curl_read_callback3)(char *, size_t, size_t, FILE *); 556 typedef size_t (*_curl_read_callback4)(void *, size_t, size_t, void *); 557 typedef size_t (*_curl_read_callback5)(void *, size_t, size_t, const void *); 558 typedef size_t (*_curl_read_callback6)(void *, size_t, size_t, FILE *); 559 560 /* evaluates to true if expr is of type curl_write_callback or "similar" */ 561 #define curlcheck_write_cb(expr) \ 562 (curlcheck_read_cb(expr) || \ 563 curlcheck_cb_compatible((expr), __typeof__(fwrite) *) || \ 564 curlcheck_cb_compatible((expr), curl_write_callback) || \ 565 curlcheck_cb_compatible((expr), _curl_write_callback1) || \ 566 curlcheck_cb_compatible((expr), _curl_write_callback2) || \ 567 curlcheck_cb_compatible((expr), _curl_write_callback3) || \ 568 curlcheck_cb_compatible((expr), _curl_write_callback4) || \ 569 curlcheck_cb_compatible((expr), _curl_write_callback5) || \ 570 curlcheck_cb_compatible((expr), _curl_write_callback6)) 571 typedef size_t (*_curl_write_callback1)(const char *, size_t, size_t, void *); 572 typedef size_t (*_curl_write_callback2)(const char *, size_t, size_t, 573 const void *); 574 typedef size_t (*_curl_write_callback3)(const char *, size_t, size_t, FILE *); 575 typedef size_t (*_curl_write_callback4)(const void *, size_t, size_t, void *); 576 typedef size_t (*_curl_write_callback5)(const void *, size_t, size_t, 577 const void *); 578 typedef size_t (*_curl_write_callback6)(const void *, size_t, size_t, FILE *); 579 580 /* evaluates to true if expr is of type curl_ioctl_callback or "similar" */ 581 #define curlcheck_ioctl_cb(expr) \ 582 (curlcheck_NULL(expr) || \ 583 curlcheck_cb_compatible((expr), curl_ioctl_callback) || \ 584 curlcheck_cb_compatible((expr), _curl_ioctl_callback1) || \ 585 curlcheck_cb_compatible((expr), _curl_ioctl_callback2) || \ 586 curlcheck_cb_compatible((expr), _curl_ioctl_callback3) || \ 587 curlcheck_cb_compatible((expr), _curl_ioctl_callback4)) 588 typedef curlioerr (*_curl_ioctl_callback1)(CURL *, int, void *); 589 typedef curlioerr (*_curl_ioctl_callback2)(CURL *, int, const void *); 590 typedef curlioerr (*_curl_ioctl_callback3)(CURL *, curliocmd, void *); 591 typedef curlioerr (*_curl_ioctl_callback4)(CURL *, curliocmd, const void *); 592 593 /* evaluates to true if expr is of type curl_sockopt_callback or "similar" */ 594 #define curlcheck_sockopt_cb(expr) \ 595 (curlcheck_NULL(expr) || \ 596 curlcheck_cb_compatible((expr), curl_sockopt_callback) || \ 597 curlcheck_cb_compatible((expr), _curl_sockopt_callback1) || \ 598 curlcheck_cb_compatible((expr), _curl_sockopt_callback2)) 599 typedef int (*_curl_sockopt_callback1)(void *, curl_socket_t, curlsocktype); 600 typedef int (*_curl_sockopt_callback2)(const void *, curl_socket_t, 601 curlsocktype); 602 603 /* evaluates to true if expr is of type curl_opensocket_callback or 604 "similar" */ 605 #define curlcheck_opensocket_cb(expr) \ 606 (curlcheck_NULL(expr) || \ 607 curlcheck_cb_compatible((expr), curl_opensocket_callback) || \ 608 curlcheck_cb_compatible((expr), _curl_opensocket_callback1) || \ 609 curlcheck_cb_compatible((expr), _curl_opensocket_callback2) || \ 610 curlcheck_cb_compatible((expr), _curl_opensocket_callback3) || \ 611 curlcheck_cb_compatible((expr), _curl_opensocket_callback4)) 612 typedef curl_socket_t (*_curl_opensocket_callback1) 613 (void *, curlsocktype, struct curl_sockaddr *); 614 typedef curl_socket_t (*_curl_opensocket_callback2) 615 (void *, curlsocktype, const struct curl_sockaddr *); 616 typedef curl_socket_t (*_curl_opensocket_callback3) 617 (const void *, curlsocktype, struct curl_sockaddr *); 618 typedef curl_socket_t (*_curl_opensocket_callback4) 619 (const void *, curlsocktype, const struct curl_sockaddr *); 620 621 /* evaluates to true if expr is of type curl_progress_callback or "similar" */ 622 #define curlcheck_progress_cb(expr) \ 623 (curlcheck_NULL(expr) || \ 624 curlcheck_cb_compatible((expr), curl_progress_callback) || \ 625 curlcheck_cb_compatible((expr), _curl_progress_callback1) || \ 626 curlcheck_cb_compatible((expr), _curl_progress_callback2)) 627 typedef int (*_curl_progress_callback1)(void *, 628 double, double, double, double); 629 typedef int (*_curl_progress_callback2)(const void *, 630 double, double, double, double); 631 632 /* evaluates to true if expr is of type curl_debug_callback or "similar" */ 633 #define curlcheck_debug_cb(expr) \ 634 (curlcheck_NULL(expr) || \ 635 curlcheck_cb_compatible((expr), curl_debug_callback) || \ 636 curlcheck_cb_compatible((expr), _curl_debug_callback1) || \ 637 curlcheck_cb_compatible((expr), _curl_debug_callback2) || \ 638 curlcheck_cb_compatible((expr), _curl_debug_callback3) || \ 639 curlcheck_cb_compatible((expr), _curl_debug_callback4) || \ 640 curlcheck_cb_compatible((expr), _curl_debug_callback5) || \ 641 curlcheck_cb_compatible((expr), _curl_debug_callback6) || \ 642 curlcheck_cb_compatible((expr), _curl_debug_callback7) || \ 643 curlcheck_cb_compatible((expr), _curl_debug_callback8)) 644 typedef int (*_curl_debug_callback1) (CURL *, 645 curl_infotype, char *, size_t, void *); 646 typedef int (*_curl_debug_callback2) (CURL *, 647 curl_infotype, char *, size_t, const void *); 648 typedef int (*_curl_debug_callback3) (CURL *, 649 curl_infotype, const char *, size_t, void *); 650 typedef int (*_curl_debug_callback4) (CURL *, 651 curl_infotype, const char *, size_t, const void *); 652 typedef int (*_curl_debug_callback5) (CURL *, 653 curl_infotype, unsigned char *, size_t, void *); 654 typedef int (*_curl_debug_callback6) (CURL *, 655 curl_infotype, unsigned char *, size_t, const void *); 656 typedef int (*_curl_debug_callback7) (CURL *, 657 curl_infotype, const unsigned char *, size_t, void *); 658 typedef int (*_curl_debug_callback8) (CURL *, 659 curl_infotype, const unsigned char *, size_t, const void *); 660 661 /* evaluates to true if expr is of type curl_ssl_ctx_callback or "similar" */ 662 /* this is getting even messier... */ 663 #define curlcheck_ssl_ctx_cb(expr) \ 664 (curlcheck_NULL(expr) || \ 665 curlcheck_cb_compatible((expr), curl_ssl_ctx_callback) || \ 666 curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback1) || \ 667 curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback2) || \ 668 curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback3) || \ 669 curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback4) || \ 670 curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback5) || \ 671 curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback6) || \ 672 curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback7) || \ 673 curlcheck_cb_compatible((expr), _curl_ssl_ctx_callback8)) 674 typedef CURLcode (*_curl_ssl_ctx_callback1)(CURL *, void *, void *); 675 typedef CURLcode (*_curl_ssl_ctx_callback2)(CURL *, void *, const void *); 676 typedef CURLcode (*_curl_ssl_ctx_callback3)(CURL *, const void *, void *); 677 typedef CURLcode (*_curl_ssl_ctx_callback4)(CURL *, const void *, 678 const void *); 679 #ifdef HEADER_SSL_H 680 /* hack: if we included OpenSSL's ssl.h, we know about SSL_CTX 681 * this will of course break if we're included before OpenSSL headers... 682 */ 683 typedef CURLcode (*_curl_ssl_ctx_callback5)(CURL *, SSL_CTX *, void *); 684 typedef CURLcode (*_curl_ssl_ctx_callback6)(CURL *, SSL_CTX *, const void *); 685 typedef CURLcode (*_curl_ssl_ctx_callback7)(CURL *, const SSL_CTX *, void *); 686 typedef CURLcode (*_curl_ssl_ctx_callback8)(CURL *, const SSL_CTX *, 687 const void *); 688 #else 689 typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback5; 690 typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback6; 691 typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback7; 692 typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback8; 693 #endif 694 695 /* evaluates to true if expr is of type curl_conv_callback or "similar" */ 696 #define curlcheck_conv_cb(expr) \ 697 (curlcheck_NULL(expr) || \ 698 curlcheck_cb_compatible((expr), curl_conv_callback) || \ 699 curlcheck_cb_compatible((expr), _curl_conv_callback1) || \ 700 curlcheck_cb_compatible((expr), _curl_conv_callback2) || \ 701 curlcheck_cb_compatible((expr), _curl_conv_callback3) || \ 702 curlcheck_cb_compatible((expr), _curl_conv_callback4)) 703 typedef CURLcode (*_curl_conv_callback1)(char *, size_t length); 704 typedef CURLcode (*_curl_conv_callback2)(const char *, size_t length); 705 typedef CURLcode (*_curl_conv_callback3)(void *, size_t length); 706 typedef CURLcode (*_curl_conv_callback4)(const void *, size_t length); 707 708 /* evaluates to true if expr is of type curl_seek_callback or "similar" */ 709 #define curlcheck_seek_cb(expr) \ 710 (curlcheck_NULL(expr) || \ 711 curlcheck_cb_compatible((expr), curl_seek_callback) || \ 712 curlcheck_cb_compatible((expr), _curl_seek_callback1) || \ 713 curlcheck_cb_compatible((expr), _curl_seek_callback2)) 714 typedef CURLcode (*_curl_seek_callback1)(void *, curl_off_t, int); 715 typedef CURLcode (*_curl_seek_callback2)(const void *, curl_off_t, int); 716 717 718 #endif /* CURLINC_TYPECHECK_GCC_H */ 719