3 #define PROJECT_H_VERSION "$Id: project.h,v 1.17 2001/06/07 23:15:09 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.17 2001/06/07 23:15:09 jongfoster
40 * Merging ACL and forward files into config file.
41 * Moving struct gateway members into struct forward_spec
42 * Removing config->proxy_args_gateways
43 * Cosmetic: Adding a few comments
45 * Revision 1.16 2001/06/04 18:31:58 swa
46 * files are now prefixed with either `confdir' or `logdir'.
47 * `make redhat-dist' replaces both entries confdir and logdir
50 * Revision 1.15 2001/06/04 11:28:53 swa
51 * redirect did not work due to missing /
53 * Revision 1.14 2001/06/03 11:03:48 oes
60 * adapted to new enlist_unique arg format
64 * introduced confdir option
66 * filters.c filtrers.h
68 * extracted-CGI relevant stuff
76 * support for new cgi mechansim
80 * functions for new list type: "map"
81 * extended enlist_unique
88 * deleted const struct interceptors
96 * added struct http_response
97 * changes struct interceptors to struct cgi_dispatcher
98 * moved HTML stuff to cgi.h
107 * Revision 1.13 2001/06/01 20:05:36 jongfoster
108 * Support for +image-blocker{}: added ACTION_IMAGE_BLOCKER
109 * constant, and removed csp->tinygif.
111 * Revision 1.12 2001/06/01 18:49:17 jongfoster
112 * Replaced "list_share" with "list" - the tiny memory gain was not
113 * worth the extra complexity.
115 * Revision 1.11 2001/06/01 10:32:47 oes
116 * Added constants for anchoring selection bitmap
118 * Revision 1.10 2001/05/31 21:33:53 jongfoster
119 * Changes for new actions file, replacing permissionsfile
120 * and parts of the config file. Also added support for
123 * Revision 1.9 2001/05/31 17:32:31 oes
125 * - Enhanced domain part globbing with infix and prefix asterisk
126 * matching and optional unanchored operation
128 * Revision 1.8 2001/05/29 20:09:15 joergs
129 * HTTP_REDIRECT_TEMPLATE fixed.
131 * Revision 1.7 2001/05/29 09:50:24 jongfoster
132 * Unified blocklist/imagelist/actionslist.
133 * File format is still under discussion, but the internal changes
136 * Also modified interceptor behaviour:
137 * - We now intercept all URLs beginning with one of the following
138 * prefixes (and *only* these prefixes):
140 * * http://ijbswa.sf.net/config/
141 * * http://ijbswa.sourceforge.net/config/
142 * - New interceptors "home page" - go to http://i.j.b/ to see it.
143 * - Internal changes so that intercepted and fast redirect pages
144 * are not replaced with an image.
145 * - Interceptors now have the option to send a binary page direct
146 * to the client. (i.e. ijb-send-banner uses this)
147 * - Implemented show-url-info interceptor. (Which is why I needed
148 * the above interceptors changes - a typical URL is
149 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
150 * The previous mechanism would not have intercepted that, and
151 * if it had been intercepted then it then it would have replaced
154 * Revision 1.6 2001/05/27 22:17:04 oes
156 * - re_process_buffer no longer writes the modified buffer
157 * to the client, which was very ugly. It now returns the
158 * buffer, which it is then written by chat.
160 * - content_length now adjusts the Content-Length: header
161 * for modified documents rather than crunch()ing it.
162 * (Length info in csp->content_length, which is 0 for
163 * unmodified documents)
165 * - For this to work, sed() is called twice when filtering.
167 * Revision 1.5 2001/05/26 00:28:36 jongfoster
168 * Automatic reloading of config file.
169 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
170 * Most of the global variables have been moved to a new
171 * struct configuration_spec, accessed through csp->config->globalname
172 * Most of the globals remaining are used by the Win32 GUI.
174 * Revision 1.4 2001/05/22 18:46:04 oes
176 * - Enabled filtering banners by size rather than URL
177 * by adding patterns that replace all standard banner
178 * sizes with the "Junkbuster" gif to the re_filterfile
180 * - Enabled filtering WebBugs by providing a pattern
181 * which kills all 1x1 images
183 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
184 * which is selected by the (nonstandard and therefore
185 * capital) letter 'U' in the option string.
186 * It causes the quantifiers to be ungreedy by default.
187 * Appending a ? turns back to greedy (!).
189 * - Added a new interceptor ijb-send-banner, which
190 * sends back the "Junkbuster" gif. Without imagelist or
191 * MSIE detection support, or if tinygif = 1, or the
192 * URL isn't recognized as an imageurl, a lame HTML
193 * explanation is sent instead.
195 * - Added new feature, which permits blocking remote
196 * script redirects and firing back a local redirect
198 * The feature is conditionally compiled, i.e. it
199 * can be disabled with --disable-fast-redirects,
200 * plus it must be activated by a "fast-redirects"
201 * line in the config file, has its own log level
202 * and of course wants to be displayed by show-proxy-args
203 * Note: Boy, all the #ifdefs in 1001 locations and
204 * all the fumbling with configure.in and acconfig.h
205 * were *way* more work than the feature itself :-(
207 * - Because a generic redirect template was needed for
208 * this, tinygif = 3 now uses the same.
210 * - Moved GIFs, and other static HTTP response templates
215 * - Removed some >400 CRs again (Jon, you really worked
218 * Revision 1.3 2001/05/20 01:21:20 jongfoster
219 * Version 2.9.4 checkin.
220 * - Merged popupfile and cookiefile, and added control over PCRS
221 * filtering, in new "actionsfile".
222 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
223 * file error you now get a message box (in the Win32 GUI) rather
224 * than the program exiting with no explanation.
225 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
227 * - Removed tabs from "config"
228 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
229 * - Bumped up version number.
231 * Revision 1.2 2001/05/17 23:01:01 oes
232 * - Cleaned CRLF's from the sources and related files
234 * Revision 1.1.1.1 2001/05/15 13:59:03 oes
235 * Initial import of version 2.9.3 source tree
238 *********************************************************************/
241 /* Declare struct FILE for vars and funcs. */
244 /* Need time_t for file_list */
248 * Include appropriate regular expression libraries.
250 * PCRS ==> Include pcre
251 * REGEX && PCRE ==> Include pcre and pcreposix
252 * REGEX && !PCRE ==> Include gnu_regex
254 * STATIC ==> Use #include "pcre.h" (compiling at same time)
255 * !STATIC ==> Use #include <pcre.h> (System library)
258 #if (defined(REGEX) && defined(PCRE)) || defined(PCRS)
264 #endif /* (defined(REGEX) && defined(PCRE)) || defined(PCRS) */
266 #if defined(REGEX) && defined(PCRE)
268 # include "pcreposix.h"
270 # include <pcreposix.h>
272 #endif /* defined(REGEX) && defined(PCRE) */
274 #if defined(REGEX) && !defined(PCRE)
275 # include "gnu_regex.h"
280 #endif /* def PCRS */
284 #endif /* def AMIGA */
290 #define BUFFER_SIZE 5000
\r
294 /* Default IP and port to listen on */
295 #define HADDR_DEFAULT "127.0.0.1"
296 #define HADDR_PORT 8000
299 /* Need this for struct client_state */
300 struct configuration_spec;
302 /* Generic linked list of strings */
303 struct list /* FIXME: Why not separate entries and header? */
305 char * str; /* valid in an entry */
306 struct list *last; /* valid in header */
325 char *hostport; /* "host[:port]" */
329 /* CGI or blocker generated response */
332 char *status; /* HTTP status */
333 struct list headers[1]; /* List of header lines */
334 int content_length; /* Length of body, REQUIRED if binary body*/
335 char *head; /* Formatted http response head */
336 char *body; /* HTTP document body */
342 char *spec; /* The string which was parsed to produce this */
343 /* url_spec. Used for debugging or display only. */
345 /* Hostname matching: */
346 char *domain; /* Fully qalified domain name (FQDN) pattern. */
347 /* May contain "*". */
348 char *dbuf; /* FIXME: Comment this */
349 char **dvec; /* Domain ptr vector */
350 int dcnt; /* How many domains in fqdn? */
351 int unanchored; /* Bitmap - flags are ANCHOR_LEFT and ANCHOR_RIGHT */
354 int port; /* The port number, or 0 to match all ports. */
357 char *path; /* The path prefix (if not using regex), or source */
359 int pathlen; /* ==strlen(path). Needed for prefix matching. */
361 regex_t *preg; /* Regex for matching path part */
365 #define ANCHOR_LEFT 1
366 #define ANCHOR_RIGHT 2
379 #define IOB_PEEK(CSP) ((CSP->iob->cur > CSP->iob->eod) ? (CSP->iob->eod - CSP->iob->cur) : 0)
380 #define IOB_RESET(CSP) if(CSP->iob->buf) free(CSP->iob->buf); memset(CSP->iob, '\0', sizeof(CSP->iob));
384 #define ACTION_MASK_ALL (~0U)
386 #define ACTION_MOST_COMPATIBLE 0x0000U
388 #define ACTION_BLOCK 0x0001U
389 #define ACTION_FAST_REDIRECTS 0x0002U
390 #define ACTION_FILTER 0x0004U
391 #define ACTION_HIDE_FORWARDED 0x0008U
392 #define ACTION_HIDE_FROM 0x0010U
393 #define ACTION_HIDE_REFERER 0x0020U /* sic - follow HTTP, not English */
394 #define ACTION_HIDE_USER_AGENT 0x0040U
395 #define ACTION_IMAGE 0x0080U
396 #define ACTION_IMAGE_BLOCKER 0x0100U
397 #define ACTION_NO_COOKIE_READ 0x0200U
398 #define ACTION_NO_COOKIE_SET 0x0400U
399 #define ACTION_NO_POPUPS 0x0800U
400 #define ACTION_VANILLA_WAFER 0x1000U
402 #define ACTION_STRING_FROM 0
403 #define ACTION_STRING_IMAGE_BLOCKER 1
404 #define ACTION_STRING_REFERER 2
405 #define ACTION_STRING_USER_AGENT 3
406 #define ACTION_STRING_COUNT 4
408 #define ACTION_MULTI_ADD_HEADER 0
409 #define ACTION_MULTI_WAFER 1
410 #define ACTION_MULTI_COUNT 2
413 * This structure contains a list of actions to apply to a URL.
414 * It only contains positive instructions - no "-" options.
415 * It is not used to store the actions list itself, only for
416 * url_actions() to return the current values.
418 struct current_action_spec
420 unsigned flags; /* a bit set to "1" = add action */
422 /* For those actions that require parameters: */
424 /* each entry is valid if & only if corresponding entry in "add" set. */
425 char * string[ACTION_STRING_COUNT];
428 struct list multi[ACTION_MULTI_COUNT][1];
433 * This structure contains a set of changes to actions.
434 * It can contain both positive and negative instructions.
435 * It is used to store an entry in the actions list.
439 unsigned mask; /* a bit set to "0" = remove action */
440 unsigned add; /* a bit set to "1" = add action */
442 /* For those actions that require parameters: */
444 /* each entry is valid if & only if corresponding entry in "add" set. */
445 char * string[ACTION_STRING_COUNT];
447 /* Strings to remove. */
448 struct list multi_remove[ACTION_MULTI_COUNT][1];
450 /* If nonzero, remove *all* strings. */
451 int multi_remove_all[ACTION_MULTI_COUNT];
454 struct list multi_add[ACTION_MULTI_COUNT][1];
458 * This structure is used to store the actions list.
460 * It contains a URL pattern, and the chages to the actions.
461 * It is a linked list.
465 struct url_spec url[1];
467 struct action_spec action[1];
469 struct url_actions * next;
473 /* Constants defining bitmask for csp->accept_types */
475 #ifdef DETECT_MSIE_IMAGES
477 /* MSIE detected by user-agent string */
478 #define ACCEPT_TYPE_IS_MSIE 0x0001
481 * *If* this is MSIE, it wants an image. (Or this is a shift-reload, or
482 * it's got an image from this URL before... yuck!)
483 * Only meaningful if ACCEPT_TYPE_IS_MSIE set
485 #define ACCEPT_TYPE_MSIE_IMAGE 0x0002
488 * *If* this is MSIE, it wants a HTML document.
489 * Only meaningful if ACCEPT_TYPE_IS_MSIE set
491 #define ACCEPT_TYPE_MSIE_HTML 0x0004
493 #endif /* def DETECT_MSIE_IMAGES */
498 /* The proxy's configuration */
499 struct configuration_spec * config;
502 /* The actions to perform on the current request */
503 struct current_action_spec action[1];
506 /* socket to talk to client (web browser) */
509 /* socket to talk to server (web server or proxy) */
514 /* 1 if this URL was rejected, 0 otherwise. Allows actual stats inc to
515 * occur in main thread only for thread-safety.
518 #endif /* def STATISTICS */
522 #endif /* def FORCE_LOAD */
526 #endif /* def TOGGLE */
529 * Client PC's IP address, as reported by the accept()_ function.
530 * Both as string and number
536 /* The referer in this request, if one was specified. */
538 #endif /* def TRUST_FILES */
540 #if defined(DETECT_MSIE_IMAGES)
541 /* Types the client will accept.
542 * Bitmask - see ACCEPT_TYPE_XXX constants.
545 #endif /* defined(DETECT_MSIE_IMAGES) */
547 /* The URL that was requested */
548 struct http_request http[1];
550 /* An I/O buffer used for buffering data read from the client */
553 /* List of all headers for this request */
554 struct list headers[1];
556 /* List of all cookies for this request */
557 struct list cookie_list[1];
559 #if defined(PCRS) || defined(KILLPOPUPS)
560 /* Nonzero if this has a text MIME type */
562 #endif /* defined(PCRS) || defined(KILLPOPUPS) */
564 /* The "X-Forwarded-For:" header sent by the client */
568 * Nonzero if this client is processing data.
569 * Set to zero when the thread associated with this structure dies.
573 /* files associated with this client */
574 struct file_list *actions_list;
577 struct file_list *rlist; /* Perl re_filterfile */
578 size_t content_length; /* Length after processing */
579 #endif /* def PCRS */
582 struct file_list *tlist; /* trustfile */
583 #endif /* def TRUST_FILES */
585 struct client_state *next;
593 char *(*parser)(const struct parsers *, char *, struct client_state *);
596 struct cgi_dispatcher
600 int (*handler)(struct client_state *csp, struct http_response *rsp, struct map *parameters);
601 const char *description;
607 * this is a pointer to the data structures associated with the file.
608 * Read-only once the structure has been created.
612 /* Normally NULL. When we are finished with file (i.e. when we have
613 * loaded a new one), set to a pointer to an unloader function.
614 * Unloader will be called by sweep() (called from main loop) when
615 * all clients using this file are done. This prevents threading
618 void (*unloader)(void *);
620 /* Used internally by sweep(). Do not access from elsewhere. */
623 #ifndef SPLIT_PROXY_ARGS
624 /* String to be displayed as part of show-proxy-args display.
625 * Read-only once the structure has been created.
628 #endif /* ndef SPLIT_PROXY_ARGS */
630 /* Following variables allow us to check if file has been changed.
631 * Read-only once the structure has been created.
636 /* Pointer to next entry in the linked list of all "file_list"s.
637 * This linked list is so that sweep() can navigate it.
638 * Since sweep() can remove items from the list, we must be careful
639 * to only access this value from main thread (when we know sweep
642 struct file_list *next;
649 struct url_spec url[1];
651 struct block_spec *next;
653 #endif /* def TRUST_FILES */
656 #define SOCKS_NONE 0 /* Don't use a SOCKS server */
657 #define SOCKS_4 40 /* original SOCKS 4 protocol */
658 #define SOCKS_4A 41 /* as modified for hosts w/o external DNS */
662 struct url_spec url[1];
664 /* Connection type - must be a SOCKS_xxx constant */
671 /* Parent HTTP proxy */
675 /* For the linked list */
676 struct forward_spec *next;
681 struct re_filterfile_spec
683 struct list patterns[1];
686 #endif /* def PCRS */
690 #define ACL_PERMIT 1 /* accept connection request */
691 #define ACL_DENY 2 /* reject connection request */
693 struct access_control_addr
700 struct access_control_list
702 struct access_control_addr src[1];
703 struct access_control_addr dst[1];
706 struct access_control_list *next;
708 #endif /* def ACL_FILES */
711 /* Maximum number of loaders (actions, re_filter, ...) */
715 * Data loaded from the configuration file.
717 * (Anomaly: toggle is still handled through a global, not this structure)
719 struct configuration_spec
728 const char *actions_file;
731 const char *re_filterfile;
732 #endif /* def PCRS */
735 const char * jarfile;
737 #endif /* def JAR_FILES */
740 * Port and IP to bind to.
741 * Defaults to HADDR_DEFAULT:HADDR_PORT == 127.0.0.1:8000
746 #ifndef SPLIT_PROXY_ARGS
747 const char *suppress_message;
748 #endif /* ndef SPLIT_PROXY_ARGS */
750 #ifndef SPLIT_PROXY_ARGS
751 /* suppress listing config files */
752 int suppress_blocklists;
753 #endif /* ndef SPLIT_PROXY_ARGS */
756 const char * trustfile;
758 struct list trust_info[1];
759 struct url_spec *trust_list[64];
760 #endif /* def TRUST_FILES */
763 struct access_control_list *acl;
764 #endif /* def ACL_FILES */
766 struct forward_spec *forward;
768 /* Various strings for show-proxy-args */
769 char *proxy_args_header;
770 char *proxy_args_invocation;
771 char *proxy_args_trailer;
773 /* the configuration file object. */
774 struct file_list *config_file_list;
776 /* List of loaders */
777 int (*loaders[NLOADERS])(struct client_state *);
779 /* bool, nonzero if we need to bind() to the new port */
784 #define SZ(X) (sizeof(X) / sizeof(*X))
786 #define WHITEBG "<body bgcolor=\"#ffffff\" link=\"#000078\" alink=\"#ff0022\" vlink=\"#787878\">\n"
787 #define BODY "<body bgcolor=\"#f8f8f0\" link=\"#000078\" alink=\"#ff0022\" vlink=\"#787878\">\n"
788 #define BANNER "<strong>Internet J<small>UNK<i><font color=\"red\">BUSTER</font></i></small></strong>"
791 #define FORCE_PREFIX "/IJB-FORCE-LOAD"
792 #endif /* def FORCE_LOAD */
794 /* Shouldn't end with '/' */
795 #define HOME_PAGE_URL "http://ijbswa.sourceforge.net"
796 #define REDIRECT_URL HOME_PAGE_URL "/redirect.php?v=" VERSION "&to="
798 #define CGI_PREFIX_HOST "i.j.b"
800 static const char CSUCCEED[] =
801 "HTTP/1.0 200 Connection established\n"
802 "Proxy-Agent: IJ/" VERSION "\n\n";
804 static const char CHEADER[] =
805 "HTTP/1.0 400 Invalid header received from browser\n\n";
807 static const char SHEADER[] =
808 "HTTP/1.0 502 Invalid header received from server\n\n";
810 #ifdef IMAGE_BLOCKING
813 * Hint: You can encode your own GIFs like that:
814 * perl -e 'while (read STDIN, $c, 1) { printf("\\%.3o,", unpack("C", $c)); }'
817 static const char BLANKGIF[] =
818 "HTTP/1.0 200 OK\r\n"
819 "Pragma: no-cache\r\n"
820 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
821 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
822 "Content-type: image/gif\r\n\r\n"
823 "GIF89a\001\000\001\000\200\000\000\377\377\377\000\000"
824 "\000!\371\004\001\000\000\000\000,\000\000\000\000\001"
825 "\000\001\000\000\002\002D\001\000;";
827 static const char JBGIF[] =
828 "HTTP/1.0 200 OK\r\n"
829 "Pragma: no-cache\r\n"
830 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
831 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
832 "Content-type: image/gif\r\n\r\n"
833 "GIF89aD\000\013\000\360\000\000\000\000\000\377\377\377!"
834 "\371\004\001\000\000\001\000,\000\000\000\000D\000\013\000"
835 "\000\002a\214\217\251\313\355\277\000\200G&K\025\316hC\037"
836 "\200\234\230Y\2309\235S\230\266\206\372J\253<\3131\253\271"
837 "\270\215\342\254\013\203\371\202\264\334P\207\332\020o\266"
838 "N\215I\332=\211\312\3513\266:\026AK)\364\370\365aobr\305"
839 "\372\003S\275\274k2\354\254z\347?\335\274x\306^9\374\276"
842 #endif /* def IMAGE_BLOCKING */
844 #if defined(FAST_REDIRECTS) || defined(IMAGE_BLOCKING)
846 static const char HTTP_REDIRECT_TEMPLATE[] =
847 "HTTP/1.0 302 Local Redirect from Junkbuster\r\n"
848 "Pragma: no-cache\r\n"
849 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
850 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
851 "Location: %s\r\n\r\n";
853 #endif /* defined(FAST_REDIRECTS) || defined(IMAGE_BLOCKING) */
859 #endif /* ndef _PROJECT_H */