3 #define PROJECT_H_VERSION "$Id: project.h,v 1.15 2001/06/04 11:28:53 swa 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.15 2001/06/04 11:28:53 swa
40 * redirect did not work due to missing /
42 * Revision 1.14 2001/06/03 11:03:48 oes
49 * adapted to new enlist_unique arg format
53 * introduced confdir option
55 * filters.c filtrers.h
57 * extracted-CGI relevant stuff
65 * support for new cgi mechansim
69 * functions for new list type: "map"
70 * extended enlist_unique
77 * deleted const struct interceptors
85 * added struct http_response
86 * changes struct interceptors to struct cgi_dispatcher
87 * moved HTML stuff to cgi.h
96 * Revision 1.13 2001/06/01 20:05:36 jongfoster
97 * Support for +image-blocker{}: added ACTION_IMAGE_BLOCKER
98 * constant, and removed csp->tinygif.
100 * Revision 1.12 2001/06/01 18:49:17 jongfoster
101 * Replaced "list_share" with "list" - the tiny memory gain was not
102 * worth the extra complexity.
104 * Revision 1.11 2001/06/01 10:32:47 oes
105 * Added constants for anchoring selection bitmap
107 * Revision 1.10 2001/05/31 21:33:53 jongfoster
108 * Changes for new actions file, replacing permissionsfile
109 * and parts of the config file. Also added support for
112 * Revision 1.9 2001/05/31 17:32:31 oes
114 * - Enhanced domain part globbing with infix and prefix asterisk
115 * matching and optional unanchored operation
117 * Revision 1.8 2001/05/29 20:09:15 joergs
118 * HTTP_REDIRECT_TEMPLATE fixed.
120 * Revision 1.7 2001/05/29 09:50:24 jongfoster
121 * Unified blocklist/imagelist/actionslist.
122 * File format is still under discussion, but the internal changes
125 * Also modified interceptor behaviour:
126 * - We now intercept all URLs beginning with one of the following
127 * prefixes (and *only* these prefixes):
129 * * http://ijbswa.sf.net/config/
130 * * http://ijbswa.sourceforge.net/config/
131 * - New interceptors "home page" - go to http://i.j.b/ to see it.
132 * - Internal changes so that intercepted and fast redirect pages
133 * are not replaced with an image.
134 * - Interceptors now have the option to send a binary page direct
135 * to the client. (i.e. ijb-send-banner uses this)
136 * - Implemented show-url-info interceptor. (Which is why I needed
137 * the above interceptors changes - a typical URL is
138 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
139 * The previous mechanism would not have intercepted that, and
140 * if it had been intercepted then it then it would have replaced
143 * Revision 1.6 2001/05/27 22:17:04 oes
145 * - re_process_buffer no longer writes the modified buffer
146 * to the client, which was very ugly. It now returns the
147 * buffer, which it is then written by chat.
149 * - content_length now adjusts the Content-Length: header
150 * for modified documents rather than crunch()ing it.
151 * (Length info in csp->content_length, which is 0 for
152 * unmodified documents)
154 * - For this to work, sed() is called twice when filtering.
156 * Revision 1.5 2001/05/26 00:28:36 jongfoster
157 * Automatic reloading of config file.
158 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
159 * Most of the global variables have been moved to a new
160 * struct configuration_spec, accessed through csp->config->globalname
161 * Most of the globals remaining are used by the Win32 GUI.
163 * Revision 1.4 2001/05/22 18:46:04 oes
165 * - Enabled filtering banners by size rather than URL
166 * by adding patterns that replace all standard banner
167 * sizes with the "Junkbuster" gif to the re_filterfile
169 * - Enabled filtering WebBugs by providing a pattern
170 * which kills all 1x1 images
172 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
173 * which is selected by the (nonstandard and therefore
174 * capital) letter 'U' in the option string.
175 * It causes the quantifiers to be ungreedy by default.
176 * Appending a ? turns back to greedy (!).
178 * - Added a new interceptor ijb-send-banner, which
179 * sends back the "Junkbuster" gif. Without imagelist or
180 * MSIE detection support, or if tinygif = 1, or the
181 * URL isn't recognized as an imageurl, a lame HTML
182 * explanation is sent instead.
184 * - Added new feature, which permits blocking remote
185 * script redirects and firing back a local redirect
187 * The feature is conditionally compiled, i.e. it
188 * can be disabled with --disable-fast-redirects,
189 * plus it must be activated by a "fast-redirects"
190 * line in the config file, has its own log level
191 * and of course wants to be displayed by show-proxy-args
192 * Note: Boy, all the #ifdefs in 1001 locations and
193 * all the fumbling with configure.in and acconfig.h
194 * were *way* more work than the feature itself :-(
196 * - Because a generic redirect template was needed for
197 * this, tinygif = 3 now uses the same.
199 * - Moved GIFs, and other static HTTP response templates
204 * - Removed some >400 CRs again (Jon, you really worked
207 * Revision 1.3 2001/05/20 01:21:20 jongfoster
208 * Version 2.9.4 checkin.
209 * - Merged popupfile and cookiefile, and added control over PCRS
210 * filtering, in new "actionsfile".
211 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
212 * file error you now get a message box (in the Win32 GUI) rather
213 * than the program exiting with no explanation.
214 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
216 * - Removed tabs from "config"
217 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
218 * - Bumped up version number.
220 * Revision 1.2 2001/05/17 23:01:01 oes
221 * - Cleaned CRLF's from the sources and related files
223 * Revision 1.1.1.1 2001/05/15 13:59:03 oes
224 * Initial import of version 2.9.3 source tree
227 *********************************************************************/
230 /* Declare struct FILE for vars and funcs. */
233 /* Need time_t for file_list */
237 * Include appropriate regular expression libraries.
239 * PCRS ==> Include pcre
240 * REGEX && PCRE ==> Include pcre and pcreposix
241 * REGEX && !PCRE ==> Include gnu_regex
243 * STATIC ==> Use #include "pcre.h" (compiling at same time)
244 * !STATIC ==> Use #include <pcre.h> (System library)
247 #if (defined(REGEX) && defined(PCRE)) || defined(PCRS)
253 #endif /* (defined(REGEX) && defined(PCRE)) || defined(PCRS) */
255 #if defined(REGEX) && defined(PCRE)
257 # include "pcreposix.h"
259 # include <pcreposix.h>
261 #endif /* defined(REGEX) && defined(PCRE) */
263 #if defined(REGEX) && !defined(PCRE)
264 # include "gnu_regex.h"
269 #endif /* def PCRS */
273 #endif /* def AMIGA */
281 /* Default IP and port to listen on */
282 #define HADDR_DEFAULT "127.0.0.1"
283 #define HADDR_PORT 8000
286 /* Need this for struct gateway */
289 /* Need this for struct client_state */
290 struct configuration_spec;
292 /* Generic linked list of strings */
293 struct list /* FIXME: Why not separate entries and header? */
295 char * str; /* valid in an entry */
296 struct list *last; /* valid in header */
308 /* Generic linked list of strings */
309 struct list_share /* FIXME: Why not separate entries and header? */
311 const char * str; /* valid in an entry */
312 struct list_share *last; /* valid in header */
313 struct list_share *next;
324 char *hostport; /* "host[:port]" */
328 /* CGI or blocker generated response */
331 char *status; /* HTTP status */
332 struct list headers[1]; /* List of header lines */
333 int content_length; /* Length of body, REQUIRED if binary body*/
334 char *head; /* Formatted http response head */
335 char *body; /* HTTP document body */
340 /* generic attributes */
342 int (*conn)(const struct gateway *, struct http_request *, struct client_state *);
345 /* domain specific attributes */
358 char *domain; /* fqdn */
360 char **dvec; /* Domain ptr vector */
361 int dcnt; /* How many domains in fqdn? */
362 int unanchored; /* bitmap 0: left, 1: right */
372 #define ANCHOR_LEFT 1
373 #define ANCHOR_RIGHT 2
386 #define IOB_PEEK(CSP) ((CSP->iob->cur > CSP->iob->eod) ? (CSP->iob->eod - CSP->iob->cur) : 0)
387 #define IOB_RESET(CSP) if(CSP->iob->buf) free(CSP->iob->buf); memset(CSP->iob, '\0', sizeof(CSP->iob));
391 #define ACTION_MASK_ALL (~0U)
393 #define ACTION_MOST_COMPATIBLE 0U
395 #define ACTION_BLOCK 0x0001U
396 #define ACTION_FAST_REDIRECTS 0x0002U
397 #define ACTION_FILTER 0x0004U
398 #define ACTION_HIDE_FORWARDED 0x0008U
399 #define ACTION_HIDE_FROM 0x0010U
400 #define ACTION_HIDE_REFERER 0x0020U /* sic - follow HTTP, not English */
401 #define ACTION_HIDE_USER_AGENT 0x0040U
402 #define ACTION_IMAGE 0x0080U
403 #define ACTION_IMAGE_BLOCKER 0x0100U
404 #define ACTION_NO_COOKIE_READ 0x0200U
405 #define ACTION_NO_COOKIE_SET 0x0400U
406 #define ACTION_NO_POPUPS 0x0800U
407 #define ACTION_VANILLA_WAFER 0x1000U
409 #define ACTION_STRING_FROM 0
410 #define ACTION_STRING_IMAGE_BLOCKER 1
411 #define ACTION_STRING_REFERER 2
412 #define ACTION_STRING_USER_AGENT 3
413 #define ACTION_STRING_COUNT 4
415 #define ACTION_MULTI_ADD_HEADER 0
416 #define ACTION_MULTI_WAFER 1
417 #define ACTION_MULTI_COUNT 2
420 struct current_action_spec
422 unsigned flags; /* a bit set to "1" = add action */
424 /* For those actions that require parameters: */
426 /* each entry is valid if & only if corresponding entry in "add" set. */
427 char * string[ACTION_STRING_COUNT];
430 struct list multi[ACTION_MULTI_COUNT][1];
435 unsigned mask; /* a bit set to "0" = remove action */
436 unsigned add; /* a bit set to "1" = add action */
438 /* For those actions that require parameters: */
440 /* each entry is valid if & only if corresponding entry in "add" set. */
441 char * string[ACTION_STRING_COUNT];
443 /* Strings to remove. */
444 struct list multi_remove[ACTION_MULTI_COUNT][1];
446 /* If nonzero, remove *all* strings. */
447 int multi_remove_all[ACTION_MULTI_COUNT];
450 struct list multi_add[ACTION_MULTI_COUNT][1];
455 struct url_spec url[1];
457 struct action_spec action[1];
459 struct url_actions * next;
463 /* Constants defining bitmask for csp->accept_types */
465 #ifdef DETECT_MSIE_IMAGES
467 /* MSIE detected by user-agent string */
468 #define ACCEPT_TYPE_IS_MSIE 0x0001
471 * *If* this is MSIE, it wants an image. (Or this is a shift-reload, or
472 * it's got an image from this URL before... yuck!)
473 * Only meaningful if ACCEPT_TYPE_IS_MSIE set
475 #define ACCEPT_TYPE_MSIE_IMAGE 0x0002
478 * *If* this is MSIE, it wants a HTML document.
479 * Only meaningful if ACCEPT_TYPE_IS_MSIE set
481 #define ACCEPT_TYPE_MSIE_HTML 0x0004
483 #endif /* def DETECT_MSIE_IMAGES */
488 /* The proxy's configuration */
489 struct configuration_spec * config;
492 /* The actions to perform on the current request */
493 struct current_action_spec action[1];
496 /* socket to talk to client (web browser) */
499 /* socket to talk to server (web server or proxy) */
504 /* 1 if this URL was rejected, 0 otherwise. Allows actual stats inc to
505 * occur in main thread only for thread-safety.
508 #endif /* def STATISTICS */
512 #endif /* def FORCE_LOAD */
516 #endif /* def TOGGLE */
519 * Client PC's IP address, as reported by the accept()_ function.
520 * Both as string and number
526 /* The referer in this request, if one was specified. */
528 #endif /* def TRUST_FILES */
530 #if defined(DETECT_MSIE_IMAGES)
531 /* Types the client will accept.
532 * Bitmask - see ACCEPT_TYPE_XXX constants.
535 #endif /* defined(DETECT_MSIE_IMAGES) */
537 /* The URL that was requested */
538 struct http_request http[1];
540 /* An I/O buffer used for buffering data read from the client */
543 /* List of all headers for this request */
544 struct list headers[1];
546 /* List of all cookies for this request */
547 struct list cookie_list[1];
549 #if defined(PCRS) || defined(KILLPOPUPS)
550 /* Nonzero if this has a text MIME type */
552 #endif /* defined(PCRS) || defined(KILLPOPUPS) */
554 /* The "X-Forwarded-For:" header sent by the client */
558 * Nonzero if this client is processing data.
559 * Set to zero when the thread associated with this structure dies.
563 /* files associated with this client */
564 struct file_list *flist; /* forwardfile */
565 struct file_list *actions_list;
569 struct file_list *alist; /* aclfile */
570 #endif /* def ACL_FILES */
573 struct file_list *rlist; /* Perl re_filterfile */
574 size_t content_length; /* Length after processing */
575 #endif /* def PCRS */
578 struct file_list *tlist; /* trustfile */
579 #endif /* def TRUST_FILES */
581 struct client_state *next;
589 char *(*parser)(const struct parsers *, char *, struct client_state *);
592 struct cgi_dispatcher
596 int (*handler)(struct client_state *csp, struct http_response *rsp, struct map *parameters);
603 * this is a pointer to the data structures associated with the file.
604 * Read-only once the structure has been created.
608 /* Normally NULL. When we are finished with file (i.e. when we have
609 * loaded a new one), set to a pointer to an unloader function.
610 * Unloader will be called by sweep() (called from main loop) when
611 * all clients using this file are done. This prevents threading
614 void (*unloader)(void *);
616 /* Used internally by sweep(). Do not access from elsewhere. */
619 #ifndef SPLIT_PROXY_ARGS
620 /* String to be displayed as part of show-proxy-args display.
621 * Read-only once the structure has been created.
624 #endif /* ndef SPLIT_PROXY_ARGS */
626 /* Following variables allow us to check if file has been changed.
627 * Read-only once the structure has been created.
632 /* Pointer to next entry in the linked list of all "file_list"s.
633 * This linked list is so that sweep() can navigate it.
634 * Since sweep() can remove items from the list, we must be careful
635 * to only access this value from main thread (when we know sweep
638 struct file_list *next;
645 struct url_spec url[1];
647 struct block_spec *next;
649 #endif /* def TRUST_FILES */
654 struct url_spec url[1];
655 struct gateway gw[1];
656 struct forward_spec *next;
661 struct re_filterfile_spec
663 struct list patterns[1];
666 #endif /* def PCRS */
670 #define ACL_PERMIT 1 /* accept connection request */
671 #define ACL_DENY 2 /* reject connection request */
673 struct access_control_addr
680 struct access_control_list
682 struct access_control_addr src[1];
683 struct access_control_addr dst[1];
686 struct access_control_list *next;
688 #endif /* def ACL_FILES */
691 /* Maximum number of loaders (actions, block, forward, acl...) */
695 * Data loaded from the configuration file.
697 * (Anomaly: toggle is still handled through a global, not this structure)
699 struct configuration_spec
708 const char *actions_file;
709 const char *forwardfile;
713 #endif /* def ACL_FILES */
716 const char *re_filterfile;
717 #endif /* def PCRS */
720 const char * jarfile;
722 #endif /* def JAR_FILES */
725 * Port and IP to bind to.
726 * Defaults to HADDR_DEFAULT:HADDR_PORT == 127.0.0.1:8000
731 #ifndef SPLIT_PROXY_ARGS
732 const char *suppress_message;
733 #endif /* ndef SPLIT_PROXY_ARGS */
735 #ifndef SPLIT_PROXY_ARGS
736 /* suppress listing config files */
737 int suppress_blocklists;
738 #endif /* ndef SPLIT_PROXY_ARGS */
741 const char * trustfile;
743 struct list trust_info[1];
744 struct url_spec *trust_list[64];
745 #endif /* def TRUST_FILES */
747 /* Various strings for show-proxy-args */
748 char *proxy_args_header;
749 char *proxy_args_invocation;
750 char *proxy_args_gateways;
751 char *proxy_args_trailer;
753 /* the configuration file object. */
754 struct file_list *config_file_list;
756 /* List of loaders */
757 int (*loaders[NLOADERS])(struct client_state *);
759 /* bool, nonzero if we need to bind() to the new port */
764 #define SZ(X) (sizeof(X) / sizeof(*X))
766 #define WHITEBG "<body bgcolor=\"#ffffff\" link=\"#000078\" alink=\"#ff0022\" vlink=\"#787878\">\n"
767 #define BODY "<body bgcolor=\"#f8f8f0\" link=\"#000078\" alink=\"#ff0022\" vlink=\"#787878\">\n"
768 #define BANNER "<strong>Internet J<small>UNK<i><font color=\"red\">BUSTER</font></i></small></strong>"
771 #define FORCE_PREFIX "/IJB-FORCE-LOAD"
772 #endif /* def FORCE_LOAD */
774 /* Shouldn't end with '/' */
775 #define HOME_PAGE_URL "http://ijbswa.sourceforge.net"
776 #define REDIRECT_URL HOME_PAGE_URL "/redirect.php?v=" VERSION "&to="
778 #define CGI_PREFIX_HOST "i.j.b"
780 static const char CSUCCEED[] =
781 "HTTP/1.0 200 Connection established\n"
782 "Proxy-Agent: IJ/" VERSION "\n\n";
784 static const char CHEADER[] =
785 "HTTP/1.0 400 Invalid header received from browser\n\n";
787 static const char SHEADER[] =
788 "HTTP/1.0 502 Invalid header received from server\n\n";
790 #ifdef IMAGE_BLOCKING
793 * Hint: You can encode your own GIFs like that:
794 * perl -e 'while (read STDIN, $c, 1) { printf("\\%.3o,", unpack("C", $c)); }'
797 static const char BLANKGIF[] =
798 "HTTP/1.0 200 OK\r\n"
799 "Pragma: no-cache\r\n"
800 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
801 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
802 "Content-type: image/gif\r\n\r\n"
803 "GIF89a\001\000\001\000\200\000\000\377\377\377\000\000"
804 "\000!\371\004\001\000\000\000\000,\000\000\000\000\001"
805 "\000\001\000\000\002\002D\001\000;";
807 static const char JBGIF[] =
808 "HTTP/1.0 200 OK\r\n"
809 "Pragma: no-cache\r\n"
810 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
811 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
812 "Content-type: image/gif\r\n\r\n"
813 "GIF89aD\000\013\000\360\000\000\000\000\000\377\377\377!"
814 "\371\004\001\000\000\001\000,\000\000\000\000D\000\013\000"
815 "\000\002a\214\217\251\313\355\277\000\200G&K\025\316hC\037"
816 "\200\234\230Y\2309\235S\230\266\206\372J\253<\3131\253\271"
817 "\270\215\342\254\013\203\371\202\264\334P\207\332\020o\266"
818 "N\215I\332=\211\312\3513\266:\026AK)\364\370\365aobr\305"
819 "\372\003S\275\274k2\354\254z\347?\335\274x\306^9\374\276"
822 #endif /* def IMAGE_BLOCKING */
824 #if defined(FAST_REDIRECTS) || defined(IMAGE_BLOCKING)
826 static const char HTTP_REDIRECT_TEMPLATE[] =
827 "HTTP/1.0 302 Local Redirect from Junkbuster\r\n"
828 "Pragma: no-cache\r\n"
829 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
830 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
831 "Location: %s\r\n\r\n";
833 #endif /* defined(FAST_REDIRECTS) || defined(IMAGE_BLOCKING) */
839 #endif /* ndef _PROJECT_H */