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