3 #define PROJECT_H_VERSION "$Id: project.h,v 1.22 2001/07/15 17:51:41 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.22 2001/07/15 17:51:41 jongfoster
40 * Renaming #define STATIC to STATIC_PCRE
42 * Revision 1.21 2001/07/13 14:03:19 oes
43 * - Reorganized regex header inclusion and #defines to
44 * comply to the scheme in configure.in
45 * - Added csp->content_type and its CT_* keys
46 * - Added ACTION_DEANIMATE
47 * - Removed all #ifdef PCRS
49 * Revision 1.20 2001/06/29 21:45:41 oes
50 * Indentation, CRLF->LF, Tab-> Space
52 * Revision 1.19 2001/06/29 13:33:36 oes
54 * - Introduced http_request.host_ip_addr_str
55 * - Introduced http_response.head_length
56 * - Introduced config.my_ip_addr_str, config.my_hostname,
57 * config.admin_address and config.proxy_info_url
58 * - Removed config.proxy_args_header and config.proxy_args_trailer,
59 * renamed config.proxy_args_invocation to config.proxy_args
60 * - Removed HTML snipplets and GIFs
61 * - Removed logentry from cancelled commit
63 * Revision 1.18 2001/06/09 10:57:39 jongfoster
64 * Adding definition of BUFFER_SIZE.
65 * Changing struct cgi_dispatcher to use "const" strings.
67 * Revision 1.17 2001/06/07 23:15:09 jongfoster
68 * Merging ACL and forward files into config file.
69 * Moving struct gateway members into struct forward_spec
70 * Removing config->proxy_args_gateways
71 * Cosmetic: Adding a few comments
73 * Revision 1.16 2001/06/04 18:31:58 swa
74 * files are now prefixed with either `confdir' or `logdir'.
75 * `make redhat-dist' replaces both entries confdir and logdir
78 * Revision 1.15 2001/06/04 11:28:53 swa
79 * redirect did not work due to missing /
81 * Revision 1.14 2001/06/03 11:03:48 oes
83 * added struct http_response,
84 * changed struct interceptors to struct cgi_dispatcher,
85 * moved HTML stuff to cgi.h
87 * Revision 1.13 2001/06/01 20:05:36 jongfoster
88 * Support for +image-blocker{}: added ACTION_IMAGE_BLOCKER
89 * constant, and removed csp->tinygif.
91 * Revision 1.12 2001/06/01 18:49:17 jongfoster
92 * Replaced "list_share" with "list" - the tiny memory gain was not
93 * worth the extra complexity.
95 * Revision 1.11 2001/06/01 10:32:47 oes
96 * Added constants for anchoring selection bitmap
98 * Revision 1.10 2001/05/31 21:33:53 jongfoster
99 * Changes for new actions file, replacing permissionsfile
100 * and parts of the config file. Also added support for
103 * Revision 1.9 2001/05/31 17:32:31 oes
105 * - Enhanced domain part globbing with infix and prefix asterisk
106 * matching and optional unanchored operation
108 * Revision 1.8 2001/05/29 20:09:15 joergs
109 * HTTP_REDIRECT_TEMPLATE fixed.
111 * Revision 1.7 2001/05/29 09:50:24 jongfoster
112 * Unified blocklist/imagelist/actionslist.
113 * File format is still under discussion, but the internal changes
116 * Also modified interceptor behaviour:
117 * - We now intercept all URLs beginning with one of the following
118 * prefixes (and *only* these prefixes):
120 * * http://ijbswa.sf.net/config/
121 * * http://ijbswa.sourceforge.net/config/
122 * - New interceptors "home page" - go to http://i.j.b/ to see it.
123 * - Internal changes so that intercepted and fast redirect pages
124 * are not replaced with an image.
125 * - Interceptors now have the option to send a binary page direct
126 * to the client. (i.e. ijb-send-banner uses this)
127 * - Implemented show-url-info interceptor. (Which is why I needed
128 * the above interceptors changes - a typical URL is
129 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
130 * The previous mechanism would not have intercepted that, and
131 * if it had been intercepted then it then it would have replaced
134 * Revision 1.6 2001/05/27 22:17:04 oes
136 * - re_process_buffer no longer writes the modified buffer
137 * to the client, which was very ugly. It now returns the
138 * buffer, which it is then written by chat.
140 * - content_length now adjusts the Content-Length: header
141 * for modified documents rather than crunch()ing it.
142 * (Length info in csp->content_length, which is 0 for
143 * unmodified documents)
145 * - For this to work, sed() is called twice when filtering.
147 * Revision 1.5 2001/05/26 00:28:36 jongfoster
148 * Automatic reloading of config file.
149 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
150 * Most of the global variables have been moved to a new
151 * struct configuration_spec, accessed through csp->config->globalname
152 * Most of the globals remaining are used by the Win32 GUI.
154 * Revision 1.4 2001/05/22 18:46:04 oes
156 * - Enabled filtering banners by size rather than URL
157 * by adding patterns that replace all standard banner
158 * sizes with the "Junkbuster" gif to the re_filterfile
160 * - Enabled filtering WebBugs by providing a pattern
161 * which kills all 1x1 images
163 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
164 * which is selected by the (nonstandard and therefore
165 * capital) letter 'U' in the option string.
166 * It causes the quantifiers to be ungreedy by default.
167 * Appending a ? turns back to greedy (!).
169 * - Added a new interceptor ijb-send-banner, which
170 * sends back the "Junkbuster" gif. Without imagelist or
171 * MSIE detection support, or if tinygif = 1, or the
172 * URL isn't recognized as an imageurl, a lame HTML
173 * explanation is sent instead.
175 * - Added new feature, which permits blocking remote
176 * script redirects and firing back a local redirect
178 * The feature is conditionally compiled, i.e. it
179 * can be disabled with --disable-fast-redirects,
180 * plus it must be activated by a "fast-redirects"
181 * line in the config file, has its own log level
182 * and of course wants to be displayed by show-proxy-args
183 * Note: Boy, all the #ifdefs in 1001 locations and
184 * all the fumbling with configure.in and acconfig.h
185 * were *way* more work than the feature itself :-(
187 * - Because a generic redirect template was needed for
188 * this, tinygif = 3 now uses the same.
190 * - Moved GIFs, and other static HTTP response templates
195 * - Removed some >400 CRs again (Jon, you really worked
198 * Revision 1.3 2001/05/20 01:21:20 jongfoster
199 * Version 2.9.4 checkin.
200 * - Merged popupfile and cookiefile, and added control over PCRS
201 * filtering, in new "actionsfile".
202 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
203 * file error you now get a message box (in the Win32 GUI) rather
204 * than the program exiting with no explanation.
205 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
207 * - Removed tabs from "config"
208 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
209 * - Bumped up version number.
211 * Revision 1.2 2001/05/17 23:01:01 oes
212 * - Cleaned CRLF's from the sources and related files
214 * Revision 1.1.1.1 2001/05/15 13:59:03 oes
215 * Initial import of version 2.9.3 source tree
218 *********************************************************************/
221 /* Declare struct FILE for vars and funcs. */
224 /* Need time_t for file_list */
228 * Include appropriate regular expression libraries.
229 * Note that pcrs and pcre (native) are needed for cgi
230 * and are included anyway.
233 #if defined(REGEX_PCRE) || defined (REGEX_GNU)
235 #endif /* defined(REGEX_PCRE) || defined (REGEX_GNU) */
249 #if defined(REGEX_PCRE)
251 # include "pcreposix.h"
253 # include <pcreposix.h>
255 #endif /* defined(REGEX_PCRE) */
257 #if defined(REGEX_GNU)
258 # include "gnu_regex.h"
263 #endif /* def AMIGA */
269 #define freez(X) if(X) free(X); X = NULL
271 #define BUFFER_SIZE 5000
275 /* Default IP and port to listen on */
276 #define HADDR_DEFAULT "127.0.0.1"
277 #define HADDR_PORT 8000
280 /* Need this for struct client_state */
281 struct configuration_spec;
283 /* Generic linked list of strings */
284 struct list /* FIXME: Why not separate entries and header? */
286 char * str; /* valid in an entry */
287 struct list *last; /* valid in header */
303 char *host_ip_addr_str; /* NULL before connect_to() */
307 char *hostport; /* "host[:port]" */
311 /* Response generated by CGI, blocker, or error handler */
314 char *status; /* HTTP status (string)*/
315 struct list headers[1]; /* List of header lines */
316 char *head; /* Formatted http response head */
317 int head_length; /* Length of http response head */
318 char *body; /* HTTP document body */
319 int content_length; /* Length of body, REQUIRED if binary body*/
325 char *spec; /* The string which was parsed to produce this */
326 /* url_spec. Used for debugging or display only. */
328 /* Hostname matching: */
329 char *domain; /* Fully qalified domain name (FQDN) pattern. */
330 /* May contain "*". */
331 char *dbuf; /* Buffer with '\0'-delimited fqdn */
332 char **dvec; /* Domain ptr vector into dbuf */
333 int dcnt; /* How many domains in fqdn? */
334 int unanchored; /* Bitmap - flags are ANCHOR_LEFT and ANCHOR_RIGHT */
337 int port; /* The port number, or 0 to match all ports. */
340 char *path; /* The path prefix (if not using regex), or source */
342 int pathlen; /* ==strlen(path). Needed for prefix matching. */
344 regex_t *preg; /* Regex for matching path part */
348 #define ANCHOR_LEFT 1
349 #define ANCHOR_RIGHT 2
362 #define IOB_PEEK(CSP) ((CSP->iob->cur > CSP->iob->eod) ? (CSP->iob->eod - CSP->iob->cur) : 0)
363 #define IOB_RESET(CSP) if(CSP->iob->buf) free(CSP->iob->buf); memset(CSP->iob, '\0', sizeof(CSP->iob));
365 /* Keys for csp->content_type */
366 #define CT_TEXT 0x01U
369 #define ACTION_MASK_ALL (~0U)
371 #define ACTION_MOST_COMPATIBLE 0x0000U
373 #define ACTION_BLOCK 0x0001U
374 #define ACTION_DEANIMATE 0x2000U
375 #define ACTION_FAST_REDIRECTS 0x0002U
376 #define ACTION_FILTER 0x0004U
377 #define ACTION_HIDE_FORWARDED 0x0008U
378 #define ACTION_HIDE_FROM 0x0010U
379 #define ACTION_HIDE_REFERER 0x0020U /* sic - follow HTTP, not English */
380 #define ACTION_HIDE_USER_AGENT 0x0040U
381 #define ACTION_IMAGE 0x0080U
382 #define ACTION_IMAGE_BLOCKER 0x0100U
383 #define ACTION_NO_COOKIE_READ 0x0200U
384 #define ACTION_NO_COOKIE_SET 0x0400U
385 #define ACTION_NO_POPUPS 0x0800U
386 #define ACTION_VANILLA_WAFER 0x1000U
388 #define ACTION_STRING_DEANIMATE 0
389 #define ACTION_STRING_FROM 1
390 #define ACTION_STRING_IMAGE_BLOCKER 2
391 #define ACTION_STRING_REFERER 3
392 #define ACTION_STRING_USER_AGENT 4
393 #define ACTION_STRING_COUNT 5
396 #define ACTION_MULTI_ADD_HEADER 0
397 #define ACTION_MULTI_WAFER 1
398 #define ACTION_MULTI_COUNT 2
401 * This structure contains a list of actions to apply to a URL.
402 * It only contains positive instructions - no "-" options.
403 * It is not used to store the actions list itself, only for
404 * url_actions() to return the current values.
406 struct current_action_spec
408 unsigned flags; /* a bit set to "1" = add action */
410 /* For those actions that require parameters: */
412 /* each entry is valid if & only if corresponding entry in "add" set. */
413 char * string[ACTION_STRING_COUNT];
416 struct list multi[ACTION_MULTI_COUNT][1];
421 * This structure contains a set of changes to actions.
422 * It can contain both positive and negative instructions.
423 * It is used to store an entry in the actions list.
427 unsigned mask; /* a bit set to "0" = remove action */
428 unsigned add; /* a bit set to "1" = add action */
430 /* For those actions that require parameters: */
432 /* each entry is valid if & only if corresponding entry in "add" set. */
433 char * string[ACTION_STRING_COUNT];
435 /* Strings to remove. */
436 struct list multi_remove[ACTION_MULTI_COUNT][1];
438 /* If nonzero, remove *all* strings. */
439 int multi_remove_all[ACTION_MULTI_COUNT];
442 struct list multi_add[ACTION_MULTI_COUNT][1];
446 * This structure is used to store the actions list.
448 * It contains a URL pattern, and the chages to the actions.
449 * It is a linked list.
453 struct url_spec url[1];
455 struct action_spec action[1];
457 struct url_actions * next;
461 /* Constants defining bitmask for csp->accept_types */
463 #ifdef DETECT_MSIE_IMAGES
465 /* MSIE detected by user-agent string */
466 #define ACCEPT_TYPE_IS_MSIE 0x0001
469 * *If* this is MSIE, it wants an image. (Or this is a shift-reload, or
470 * it's got an image from this URL before... yuck!)
471 * Only meaningful if ACCEPT_TYPE_IS_MSIE set
473 #define ACCEPT_TYPE_MSIE_IMAGE 0x0002
476 * *If* this is MSIE, it wants a HTML document.
477 * Only meaningful if ACCEPT_TYPE_IS_MSIE set
479 #define ACCEPT_TYPE_MSIE_HTML 0x0004
481 #endif /* def DETECT_MSIE_IMAGES */
486 /* The proxy's configuration */
487 struct configuration_spec * config;
489 /* The actions to perform on the current request */
490 struct current_action_spec action[1];
492 /* socket to talk to client (web browser) */
495 /* socket to talk to server (web server or proxy) */
500 /* 1 if this URL was rejected, 0 otherwise. Allows actual stats inc to
501 * occur in main thread only for thread-safety.
504 #endif /* def STATISTICS */
508 #endif /* def FORCE_LOAD */
512 #endif /* def TOGGLE */
515 * Client PC's IP address, as reported by the accept()_ function.
516 * Both as string and number
522 /* Our IP address and hostname, i.e. the IP address that
523 the client used to reach us, and the associated hostname,
526 char *my_ip_addr_str;
530 /* The referer in this request, if one was specified. */
532 #endif /* def TRUST_FILES */
534 #if defined(DETECT_MSIE_IMAGES)
535 /* Types the client will accept.
536 * Bitmask - see ACCEPT_TYPE_XXX constants.
539 #endif /* defined(DETECT_MSIE_IMAGES) */
541 /* The URL that was requested */
542 struct http_request http[1];
544 /* An I/O buffer used for buffering data read from the client */
547 /* List of all headers for this request */
548 struct list headers[1];
550 /* List of all cookies for this request */
551 struct list cookie_list[1];
553 /* MIME-Type bitmap, see CT_* above */
554 unsigned char content_type;
556 /* The "X-Forwarded-For:" header sent by the client */
560 * Nonzero if this client is processing data.
561 * Set to zero when the thread associated with this structure dies.
565 /* files associated with this client */
566 struct file_list *actions_list;
568 struct file_list *rlist; /* pcrs job file */
569 size_t content_length; /* Length after content modification */
572 struct file_list *tlist; /* trustfile */
573 #endif /* def TRUST_FILES */
575 struct client_state *next;
583 char *(*parser)(const struct parsers *, char *, struct client_state *);
586 struct cgi_dispatcher
590 int (*handler)(struct client_state *csp, struct http_response *rsp, struct map *parameters);
591 const char *description;
597 * this is a pointer to the data structures associated with the file.
598 * Read-only once the structure has been created.
602 /* Normally NULL. When we are finished with file (i.e. when we have
603 * loaded a new one), set to a pointer to an unloader function.
604 * Unloader will be called by sweep() (called from main loop) when
605 * all clients using this file are done. This prevents threading
608 void (*unloader)(void *);
610 /* Used internally by sweep(). Do not access from elsewhere. */
613 #ifndef SPLIT_PROXY_ARGS
614 /* String to be displayed as part of show-proxy-args display.
615 * Read-only once the structure has been created.
618 #endif /* ndef SPLIT_PROXY_ARGS */
620 /* Following variables allow us to check if file has been changed.
621 * Read-only once the structure has been created.
626 /* Pointer to next entry in the linked list of all "file_list"s.
627 * This linked list is so that sweep() can navigate it.
628 * Since sweep() can remove items from the list, we must be careful
629 * to only access this value from main thread (when we know sweep
632 struct file_list *next;
639 struct url_spec url[1];
641 struct block_spec *next;
643 #endif /* def TRUST_FILES */
646 #define SOCKS_NONE 0 /* Don't use a SOCKS server */
647 #define SOCKS_4 40 /* original SOCKS 4 protocol */
648 #define SOCKS_4A 41 /* as modified for hosts w/o external DNS */
652 struct url_spec url[1];
654 /* Connection type - must be a SOCKS_xxx constant */
661 /* Parent HTTP proxy */
665 /* For the linked list */
666 struct forward_spec *next;
669 struct re_filterfile_spec
671 struct list patterns[1];
676 #define ACL_PERMIT 1 /* accept connection request */
677 #define ACL_DENY 2 /* reject connection request */
679 struct access_control_addr
686 struct access_control_list
688 struct access_control_addr src[1];
689 struct access_control_addr dst[1];
692 struct access_control_list *next;
694 #endif /* def ACL_FILES */
697 /* Maximum number of loaders (actions, re_filter, ...) */
701 * Data loaded from the configuration file.
703 * (Anomaly: toggle is still handled through a global, not this structure)
705 struct configuration_spec
714 const char *actions_file;
716 /* The administrator's email address */
719 /* A URL with info on this proxy */
720 char *proxy_info_url;
722 const char *re_filterfile;
725 const char * jarfile;
727 #endif /* def JAR_FILES */
730 * Port and IP to bind to.
731 * Defaults to HADDR_DEFAULT:HADDR_PORT == 127.0.0.1:8000
736 #ifndef SPLIT_PROXY_ARGS
737 const char *suppress_message;
738 #endif /* ndef SPLIT_PROXY_ARGS */
740 #ifndef SPLIT_PROXY_ARGS
741 /* suppress listing config files */
742 int suppress_blocklists;
743 #endif /* ndef SPLIT_PROXY_ARGS */
746 const char * trustfile;
748 struct list trust_info[1];
749 struct url_spec *trust_list[64];
750 #endif /* def TRUST_FILES */
753 struct access_control_list *acl;
754 #endif /* def ACL_FILES */
756 struct forward_spec *forward;
758 /* All options from the config file, HTML-formatted */
761 /* the configuration file object. */
762 struct file_list *config_file_list;
764 /* List of loaders */
765 int (*loaders[NLOADERS])(struct client_state *);
767 /* bool, nonzero if we need to bind() to the new port */
772 #define SZ(X) (sizeof(X) / sizeof(*X))
775 #define FORCE_PREFIX "/IJB-FORCE-LOAD"
776 #endif /* def FORCE_LOAD */
779 #define HOME_PAGE_URL "http://ijbswa.sourceforge.net"
780 #define REDIRECT_URL HOME_PAGE_URL "/redirect.php?v=" VERSION "&to="
781 #define CGI_PREFIX_HOST "i.j.b"
784 static const char CSUCCEED[] =
785 "HTTP/1.0 200 Connection established\n"
786 "Proxy-Agent: IJ/" VERSION "\n\n";
788 static const char CHEADER[] =
789 "HTTP/1.0 400 Invalid header received from browser\n\n";
795 #endif /* ndef _PROJECT_H */