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