Made failure to bind() a fatal error.
[privoxy.git] / project.h
1 #ifndef _PROJECT_H
2 #define _PROJECT_H
3 #define PROJECT_H_VERSION "$Id: project.h,v 1.2 2001/05/17 23:01:01 oes Exp $"
4 /*********************************************************************
5  *
6  * File        :  $Source: /cvsroot/ijbswa/current/project.h,v $
7  *
8  * Purpose     :  Defines data structures which are widely used in the
9  *                project.  Does not define any variables or functions
10  *                (though it does declare some macros).
11  *
12  * Copyright   :  Written by and Copyright (C) 2001 the SourceForge
13  *                IJBSWA team.  http://ijbswa.sourceforge.net
14  *
15  *                Based on the Internet Junkbuster originally written
16  *                by and Copyright (C) 1997 Anonymous Coders and 
17  *                Junkbusters Corporation.  http://www.junkbusters.com
18  *
19  *                This program is free software; you can redistribute it 
20  *                and/or modify it under the terms of the GNU General
21  *                Public License as published by the Free Software
22  *                Foundation; either version 2 of the License, or (at
23  *                your option) any later version.
24  *
25  *                This program is distributed in the hope that it will
26  *                be useful, but WITHOUT ANY WARRANTY; without even the
27  *                implied warranty of MERCHANTABILITY or FITNESS FOR A
28  *                PARTICULAR PURPOSE.  See the GNU General Public
29  *                License for more details.
30  *
31  *                The GNU General Public License should be included with
32  *                this file.  If not, you can view it at
33  *                http://www.gnu.org/copyleft/gpl.html
34  *                or write to the Free Software Foundation, Inc., 59
35  *                Temple Place - Suite 330, Boston, MA  02111-1307, USA.
36  *
37  * Revisions   :
38  *    $Log: project.h,v $
39  *    Revision 1.2  2001/05/17 23:01:01  oes
40  *     - Cleaned CRLF's from the sources and related files
41  *
42  *    Revision 1.1.1.1  2001/05/15 13:59:03  oes
43  *    Initial import of version 2.9.3 source tree
44  *
45  *
46  *********************************************************************/
47 \f
48
49 /* Declare struct FILE for vars and funcs. */
50 #include <stdio.h>
51
52 /* Need time_t for file_list */
53 #include <time.h>
54
55 /*
56  * Include appropriate regular expression libraries.
57  *
58  * PCRS           ==> Include pcre
59  * REGEX && PCRE  ==> Include pcre and pcreposix
60  * REGEX && !PCRE ==> Include gnu_regex
61  *
62  * STATIC  ==> Use  #include "pcre.h"  (compiling at same time)
63  * !STATIC ==> Use  #include <pcre.h>  (System library)
64  *
65  */
66 #if (defined(REGEX) && defined(PCRE)) || defined(PCRS)
67 #  ifdef STATIC
68 #    include "pcre.h"
69 #  else
70 #    include <pcre.h>
71 #  endif
72 #endif /* (defined(REGEX) && defined(PCRE)) || defined(PCRS) */
73
74 #if defined(REGEX) && defined(PCRE)
75 #  ifdef STATIC
76 #    include "pcreposix.h"
77 #  else
78 #    include <pcreposix.h>
79 #  endif
80 #endif /* defined(REGEX) && defined(PCRE) */
81
82 #if defined(REGEX) && !defined(PCRE)
83 #  include "gnu_regex.h"
84 #endif
85
86 #ifdef PCRS
87 #include "pcrs.h"
88 #endif /* def PCRS */
89
90 #ifdef AMIGA 
91 #include "amiga.h" 
92 #endif /* def AMIGA */
93
94 #ifdef __cplusplus
95 extern "C" {
96 #endif
97
98 #define FOREVER 1
99
100 /* Default IP and port to listen on */
101 #define HADDR_DEFAULT   "127.0.0.1"
102 #define HADDR_PORT      8000
103
104
105 /* Need this for struct gateway */
106 struct client_state;
107
108
109 struct http_request
110 {
111    char *cmd;
112    char *gpc;
113    char *host;
114    int   port;
115    char *path;
116    char *ver;
117    char *hostport; /* "host[:port]" */
118    int   ssl;
119 };
120
121
122 struct gateway
123 {
124    /* generic attributes */
125    char *name;
126    int (*conn)(const struct gateway *, struct http_request *, struct client_state *);
127    int   type;
128
129    /* domain specific attributes */
130    char *gateway_host;
131    int   gateway_port;
132
133    char *forward_host;
134    int   forward_port;
135 };
136
137
138 struct proxy_args
139 {
140    char *header;
141    char *invocation;
142    char *gateways;
143    char *trailer;
144 };
145
146
147 struct iob
148 {
149    char *buf;
150    char *cur;
151    char *eod;
152 };
153
154
155 struct list
156 {
157    char *str;
158    struct list *last;
159    struct list *next;
160 };
161
162 #define IOB_PEEK(CSP) ((CSP->iob->cur > CSP->iob->eod) ? (CSP->iob->eod - CSP->iob->cur) : 0)
163 #define IOB_RESET(CSP) if(CSP->iob->buf) free(CSP->iob->buf); memset(CSP->iob, '\0', sizeof(CSP->iob));
164
165
166 /* Constants defining bitmask for csp->accept_types */
167
168 #ifdef DETECT_MSIE_IMAGES
169
170 /* MSIE detected by user-agent string */
171 #define ACCEPT_TYPE_IS_MSIE     0x0001
172
173 /*
174  * *If* this is MSIE, it wants an image.  (Or this is a shift-reload, or
175  * it's got an image from this URL before...  yuck!)
176  * Only meaningful if ACCEPT_TYPE_IS_MSIE set 
177  */
178 #define ACCEPT_TYPE_MSIE_IMAGE  0x0002
179
180 /*
181  * *If* this is MSIE, it wants a HTML document.
182  * Only meaningful if ACCEPT_TYPE_IS_MSIE set
183  */
184 #define ACCEPT_TYPE_MSIE_HTML   0x0004
185
186 #endif /* def DETECT_MSIE_IMAGES */
187
188
189 struct client_state
190 {
191    int  permissions;\r
192    \r
193    int  cfd;
194    int  sfd;
195
196 #ifdef STATISTICS
197    /* 1 if this URL was rejected, 0 otherwise. Allows actual stats inc to 
198     * occur in main thread only for thread-safety. 
199     */
200    int  rejected;
201 #endif /* def STATISTICS */
202
203 #ifdef FORCE_LOAD
204    int force;
205 #endif /* def FORCE_LOAD */
206
207 #ifdef TOGGLE
208    /*
209     * by haroon - most of credit to srt19170
210     * We add an "on/off" toggle here that is used to effectively toggle
211     * the Junkbuster off or on
212     */
213    int   toggled_on;
214 #endif
215
216    char *ip_addr_str;
217    long  ip_addr_long;
218    char *referrer;
219
220 #if defined(DETECT_MSIE_IMAGES)
221    /* Types the client will accept.
222     * Bitmask - see ACCEPT_TYPE_XXX constants.
223     */
224    int accept_types;
225 #endif /* defined(DETECT_MSIE_IMAGES) */
226
227    const struct gateway *gw;
228    struct http_request http[1];
229
230    struct iob iob[1];
231
232    struct list headers[1];
233    struct list cookie_list[1];
234 #if defined(PCRS) || defined(KILLPOPUPS)
235    int is_text;
236 #endif /* defined(PCRS) || defined(KILLPOPUPS) */
237
238    char   *x_forwarded;
239
240    int active;
241
242    /* files associated with this client */
243    struct file_list *blist;   /* blockfile */
244    struct file_list *flist;   /* forwardfile */
245    struct file_list *permissions_list;\r
246 \r
247
248 #ifdef ACL_FILES\r
249    struct file_list *alist;   /* aclfile */
250 #endif /* def ACL_FILES */
251
252 #ifdef USE_IMAGE_LIST
253    struct file_list *ilist;   /* imagefile */
254 #endif /* def USE_IMAGE_LIST */
255 \r
256 #ifdef PCRS
257      struct file_list *rlist;   /* Perl re_filterfile */
258 #endif /* def PCRS */
259
260 #ifdef TRUST_FILES
261    struct file_list *tlist;   /* trustfile */
262 #endif /* def TRUST_FILES */
263 \r
264    struct client_state *next;
265 };
266
267
268 struct parsers
269 {
270    char *str;
271    char  len;
272    char *(*parser)(const struct parsers *, char *, struct client_state *);
273 };
274
275
276 struct interceptors
277 {
278    char *str;
279    char  len;
280    char *(*interceptor)(struct http_request *http, struct client_state *csp);
281 };
282
283
284 /* this allows the proxy to permit/block access to any host and/or path */
285
286 struct url_spec
287 {
288    char  *spec;
289    char  *domain;
290    char  *dbuf;
291    char **dvec;
292    int    dcnt;
293    int    toplevel;
294
295    char *path;
296    int   pathlen;
297    int   port;
298 #ifdef REGEX
299    regex_t *preg;
300 #endif
301 };
302
303
304 struct file_list
305 {
306    /*
307     * this is a pointer to the data structures associated with the file.
308     * Read-only once the structure has been created.
309     */
310    void *f;
311    
312    /* Normally NULL.  When we are finished with file (i.e. when we have
313     * loaded a new one), set to a pointer to an unloader function.
314     * Unloader will be called by sweep() (called from main loop) when
315     * all clients using this file are done.  This prevents threading 
316     * problems.
317     */
318    void (*unloader)(void *);
319
320    /* Used internally by sweep().  Do not access from elsewhere. */
321    int active;
322
323 #ifndef SPLIT_PROXY_ARGS
324    /* String to be displayed as part of show-proxy-args display.
325     * Read-only once the structure has been created.
326     */
327    char *proxy_args;
328 #endif /* ndef SPLIT_PROXY_ARGS */
329
330    /* Following variables allow us to check if file has been changed.
331     * Read-only once the structure has been created.
332     */
333    time_t lastmodified;
334    char * filename;
335
336    /* Pointer to next entry in the linked list of all "file_list"s.
337     * This linked list is so that sweep() can navigate it.
338     * Since sweep() can remove items from the list, we must be careful
339     * to only access this value from main thread (when we know sweep
340     * won't be running).
341     */
342    struct file_list *next;
343 };
344
345
346 struct block_spec
347 {
348    struct url_spec url[1];
349    int    reject;
350    struct block_spec *next;
351 };
352 \r
353
354 #define PERMIT_COOKIE_SET    0x0001\r
355 #define PERMIT_COOKIE_READ   0x0002\r
356 #define PERMIT_RE_FILTER     0x0004\r
357 #define PERMIT_POPUPS        0x0008\r
358
359 struct permissions_spec\r
360 {\r
361    struct url_spec           url[1];\r
362    int                       permissions;\r
363    struct permissions_spec * next;\r
364 };\r
365 \r
366 struct forward_spec
367 {
368    struct url_spec url[1];
369    int   reject;
370    struct gateway gw[1];
371    struct forward_spec *next;
372 };
373
374
375 #ifdef PCRS
376 struct re_filterfile_spec
377 {
378    struct list patterns[1];
379    /* See README.re_filter */
380    pcrs_job *joblist;
381 };
382 #endif /* def PCRS */
383 \r
384
385 #ifdef ACL_FILES
386 #define ACL_PERMIT   1  /* accept connection request */
387 #define ACL_DENY     2  /* reject connection request */
388
389 struct access_control_addr
390 {
391    unsigned long addr;
392    unsigned long mask;
393    unsigned long port;
394 };
395
396 struct access_control_list
397 {
398    struct access_control_addr src[1];
399    struct access_control_addr dst[1];
400
401    short action;
402    struct access_control_list *next;
403 };
404 #endif /* def ACL_FILES */
405
406 #define SZ(X)  (sizeof(X) / sizeof(*X))
407
408 #define WHITEBG   "<body bgcolor=\"#ffffff\" link=\"#000078\" alink=\"#ff0022\" vlink=\"#787878\">\n"
409 #define BODY      "<body bgcolor=\"#f8f8f0\" link=\"#000078\" alink=\"#ff0022\" vlink=\"#787878\">\n"
410 #define BANNER    "<strong>Internet J<small>UNK<i><font color=\"red\">BUSTER</font></i></small></strong>"
411
412 #ifdef FORCE_LOAD
413 /*
414  * FIXME: Unfortunately, IE lowercases the domain name.  JunkBuster does
415  * a case-sensitive compare.  JunkBuster should be modified to do a
416  * case-insensitive compatison.  As a temporary workaround, I've lowercased
417  * the FORCE_PREFIX.
418  *
419  * #define FORCE_PREFIX "IJB-FORCE-LOAD-"
420  */
421 #define FORCE_PREFIX "ijb-force-load-"
422 #endif /* def FORCE_LOAD */
423
424 #define HOME_PAGE_URL  "http://ijbswa.sourceforge.net/"
425 #define REDIRECT_URL HOME_PAGE_URL "redirect.php?v=" VERSION "&to="
426
427 #ifdef __cplusplus
428 } /* extern "C" */
429 #endif
430
431 #endif /* ndef _PROJECT_H */
432
433 /*
434   Local Variables:
435   tab-width: 3
436   end:
437 */