Merge branch 'fleischer-dc17'
[polipo.git] / polipo.h
blobb0481b8efc331c61ebcb83552f7970d1b077c35a
1 /*
2 Copyright (c) 2003-2006 by Juliusz Chroboczek
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 THE SOFTWARE.
23 #ifndef _GNU_SOURCE
24 #define _GNU_SOURCE
25 #endif
27 #include <sys/param.h>
29 #ifdef __MINGW32_VERSION
30 #define MINGW
31 #endif
33 #include <limits.h>
34 #include <stdlib.h>
35 #include <stdarg.h>
36 #include <stdio.h>
37 #include <errno.h>
38 #include <string.h>
39 #include <assert.h>
40 #include <unistd.h>
41 #include <fcntl.h>
42 #include <time.h>
43 #include <sys/time.h>
44 #include <sys/stat.h>
45 #include <dirent.h>
46 #ifndef MINGW
47 #include <sys/mman.h>
48 #include <sys/socket.h>
49 #include <netinet/in.h>
50 #include <netinet/tcp.h>
51 #include <arpa/inet.h>
52 #include <netdb.h>
53 #include <sys/types.h>
54 #include <sys/uio.h>
55 #include <sys/poll.h>
56 #include <sys/wait.h>
57 #include <sys/ioctl.h>
58 #include <signal.h>
59 #endif
61 #ifndef MAP_ANONYMOUS
62 #define MAP_ANONYMOUS MAP_ANON
63 #endif
65 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
66 /* nothing */
67 #elif defined(__GNUC__)
68 #define inline __inline
69 #if (__GNUC__ >= 3)
70 #define restrict __restrict
71 #else
72 #define restrict /**/
73 #endif
74 #else
75 #define inline /**/
76 #define restrict /**/
77 #endif
79 #if defined(__GNUC__) && (__GNUC__ >= 3)
80 #define ATTRIBUTE(x) __attribute__(x)
81 #else
82 #define ATTRIBUTE(x) /**/
83 #endif
85 #if defined __GLIBC__
86 #define HAVE_TM_GMTOFF
87 #ifndef __UCLIBC__
88 #define HAVE_TIMEGM
89 #define HAVE_FTS
90 #define HAVE_FFSL
91 #define HAVE_FFSLL
92 #endif
93 #define HAVE_SETENV
94 #define HAVE_ASPRINTF
95 #if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)
96 #define HAVE_MEMRCHR
97 #endif
98 #endif
100 #if defined(__linux__) && (__GNU_LIBRARY__ == 1)
101 /* Linux libc 5 */
102 #define HAVE_TIMEGM
103 #define HAVE_SETENV
104 #endif
106 #ifdef BSD
107 #define HAVE_TM_GMTOFF
108 #define HAVE_FTS
109 #define HAVE_SETENV
110 #endif
112 #ifdef __CYGWIN__
113 #define HAVE_SETENV
114 #define HAVE_ASPRINTF
115 #endif
117 #ifndef O_BINARY
118 #define O_BINARY 0
119 #endif
121 #define HAVE_TZSET
123 #if _POSIX_VERSION >= 200112L
124 #define HAVE_SETENV
125 #endif
127 #ifndef NO_IPv6
129 #ifdef __GLIBC__
130 #if (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)
131 #define HAVE_IPv6
132 #endif
133 #endif
135 #ifdef __FreeBSD__
136 #define HAVE_ASPRINTF
137 #if __FreeBSD_version >= 400000
138 #define HAVE_IPv6
139 #define HAVE_TIMEGM
140 #endif
141 #if __FreeBSD_version >= 503001
142 #define HAVE_FFSL
143 #endif
144 #endif
146 #ifdef __NetBSD__
147 #if __NetBSD_Version__ >= 105000000
148 #define HAVE_IPv6
149 #endif
150 #if __NetBSD_Version__ >= 200000000
151 #define HAVE_TIMEGM
152 #define HAVE_ASPRINTF
153 #endif
154 #endif
156 #ifdef __OpenBSD__
157 #if OpenBSD >= 200311
158 #define HAVE_IPv6
159 #endif
160 #endif
162 #endif
164 #if defined(i386) || defined(__mc68020__) || defined(__x86_64__)
165 #define UNALIGNED_ACCESS
166 #endif
168 #ifndef MINGW
169 #define HAVE_FORK
170 #ifndef NO_SYSLOG
171 #define HAVE_SYSLOG
172 #endif
173 #define HAVE_READV_WRITEV
174 #define HAVE_FFS
175 #define READ(x, y, z) read(x, y, z)
176 #define WRITE(x, y, z) write(x, y, z)
177 #define CLOSE(x) close(x)
178 #else
179 #ifndef HAVE_REGEX
180 #define NO_FORBIDDEN
181 #endif
182 #endif
184 #ifdef HAVE_READV_WRITEV
185 #define WRITEV(x, y, z) writev(x, y, z)
186 #define READV(x, y, z) readv(x, y, z)
187 #endif
189 #ifndef HAVE_FORK
190 #define NO_REDIRECTOR
191 #endif
193 #include "mingw.h"
195 #include "ftsimport.h"
196 #include "atom.h"
197 #include "util.h"
198 #include "config.h"
199 #include "event.h"
200 #include "io.h"
201 #include "socks.h"
202 #include "chunk.h"
203 #include "object.h"
204 #include "dns.h"
205 #include "http.h"
206 #include "client.h"
207 #include "local.h"
208 #include "diskcache.h"
209 #include "server.h"
210 #include "http_parse.h"
211 #include "parse_time.h"
212 #include "forbidden.h"
213 #include "log.h"
214 #include "auth.h"
215 #include "tunnel.h"
217 extern AtomPtr configFile;
218 extern int daemonise;
219 extern AtomPtr pidFile;