3 #define PROJECT_H_VERSION "$Id: project.h,v 1.16 2001/06/04 18:31:58 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.16 2001/06/04 18:31:58 swa
40 * files are now prefixed with either `confdir' or `logdir'.
41 * `make redhat-dist' replaces both entries confdir and logdir
44 * Revision 1.15 2001/06/04 11:28:53 swa
45 * redirect did not work due to missing /
47 * Revision 1.14 2001/06/03 11:03:48 oes
54 * adapted to new enlist_unique arg format
58 * introduced confdir option
60 * filters.c filtrers.h
62 * extracted-CGI relevant stuff
70 * support for new cgi mechansim
74 * functions for new list type: "map"
75 * extended enlist_unique
82 * deleted const struct interceptors
90 * added struct http_response
91 * changes struct interceptors to struct cgi_dispatcher
92 * moved HTML stuff to cgi.h
101 * Revision 1.13 2001/06/01 20:05:36 jongfoster
102 * Support for +image-blocker{}: added ACTION_IMAGE_BLOCKER
103 * constant, and removed csp->tinygif.
105 * Revision 1.12 2001/06/01 18:49:17 jongfoster
106 * Replaced "list_share" with "list" - the tiny memory gain was not
107 * worth the extra complexity.
109 * Revision 1.11 2001/06/01 10:32:47 oes
110 * Added constants for anchoring selection bitmap
112 * Revision 1.10 2001/05/31 21:33:53 jongfoster
113 * Changes for new actions file, replacing permissionsfile
114 * and parts of the config file. Also added support for
117 * Revision 1.9 2001/05/31 17:32:31 oes
119 * - Enhanced domain part globbing with infix and prefix asterisk
120 * matching and optional unanchored operation
122 * Revision 1.8 2001/05/29 20:09:15 joergs
123 * HTTP_REDIRECT_TEMPLATE fixed.
125 * Revision 1.7 2001/05/29 09:50:24 jongfoster
126 * Unified blocklist/imagelist/actionslist.
127 * File format is still under discussion, but the internal changes
130 * Also modified interceptor behaviour:
131 * - We now intercept all URLs beginning with one of the following
132 * prefixes (and *only* these prefixes):
134 * * http://ijbswa.sf.net/config/
135 * * http://ijbswa.sourceforge.net/config/
136 * - New interceptors "home page" - go to http://i.j.b/ to see it.
137 * - Internal changes so that intercepted and fast redirect pages
138 * are not replaced with an image.
139 * - Interceptors now have the option to send a binary page direct
140 * to the client. (i.e. ijb-send-banner uses this)
141 * - Implemented show-url-info interceptor. (Which is why I needed
142 * the above interceptors changes - a typical URL is
143 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
144 * The previous mechanism would not have intercepted that, and
145 * if it had been intercepted then it then it would have replaced
148 * Revision 1.6 2001/05/27 22:17:04 oes
150 * - re_process_buffer no longer writes the modified buffer
151 * to the client, which was very ugly. It now returns the
152 * buffer, which it is then written by chat.
154 * - content_length now adjusts the Content-Length: header
155 * for modified documents rather than crunch()ing it.
156 * (Length info in csp->content_length, which is 0 for
157 * unmodified documents)
159 * - For this to work, sed() is called twice when filtering.
161 * Revision 1.5 2001/05/26 00:28:36 jongfoster
162 * Automatic reloading of config file.
163 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
164 * Most of the global variables have been moved to a new
165 * struct configuration_spec, accessed through csp->config->globalname
166 * Most of the globals remaining are used by the Win32 GUI.
168 * Revision 1.4 2001/05/22 18:46:04 oes
170 * - Enabled filtering banners by size rather than URL
171 * by adding patterns that replace all standard banner
172 * sizes with the "Junkbuster" gif to the re_filterfile
174 * - Enabled filtering WebBugs by providing a pattern
175 * which kills all 1x1 images
177 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
178 * which is selected by the (nonstandard and therefore
179 * capital) letter 'U' in the option string.
180 * It causes the quantifiers to be ungreedy by default.
181 * Appending a ? turns back to greedy (!).
183 * - Added a new interceptor ijb-send-banner, which
184 * sends back the "Junkbuster" gif. Without imagelist or
185 * MSIE detection support, or if tinygif = 1, or the
186 * URL isn't recognized as an imageurl, a lame HTML
187 * explanation is sent instead.
189 * - Added new feature, which permits blocking remote
190 * script redirects and firing back a local redirect
192 * The feature is conditionally compiled, i.e. it
193 * can be disabled with --disable-fast-redirects,
194 * plus it must be activated by a "fast-redirects"
195 * line in the config file, has its own log level
196 * and of course wants to be displayed by show-proxy-args
197 * Note: Boy, all the #ifdefs in 1001 locations and
198 * all the fumbling with configure.in and acconfig.h
199 * were *way* more work than the feature itself :-(
201 * - Because a generic redirect template was needed for
202 * this, tinygif = 3 now uses the same.
204 * - Moved GIFs, and other static HTTP response templates
209 * - Removed some >400 CRs again (Jon, you really worked
212 * Revision 1.3 2001/05/20 01:21:20 jongfoster
213 * Version 2.9.4 checkin.
214 * - Merged popupfile and cookiefile, and added control over PCRS
215 * filtering, in new "actionsfile".
216 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
217 * file error you now get a message box (in the Win32 GUI) rather
218 * than the program exiting with no explanation.
219 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
221 * - Removed tabs from "config"
222 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
223 * - Bumped up version number.
225 * Revision 1.2 2001/05/17 23:01:01 oes
226 * - Cleaned CRLF's from the sources and related files
228 * Revision 1.1.1.1 2001/05/15 13:59:03 oes
229 * Initial import of version 2.9.3 source tree
232 *********************************************************************/
235 /* Declare struct FILE for vars and funcs. */
238 /* Need time_t for file_list */
242 * Include appropriate regular expression libraries.
244 * PCRS ==> Include pcre
245 * REGEX && PCRE ==> Include pcre and pcreposix
246 * REGEX && !PCRE ==> Include gnu_regex
248 * STATIC ==> Use #include "pcre.h" (compiling at same time)
249 * !STATIC ==> Use #include <pcre.h> (System library)
252 #if (defined(REGEX) && defined(PCRE)) || defined(PCRS)
258 #endif /* (defined(REGEX) && defined(PCRE)) || defined(PCRS) */
260 #if defined(REGEX) && defined(PCRE)
262 # include "pcreposix.h"
264 # include <pcreposix.h>
266 #endif /* defined(REGEX) && defined(PCRE) */
268 #if defined(REGEX) && !defined(PCRE)
269 # include "gnu_regex.h"
274 #endif /* def PCRS */
278 #endif /* def AMIGA */
286 /* Default IP and port to listen on */
287 #define HADDR_DEFAULT "127.0.0.1"
288 #define HADDR_PORT 8000
291 /* Need this for struct client_state */
292 struct configuration_spec;
294 /* Generic linked list of strings */
295 struct list /* FIXME: Why not separate entries and header? */
297 char * str; /* valid in an entry */
298 struct list *last; /* valid in header */
317 char *hostport; /* "host[:port]" */
321 /* CGI or blocker generated response */
324 char *status; /* HTTP status */
325 struct list headers[1]; /* List of header lines */
326 int content_length; /* Length of body, REQUIRED if binary body*/
327 char *head; /* Formatted http response head */
328 char *body; /* HTTP document body */
334 char *spec; /* The string which was parsed to produce this */
335 /* url_spec. Used for debugging or display only. */
337 /* Hostname matching: */
338 char *domain; /* Fully qalified domain name (FQDN) pattern. */
339 /* May contain "*". */
340 char *dbuf; /* FIXME: Comment this */
341 char **dvec; /* Domain ptr vector */
342 int dcnt; /* How many domains in fqdn? */
343 int unanchored; /* Bitmap - flags are ANCHOR_LEFT and ANCHOR_RIGHT */
346 int port; /* The port number, or 0 to match all ports. */
349 char *path; /* The path prefix (if not using regex), or source */
351 int pathlen; /* ==strlen(path). Needed for prefix matching. */
353 regex_t *preg; /* Regex for matching path part */
357 #define ANCHOR_LEFT 1
358 #define ANCHOR_RIGHT 2
371 #define IOB_PEEK(CSP) ((CSP->iob->cur > CSP->iob->eod) ? (CSP->iob->eod - CSP->iob->cur) : 0)
372 #define IOB_RESET(CSP) if(CSP->iob->buf) free(CSP->iob->buf); memset(CSP->iob, '\0', sizeof(CSP->iob));
376 #define ACTION_MASK_ALL (~0U)
378 #define ACTION_MOST_COMPATIBLE 0x0000U
380 #define ACTION_BLOCK 0x0001U
381 #define ACTION_FAST_REDIRECTS 0x0002U
382 #define ACTION_FILTER 0x0004U
383 #define ACTION_HIDE_FORWARDED 0x0008U
384 #define ACTION_HIDE_FROM 0x0010U
385 #define ACTION_HIDE_REFERER 0x0020U /* sic - follow HTTP, not English */
386 #define ACTION_HIDE_USER_AGENT 0x0040U
387 #define ACTION_IMAGE 0x0080U
388 #define ACTION_IMAGE_BLOCKER 0x0100U
389 #define ACTION_NO_COOKIE_READ 0x0200U
390 #define ACTION_NO_COOKIE_SET 0x0400U
391 #define ACTION_NO_POPUPS 0x0800U
392 #define ACTION_VANILLA_WAFER 0x1000U
394 #define ACTION_STRING_FROM 0
395 #define ACTION_STRING_IMAGE_BLOCKER 1
396 #define ACTION_STRING_REFERER 2
397 #define ACTION_STRING_USER_AGENT 3
398 #define ACTION_STRING_COUNT 4
400 #define ACTION_MULTI_ADD_HEADER 0
401 #define ACTION_MULTI_WAFER 1
402 #define ACTION_MULTI_COUNT 2
405 * This structure contains a list of actions to apply to a URL.
406 * It only contains positive instructions - no "-" options.
407 * It is not used to store the actions list itself, only for
408 * url_actions() to return the current values.
410 struct current_action_spec
412 unsigned flags; /* a bit set to "1" = add action */
414 /* For those actions that require parameters: */
416 /* each entry is valid if & only if corresponding entry in "add" set. */
417 char * string[ACTION_STRING_COUNT];
420 struct list multi[ACTION_MULTI_COUNT][1];
425 * This structure contains a set of changes to actions.
426 * It can contain both positive and negative instructions.
427 * It is used to store an entry in the actions list.
431 unsigned mask; /* a bit set to "0" = remove action */
432 unsigned add; /* a bit set to "1" = add action */
434 /* For those actions that require parameters: */
436 /* each entry is valid if & only if corresponding entry in "add" set. */
437 char * string[ACTION_STRING_COUNT];
439 /* Strings to remove. */
440 struct list multi_remove[ACTION_MULTI_COUNT][1];
442 /* If nonzero, remove *all* strings. */
443 int multi_remove_all[ACTION_MULTI_COUNT];
446 struct list multi_add[ACTION_MULTI_COUNT][1];
450 * This structure is used to store the actions list.
452 * It contains a URL pattern, and the chages to the actions.
453 * It is a linked list.
457 struct url_spec url[1];
459 struct action_spec action[1];
461 struct url_actions * next;
465 /* Constants defining bitmask for csp->accept_types */
467 #ifdef DETECT_MSIE_IMAGES
469 /* MSIE detected by user-agent string */
470 #define ACCEPT_TYPE_IS_MSIE 0x0001
473 * *If* this is MSIE, it wants an image. (Or this is a shift-reload, or
474 * it's got an image from this URL before... yuck!)
475 * Only meaningful if ACCEPT_TYPE_IS_MSIE set
477 #define ACCEPT_TYPE_MSIE_IMAGE 0x0002
480 * *If* this is MSIE, it wants a HTML document.
481 * Only meaningful if ACCEPT_TYPE_IS_MSIE set
483 #define ACCEPT_TYPE_MSIE_HTML 0x0004
485 #endif /* def DETECT_MSIE_IMAGES */
490 /* The proxy's configuration */
491 struct configuration_spec * config;
494 /* The actions to perform on the current request */
495 struct current_action_spec action[1];
498 /* socket to talk to client (web browser) */
501 /* socket to talk to server (web server or proxy) */
506 /* 1 if this URL was rejected, 0 otherwise. Allows actual stats inc to
507 * occur in main thread only for thread-safety.
510 #endif /* def STATISTICS */
514 #endif /* def FORCE_LOAD */
518 #endif /* def TOGGLE */
521 * Client PC's IP address, as reported by the accept()_ function.
522 * Both as string and number
528 /* The referer in this request, if one was specified. */
530 #endif /* def TRUST_FILES */
532 #if defined(DETECT_MSIE_IMAGES)
533 /* Types the client will accept.
534 * Bitmask - see ACCEPT_TYPE_XXX constants.
537 #endif /* defined(DETECT_MSIE_IMAGES) */
539 /* The URL that was requested */
540 struct http_request http[1];
542 /* An I/O buffer used for buffering data read from the client */
545 /* List of all headers for this request */
546 struct list headers[1];
548 /* List of all cookies for this request */
549 struct list cookie_list[1];
551 #if defined(PCRS) || defined(KILLPOPUPS)
552 /* Nonzero if this has a text MIME type */
554 #endif /* defined(PCRS) || defined(KILLPOPUPS) */
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;
569 struct file_list *rlist; /* Perl re_filterfile */
570 size_t content_length; /* Length after processing */
571 #endif /* def PCRS */
574 struct file_list *tlist; /* trustfile */
575 #endif /* def TRUST_FILES */
577 struct client_state *next;
585 char *(*parser)(const struct parsers *, char *, struct client_state *);
588 struct cgi_dispatcher
592 int (*handler)(struct client_state *csp, struct http_response *rsp, struct map *parameters);
599 * this is a pointer to the data structures associated with the file.
600 * Read-only once the structure has been created.
604 /* Normally NULL. When we are finished with file (i.e. when we have
605 * loaded a new one), set to a pointer to an unloader function.
606 * Unloader will be called by sweep() (called from main loop) when
607 * all clients using this file are done. This prevents threading
610 void (*unloader)(void *);
612 /* Used internally by sweep(). Do not access from elsewhere. */
615 #ifndef SPLIT_PROXY_ARGS
616 /* String to be displayed as part of show-proxy-args display.
617 * Read-only once the structure has been created.
620 #endif /* ndef SPLIT_PROXY_ARGS */
622 /* Following variables allow us to check if file has been changed.
623 * Read-only once the structure has been created.
628 /* Pointer to next entry in the linked list of all "file_list"s.
629 * This linked list is so that sweep() can navigate it.
630 * Since sweep() can remove items from the list, we must be careful
631 * to only access this value from main thread (when we know sweep
634 struct file_list *next;
641 struct url_spec url[1];
643 struct block_spec *next;
645 #endif /* def TRUST_FILES */
648 #define SOCKS_NONE 0 /* Don't use a SOCKS server */
649 #define SOCKS_4 40 /* original SOCKS 4 protocol */
650 #define SOCKS_4A 41 /* as modified for hosts w/o external DNS */
654 struct url_spec url[1];
656 /* Connection type - must be a SOCKS_xxx constant */
663 /* Parent HTTP proxy */
667 /* For the linked list */
668 struct forward_spec *next;
673 struct re_filterfile_spec
675 struct list patterns[1];
678 #endif /* def PCRS */
682 #define ACL_PERMIT 1 /* accept connection request */
683 #define ACL_DENY 2 /* reject connection request */
685 struct access_control_addr
692 struct access_control_list
694 struct access_control_addr src[1];
695 struct access_control_addr dst[1];
698 struct access_control_list *next;
700 #endif /* def ACL_FILES */
703 /* Maximum number of loaders (actions, re_filter, ...) */
707 * Data loaded from the configuration file.
709 * (Anomaly: toggle is still handled through a global, not this structure)
711 struct configuration_spec
720 const char *actions_file;
723 const char *re_filterfile;
724 #endif /* def PCRS */
727 const char * jarfile;
729 #endif /* def JAR_FILES */
732 * Port and IP to bind to.
733 * Defaults to HADDR_DEFAULT:HADDR_PORT == 127.0.0.1:8000
738 #ifndef SPLIT_PROXY_ARGS
739 const char *suppress_message;
740 #endif /* ndef SPLIT_PROXY_ARGS */
742 #ifndef SPLIT_PROXY_ARGS
743 /* suppress listing config files */
744 int suppress_blocklists;
745 #endif /* ndef SPLIT_PROXY_ARGS */
748 const char * trustfile;
750 struct list trust_info[1];
751 struct url_spec *trust_list[64];
752 #endif /* def TRUST_FILES */
755 struct access_control_list *acl;
756 #endif /* def ACL_FILES */
758 struct forward_spec *forward;
760 /* Various strings for show-proxy-args */
761 char *proxy_args_header;
762 char *proxy_args_invocation;
763 char *proxy_args_trailer;
765 /* the configuration file object. */
766 struct file_list *config_file_list;
768 /* List of loaders */
769 int (*loaders[NLOADERS])(struct client_state *);
771 /* bool, nonzero if we need to bind() to the new port */
776 #define SZ(X) (sizeof(X) / sizeof(*X))
778 #define WHITEBG "<body bgcolor=\"#ffffff\" link=\"#000078\" alink=\"#ff0022\" vlink=\"#787878\">\n"
779 #define BODY "<body bgcolor=\"#f8f8f0\" link=\"#000078\" alink=\"#ff0022\" vlink=\"#787878\">\n"
780 #define BANNER "<strong>Internet J<small>UNK<i><font color=\"red\">BUSTER</font></i></small></strong>"
783 #define FORCE_PREFIX "/IJB-FORCE-LOAD"
784 #endif /* def FORCE_LOAD */
786 /* Shouldn't end with '/' */
787 #define HOME_PAGE_URL "http://ijbswa.sourceforge.net"
788 #define REDIRECT_URL HOME_PAGE_URL "/redirect.php?v=" VERSION "&to="
790 #define CGI_PREFIX_HOST "i.j.b"
792 static const char CSUCCEED[] =
793 "HTTP/1.0 200 Connection established\n"
794 "Proxy-Agent: IJ/" VERSION "\n\n";
796 static const char CHEADER[] =
797 "HTTP/1.0 400 Invalid header received from browser\n\n";
799 static const char SHEADER[] =
800 "HTTP/1.0 502 Invalid header received from server\n\n";
802 #ifdef IMAGE_BLOCKING
805 * Hint: You can encode your own GIFs like that:
806 * perl -e 'while (read STDIN, $c, 1) { printf("\\%.3o,", unpack("C", $c)); }'
809 static const char BLANKGIF[] =
810 "HTTP/1.0 200 OK\r\n"
811 "Pragma: no-cache\r\n"
812 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
813 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
814 "Content-type: image/gif\r\n\r\n"
815 "GIF89a\001\000\001\000\200\000\000\377\377\377\000\000"
816 "\000!\371\004\001\000\000\000\000,\000\000\000\000\001"
817 "\000\001\000\000\002\002D\001\000;";
819 static const char JBGIF[] =
820 "HTTP/1.0 200 OK\r\n"
821 "Pragma: no-cache\r\n"
822 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
823 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
824 "Content-type: image/gif\r\n\r\n"
825 "GIF89aD\000\013\000\360\000\000\000\000\000\377\377\377!"
826 "\371\004\001\000\000\001\000,\000\000\000\000D\000\013\000"
827 "\000\002a\214\217\251\313\355\277\000\200G&K\025\316hC\037"
828 "\200\234\230Y\2309\235S\230\266\206\372J\253<\3131\253\271"
829 "\270\215\342\254\013\203\371\202\264\334P\207\332\020o\266"
830 "N\215I\332=\211\312\3513\266:\026AK)\364\370\365aobr\305"
831 "\372\003S\275\274k2\354\254z\347?\335\274x\306^9\374\276"
834 #endif /* def IMAGE_BLOCKING */
836 #if defined(FAST_REDIRECTS) || defined(IMAGE_BLOCKING)
838 static const char HTTP_REDIRECT_TEMPLATE[] =
839 "HTTP/1.0 302 Local Redirect from Junkbuster\r\n"
840 "Pragma: no-cache\r\n"
841 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
842 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
843 "Location: %s\r\n\r\n";
845 #endif /* defined(FAST_REDIRECTS) || defined(IMAGE_BLOCKING) */
851 #endif /* ndef _PROJECT_H */