typecheck-gcc.h 41 KB

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