Plug memory leak if listen-address only specifies the port.
[privoxy.git] / miscutil.h
1 #ifndef MISCUTIL_H_INCLUDED
2 #define MISCUTIL_H_INCLUDED
3 #define MISCUTIL_H_VERSION "$Id: miscutil.h,v 1.28 2007/05/11 11:48:16 fabiankeil Exp $"
4 /*********************************************************************
5  *
6  * File        :  $Source: /cvsroot/ijbswa/current/miscutil.h,v $
7  *
8  * Purpose     :  zalloc, hash_string, safe_strerror, strcmpic,
9  *                strncmpic, and MinGW32 strdup functions.  These are
10  *                each too small to deserve their own file but don't 
11  *                really fit in any other file.
12  *
13  * Copyright   :  Written by and Copyright (C) 2001-2007 the SourceForge
14  *                Privoxy team. http://www.privoxy.org/
15  *
16  *                Based on the Internet Junkbuster originally written
17  *                by and Copyright (C) 1997 Anonymous Coders and 
18  *                Junkbusters Corporation.  http://www.junkbusters.com
19  *
20  *                This program is free software; you can redistribute it 
21  *                and/or modify it under the terms of the GNU General
22  *                Public License as published by the Free Software
23  *                Foundation; either version 2 of the License, or (at
24  *                your option) any later version.
25  *
26  *                This program is distributed in the hope that it will
27  *                be useful, but WITHOUT ANY WARRANTY; without even the
28  *                implied warranty of MERCHANTABILITY or FITNESS FOR A
29  *                PARTICULAR PURPOSE.  See the GNU General Public
30  *                License for more details.
31  *
32  *                The GNU General Public License should be included with
33  *                this file.  If not, you can view it at
34  *                http://www.gnu.org/copyleft/gpl.html
35  *                or write to the Free Software Foundation, Inc., 59
36  *                Temple Place - Suite 330, Boston, MA  02111-1307, USA.
37  *
38  * Revisions   :
39  *    $Log: miscutil.h,v $
40  *    Revision 1.28  2007/05/11 11:48:16  fabiankeil
41  *    - Delete strsav() which was replaced
42  *      by string_append() years ago.
43  *    - Add a strlcat() look-alike.
44  *    - Use strlcat() and strlcpy() in those parts
45  *      of the code that are run on unixes.
46  *
47  *    Revision 1.27  2007/04/09 17:48:51  fabiankeil
48  *    Check for HAVE_SNPRINTF instead of __OS2__
49  *    before including the portable snprintf() code.
50  *
51  *    Revision 1.26  2007/04/08 17:04:51  fabiankeil
52  *    Add macro for strlcpy() in case the libc lacks it.
53  *
54  *    Revision 1.25  2007/01/18 15:03:20  fabiankeil
55  *    Don't include replacement timegm() if
56  *    putenv() or tzset() isn't available.
57  *
58  *    Revision 1.24  2006/08/17 17:15:10  fabiankeil
59  *    - Back to timegm() using GnuPG's replacement if necessary.
60  *      Using mktime() and localtime() could add a on hour offset if
61  *      the randomize factor was big enough to lead to a summer/wintertime
62  *      switch.
63  *
64  *    - Removed now-useless Privoxy 3.0.3 compatibility glue.
65  *
66  *    - Moved randomization code into pick_from_range().
67  *
68  *    - Changed parse_header_time definition.
69  *      time_t isn't guaranteed to be signed and
70  *      if it isn't, -1 isn't available as error code.
71  *      Changed some variable types in client_if_modified_since()
72  *      because of the same reason.
73  *
74  *    Revision 1.23  2006/07/18 14:48:47  david__schmidt
75  *    Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
76  *    with what was really the latest development (the v_3_0_branch branch)
77  *
78  *    Revision 1.21  2002/04/26 12:55:38  oes
79  *    New function string_toupper
80  *
81  *    Revision 1.20  2002/03/26 22:29:55  swa
82  *    we have a new homepage!
83  *
84  *    Revision 1.19  2002/03/24 13:25:43  swa
85  *    name change related issues
86  *
87  *    Revision 1.18  2002/03/07 03:46:17  oes
88  *    Fixed compiler warnings
89  *
90  *    Revision 1.17  2002/03/04 18:28:32  oes
91  *    Deleted deletePidFile, played syleguide police
92  *
93  *    Revision 1.16  2002/01/21 00:53:36  jongfoster
94  *    Adding string_join()
95  *
96  *    Revision 1.15  2001/12/30 14:07:32  steudten
97  *    - Add signal handling (unix)
98  *    - Add SIGHUP handler (unix)
99  *    - Add creation of pidfile (unix)
100  *    - Add action 'top' in rc file (RH)
101  *    - Add entry 'SIGNALS' to manpage
102  *    - Add exit message to logfile (unix)
103  *
104  *    Revision 1.14  2001/11/05 21:43:48  steudten
105  *    Add global var 'basedir' for unix os.
106  *
107  *    Revision 1.13  2001/10/29 03:48:10  david__schmidt
108  *    OS/2 native needed a snprintf() routine.  Added one to miscutil, brackedted
109  *    by and __OS2__ ifdef.
110  *
111  *    Revision 1.12  2001/10/23 21:27:50  jongfoster
112  *    Standardising error codes in string_append
113  *    make_path() no longer adds '\\' if the dir already ends in '\\' (this
114  *    is just copying a UNIX-specific fix to the Windows-specific part)
115  *
116  *    Revision 1.11  2001/10/14 22:02:57  jongfoster
117  *    New function string_append() which is like strsav(), but running
118  *    out of memory isn't automatically FATAL.
119  *
120  *    Revision 1.10  2001/09/20 13:34:09  steudten
121  *
122  *    change long to int for prototype hash_string()
123  *
124  *    Revision 1.9  2001/07/29 18:43:08  jongfoster
125  *    Changing #ifdef _FILENAME_H to FILENAME_H_INCLUDED, to conform to
126  *    ANSI C rules.
127  *
128  *    Revision 1.8  2001/06/29 13:32:14  oes
129  *    Removed logentry from cancelled commit
130  *
131  *    Revision 1.7  2001/06/05 22:32:01  jongfoster
132  *    New function make_path() to splice directory and file names together.
133  *
134  *    Revision 1.6  2001/06/03 19:12:30  oes
135  *    introduced bindup()
136  *
137  *    Revision 1.5  2001/06/01 10:31:51  oes
138  *    Added character class matching to trivimatch; renamed to simplematch
139  *
140  *    Revision 1.4  2001/05/31 17:32:31  oes
141  *
142  *     - Enhanced domain part globbing with infix and prefix asterisk
143  *       matching and optional unanchored operation
144  *
145  *    Revision 1.3  2001/05/29 23:10:09  oes
146  *
147  *
148  *     - Introduced chomp()
149  *     - Moved strsav() from showargs to miscutil
150  *
151  *    Revision 1.2  2001/05/29 09:50:24  jongfoster
152  *    Unified blocklist/imagelist/permissionslist.
153  *    File format is still under discussion, but the internal changes
154  *    are (mostly) done.
155  *
156  *    Also modified interceptor behaviour:
157  *    - We now intercept all URLs beginning with one of the following
158  *      prefixes (and *only* these prefixes):
159  *        * http://i.j.b/
160  *        * http://ijbswa.sf.net/config/
161  *        * http://ijbswa.sourceforge.net/config/
162  *    - New interceptors "home page" - go to http://i.j.b/ to see it.
163  *    - Internal changes so that intercepted and fast redirect pages
164  *      are not replaced with an image.
165  *    - Interceptors now have the option to send a binary page direct
166  *      to the client. (i.e. ijb-send-banner uses this)
167  *    - Implemented show-url-info interceptor.  (Which is why I needed
168  *      the above interceptors changes - a typical URL is
169  *      "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
170  *      The previous mechanism would not have intercepted that, and
171  *      if it had been intercepted then it then it would have replaced
172  *      it with an image.)
173  *
174  *    Revision 1.1.1.1  2001/05/15 13:59:00  oes
175  *    Initial import of version 2.9.3 source tree
176  *
177  *
178  *********************************************************************/
179 \f
180
181 #include "project.h"
182
183 #if defined(__cplusplus)
184 extern "C" {
185 #endif
186
187 extern const char *basedir;
188 extern void *zalloc(size_t size);
189
190 #if defined(unix)
191 extern void write_pid_file(void);
192 #endif /* unix */
193
194 extern unsigned int hash_string(const char* s);
195
196 extern char *safe_strerror(int err);
197
198 extern int strcmpic(const char *s1, const char *s2);
199 extern int strncmpic(const char *s1, const char *s2, size_t n);
200
201 extern jb_err string_append(char **target_string, const char *text_to_append);
202 extern jb_err string_join  (char **target_string,       char *text_to_append);
203
204 extern char *string_toupper(const char *string);
205 extern char *chomp(char *string);
206 extern int simplematch(char *pattern, char *text);
207
208 extern char *bindup(const char *string, size_t len);
209
210 extern char *make_path(const char * dir, const char * file);
211
212 long int pick_from_range(long int range);
213
214 #ifdef __MINGW32__
215 extern char *strdup(const char *s);
216 #endif /* def __MINGW32__ */
217
218 #ifndef HAVE_SNPRINTF
219 extern int snprintf(char *, size_t, const char *, /*args*/ ...);
220 #endif /* ndef HAVE_SNPRINTF */
221
222 #if !defined(HAVE_TIMEGM) && defined(HAVE_TZSET) && defined(HAVE_PUTENV)
223 time_t timegm(struct tm *tm);
224 #endif /* !defined(HAVE_TIMEGM) && defined(HAVE_TZSET) && defined(HAVE_PUTENV) */
225
226 /* Here's looking at you, Ulrich. */
227 #if !defined(HAVE_STRLCPY)
228 size_t privoxy_strlcpy(char *destination, const char *source, size_t size);
229 #define strlcpy privoxy_strlcpy
230 #define USE_PRIVOXY_STRLCPY 1
231 #define HAVE_STRLCPY 1
232 #endif /* ndef HAVE_STRLCPY*/
233
234 #ifndef HAVE_STRLCAT
235 size_t privoxy_strlcat(char *destination, const char *source, size_t size);
236 #define strlcat privoxy_strlcat
237 #endif /* ndef HAVE_STRLCAT */
238
239 /* Revision control strings from this header and associated .c file */
240 extern const char miscutil_rcs[];
241 extern const char miscutil_h_rcs[];
242
243 #if defined(__cplusplus)
244 }
245 #endif
246
247 #endif /* ndef MISCUTIL_H_INCLUDED */
248
249 /*
250   Local Variables:
251   tab-width: 3
252   end:
253 */