allow lads.myspacecdn.com
[privoxy.git] / jcc.h
1 #ifndef JCC_H_INCLUDED
2 #define JCC_H_INCLUDED
3 #define JCC_H_VERSION "$Id: jcc.h,v 1.24 2008/09/07 12:35:05 fabiankeil Exp $"
4 /*********************************************************************
5  *
6  * File        :  $Source: /cvsroot/ijbswa/current/jcc.h,v $
7  *
8  * Purpose     :  Main file.  Contains main() method, main loop, and 
9  *                the main connection-handling function.
10  *
11  * Copyright   :  Written by and Copyright (C) 2001-2006 the SourceForge
12  *                Privoxy team. http://www.privoxy.org/
13  *
14  *                Based on the Internet Junkbuster originally written
15  *                by and Copyright (C) 1997 Anonymous Coders and 
16  *                Junkbusters Corporation.  http://www.junkbusters.com
17  *
18  *                This program is free software; you can redistribute it 
19  *                and/or modify it under the terms of the GNU General
20  *                Public License as published by the Free Software
21  *                Foundation; either version 2 of the License, or (at
22  *                your option) any later version.
23  *
24  *                This program is distributed in the hope that it will
25  *                be useful, but WITHOUT ANY WARRANTY; without even the
26  *                implied warranty of MERCHANTABILITY or FITNESS FOR A
27  *                PARTICULAR PURPOSE.  See the GNU General Public
28  *                License for more details.
29  *
30  *                The GNU General Public License should be included with
31  *                this file.  If not, you can view it at
32  *                http://www.gnu.org/copyleft/gpl.html
33  *                or write to the Free Software Foundation, Inc., 59
34  *                Temple Place - Suite 330, Boston, MA  02111-1307, USA.
35  *
36  * Revisions   :
37  *    $Log: jcc.h,v $
38  *    Revision 1.24  2008/09/07 12:35:05  fabiankeil
39  *    Add mutex lock support for _WIN32.
40  *
41  *    Revision 1.23  2008/09/04 08:13:58  fabiankeil
42  *    Prepare for critical sections on Windows by adding a
43  *    layer of indirection before the pthread mutex functions.
44  *
45  *    Revision 1.22  2007/06/01 18:16:36  fabiankeil
46  *    Use the same mutex for gethostbyname() and gethostbyaddr() to prevent
47  *    deadlocks and crashes on OpenBSD and possibly other OS with neither
48  *    gethostbyname_r() nor gethostaddr_r(). Closes BR#1729174.
49  *    Thanks to Ralf Horstmann for report and solution.
50  *
51  *    Revision 1.21  2007/04/22 13:18:06  fabiankeil
52  *    Keep the HTTP snippets local.
53  *
54  *    Revision 1.20  2006/12/26 17:31:41  fabiankeil
55  *    Mutex protect rand() if POSIX threading
56  *    is used, warn the user if that's not possible
57  *    and stop using it on _WIN32 where it could
58  *    cause crashes.
59  *
60  *    Revision 1.19  2006/12/06 19:41:39  fabiankeil
61  *    Privoxy is now able to run as intercepting
62  *    proxy in combination with any packet filter
63  *    that does the port redirection. The destination
64  *    is extracted from the "Host:" header which
65  *    should be available for nearly all requests.
66  *
67  *    Moved HTTP snipplets into jcc.c.
68  *    Added error message for gopher proxy requests.
69  *
70  *    Revision 1.18  2006/11/13 19:05:51  fabiankeil
71  *    Make pthread mutex locking more generic. Instead of
72  *    checking for OSX and OpenBSD, check for FEATURE_PTHREAD
73  *    and use mutex locking unless there is an _r function
74  *    available. Better safe than sorry.
75  *
76  *    Fixes "./configure --disable-pthread" and should result
77  *    in less threading-related problems on pthread-using platforms,
78  *    but it still doesn't fix BR#1122404.
79  *
80  *    Revision 1.17  2006/11/06 19:58:23  fabiankeil
81  *    Move pthread.h inclusion from jcc.c to jcc.h.
82  *    Fixes build on x86-freebsd1 (FreeBSD 5.4-RELEASE).
83  *
84  *    Revision 1.16  2006/09/02 15:36:42  fabiankeil
85  *    Follow the OpenBSD port's lead and protect the resolve
86  *    functions on OpenBSD as well.
87  *
88  *    Revision 1.15  2006/09/02 10:24:30  fabiankeil
89  *    Include pthread.h for OpenBSD to make Privoxy build again.
90  *
91  *    Tested shortly on OpenBSD 3.9 without problems, but the OpenBSD
92  *    port has additional patches to use the mutexes OSX_DARWIN needs,
93  *    and it should be investigated if they are still required for
94  *    reliable operation.
95  *
96  *    Revision 1.14  2006/07/18 14:48:46  david__schmidt
97  *    Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
98  *    with what was really the latest development (the v_3_0_branch branch)
99  *
100  *    Revision 1.12.2.3  2006/01/21 16:16:08  david__schmidt
101  *    Thanks to  Edward Carrel for his patch to modernize OSX's\rpthreads support.  See bug #1409623.
102  *
103  *    Revision 1.12.2.2  2005/04/03 20:10:50  david__schmidt
104  *    Thanks to Jindrich Makovicka for a race condition fix for the log
105  *    file.  The race condition remains for non-pthread implementations.
106  *    Reference patch #1175720.
107  *
108  *    Revision 1.12.2.1  2003/03/07 03:41:05  david__schmidt
109  *    Wrapping all *_r functions (the non-_r versions of them) with mutex 
110  *    semaphores for OSX.  Hopefully this will take care of all of those pesky
111  *    crash reports.
112  *
113  *    Revision 1.12  2002/03/26 22:29:55  swa
114  *    we have a new homepage!
115  *
116  *    Revision 1.11  2002/03/24 13:25:43  swa
117  *    name change related issues
118  *
119  *    Revision 1.10  2002/03/16 23:54:06  jongfoster
120  *    Adding graceful termination feature, to help look for memory leaks.
121  *    If you enable this (which, by design, has to be done by hand
122  *    editing config.h) and then go to http://i.j.b/die, then the program
123  *    will exit cleanly after the *next* request.  It should free all the
124  *    memory that was used.
125  *
126  *    Revision 1.9  2002/03/07 03:52:44  oes
127  *    Set logging to tty for --no-daemon mode
128  *
129  *    Revision 1.8  2002/03/04 18:19:49  oes
130  *    Added extern const char *pidfile
131  *
132  *    Revision 1.7  2001/11/05 21:41:43  steudten
133  *    Add changes to be a real daemon just for unix os.
134  *    (change cwd to /, detach from controlling tty, set
135  *    process group and session leader to the own process.
136  *    Add DBG() Macro.
137  *    Add some fatal-error log message for failed malloc().
138  *    Add '-d' if compiled with 'configure --with-debug' to
139  *    enable debug output.
140  *
141  *    Revision 1.6  2001/07/30 22:08:36  jongfoster
142  *    Tidying up #defines:
143  *    - All feature #defines are now of the form FEATURE_xxx
144  *    - Permanently turned off WIN_GUI_EDIT
145  *    - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
146  *
147  *    Revision 1.5  2001/07/29 19:32:00  jongfoster
148  *    Renaming _main() [mingw32 only] to real_main(), for ANSI compliance.
149  *
150  *    Revision 1.4  2001/07/29 18:58:15  jongfoster
151  *    Removing nested #includes, adding forward declarations for needed
152  *    structures, and changing the #define _FILENAME_H to FILENAME_H_INCLUDED.
153  *
154  *    Revision 1.3  2001/07/18 12:31:58  oes
155  *    moved #define freez from jcc.h to project.h
156  *
157  *    Revision 1.2  2001/05/31 21:24:47  jongfoster
158  *    Changed "permission" to "action" throughout.
159  *    Removed DEFAULT_USER_AGENT - it must now be specified manually.
160  *    Moved vanilla wafer check into chat(), since we must now
161  *    decide whether or not to add it based on the URL.
162  *
163  *    Revision 1.1.1.1  2001/05/15 13:58:56  oes
164  *    Initial import of version 2.9.3 source tree
165  *
166  *
167  *********************************************************************/
168 \f
169
170 #ifdef __cplusplus
171 extern "C" {
172 #endif
173
174 struct client_state;
175 struct file_list;
176
177 /* Global variables */
178
179 #ifdef FEATURE_STATISTICS
180 extern int urls_read;
181 extern int urls_rejected;
182 #endif /*def FEATURE_STATISTICS*/
183
184 extern struct client_state clients[1];
185 extern struct file_list    files[1];
186
187 #ifdef unix
188 extern const char *pidfile;
189 #endif
190 extern int no_daemon;
191
192 #ifdef FEATURE_GRACEFUL_TERMINATION
193 extern int g_terminate;
194 #endif
195
196 #if defined(FEATURE_PTHREAD) || defined(_WIN32)
197 #define MUTEX_LOCKS_AVAILABLE
198
199 #ifdef FEATURE_PTHREAD
200 #include <pthread.h>
201
202 typedef pthread_mutex_t privoxy_mutex_t;
203
204 #else
205
206 typedef CRITICAL_SECTION privoxy_mutex_t;
207
208 #endif
209
210 extern void privoxy_mutex_lock(privoxy_mutex_t *mutex);
211 extern void privoxy_mutex_unlock(privoxy_mutex_t *mutex);
212
213 extern privoxy_mutex_t log_mutex;
214 extern privoxy_mutex_t log_init_mutex;
215 extern privoxy_mutex_t connection_reuse_mutex;
216
217 #ifndef HAVE_GMTIME_R
218 extern privoxy_mutex_t gmtime_mutex;
219 #endif /* ndef HAVE_GMTIME_R */
220
221 #ifndef HAVE_LOCALTIME_R
222 extern privoxy_mutex_t localtime_mutex;
223 #endif /* ndef HAVE_GMTIME_R */
224
225 #if !defined(HAVE_GETHOSTBYADDR_R) || !defined(HAVE_GETHOSTBYNAME_R)
226 extern privoxy_mutex_t resolver_mutex;
227 #endif /* !defined(HAVE_GETHOSTBYADDR_R) || !defined(HAVE_GETHOSTBYNAME_R) */
228
229 #ifndef HAVE_RANDOM
230 extern privoxy_mutex_t rand_mutex;
231 #endif /* ndef HAVE_RANDOM */
232
233 #endif /* FEATURE_PTHREAD */
234
235 /* Functions */
236
237 #ifdef __MINGW32__
238 int real_main(int argc, const char *argv[]);
239 #else
240 int main(int argc, const char *argv[]);
241 #endif
242
243 /* Revision control strings from this header and associated .c file */
244 extern const char jcc_rcs[];
245 extern const char jcc_h_rcs[];
246
247 #ifdef __cplusplus
248 } /* extern "C" */
249 #endif
250
251 #endif /* ndef JCC_H_INCLUDED */
252
253 /*
254   Local Variables:
255   tab-width: 3
256   end:
257 */