]> git.ipfire.org Git - thirdparty/squid.git/blame - src/squid.h
merge changes from SQUID_2_3 branch
[thirdparty/squid.git] / src / squid.h
CommitLineData
b560dd20 1
e090b977 2/*
7e3ce7b9 3 * $Id: squid.h,v 1.196 1999/12/30 17:36:50 wessels Exp $
e090b977 4 *
5 * AUTHOR: Duane Wessels
6 *
42c04c16 7 * SQUID Internet Object Cache http://squid.nlanr.net/Squid/
e25c139f 8 * ----------------------------------------------------------
e090b977 9 *
10 * Squid is the result of efforts by numerous individuals from the
11 * Internet community. Development is led by Duane Wessels of the
e25c139f 12 * National Laboratory for Applied Network Research and funded by the
13 * National Science Foundation. Squid is Copyrighted (C) 1998 by
14 * Duane Wessels and the University of California San Diego. Please
15 * see the COPYRIGHT file for full details. Squid incorporates
16 * software developed and/or copyrighted by other sources. Please see
17 * the CREDITS file for full details.
e090b977 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
cbdec147 31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
e25c139f 32 *
e090b977 33 */
44a47c6e 34
0ee4272b 35#ifndef SQUID_H
36#define SQUID_H
37
44a47c6e 38#include "config.h"
44a47c6e 39
9fa2cd4d 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
9d9d144b 44 * configure-discovered maximum *before* any system includes.
9fa2cd4d 45 */
e924600d 46#define CHANGE_FD_SETSIZE 1
9fa2cd4d 47
e924600d 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
9d9d144b 53
9bc73deb 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 */
e924600d 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
9bc73deb 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
e924600d 77/* Increase FD_SETSIZE if SQUID_MAXFD is bigger */
78#if CHANGE_FD_SETSIZE && SQUID_MAXFD > DEFAULT_FD_SETSIZE
9fa2cd4d 79#define FD_SETSIZE SQUID_MAXFD
80#endif
9d9d144b 81
aaf1b235 82#if PURIFY
54f742e7 83#define assert(EX) ((void)0)
6de2df60 84#elif STDC_HEADERS
54f742e7 85#define assert(EX) ((EX)?((void)0):xassert( # EX , __FILE__, __LINE__))
86#else
87#define assert(EX) ((EX)?((void)0):xassert("EX", __FILE__, __LINE__))
aaf1b235 88#endif
89
e090b977 90#if HAVE_UNISTD_H
44a47c6e 91#include <unistd.h>
e090b977 92#endif
93#if HAVE_STDLIB_H
44a47c6e 94#include <stdlib.h>
e090b977 95#endif
96#if HAVE_STDIO_H
44a47c6e 97#include <stdio.h>
e090b977 98#endif
99#if HAVE_SYS_TYPES_H
44a47c6e 100#include <sys/types.h>
e090b977 101#endif
102#if HAVE_CTYPE_H
44a47c6e 103#include <ctype.h>
e090b977 104#endif
105#if HAVE_ERRNO_H
44a47c6e 106#include <errno.h>
e090b977 107#endif
108#if HAVE_FCNTL_H
44a47c6e 109#include <fcntl.h>
e090b977 110#endif
111#if HAVE_GRP_H
44a47c6e 112#include <grp.h>
e090b977 113#endif
88738790 114#if HAVE_GNUMALLOC_H
115#include <gnumalloc.h>
116#elif HAVE_MALLOC_H && !defined(_SQUID_FREEBSD_) && !defined(_SQUID_NEXT_)
44a47c6e 117#include <malloc.h>
983061ed 118#endif
e090b977 119#if HAVE_MEMORY_H
44a47c6e 120#include <memory.h>
e090b977 121#endif
122#if HAVE_NETDB_H && !defined(_SQUID_NETDB_H_) /* protect NEXTSTEP */
123#define _SQUID_NETDB_H_
caebbe00 124#ifdef _SQUID_NEXT_
125#include <netinet/in_systm.h>
126#endif
44a47c6e 127#include <netdb.h>
e090b977 128#endif
129#if HAVE_PWD_H
44a47c6e 130#include <pwd.h>
e090b977 131#endif
132#if HAVE_SIGNAL_H
44a47c6e 133#include <signal.h>
e090b977 134#endif
135#if HAVE_TIME_H
db40ae20 136#include <time.h>
e090b977 137#endif
138#if HAVE_SYS_PARAM_H
44a47c6e 139#include <sys/param.h>
e090b977 140#endif
141#if HAVE_SYS_TIME_H
db40ae20 142#include <sys/time.h>
e090b977 143#endif
144#if HAVE_SYS_RESOURCE_H
db40ae20 145#include <sys/resource.h> /* needs sys/time.h above it */
e090b977 146#endif
147#if HAVE_SYS_SOCKET_H
44a47c6e 148#include <sys/socket.h>
e090b977 149#endif
150#if HAVE_NETINET_IN_H
44a47c6e 151#include <netinet/in.h>
e090b977 152#endif
153#if HAVE_ARPA_INET_H
44a47c6e 154#include <arpa/inet.h>
e090b977 155#endif
156#if HAVE_SYS_STAT_H
44a47c6e 157#include <sys/stat.h>
e090b977 158#endif
159#if HAVE_SYS_UN_H
44a47c6e 160#include <sys/un.h>
e090b977 161#endif
162#if HAVE_SYS_WAIT_H
44a47c6e 163#include <sys/wait.h>
e090b977 164#endif
165#if HAVE_LIBC_H
166#include <libc.h>
167#endif
234967c9 168#ifdef HAVE_SYS_SYSCALL_H
169#include <sys/syscall.h>
170#endif
db40ae20 171#ifdef HAVE_STRING_H
172#include <string.h>
173#endif
db40ae20 174#ifdef HAVE_STRINGS_H
175#include <strings.h>
44a47c6e 176#endif
44a47c6e 177#if HAVE_BSTRING_H
178#include <bstring.h>
179#endif
44a47c6e 180#ifdef HAVE_CRYPT_H
181#include <crypt.h>
182#endif
db40ae20 183#if HAVE_SYS_SELECT_H
184#include <sys/select.h>
185#endif
ef2d27ff 186#if HAVE_GETOPT_H
187#include <getopt.h>
188#endif
7e3ce7b9 189#if HAVE_LIMITS_H
190#include <limits.h>
191#endif
dcfe6390 192
f09f5b26 193#if HAVE_DIRENT_H
194#include <dirent.h>
195#define NAMLEN(dirent) strlen((dirent)->d_name)
196#else /* HAVE_DIRENT_H */
197#define dirent direct
198#define NAMLEN(dirent) (dirent)->d_namlen
199#if HAVE_SYS_NDIR_H
200#include <sys/ndir.h>
201#endif /* HAVE_SYS_NDIR_H */
202#if HAVE_SYS_DIR_H
203#include <sys/dir.h>
204#endif /* HAVE_SYS_DIR_H */
205#if HAVE_NDIR_H
206#include <ndir.h>
207#endif /* HAVE_NDIR_H */
208#endif /* HAVE_DIRENT_H */
209
75e5a32e 210#if defined(__QNX__)
211#include <unix.h>
212#endif
213
6425b967 214/*
5f25bc27 215 * We require poll.h before using poll(). If the symbols used
216 * by poll() are defined elsewhere, we will need to make this
217 * a more sophisticated test.
6425b967 218 * -- Oskar Pearson <oskar@is.co.za>
219 * -- Stewart Forster <slf@connect.com.au>
220 */
32ed74b6 221#if HAVE_POLL
6425b967 222#if HAVE_POLL_H
32ed74b6 223#include <poll.h>
6425b967 224#else /* HAVE_POLL_H */
32ed74b6 225#undef HAVE_POLL
6425b967 226#endif /* HAVE_POLL_H */
32ed74b6 227#endif /* HAVE_POLL */
228
6de2df60 229#if STDC_HEADERS
44a47c6e 230#include <stdarg.h>
231#else
232#include <varargs.h>
233#endif
234
058ef87c 235/* Make sure syslog goes after stdarg/varargs */
236#ifdef HAVE_SYSLOG_H
c68e9c6b 237#ifdef _SQUID_AIX_
238#define _XOPEN_EXTENDED_SOURCE
7e3ce7b9 239#define _XOPEN_SOURCE_EXTENDED 1
c68e9c6b 240#endif
058ef87c 241#include <syslog.h>
242#endif
243
34cbdf10 244#if HAVE_MATH_H
245#include <math.h>
246#endif
247
44a47c6e 248#if !defined(MAXHOSTNAMELEN) || (MAXHOSTNAMELEN < 128)
249#define SQUIDHOSTNAMELEN 128
250#else
251#define SQUIDHOSTNAMELEN MAXHOSTNAMELEN
252#endif
253
5ad764e2 254#define SQUID_MAXPATHLEN 256
8da4e36f 255#ifndef MAXPATHLEN
256#define MAXPATHLEN SQUID_MAXPATHLEN
257#endif
5ad764e2 258
bd8f4682 259#if !HAVE_GETRUSAGE
260#if defined(_SQUID_HPUX_)
48f44632 261#define HAVE_GETRUSAGE 1
e090b977 262#define getrusage(a, b) syscall(SYS_GETRUSAGE, a, b)
b54a6789 263#endif
264#endif
265
266#if !HAVE_STRUCT_RUSAGE
bd8f4682 267/*
268 * If we don't have getrusage() then we create a fake structure
269 * with only the fields Squid cares about. This just makes the
270 * source code cleaner, so we don't need lots of #ifdefs in other
271 * places
272 */
4f328706 273struct rusage {
364aa4a1 274 struct timeval ru_stime;
4f328706 275 struct timeval ru_utime;
364aa4a1 276 int ru_maxrss;
277 int ru_majflt;
4f328706 278};
0e473d70 279
e090b977 280#endif
281
282#if !defined(HAVE_GETPAGESIZE) && defined(_SQUID_HPUX_)
283#define HAVE_GETPAGESIZE
284#define getpagesize( ) sysconf(_SC_PAGE_SIZE)
285#endif
286
983061ed 287#ifndef BUFSIZ
288#define BUFSIZ 4096 /* make reasonable guess */
289#endif
290
03d7b07f 291
e090b977 292#ifndef SA_RESTART
293#define SA_RESTART 0
294#endif
295#ifndef SA_NODEFER
296#define SA_NODEFER 0
297#endif
e090b977 298#ifndef SA_RESETHAND
e090b977 299#define SA_RESETHAND 0
6e40f263 300#endif
301#if SA_RESETHAND == 0 && defined(SA_ONESHOT)
af00901c 302#undef SA_RESETHAND
6e40f263 303#define SA_RESETHAND SA_ONESHOT
304#endif
e090b977 305
9864ee44 306#if PURIFY
95d659f0 307#define LOCAL_ARRAY(type,name,size) \
308 static type *local_##name=NULL; \
309 type *name = local_##name ? local_##name : \
310 ( local_##name = (type *)xcalloc(size, sizeof(type)) )
311#else
312#define LOCAL_ARRAY(type,name,size) static type name[size]
313#endif
314
4e3f712d 315#if CBDATA_DEBUG
b23c677a 316#define cbdataAdd(a,b,c) cbdataAddDbg(a,b,c,__FILE__,__LINE__)
b7e6c377 317#define cbdataLock(a) cbdataLockDbg(a,__FILE__,__LINE__)
318#define cbdataUnlock(a) cbdataUnlockDbg(a,__FILE__,__LINE__)
4e3f712d 319#endif
320
5d620373 321#if USE_LEAKFINDER
322#define leakAdd(p) leakAddFL(p,__FILE__,__LINE__)
323#define leakTouch(p) leakTouchFL(p,__FILE__,__LINE__)
324#else
325#define leakAdd(p) p
326#define leakTouch(p) p
327#define leakFree(p) p
328#endif
329
c68e9c6b 330#if defined(_SQUID_NEXT_) && !defined(S_ISDIR)
331#define S_ISDIR(mode) (((mode) & (_S_IFMT)) == (_S_IFDIR))
332#endif
333
74946a0f 334#ifdef USE_GNUREGEX
473471f2 335#include "GNUregex.h"
74946a0f 336#elif HAVE_REGEX_H
337#include <regex.h>
338#endif
e090b977 339
1b4b8ead 340#if USE_ASYNC_IO
341#undef USE_UNLINKD
342#else
343#define USE_UNLINKD 1
344#endif
345
6507d007 346#include "md5.h"
b5107edb 347#include "Stack.h"
348
8b9a09e7 349/* Needed for poll() on Linux at least */
350#if HAVE_POLL
351#ifndef POLLRDNORM
352#define POLLRDNORM POLLIN
353#endif
354#ifndef POLLWRNORM
355#define POLLWRNORM POLLOUT
356#endif
357#endif
358
43d4303e 359#ifdef SQUID_SNMP
360#include "cache_snmp.h"
361#endif
362
f703eacb 363#include "hash.h"
7b724b86 364#include "rfc1035.h"
2b906e48 365#if HEAP_REPLACEMENT
366#include "heap.h"
367#endif
f703eacb 368
f1dc9b30 369#include "defines.h"
a4394ebd 370#include "enums.h"
f1dc9b30 371#include "typedefs.h"
372#include "structs.h"
373#include "protos.h"
374#include "globals.h"
375
44a47c6e 376#include "util.h"
9bc73deb 377
378/*
379 * Mac OS X Server already has radix.h as a standard header, so
380 * this causes conflicts.
7e3ce7b9 381 */
9bc73deb 382#ifndef _SQUID_APPLE_
364aa4a1 383#include "radix.h"
9bc73deb 384#endif
44a47c6e 385
e090b977 386#if !HAVE_TEMPNAM
387#include "tempnam.h"
388#endif
389
0b1bb521 390#if !HAVE_SNPRINTF
391#include "snprintf.h"
392#endif
393
0254ee29 394#define XMIN(x,y) ((x)<(y)? (x) : (y))
395#define XMAX(a,b) ((a)>(b)? (a) : (b))
396
2086b06c 397/*
398 * Squid source files should not call these functions directly
399 */
b6a2f15e 400#ifndef malloc
2086b06c 401#define malloc +
b6a2f15e 402#endif
403#ifndef free
2086b06c 404#define free +
b6a2f15e 405#endif
406#ifndef calloc
2086b06c 407#define calloc +
b6a2f15e 408#endif
409#ifndef sprintf
2086b06c 410#define sprintf +
b6a2f15e 411#endif
412#ifndef strdup
f511ab6f 413#define strdup +
b6a2f15e 414#endif
a561a1c4 415
6b7568e6 416/*
417 * Hey dummy, don't be tempted to move this to lib/config.h.in again. O_NONBLOCK
418 * will not be defined there because you didn't #include <fcntl.h> yet.
419 */
420#if defined(O_NONBLOCK) && !defined(_SQUID_SUNOS_) && !defined(_SQUID_SOLARIS_)
421#define SQUID_NONBLOCK O_NONBLOCK
422#else
423#define SQUID_NONBLOCK O_NDELAY
424#endif
8638fc66 425
95dcd2b8 426#define SWAP_DIR_SHIFT 24
427#define SWAP_FILE_MASK 0x00FFFFFF
428
0ee4272b 429#endif /* SQUID_H */