- Cleaned CRLF's from the sources and related files
[privoxy.git] / project.h
1 #ifndef _PROJECT_H
2 #define _PROJECT_H
3 #define PROJECT_H_VERSION "$Id: project.h,v 1.1.1.1 2001/05/15 13:59:03 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.1.1.1  2001/05/15 13:59:03  oes
40  *    Initial import of version 2.9.3 source tree
41  *
42  *
43  *********************************************************************/
44 \f
45
46 /* Declare struct FILE for vars and funcs. */
47 #include <stdio.h>
48
49 /* Need time_t for file_list */
50 #include <time.h>
51
52 /*
53  * Include appropriate regular expression libraries.
54  *
55  * PCRS           ==> Include pcre
56  * REGEX && PCRE  ==> Include pcre and pcreposix
57  * REGEX && !PCRE ==> Include gnu_regex
58  *
59  * STATIC  ==> Use  #include "pcre.h"  (compiling at same time)
60  * !STATIC ==> Use  #include <pcre.h>  (System library)
61  *
62  */
63 #if (defined(REGEX) && defined(PCRE)) || defined(PCRS)
64 #  ifdef STATIC
65 #    include "pcre.h"
66 #  else
67 #    include <pcre.h>
68 #  endif
69 #endif /* (defined(REGEX) && defined(PCRE)) || defined(PCRS) */
70
71 #if defined(REGEX) && defined(PCRE)
72 #  ifdef STATIC
73 #    include "pcreposix.h"
74 #  else
75 #    include <pcreposix.h>
76 #  endif
77 #endif /* defined(REGEX) && defined(PCRE) */
78
79 #if defined(REGEX) && !defined(PCRE)
80 #  include "gnu_regex.h"
81 #endif
82
83 #ifdef PCRS
84 #include "pcrs.h"
85 #endif /* def PCRS */
86
87 #ifdef AMIGA 
88 #include "amiga.h" 
89 #endif /* def AMIGA */
90
91 #ifdef __cplusplus
92 extern "C" {
93 #endif
94
95 #define FOREVER 1
96
97 /* Default IP and port to listen on */
98 #define HADDR_DEFAULT   "127.0.0.1"
99 #define HADDR_PORT      8000
100
101
102 /* Need this for struct gateway */
103 struct client_state;
104
105
106 struct http_request
107 {
108    char *cmd;
109    char *gpc;
110    char *host;
111    int   port;
112    char *path;
113    char *ver;
114    char *hostport; /* "host[:port]" */
115    int   ssl;
116 };
117
118
119 struct gateway
120 {
121    /* generic attributes */
122    char *name;
123    int (*conn)(const struct gateway *, struct http_request *, struct client_state *);
124    int   type;
125
126    /* domain specific attributes */
127    char *gateway_host;
128    int   gateway_port;
129
130    char *forward_host;
131    int   forward_port;
132 };
133
134
135 struct proxy_args
136 {
137    char *header;
138    char *invocation;
139    char *gateways;
140    char *trailer;
141 };
142
143
144 struct iob
145 {
146    char *buf;
147    char *cur;
148    char *eod;
149 };
150
151
152 struct list
153 {
154    char *str;
155    struct list *last;
156    struct list *next;
157 };
158
159 #define IOB_PEEK(CSP) ((CSP->iob->cur > CSP->iob->eod) ? (CSP->iob->eod - CSP->iob->cur) : 0)
160 #define IOB_RESET(CSP) if(CSP->iob->buf) free(CSP->iob->buf); memset(CSP->iob, '\0', sizeof(CSP->iob));
161
162
163 /* Constants defining bitmask for csp->accept_types */
164
165 #ifdef DETECT_MSIE_IMAGES
166
167 /* MSIE detected by user-agent string */
168 #define ACCEPT_TYPE_IS_MSIE     0x0001
169
170 /*
171  * *If* this is MSIE, it wants an image.  (Or this is a shift-reload, or
172  * it's got an image from this URL before...  yuck!)
173  * Only meaningful if ACCEPT_TYPE_IS_MSIE set 
174  */
175 #define ACCEPT_TYPE_MSIE_IMAGE  0x0002
176
177 /*
178  * *If* this is MSIE, it wants a HTML document.
179  * Only meaningful if ACCEPT_TYPE_IS_MSIE set
180  */
181 #define ACCEPT_TYPE_MSIE_HTML   0x0004
182
183 #endif /* def DETECT_MSIE_IMAGES */
184
185
186 struct client_state
187 {
188    int  send_user_cookie;
189    int  accept_server_cookie;
190    int  cfd;
191    int  sfd;
192
193 #ifdef STATISTICS
194    /* 1 if this URL was rejected, 0 otherwise. Allows actual stats inc to 
195     * occur in main thread only for thread-safety. 
196     */
197    int  rejected;
198 #endif /* def STATISTICS */
199
200 #ifdef FORCE_LOAD
201    int force;
202 #endif /* def FORCE_LOAD */
203
204 #ifdef TOGGLE
205    /*
206     * by haroon - most of credit to srt19170
207     * We add an "on/off" toggle here that is used to effectively toggle
208     * the Junkbuster off or on
209     */
210    int   toggled_on;
211 #endif
212
213    char *ip_addr_str;
214    long  ip_addr_long;
215    char *referrer;
216
217 #if defined(DETECT_MSIE_IMAGES)
218    /* Types the client will accept.
219     * Bitmask - see ACCEPT_TYPE_XXX constants.
220     */
221    int accept_types;
222 #endif /* defined(DETECT_MSIE_IMAGES) */
223
224    const struct gateway *gw;
225    struct http_request http[1];
226
227    struct iob iob[1];
228
229    struct list headers[1];
230    struct list cookie_list[1];
231 #ifdef PCRS
232    int is_text;
233 #endif /* def PCRS */
234
235    char   *x_forwarded;
236
237    int active;
238
239    /* files associated with this client */
240    struct file_list *blist;   /* blockfile */
241    struct file_list *clist;   /* cookiefile */
242    struct file_list *flist;   /* forwardfile */
243
244 #ifdef ACL_FILES
245    struct file_list *alist;   /* aclfile */
246 #endif /* def ACL_FILES */
247
248 #ifdef USE_IMAGE_LIST
249    struct file_list *ilist;   /* imagefile */
250 #endif /* def USE_IMAGE_LIST */
251
252 #ifdef KILLPOPUPS
253    struct file_list *plist;   /* kill popup file */
254 #endif /* def KILLPOPUPS */
255
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
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
353
354 struct cookie_spec
355 {
356    struct url_spec url[1];
357    int   send_user_cookie;
358    int   accept_server_cookie;
359    struct cookie_spec *next;
360 };
361
362
363 struct forward_spec
364 {
365    struct url_spec url[1];
366    int   reject;
367    struct gateway gw[1];
368    struct forward_spec *next;
369 };
370
371
372 #ifdef PCRS
373 struct re_filterfile_spec
374 {
375    struct list patterns[1];
376    /* See README.re_filter */
377    pcrs_job *joblist;
378 };
379 #endif /* def PCRS */
380
381
382 #ifdef KILLPOPUPS
383 /* Entries on popup blocklist */
384 struct popup_blocklist
385 {
386    char *host_name;
387    struct popup_blocklist *next;
388 };
389
390 /* Actual type used in file object */
391 struct popup_settings
392 {
393    struct popup_blocklist *blocked;
394    struct popup_blocklist *allowed;
395 };
396 #endif /* def KILLPOPUPS */
397
398 #ifdef ACL_FILES
399 #define ACL_PERMIT   1  /* accept connection request */
400 #define ACL_DENY     2  /* reject connection request */
401
402 struct access_control_addr
403 {
404    unsigned long addr;
405    unsigned long mask;
406    unsigned long port;
407 };
408
409 struct access_control_list
410 {
411    struct access_control_addr src[1];
412    struct access_control_addr dst[1];
413
414    short action;
415    struct access_control_list *next;
416 };
417 #endif /* def ACL_FILES */
418
419 #define SZ(X)  (sizeof(X) / sizeof(*X))
420
421 #define WHITEBG   "<body bgcolor=\"#ffffff\" link=\"#000078\" alink=\"#ff0022\" vlink=\"#787878\">\n"
422 #define BODY      "<body bgcolor=\"#f8f8f0\" link=\"#000078\" alink=\"#ff0022\" vlink=\"#787878\">\n"
423 #define BANNER    "<strong>Internet J<small>UNK<i><font color=\"red\">BUSTER</font></i></small></strong>"
424
425 #ifdef FORCE_LOAD
426 /*
427  * FIXME: Unfortunately, IE lowercases the domain name.  JunkBuster does
428  * a case-sensitive compare.  JunkBuster should be modified to do a
429  * case-insensitive compatison.  As a temporary workaround, I've lowercased
430  * the FORCE_PREFIX.
431  *
432  * #define FORCE_PREFIX "IJB-FORCE-LOAD-"
433  */
434 #define FORCE_PREFIX "ijb-force-load-"
435 #endif /* def FORCE_LOAD */
436
437 #define HOME_PAGE_URL  "http://ijbswa.sourceforge.net/"
438 #define REDIRECT_URL HOME_PAGE_URL "redirect.php?v=" VERSION "&to="
439
440 #ifdef __cplusplus
441 } /* extern "C" */
442 #endif
443
444 #endif /* ndef _PROJECT_H */
445
446 /*
447   Local Variables:
448   tab-width: 3
449   end:
450 */