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