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 /*********************************************************************
6 * File : $Source: /cvsroot/ijbswa/current/project.h,v $
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).
12 * Copyright : Written by and Copyright (C) 2001 the SourceForge
13 * IJBSWA team. http://ijbswa.sourceforge.net
15 * Based on the Internet Junkbuster originally written
16 * by and Copyright (C) 1997 Anonymous Coders and
17 * Junkbusters Corporation. http://www.junkbusters.com
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.
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.
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.
39 * Revision 1.29 2001/09/13 23:29:43 jongfoster
40 * Defining FORWARD_SPEC_INITIALIZER
42 * Revision 1.28 2001/09/13 23:05:50 jongfoster
43 * Changing the string paramater to the header parsers a "const".
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).
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
58 * Revision 1.25 2001/07/29 18:43:08 jongfoster
59 * Changing #ifdef _FILENAME_H to FILENAME_H_INCLUDED, to conform to
62 * Revision 1.24 2001/07/25 17:20:27 oes
63 * Introduced http->user_agent
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
69 * Revision 1.22 2001/07/15 17:51:41 jongfoster
70 * Renaming #define STATIC to STATIC_PCRE
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
79 * Revision 1.20 2001/06/29 21:45:41 oes
80 * Indentation, CRLF->LF, Tab-> Space
82 * Revision 1.19 2001/06/29 13:33:36 oes
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
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.
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
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
108 * Revision 1.15 2001/06/04 11:28:53 swa
109 * redirect did not work due to missing /
111 * Revision 1.14 2001/06/03 11:03:48 oes
113 * added struct http_response,
114 * changed struct interceptors to struct cgi_dispatcher,
115 * moved HTML stuff to cgi.h
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.
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.
125 * Revision 1.11 2001/06/01 10:32:47 oes
126 * Added constants for anchoring selection bitmap
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
133 * Revision 1.9 2001/05/31 17:32:31 oes
135 * - Enhanced domain part globbing with infix and prefix asterisk
136 * matching and optional unanchored operation
138 * Revision 1.8 2001/05/29 20:09:15 joergs
139 * HTTP_REDIRECT_TEMPLATE fixed.
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
146 * Also modified interceptor behaviour:
147 * - We now intercept all URLs beginning with one of the following
148 * prefixes (and *only* these prefixes):
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
164 * Revision 1.6 2001/05/27 22:17:04 oes
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.
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)
175 * - For this to work, sed() is called twice when filtering.
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.
184 * Revision 1.4 2001/05/22 18:46:04 oes
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
190 * - Enabled filtering WebBugs by providing a pattern
191 * which kills all 1x1 images
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 (!).
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.
205 * - Added new feature, which permits blocking remote
206 * script redirects and firing back a local redirect
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 :-(
217 * - Because a generic redirect template was needed for
218 * this, tinygif = 3 now uses the same.
220 * - Moved GIFs, and other static HTTP response templates
225 * - Removed some >400 CRs again (Jon, you really worked
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
237 * - Removed tabs from "config"
238 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
239 * - Bumped up version number.
241 * Revision 1.2 2001/05/17 23:01:01 oes
242 * - Cleaned CRLF's from the sources and related files
244 * Revision 1.1.1.1 2001/05/15 13:59:03 oes
245 * Initial import of version 2.9.3 source tree
248 *********************************************************************/
251 /* Declare struct FILE for vars and funcs. */
254 /* Need time_t for file_list */
258 * Include appropriate regular expression libraries.
259 * Note that pcrs and pcre (native) are needed for cgi
260 * and are included anyway.
263 #if defined(REGEX_PCRE) || defined (REGEX_GNU)
265 #endif /* defined(REGEX_PCRE) || defined (REGEX_GNU) */
279 #if defined(REGEX_PCRE)
281 # include "pcreposix.h"
283 # include <pcreposix.h>
285 #endif /* defined(REGEX_PCRE) */
287 #if defined(REGEX_GNU)
288 # include "gnu_regex.h"
293 #endif /* def AMIGA */
299 #define freez(X) if(X) free(X); X = NULL
301 #define BUFFER_SIZE 5000
305 /* Default IP and port to listen on */
306 #define HADDR_DEFAULT "127.0.0.1"
307 #define HADDR_PORT 8000
310 /* Need this for struct client_state */
311 struct configuration_spec;
313 /* Generic linked list of strings */
314 struct list /* FIXME: Why not separate entries and header? */
316 char * str; /* valid in an entry */
317 struct list *last; /* valid in header */
325 struct map_entry *next;
330 struct map_entry *first;
331 struct map_entry *last;
339 char *host_ip_addr_str; /* NULL before connect_to() */
343 char *hostport; /* "host[:port]" */
345 char *user_agent; /* Client's User-Agent: header value */
348 /* Response generated by CGI, blocker, or error handler */
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) */
364 char *spec; /* The string which was parsed to produce this */
365 /* url_spec. Used for debugging or display only. */
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 */
376 int port; /* The port number, or 0 to match all ports. */
379 char *path; /* The path prefix (if not using regex), or source */
381 int pathlen; /* ==strlen(path). Needed for prefix matching. */
383 regex_t *preg; /* Regex for matching path part */
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 */
392 /* Constants for host part matching in URLs */
393 #define ANCHOR_LEFT 1
394 #define ANCHOR_RIGHT 2
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));
409 /* Keys for csp->content_type */
410 #define CT_TEXT 0x01U
413 #define ACTION_MASK_ALL (~0U)
415 #define ACTION_MOST_COMPATIBLE 0x0000U
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
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
440 #define ACTION_MULTI_ADD_HEADER 0
441 #define ACTION_MULTI_WAFER 1
442 #define ACTION_MULTI_COUNT 2
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.
450 struct current_action_spec
452 unsigned flags; /* a bit set to "1" = add action */
454 /* For those actions that require parameters: */
456 /* each entry is valid if & only if corresponding entry in "add" set. */
457 char * string[ACTION_STRING_COUNT];
460 struct list multi[ACTION_MULTI_COUNT][1];
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.
471 unsigned mask; /* a bit set to "0" = remove action */
472 unsigned add; /* a bit set to "1" = add action */
474 /* For those actions that require parameters: */
476 /* each entry is valid if & only if corresponding entry in "add" set. */
477 char * string[ACTION_STRING_COUNT];
479 /* Strings to remove. */
480 struct list multi_remove[ACTION_MULTI_COUNT][1];
482 /* If nonzero, remove *all* strings. */
483 int multi_remove_all[ACTION_MULTI_COUNT];
486 struct list multi_add[ACTION_MULTI_COUNT][1];
490 * This structure is used to store the actions list.
492 * It contains a URL pattern, and the chages to the actions.
493 * It is a linked list.
497 struct url_spec url[1];
499 struct action_spec action[1];
501 struct url_actions * next;
505 /* Constants defining bitmask for csp->accept_types */
507 #ifdef FEATURE_IMAGE_DETECT_MSIE
509 /* MSIE detected by user-agent string */
510 #define ACCEPT_TYPE_IS_MSIE 0x0001
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
517 #define ACCEPT_TYPE_MSIE_IMAGE 0x0002
520 * *If* this is MSIE, it wants a HTML document.
521 * Only meaningful if ACCEPT_TYPE_IS_MSIE set
523 #define ACCEPT_TYPE_MSIE_HTML 0x0004
525 #endif /* def FEATURE_IMAGE_DETECT_MSIE */
530 /* The proxy's configuration */
531 struct configuration_spec * config;
533 /* The actions to perform on the current request */
534 struct current_action_spec action[1];
536 /* socket to talk to client (web browser) */
539 /* socket to talk to server (web server or proxy) */
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.
548 #endif /* def FEATURE_STATISTICS */
550 #ifdef FEATURE_FORCE_LOAD
552 #endif /* def FEATURE_FORCE_LOAD */
554 #ifdef FEATURE_TOGGLE
556 #endif /* def FEATURE_TOGGLE */
559 * Client PC's IP address, as reported by the accept()_ function.
560 * Both as string and number
566 /* Our IP address and hostname, i.e. the IP address that
567 the client used to reach us, and the associated hostname,
570 char *my_ip_addr_str;
574 /* The referer in this request, if one was specified. */
576 #endif /* def FEATURE_TRUST */
578 #if defined(FEATURE_IMAGE_DETECT_MSIE)
579 /* Types the client will accept.
580 * Bitmask - see ACCEPT_TYPE_XXX constants.
583 #endif /* defined(FEATURE_IMAGE_DETECT_MSIE) */
585 /* The URL that was requested */
586 struct http_request http[1];
588 /* An I/O buffer used for buffering data read from the client */
591 /* List of all headers for this request */
592 struct list headers[1];
594 /* List of all cookies for this request */
595 struct list cookie_list[1];
597 /* MIME-Type bitmap, see CT_* above */
598 unsigned char content_type;
600 /* The "X-Forwarded-For:" header sent by the client */
604 * Nonzero if this client is processing data.
605 * Set to zero when the thread associated with this structure dies.
609 /* files associated with this client */
610 struct file_list *actions_list;
612 struct file_list *rlist; /* pcrs job file */
613 size_t content_length; /* Length after content modification */
616 struct file_list *tlist; /* trustfile */
617 #endif /* def FEATURE_TRUST */
619 struct client_state *next;
627 char *(*parser)(const struct parsers *, const char *, struct client_state *);
630 struct cgi_dispatcher
634 int (*handler)(struct client_state *csp, struct http_response *rsp, struct map *parameters);
635 const char *description;
641 * this is a pointer to the data structures associated with the file.
642 * Read-only once the structure has been created.
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
652 void (*unloader)(void *);
654 /* Used internally by sweep(). Do not access from elsewhere. */
657 /* Following variables allow us to check if file has been changed.
658 * Read-only once the structure has been created.
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
669 struct file_list *next;
676 struct url_spec url[1];
678 struct block_spec *next;
680 #endif /* def FEATURE_TRUST */
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 */
689 struct url_spec url[1];
691 /* Connection type - must be a SOCKS_xxx constant */
698 /* Parent HTTP proxy */
702 /* For the linked list */
703 struct forward_spec *next;
705 #define FORWARD_SPEC_INITIALIZER { URL_SPEC_INITIALIZER, 0, NULL, 0, NULL, 0, NULL }
708 struct re_filterfile_spec
712 struct list patterns[1];
717 #define ACL_PERMIT 1 /* accept connection request */
718 #define ACL_DENY 2 /* reject connection request */
720 struct access_control_addr
727 struct access_control_list
729 struct access_control_addr src[1];
730 struct access_control_addr dst[1];
733 struct access_control_list *next;
735 #endif /* def FEATURE_ACL */
738 /* Maximum number of loaders (actions, re_filter, ...) */
742 * Data loaded from the configuration file.
744 * (Anomaly: toggle is still handled through a global, not this structure)
746 struct configuration_spec
755 const char *actions_file;
757 /* The administrator's email address */
760 /* A URL with info on this proxy */
761 char *proxy_info_url;
763 const char *re_filterfile;
765 #ifdef FEATURE_COOKIE_JAR
766 const char * jarfile;
768 #endif /* def FEATURE_COOKIE_JAR */
771 * Port and IP to bind to.
772 * Defaults to HADDR_DEFAULT:HADDR_PORT == 127.0.0.1:8000
778 const char * trustfile;
780 struct list trust_info[1];
781 struct url_spec *trust_list[64];
782 #endif /* def FEATURE_TRUST */
785 struct access_control_list *acl;
786 #endif /* def FEATURE_ACL */
788 struct forward_spec *forward;
790 /* All options from the config file, HTML-formatted */
793 /* the configuration file object. */
794 struct file_list *config_file_list;
796 /* List of loaders */
797 int (*loaders[NLOADERS])(struct client_state *);
799 /* bool, nonzero if we need to bind() to the new port */
804 #define SZ(X) (sizeof(X) / sizeof(*X))
806 #ifdef FEATURE_FORCE_LOAD
807 #define FORCE_PREFIX "/IJB-FORCE-LOAD"
808 #endif /* def FEATURE_FORCE_LOAD */
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"
816 static const char CSUCCEED[] =
817 "HTTP/1.0 200 Connection established\n"
818 "Proxy-Agent: IJ/" VERSION "\n\n";
820 static const char CHEADER[] =
821 "HTTP/1.0 400 Invalid header received from browser\n\n";
827 #endif /* ndef PROJECT_H_INCLUDED */