curl_setup.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845
  1. #ifndef HEADER_CURL_SETUP_H
  2. #define HEADER_CURL_SETUP_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 1998 - 2021, 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. ***************************************************************************/
  24. #if defined(BUILDING_LIBCURL) && !defined(CURL_NO_OLDIES)
  25. #define CURL_NO_OLDIES
  26. #endif
  27. /*
  28. * Disable Visual Studio warnings:
  29. * 4127 "conditional expression is constant"
  30. */
  31. #ifdef _MSC_VER
  32. #pragma warning(disable:4127)
  33. #endif
  34. /*
  35. * Define WIN32 when build target is Win32 API
  36. */
  37. #if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
  38. #define WIN32
  39. #endif
  40. #ifdef WIN32
  41. /*
  42. * Don't include unneeded stuff in Windows headers to avoid compiler
  43. * warnings and macro clashes.
  44. * Make sure to define this macro before including any Windows headers.
  45. */
  46. # ifndef WIN32_LEAN_AND_MEAN
  47. # define WIN32_LEAN_AND_MEAN
  48. # endif
  49. # ifndef NOGDI
  50. # define NOGDI
  51. # endif
  52. /* Detect Windows App environment which has a restricted access
  53. * to the Win32 APIs. */
  54. # if (defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)) || \
  55. defined(WINAPI_FAMILY)
  56. # include <winapifamily.h>
  57. # if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \
  58. !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
  59. # define CURL_WINDOWS_APP
  60. # endif
  61. # endif
  62. #endif
  63. /*
  64. * Include configuration script results or hand-crafted
  65. * configuration file for platforms which lack config tool.
  66. */
  67. #ifdef HAVE_CONFIG_H
  68. #include "curl_config.h"
  69. #else /* HAVE_CONFIG_H */
  70. #ifdef _WIN32_WCE
  71. # include "config-win32ce.h"
  72. #else
  73. # ifdef WIN32
  74. # include "config-win32.h"
  75. # endif
  76. #endif
  77. #if defined(macintosh) && defined(__MRC__)
  78. # include "config-mac.h"
  79. #endif
  80. #ifdef __riscos__
  81. # include "config-riscos.h"
  82. #endif
  83. #ifdef __AMIGA__
  84. # include "config-amigaos.h"
  85. #endif
  86. #ifdef __OS400__
  87. # include "config-os400.h"
  88. #endif
  89. #ifdef TPF
  90. # include "config-tpf.h"
  91. #endif
  92. #ifdef __VXWORKS__
  93. # include "config-vxworks.h"
  94. #endif
  95. #ifdef __PLAN9__
  96. # include "config-plan9.h"
  97. #endif
  98. #endif /* HAVE_CONFIG_H */
  99. /* ================================================================ */
  100. /* Definition of preprocessor macros/symbols which modify compiler */
  101. /* behavior or generated code characteristics must be done here, */
  102. /* as appropriate, before any system header file is included. It is */
  103. /* also possible to have them defined in the config file included */
  104. /* before this point. As a result of all this we frown inclusion of */
  105. /* system header files in our config files, avoid this at any cost. */
  106. /* ================================================================ */
  107. /*
  108. * AIX 4.3 and newer needs _THREAD_SAFE defined to build
  109. * proper reentrant code. Others may also need it.
  110. */
  111. #ifdef NEED_THREAD_SAFE
  112. # ifndef _THREAD_SAFE
  113. # define _THREAD_SAFE
  114. # endif
  115. #endif
  116. /*
  117. * Tru64 needs _REENTRANT set for a few function prototypes and
  118. * things to appear in the system header files. Unixware needs it
  119. * to build proper reentrant code. Others may also need it.
  120. */
  121. #ifdef NEED_REENTRANT
  122. # ifndef _REENTRANT
  123. # define _REENTRANT
  124. # endif
  125. #endif
  126. /* Solaris needs this to get a POSIX-conformant getpwuid_r */
  127. #if defined(sun) || defined(__sun)
  128. # ifndef _POSIX_PTHREAD_SEMANTICS
  129. # define _POSIX_PTHREAD_SEMANTICS 1
  130. # endif
  131. #endif
  132. /* ================================================================ */
  133. /* If you need to include a system header file for your platform, */
  134. /* please, do it beyond the point further indicated in this file. */
  135. /* ================================================================ */
  136. #include <curl/curl.h>
  137. /*
  138. * Disable other protocols when http is the only one desired.
  139. */
  140. #ifdef HTTP_ONLY
  141. # ifndef CURL_DISABLE_DICT
  142. # define CURL_DISABLE_DICT
  143. # endif
  144. # ifndef CURL_DISABLE_FILE
  145. # define CURL_DISABLE_FILE
  146. # endif
  147. # ifndef CURL_DISABLE_FTP
  148. # define CURL_DISABLE_FTP
  149. # endif
  150. # ifndef CURL_DISABLE_GOPHER
  151. # define CURL_DISABLE_GOPHER
  152. # endif
  153. # ifndef CURL_DISABLE_IMAP
  154. # define CURL_DISABLE_IMAP
  155. # endif
  156. # ifndef CURL_DISABLE_LDAP
  157. # define CURL_DISABLE_LDAP
  158. # endif
  159. # ifndef CURL_DISABLE_LDAPS
  160. # define CURL_DISABLE_LDAPS
  161. # endif
  162. # ifndef CURL_DISABLE_MQTT
  163. # define CURL_DISABLE_MQTT
  164. # endif
  165. # ifndef CURL_DISABLE_POP3
  166. # define CURL_DISABLE_POP3
  167. # endif
  168. # ifndef CURL_DISABLE_RTSP
  169. # define CURL_DISABLE_RTSP
  170. # endif
  171. # ifndef CURL_DISABLE_SMB
  172. # define CURL_DISABLE_SMB
  173. # endif
  174. # ifndef CURL_DISABLE_SMTP
  175. # define CURL_DISABLE_SMTP
  176. # endif
  177. # ifndef CURL_DISABLE_TELNET
  178. # define CURL_DISABLE_TELNET
  179. # endif
  180. # ifndef CURL_DISABLE_TFTP
  181. # define CURL_DISABLE_TFTP
  182. # endif
  183. #endif
  184. /*
  185. * When http is disabled rtsp is not supported.
  186. */
  187. #if defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_RTSP)
  188. # define CURL_DISABLE_RTSP
  189. #endif
  190. /* ================================================================ */
  191. /* No system header file shall be included in this file before this */
  192. /* point. The only allowed ones are those included from curl/system.h */
  193. /* ================================================================ */
  194. /*
  195. * OS/400 setup file includes some system headers.
  196. */
  197. #ifdef __OS400__
  198. # include "setup-os400.h"
  199. #endif
  200. /*
  201. * VMS setup file includes some system headers.
  202. */
  203. #ifdef __VMS
  204. # include "setup-vms.h"
  205. #endif
  206. /*
  207. * Windows setup file includes some system headers.
  208. */
  209. #ifdef HAVE_WINDOWS_H
  210. # include "setup-win32.h"
  211. #endif
  212. /*
  213. * Use getaddrinfo to resolve the IPv4 address literal. If the current network
  214. * interface doesn't support IPv4, but supports IPv6, NAT64, and DNS64,
  215. * performing this task will result in a synthesized IPv6 address.
  216. */
  217. #if defined(__APPLE__) && !defined(USE_ARES)
  218. #include <TargetConditionals.h>
  219. #define USE_RESOLVE_ON_IPS 1
  220. # if defined(TARGET_OS_OSX) && TARGET_OS_OSX
  221. # define CURL_OSX_CALL_COPYPROXIES 1
  222. # endif
  223. #endif
  224. #ifdef USE_LWIPSOCK
  225. # include <lwip/init.h>
  226. # include <lwip/sockets.h>
  227. # include <lwip/netdb.h>
  228. #endif
  229. #ifdef HAVE_EXTRA_STRICMP_H
  230. # include <extra/stricmp.h>
  231. #endif
  232. #ifdef HAVE_EXTRA_STRDUP_H
  233. # include <extra/strdup.h>
  234. #endif
  235. #ifdef TPF
  236. # include <strings.h> /* for bzero, strcasecmp, and strncasecmp */
  237. # include <string.h> /* for strcpy and strlen */
  238. # include <stdlib.h> /* for rand and srand */
  239. # include <sys/socket.h> /* for select and ioctl*/
  240. # include <netdb.h> /* for in_addr_t definition */
  241. # include <tpf/sysapi.h> /* for tpf_process_signals */
  242. /* change which select is used for libcurl */
  243. # define select(a,b,c,d,e) tpf_select_libcurl(a,b,c,d,e)
  244. #endif
  245. #ifdef __VXWORKS__
  246. # include <sockLib.h> /* for generic BSD socket functions */
  247. # include <ioLib.h> /* for basic I/O interface functions */
  248. #endif
  249. #ifdef __AMIGA__
  250. # include <exec/types.h>
  251. # include <exec/execbase.h>
  252. # include <proto/exec.h>
  253. # include <proto/dos.h>
  254. # include <unistd.h>
  255. # ifdef HAVE_PROTO_BSDSOCKET_H
  256. # include <proto/bsdsocket.h> /* ensure bsdsocket.library use */
  257. # define select(a,b,c,d,e) WaitSelect(a,b,c,d,e,0)
  258. # endif
  259. /*
  260. * In clib2 arpa/inet.h warns that some prototypes may clash
  261. * with bsdsocket.library. This avoids the definition of those.
  262. */
  263. # define __NO_NET_API
  264. #endif
  265. #include <stdio.h>
  266. #ifdef HAVE_ASSERT_H
  267. #include <assert.h>
  268. #endif
  269. #ifdef __TANDEM /* for nsr-tandem-nsk systems */
  270. #include <floss.h>
  271. #endif
  272. #ifndef STDC_HEADERS /* no standard C headers! */
  273. #include <curl/stdcheaders.h>
  274. #endif
  275. #ifdef __POCC__
  276. # include <sys/types.h>
  277. # include <unistd.h>
  278. # define sys_nerr EILSEQ
  279. #endif
  280. /*
  281. * Salford-C kludge section (mostly borrowed from wxWidgets).
  282. */
  283. #ifdef __SALFORDC__
  284. #pragma suppress 353 /* Possible nested comments */
  285. #pragma suppress 593 /* Define not used */
  286. #pragma suppress 61 /* enum has no name */
  287. #pragma suppress 106 /* unnamed, unused parameter */
  288. #include <clib.h>
  289. #endif
  290. /*
  291. * Large file (>2Gb) support using WIN32 functions.
  292. */
  293. #ifdef USE_WIN32_LARGE_FILES
  294. # include <io.h>
  295. # include <sys/types.h>
  296. # include <sys/stat.h>
  297. # undef lseek
  298. # define lseek(fdes,offset,whence) _lseeki64(fdes, offset, whence)
  299. # undef fstat
  300. # define fstat(fdes,stp) _fstati64(fdes, stp)
  301. # undef stat
  302. # define stat(fname,stp) curlx_win32_stat(fname, stp)
  303. # define struct_stat struct _stati64
  304. # define LSEEK_ERROR (__int64)-1
  305. # define open curlx_win32_open
  306. # define fopen(fname,mode) curlx_win32_fopen(fname, mode)
  307. # define access(fname,mode) curlx_win32_access(fname, mode)
  308. int curlx_win32_open(const char *filename, int oflag, ...);
  309. int curlx_win32_stat(const char *path, struct_stat *buffer);
  310. FILE *curlx_win32_fopen(const char *filename, const char *mode);
  311. int curlx_win32_access(const char *path, int mode);
  312. #endif
  313. /*
  314. * Small file (<2Gb) support using WIN32 functions.
  315. */
  316. #ifdef USE_WIN32_SMALL_FILES
  317. # include <io.h>
  318. # include <sys/types.h>
  319. # include <sys/stat.h>
  320. # ifndef _WIN32_WCE
  321. # undef lseek
  322. # define lseek(fdes,offset,whence) _lseek(fdes, (long)offset, whence)
  323. # define fstat(fdes,stp) _fstat(fdes, stp)
  324. # define stat(fname,stp) curlx_win32_stat(fname, stp)
  325. # define struct_stat struct _stat
  326. # define open curlx_win32_open
  327. # define fopen(fname,mode) curlx_win32_fopen(fname, mode)
  328. # define access(fname,mode) curlx_win32_access(fname, mode)
  329. int curlx_win32_stat(const char *path, struct_stat *buffer);
  330. int curlx_win32_open(const char *filename, int oflag, ...);
  331. FILE *curlx_win32_fopen(const char *filename, const char *mode);
  332. int curlx_win32_access(const char *path, int mode);
  333. # endif
  334. # define LSEEK_ERROR (long)-1
  335. #endif
  336. #ifndef struct_stat
  337. # define struct_stat struct stat
  338. #endif
  339. #ifndef LSEEK_ERROR
  340. # define LSEEK_ERROR (off_t)-1
  341. #endif
  342. #ifndef SIZEOF_TIME_T
  343. /* assume default size of time_t to be 32 bit */
  344. #define SIZEOF_TIME_T 4
  345. #endif
  346. /*
  347. * Default sizeof(off_t) in case it hasn't been defined in config file.
  348. */
  349. #ifndef SIZEOF_OFF_T
  350. # if defined(__VMS) && !defined(__VAX)
  351. # if defined(_LARGEFILE)
  352. # define SIZEOF_OFF_T 8
  353. # endif
  354. # elif defined(__OS400__) && defined(__ILEC400__)
  355. # if defined(_LARGE_FILES)
  356. # define SIZEOF_OFF_T 8
  357. # endif
  358. # elif defined(__MVS__) && defined(__IBMC__)
  359. # if defined(_LP64) || defined(_LARGE_FILES)
  360. # define SIZEOF_OFF_T 8
  361. # endif
  362. # elif defined(__370__) && defined(__IBMC__)
  363. # if defined(_LP64) || defined(_LARGE_FILES)
  364. # define SIZEOF_OFF_T 8
  365. # endif
  366. # endif
  367. # ifndef SIZEOF_OFF_T
  368. # define SIZEOF_OFF_T 4
  369. # endif
  370. #endif
  371. #if (SIZEOF_CURL_OFF_T == 4)
  372. # define CURL_OFF_T_MAX CURL_OFF_T_C(0x7FFFFFFF)
  373. #else
  374. /* assume SIZEOF_CURL_OFF_T == 8 */
  375. # define CURL_OFF_T_MAX CURL_OFF_T_C(0x7FFFFFFFFFFFFFFF)
  376. #endif
  377. #define CURL_OFF_T_MIN (-CURL_OFF_T_MAX - CURL_OFF_T_C(1))
  378. #if (SIZEOF_TIME_T == 4)
  379. # ifdef HAVE_TIME_T_UNSIGNED
  380. # define TIME_T_MAX UINT_MAX
  381. # define TIME_T_MIN 0
  382. # else
  383. # define TIME_T_MAX INT_MAX
  384. # define TIME_T_MIN INT_MIN
  385. # endif
  386. #else
  387. # ifdef HAVE_TIME_T_UNSIGNED
  388. # define TIME_T_MAX 0xFFFFFFFFFFFFFFFF
  389. # define TIME_T_MIN 0
  390. # else
  391. # define TIME_T_MAX 0x7FFFFFFFFFFFFFFF
  392. # define TIME_T_MIN (-TIME_T_MAX - 1)
  393. # endif
  394. #endif
  395. #ifndef SIZE_T_MAX
  396. /* some limits.h headers have this defined, some don't */
  397. #if defined(SIZEOF_SIZE_T) && (SIZEOF_SIZE_T > 4)
  398. #define SIZE_T_MAX 18446744073709551615U
  399. #else
  400. #define SIZE_T_MAX 4294967295U
  401. #endif
  402. #endif
  403. #ifndef SSIZE_T_MAX
  404. /* some limits.h headers have this defined, some don't */
  405. #if defined(SIZEOF_SIZE_T) && (SIZEOF_SIZE_T > 4)
  406. #define SSIZE_T_MAX 9223372036854775807
  407. #else
  408. #define SSIZE_T_MAX 2147483647
  409. #endif
  410. #endif
  411. /*
  412. * Arg 2 type for gethostname in case it hasn't been defined in config file.
  413. */
  414. #ifndef GETHOSTNAME_TYPE_ARG2
  415. # ifdef USE_WINSOCK
  416. # define GETHOSTNAME_TYPE_ARG2 int
  417. # else
  418. # define GETHOSTNAME_TYPE_ARG2 size_t
  419. # endif
  420. #endif
  421. /* Below we define some functions. They should
  422. 4. set the SIGALRM signal timeout
  423. 5. set dir/file naming defines
  424. */
  425. #ifdef WIN32
  426. # define DIR_CHAR "\\"
  427. #else /* WIN32 */
  428. # ifdef MSDOS /* Watt-32 */
  429. # include <sys/ioctl.h>
  430. # define select(n,r,w,x,t) select_s(n,r,w,x,t)
  431. # define ioctl(x,y,z) ioctlsocket(x,y,(char *)(z))
  432. # include <tcp.h>
  433. # ifdef word
  434. # undef word
  435. # endif
  436. # ifdef byte
  437. # undef byte
  438. # endif
  439. # endif /* MSDOS */
  440. # ifdef __minix
  441. /* Minix 3 versions up to at least 3.1.3 are missing these prototypes */
  442. extern char *strtok_r(char *s, const char *delim, char **last);
  443. extern struct tm *gmtime_r(const time_t * const timep, struct tm *tmp);
  444. # endif
  445. # define DIR_CHAR "/"
  446. # ifndef fileno /* sunos 4 have this as a macro! */
  447. int fileno(FILE *stream);
  448. # endif
  449. #endif /* WIN32 */
  450. /*
  451. * msvc 6.0 requires PSDK in order to have INET6_ADDRSTRLEN
  452. * defined in ws2tcpip.h as well as to provide IPv6 support.
  453. * Does not apply if lwIP is used.
  454. */
  455. #if defined(_MSC_VER) && !defined(__POCC__) && !defined(USE_LWIPSOCK)
  456. # if !defined(HAVE_WS2TCPIP_H) || \
  457. ((_MSC_VER < 1300) && !defined(INET6_ADDRSTRLEN))
  458. # undef HAVE_GETADDRINFO_THREADSAFE
  459. # undef HAVE_FREEADDRINFO
  460. # undef HAVE_GETADDRINFO
  461. # undef ENABLE_IPV6
  462. # endif
  463. #endif
  464. /* ---------------------------------------------------------------- */
  465. /* resolver specialty compile-time defines */
  466. /* CURLRES_* defines to use in the host*.c sources */
  467. /* ---------------------------------------------------------------- */
  468. /*
  469. * lcc-win32 doesn't have _beginthreadex(), lacks threads support.
  470. */
  471. #if defined(__LCC__) && defined(WIN32)
  472. # undef USE_THREADS_POSIX
  473. # undef USE_THREADS_WIN32
  474. #endif
  475. /*
  476. * MSVC threads support requires a multi-threaded runtime library.
  477. * _beginthreadex() is not available in single-threaded ones.
  478. */
  479. #if defined(_MSC_VER) && !defined(__POCC__) && !defined(_MT)
  480. # undef USE_THREADS_POSIX
  481. # undef USE_THREADS_WIN32
  482. #endif
  483. /*
  484. * Mutually exclusive CURLRES_* definitions.
  485. */
  486. #if defined(ENABLE_IPV6) && defined(HAVE_GETADDRINFO)
  487. # define CURLRES_IPV6
  488. #else
  489. # define CURLRES_IPV4
  490. #endif
  491. #ifdef USE_ARES
  492. # define CURLRES_ASYNCH
  493. # define CURLRES_ARES
  494. /* now undef the stock libc functions just to avoid them being used */
  495. # undef HAVE_GETADDRINFO
  496. # undef HAVE_FREEADDRINFO
  497. # undef HAVE_GETHOSTBYNAME
  498. #elif defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
  499. # define CURLRES_ASYNCH
  500. # define CURLRES_THREADED
  501. #else
  502. # define CURLRES_SYNCH
  503. #endif
  504. /* ---------------------------------------------------------------- */
  505. /*
  506. * msvc 6.0 does not have struct sockaddr_storage and
  507. * does not define IPPROTO_ESP in winsock2.h. But both
  508. * are available if PSDK is properly installed.
  509. */
  510. #if defined(_MSC_VER) && !defined(__POCC__)
  511. # if !defined(HAVE_WINSOCK2_H) || ((_MSC_VER < 1300) && !defined(IPPROTO_ESP))
  512. # undef HAVE_STRUCT_SOCKADDR_STORAGE
  513. # endif
  514. #endif
  515. /*
  516. * Intentionally fail to build when using msvc 6.0 without PSDK installed.
  517. * The brave of heart can circumvent this, defining ALLOW_MSVC6_WITHOUT_PSDK
  518. * in lib/config-win32.h although absolutely discouraged and unsupported.
  519. */
  520. #if defined(_MSC_VER) && !defined(__POCC__)
  521. # if !defined(HAVE_WINDOWS_H) || ((_MSC_VER < 1300) && !defined(_FILETIME_))
  522. # if !defined(ALLOW_MSVC6_WITHOUT_PSDK)
  523. # error MSVC 6.0 requires "February 2003 Platform SDK" a.k.a. \
  524. "Windows Server 2003 PSDK"
  525. # else
  526. # define CURL_DISABLE_LDAP 1
  527. # endif
  528. # endif
  529. #endif
  530. #ifdef NETWARE
  531. int netware_init(void);
  532. #ifndef __NOVELL_LIBC__
  533. #include <sys/bsdskt.h>
  534. #include <sys/timeval.h>
  535. #endif
  536. #endif
  537. #if defined(HAVE_LIBIDN2) && defined(HAVE_IDN2_H) && !defined(USE_WIN32_IDN)
  538. /* The lib and header are present */
  539. #define USE_LIBIDN2
  540. #endif
  541. #if defined(USE_LIBIDN2) && defined(USE_WIN32_IDN)
  542. #error "Both libidn2 and WinIDN are enabled, choose one."
  543. #endif
  544. #define LIBIDN_REQUIRED_VERSION "0.4.1"
  545. #if defined(USE_GNUTLS) || defined(USE_OPENSSL) || defined(USE_NSS) || \
  546. defined(USE_MBEDTLS) || \
  547. defined(USE_WOLFSSL) || defined(USE_SCHANNEL) || \
  548. defined(USE_SECTRANSP) || defined(USE_GSKIT) || defined(USE_MESALINK) || \
  549. defined(USE_BEARSSL) || defined(USE_RUSTLS)
  550. #define USE_SSL /* SSL support has been enabled */
  551. #endif
  552. /* Single point where USE_SPNEGO definition might be defined */
  553. #if !defined(CURL_DISABLE_CRYPTO_AUTH) && \
  554. (defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI))
  555. #define USE_SPNEGO
  556. #endif
  557. /* Single point where USE_KERBEROS5 definition might be defined */
  558. #if !defined(CURL_DISABLE_CRYPTO_AUTH) && \
  559. (defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI))
  560. #define USE_KERBEROS5
  561. #endif
  562. /* Single point where USE_NTLM definition might be defined */
  563. #if !defined(CURL_DISABLE_CRYPTO_AUTH) && !defined(CURL_DISABLE_NTLM)
  564. # if defined(USE_OPENSSL) || defined(USE_MBEDTLS) || \
  565. defined(USE_GNUTLS) || defined(USE_NSS) || defined(USE_SECTRANSP) || \
  566. defined(USE_OS400CRYPTO) || defined(USE_WIN32_CRYPTO) || \
  567. (defined(USE_WOLFSSL) && defined(HAVE_WOLFSSL_DES_ECB_ENCRYPT))
  568. # define USE_CURL_NTLM_CORE
  569. # endif
  570. # if defined(USE_CURL_NTLM_CORE) || defined(USE_WINDOWS_SSPI)
  571. # define USE_NTLM
  572. # endif
  573. #endif
  574. #ifdef CURL_WANTS_CA_BUNDLE_ENV
  575. #error "No longer supported. Set CURLOPT_CAINFO at runtime instead."
  576. #endif
  577. #if defined(USE_LIBSSH2) || defined(USE_LIBSSH) || defined(USE_WOLFSSH)
  578. #define USE_SSH
  579. #endif
  580. /*
  581. * Provide a mechanism to silence picky compilers, such as gcc 4.6+.
  582. * Parameters should of course normally not be unused, but for example when
  583. * we have multiple implementations of the same interface it may happen.
  584. */
  585. #if defined(__GNUC__) && ((__GNUC__ >= 3) || \
  586. ((__GNUC__ == 2) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ >= 7)))
  587. # define UNUSED_PARAM __attribute__((__unused__))
  588. # define WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  589. #else
  590. # define UNUSED_PARAM /*NOTHING*/
  591. # define WARN_UNUSED_RESULT
  592. #endif
  593. /*
  594. * Include macros and defines that should only be processed once.
  595. */
  596. #ifndef HEADER_CURL_SETUP_ONCE_H
  597. #include "curl_setup_once.h"
  598. #endif
  599. /*
  600. * Definition of our NOP statement Object-like macro
  601. */
  602. #ifndef Curl_nop_stmt
  603. # define Curl_nop_stmt do { } while(0)
  604. #endif
  605. /*
  606. * Ensure that Winsock and lwIP TCP/IP stacks are not mixed.
  607. */
  608. #if defined(__LWIP_OPT_H__) || defined(LWIP_HDR_OPT_H)
  609. # if defined(SOCKET) || \
  610. defined(USE_WINSOCK) || \
  611. defined(HAVE_WINSOCK_H) || \
  612. defined(HAVE_WINSOCK2_H) || \
  613. defined(HAVE_WS2TCPIP_H)
  614. # error "WinSock and lwIP TCP/IP stack definitions shall not coexist!"
  615. # endif
  616. #endif
  617. /*
  618. * shutdown() flags for systems that don't define them
  619. */
  620. #ifndef SHUT_RD
  621. #define SHUT_RD 0x00
  622. #endif
  623. #ifndef SHUT_WR
  624. #define SHUT_WR 0x01
  625. #endif
  626. #ifndef SHUT_RDWR
  627. #define SHUT_RDWR 0x02
  628. #endif
  629. /* Define S_ISREG if not defined by system headers, f.e. MSVC */
  630. #if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
  631. #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  632. #endif
  633. /* Define S_ISDIR if not defined by system headers, f.e. MSVC */
  634. #if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR)
  635. #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  636. #endif
  637. /* In Windows the default file mode is text but an application can override it.
  638. Therefore we specify it explicitly. https://github.com/curl/curl/pull/258
  639. */
  640. #if defined(WIN32) || defined(MSDOS)
  641. #define FOPEN_READTEXT "rt"
  642. #define FOPEN_WRITETEXT "wt"
  643. #define FOPEN_APPENDTEXT "at"
  644. #elif defined(__CYGWIN__)
  645. /* Cygwin has specific behavior we need to address when WIN32 is not defined.
  646. https://cygwin.com/cygwin-ug-net/using-textbinary.html
  647. For write we want our output to have line endings of LF and be compatible with
  648. other Cygwin utilities. For read we want to handle input that may have line
  649. endings either CRLF or LF so 't' is appropriate.
  650. */
  651. #define FOPEN_READTEXT "rt"
  652. #define FOPEN_WRITETEXT "w"
  653. #define FOPEN_APPENDTEXT "a"
  654. #else
  655. #define FOPEN_READTEXT "r"
  656. #define FOPEN_WRITETEXT "w"
  657. #define FOPEN_APPENDTEXT "a"
  658. #endif
  659. /* WinSock destroys recv() buffer when send() failed.
  660. * Enabled automatically for Windows and for Cygwin as Cygwin sockets are
  661. * wrappers for WinSock sockets. https://github.com/curl/curl/issues/657
  662. * Define DONT_USE_RECV_BEFORE_SEND_WORKAROUND to force disable workaround.
  663. */
  664. #if !defined(DONT_USE_RECV_BEFORE_SEND_WORKAROUND)
  665. # if defined(WIN32) || defined(__CYGWIN__)
  666. # define USE_RECV_BEFORE_SEND_WORKAROUND
  667. # endif
  668. #else /* DONT_USE_RECV_BEFORE_SEND_WORKAROUND */
  669. # ifdef USE_RECV_BEFORE_SEND_WORKAROUND
  670. # undef USE_RECV_BEFORE_SEND_WORKAROUND
  671. # endif
  672. #endif /* DONT_USE_RECV_BEFORE_SEND_WORKAROUND */
  673. /* for systems that don't detect this in configure */
  674. #ifndef CURL_SA_FAMILY_T
  675. # if defined(HAVE_SA_FAMILY_T)
  676. # define CURL_SA_FAMILY_T sa_family_t
  677. # elif defined(HAVE_ADDRESS_FAMILY)
  678. # define CURL_SA_FAMILY_T ADDRESS_FAMILY
  679. # else
  680. /* use a sensible default */
  681. # define CURL_SA_FAMILY_T unsigned short
  682. # endif
  683. #endif
  684. /* Some convenience macros to get the larger/smaller value out of two given.
  685. We prefix with CURL to prevent name collisions. */
  686. #define CURLMAX(x,y) ((x)>(y)?(x):(y))
  687. #define CURLMIN(x,y) ((x)<(y)?(x):(y))
  688. /* Some versions of the Android SDK is missing the declaration */
  689. #if defined(HAVE_GETPWUID_R) && defined(HAVE_DECL_GETPWUID_R_MISSING)
  690. struct passwd;
  691. int getpwuid_r(uid_t uid, struct passwd *pwd, char *buf,
  692. size_t buflen, struct passwd **result);
  693. #endif
  694. #ifdef DEBUGBUILD
  695. #define UNITTEST
  696. #else
  697. #define UNITTEST static
  698. #endif
  699. #if defined(USE_NGHTTP2) || defined(USE_HYPER)
  700. #define USE_HTTP2
  701. #endif
  702. #if defined(USE_NGTCP2) || defined(USE_QUICHE)
  703. #define ENABLE_QUIC
  704. #endif
  705. #if defined(USE_UNIX_SOCKETS) && defined(WIN32)
  706. # if defined(__MINGW32__) && !defined(LUP_SECURE)
  707. typedef u_short ADDRESS_FAMILY; /* Classic mingw, 11y+ old mingw-w64 */
  708. # endif
  709. # if !defined(UNIX_PATH_MAX)
  710. /* Replicating logic present in afunix.h
  711. (distributed with newer Windows 10 SDK versions only) */
  712. # define UNIX_PATH_MAX 108
  713. /* !checksrc! disable TYPEDEFSTRUCT 1 */
  714. typedef struct sockaddr_un {
  715. ADDRESS_FAMILY sun_family;
  716. char sun_path[UNIX_PATH_MAX];
  717. } SOCKADDR_UN, *PSOCKADDR_UN;
  718. # endif
  719. #endif
  720. #endif /* HEADER_CURL_SETUP_H */