curl_setup.h 24 KB

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