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