]> git.ipfire.org Git - thirdparty/squid.git/blob - include/util.h
Merge from trunk
[thirdparty/squid.git] / include / util.h
1 /*
2 * $Id$
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 #ifdef __GNUC_STDC_INLINE__
85 #define _SQUID_EXTERNNEW_ extern inline __attribute__((gnu_inline))
86 #else
87 #define _SQUID_EXTERNNEW_ extern inline
88 #endif
89 #endif
90 #include "SquidNew.h"
91 #endif
92
93 /* charset.c */
94 SQUIDCEXTERN char *latin1_to_utf8(char *out, size_t size, const char *in);
95
96 /* html.c */
97 SQUIDCEXTERN char *html_quote(const char *);
98
99 #if XMALLOC_STATISTICS
100 SQUIDCEXTERN void malloc_statistics(void (*)(int, int, int, void *), void *);
101 #endif
102
103 #if XMALLOC_TRACE
104 #define xmalloc(size) (xmalloc_func="xmalloc",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xmalloc(size))
105 #define xfree(ptr) (xmalloc_func="xfree",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xfree(ptr))
106 #define xxfree(ptr) (xmalloc_func="xxfree",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xxfree(ptr))
107 #define xrealloc(ptr,size) (xmalloc_func="xrealloc",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xrealloc(ptr,size))
108 #define xcalloc(n,size) (xmalloc_func="xcalloc",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xcalloc(n,size))
109 #define xstrdup(ptr) (xmalloc_func="xstrdup",xmalloc_line=__LINE__,xmalloc_file=__FILE__,xstrdup(ptr))
110 extern int xmalloc_line;
111 extern char *xmalloc_file;
112 extern char *xmalloc_func;
113 extern int xmalloc_trace;
114 extern size_t xmalloc_total;
115 extern void xmalloc_find_leaks(void);
116 #endif
117
118 SQUIDCEXTERN time_t parse_iso3307_time(const char *buf);
119 SQUIDCEXTERN char *base64_decode(const char *coded);
120 SQUIDCEXTERN const char *base64_encode(const char *decoded);
121 SQUIDCEXTERN const char *base64_encode_bin(const char *data, int len);
122
123 SQUIDCEXTERN double xpercent(double part, double whole);
124 SQUIDCEXTERN int xpercentInt(double part, double whole);
125 SQUIDCEXTERN double xdiv(double nom, double denom);
126
127 SQUIDCEXTERN const char *xitoa(int num);
128 SQUIDCEXTERN const char *xint64toa(int64_t num);
129
130 #if !HAVE_DRAND48
131 SQUIDCEXTERN double drand48(void);
132 #endif
133
134 typedef struct {
135 size_t count;
136 size_t bytes;
137 size_t gb;
138 } gb_t;
139
140 /* gb_type operations */
141 #define gb_flush_limit (0x3FFFFFFF)
142 #define gb_inc(gb, delta) { if ((gb)->bytes > gb_flush_limit || delta > gb_flush_limit) gb_flush(gb); (gb)->bytes += delta; (gb)->count++; }
143 #define gb_incb(gb, delta) { if ((gb)->bytes > gb_flush_limit || delta > gb_flush_limit) gb_flush(gb); (gb)->bytes += delta; }
144 #define gb_incc(gb, delta) { if ((gb)->bytes > gb_flush_limit || delta > gb_flush_limit) gb_flush(gb); (gb)->count+= delta; }
145 extern double gb_to_double(const gb_t *);
146 SQUIDCEXTERN const char *double_to_str(char *buf, int buf_size, double value);
147 extern const char *gb_to_str(const gb_t *);
148 extern void gb_flush(gb_t *); /* internal, do not use this */
149
150 /*
151 * Returns the amount of known allocated memory
152 */
153 int statMemoryAccounted(void);
154
155 /* Windows Port */
156 /* win32lib.c */
157 #ifdef _SQUID_MSWIN_
158 SQUIDCEXTERN int chroot (const char *);
159 SQUIDCEXTERN int ftruncate(int, off_t);
160 #ifndef HAVE_GETTIMEOFDAY
161 SQUIDCEXTERN int gettimeofday(struct timeval * ,void *);
162 #endif
163 SQUIDCEXTERN int kill(pid_t, int);
164 SQUIDCEXTERN int statfs(const char *, struct statfs *);
165 SQUIDCEXTERN int truncate(const char *, off_t);
166 SQUIDCEXTERN const char * wsastrerror(int);
167 SQUIDCEXTERN struct passwd *getpwnam(char *);
168 SQUIDCEXTERN struct group *getgrnam(char *);
169 SQUIDCEXTERN uid_t geteuid(void);
170 SQUIDCEXTERN uid_t getuid(void);
171 SQUIDCEXTERN int setuid(uid_t);
172 SQUIDCEXTERN int seteuid(uid_t);
173 SQUIDCEXTERN gid_t getgid(void);
174 SQUIDCEXTERN gid_t getegid(void);
175 SQUIDCEXTERN int setgid(gid_t);
176 SQUIDCEXTERN int setegid(gid_t);
177 SQUIDCEXTERN const char *WIN32_strerror(int);
178 SQUIDCEXTERN void WIN32_maperror(unsigned long);
179 #endif
180 #endif /* SQUID_UTIL_H */