1 #ifndef HEADER_CURL_LIB_SETUP_H
2 #define HEADER_CURL_LIB_SETUP_H
3 /***************************************************************************
4  *                                  _   _ ____  _
5  *  Project                     ___| | | |  _ \| |
6  *                             / __| | | | |_) | |
7  *                            | (__| |_| |  _ <| |___
8  *                             \___|\___/|_| \_\_____|
9  *
10  * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
11  *
12  * This software is licensed as described in the file COPYING, which
13  * you should have received as part of this distribution. The terms
14  * are also available at http://curl.haxx.se/docs/copyright.html.
15  *
16  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17  * copies of the Software, and permit persons to whom the Software is
18  * furnished to do so, under the terms of the COPYING file.
19  *
20  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21  * KIND, either express or implied.
22  *
23  ***************************************************************************/
24 
25 /*
26  * Define WIN32 when build target is Win32 API
27  */
28 
29 #if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) && !defined(__SYMBIAN32__)
30 #define WIN32
31 #endif
32 
33 /*
34  * Include configuration script results or hand-crafted
35  * configuration file for platforms which lack config tool.
36  */
37 
38 #ifdef HAVE_CONFIG_H
39 
40 #include "curl_config.h"
41 
42 #else /* HAVE_CONFIG_H */
43 
44 #ifdef _WIN32_WCE
45 #  include "config-win32ce.h"
46 #else
47 #  ifdef WIN32
48 #    include "config-win32.h"
49 #  endif
50 #endif
51 
52 #if defined(macintosh) && defined(__MRC__)
53 #  include "config-mac.h"
54 #endif
55 
56 #ifdef __AMIGA__
57 #  include "amigaos.h"
58 #endif
59 
60 #ifdef __SYMBIAN32__
61 #  include "config-symbian.h"
62 #endif
63 
64 #ifdef __OS400__
65 #  include "config-os400.h"
66 #endif
67 
68 #ifdef TPF
69 #  include "config-tpf.h"
70 #endif
71 
72 #ifdef __VXWORKS__
73 #  include "config-vxworks.h"
74 #endif
75 
76 #endif /* HAVE_CONFIG_H */
77 
78 /* ================================================================ */
79 /* Definition of preprocessor macros/symbols which modify compiler  */
80 /* behavior or generated code characteristics must be done here,   */
81 /* as appropriate, before any system header file is included. It is */
82 /* also possible to have them defined in the config file included   */
83 /* before this point. As a result of all this we frown inclusion of */
84 /* system header files in our config files, avoid this at any cost. */
85 /* ================================================================ */
86 
87 /*
88  * AIX 4.3 and newer needs _THREAD_SAFE defined to build
89  * proper reentrant code. Others may also need it.
90  */
91 
92 #ifdef NEED_THREAD_SAFE
93 #  ifndef _THREAD_SAFE
94 #    define _THREAD_SAFE
95 #  endif
96 #endif
97 
98 /*
99  * Tru64 needs _REENTRANT set for a few function prototypes and
100  * things to appear in the system header files. Unixware needs it
101  * to build proper reentrant code. Others may also need it.
102  */
103 
104 #ifdef NEED_REENTRANT
105 #  ifndef _REENTRANT
106 #    define _REENTRANT
107 #  endif
108 #endif
109 
110 /* ================================================================ */
111 /*  If you need to include a system header file for your platform,  */
112 /*  please, do it beyond the point further indicated in this file.  */
113 /* ================================================================ */
114 
115 /*
116  * libcurl's external interface definitions are also used internally,
117  * and might also include required system header files to define them.
118  */
119 
120 #include <curl/curlbuild.h>
121 
122 /*
123  * Compile time sanity checks must also be done when building the library.
124  */
125 
126 #include <curl/curlrules.h>
127 
128 /*
129  * Ensure that no one is using the old SIZEOF_CURL_OFF_T macro
130  */
131 
132 #ifdef SIZEOF_CURL_OFF_T
133 #  error "SIZEOF_CURL_OFF_T shall not be defined!"
134    Error Compilation_aborted_SIZEOF_CURL_OFF_T_shall_not_be_defined
135 #endif
136 
137 /*
138  * Set up internal curl_off_t formatting string directives for
139  * exclusive use with libcurl's internal *printf functions.
140  */
141 
142 #ifdef FORMAT_OFF_T
143 #  error "FORMAT_OFF_T shall not be defined before this point!"
144    Error Compilation_aborted_FORMAT_OFF_T_already_defined
145 #endif
146 
147 #ifdef FORMAT_OFF_TU
148 #  error "FORMAT_OFF_TU shall not be defined before this point!"
149    Error Compilation_aborted_FORMAT_OFF_TU_already_defined
150 #endif
151 
152 #if (CURL_SIZEOF_CURL_OFF_T > CURL_SIZEOF_LONG)
153 #  define FORMAT_OFF_T  "lld"
154 #  define FORMAT_OFF_TU "llu"
155 #else
156 #  define FORMAT_OFF_T  "ld"
157 #  define FORMAT_OFF_TU "lu"
158 #endif
159 
160 /*
161  * Disable other protocols when http is the only one desired.
162  */
163 
164 #ifdef HTTP_ONLY
165 #  ifndef CURL_DISABLE_TFTP
166 #    define CURL_DISABLE_TFTP
167 #  endif
168 #  ifndef CURL_DISABLE_FTP
169 #    define CURL_DISABLE_FTP
170 #  endif
171 #  ifndef CURL_DISABLE_LDAP
172 #    define CURL_DISABLE_LDAP
173 #  endif
174 #  ifndef CURL_DISABLE_TELNET
175 #    define CURL_DISABLE_TELNET
176 #  endif
177 #  ifndef CURL_DISABLE_DICT
178 #    define CURL_DISABLE_DICT
179 #  endif
180 #  ifndef CURL_DISABLE_FILE
181 #    define CURL_DISABLE_FILE
182 #  endif
183 #  ifndef CURL_DISABLE_RTSP
184 #    define CURL_DISABLE_RTSP
185 #  endif
186 #endif
187 
188 /*
189  * When http is disabled rtsp is not supported.
190  */
191 
192 #if defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_RTSP)
193 #  define CURL_DISABLE_RTSP
194 #endif
195 
196 /* ================================================================ */
197 /* No system header file shall be included in this file before this */
198 /* point. The only allowed ones are those included from curlbuild.h */
199 /* ================================================================ */
200 
201 /*
202  * OS/400 setup file includes some system headers.
203  */
204 
205 #ifdef __OS400__
206 #  include "setup-os400.h"
207 #endif
208 
209 /*
210  * Include header files for windows builds before redefining anything.
211  * Use this preprocessor block only to include or exclude windows.h,
212  * winsock2.h, ws2tcpip.h or winsock.h. Any other windows thing belongs
213  * to any other further and independent block.  Under Cygwin things work
214  * just as under linux (e.g. <sys/socket.h>) and the winsock headers should
215  * never be included when __CYGWIN__ is defined.  configure script takes
216  * care of this, not defining HAVE_WINDOWS_H, HAVE_WINSOCK_H, HAVE_WINSOCK2_H,
217  * neither HAVE_WS2TCPIP_H when __CYGWIN__ is defined.
218  */
219 
220 #ifdef HAVE_WINDOWS_H
221 #  ifndef WIN32_LEAN_AND_MEAN
222 #    define WIN32_LEAN_AND_MEAN
223 #  endif
224 #  include <windows.h>
225 #  ifdef HAVE_WINSOCK2_H
226 #    include <winsock2.h>
227 #    ifdef HAVE_WS2TCPIP_H
228 #       include <ws2tcpip.h>
229 #    endif
230 #  else
231 #    ifdef HAVE_WINSOCK_H
232 #      include <winsock.h>
233 #    endif
234 #  endif
235 #endif
236 
237 /*
238  * Define USE_WINSOCK to 2 if we have and use WINSOCK2 API, else
239  * define USE_WINSOCK to 1 if we have and use WINSOCK  API, else
240  * undefine USE_WINSOCK.
241  */
242 
243 #undef USE_WINSOCK
244 
245 #ifdef HAVE_WINSOCK2_H
246 #  define USE_WINSOCK 2
247 #else
248 #  ifdef HAVE_WINSOCK_H
249 #    define USE_WINSOCK 1
250 #  endif
251 #endif
252 
253 #ifdef HAVE_EXTRA_STRICMP_H
254 #  include <extra/stricmp.h>
255 #endif
256 
257 #ifdef HAVE_EXTRA_STRDUP_H
258 #  include <extra/strdup.h>
259 #endif
260 
261 #ifdef TPF
262 #  include <strings.h>    /* for bzero, strcasecmp, and strncasecmp */
263 #  include <string.h>     /* for strcpy and strlen */
264 #  include <stdlib.h>     /* for rand and srand */
265 #  include <sys/socket.h> /* for select and ioctl*/
266 #  include <netdb.h>      /* for in_addr_t definition */
267 #  include <tpf/sysapi.h> /* for tpf_process_signals */
268    /* change which select is used for libcurl */
269 #  define select(a,b,c,d,e) tpf_select_libcurl(a,b,c,d,e)
270 #endif
271 
272 #ifdef __VXWORKS__
273 #  include <sockLib.h>    /* for generic BSD socket functions */
274 #  include <ioLib.h>      /* for basic I/O interface functions */
275 #endif
276 
277 #include <stdio.h>
278 #ifdef HAVE_ASSERT_H
279 #include <assert.h>
280 #endif
281 #include <errno.h>
282 
283 #ifdef __TANDEM /* for nsr-tandem-nsk systems */
284 #include <floss.h>
285 #endif
286 
287 #ifndef STDC_HEADERS /* no standard C headers! */
288 #include <curl/stdcheaders.h>
289 #endif
290 
291 #ifdef __POCC__
292 #  include <sys/types.h>
293 #  include <unistd.h>
294 #  define sys_nerr EILSEQ
295 #endif
296 
297 /*
298  * Salford-C kludge section (mostly borrowed from wxWidgets).
299  */
300 #ifdef __SALFORDC__
301   #pragma suppress 353             /* Possible nested comments */
302   #pragma suppress 593             /* Define not used */
303   #pragma suppress 61              /* enum has no name */
304   #pragma suppress 106             /* unnamed, unused parameter */
305   #include <clib.h>
306 #endif
307 
308 /*
309  * Large file (>2Gb) support using WIN32 functions.
310  */
311 
312 #ifdef USE_WIN32_LARGE_FILES
313 #  include <io.h>
314 #  include <sys/types.h>
315 #  include <sys/stat.h>
316 #  define lseek(fdes,offset,whence)  _lseeki64(fdes, offset, whence)
317 #  define fstat(fdes,stp)            _fstati64(fdes, stp)
318 #  define stat(fname,stp)            _stati64(fname, stp)
319 #  define struct_stat                struct _stati64
320 #  define LSEEK_ERROR                (__int64)-1
321 #endif
322 
323 /*
324  * Small file (<2Gb) support using WIN32 functions.
325  */
326 
327 #ifdef USE_WIN32_SMALL_FILES
328 #  include <io.h>
329 #  include <sys/types.h>
330 #  include <sys/stat.h>
331 #  define lseek(fdes,offset,whence)  _lseek(fdes, (long)offset, whence)
332 #  define fstat(fdes,stp)            _fstat(fdes, stp)
333 #  define stat(fname,stp)            _stat(fname, stp)
334 #  define struct_stat                struct _stat
335 #  define LSEEK_ERROR                (long)-1
336 #endif
337 
338 #ifndef struct_stat
339 #  define struct_stat struct stat
340 #endif
341 
342 #ifndef LSEEK_ERROR
343 #  define LSEEK_ERROR (off_t)-1
344 #endif
345 
346 /*
347  * Default sizeof(off_t) in case it hasn't been defined in config file.
348  */
349 
350 #ifndef SIZEOF_OFF_T
351 #  if defined(__VMS) && !defined(__VAX)
352 #    if defined(_LARGEFILE)
353 #      define SIZEOF_OFF_T 8
354 #    endif
355 #  elif defined(__OS400__) && defined(__ILEC400__)
356 #    if defined(_LARGE_FILES)
357 #      define SIZEOF_OFF_T 8
358 #    endif
359 #  elif defined(__MVS__) && defined(__IBMC__)
360 #    if defined(_LP64) || defined(_LARGE_FILES)
361 #      define SIZEOF_OFF_T 8
362 #    endif
363 #  elif defined(__370__) && defined(__IBMC__)
364 #    if defined(_LP64) || defined(_LARGE_FILES)
365 #      define SIZEOF_OFF_T 8
366 #    endif
367 #  endif
368 #  ifndef SIZEOF_OFF_T
369 #    define SIZEOF_OFF_T 4
370 #  endif
371 #endif
372 
373 /*
374  * Arg 2 type for gethostname in case it hasn't been defined in config file.
375  */
376 
377 #ifndef GETHOSTNAME_TYPE_ARG2
378 #  ifdef USE_WINSOCK
379 #    define GETHOSTNAME_TYPE_ARG2 int
380 #  else
381 #    define GETHOSTNAME_TYPE_ARG2 size_t
382 #  endif
383 #endif
384 
385 /* Below we define some functions. They should
386 
387    4. set the SIGALRM signal timeout
388    5. set dir/file naming defines
389    */
390 
391 #ifdef WIN32
392 
393 #  define DIR_CHAR      "\\"
394 #  define DOT_CHAR      "_"
395 
396 #else /* WIN32 */
397 
398 #  ifdef MSDOS  /* Watt-32 */
399 
400 #    include <sys/ioctl.h>
401 #    define select(n,r,w,x,t) select_s(n,r,w,x,t)
402 #    define ioctl(x,y,z) ioctlsocket(x,y,(char *)(z))
403 #    include <tcp.h>
404 #    ifdef word
405 #      undef word
406 #    endif
407 #    ifdef byte
408 #      undef byte
409 #    endif
410 
411 #  endif /* MSDOS */
412 
413 #  ifdef __minix
414      /* Minix 3 versions up to at least 3.1.3 are missing these prototypes */
415      extern char * strtok_r(char *s, const char *delim, char **last);
416      extern struct tm * gmtime_r(const time_t * const timep, struct tm *tmp);
417 #  endif
418 
419 #  define DIR_CHAR      "/"
420 #  ifndef DOT_CHAR
421 #    define DOT_CHAR      "."
422 #  endif
423 
424 #  ifdef MSDOS
425 #    undef DOT_CHAR
426 #    define DOT_CHAR      "_"
427 #  endif
428 
429 #  ifndef fileno /* sunos 4 have this as a macro! */
430      int fileno( FILE *stream);
431 #  endif
432 
433 #endif /* WIN32 */
434 
435 /*
436  * msvc 6.0 requires PSDK in order to have INET6_ADDRSTRLEN
437  * defined in ws2tcpip.h as well as to provide IPv6 support.
438  */
439 
440 #if defined(_MSC_VER) && !defined(__POCC__)
441 #  if !defined(HAVE_WS2TCPIP_H) || \
442      ((_MSC_VER < 1300) && !defined(INET6_ADDRSTRLEN))
443 #    undef HAVE_GETADDRINFO_THREADSAFE
444 #    undef HAVE_FREEADDRINFO
445 #    undef HAVE_GETADDRINFO
446 #    undef HAVE_GETNAMEINFO
447 #    undef ENABLE_IPV6
448 #  endif
449 #endif
450 
451 /* ---------------------------------------------------------------- */
452 /*             resolver specialty compile-time defines              */
453 /*         CURLRES_* defines to use in the host*.c sources          */
454 /* ---------------------------------------------------------------- */
455 
456 /*
457  * lcc-win32 doesn't have _beginthreadex(), lacks threads support.
458  */
459 
460 #if defined(__LCC__) && defined(WIN32)
461 #  undef USE_THREADS_POSIX
462 #  undef USE_THREADS_WIN32
463 #endif
464 
465 /*
466  * MSVC threads support requires a multi-threaded runtime library.
467  * _beginthreadex() is not available in single-threaded ones.
468  */
469 
470 #if defined(_MSC_VER) && !defined(__POCC__) && !defined(_MT)
471 #  undef USE_THREADS_POSIX
472 #  undef USE_THREADS_WIN32
473 #endif
474 
475 /*
476  * Mutually exclusive CURLRES_* definitions.
477  */
478 
479 #ifdef USE_ARES
480 #  define CURLRES_ASYNCH
481 #  define CURLRES_ARES
482 #elif defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
483 #  define CURLRES_ASYNCH
484 #  define CURLRES_THREADED
485 #else
486 #  define CURLRES_SYNCH
487 #endif
488 
489 #ifdef ENABLE_IPV6
490 #  define CURLRES_IPV6
491 #else
492 #  define CURLRES_IPV4
493 #endif
494 
495 /* ---------------------------------------------------------------- */
496 
497 /*
498  * When using WINSOCK, TELNET protocol requires WINSOCK2 API.
499  */
500 
501 #if defined(USE_WINSOCK) && (USE_WINSOCK != 2)
502 #  define CURL_DISABLE_TELNET 1
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 
511 #if defined(_MSC_VER) && !defined(__POCC__)
512 #  if !defined(HAVE_WINSOCK2_H) || ((_MSC_VER < 1300) && !defined(IPPROTO_ESP))
513 #    undef HAVE_STRUCT_SOCKADDR_STORAGE
514 #  endif
515 #endif
516 
517 /*
518  * Intentionally fail to build when using msvc 6.0 without PSDK installed.
519  * The brave of heart can circumvent this, defining ALLOW_MSVC6_WITHOUT_PSDK
520  * in lib/config-win32.h although absolutely discouraged and unsupported.
521  */
522 
523 #if defined(_MSC_VER) && !defined(__POCC__)
524 #  if !defined(HAVE_WINDOWS_H) || ((_MSC_VER < 1300) && !defined(_FILETIME_))
525 #    if !defined(ALLOW_MSVC6_WITHOUT_PSDK)
526 #      error MSVC 6.0 requires "February 2003 Platform SDK" a.k.a. "Windows Server 2003 PSDK"
527 #    else
528 #      define CURL_DISABLE_LDAP 1
529 #    endif
530 #  endif
531 #endif
532 
533 #ifdef NETWARE
534 int netware_init(void);
535 #ifndef __NOVELL_LIBC__
536 #include <sys/bsdskt.h>
537 #include <sys/timeval.h>
538 #endif
539 #endif
540 
541 #if defined(HAVE_LIBIDN) && defined(HAVE_TLD_H)
542 /* The lib was present and the tld.h header (which is missing in libidn 0.3.X
543    but we only work with libidn 0.4.1 or later) */
544 #define USE_LIBIDN
545 #endif
546 
547 #ifndef SIZEOF_TIME_T
548 /* assume default size of time_t to be 32 bit */
549 #define SIZEOF_TIME_T 4
550 #endif
551 
552 #define LIBIDN_REQUIRED_VERSION "0.4.1"
553 
554 #if defined(USE_GNUTLS) || defined(USE_SSLEAY) || defined(USE_NSS) || defined(USE_QSOSSL) || defined(USE_POLARSSL) || defined(USE_AXTLS) || defined(USE_CYASSL)
555 #define USE_SSL    /* SSL support has been enabled */
556 #endif
557 
558 #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
559 #define USE_HTTP_NEGOTIATE
560 #endif
561 
562 #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_NTLM)
563 #if defined(USE_SSLEAY) || defined(USE_WINDOWS_SSPI) || defined(USE_GNUTLS) || defined(USE_NSS)
564 #define USE_NTLM
565 #endif
566 #endif
567 
568 /* non-configure builds may define CURL_WANTS_CA_BUNDLE_ENV */
569 #if defined(CURL_WANTS_CA_BUNDLE_ENV) && !defined(CURL_CA_BUNDLE)
570 #define CURL_CA_BUNDLE getenv("CURL_CA_BUNDLE")
571 #endif
572 
573 /* Define S_ISREG if not defined by system headers, f.e. MSVC */
574 #if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
575 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
576 #endif
577 
578 /*
579  * Include macros and defines that should only be processed once.
580  */
581 
582 #ifndef __SETUP_ONCE_H
583 #include "setup_once.h"
584 #endif
585 
586 #endif /* HEADER_CURL_LIB_SETUP_H */
587