Fix reading of requests larger than a chunk's worth.
[polipo.git] / polipo.h
blob5af55d7992ab1b703e4cea92f724c516c4bdd1e1
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 #endif
143 #ifdef __NetBSD__
144 #if __NetBSD_Version__ >= 105000000
145 #define HAVE_IPv6
146 #endif
147 #if __NetBSD_Version__ >= 200000000
148 #define HAVE_TIMEGM
149 #define HAVE_ASPRINTF
150 #endif
151 #endif
153 #ifdef __OpenBSD__
154 #if OpenBSD >= 200311
155 #define HAVE_IPv6
156 #endif
157 #endif
159 #endif
161 #if defined(i386) || defined(__mc68020__)
162 #define UNALIGNED_ACCESS
163 #endif
165 #ifndef MINGW
166 #define HAVE_FORK
167 #ifndef NO_SYSLOG
168 #define HAVE_SYSLOG
169 #endif
170 #define HAVE_READV_WRITEV
171 #define HAVE_FFS
172 #define READ(x, y, z) read(x, y, z)
173 #define WRITE(x, y, z) write(x, y, z)
174 #define CLOSE(x) close(x)
175 #else
176 #ifndef HAVE_REGEX
177 #define NO_FORBIDDEN
178 #endif
179 #endif
181 #ifdef HAVE_READV_WRITEV
182 #define WRITEV(x, y, z) writev(x, y, z)
183 #define READV(x, y, z) readv(x, y, z)
184 #endif
186 #ifndef HAVE_FORK
187 #define NO_REDIRECTOR
188 #endif
190 #include "mingw.h"
192 #include "ftsimport.h"
193 #include "atom.h"
194 #include "util.h"
195 #include "config.h"
196 #include "event.h"
197 #include "io.h"
198 #include "socks.h"
199 #include "chunk.h"
200 #include "object.h"
201 #include "dns.h"
202 #include "http.h"
203 #include "client.h"
204 #include "local.h"
205 #include "diskcache.h"
206 #include "server.h"
207 #include "http_parse.h"
208 #include "parse_time.h"
209 #include "forbidden.h"
210 #include "log.h"
211 #include "auth.h"
212 #include "tunnel.h"
214 extern AtomPtr configFile;
215 extern int daemonise;
216 extern AtomPtr pidFile;