]> git.ipfire.org Git - thirdparty/squid.git/blob - include/util.h
Import of fix-ranges branch
[thirdparty/squid.git] / include / util.h
1 /*
2 * $Id: util.h,v 1.67 2003/01/23 00:36:48 robertc Exp $
3 *
4 * AUTHOR: Harvest Derived
5 *
6 * SQUID Web Proxy Cache http://www.squid-cache.org/
7 * ----------------------------------------------------------
8 *
9 * Squid is the result of efforts by numerous individuals from
10 * the Internet community; see the CONTRIBUTORS file for full
11 * details. Many organizations have provided support for Squid's
12 * development; see the SPONSORS file for full details. Squid is
13 * Copyrighted (C) 2001 by the Regents of the University of
14 * California; see the COPYRIGHT file for full details. Squid
15 * incorporates software developed and/or copyrighted by other
16 * sources; see the CREDITS file for full details.
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
31 *
32 */
33
34 #ifndef SQUID_UTIL_H
35 #define SQUID_UTIL_H
36
37 #include "config.h"
38 #include <stdio.h>
39 #include <time.h>
40 #if HAVE_TIME_H
41 #include <time.h>
42 #endif
43 #if HAVE_SYS_TIME_H
44 #include <sys/time.h>
45 #endif
46
47 #if !defined(SQUIDHOSTNAMELEN)
48 #include <sys/param.h>
49 #ifndef _SQUID_NETDB_H_ /* need protection on NEXTSTEP */
50 #define _SQUID_NETDB_H_
51 #include <netdb.h>
52 #endif
53 #if !defined(MAXHOSTNAMELEN) || (MAXHOSTNAMELEN < 128)
54 #define SQUIDHOSTNAMELEN 128
55 #else
56 #define SQUIDHOSTNAMELEN MAXHOSTNAMELEN
57 #endif
58 #endif
59
60 #if defined(_SQUID_FREEBSD_)
61 #define _etext etext
62 #endif
63
64 SQUIDCEXTERN const char *getfullhostname(void);
65 SQUIDCEXTERN const char *mkhttpdlogtime(const time_t *);
66 SQUIDCEXTERN const char *mkrfc1123(time_t);
67 SQUIDCEXTERN char *uudecode(const char *);
68 SQUIDCEXTERN char *xstrdup(const char *);
69 SQUIDCEXTERN char *xstrndup(const char *, size_t);
70 SQUIDCEXTERN const char *xstrerror(void);
71 extern const char *xbstrerror(int);
72 SQUIDCEXTERN int tvSubMsec(struct timeval, struct timeval);
73 SQUIDCEXTERN int tvSubUsec(struct timeval, struct timeval);
74 SQUIDCEXTERN double tvSubDsec(struct timeval, struct timeval);
75 SQUIDCEXTERN char *xstrncpy(char *, const char *, size_t);
76 SQUIDCEXTERN size_t xcountws(const char *str);
77 SQUIDCEXTERN time_t parse_rfc1123(const char *str);
78 SQUIDCEXTERN void *xcalloc(size_t, size_t);
79 SQUIDCEXTERN void *xmalloc(size_t);
80 SQUIDCEXTERN void *xrealloc(void *, size_t);
81 SQUIDCEXTERN void Tolower(char *);
82 SQUIDCEXTERN void xfree(void *);
83 SQUIDCEXTERN void xxfree(const void *);
84 #ifdef __cplusplus
85 inline void *operator new(size_t size)
86 {
87 return xmalloc(size);
88 }
89 inline void operator delete (void *address)
90 {
91 xfree (address);
92 }
93 inline void *operator new[] (size_t size)
94 {
95 return xmalloc(size);
96 }
97 inline void operator delete[] (void *address)
98 {
99 xfree (address);
100 }
101 #endif
102
103 /* rfc1738.c */
104 SQUIDCEXTERN char *rfc1738_escape(const char *);
105 SQUIDCEXTERN char *rfc1738_escape_unescaped(const char *);
106 SQUIDCEXTERN char *rfc1738_escape_part(const char *);
107 SQUIDCEXTERN void rfc1738_unescape(char *);
108
109 /* html.c */
110 SQUIDCEXTERN char *html_quote(const char *);
111
112 #if XMALLOC_STATISTICS
113 SQUIDCEXTERN void malloc_statistics(void (*)(int, int, int, void *), void *);
114 #endif
115
116 #if XMALLOC_TRACE
117 #define xmalloc(size) (xmalloc_func="xmalloc",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xmalloc(size))
118 #define xfree(ptr) (xmalloc_func="xfree",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xfree(ptr))
119 #define xxfree(ptr) (xmalloc_func="xxfree",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xxfree(ptr))
120 #define xrealloc(ptr,size) (xmalloc_func="xrealloc",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xrealloc(ptr,size))
121 #define xcalloc(n,size) (xmalloc_func="xcalloc",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xcalloc(n,size))
122 #define xstrdup(ptr) (xmalloc_func="xstrdup",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xstrdup(ptr))
123 extern int xmalloc_line;
124 extern char *xmalloc_file;
125 extern char *xmalloc_func;
126 extern int xmalloc_trace;
127 extern size_t xmalloc_total;
128 extern void xmalloc_find_leaks(void);
129 #endif
130
131 typedef struct in_addr SIA;
132 SQUIDCEXTERN int safe_inet_addr(const char *, SIA *);
133 SQUIDCEXTERN time_t parse_iso3307_time(const char *buf);
134 SQUIDCEXTERN char *base64_decode(const char *coded);
135 SQUIDCEXTERN const char *base64_encode(const char *decoded);
136 SQUIDCEXTERN const char *base64_encode_bin(const char *data, int len);
137
138 SQUIDCEXTERN double xpercent(double part, double whole);
139 SQUIDCEXTERN int xpercentInt(double part, double whole);
140 SQUIDCEXTERN double xdiv(double nom, double denom);
141
142 SQUIDCEXTERN const char *xitoa(int num);
143
144 #if !HAVE_DRAND48
145 double drand48(void);
146 #endif
147
148 typedef struct {
149 size_t count;
150 size_t bytes;
151 size_t gb;
152 } gb_t;
153
154 /* gb_type operations */
155 #define gb_flush_limit (0x3FFFFFFF)
156 #define gb_inc(gb, delta) { if ((gb)->bytes > gb_flush_limit || delta > gb_flush_limit) gb_flush(gb); (gb)->bytes += delta; (gb)->count++; }
157 #define gb_incb(gb, delta) { if ((gb)->bytes > gb_flush_limit || delta > gb_flush_limit) gb_flush(gb); (gb)->bytes += delta; }
158 #define gb_incc(gb, delta) { if ((gb)->bytes > gb_flush_limit || delta > gb_flush_limit) gb_flush(gb); (gb)->count+= delta; }
159 extern double gb_to_double(const gb_t *);
160 SQUIDCEXTERN const char *double_to_str(char *buf, int buf_size, double value);
161 extern const char *gb_to_str(const gb_t *);
162 extern void gb_flush(gb_t *); /* internal, do not use this */
163
164 /*
165 * Returns the amount of known allocated memory
166 */
167 int statMemoryAccounted(void);
168
169 #endif /* SQUID_UTIL_H */