]> git.ipfire.org Git - thirdparty/squid.git/blob - src/squid.h
SSL->HTTP gatewaying support by Benno Rice
[thirdparty/squid.git] / src / squid.h
1
2 /*
3 * $Id: squid.h,v 1.215 2001/04/14 00:03:23 hno Exp $
4 *
5 * AUTHOR: Duane Wessels
6 *
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
9 *
10 * Squid is the result of efforts by numerous individuals from
11 * the Internet community; see the CONTRIBUTORS file for full
12 * details. Many organizations have provided support for Squid's
13 * development; see the SPONSORS file for full details. Squid is
14 * Copyrighted (C) 2001 by the Regents of the University of
15 * California; see the COPYRIGHT file for full details. Squid
16 * incorporates software developed and/or copyrighted by other
17 * sources; see the CREDITS file for full details.
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
32 *
33 */
34
35 #ifndef SQUID_H
36 #define SQUID_H
37
38 #include "config.h"
39
40 /*
41 * On some systems, FD_SETSIZE is set to something lower than the
42 * actual number of files which can be opened. IRIX is one case,
43 * NetBSD is another. So here we increase FD_SETSIZE to our
44 * configure-discovered maximum *before* any system includes.
45 */
46 #define CHANGE_FD_SETSIZE 1
47
48 /* Cannot increase FD_SETSIZE on Linux */
49 #if defined(_SQUID_LINUX_)
50 #undef CHANGE_FD_SETSIZE
51 #define CHANGE_FD_SETSIZE 0
52 #endif
53
54 /*
55 * Cannot increase FD_SETSIZE on FreeBSD before 2.2.0, causes select(2)
56 * to return EINVAL.
57 * --Marian Durkovic <marian@svf.stuba.sk>
58 * --Peter Wemm <peter@spinner.DIALix.COM>
59 */
60 #if defined(_SQUID_FREEBSD_)
61 #include <osreldate.h>
62 #if __FreeBSD_version < 220000
63 #undef CHANGE_FD_SETSIZE
64 #define CHANGE_FD_SETSIZE 0
65 #endif
66 #endif
67
68 /*
69 * Trying to redefine CHANGE_FD_SETSIZE causes a slew of warnings
70 * on Mac OS X Server.
71 */
72 #if defined(_SQUID_APPLE_)
73 #undef CHANGE_FD_SETSIZE
74 #define CHANGE_FD_SETSIZE 0
75 #endif
76
77 /* Increase FD_SETSIZE if SQUID_MAXFD is bigger */
78 #if CHANGE_FD_SETSIZE && SQUID_MAXFD > DEFAULT_FD_SETSIZE
79 #define FD_SETSIZE SQUID_MAXFD
80 #endif
81
82 #if PURIFY
83 #define assert(EX) ((void)0)
84 #elif defined(NODEBUG)
85 #define assert(EX) ((void)0)
86 #elif STDC_HEADERS
87 #define assert(EX) ((EX)?((void)0):xassert( # EX , __FILE__, __LINE__))
88 #else
89 #define assert(EX) ((EX)?((void)0):xassert("EX", __FILE__, __LINE__))
90 #endif
91
92
93 /* 32 bit integer compatability */
94 #include "squid_types.h"
95 #define num32 int32_t
96 #define u_num32 u_int32_t
97
98 #if HAVE_UNISTD_H
99 #include <unistd.h>
100 #endif
101 #if HAVE_STDLIB_H
102 #include <stdlib.h>
103 #endif
104 #if HAVE_STDIO_H
105 #include <stdio.h>
106 #endif
107 #if HAVE_SYS_TYPES_H
108 #include <sys/types.h>
109 #endif
110 #if HAVE_CTYPE_H
111 #include <ctype.h>
112 #endif
113 #if HAVE_ERRNO_H
114 #include <errno.h>
115 #endif
116 #if HAVE_FCNTL_H
117 #include <fcntl.h>
118 #endif
119 #if HAVE_GRP_H
120 #include <grp.h>
121 #endif
122 #if HAVE_GNUMALLOC_H
123 #include <gnumalloc.h>
124 #elif HAVE_MALLOC_H && !defined(_SQUID_FREEBSD_) && !defined(_SQUID_NEXT_)
125 #include <malloc.h>
126 #endif
127 #if HAVE_MEMORY_H
128 #include <memory.h>
129 #endif
130 #if HAVE_NETDB_H && !defined(_SQUID_NETDB_H_) /* protect NEXTSTEP */
131 #define _SQUID_NETDB_H_
132 #ifdef _SQUID_NEXT_
133 #include <netinet/in_systm.h>
134 #endif
135 #include <netdb.h>
136 #endif
137 #if HAVE_PWD_H
138 #include <pwd.h>
139 #endif
140 #if HAVE_SIGNAL_H
141 #include <signal.h>
142 #endif
143 #if HAVE_TIME_H
144 #include <time.h>
145 #endif
146 #if HAVE_SYS_PARAM_H
147 #include <sys/param.h>
148 #endif
149 #if HAVE_SYS_TIME_H
150 #include <sys/time.h>
151 #endif
152 #if HAVE_SYS_RESOURCE_H
153 #include <sys/resource.h> /* needs sys/time.h above it */
154 #endif
155 #if HAVE_SYS_SOCKET_H
156 #include <sys/socket.h>
157 #endif
158 #if HAVE_NETINET_IN_H
159 #include <netinet/in.h>
160 #endif
161 #if HAVE_ARPA_INET_H
162 #include <arpa/inet.h>
163 #endif
164 #if HAVE_SYS_STAT_H
165 #include <sys/stat.h>
166 #endif
167 #if HAVE_SYS_UN_H
168 #include <sys/un.h>
169 #endif
170 #if HAVE_SYS_WAIT_H
171 #include <sys/wait.h>
172 #endif
173 #if HAVE_LIBC_H
174 #include <libc.h>
175 #endif
176 #ifdef HAVE_SYS_SYSCALL_H
177 #include <sys/syscall.h>
178 #endif
179 #ifdef HAVE_STRING_H
180 #include <string.h>
181 #endif
182 #ifdef HAVE_STRINGS_H
183 #include <strings.h>
184 #endif
185 #if HAVE_BSTRING_H
186 #include <bstring.h>
187 #endif
188 #ifdef HAVE_CRYPT_H
189 #include <crypt.h>
190 #endif
191 #if HAVE_SYS_SELECT_H
192 #include <sys/select.h>
193 #endif
194 #if HAVE_GETOPT_H
195 #include <getopt.h>
196 #endif
197 #if HAVE_LIMITS_H
198 #include <limits.h>
199 #endif
200 #if defined(_SQUID_CYGWIN_)
201 #include <io.h>
202 #endif
203
204 #if HAVE_DIRENT_H
205 #include <dirent.h>
206 #define NAMLEN(dirent) strlen((dirent)->d_name)
207 #else /* HAVE_DIRENT_H */
208 #define dirent direct
209 #define NAMLEN(dirent) (dirent)->d_namlen
210 #if HAVE_SYS_NDIR_H
211 #include <sys/ndir.h>
212 #endif /* HAVE_SYS_NDIR_H */
213 #if HAVE_SYS_DIR_H
214 #include <sys/dir.h>
215 #endif /* HAVE_SYS_DIR_H */
216 #if HAVE_NDIR_H
217 #include <ndir.h>
218 #endif /* HAVE_NDIR_H */
219 #endif /* HAVE_DIRENT_H */
220
221 #if defined(__QNX__)
222 #include <unix.h>
223 #endif
224
225 #if HAVE_SYS_MOUNT_H
226 #include <sys/mount.h>
227 #endif
228
229 /*
230 * We require poll.h before using poll(). If the symbols used
231 * by poll() are defined elsewhere, we will need to make this
232 * a more sophisticated test.
233 * -- Oskar Pearson <oskar@is.co.za>
234 * -- Stewart Forster <slf@connect.com.au>
235 */
236 #if HAVE_POLL
237 #if HAVE_POLL_H
238 #include <poll.h>
239 #else /* HAVE_POLL_H */
240 #undef HAVE_POLL
241 #endif /* HAVE_POLL_H */
242 #endif /* HAVE_POLL */
243
244 #if defined(HAVE_STDARG_H)
245 #include <stdarg.h>
246 #define HAVE_STDARGS /* let's hope that works everywhere (mj) */
247 #define VA_LOCAL_DECL va_list ap;
248 #define VA_START(f) va_start(ap, f)
249 #define VA_SHIFT(v,t) ; /* no-op for ANSI */
250 #define VA_END va_end(ap)
251 #else
252 #if defined(HAVE_VARARGS_H)
253 #include <varargs.h>
254 #undef HAVE_STDARGS
255 #define VA_LOCAL_DECL va_list ap;
256 #define VA_START(f) va_start(ap) /* f is ignored! */
257 #define VA_SHIFT(v,t) v = va_arg(ap,t)
258 #define VA_END va_end(ap)
259 #else
260 #error XX **NO VARARGS ** XX
261 #endif
262 #endif
263
264 /* Make sure syslog goes after stdarg/varargs */
265 #ifdef HAVE_SYSLOG_H
266 #ifdef _SQUID_AIX_
267 #define _XOPEN_EXTENDED_SOURCE
268 #define _XOPEN_SOURCE_EXTENDED 1
269 #endif
270 #include <syslog.h>
271 #endif
272
273 #if HAVE_MATH_H
274 #include <math.h>
275 #endif
276
277 #if !defined(MAXHOSTNAMELEN) || (MAXHOSTNAMELEN < 128)
278 #define SQUIDHOSTNAMELEN 128
279 #else
280 #define SQUIDHOSTNAMELEN MAXHOSTNAMELEN
281 #endif
282
283 #define SQUID_MAXPATHLEN 256
284 #ifndef MAXPATHLEN
285 #define MAXPATHLEN SQUID_MAXPATHLEN
286 #endif
287
288 #if !HAVE_GETRUSAGE
289 #if defined(_SQUID_HPUX_)
290 #define HAVE_GETRUSAGE 1
291 #define getrusage(a, b) syscall(SYS_GETRUSAGE, a, b)
292 #endif
293 #endif
294
295 #if !HAVE_STRUCT_RUSAGE
296 /*
297 * If we don't have getrusage() then we create a fake structure
298 * with only the fields Squid cares about. This just makes the
299 * source code cleaner, so we don't need lots of #ifdefs in other
300 * places
301 */
302 struct rusage {
303 struct timeval ru_stime;
304 struct timeval ru_utime;
305 int ru_maxrss;
306 int ru_majflt;
307 };
308
309 #endif
310
311 #if !defined(HAVE_GETPAGESIZE) && defined(_SQUID_HPUX_)
312 #define HAVE_GETPAGESIZE
313 #define getpagesize( ) sysconf(_SC_PAGE_SIZE)
314 #endif
315
316 #ifndef BUFSIZ
317 #define BUFSIZ 4096 /* make reasonable guess */
318 #endif
319
320
321 #ifndef SA_RESTART
322 #define SA_RESTART 0
323 #endif
324 #ifndef SA_NODEFER
325 #define SA_NODEFER 0
326 #endif
327 #ifndef SA_RESETHAND
328 #define SA_RESETHAND 0
329 #endif
330 #if SA_RESETHAND == 0 && defined(SA_ONESHOT)
331 #undef SA_RESETHAND
332 #define SA_RESETHAND SA_ONESHOT
333 #endif
334
335 #if PURIFY
336 #define LOCAL_ARRAY(type,name,size) \
337 static type *local_##name=NULL; \
338 type *name = local_##name ? local_##name : \
339 ( local_##name = (type *)xcalloc(size, sizeof(type)) )
340 #else
341 #define LOCAL_ARRAY(type,name,size) static type name[size]
342 #endif
343
344 #if CBDATA_DEBUG
345 #define cbdataAlloc(a,b) cbdataAllocDbg(a,b,__FILE__,__LINE__)
346 #define cbdataLock(a) cbdataLockDbg(a,__FILE__,__LINE__)
347 #define cbdataUnlock(a) cbdataUnlockDbg(a,__FILE__,__LINE__)
348 #endif
349
350 #if USE_LEAKFINDER
351 #define leakAdd(p) leakAddFL(p,__FILE__,__LINE__)
352 #define leakTouch(p) leakTouchFL(p,__FILE__,__LINE__)
353 #define leakFree(p) leakFreeFL(p,__FILE__,__LINE__)
354 #else
355 #define leakAdd(p) p
356 #define leakTouch(p) p
357 #define leakFree(p) p
358 #endif
359
360 #if defined(_SQUID_NEXT_) && !defined(S_ISDIR)
361 #define S_ISDIR(mode) (((mode) & (_S_IFMT)) == (_S_IFDIR))
362 #endif
363
364 #ifdef USE_GNUREGEX
365 #include "GNUregex.h"
366 #elif HAVE_REGEX_H
367 #include <regex.h>
368 #endif
369
370 #include "md5.h"
371
372 #if USE_SSL
373 #include "ssl_support.h"
374 /* This is an ugly hack, but necessary.
375 *
376 * Squid's md5 conflicts with OpenSSL's md5, but they're more or less
377 * interchangable.
378 * Free is defined in include/radix.h and also in OpenSSL, but we don't need
379 * OpenSSL's, so it can be undef'd and then appear from radix.h later.
380 * It's dangerous and ugly, but I can't see any other way to get around it.
381 */
382 #undef Free
383 #endif
384
385 #include "Stack.h"
386
387 /* Needed for poll() on Linux at least */
388 #if HAVE_POLL
389 #ifndef POLLRDNORM
390 #define POLLRDNORM POLLIN
391 #endif
392 #ifndef POLLWRNORM
393 #define POLLWRNORM POLLOUT
394 #endif
395 #endif
396
397 #ifdef SQUID_SNMP
398 #include "cache_snmp.h"
399 #endif
400
401 #include "hash.h"
402 #include "rfc1035.h"
403
404 #include "defines.h"
405 #include "enums.h"
406 #include "typedefs.h"
407 #include "structs.h"
408 #include "protos.h"
409 #include "globals.h"
410
411 #include "util.h"
412
413 /*
414 * Mac OS X Server already has radix.h as a standard header, so
415 * this causes conflicts.
416 */
417 #ifndef _SQUID_APPLE_
418 #include "radix.h"
419 #endif
420
421 #if !HAVE_TEMPNAM
422 #include "tempnam.h"
423 #endif
424
425 #if !HAVE_SNPRINTF
426 #include "snprintf.h"
427 #endif
428
429 #define XMIN(x,y) ((x)<(y)? (x) : (y))
430 #define XMAX(a,b) ((a)>(b)? (a) : (b))
431
432 /*
433 * Squid source files should not call these functions directly.
434 * Use xmalloc, xfree, xcalloc, snprintf, and xstrdup instead.
435 * Also use xmemcpy, xisspace, ...
436 */
437 #ifndef malloc
438 #define malloc +
439 #endif
440 #ifndef free
441 #define free +
442 #endif
443 #ifndef calloc
444 #define calloc +
445 #endif
446 #ifndef sprintf
447 #define sprintf +
448 #endif
449 #ifndef strdup
450 #define strdup +
451 #endif
452
453 /*
454 * Hey dummy, don't be tempted to move this to lib/config.h.in
455 * again. O_NONBLOCK will not be defined there because you didn't
456 * #include <fcntl.h> yet.
457 */
458 #if defined(_SQUID_SUNOS_)
459 /*
460 * We assume O_NONBLOCK is broken, or does not exist, on SunOS.
461 */
462 #define SQUID_NONBLOCK O_NDELAY
463 #elif defined(O_NONBLOCK)
464 /*
465 * We used to assume O_NONBLOCK was broken on Solaris, but evidence
466 * now indicates that its fine on Solaris 8, and in fact required for
467 * properly detecting EOF on FIFOs. So now we assume that if
468 * its defined, it works correctly on all operating systems.
469 */
470 #define SQUID_NONBLOCK O_NONBLOCK
471 /*
472 * O_NDELAY is our fallback.
473 */
474 #else
475 #define SQUID_NONBLOCK O_NDELAY
476 #endif
477
478 /*
479 * I'm sick of having to keep doing this ..
480 */
481 #define INDEXSD(i) (&Config.cacheSwap.swapDirs[(i)])
482
483 #define FD_READ_METHOD(fd, buf, len) (*fd_table[fd].read_method)(fd, buf, len)
484 #define FD_WRITE_METHOD(fd, buf, len) (*fd_table[fd].write_method)(fd, buf, len)
485
486 #endif /* SQUID_H */