typecheck-gcc.h 43 KB

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