1#ifndef HEADER_CURL_SETUP_H
2#define HEADER_CURL_SETUP_H
3/***************************************************************************
4 *                                  _   _ ____  _
5 *  Project                     ___| | | |  _ \| |
6 *                             / __| | | | |_) | |
7 *                            | (__| |_| |  _ <| |___
8 *                             \___|\___/|_| \_\_____|
9 *
10 * Copyright (C) 1998 - 2013, 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) && \
30    !defined(__SYMBIAN32__)
31#define WIN32
32#endif
33
34/*
35 * Include configuration script results or hand-crafted
36 * configuration file for platforms which lack config tool.
37 */
38
39#ifdef HAVE_CONFIG_H
40
41#include "curl_config.h"
42
43#else /* HAVE_CONFIG_H */
44
45#ifdef _WIN32_WCE
46#  include "config-win32ce.h"
47#else
48#  ifdef WIN32
49#    include "config-win32.h"
50#  endif
51#endif
52
53#if defined(macintosh) && defined(__MRC__)
54#  include "config-mac.h"
55#endif
56
57#ifdef __riscos__
58#  include "config-riscos.h"
59#endif
60
61#ifdef __AMIGA__
62#  include "config-amigaos.h"
63#endif
64
65#ifdef __SYMBIAN32__
66#  include "config-symbian.h"
67#endif
68
69#ifdef __OS400__
70#  include "config-os400.h"
71#endif
72
73#ifdef TPF
74#  include "config-tpf.h"
75#endif
76
77#ifdef __VXWORKS__
78#  include "config-vxworks.h"
79#endif
80
81#endif /* HAVE_CONFIG_H */
82
83/* ================================================================ */
84/* Definition of preprocessor macros/symbols which modify compiler  */
85/* behavior or generated code characteristics must be done here,   */
86/* as appropriate, before any system header file is included. It is */
87/* also possible to have them defined in the config file included   */
88/* before this point. As a result of all this we frown inclusion of */
89/* system header files in our config files, avoid this at any cost. */
90/* ================================================================ */
91
92/*
93 * AIX 4.3 and newer needs _THREAD_SAFE defined to build
94 * proper reentrant code. Others may also need it.
95 */
96
97#ifdef NEED_THREAD_SAFE
98#  ifndef _THREAD_SAFE
99#    define _THREAD_SAFE
100#  endif
101#endif
102
103/*
104 * Tru64 needs _REENTRANT set for a few function prototypes and
105 * things to appear in the system header files. Unixware needs it
106 * to build proper reentrant code. Others may also need it.
107 */
108
109#ifdef NEED_REENTRANT
110#  ifndef _REENTRANT
111#    define _REENTRANT
112#  endif
113#endif
114
115/* ================================================================ */
116/*  If you need to include a system header file for your platform,  */
117/*  please, do it beyond the point further indicated in this file.  */
118/* ================================================================ */
119
120/*
121 * libcurl's external interface definitions are also used internally,
122 * and might also include required system header files to define them.
123 */
124
125#include <curl/curlbuild.h>
126
127/*
128 * Compile time sanity checks must also be done when building the library.
129 */
130
131#include <curl/curlrules.h>
132
133/*
134 * Ensure that no one is using the old SIZEOF_CURL_OFF_T macro
135 */
136
137#ifdef SIZEOF_CURL_OFF_T
138#  error "SIZEOF_CURL_OFF_T shall not be defined!"
139   Error Compilation_aborted_SIZEOF_CURL_OFF_T_shall_not_be_defined
140#endif
141
142/*
143 * Disable other protocols when http is the only one desired.
144 */
145
146#ifdef HTTP_ONLY
147#  ifndef CURL_DISABLE_TFTP
148#    define CURL_DISABLE_TFTP
149#  endif
150#  ifndef CURL_DISABLE_FTP
151#    define CURL_DISABLE_FTP
152#  endif
153#  ifndef CURL_DISABLE_LDAP
154#    define CURL_DISABLE_LDAP
155#  endif
156#  ifndef CURL_DISABLE_TELNET
157#    define CURL_DISABLE_TELNET
158#  endif
159#  ifndef CURL_DISABLE_DICT
160#    define CURL_DISABLE_DICT
161#  endif
162#  ifndef CURL_DISABLE_FILE
163#    define CURL_DISABLE_FILE
164#  endif
165#  ifndef CURL_DISABLE_RTSP
166#    define CURL_DISABLE_RTSP
167#  endif
168#  ifndef CURL_DISABLE_POP3
169#    define CURL_DISABLE_POP3
170#  endif
171#  ifndef CURL_DISABLE_IMAP
172#    define CURL_DISABLE_IMAP
173#  endif
174#  ifndef CURL_DISABLE_SMTP
175#    define CURL_DISABLE_SMTP
176#  endif
177#  ifndef CURL_DISABLE_RTSP
178#    define CURL_DISABLE_RTSP
179#  endif
180#  ifndef CURL_DISABLE_RTMP
181#    define CURL_DISABLE_RTMP
182#  endif
183#  ifndef CURL_DISABLE_GOPHER
184#    define CURL_DISABLE_GOPHER
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 * VMS setup file includes some system headers.
211 */
212
213#ifdef __VMS
214#  include "setup-vms.h"
215#endif
216
217/*
218 * Include header files for windows builds before redefining anything.
219 * Use this preprocessor block only to include or exclude windows.h,
220 * winsock2.h, ws2tcpip.h or winsock.h. Any other windows thing belongs
221 * to any other further and independent block.  Under Cygwin things work
222 * just as under linux (e.g. <sys/socket.h>) and the winsock headers should
223 * never be included when __CYGWIN__ is defined.  configure script takes
224 * care of this, not defining HAVE_WINDOWS_H, HAVE_WINSOCK_H, HAVE_WINSOCK2_H,
225 * neither HAVE_WS2TCPIP_H when __CYGWIN__ is defined.
226 */
227
228#ifdef HAVE_WINDOWS_H
229#  if defined(UNICODE) && !defined(_UNICODE)
230#    define _UNICODE
231#  endif
232#  if defined(_UNICODE) && !defined(UNICODE)
233#    define UNICODE
234#  endif
235#  ifndef WIN32_LEAN_AND_MEAN
236#    define WIN32_LEAN_AND_MEAN
237#  endif
238#  include <windows.h>
239#  ifdef HAVE_WINSOCK2_H
240#    include <winsock2.h>
241#    ifdef HAVE_WS2TCPIP_H
242#       include <ws2tcpip.h>
243#    endif
244#  else
245#    ifdef HAVE_WINSOCK_H
246#      include <winsock.h>
247#    endif
248#  endif
249#  include <tchar.h>
250#  ifdef UNICODE
251     typedef wchar_t *(*curl_wcsdup_callback)(const wchar_t *str);
252#  endif
253#endif
254
255/*
256 * Define USE_WINSOCK to 2 if we have and use WINSOCK2 API, else
257 * define USE_WINSOCK to 1 if we have and use WINSOCK  API, else
258 * undefine USE_WINSOCK.
259 */
260
261#undef USE_WINSOCK
262
263#ifdef HAVE_WINSOCK2_H
264#  define USE_WINSOCK 2
265#else
266#  ifdef HAVE_WINSOCK_H
267#    define USE_WINSOCK 1
268#  endif
269#endif
270
271#ifdef USE_LWIPSOCK
272#  include <lwip/init.h>
273#  include <lwip/sockets.h>
274#  include <lwip/netdb.h>
275#endif
276
277#ifdef HAVE_EXTRA_STRICMP_H
278#  include <extra/stricmp.h>
279#endif
280
281#ifdef HAVE_EXTRA_STRDUP_H
282#  include <extra/strdup.h>
283#endif
284
285#ifdef TPF
286#  include <strings.h>    /* for bzero, strcasecmp, and strncasecmp */
287#  include <string.h>     /* for strcpy and strlen */
288#  include <stdlib.h>     /* for rand and srand */
289#  include <sys/socket.h> /* for select and ioctl*/
290#  include <netdb.h>      /* for in_addr_t definition */
291#  include <tpf/sysapi.h> /* for tpf_process_signals */
292   /* change which select is used for libcurl */
293#  define select(a,b,c,d,e) tpf_select_libcurl(a,b,c,d,e)
294#endif
295
296#ifdef __VXWORKS__
297#  include <sockLib.h>    /* for generic BSD socket functions */
298#  include <ioLib.h>      /* for basic I/O interface functions */
299#endif
300
301#ifdef __AMIGA__
302#  ifndef __ixemul__
303#    include <exec/types.h>
304#    include <exec/execbase.h>
305#    include <proto/exec.h>
306#    include <proto/dos.h>
307#    define select(a,b,c,d,e) WaitSelect(a,b,c,d,e,0)
308#  endif
309#endif
310
311#include <stdio.h>
312#ifdef HAVE_ASSERT_H
313#include <assert.h>
314#endif
315
316#ifdef __TANDEM /* for nsr-tandem-nsk systems */
317#include <floss.h>
318#endif
319
320#ifndef STDC_HEADERS /* no standard C headers! */
321#include <curl/stdcheaders.h>
322#endif
323
324#ifdef __POCC__
325#  include <sys/types.h>
326#  include <unistd.h>
327#  define sys_nerr EILSEQ
328#endif
329
330/*
331 * Salford-C kludge section (mostly borrowed from wxWidgets).
332 */
333#ifdef __SALFORDC__
334  #pragma suppress 353             /* Possible nested comments */
335  #pragma suppress 593             /* Define not used */
336  #pragma suppress 61              /* enum has no name */
337  #pragma suppress 106             /* unnamed, unused parameter */
338  #include <clib.h>
339#endif
340
341/*
342 * Large file (>2Gb) support using WIN32 functions.
343 */
344
345#ifdef USE_WIN32_LARGE_FILES
346#  include <io.h>
347#  include <sys/types.h>
348#  include <sys/stat.h>
349#  undef  lseek
350#  define lseek(fdes,offset,whence)  _lseeki64(fdes, offset, whence)
351#  undef  fstat
352#  define fstat(fdes,stp)            _fstati64(fdes, stp)
353#  undef  stat
354#  define stat(fname,stp)            _stati64(fname, stp)
355#  define struct_stat                struct _stati64
356#  define LSEEK_ERROR                (__int64)-1
357#endif
358
359/*
360 * Small file (<2Gb) support using WIN32 functions.
361 */
362
363#ifdef USE_WIN32_SMALL_FILES
364#  include <io.h>
365#  include <sys/types.h>
366#  include <sys/stat.h>
367#  ifndef _WIN32_WCE
368#    undef  lseek
369#    define lseek(fdes,offset,whence)  _lseek(fdes, (long)offset, whence)
370#    define fstat(fdes,stp)            _fstat(fdes, stp)
371#    define stat(fname,stp)            _stat(fname, stp)
372#    define struct_stat                struct _stat
373#  endif
374#  define LSEEK_ERROR                (long)-1
375#endif
376
377#ifndef struct_stat
378#  define struct_stat struct stat
379#endif
380
381#ifndef LSEEK_ERROR
382#  define LSEEK_ERROR (off_t)-1
383#endif
384
385/*
386 * Default sizeof(off_t) in case it hasn't been defined in config file.
387 */
388
389#ifndef SIZEOF_OFF_T
390#  if defined(__VMS) && !defined(__VAX)
391#    if defined(_LARGEFILE)
392#      define SIZEOF_OFF_T 8
393#    endif
394#  elif defined(__OS400__) && defined(__ILEC400__)
395#    if defined(_LARGE_FILES)
396#      define SIZEOF_OFF_T 8
397#    endif
398#  elif defined(__MVS__) && defined(__IBMC__)
399#    if defined(_LP64) || defined(_LARGE_FILES)
400#      define SIZEOF_OFF_T 8
401#    endif
402#  elif defined(__370__) && defined(__IBMC__)
403#    if defined(_LP64) || defined(_LARGE_FILES)
404#      define SIZEOF_OFF_T 8
405#    endif
406#  endif
407#  ifndef SIZEOF_OFF_T
408#    define SIZEOF_OFF_T 4
409#  endif
410#endif
411
412/*
413 * Arg 2 type for gethostname in case it hasn't been defined in config file.
414 */
415
416#ifndef GETHOSTNAME_TYPE_ARG2
417#  ifdef USE_WINSOCK
418#    define GETHOSTNAME_TYPE_ARG2 int
419#  else
420#    define GETHOSTNAME_TYPE_ARG2 size_t
421#  endif
422#endif
423
424/* Below we define some functions. They should
425
426   4. set the SIGALRM signal timeout
427   5. set dir/file naming defines
428   */
429
430#ifdef WIN32
431
432#  define DIR_CHAR      "\\"
433#  define DOT_CHAR      "_"
434
435#else /* WIN32 */
436
437#  ifdef MSDOS  /* Watt-32 */
438
439#    include <sys/ioctl.h>
440#    define select(n,r,w,x,t) select_s(n,r,w,x,t)
441#    define ioctl(x,y,z) ioctlsocket(x,y,(char *)(z))
442#    include <tcp.h>
443#    ifdef word
444#      undef word
445#    endif
446#    ifdef byte
447#      undef byte
448#    endif
449
450#  endif /* MSDOS */
451
452#  ifdef __minix
453     /* Minix 3 versions up to at least 3.1.3 are missing these prototypes */
454     extern char * strtok_r(char *s, const char *delim, char **last);
455     extern struct tm * gmtime_r(const time_t * const timep, struct tm *tmp);
456#  endif
457
458#  define DIR_CHAR      "/"
459#  ifndef DOT_CHAR
460#    define DOT_CHAR      "."
461#  endif
462
463#  ifdef MSDOS
464#    undef DOT_CHAR
465#    define DOT_CHAR      "_"
466#  endif
467
468#  ifndef fileno /* sunos 4 have this as a macro! */
469     int fileno( FILE *stream);
470#  endif
471
472#endif /* WIN32 */
473
474/*
475 * msvc 6.0 requires PSDK in order to have INET6_ADDRSTRLEN
476 * defined in ws2tcpip.h as well as to provide IPv6 support.
477 */
478
479#if defined(_MSC_VER) && !defined(__POCC__)
480#  if !defined(HAVE_WS2TCPIP_H) || \
481     ((_MSC_VER < 1300) && !defined(INET6_ADDRSTRLEN))
482#    undef HAVE_GETADDRINFO_THREADSAFE
483#    undef HAVE_FREEADDRINFO
484#    undef HAVE_GETADDRINFO
485#    undef HAVE_GETNAMEINFO
486#    undef ENABLE_IPV6
487#  endif
488#endif
489
490/* ---------------------------------------------------------------- */
491/*             resolver specialty compile-time defines              */
492/*         CURLRES_* defines to use in the host*.c sources          */
493/* ---------------------------------------------------------------- */
494
495/*
496 * lcc-win32 doesn't have _beginthreadex(), lacks threads support.
497 */
498
499#if defined(__LCC__) && defined(WIN32)
500#  undef USE_THREADS_POSIX
501#  undef USE_THREADS_WIN32
502#endif
503
504/*
505 * MSVC threads support requires a multi-threaded runtime library.
506 * _beginthreadex() is not available in single-threaded ones.
507 */
508
509#if defined(_MSC_VER) && !defined(__POCC__) && !defined(_MT)
510#  undef USE_THREADS_POSIX
511#  undef USE_THREADS_WIN32
512#endif
513
514/*
515 * Mutually exclusive CURLRES_* definitions.
516 */
517
518#ifdef USE_ARES
519#  define CURLRES_ASYNCH
520#  define CURLRES_ARES
521/* now undef the stock libc functions just to avoid them being used */
522#  undef HAVE_GETADDRINFO
523#  undef HAVE_GETHOSTBYNAME
524#elif defined(USE_THREADS_POSIX) || defined(USE_THREADS_WIN32)
525#  define CURLRES_ASYNCH
526#  define CURLRES_THREADED
527#else
528#  define CURLRES_SYNCH
529#endif
530
531#ifdef ENABLE_IPV6
532#  define CURLRES_IPV6
533#else
534#  define CURLRES_IPV4
535#endif
536
537/* ---------------------------------------------------------------- */
538
539/*
540 * When using WINSOCK, TELNET protocol requires WINSOCK2 API.
541 */
542
543#if defined(USE_WINSOCK) && (USE_WINSOCK != 2)
544#  define CURL_DISABLE_TELNET 1
545#endif
546
547/*
548 * msvc 6.0 does not have struct sockaddr_storage and
549 * does not define IPPROTO_ESP in winsock2.h. But both
550 * are available if PSDK is properly installed.
551 */
552
553#if defined(_MSC_VER) && !defined(__POCC__)
554#  if !defined(HAVE_WINSOCK2_H) || ((_MSC_VER < 1300) && !defined(IPPROTO_ESP))
555#    undef HAVE_STRUCT_SOCKADDR_STORAGE
556#  endif
557#endif
558
559/*
560 * Intentionally fail to build when using msvc 6.0 without PSDK installed.
561 * The brave of heart can circumvent this, defining ALLOW_MSVC6_WITHOUT_PSDK
562 * in lib/config-win32.h although absolutely discouraged and unsupported.
563 */
564
565#if defined(_MSC_VER) && !defined(__POCC__)
566#  if !defined(HAVE_WINDOWS_H) || ((_MSC_VER < 1300) && !defined(_FILETIME_))
567#    if !defined(ALLOW_MSVC6_WITHOUT_PSDK)
568#      error MSVC 6.0 requires "February 2003 Platform SDK" a.k.a. \
569             "Windows Server 2003 PSDK"
570#    else
571#      define CURL_DISABLE_LDAP 1
572#    endif
573#  endif
574#endif
575
576#ifdef NETWARE
577int netware_init(void);
578#ifndef __NOVELL_LIBC__
579#include <sys/bsdskt.h>
580#include <sys/timeval.h>
581#endif
582#endif
583
584#if defined(HAVE_LIBIDN) && defined(HAVE_TLD_H)
585/* The lib was present and the tld.h header (which is missing in libidn 0.3.X
586   but we only work with libidn 0.4.1 or later) */
587#define USE_LIBIDN
588#endif
589
590#ifndef SIZEOF_TIME_T
591/* assume default size of time_t to be 32 bit */
592#define SIZEOF_TIME_T 4
593#endif
594
595#define LIBIDN_REQUIRED_VERSION "0.4.1"
596
597#if defined(USE_GNUTLS) || defined(USE_SSLEAY) || defined(USE_NSS) || \
598    defined(USE_QSOSSL) || defined(USE_POLARSSL) || defined(USE_AXTLS) || \
599    defined(USE_CYASSL) || defined(USE_SCHANNEL) || \
600    defined(USE_DARWINSSL) || defined(USE_GSKIT)
601#define USE_SSL    /* SSL support has been enabled */
602#endif
603
604#if !defined(CURL_DISABLE_CRYPTO_AUTH) && \
605    (defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI))
606#define USE_HTTP_NEGOTIATE
607#endif
608
609/* Single point where USE_NTLM definition might be done */
610#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_NTLM) && \
611    !defined(CURL_DISABLE_CRYPTO_AUTH)
612#if defined(USE_SSLEAY) || defined(USE_WINDOWS_SSPI) || \
613    defined(USE_GNUTLS) || defined(USE_NSS) || defined(USE_DARWINSSL)
614#define USE_NTLM
615#endif
616#endif
617
618/* non-configure builds may define CURL_WANTS_CA_BUNDLE_ENV */
619#if defined(CURL_WANTS_CA_BUNDLE_ENV) && !defined(CURL_CA_BUNDLE)
620#define CURL_CA_BUNDLE getenv("CURL_CA_BUNDLE")
621#endif
622
623/*
624 * Provide a mechanism to silence picky compilers, such as gcc 4.6+.
625 * Parameters should of course normally not be unused, but for example when
626 * we have multiple implementations of the same interface it may happen.
627 */
628
629#if defined(__GNUC__) && ((__GNUC__ >= 3) || \
630  ((__GNUC__ == 2) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ >= 7)))
631#  define UNUSED_PARAM __attribute__((__unused__))
632#else
633#  define UNUSED_PARAM /*NOTHING*/
634#endif
635
636/*
637 * Include macros and defines that should only be processed once.
638 */
639
640#ifndef HEADER_CURL_SETUP_ONCE_H
641#include "curl_setup_once.h"
642#endif
643
644/*
645 * Definition of our NOP statement Object-like macro
646 */
647
648#ifndef Curl_nop_stmt
649#  define Curl_nop_stmt do { } WHILE_FALSE
650#endif
651
652/*
653 * Ensure that Winsock and lwIP TCP/IP stacks are not mixed.
654 */
655
656#if defined(__LWIP_OPT_H__)
657#  if defined(SOCKET) || \
658     defined(USE_WINSOCK) || \
659     defined(HAVE_WINSOCK_H) || \
660     defined(HAVE_WINSOCK2_H) || \
661     defined(HAVE_WS2TCPIP_H)
662#    error "Winsock and lwIP TCP/IP stack definitions shall not coexist!"
663#  endif
664#endif
665
666/*
667 * Portable symbolic names for Winsock shutdown() mode flags.
668 */
669
670#ifdef USE_WINSOCK
671#  define SHUT_RD   0x00
672#  define SHUT_WR   0x01
673#  define SHUT_RDWR 0x02
674#endif
675
676/* Define S_ISREG if not defined by system headers, f.e. MSVC */
677#if !defined(S_ISREG) && defined(S_IFMT) && defined(S_IFREG)
678#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
679#endif
680
681/* Define S_ISDIR if not defined by system headers, f.e. MSVC */
682#if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR)
683#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
684#endif
685
686#endif /* HEADER_CURL_SETUP_H */
687