3 #define PROJECT_H_VERSION "$Id: project.h,v 1.14 2001/06/03 11:03:48 oes 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.14 2001/06/03 11:03:48 oes
46 * adapted to new enlist_unique arg format
50 * introduced confdir option
52 * filters.c filtrers.h
54 * extracted-CGI relevant stuff
62 * support for new cgi mechansim
66 * functions for new list type: "map"
67 * extended enlist_unique
74 * deleted const struct interceptors
82 * added struct http_response
83 * changes struct interceptors to struct cgi_dispatcher
84 * moved HTML stuff to cgi.h
93 * Revision 1.13 2001/06/01 20:05:36 jongfoster
94 * Support for +image-blocker{}: added ACTION_IMAGE_BLOCKER
95 * constant, and removed csp->tinygif.
97 * Revision 1.12 2001/06/01 18:49:17 jongfoster
98 * Replaced "list_share" with "list" - the tiny memory gain was not
99 * worth the extra complexity.
101 * Revision 1.11 2001/06/01 10:32:47 oes
102 * Added constants for anchoring selection bitmap
104 * Revision 1.10 2001/05/31 21:33:53 jongfoster
105 * Changes for new actions file, replacing permissionsfile
106 * and parts of the config file. Also added support for
109 * Revision 1.9 2001/05/31 17:32:31 oes
111 * - Enhanced domain part globbing with infix and prefix asterisk
112 * matching and optional unanchored operation
114 * Revision 1.8 2001/05/29 20:09:15 joergs
115 * HTTP_REDIRECT_TEMPLATE fixed.
117 * Revision 1.7 2001/05/29 09:50:24 jongfoster
118 * Unified blocklist/imagelist/actionslist.
119 * File format is still under discussion, but the internal changes
122 * Also modified interceptor behaviour:
123 * - We now intercept all URLs beginning with one of the following
124 * prefixes (and *only* these prefixes):
126 * * http://ijbswa.sf.net/config/
127 * * http://ijbswa.sourceforge.net/config/
128 * - New interceptors "home page" - go to http://i.j.b/ to see it.
129 * - Internal changes so that intercepted and fast redirect pages
130 * are not replaced with an image.
131 * - Interceptors now have the option to send a binary page direct
132 * to the client. (i.e. ijb-send-banner uses this)
133 * - Implemented show-url-info interceptor. (Which is why I needed
134 * the above interceptors changes - a typical URL is
135 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
136 * The previous mechanism would not have intercepted that, and
137 * if it had been intercepted then it then it would have replaced
140 * Revision 1.6 2001/05/27 22:17:04 oes
142 * - re_process_buffer no longer writes the modified buffer
143 * to the client, which was very ugly. It now returns the
144 * buffer, which it is then written by chat.
146 * - content_length now adjusts the Content-Length: header
147 * for modified documents rather than crunch()ing it.
148 * (Length info in csp->content_length, which is 0 for
149 * unmodified documents)
151 * - For this to work, sed() is called twice when filtering.
153 * Revision 1.5 2001/05/26 00:28:36 jongfoster
154 * Automatic reloading of config file.
155 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
156 * Most of the global variables have been moved to a new
157 * struct configuration_spec, accessed through csp->config->globalname
158 * Most of the globals remaining are used by the Win32 GUI.
160 * Revision 1.4 2001/05/22 18:46:04 oes
162 * - Enabled filtering banners by size rather than URL
163 * by adding patterns that replace all standard banner
164 * sizes with the "Junkbuster" gif to the re_filterfile
166 * - Enabled filtering WebBugs by providing a pattern
167 * which kills all 1x1 images
169 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
170 * which is selected by the (nonstandard and therefore
171 * capital) letter 'U' in the option string.
172 * It causes the quantifiers to be ungreedy by default.
173 * Appending a ? turns back to greedy (!).
175 * - Added a new interceptor ijb-send-banner, which
176 * sends back the "Junkbuster" gif. Without imagelist or
177 * MSIE detection support, or if tinygif = 1, or the
178 * URL isn't recognized as an imageurl, a lame HTML
179 * explanation is sent instead.
181 * - Added new feature, which permits blocking remote
182 * script redirects and firing back a local redirect
184 * The feature is conditionally compiled, i.e. it
185 * can be disabled with --disable-fast-redirects,
186 * plus it must be activated by a "fast-redirects"
187 * line in the config file, has its own log level
188 * and of course wants to be displayed by show-proxy-args
189 * Note: Boy, all the #ifdefs in 1001 locations and
190 * all the fumbling with configure.in and acconfig.h
191 * were *way* more work than the feature itself :-(
193 * - Because a generic redirect template was needed for
194 * this, tinygif = 3 now uses the same.
196 * - Moved GIFs, and other static HTTP response templates
201 * - Removed some >400 CRs again (Jon, you really worked
204 * Revision 1.3 2001/05/20 01:21:20 jongfoster
205 * Version 2.9.4 checkin.
206 * - Merged popupfile and cookiefile, and added control over PCRS
207 * filtering, in new "actionsfile".
208 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
209 * file error you now get a message box (in the Win32 GUI) rather
210 * than the program exiting with no explanation.
211 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
213 * - Removed tabs from "config"
214 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
215 * - Bumped up version number.
217 * Revision 1.2 2001/05/17 23:01:01 oes
218 * - Cleaned CRLF's from the sources and related files
220 * Revision 1.1.1.1 2001/05/15 13:59:03 oes
221 * Initial import of version 2.9.3 source tree
224 *********************************************************************/
227 /* Declare struct FILE for vars and funcs. */
230 /* Need time_t for file_list */
234 * Include appropriate regular expression libraries.
236 * PCRS ==> Include pcre
237 * REGEX && PCRE ==> Include pcre and pcreposix
238 * REGEX && !PCRE ==> Include gnu_regex
240 * STATIC ==> Use #include "pcre.h" (compiling at same time)
241 * !STATIC ==> Use #include <pcre.h> (System library)
244 #if (defined(REGEX) && defined(PCRE)) || defined(PCRS)
250 #endif /* (defined(REGEX) && defined(PCRE)) || defined(PCRS) */
252 #if defined(REGEX) && defined(PCRE)
254 # include "pcreposix.h"
256 # include <pcreposix.h>
258 #endif /* defined(REGEX) && defined(PCRE) */
260 #if defined(REGEX) && !defined(PCRE)
261 # include "gnu_regex.h"
266 #endif /* def PCRS */
270 #endif /* def AMIGA */
278 /* Default IP and port to listen on */
279 #define HADDR_DEFAULT "127.0.0.1"
280 #define HADDR_PORT 8000
283 /* Need this for struct gateway */
286 /* Need this for struct client_state */
287 struct configuration_spec;
289 /* Generic linked list of strings */
290 struct list /* FIXME: Why not separate entries and header? */
292 char * str; /* valid in an entry */
293 struct list *last; /* valid in header */
305 /* Generic linked list of strings */
306 struct list_share /* FIXME: Why not separate entries and header? */
308 const char * str; /* valid in an entry */
309 struct list_share *last; /* valid in header */
310 struct list_share *next;
321 char *hostport; /* "host[:port]" */
325 /* CGI or blocker generated response */
328 char *status; /* HTTP status */
329 struct list headers[1]; /* List of header lines */
330 int content_length; /* Length of body, REQUIRED if binary body*/
331 char *head; /* Formatted http response head */
332 char *body; /* HTTP document body */
337 /* generic attributes */
339 int (*conn)(const struct gateway *, struct http_request *, struct client_state *);
342 /* domain specific attributes */
355 char *domain; /* fqdn */
357 char **dvec; /* Domain ptr vector */
358 int dcnt; /* How many domains in fqdn? */
359 int unanchored; /* bitmap 0: left, 1: right */
369 #define ANCHOR_LEFT 1
370 #define ANCHOR_RIGHT 2
383 #define IOB_PEEK(CSP) ((CSP->iob->cur > CSP->iob->eod) ? (CSP->iob->eod - CSP->iob->cur) : 0)
384 #define IOB_RESET(CSP) if(CSP->iob->buf) free(CSP->iob->buf); memset(CSP->iob, '\0', sizeof(CSP->iob));
388 #define ACTION_MASK_ALL (~0U)
390 #define ACTION_MOST_COMPATIBLE 0U
392 #define ACTION_BLOCK 0x0001U
393 #define ACTION_FAST_REDIRECTS 0x0002U
394 #define ACTION_FILTER 0x0004U
395 #define ACTION_HIDE_FORWARDED 0x0008U
396 #define ACTION_HIDE_FROM 0x0010U
397 #define ACTION_HIDE_REFERER 0x0020U /* sic - follow HTTP, not English */
398 #define ACTION_HIDE_USER_AGENT 0x0040U
399 #define ACTION_IMAGE 0x0080U
400 #define ACTION_IMAGE_BLOCKER 0x0100U
401 #define ACTION_NO_COOKIE_READ 0x0200U
402 #define ACTION_NO_COOKIE_SET 0x0400U
403 #define ACTION_NO_POPUPS 0x0800U
404 #define ACTION_VANILLA_WAFER 0x1000U
406 #define ACTION_STRING_FROM 0
407 #define ACTION_STRING_IMAGE_BLOCKER 1
408 #define ACTION_STRING_REFERER 2
409 #define ACTION_STRING_USER_AGENT 3
410 #define ACTION_STRING_COUNT 4
412 #define ACTION_MULTI_ADD_HEADER 0
413 #define ACTION_MULTI_WAFER 1
414 #define ACTION_MULTI_COUNT 2
417 struct current_action_spec
419 unsigned flags; /* a bit set to "1" = add action */
421 /* For those actions that require parameters: */
423 /* each entry is valid if & only if corresponding entry in "add" set. */
424 char * string[ACTION_STRING_COUNT];
427 struct list multi[ACTION_MULTI_COUNT][1];
432 unsigned mask; /* a bit set to "0" = remove action */
433 unsigned add; /* a bit set to "1" = add action */
435 /* For those actions that require parameters: */
437 /* each entry is valid if & only if corresponding entry in "add" set. */
438 char * string[ACTION_STRING_COUNT];
440 /* Strings to remove. */
441 struct list multi_remove[ACTION_MULTI_COUNT][1];
443 /* If nonzero, remove *all* strings. */
444 int multi_remove_all[ACTION_MULTI_COUNT];
447 struct list multi_add[ACTION_MULTI_COUNT][1];
452 struct url_spec url[1];
454 struct action_spec action[1];
456 struct url_actions * next;
460 /* Constants defining bitmask for csp->accept_types */
462 #ifdef DETECT_MSIE_IMAGES
464 /* MSIE detected by user-agent string */
465 #define ACCEPT_TYPE_IS_MSIE 0x0001
468 * *If* this is MSIE, it wants an image. (Or this is a shift-reload, or
469 * it's got an image from this URL before... yuck!)
470 * Only meaningful if ACCEPT_TYPE_IS_MSIE set
472 #define ACCEPT_TYPE_MSIE_IMAGE 0x0002
475 * *If* this is MSIE, it wants a HTML document.
476 * Only meaningful if ACCEPT_TYPE_IS_MSIE set
478 #define ACCEPT_TYPE_MSIE_HTML 0x0004
480 #endif /* def DETECT_MSIE_IMAGES */
485 /* The proxy's configuration */
486 struct configuration_spec * config;
489 /* The actions to perform on the current request */
490 struct current_action_spec action[1];
493 /* socket to talk to client (web browser) */
496 /* socket to talk to server (web server or proxy) */
501 /* 1 if this URL was rejected, 0 otherwise. Allows actual stats inc to
502 * occur in main thread only for thread-safety.
505 #endif /* def STATISTICS */
509 #endif /* def FORCE_LOAD */
513 #endif /* def TOGGLE */
516 * Client PC's IP address, as reported by the accept()_ function.
517 * Both as string and number
523 /* The referer in this request, if one was specified. */
525 #endif /* def TRUST_FILES */
527 #if defined(DETECT_MSIE_IMAGES)
528 /* Types the client will accept.
529 * Bitmask - see ACCEPT_TYPE_XXX constants.
532 #endif /* defined(DETECT_MSIE_IMAGES) */
534 /* The URL that was requested */
535 struct http_request http[1];
537 /* An I/O buffer used for buffering data read from the client */
540 /* List of all headers for this request */
541 struct list headers[1];
543 /* List of all cookies for this request */
544 struct list cookie_list[1];
546 #if defined(PCRS) || defined(KILLPOPUPS)
547 /* Nonzero if this has a text MIME type */
549 #endif /* defined(PCRS) || defined(KILLPOPUPS) */
551 /* The "X-Forwarded-For:" header sent by the client */
555 * Nonzero if this client is processing data.
556 * Set to zero when the thread associated with this structure dies.
560 /* files associated with this client */
561 struct file_list *flist; /* forwardfile */
562 struct file_list *actions_list;
566 struct file_list *alist; /* aclfile */
567 #endif /* def ACL_FILES */
570 struct file_list *rlist; /* Perl re_filterfile */
571 size_t content_length; /* Length after processing */
572 #endif /* def PCRS */
575 struct file_list *tlist; /* trustfile */
576 #endif /* def TRUST_FILES */
578 struct client_state *next;
586 char *(*parser)(const struct parsers *, char *, struct client_state *);
589 struct cgi_dispatcher
593 int (*handler)(struct client_state *csp, struct http_response *rsp, struct map *parameters);
600 * this is a pointer to the data structures associated with the file.
601 * Read-only once the structure has been created.
605 /* Normally NULL. When we are finished with file (i.e. when we have
606 * loaded a new one), set to a pointer to an unloader function.
607 * Unloader will be called by sweep() (called from main loop) when
608 * all clients using this file are done. This prevents threading
611 void (*unloader)(void *);
613 /* Used internally by sweep(). Do not access from elsewhere. */
616 #ifndef SPLIT_PROXY_ARGS
617 /* String to be displayed as part of show-proxy-args display.
618 * Read-only once the structure has been created.
621 #endif /* ndef SPLIT_PROXY_ARGS */
623 /* Following variables allow us to check if file has been changed.
624 * Read-only once the structure has been created.
629 /* Pointer to next entry in the linked list of all "file_list"s.
630 * This linked list is so that sweep() can navigate it.
631 * Since sweep() can remove items from the list, we must be careful
632 * to only access this value from main thread (when we know sweep
635 struct file_list *next;
642 struct url_spec url[1];
644 struct block_spec *next;
646 #endif /* def TRUST_FILES */
651 struct url_spec url[1];
652 struct gateway gw[1];
653 struct forward_spec *next;
658 struct re_filterfile_spec
660 struct list patterns[1];
663 #endif /* def PCRS */
667 #define ACL_PERMIT 1 /* accept connection request */
668 #define ACL_DENY 2 /* reject connection request */
670 struct access_control_addr
677 struct access_control_list
679 struct access_control_addr src[1];
680 struct access_control_addr dst[1];
683 struct access_control_list *next;
685 #endif /* def ACL_FILES */
688 /* Maximum number of loaders (actions, block, forward, acl...) */
692 * Data loaded from the configuration file.
694 * (Anomaly: toggle is still handled through a global, not this structure)
696 struct configuration_spec
704 const char *actions_file;
705 const char *forwardfile;
709 #endif /* def ACL_FILES */
712 const char *re_filterfile;
713 #endif /* def PCRS */
716 const char * jarfile;
718 #endif /* def JAR_FILES */
721 * Port and IP to bind to.
722 * Defaults to HADDR_DEFAULT:HADDR_PORT == 127.0.0.1:8000
727 #ifndef SPLIT_PROXY_ARGS
728 const char *suppress_message;
729 #endif /* ndef SPLIT_PROXY_ARGS */
731 #ifndef SPLIT_PROXY_ARGS
732 /* suppress listing config files */
733 int suppress_blocklists;
734 #endif /* ndef SPLIT_PROXY_ARGS */
737 const char * trustfile;
739 struct list trust_info[1];
740 struct url_spec *trust_list[64];
741 #endif /* def TRUST_FILES */
743 /* Various strings for show-proxy-args */
744 char *proxy_args_header;
745 char *proxy_args_invocation;
746 char *proxy_args_gateways;
747 char *proxy_args_trailer;
749 /* the configuration file object. */
750 struct file_list *config_file_list;
752 /* List of loaders */
753 int (*loaders[NLOADERS])(struct client_state *);
755 /* bool, nonzero if we need to bind() to the new port */
760 #define SZ(X) (sizeof(X) / sizeof(*X))
762 #define WHITEBG "<body bgcolor=\"#ffffff\" link=\"#000078\" alink=\"#ff0022\" vlink=\"#787878\">\n"
763 #define BODY "<body bgcolor=\"#f8f8f0\" link=\"#000078\" alink=\"#ff0022\" vlink=\"#787878\">\n"
764 #define BANNER "<strong>Internet J<small>UNK<i><font color=\"red\">BUSTER</font></i></small></strong>"
767 #define FORCE_PREFIX "/IJB-FORCE-LOAD"
768 #endif /* def FORCE_LOAD */
770 /* Shouldn't end with '/' */
771 #define HOME_PAGE_URL "http://ijbswa.sourceforge.net"
772 #define REDIRECT_URL HOME_PAGE_URL "redirect.php?v=" VERSION "&to="
774 #define CGI_PREFIX_HOST "i.j.b"
776 static const char CSUCCEED[] =
777 "HTTP/1.0 200 Connection established\n"
778 "Proxy-Agent: IJ/" VERSION "\n\n";
780 static const char CHEADER[] =
781 "HTTP/1.0 400 Invalid header received from browser\n\n";
783 static const char SHEADER[] =
784 "HTTP/1.0 502 Invalid header received from server\n\n";
786 #ifdef IMAGE_BLOCKING
789 * Hint: You can encode your own GIFs like that:
790 * perl -e 'while (read STDIN, $c, 1) { printf("\\%.3o,", unpack("C", $c)); }'
793 static const char BLANKGIF[] =
794 "HTTP/1.0 200 OK\r\n"
795 "Pragma: no-cache\r\n"
796 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
797 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
798 "Content-type: image/gif\r\n\r\n"
799 "GIF89a\001\000\001\000\200\000\000\377\377\377\000\000"
800 "\000!\371\004\001\000\000\000\000,\000\000\000\000\001"
801 "\000\001\000\000\002\002D\001\000;";
803 static const char JBGIF[] =
804 "HTTP/1.0 200 OK\r\n"
805 "Pragma: no-cache\r\n"
806 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
807 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
808 "Content-type: image/gif\r\n\r\n"
809 "GIF89aD\000\013\000\360\000\000\000\000\000\377\377\377!"
810 "\371\004\001\000\000\001\000,\000\000\000\000D\000\013\000"
811 "\000\002a\214\217\251\313\355\277\000\200G&K\025\316hC\037"
812 "\200\234\230Y\2309\235S\230\266\206\372J\253<\3131\253\271"
813 "\270\215\342\254\013\203\371\202\264\334P\207\332\020o\266"
814 "N\215I\332=\211\312\3513\266:\026AK)\364\370\365aobr\305"
815 "\372\003S\275\274k2\354\254z\347?\335\274x\306^9\374\276"
818 #endif /* def IMAGE_BLOCKING */
820 #if defined(FAST_REDIRECTS) || defined(IMAGE_BLOCKING)
822 static const char HTTP_REDIRECT_TEMPLATE[] =
823 "HTTP/1.0 302 Local Redirect from Junkbuster\r\n"
824 "Pragma: no-cache\r\n"
825 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
826 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
827 "Location: %s\r\n\r\n";
829 #endif /* defined(FAST_REDIRECTS) || defined(IMAGE_BLOCKING) */
835 #endif /* ndef _PROJECT_H */