]> git.ipfire.org Git - thirdparty/squid.git/blob - include/util.h
Merged from trunk.
[thirdparty/squid.git] / include / util.h
1 /*
2 * $Id: util.h,v 1.79 2007/12/14 23:11:44 amosjeffries 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
39 #if HAVE_STDIO_H
40 #include <stdio.h>
41 #endif
42 #if HAVE_TIME_H
43 #include <time.h>
44 #endif
45 #if HAVE_SYS_TIME_H
46 #include <sys/time.h>
47 #endif
48 #if HAVE_ARPA_INET_H
49 #include <arpa/inet.h>
50 #endif
51
52 #if defined(_SQUID_FREEBSD_)
53 #define _etext etext
54 #endif
55
56 SQUIDCEXTERN const char *mkhttpdlogtime(const time_t *);
57 SQUIDCEXTERN const char *mkrfc1123(time_t);
58 SQUIDCEXTERN char *uudecode(const char *);
59 SQUIDCEXTERN char *xstrdup(const char *);
60 SQUIDCEXTERN char *xstrndup(const char *, size_t);
61 SQUIDCEXTERN const char *xstrerr(int xerrno);
62 SQUIDCEXTERN const char *xstrerror(void);
63 SQUIDCEXTERN int tvSubMsec(struct timeval, struct timeval);
64 SQUIDCEXTERN int tvSubUsec(struct timeval, struct timeval);
65 SQUIDCEXTERN double tvSubDsec(struct timeval, struct timeval);
66 SQUIDCEXTERN char *xstrncpy(char *, const char *, size_t);
67 SQUIDCEXTERN size_t xcountws(const char *str);
68 SQUIDCEXTERN time_t parse_rfc1123(const char *str);
69 SQUIDCEXTERN void *xcalloc(size_t, size_t);
70 SQUIDCEXTERN void *xmalloc(size_t);
71 SQUIDCEXTERN void *xrealloc(void *, size_t);
72 SQUIDCEXTERN void Tolower(char *);
73 SQUIDCEXTERN void xfree(void *);
74 SQUIDCEXTERN void xxfree(const void *);
75 #ifdef __cplusplus
76 /*
77 * Any code using libstdc++ must have externally resolvable overloads
78 * for void * operator new - which means in the .o for the binary,
79 * or in a shared library. static libs don't propogate the symbol
80 * so, look in the translation unit containing main() in squid
81 * for the extern version in squid
82 */
83 #ifndef _SQUID_EXTERNNEW_
84 #if defined(_SQUID_SGI_) && !defined(_GNUC_)
85 /*
86 * The gcc compiler treats extern inline functions as being extern,
87 * while the SGI MIPSpro compilers treat them as inline. To get equivalent
88 * behavior, remove the inline keyword.
89 */
90 #define _SQUID_EXTERNNEW_ extern
91 #else
92 #ifdef __GNUC_STDC_INLINE__
93 #define _SQUID_EXTERNNEW_ extern inline __attribute__((gnu_inline))
94 #else
95 #define _SQUID_EXTERNNEW_ extern inline
96 #endif
97 #endif
98 #endif
99 #include "SquidNew.h"
100 #endif
101
102 /* rfc1738.c */
103 SQUIDCEXTERN char *rfc1738_escape(const char *);
104 SQUIDCEXTERN char *rfc1738_escape_unescaped(const char *);
105 SQUIDCEXTERN char *rfc1738_escape_part(const char *);
106 SQUIDCEXTERN void rfc1738_unescape(char *);
107
108 /* charset.c */
109 SQUIDCEXTERN char *latin1_to_utf8(char *out, size_t size, const char *in);
110
111 /* html.c */
112 SQUIDCEXTERN char *html_quote(const char *);
113
114 #if XMALLOC_STATISTICS
115 SQUIDCEXTERN void malloc_statistics(void (*)(int, int, int, void *), void *);
116 #endif
117
118 #if XMALLOC_TRACE
119 #define xmalloc(size) (xmalloc_func="xmalloc",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xmalloc(size))
120 #define xfree(ptr) (xmalloc_func="xfree",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xfree(ptr))
121 #define xxfree(ptr) (xmalloc_func="xxfree",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xxfree(ptr))
122 #define xrealloc(ptr,size) (xmalloc_func="xrealloc",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xrealloc(ptr,size))
123 #define xcalloc(n,size) (xmalloc_func="xcalloc",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xcalloc(n,size))
124 #define xstrdup(ptr) (xmalloc_func="xstrdup",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xstrdup(ptr))
125 extern int xmalloc_line;
126 extern char *xmalloc_file;
127 extern char *xmalloc_func;
128 extern int xmalloc_trace;
129 extern size_t xmalloc_total;
130 extern void xmalloc_find_leaks(void);
131 #endif
132
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 SQUIDCEXTERN const char *xint64toa(int64_t num);
144
145 #if !HAVE_DRAND48
146 SQUIDCEXTERN double drand48(void);
147 #endif
148
149 #ifndef xmax
150 #define xmax(a,b) ((a) < (b) ? (b) : (a))
151 #endif
152 #ifndef xmin
153 #define xmin(a,b) ((a) < (b) ? (a) : (b))
154 #endif
155
156 typedef struct {
157 size_t count;
158 size_t bytes;
159 size_t gb;
160 } gb_t;
161
162 /* gb_type operations */
163 #define gb_flush_limit (0x3FFFFFFF)
164 #define gb_inc(gb, delta) { if ((gb)->bytes > gb_flush_limit || delta > gb_flush_limit) gb_flush(gb); (gb)->bytes += delta; (gb)->count++; }
165 #define gb_incb(gb, delta) { if ((gb)->bytes > gb_flush_limit || delta > gb_flush_limit) gb_flush(gb); (gb)->bytes += delta; }
166 #define gb_incc(gb, delta) { if ((gb)->bytes > gb_flush_limit || delta > gb_flush_limit) gb_flush(gb); (gb)->count+= delta; }
167 extern double gb_to_double(const gb_t *);
168 SQUIDCEXTERN const char *double_to_str(char *buf, int buf_size, double value);
169 extern const char *gb_to_str(const gb_t *);
170 extern void gb_flush(gb_t *); /* internal, do not use this */
171
172 /*
173 * Returns the amount of known allocated memory
174 */
175 int statMemoryAccounted(void);
176
177 /* Windows Port */
178 /* win32lib.c */
179 #ifdef _SQUID_MSWIN_
180 SQUIDCEXTERN int chroot (const char *);
181 SQUIDCEXTERN int ftruncate(int, off_t);
182 #ifndef HAVE_GETTIMEOFDAY
183 SQUIDCEXTERN int gettimeofday(struct timeval * ,void *);
184 #endif
185 SQUIDCEXTERN int kill(pid_t, int);
186 SQUIDCEXTERN int statfs(const char *, struct statfs *);
187 SQUIDCEXTERN int truncate(const char *, off_t);
188 SQUIDCEXTERN const char * wsastrerror(int);
189 SQUIDCEXTERN struct passwd *getpwnam(char *);
190 SQUIDCEXTERN struct group *getgrnam(char *);
191 SQUIDCEXTERN uid_t geteuid(void);
192 SQUIDCEXTERN uid_t getuid(void);
193 SQUIDCEXTERN int setuid(uid_t);
194 SQUIDCEXTERN int seteuid(uid_t);
195 SQUIDCEXTERN gid_t getgid(void);
196 SQUIDCEXTERN gid_t getegid(void);
197 SQUIDCEXTERN int setgid(gid_t);
198 SQUIDCEXTERN int setegid(gid_t);
199 SQUIDCEXTERN const char *WIN32_strerror(int);
200 SQUIDCEXTERN void WIN32_maperror(unsigned long);
201 #endif
202 #endif /* SQUID_UTIL_H */