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