LCOV - code coverage report
Current view: top level - curl - typecheck-gcc.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 30 0.0 %
Date: 2025-06-01 18:24:50 Functions: 0 30 0.0 %

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

Generated by: LCOV version 1.16