typecheck-gcc.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. #ifndef __CURL_TYPECHECK_GCC_H
  2. #define __CURL_TYPECHECK_GCC_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 1998 - 2009, 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 http://curl.haxx.se/docs/copyright.html.
  15. *
  16. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. * copies of the Software, and permit persons to whom the Software is
  18. * furnished to do so, under the terms of the COPYING file.
  19. *
  20. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. * KIND, either express or implied.
  22. *
  23. * $Id: typecheck-gcc.h,v 1.9 2009-01-25 23:26:31 bagder Exp $
  24. ***************************************************************************/
  25. /* wraps curl_easy_setopt() with typechecking */
  26. /* To add a new kind of warning, add an
  27. * if(_curl_is_sometype_option(_curl_opt) && ! _curl_is_sometype(value))
  28. * _curl_easy_setopt_err_sometype();
  29. * block and define _curl_is_sometype_option, _curl_is_sometype and
  30. * _curl_easy_setopt_err_sometype below
  31. *
  32. * To add an option that uses the same type as an existing option, you'll just
  33. * need to extend the appropriate _curl_*_option macro
  34. */
  35. #define curl_easy_setopt(handle, option, value) \
  36. __extension__ ({ \
  37. __typeof__ (option) _curl_opt = option; \
  38. if (__builtin_constant_p(_curl_opt)) { \
  39. if (_curl_is_long_option(_curl_opt) && !_curl_is_long(value)) \
  40. _curl_easy_setopt_err_long(); \
  41. if (_curl_is_off_t_option(_curl_opt) && !_curl_is_off_t(value)) \
  42. _curl_easy_setopt_err_curl_off_t(); \
  43. if (_curl_is_string_option(_curl_opt) && !_curl_is_string(value)) \
  44. _curl_easy_setopt_err_string(); \
  45. if (_curl_is_write_cb_option(_curl_opt) && !_curl_is_write_cb(value)) \
  46. _curl_easy_setopt_err_write_callback(); \
  47. if ((_curl_opt) == CURLOPT_READFUNCTION && !_curl_is_read_cb(value)) \
  48. _curl_easy_setopt_err_read_cb(); \
  49. if ((_curl_opt) == CURLOPT_IOCTLFUNCTION && !_curl_is_ioctl_cb(value)) \
  50. _curl_easy_setopt_err_ioctl_cb(); \
  51. if ((_curl_opt) == CURLOPT_SOCKOPTFUNCTION && !_curl_is_sockopt_cb(value))\
  52. _curl_easy_setopt_err_sockopt_cb(); \
  53. if ((_curl_opt) == CURLOPT_OPENSOCKETFUNCTION && \
  54. !_curl_is_opensocket_cb(value)) \
  55. _curl_easy_setopt_err_opensocket_cb(); \
  56. if ((_curl_opt) == CURLOPT_PROGRESSFUNCTION && \
  57. !_curl_is_progress_cb(value)) \
  58. _curl_easy_setopt_err_progress_cb(); \
  59. if ((_curl_opt) == CURLOPT_DEBUGFUNCTION && !_curl_is_debug_cb(value)) \
  60. _curl_easy_setopt_err_debug_cb(); \
  61. if ((_curl_opt) == CURLOPT_SSL_CTX_FUNCTION && \
  62. !_curl_is_ssl_ctx_cb(value)) \
  63. _curl_easy_setopt_err_ssl_ctx_cb(); \
  64. if (_curl_is_conv_cb_option(_curl_opt) && !_curl_is_conv_cb(value)) \
  65. _curl_easy_setopt_err_conv_cb(); \
  66. if ((_curl_opt) == CURLOPT_SEEKFUNCTION && !_curl_is_seek_cb(value)) \
  67. _curl_easy_setopt_err_seek_cb(); \
  68. if (_curl_is_cb_data_option(_curl_opt) && !_curl_is_cb_data(value)) \
  69. _curl_easy_setopt_err_cb_data(); \
  70. if ((_curl_opt) == CURLOPT_ERRORBUFFER && !_curl_is_error_buffer(value)) \
  71. _curl_easy_setopt_err_error_buffer(); \
  72. if ((_curl_opt) == CURLOPT_STDERR && !_curl_is_FILE(value)) \
  73. _curl_easy_setopt_err_FILE(); \
  74. if (_curl_is_postfields_option(_curl_opt) && !_curl_is_postfields(value)) \
  75. _curl_easy_setopt_err_postfields(); \
  76. if ((_curl_opt) == CURLOPT_HTTPPOST && \
  77. !_curl_is_arr((value), struct curl_httppost)) \
  78. _curl_easy_setopt_err_curl_httpost(); \
  79. if (_curl_is_slist_option(_curl_opt) && \
  80. !_curl_is_arr((value), struct curl_slist)) \
  81. _curl_easy_setopt_err_curl_slist(); \
  82. if ((_curl_opt) == CURLOPT_SHARE && !_curl_is_ptr((value), CURLSH)) \
  83. _curl_easy_setopt_err_CURLSH(); \
  84. } \
  85. curl_easy_setopt(handle, _curl_opt, value); \
  86. })
  87. /* wraps curl_easy_getinfo() with typechecking */
  88. /* FIXME: don't allow const pointers */
  89. #define curl_easy_getinfo(handle, info, arg) \
  90. __extension__ ({ \
  91. __typeof__ (info) _curl_info = info; \
  92. if (__builtin_constant_p(_curl_info)) { \
  93. if (_curl_is_string_info(_curl_info) && !_curl_is_arr((arg), char *)) \
  94. _curl_easy_getinfo_err_string(); \
  95. if (_curl_is_long_info(_curl_info) && !_curl_is_arr((arg), long)) \
  96. _curl_easy_getinfo_err_long(); \
  97. if (_curl_is_double_info(_curl_info) && !_curl_is_arr((arg), double)) \
  98. _curl_easy_getinfo_err_double(); \
  99. if (_curl_is_slist_info(_curl_info) && \
  100. !_curl_is_arr((arg), struct curl_slist *)) \
  101. _curl_easy_getinfo_err_curl_slist(); \
  102. } \
  103. curl_easy_getinfo(handle, _curl_info, arg); \
  104. })
  105. /* TODO: typechecking for curl_share_setopt() and curl_multi_setopt(),
  106. * for now just make sure that the functions are called with three
  107. * arguments
  108. */
  109. #define curl_share_setopt(share,opt,param) curl_share_setopt(share,opt,param)
  110. #define curl_multi_setopt(handle,opt,param) curl_multi_setopt(handle,opt,param)
  111. /* the actual warnings, triggered by calling the _curl_easy_setopt_err*
  112. * functions */
  113. /* To define a new warning, use _CURL_WARNING(identifier, "message") */
  114. #define _CURL_WARNING(id, message) \
  115. static void __attribute__((warning(message))) __attribute__((unused)) \
  116. __attribute__((noinline)) id(void) { __asm__(""); }
  117. _CURL_WARNING(_curl_easy_setopt_err_long,
  118. "curl_easy_setopt expects a long argument for this option")
  119. _CURL_WARNING(_curl_easy_setopt_err_curl_off_t,
  120. "curl_easy_setopt expects a curl_off_t argument for this option")
  121. _CURL_WARNING(_curl_easy_setopt_err_string,
  122. "curl_easy_setopt expects a string (char* or char[]) argument for this option"
  123. )
  124. _CURL_WARNING(_curl_easy_setopt_err_write_callback,
  125. "curl_easy_setopt expects a curl_write_callback argument for this option")
  126. _CURL_WARNING(_curl_easy_setopt_err_read_cb,
  127. "curl_easy_setopt expects a curl_read_callback argument for this option")
  128. _CURL_WARNING(_curl_easy_setopt_err_ioctl_cb,
  129. "curl_easy_setopt expects a curl_ioctl_callback argument for this option")
  130. _CURL_WARNING(_curl_easy_setopt_err_sockopt_cb,
  131. "curl_easy_setopt expects a curl_sockopt_callback argument for this option")
  132. _CURL_WARNING(_curl_easy_setopt_err_opensocket_cb,
  133. "curl_easy_setopt expects a curl_opensocket_callback argument for this option"
  134. )
  135. _CURL_WARNING(_curl_easy_setopt_err_progress_cb,
  136. "curl_easy_setopt expects a curl_progress_callback argument for this option")
  137. _CURL_WARNING(_curl_easy_setopt_err_debug_cb,
  138. "curl_easy_setopt expects a curl_debug_callback argument for this option")
  139. _CURL_WARNING(_curl_easy_setopt_err_ssl_ctx_cb,
  140. "curl_easy_setopt expects a curl_ssl_ctx_callback argument for this option")
  141. _CURL_WARNING(_curl_easy_setopt_err_conv_cb,
  142. "curl_easy_setopt expects a curl_conv_callback argument for this option")
  143. _CURL_WARNING(_curl_easy_setopt_err_seek_cb,
  144. "curl_easy_setopt expects a curl_seek_callback argument for this option")
  145. _CURL_WARNING(_curl_easy_setopt_err_cb_data,
  146. "curl_easy_setopt expects a private data pointer as argument for this option")
  147. _CURL_WARNING(_curl_easy_setopt_err_error_buffer,
  148. "curl_easy_setopt expects a char buffer of CURL_ERROR_SIZE as argument for this option")
  149. _CURL_WARNING(_curl_easy_setopt_err_FILE,
  150. "curl_easy_setopt expects a FILE* argument for this option")
  151. _CURL_WARNING(_curl_easy_setopt_err_postfields,
  152. "curl_easy_setopt expects a void* or char* argument for this option")
  153. _CURL_WARNING(_curl_easy_setopt_err_curl_httpost,
  154. "curl_easy_setopt expects a struct curl_httppost* argument for this option")
  155. _CURL_WARNING(_curl_easy_setopt_err_curl_slist,
  156. "curl_easy_setopt expects a struct curl_slist* argument for this option")
  157. _CURL_WARNING(_curl_easy_setopt_err_CURLSH,
  158. "curl_easy_setopt expects a CURLSH* argument for this option")
  159. _CURL_WARNING(_curl_easy_getinfo_err_string,
  160. "curl_easy_getinfo expects a pointer to char * for this info")
  161. _CURL_WARNING(_curl_easy_getinfo_err_long,
  162. "curl_easy_getinfo expects a pointer to long for this info")
  163. _CURL_WARNING(_curl_easy_getinfo_err_double,
  164. "curl_easy_getinfo expects a pointer to double for this info")
  165. _CURL_WARNING(_curl_easy_getinfo_err_curl_slist,
  166. "curl_easy_getinfo expects a pointer to struct curl_slist * for this info")
  167. /* groups of curl_easy_setops options that take the same type of argument */
  168. /* To add a new option to one of the groups, just add
  169. * (option) == CURLOPT_SOMETHING
  170. * to the or-expression. If the option takes a long or curl_off_t, you don't
  171. * have to do anything
  172. */
  173. /* evaluates to true if option takes a long argument */
  174. #define _curl_is_long_option(option) \
  175. (0 < (option) && (option) < CURLOPTTYPE_OBJECTPOINT)
  176. #define _curl_is_off_t_option(option) \
  177. ((option) > CURLOPTTYPE_OFF_T)
  178. /* evaluates to true if option takes a char* argument */
  179. #define _curl_is_string_option(option) \
  180. ((option) == CURLOPT_URL || \
  181. (option) == CURLOPT_PROXY || \
  182. (option) == CURLOPT_INTERFACE || \
  183. (option) == CURLOPT_NETRC_FILE || \
  184. (option) == CURLOPT_USERPWD || \
  185. (option) == CURLOPT_USERNAME || \
  186. (option) == CURLOPT_PASSWORD || \
  187. (option) == CURLOPT_PROXYUSERPWD || \
  188. (option) == CURLOPT_PROXYUSERNAME || \
  189. (option) == CURLOPT_PROXYPASSWORD || \
  190. (option) == CURLOPT_NOPROXY || \
  191. (option) == CURLOPT_ENCODING || \
  192. (option) == CURLOPT_REFERER || \
  193. (option) == CURLOPT_USERAGENT || \
  194. (option) == CURLOPT_COOKIE || \
  195. (option) == CURLOPT_COOKIEFILE || \
  196. (option) == CURLOPT_COOKIEJAR || \
  197. (option) == CURLOPT_COOKIELIST || \
  198. (option) == CURLOPT_FTPPORT || \
  199. (option) == CURLOPT_FTP_ALTERNATIVE_TO_USER || \
  200. (option) == CURLOPT_FTP_ACCOUNT || \
  201. (option) == CURLOPT_RANGE || \
  202. (option) == CURLOPT_CUSTOMREQUEST || \
  203. (option) == CURLOPT_SSLCERT || \
  204. (option) == CURLOPT_SSLCERTTYPE || \
  205. (option) == CURLOPT_SSLKEY || \
  206. (option) == CURLOPT_SSLKEYTYPE || \
  207. (option) == CURLOPT_KEYPASSWD || \
  208. (option) == CURLOPT_SSLENGINE || \
  209. (option) == CURLOPT_CAINFO || \
  210. (option) == CURLOPT_CAPATH || \
  211. (option) == CURLOPT_RANDOM_FILE || \
  212. (option) == CURLOPT_EGDSOCKET || \
  213. (option) == CURLOPT_SSL_CIPHER_LIST || \
  214. (option) == CURLOPT_KRBLEVEL || \
  215. (option) == CURLOPT_SSH_HOST_PUBLIC_KEY_MD5 || \
  216. (option) == CURLOPT_SSH_PUBLIC_KEYFILE || \
  217. (option) == CURLOPT_SSH_PRIVATE_KEYFILE || \
  218. (option) == CURLOPT_CRLFILE || \
  219. (option) == CURLOPT_ISSUERCERT || \
  220. 0)
  221. /* evaluates to true if option takes a curl_write_callback argument */
  222. #define _curl_is_write_cb_option(option) \
  223. ((option) == CURLOPT_HEADERFUNCTION || \
  224. (option) == CURLOPT_WRITEFUNCTION)
  225. /* evaluates to true if option takes a curl_conv_callback argument */
  226. #define _curl_is_conv_cb_option(option) \
  227. ((option) == CURLOPT_CONV_TO_NETWORK_FUNCTION || \
  228. (option) == CURLOPT_CONV_FROM_NETWORK_FUNCTION || \
  229. (option) == CURLOPT_CONV_FROM_UTF8_FUNCTION)
  230. /* evaluates to true if option takes a data argument to pass to a callback */
  231. #define _curl_is_cb_data_option(option) \
  232. ((option) == CURLOPT_WRITEDATA || \
  233. (option) == CURLOPT_READDATA || \
  234. (option) == CURLOPT_IOCTLDATA || \
  235. (option) == CURLOPT_SOCKOPTDATA || \
  236. (option) == CURLOPT_OPENSOCKETDATA || \
  237. (option) == CURLOPT_PROGRESSDATA || \
  238. (option) == CURLOPT_WRITEHEADER || \
  239. (option) == CURLOPT_DEBUGDATA || \
  240. (option) == CURLOPT_SSL_CTX_DATA || \
  241. (option) == CURLOPT_SEEKDATA || \
  242. (option) == CURLOPT_PRIVATE || \
  243. 0)
  244. /* evaluates to true if option takes a POST data argument (void* or char*) */
  245. #define _curl_is_postfields_option(option) \
  246. ((option) == CURLOPT_POSTFIELDS || \
  247. (option) == CURLOPT_COPYPOSTFIELDS || \
  248. 0)
  249. /* evaluates to true if option takes a struct curl_slist * argument */
  250. #define _curl_is_slist_option(option) \
  251. ((option) == CURLOPT_HTTPHEADER || \
  252. (option) == CURLOPT_HTTP200ALIASES || \
  253. (option) == CURLOPT_QUOTE || \
  254. (option) == CURLOPT_POSTQUOTE || \
  255. (option) == CURLOPT_PREQUOTE || \
  256. (option) == CURLOPT_TELNETOPTIONS || \
  257. 0)
  258. /* groups of curl_easy_getinfo infos that take the same type of argument */
  259. /* evaluates to true if info expects a pointer to char * argument */
  260. #define _curl_is_string_info(info) \
  261. (CURLINFO_STRING < (info) && (info) < CURLINFO_LONG)
  262. /* evaluates to true if info expects a pointer to long argument */
  263. #define _curl_is_long_info(info) \
  264. (CURLINFO_LONG < (info) && (info) < CURLINFO_DOUBLE)
  265. /* evaluates to true if info expects a pointer to double argument */
  266. #define _curl_is_double_info(info) \
  267. (CURLINFO_DOUBLE < (info) && (info) < CURLINFO_SLIST)
  268. /* true if info expects a pointer to struct curl_slist * argument */
  269. #define _curl_is_slist_info(info) \
  270. (CURLINFO_SLIST < (info))
  271. /* typecheck helpers -- check whether given expression has requested type*/
  272. /* For pointers, you can use the _curl_is_ptr/_curl_is_arr macros,
  273. * otherwise define a new macro. Search for __builtin_types_compatible_p
  274. * in the GCC manual.
  275. * NOTE: these macros MUST NOT EVALUATE their arguments! The argument is
  276. * the actual expression passed to the curl_easy_setopt macro. This
  277. * means that you can only apply the sizeof and __typeof__ operators, no
  278. * == or whatsoever.
  279. */
  280. /* XXX: should evaluate to true iff expr is a pointer */
  281. #define _curl_is_any_ptr(expr) \
  282. (sizeof(expr) == sizeof(void*))
  283. /* evaluates to true if expr is NULL */
  284. /* XXX: must not evaluate expr, so this check is not accurate */
  285. #define _curl_is_NULL(expr) \
  286. (__builtin_types_compatible_p(__typeof__(expr), __typeof__(NULL)))
  287. /* evaluates to true if expr is type*, const type* or NULL */
  288. #define _curl_is_ptr(expr, type) \
  289. (_curl_is_NULL(expr) || \
  290. __builtin_types_compatible_p(__typeof__(expr), type *) || \
  291. __builtin_types_compatible_p(__typeof__(expr), const type *))
  292. /* evaluates to true if expr is one of type[], type*, NULL or const type* */
  293. #define _curl_is_arr(expr, type) \
  294. (_curl_is_ptr((expr), type) || \
  295. __builtin_types_compatible_p(__typeof__(expr), type []))
  296. /* evaluates to true if expr is a string */
  297. #define _curl_is_string(expr) \
  298. (_curl_is_arr((expr), char) || \
  299. _curl_is_arr((expr), signed char) || \
  300. _curl_is_arr((expr), unsigned char))
  301. /* evaluates to true if expr is a long (no matter the signedness)
  302. * XXX: for now, int is also accepted (and therefore short and char, which
  303. * are promoted to int when passed to a variadic function) */
  304. #define _curl_is_long(expr) \
  305. (__builtin_types_compatible_p(__typeof__(expr), long) || \
  306. __builtin_types_compatible_p(__typeof__(expr), signed long) || \
  307. __builtin_types_compatible_p(__typeof__(expr), unsigned long) || \
  308. __builtin_types_compatible_p(__typeof__(expr), int) || \
  309. __builtin_types_compatible_p(__typeof__(expr), signed int) || \
  310. __builtin_types_compatible_p(__typeof__(expr), unsigned int) || \
  311. __builtin_types_compatible_p(__typeof__(expr), short) || \
  312. __builtin_types_compatible_p(__typeof__(expr), signed short) || \
  313. __builtin_types_compatible_p(__typeof__(expr), unsigned short) || \
  314. __builtin_types_compatible_p(__typeof__(expr), char) || \
  315. __builtin_types_compatible_p(__typeof__(expr), signed char) || \
  316. __builtin_types_compatible_p(__typeof__(expr), unsigned char))
  317. /* evaluates to true if expr is of type curl_off_t */
  318. #define _curl_is_off_t(expr) \
  319. (__builtin_types_compatible_p(__typeof__(expr), curl_off_t))
  320. /* evaluates to true if expr is abuffer suitable for CURLOPT_ERRORBUFFER */
  321. /* XXX: also check size of an char[] array? */
  322. #define _curl_is_error_buffer(expr) \
  323. (__builtin_types_compatible_p(__typeof__(expr), char *) || \
  324. __builtin_types_compatible_p(__typeof__(expr), char[]))
  325. /* evaluates to true if expr is of type (const) void* or (const) FILE* */
  326. #if 0
  327. #define _curl_is_cb_data(expr) \
  328. (_curl_is_ptr((expr), void) || \
  329. _curl_is_ptr((expr), FILE))
  330. #else /* be less strict */
  331. #define _curl_is_cb_data(expr) \
  332. _curl_is_any_ptr(expr)
  333. #endif
  334. /* evaluates to true if expr is of type FILE* */
  335. #define _curl_is_FILE(expr) \
  336. (__builtin_types_compatible_p(__typeof__(expr), FILE *))
  337. /* evaluates to true if expr can be passed as POST data (void* or char*) */
  338. #define _curl_is_postfields(expr) \
  339. (_curl_is_ptr((expr), void) || \
  340. _curl_is_arr((expr), char))
  341. /* FIXME: the whole callback checking is messy...
  342. * The idea is to tolerate char vs. void and const vs. not const
  343. * pointers in arguments at least
  344. */
  345. /* helper: __builtin_types_compatible_p distinguishes between functions and
  346. * function pointers, hide it */
  347. #define _curl_callback_compatible(func, type) \
  348. (__builtin_types_compatible_p(__typeof__(func), type) || \
  349. __builtin_types_compatible_p(__typeof__(func), type*))
  350. /* evaluates to true if expr is of type curl_read_callback or "similar" */
  351. #define _curl_is_read_cb(expr) \
  352. (_curl_is_NULL(expr) || \
  353. __builtin_types_compatible_p(__typeof__(expr), __typeof__(fread)) || \
  354. __builtin_types_compatible_p(__typeof__(expr), curl_read_callback) || \
  355. _curl_callback_compatible((expr), _curl_read_callback1) || \
  356. _curl_callback_compatible((expr), _curl_read_callback2) || \
  357. _curl_callback_compatible((expr), _curl_read_callback3) || \
  358. _curl_callback_compatible((expr), _curl_read_callback4) || \
  359. _curl_callback_compatible((expr), _curl_read_callback5) || \
  360. _curl_callback_compatible((expr), _curl_read_callback6))
  361. typedef size_t (_curl_read_callback1)(char *, size_t, size_t, void*);
  362. typedef size_t (_curl_read_callback2)(char *, size_t, size_t, const void*);
  363. typedef size_t (_curl_read_callback3)(char *, size_t, size_t, FILE*);
  364. typedef size_t (_curl_read_callback4)(void *, size_t, size_t, void*);
  365. typedef size_t (_curl_read_callback5)(void *, size_t, size_t, const void*);
  366. typedef size_t (_curl_read_callback6)(void *, size_t, size_t, FILE*);
  367. /* evaluates to true if expr is of type curl_write_callback or "similar" */
  368. #define _curl_is_write_cb(expr) \
  369. (_curl_is_read_cb(expr) || \
  370. __builtin_types_compatible_p(__typeof__(expr), __typeof__(fwrite)) || \
  371. __builtin_types_compatible_p(__typeof__(expr), curl_write_callback) || \
  372. _curl_callback_compatible((expr), _curl_write_callback1) || \
  373. _curl_callback_compatible((expr), _curl_write_callback2) || \
  374. _curl_callback_compatible((expr), _curl_write_callback3) || \
  375. _curl_callback_compatible((expr), _curl_write_callback4) || \
  376. _curl_callback_compatible((expr), _curl_write_callback5) || \
  377. _curl_callback_compatible((expr), _curl_write_callback6))
  378. typedef size_t (_curl_write_callback1)(const char *, size_t, size_t, void*);
  379. typedef size_t (_curl_write_callback2)(const char *, size_t, size_t,
  380. const void*);
  381. typedef size_t (_curl_write_callback3)(const char *, size_t, size_t, FILE*);
  382. typedef size_t (_curl_write_callback4)(const void *, size_t, size_t, void*);
  383. typedef size_t (_curl_write_callback5)(const void *, size_t, size_t,
  384. const void*);
  385. typedef size_t (_curl_write_callback6)(const void *, size_t, size_t, FILE*);
  386. /* evaluates to true if expr is of type curl_ioctl_callback or "similar" */
  387. #define _curl_is_ioctl_cb(expr) \
  388. (_curl_is_NULL(expr) || \
  389. __builtin_types_compatible_p(__typeof__(expr), curl_ioctl_callback) || \
  390. _curl_callback_compatible((expr), _curl_ioctl_callback1) || \
  391. _curl_callback_compatible((expr), _curl_ioctl_callback2) || \
  392. _curl_callback_compatible((expr), _curl_ioctl_callback3) || \
  393. _curl_callback_compatible((expr), _curl_ioctl_callback4))
  394. typedef curlioerr (_curl_ioctl_callback1)(CURL *, int, void*);
  395. typedef curlioerr (_curl_ioctl_callback2)(CURL *, int, const void*);
  396. typedef curlioerr (_curl_ioctl_callback3)(CURL *, curliocmd, void*);
  397. typedef curlioerr (_curl_ioctl_callback4)(CURL *, curliocmd, const void*);
  398. /* evaluates to true if expr is of type curl_sockopt_callback or "similar" */
  399. #define _curl_is_sockopt_cb(expr) \
  400. (_curl_is_NULL(expr) || \
  401. __builtin_types_compatible_p(__typeof__(expr), curl_sockopt_callback) || \
  402. _curl_callback_compatible((expr), _curl_sockopt_callback1) || \
  403. _curl_callback_compatible((expr), _curl_sockopt_callback2))
  404. typedef int (_curl_sockopt_callback1)(void *, curl_socket_t, curlsocktype);
  405. typedef int (_curl_sockopt_callback2)(const void *, curl_socket_t,
  406. curlsocktype);
  407. /* evaluates to true if expr is of type curl_opensocket_callback or "similar" */
  408. #define _curl_is_opensocket_cb(expr) \
  409. (_curl_is_NULL(expr) || \
  410. __builtin_types_compatible_p(__typeof__(expr), curl_opensocket_callback) ||\
  411. _curl_callback_compatible((expr), _curl_opensocket_callback1) || \
  412. _curl_callback_compatible((expr), _curl_opensocket_callback2) || \
  413. _curl_callback_compatible((expr), _curl_opensocket_callback3) || \
  414. _curl_callback_compatible((expr), _curl_opensocket_callback4))
  415. typedef curl_socket_t (_curl_opensocket_callback1)
  416. (void *, curlsocktype, struct curl_sockaddr *);
  417. typedef curl_socket_t (_curl_opensocket_callback2)
  418. (void *, curlsocktype, const struct curl_sockaddr *);
  419. typedef curl_socket_t (_curl_opensocket_callback3)
  420. (const void *, curlsocktype, struct curl_sockaddr *);
  421. typedef curl_socket_t (_curl_opensocket_callback4)
  422. (const void *, curlsocktype, const struct curl_sockaddr *);
  423. /* evaluates to true if expr is of type curl_progress_callback or "similar" */
  424. #define _curl_is_progress_cb(expr) \
  425. (_curl_is_NULL(expr) || \
  426. __builtin_types_compatible_p(__typeof__(expr), curl_progress_callback) || \
  427. _curl_callback_compatible((expr), _curl_progress_callback1) || \
  428. _curl_callback_compatible((expr), _curl_progress_callback2))
  429. typedef int (_curl_progress_callback1)(void *,
  430. double, double, double, double);
  431. typedef int (_curl_progress_callback2)(const void *,
  432. double, double, double, double);
  433. /* evaluates to true if expr is of type curl_debug_callback or "similar" */
  434. #define _curl_is_debug_cb(expr) \
  435. (_curl_is_NULL(expr) || \
  436. __builtin_types_compatible_p(__typeof__(expr), curl_debug_callback) || \
  437. _curl_callback_compatible((expr), _curl_debug_callback1) || \
  438. _curl_callback_compatible((expr), _curl_debug_callback2) || \
  439. _curl_callback_compatible((expr), _curl_debug_callback3) || \
  440. _curl_callback_compatible((expr), _curl_debug_callback4))
  441. typedef int (_curl_debug_callback1) (CURL *,
  442. curl_infotype, char *, size_t, void *);
  443. typedef int (_curl_debug_callback2) (CURL *,
  444. curl_infotype, char *, size_t, const void *);
  445. typedef int (_curl_debug_callback3) (CURL *,
  446. curl_infotype, const char *, size_t, void *);
  447. typedef int (_curl_debug_callback4) (CURL *,
  448. curl_infotype, const char *, size_t, const void *);
  449. /* evaluates to true if expr is of type curl_ssl_ctx_callback or "similar" */
  450. /* this is getting even messier... */
  451. #define _curl_is_ssl_ctx_cb(expr) \
  452. (_curl_is_NULL(expr) || \
  453. __builtin_types_compatible_p(__typeof__(expr), curl_ssl_ctx_callback) || \
  454. _curl_callback_compatible((expr), _curl_ssl_ctx_callback1) || \
  455. _curl_callback_compatible((expr), _curl_ssl_ctx_callback2) || \
  456. _curl_callback_compatible((expr), _curl_ssl_ctx_callback3) || \
  457. _curl_callback_compatible((expr), _curl_ssl_ctx_callback4) || \
  458. _curl_callback_compatible((expr), _curl_ssl_ctx_callback5) || \
  459. _curl_callback_compatible((expr), _curl_ssl_ctx_callback6) || \
  460. _curl_callback_compatible((expr), _curl_ssl_ctx_callback7) || \
  461. _curl_callback_compatible((expr), _curl_ssl_ctx_callback8))
  462. typedef CURLcode (_curl_ssl_ctx_callback1)(CURL *, void *, void *);
  463. typedef CURLcode (_curl_ssl_ctx_callback2)(CURL *, void *, const void *);
  464. typedef CURLcode (_curl_ssl_ctx_callback3)(CURL *, const void *, void *);
  465. typedef CURLcode (_curl_ssl_ctx_callback4)(CURL *, const void *, const void *);
  466. #ifdef HEADER_SSL_H
  467. /* hack: if we included OpenSSL's ssl.h, we know about SSL_CTX
  468. * this will of course break if we're included before OpenSSL headers...
  469. */
  470. typedef CURLcode (_curl_ssl_ctx_callback5)(CURL *, SSL_CTX, void *);
  471. typedef CURLcode (_curl_ssl_ctx_callback6)(CURL *, SSL_CTX, const void *);
  472. typedef CURLcode (_curl_ssl_ctx_callback7)(CURL *, const SSL_CTX, void *);
  473. typedef CURLcode (_curl_ssl_ctx_callback8)(CURL *, const SSL_CTX, const void *);
  474. #else
  475. typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback5;
  476. typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback6;
  477. typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback7;
  478. typedef _curl_ssl_ctx_callback1 _curl_ssl_ctx_callback8;
  479. #endif
  480. /* evaluates to true if expr is of type curl_conv_callback or "similar" */
  481. #define _curl_is_conv_cb(expr) \
  482. (_curl_is_NULL(expr) || \
  483. __builtin_types_compatible_p(__typeof__(expr), curl_conv_callback) || \
  484. _curl_callback_compatible((expr), _curl_conv_callback1) || \
  485. _curl_callback_compatible((expr), _curl_conv_callback2) || \
  486. _curl_callback_compatible((expr), _curl_conv_callback3) || \
  487. _curl_callback_compatible((expr), _curl_conv_callback4))
  488. typedef CURLcode (*_curl_conv_callback1)(char *, size_t length);
  489. typedef CURLcode (*_curl_conv_callback2)(const char *, size_t length);
  490. typedef CURLcode (*_curl_conv_callback3)(void *, size_t length);
  491. typedef CURLcode (*_curl_conv_callback4)(const void *, size_t length);
  492. /* evaluates to true if expr is of type curl_seek_callback or "similar" */
  493. #define _curl_is_seek_cb(expr) \
  494. (_curl_is_NULL(expr) || \
  495. __builtin_types_compatible_p(__typeof__(expr), curl_seek_callback) || \
  496. _curl_callback_compatible((expr), _curl_seek_callback1) || \
  497. _curl_callback_compatible((expr), _curl_seek_callback2))
  498. typedef CURLcode (*_curl_seek_callback1)(void *, curl_off_t, int);
  499. typedef CURLcode (*_curl_seek_callback2)(const void *, curl_off_t, int);
  500. #endif /* __CURL_TYPECHECK_GCC_H */