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