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