Added filter to replace "Nimda" code by a warning.
[privoxy.git] / project.h
1 #ifndef PROJECT_H_INCLUDED
2 #define PROJECT_H_INCLUDED
3 #define PROJECT_H_VERSION "$Id: project.h,v 1.32 2001/09/16 23:02:51 jongfoster 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.32  2001/09/16 23:02:51  jongfoster
40  *    Fixing warning
41  *
42  *    Revision 1.31  2001/09/16 13:20:29  jongfoster
43  *    Rewrite of list library.  Now has seperate header and list_entry
44  *    structures.  Also added a large sprinking of assert()s to the list
45  *    code.
46  *
47  *    Revision 1.30  2001/09/13 23:52:00  jongfoster
48  *    Support for both static and dynamically generated CGI pages
49  *
50  *    Revision 1.29  2001/09/13 23:29:43  jongfoster
51  *    Defining FORWARD_SPEC_INITIALIZER
52  *
53  *    Revision 1.28  2001/09/13 23:05:50  jongfoster
54  *    Changing the string paramater to the header parsers a "const".
55  *
56  *    Revision 1.27  2001/08/05 16:06:20  jongfoster
57  *    Modifiying "struct map" so that there are now separate header and
58  *    "map_entry" structures.  This means that functions which modify a
59  *    map no longer need to return a pointer to the modified map.
60  *    Also, it no longer reverses the order of the entries (which may be
61  *    important with some advanced template substitutions).
62  *
63  *    Revision 1.26  2001/07/30 22:08:36  jongfoster
64  *    Tidying up #defines:
65  *    - All feature #defines are now of the form FEATURE_xxx
66  *    - Permanently turned off WIN_GUI_EDIT
67  *    - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
68  *
69  *    Revision 1.25  2001/07/29 18:43:08  jongfoster
70  *    Changing #ifdef _FILENAME_H to FILENAME_H_INCLUDED, to conform to
71  *    ANSI C rules.
72  *
73  *    Revision 1.24  2001/07/25 17:20:27  oes
74  *    Introduced http->user_agent
75  *
76  *    Revision 1.23  2001/07/18 12:32:23  oes
77  *    - Added ACTION_STRING_DEANIMATE
78  *    - moved #define freez from jcc.h to project.h
79  *
80  *    Revision 1.22  2001/07/15 17:51:41  jongfoster
81  *    Renaming #define STATIC to STATIC_PCRE
82  *
83  *    Revision 1.21  2001/07/13 14:03:19  oes
84  *     - Reorganized regex header inclusion and #defines to
85  *       comply to the scheme in configure.in
86  *     - Added csp->content_type and its CT_* keys
87  *     - Added ACTION_DEANIMATE
88  *     - Removed all #ifdef PCRS
89  *
90  *    Revision 1.20  2001/06/29 21:45:41  oes
91  *    Indentation, CRLF->LF, Tab-> Space
92  *
93  *    Revision 1.19  2001/06/29 13:33:36  oes
94  *    - Improved comments
95  *    - Introduced http_request.host_ip_addr_str
96  *    - Introduced http_response.head_length
97  *    - Introduced config.my_ip_addr_str, config.my_hostname,
98  *      config.admin_address and config.proxy_info_url
99  *    - Removed config.proxy_args_header and config.proxy_args_trailer,
100  *      renamed config.proxy_args_invocation to config.proxy_args
101  *    - Removed HTML snipplets and GIFs
102  *    - Removed logentry from cancelled commit
103  *
104  *    Revision 1.18  2001/06/09 10:57:39  jongfoster
105  *    Adding definition of BUFFER_SIZE.
106  *    Changing struct cgi_dispatcher to use "const" strings.
107  *
108  *    Revision 1.17  2001/06/07 23:15:09  jongfoster
109  *    Merging ACL and forward files into config file.
110  *    Moving struct gateway members into struct forward_spec
111  *    Removing config->proxy_args_gateways
112  *    Cosmetic: Adding a few comments
113  *
114  *    Revision 1.16  2001/06/04 18:31:58  swa
115  *    files are now prefixed with either `confdir' or `logdir'.
116  *    `make redhat-dist' replaces both entries confdir and logdir
117  *    with redhat values
118  *
119  *    Revision 1.15  2001/06/04 11:28:53  swa
120  *    redirect did not work due to missing /
121  *
122  *    Revision 1.14  2001/06/03 11:03:48  oes
123  *    Added struct map,
124  *    added struct http_response,
125  *    changed struct interceptors to struct cgi_dispatcher,
126  *    moved HTML stuff to cgi.h
127  *
128  *    Revision 1.13  2001/06/01 20:05:36  jongfoster
129  *    Support for +image-blocker{}: added ACTION_IMAGE_BLOCKER
130  *    constant, and removed csp->tinygif.
131  *
132  *    Revision 1.12  2001/06/01 18:49:17  jongfoster
133  *    Replaced "list_share" with "list" - the tiny memory gain was not
134  *    worth the extra complexity.
135  *
136  *    Revision 1.11  2001/06/01 10:32:47  oes
137  *    Added constants for anchoring selection bitmap
138  *
139  *    Revision 1.10  2001/05/31 21:33:53  jongfoster
140  *    Changes for new actions file, replacing permissionsfile
141  *    and parts of the config file.  Also added support for
142  *    list_shared.
143  *
144  *    Revision 1.9  2001/05/31 17:32:31  oes
145  *
146  *     - Enhanced domain part globbing with infix and prefix asterisk
147  *       matching and optional unanchored operation
148  *
149  *    Revision 1.8  2001/05/29 20:09:15  joergs
150  *    HTTP_REDIRECT_TEMPLATE fixed.
151  *
152  *    Revision 1.7  2001/05/29 09:50:24  jongfoster
153  *    Unified blocklist/imagelist/actionslist.
154  *    File format is still under discussion, but the internal changes
155  *    are (mostly) done.
156  *
157  *    Also modified interceptor behaviour:
158  *    - We now intercept all URLs beginning with one of the following
159  *      prefixes (and *only* these prefixes):
160  *        * http://i.j.b/
161  *        * http://ijbswa.sf.net/config/
162  *        * http://ijbswa.sourceforge.net/config/
163  *    - New interceptors "home page" - go to http://i.j.b/ to see it.
164  *    - Internal changes so that intercepted and fast redirect pages
165  *      are not replaced with an image.
166  *    - Interceptors now have the option to send a binary page direct
167  *      to the client. (i.e. ijb-send-banner uses this)
168  *    - Implemented show-url-info interceptor.  (Which is why I needed
169  *      the above interceptors changes - a typical URL is
170  *      "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
171  *      The previous mechanism would not have intercepted that, and
172  *      if it had been intercepted then it then it would have replaced
173  *      it with an image.)
174  *
175  *    Revision 1.6  2001/05/27 22:17:04  oes
176  *
177  *    - re_process_buffer no longer writes the modified buffer
178  *      to the client, which was very ugly. It now returns the
179  *      buffer, which it is then written by chat.
180  *
181  *    - content_length now adjusts the Content-Length: header
182  *      for modified documents rather than crunch()ing it.
183  *      (Length info in csp->content_length, which is 0 for
184  *      unmodified documents)
185  *
186  *    - For this to work, sed() is called twice when filtering.
187  *
188  *    Revision 1.5  2001/05/26 00:28:36  jongfoster
189  *    Automatic reloading of config file.
190  *    Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
191  *    Most of the global variables have been moved to a new
192  *    struct configuration_spec, accessed through csp->config->globalname
193  *    Most of the globals remaining are used by the Win32 GUI.
194  *
195  *    Revision 1.4  2001/05/22 18:46:04  oes
196  *
197  *    - Enabled filtering banners by size rather than URL
198  *      by adding patterns that replace all standard banner
199  *      sizes with the "Junkbuster" gif to the re_filterfile
200  *
201  *    - Enabled filtering WebBugs by providing a pattern
202  *      which kills all 1x1 images
203  *
204  *    - Added support for PCRE_UNGREEDY behaviour to pcrs,
205  *      which is selected by the (nonstandard and therefore
206  *      capital) letter 'U' in the option string.
207  *      It causes the quantifiers to be ungreedy by default.
208  *      Appending a ? turns back to greedy (!).
209  *
210  *    - Added a new interceptor ijb-send-banner, which
211  *      sends back the "Junkbuster" gif. Without imagelist or
212  *      MSIE detection support, or if tinygif = 1, or the
213  *      URL isn't recognized as an imageurl, a lame HTML
214  *      explanation is sent instead.
215  *
216  *    - Added new feature, which permits blocking remote
217  *      script redirects and firing back a local redirect
218  *      to the browser.
219  *      The feature is conditionally compiled, i.e. it
220  *      can be disabled with --disable-fast-redirects,
221  *      plus it must be activated by a "fast-redirects"
222  *      line in the config file, has its own log level
223  *      and of course wants to be displayed by show-proxy-args
224  *      Note: Boy, all the #ifdefs in 1001 locations and
225  *      all the fumbling with configure.in and acconfig.h
226  *      were *way* more work than the feature itself :-(
227  *
228  *    - Because a generic redirect template was needed for
229  *      this, tinygif = 3 now uses the same.
230  *
231  *    - Moved GIFs, and other static HTTP response templates
232  *      to project.h
233  *
234  *    - Some minor fixes
235  *
236  *    - Removed some >400 CRs again (Jon, you really worked
237  *      a lot! ;-)
238  *
239  *    Revision 1.3  2001/05/20 01:21:20  jongfoster
240  *    Version 2.9.4 checkin.
241  *    - Merged popupfile and cookiefile, and added control over PCRS
242  *      filtering, in new "actionsfile".
243  *    - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
244  *      file error you now get a message box (in the Win32 GUI) rather
245  *      than the program exiting with no explanation.
246  *    - Made killpopup use the PCRS MIME-type checking and HTTP-header
247  *      skipping.
248  *    - Removed tabs from "config"
249  *    - Moved duplicated url parsing code in "loaders.c" to a new funcition.
250  *    - Bumped up version number.
251  *
252  *    Revision 1.2  2001/05/17 23:01:01  oes
253  *     - Cleaned CRLF's from the sources and related files
254  *
255  *    Revision 1.1.1.1  2001/05/15 13:59:03  oes
256  *    Initial import of version 2.9.3 source tree
257  *
258  *
259  *********************************************************************/
260 \f
261
262 /* Declare struct FILE for vars and funcs. */
263 #include <stdio.h>
264
265 /* Need time_t for file_list */
266 #include <time.h>
267
268 /*
269  * Include appropriate regular expression libraries.
270  * Note that pcrs and pcre (native) are needed for cgi
271  * and are included anyway.
272  */
273
274 #if defined(REGEX_PCRE) || defined (REGEX_GNU)
275 # define REGEX
276 #endif /* defined(REGEX_PCRE) || defined (REGEX_GNU) */
277
278 #ifdef STATIC_PCRE
279 #  include "pcre.h"
280 #else
281 #  include <pcre.h>
282 #endif
283
284 #ifdef STATIC_PCRS
285 #  include "pcrs.h" 
286 #else
287 #  include <pcrs.h> 
288 #endif
289
290 #if defined(REGEX_PCRE)
291 #  ifdef STATIC_PCRE
292 #    include "pcreposix.h"
293 #  else
294 #    include <pcreposix.h>
295 #  endif
296 #endif /* defined(REGEX_PCRE) */
297
298 #if defined(REGEX_GNU)
299 #  include "gnu_regex.h"
300 #endif
301
302 #ifdef AMIGA 
303 #include "amiga.h" 
304 #endif /* def AMIGA */
305
306 #ifdef __cplusplus
307 extern "C" {
308 #endif
309
310 #define freez(X)  { if(X) { free(X); X = NULL ; } }
311
312 #define BUFFER_SIZE 5000
313
314 #define FOREVER 1
315
316 /* Default IP and port to listen on */
317 #define HADDR_DEFAULT   "127.0.0.1"
318 #define HADDR_PORT      8000
319
320
321 /* Forward defs for various structures */
322
323 /* Need this for struct client_state */
324 struct configuration_spec;
325
326
327 /* Generic linked list of strings */
328
329 struct list_entry
330 {
331    const char *str;
332    struct list_entry *next;
333 };
334
335 struct list
336 {
337    struct list_entry *first;
338    struct list_entry *last;
339 };
340
341
342 /* A map from a string to another string */
343
344 struct map_entry
345 {
346    const char *name;
347    const char *value;
348    struct map_entry *next;
349 };
350
351 struct map
352 {
353    struct map_entry *first;
354    struct map_entry *last;
355 };
356
357
358 struct http_request
359 {
360    char *cmd;
361    char *gpc;
362    char *host;
363    char *host_ip_addr_str; /* NULL before connect_to() */
364    int   port;
365    char *path;
366    char *ver;
367    char *hostport; /* "host[:port]" */
368    int   ssl;
369    char *user_agent; /* Client's User-Agent: header value */
370 };
371
372 /* Response generated by CGI, blocker, or error handler */
373 struct http_response
374 {
375   char *status;           /* HTTP status (string)*/
376   struct list headers[1]; /* List of header lines */
377   char *head;             /* Formatted http response head */
378   int   head_length;      /* Length of http response head */
379   char *body;             /* HTTP document body */
380   int   content_length;   /* Length of body, REQUIRED if binary body */
381   int   is_static;        /* Nonzero if the content will never change and
382                            * should be cached by the broser (e.g. images) */
383 };
384
385 /* A URL pattern */
386 struct url_spec
387 {
388    char  *spec;        /* The string which was parsed to produce this       */
389                        /* url_spec.  Used for debugging or display only.    */
390
391    /* Hostname matching: */
392    char  *domain;      /* Fully qalified domain name (FQDN) pattern.        */
393                        /* May contain "*".                                  */
394    char  *dbuf;        /* Buffer with '\0'-delimited fqdn                   */
395    char **dvec;        /* Domain ptr vector into dbuf                       */
396    int    dcnt;        /* How many domains in fqdn?                         */
397    int    unanchored;  /* Bitmap - flags are ANCHOR_LEFT and ANCHOR_RIGHT   */
398
399    /* Port matching: */
400    int   port;         /* The port number, or 0 to match all ports.         */
401
402    /* Path matching: */
403    char *path;         /* The path prefix (if not using regex), or source   */
404                        /* for the regex.                                    */
405    int   pathlen;      /* ==strlen(path).  Needed for prefix matching.      */
406 #ifdef REGEX
407    regex_t *preg;      /* Regex for matching path part                      */
408 #endif
409 };
410 #ifdef REGEX
411 #define URL_SPEC_INITIALIZER { NULL, NULL, NULL, NULL, 0, 0, 0, NULL, 0, NULL }
412 #else /* ifndef REGEX */
413 #define URL_SPEC_INITIALIZER { NULL, NULL, NULL, NULL, 0, 0, 0, NULL, 0 }
414 #endif /* ndef REGEX */
415
416 /* Constants for host part matching in URLs */
417 #define ANCHOR_LEFT  1
418 #define ANCHOR_RIGHT 2
419
420
421 /* An I/O buffer */
422 struct iob
423 {
424    char *buf;
425    char *cur;
426    char *eod;
427 };
428
429
430 #define IOB_PEEK(CSP) ((CSP->iob->cur > CSP->iob->eod) ? (CSP->iob->eod - CSP->iob->cur) : 0)
431 #define IOB_RESET(CSP) if(CSP->iob->buf) free(CSP->iob->buf); memset(CSP->iob, '\0', sizeof(CSP->iob));
432
433 /* Keys for csp->content_type */
434 #define CT_TEXT 0x01U
435 #define CT_GIF  0x02U
436
437 #define ACTION_MASK_ALL        (~0U)
438
439 #define ACTION_MOST_COMPATIBLE 0x0000U
440
441 #define ACTION_BLOCK           0x0001U
442 #define ACTION_DEANIMATE       0x2000U
443 #define ACTION_FAST_REDIRECTS  0x0002U
444 #define ACTION_FILTER          0x0004U
445 #define ACTION_HIDE_FORWARDED  0x0008U
446 #define ACTION_HIDE_FROM       0x0010U
447 #define ACTION_HIDE_REFERER    0x0020U /* sic - follow HTTP, not English */
448 #define ACTION_HIDE_USER_AGENT 0x0040U
449 #define ACTION_IMAGE           0x0080U
450 #define ACTION_IMAGE_BLOCKER   0x0100U
451 #define ACTION_NO_COOKIE_READ  0x0200U
452 #define ACTION_NO_COOKIE_SET   0x0400U
453 #define ACTION_NO_POPUPS       0x0800U
454 #define ACTION_VANILLA_WAFER   0x1000U
455
456 #define ACTION_STRING_DEANIMATE     0
457 #define ACTION_STRING_FROM          1
458 #define ACTION_STRING_IMAGE_BLOCKER 2
459 #define ACTION_STRING_REFERER       3
460 #define ACTION_STRING_USER_AGENT    4
461 #define ACTION_STRING_COUNT         5
462
463
464 #define ACTION_MULTI_ADD_HEADER     0
465 #define ACTION_MULTI_WAFER          1
466 #define ACTION_MULTI_COUNT          2
467
468 /*
469  * This structure contains a list of actions to apply to a URL.
470  * It only contains positive instructions - no "-" options.
471  * It is not used to store the actions list itself, only for
472  * url_actions() to return the current values.
473  */
474 struct current_action_spec
475 {
476    unsigned flags;    /* a bit set to "1" = add action    */
477
478    /* For those actions that require parameters: */
479
480    /* each entry is valid if & only if corresponding entry in "add" set. */
481    char * string[ACTION_STRING_COUNT];
482
483    /* Strings to add */
484    struct list multi[ACTION_MULTI_COUNT][1];
485 };
486
487
488 /*
489  * This structure contains a set of changes to actions.
490  * It can contain both positive and negative instructions.
491  * It is used to store an entry in the actions list.
492  */
493 struct action_spec
494 {
495    unsigned mask;   /* a bit set to "0" = remove action */
496    unsigned add;    /* a bit set to "1" = add action    */
497
498    /* For those actions that require parameters: */
499
500    /* each entry is valid if & only if corresponding entry in "add" set. */
501    char * string[ACTION_STRING_COUNT];
502
503    /* Strings to remove. */
504    struct list multi_remove[ACTION_MULTI_COUNT][1];
505
506    /* If nonzero, remove *all* strings. */
507    int         multi_remove_all[ACTION_MULTI_COUNT];
508
509    /* Strings to add */
510    struct list multi_add[ACTION_MULTI_COUNT][1];
511 };
512
513 /*
514  * This structure is used to store the actions list.
515  *
516  * It contains a URL pattern, and the chages to the actions.
517  * It is a linked list.
518  */
519 struct url_actions
520 {
521    struct url_spec url[1];
522
523    struct action_spec action[1];
524
525    struct url_actions * next;
526 };
527
528
529 /* Constants defining bitmask for csp->accept_types */
530
531 #ifdef FEATURE_IMAGE_DETECT_MSIE
532
533 /* MSIE detected by user-agent string */
534 #define ACCEPT_TYPE_IS_MSIE     0x0001
535
536 /*
537  * *If* this is MSIE, it wants an image.  (Or this is a shift-reload, or
538  * it's got an image from this URL before...  yuck!)
539  * Only meaningful if ACCEPT_TYPE_IS_MSIE set 
540  */
541 #define ACCEPT_TYPE_MSIE_IMAGE  0x0002
542
543 /*
544  * *If* this is MSIE, it wants a HTML document.
545  * Only meaningful if ACCEPT_TYPE_IS_MSIE set
546  */
547 #define ACCEPT_TYPE_MSIE_HTML   0x0004
548
549 #endif /* def FEATURE_IMAGE_DETECT_MSIE */
550
551
552 struct client_state
553 {
554    /* The proxy's configuration */
555    struct configuration_spec * config;
556
557    /* The actions to perform on the current request */
558    struct current_action_spec  action[1];
559
560    /* socket to talk to client (web browser) */
561    int  cfd;
562
563    /* socket to talk to server (web server or proxy) */
564    int  sfd;
565
566
567 #ifdef FEATURE_STATISTICS
568    /* 1 if this URL was rejected, 0 otherwise. Allows actual stats inc to 
569     * occur in main thread only for thread-safety. 
570     */
571    int  rejected;
572 #endif /* def FEATURE_STATISTICS */
573
574 #ifdef FEATURE_FORCE_LOAD
575    int force;
576 #endif /* def FEATURE_FORCE_LOAD */
577
578 #ifdef FEATURE_TOGGLE
579    int   toggled_on;
580 #endif /* def FEATURE_TOGGLE */
581
582    /*
583     * Client PC's IP address, as reported by the accept()_ function.
584     * Both as string and number
585     */
586    char *ip_addr_str;
587    long  ip_addr_long;
588
589
590    /* Our IP address and hostname, i.e. the IP address that
591       the client used to reach us, and the associated hostname,
592       both as strings
593     */
594    char *my_ip_addr_str;
595    char *my_hostname;
596
597 #ifdef FEATURE_TRUST
598    /* The referer in this request, if one was specified. */
599    char *referrer;
600 #endif /* def FEATURE_TRUST */
601
602 #if defined(FEATURE_IMAGE_DETECT_MSIE)
603    /* Types the client will accept.
604     * Bitmask - see ACCEPT_TYPE_XXX constants.
605     */
606    int accept_types;
607 #endif /* defined(FEATURE_IMAGE_DETECT_MSIE) */
608
609    /* The URL that was requested */
610    struct http_request http[1];
611
612    /* An I/O buffer used for buffering data read from the client */
613    struct iob iob[1];
614
615    /* List of all headers for this request */
616    struct list headers[1];
617
618    /* List of all cookies for this request */
619    struct list cookie_list[1];
620
621    /* MIME-Type bitmap, see CT_* above */
622    unsigned char content_type;
623
624    /* The "X-Forwarded-For:" header sent by the client */
625    char   *x_forwarded;
626
627    /*
628     * Nonzero if this client is processing data.
629     * Set to zero when the thread associated with this structure dies.
630     */
631    int active;
632
633    /* files associated with this client */
634    struct file_list *actions_list;
635
636    struct file_list *rlist;   /* pcrs job file */
637    size_t content_length;     /* Length after content modification */ 
638
639 #ifdef FEATURE_TRUST
640    struct file_list *tlist;   /* trustfile */
641 #endif /* def FEATURE_TRUST */
642
643    struct client_state *next;
644 };
645
646
647 struct parsers
648 {
649    char *str;
650    char  len;
651    char *(*parser)(const struct parsers *, const char *, struct client_state *);
652 };
653
654 struct cgi_dispatcher
655 {
656    const char *name;
657    int         name_length;
658    int         (*handler)(struct client_state *csp, struct http_response *rsp, struct map *parameters);
659    const char *description;
660 };
661
662 struct file_list
663 {
664    /*
665     * this is a pointer to the data structures associated with the file.
666     * Read-only once the structure has been created.
667     */
668    void *f;
669    
670    /* Normally NULL.  When we are finished with file (i.e. when we have
671     * loaded a new one), set to a pointer to an unloader function.
672     * Unloader will be called by sweep() (called from main loop) when
673     * all clients using this file are done.  This prevents threading 
674     * problems.
675     */
676    void (*unloader)(void *);
677
678    /* Used internally by sweep().  Do not access from elsewhere. */
679    int active;
680
681    /* Following variables allow us to check if file has been changed.
682     * Read-only once the structure has been created.
683     */
684    time_t lastmodified;
685    char * filename;
686
687    /* Pointer to next entry in the linked list of all "file_list"s.
688     * This linked list is so that sweep() can navigate it.
689     * Since sweep() can remove items from the list, we must be careful
690     * to only access this value from main thread (when we know sweep
691     * won't be running).
692     */
693    struct file_list *next;
694 };
695
696
697 #ifdef FEATURE_TRUST
698 struct block_spec
699 {
700    struct url_spec url[1];
701    int    reject;
702    struct block_spec *next;
703 };
704 #endif /* def FEATURE_TRUST */
705
706
707 #define SOCKS_NONE    0    /* Don't use a SOCKS server */
708 #define SOCKS_4      40    /* original SOCKS 4 protocol */
709 #define SOCKS_4A     41    /* as modified for hosts w/o external DNS */
710
711 struct forward_spec
712 {
713    struct url_spec url[1];
714
715    /* Connection type - must be a SOCKS_xxx constant */
716    int   type;
717
718    /* SOCKS server */
719    char *gateway_host;
720    int   gateway_port;
721
722    /* Parent HTTP proxy */
723    char *forward_host;
724    int   forward_port;
725
726    /* For the linked list */
727    struct forward_spec *next;
728 };
729 #define FORWARD_SPEC_INITIALIZER { { URL_SPEC_INITIALIZER }, 0, NULL, 0, NULL, 0, NULL }
730
731
732 struct re_filterfile_spec
733 {
734    char *username;
735    char *filtername;
736    struct list patterns[1];
737    pcrs_job *joblist;
738 };
739
740 #ifdef FEATURE_ACL
741 #define ACL_PERMIT   1  /* accept connection request */
742 #define ACL_DENY     2  /* reject connection request */
743
744 struct access_control_addr
745 {
746    unsigned long addr;
747    unsigned long mask;
748    unsigned long port;
749 };
750
751 struct access_control_list
752 {
753    struct access_control_addr src[1];
754    struct access_control_addr dst[1];
755
756    short action;
757    struct access_control_list *next;
758 };
759 #endif /* def FEATURE_ACL */
760
761
762 /* Maximum number of loaders (actions, re_filter, ...) */
763 #define NLOADERS 8
764
765 /*
766  * Data loaded from the configuration file.
767  *
768  * (Anomaly: toggle is still handled through a global, not this structure)
769  */
770 struct configuration_spec
771 {
772    int debug;
773    int multi_threaded;
774
775    const char *logfile;
776
777    const char *confdir;
778    const char *logdir;
779    const char *actions_file;
780
781    /* The administrator's email address */
782    char *admin_address;
783
784    /* A URL with info on this proxy */
785    char *proxy_info_url;
786
787    const char *re_filterfile;
788
789 #ifdef FEATURE_COOKIE_JAR
790    const char * jarfile;
791    FILE * jar;
792 #endif /* def FEATURE_COOKIE_JAR */
793
794    /*
795     * Port and IP to bind to.
796     * Defaults to HADDR_DEFAULT:HADDR_PORT == 127.0.0.1:8000
797     */
798    const char *haddr;
799    int         hport;
800
801 #ifdef FEATURE_TRUST
802    const char * trustfile;
803
804    struct list trust_info[1];
805    struct url_spec *trust_list[64];
806 #endif /* def FEATURE_TRUST */
807
808 #ifdef FEATURE_ACL
809    struct access_control_list *acl;
810 #endif /* def FEATURE_ACL */
811
812    struct forward_spec *forward;
813
814    /* All options from the config file, HTML-formatted */
815    char *proxy_args;
816
817    /* the configuration file object. */
818    struct file_list *config_file_list;
819
820    /* List of loaders */
821    int (*loaders[NLOADERS])(struct client_state *);
822
823    /* bool, nonzero if we need to bind() to the new port */
824    int need_bind;
825 };
826
827
828 #define SZ(X)  (sizeof(X) / sizeof(*X))
829
830 #ifdef FEATURE_FORCE_LOAD
831 #define FORCE_PREFIX "/IJB-FORCE-LOAD"
832 #endif /* def FEATURE_FORCE_LOAD */
833
834 /* Hardwired URLs */
835 #define HOME_PAGE_URL  "http://ijbswa.sourceforge.net"
836 #define REDIRECT_URL HOME_PAGE_URL "/redirect.php?v=" VERSION "&to="
837 #define CGI_PREFIX_HOST "i.j.b"
838
839 /* HTTP snipplets */
840 static const char CSUCCEED[] =
841    "HTTP/1.0 200 Connection established\n"
842    "Proxy-Agent: IJ/" VERSION "\n\n";
843
844 static const char CHEADER[] =
845    "HTTP/1.0 400 Invalid header received from browser\n\n";
846
847 #ifdef __cplusplus
848 } /* extern "C" */
849 #endif
850
851 #endif /* ndef PROJECT_H_INCLUDED */
852
853 /*
854   Local Variables:
855   tab-width: 3
856   end:
857 */