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