3 #define PROJECT_H_VERSION "$Id: project.h,v 1.10 2001/05/31 21:33:53 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.10 2001/05/31 21:33:53 jongfoster
40 * Changes for new actions file, replacing permissionsfile
41 * and parts of the config file. Also added support for
44 * Revision 1.9 2001/05/31 17:32:31 oes
46 * - Enhanced domain part globbing with infix and prefix asterisk
47 * matching and optional unanchored operation
49 * Revision 1.8 2001/05/29 20:09:15 joergs
50 * HTTP_REDIRECT_TEMPLATE fixed.
52 * Revision 1.7 2001/05/29 09:50:24 jongfoster
53 * Unified blocklist/imagelist/actionslist.
54 * File format is still under discussion, but the internal changes
57 * Also modified interceptor behaviour:
58 * - We now intercept all URLs beginning with one of the following
59 * prefixes (and *only* these prefixes):
61 * * http://ijbswa.sf.net/config/
62 * * http://ijbswa.sourceforge.net/config/
63 * - New interceptors "home page" - go to http://i.j.b/ to see it.
64 * - Internal changes so that intercepted and fast redirect pages
65 * are not replaced with an image.
66 * - Interceptors now have the option to send a binary page direct
67 * to the client. (i.e. ijb-send-banner uses this)
68 * - Implemented show-url-info interceptor. (Which is why I needed
69 * the above interceptors changes - a typical URL is
70 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
71 * The previous mechanism would not have intercepted that, and
72 * if it had been intercepted then it then it would have replaced
75 * Revision 1.6 2001/05/27 22:17:04 oes
77 * - re_process_buffer no longer writes the modified buffer
78 * to the client, which was very ugly. It now returns the
79 * buffer, which it is then written by chat.
81 * - content_length now adjusts the Content-Length: header
82 * for modified documents rather than crunch()ing it.
83 * (Length info in csp->content_length, which is 0 for
84 * unmodified documents)
86 * - For this to work, sed() is called twice when filtering.
88 * Revision 1.5 2001/05/26 00:28:36 jongfoster
89 * Automatic reloading of config file.
90 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
91 * Most of the global variables have been moved to a new
92 * struct configuration_spec, accessed through csp->config->globalname
93 * Most of the globals remaining are used by the Win32 GUI.
95 * Revision 1.4 2001/05/22 18:46:04 oes
97 * - Enabled filtering banners by size rather than URL
98 * by adding patterns that replace all standard banner
99 * sizes with the "Junkbuster" gif to the re_filterfile
101 * - Enabled filtering WebBugs by providing a pattern
102 * which kills all 1x1 images
104 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
105 * which is selected by the (nonstandard and therefore
106 * capital) letter 'U' in the option string.
107 * It causes the quantifiers to be ungreedy by default.
108 * Appending a ? turns back to greedy (!).
110 * - Added a new interceptor ijb-send-banner, which
111 * sends back the "Junkbuster" gif. Without imagelist or
112 * MSIE detection support, or if tinygif = 1, or the
113 * URL isn't recognized as an imageurl, a lame HTML
114 * explanation is sent instead.
116 * - Added new feature, which permits blocking remote
117 * script redirects and firing back a local redirect
119 * The feature is conditionally compiled, i.e. it
120 * can be disabled with --disable-fast-redirects,
121 * plus it must be activated by a "fast-redirects"
122 * line in the config file, has its own log level
123 * and of course wants to be displayed by show-proxy-args
124 * Note: Boy, all the #ifdefs in 1001 locations and
125 * all the fumbling with configure.in and acconfig.h
126 * were *way* more work than the feature itself :-(
128 * - Because a generic redirect template was needed for
129 * this, tinygif = 3 now uses the same.
131 * - Moved GIFs, and other static HTTP response templates
136 * - Removed some >400 CRs again (Jon, you really worked
139 * Revision 1.3 2001/05/20 01:21:20 jongfoster
140 * Version 2.9.4 checkin.
141 * - Merged popupfile and cookiefile, and added control over PCRS
142 * filtering, in new "actionsfile".
143 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
144 * file error you now get a message box (in the Win32 GUI) rather
145 * than the program exiting with no explanation.
146 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
148 * - Removed tabs from "config"
149 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
150 * - Bumped up version number.
152 * Revision 1.2 2001/05/17 23:01:01 oes
153 * - Cleaned CRLF's from the sources and related files
155 * Revision 1.1.1.1 2001/05/15 13:59:03 oes
156 * Initial import of version 2.9.3 source tree
159 *********************************************************************/
162 /* Declare struct FILE for vars and funcs. */
165 /* Need time_t for file_list */
169 * Include appropriate regular expression libraries.
171 * PCRS ==> Include pcre
172 * REGEX && PCRE ==> Include pcre and pcreposix
173 * REGEX && !PCRE ==> Include gnu_regex
175 * STATIC ==> Use #include "pcre.h" (compiling at same time)
176 * !STATIC ==> Use #include <pcre.h> (System library)
179 #if (defined(REGEX) && defined(PCRE)) || defined(PCRS)
185 #endif /* (defined(REGEX) && defined(PCRE)) || defined(PCRS) */
187 #if defined(REGEX) && defined(PCRE)
189 # include "pcreposix.h"
191 # include <pcreposix.h>
193 #endif /* defined(REGEX) && defined(PCRE) */
195 #if defined(REGEX) && !defined(PCRE)
196 # include "gnu_regex.h"
201 #endif /* def PCRS */
205 #endif /* def AMIGA */
213 /* Default IP and port to listen on */
214 #define HADDR_DEFAULT "127.0.0.1"
215 #define HADDR_PORT 8000
218 /* Need this for struct gateway */
221 /* Need this for struct client_state */
222 struct configuration_spec;
233 char *hostport; /* "host[:port]" */
239 /* generic attributes */
241 int (*conn)(const struct gateway *, struct http_request *, struct client_state *);
244 /* domain specific attributes */
253 /* Generic linked list of strings */
254 struct list /* FIXME: Why not separate entries and header? */
256 char * str; /* valid in an entry */
257 struct list *last; /* valid in header */
262 /* Generic linked list of strings */
263 struct list_share /* FIXME: Why not separate entries and header? */
265 const char * str; /* valid in an entry */
266 struct list_share *last; /* valid in header */
267 struct list_share *next;
275 char *domain; /* fqdn */
277 char **dvec; /* Domain ptr vector */
278 int dcnt; /* How many domains in fqdn? */
279 int unanchored; /* bitmap 0: left, 1: right */
289 #define ANCHOR_LEFT 1
290 #define ANCHOR_RIGHT 2
302 #define IOB_PEEK(CSP) ((CSP->iob->cur > CSP->iob->eod) ? (CSP->iob->eod - CSP->iob->cur) : 0)
303 #define IOB_RESET(CSP) if(CSP->iob->buf) free(CSP->iob->buf); memset(CSP->iob, '\0', sizeof(CSP->iob));
307 #define ACTION_MASK_ALL (~0U)
309 #define ACTION_MOST_COMPATIBLE 0U
311 #define ACTION_BLOCK 0x0001U
312 #define ACTION_FAST_REDIRECTS 0x0002U
313 #define ACTION_FILTER 0x0004U
314 #define ACTION_HIDE_FORWARDED 0x0008U
315 #define ACTION_HIDE_FROM 0x0010U
316 #define ACTION_HIDE_REFERER 0x0020U /* sic - follow HTTP, not English */
317 #define ACTION_HIDE_USER_AGENT 0x0040U
318 #define ACTION_IMAGE 0x0080U
319 #define ACTION_NO_COOKIE_READ 0x0100U
320 #define ACTION_NO_COOKIE_SET 0x0200U
321 #define ACTION_NO_POPUPS 0x0400U
322 #define ACTION_VANILLA_WAFER 0x0800U
324 #define ACTION_STRING_FROM 0
325 #define ACTION_STRING_REFERER 1
326 #define ACTION_STRING_USER_AGENT 2
327 #define ACTION_STRING_COUNT 3
329 #define ACTION_MULTI_ADD_HEADER 0
330 #define ACTION_MULTI_WAFER 1
331 #define ACTION_MULTI_COUNT 2
334 struct current_action_spec
336 unsigned flags; /* a bit set to "1" = add action */
338 /* For those actions that require parameters: */
340 /* each entry is valid if & only if corresponding entry in "add" set. */
341 char * string[ACTION_STRING_COUNT];
344 struct list_share multi[ACTION_MULTI_COUNT][1];
349 unsigned mask; /* a bit set to "0" = remove action */
350 unsigned add; /* a bit set to "1" = add action */
352 /* For those actions that require parameters: */
354 /* each entry is valid if & only if corresponding entry in "add" set. */
355 char * string[ACTION_STRING_COUNT];
357 /* Strings to remove. */
358 struct list multi_remove[ACTION_MULTI_COUNT][1];
360 /* If nonzero, remove *all* strings. */
361 int multi_remove_all[ACTION_MULTI_COUNT];
364 struct list multi_add[ACTION_MULTI_COUNT][1];
369 struct url_spec url[1];
371 struct action_spec action[1];
373 struct url_actions * next;
377 /* Constants defining bitmask for csp->accept_types */
379 #ifdef DETECT_MSIE_IMAGES
381 /* MSIE detected by user-agent string */
382 #define ACCEPT_TYPE_IS_MSIE 0x0001
385 * *If* this is MSIE, it wants an image. (Or this is a shift-reload, or
386 * it's got an image from this URL before... yuck!)
387 * Only meaningful if ACCEPT_TYPE_IS_MSIE set
389 #define ACCEPT_TYPE_MSIE_IMAGE 0x0002
392 * *If* this is MSIE, it wants a HTML document.
393 * Only meaningful if ACCEPT_TYPE_IS_MSIE set
395 #define ACCEPT_TYPE_MSIE_HTML 0x0004
397 #endif /* def DETECT_MSIE_IMAGES */
402 /* The proxy's configuration */
403 struct configuration_spec * config;
406 /* The actions to perform on the current request */
407 struct current_action_spec action[1];
410 /* socket to talk to client (web browser) */
413 /* socket to talk to server (web server or proxy) */
418 /* 1 if this URL was rejected, 0 otherwise. Allows actual stats inc to
419 * occur in main thread only for thread-safety.
422 #endif /* def STATISTICS */
426 #endif /* def FORCE_LOAD */
430 #endif /* def TOGGLE */
433 * Client PC's IP address, as reported by the accept()_ function.
434 * Both as string and number
440 /* The referer in this request, if one was specified. */
442 #endif /* def TRUST_FILES */
444 #if defined(DETECT_MSIE_IMAGES)
445 /* Types the client will accept.
446 * Bitmask - see ACCEPT_TYPE_XXX constants.
449 #endif /* defined(DETECT_MSIE_IMAGES) */
451 /* The URL that was requested */
452 struct http_request http[1];
454 /* An I/O buffer used for buffering data read from the client */
457 /* List of all headers for this request */
458 struct list headers[1];
460 /* List of all cookies for this request */
461 struct list cookie_list[1];
463 #if defined(PCRS) || defined(KILLPOPUPS)
464 /* Nonzero if this has a text MIME type */
466 #endif /* defined(PCRS) || defined(KILLPOPUPS) */
468 /* The "X-Forwarded-For:" header sent by the client */
472 * Nonzero if this client is processing data.
473 * Set to zero when the thread associated with this structure dies.
477 /* files associated with this client */
478 struct file_list *flist; /* forwardfile */
479 struct file_list *actions_list;
483 struct file_list *alist; /* aclfile */
484 #endif /* def ACL_FILES */
487 struct file_list *rlist; /* Perl re_filterfile */
488 size_t content_length; /* Length after processing */
489 #endif /* def PCRS */
492 struct file_list *tlist; /* trustfile */
493 #endif /* def TRUST_FILES */
495 struct client_state *next;
503 char *(*parser)(const struct parsers *, char *, struct client_state *);
511 char *(*interceptor)(struct http_request *http, struct client_state *csp);
518 * this is a pointer to the data structures associated with the file.
519 * Read-only once the structure has been created.
523 /* Normally NULL. When we are finished with file (i.e. when we have
524 * loaded a new one), set to a pointer to an unloader function.
525 * Unloader will be called by sweep() (called from main loop) when
526 * all clients using this file are done. This prevents threading
529 void (*unloader)(void *);
531 /* Used internally by sweep(). Do not access from elsewhere. */
534 #ifndef SPLIT_PROXY_ARGS
535 /* String to be displayed as part of show-proxy-args display.
536 * Read-only once the structure has been created.
539 #endif /* ndef SPLIT_PROXY_ARGS */
541 /* Following variables allow us to check if file has been changed.
542 * Read-only once the structure has been created.
547 /* Pointer to next entry in the linked list of all "file_list"s.
548 * This linked list is so that sweep() can navigate it.
549 * Since sweep() can remove items from the list, we must be careful
550 * to only access this value from main thread (when we know sweep
553 struct file_list *next;
560 struct url_spec url[1];
562 struct block_spec *next;
564 #endif /* def TRUST_FILES */
569 struct url_spec url[1];
570 struct gateway gw[1];
571 struct forward_spec *next;
576 struct re_filterfile_spec
578 struct list patterns[1];
579 /* See README.re_filter */
582 #endif /* def PCRS */
586 #define ACL_PERMIT 1 /* accept connection request */
587 #define ACL_DENY 2 /* reject connection request */
589 struct access_control_addr
596 struct access_control_list
598 struct access_control_addr src[1];
599 struct access_control_addr dst[1];
602 struct access_control_list *next;
604 #endif /* def ACL_FILES */
607 /* Maximum number of loaders (actions, block, forward, acl...) */
611 * Data loaded from the configuration file.
613 * (Anomaly: toggle is still handled through a global, not this structure)
615 struct configuration_spec
620 #ifdef IMAGE_BLOCKING
621 int tinygif; /* FIXME Should be an action */
622 const char *tinygifurl; /* FIXME Should be an action */
623 #endif /* def IMAGE_BLOCKING */
627 const char *actions_file;
628 const char *forwardfile;
632 #endif /* def ACL_FILES */
635 const char *re_filterfile;
636 #endif /* def PCRS */
639 const char * jarfile;
641 #endif /* def JAR_FILES */
644 * Port and IP to bind to.
645 * Defaults to HADDR_DEFAULT:HADDR_PORT == 127.0.0.1:8000
650 #ifndef SPLIT_PROXY_ARGS
651 const char *suppress_message;
652 #endif /* ndef SPLIT_PROXY_ARGS */
654 #ifndef SPLIT_PROXY_ARGS
655 /* suppress listing config files */
656 int suppress_blocklists;
657 #endif /* ndef SPLIT_PROXY_ARGS */
660 const char * trustfile;
662 struct list trust_info[1];
663 struct url_spec *trust_list[64];
664 #endif /* def TRUST_FILES */
666 /* Various strings for show-proxy-args */
667 char *proxy_args_header;
668 char *proxy_args_invocation;
669 char *proxy_args_gateways;
670 char *proxy_args_trailer;
672 /* the configuration file object. */
673 struct file_list *config_file_list;
675 /* List of loaders */
676 int (*loaders[NLOADERS])(struct client_state *);
678 /* bool, nonzero if we need to bind() to the new port */
683 #define SZ(X) (sizeof(X) / sizeof(*X))
685 #define WHITEBG "<body bgcolor=\"#ffffff\" link=\"#000078\" alink=\"#ff0022\" vlink=\"#787878\">\n"
686 #define BODY "<body bgcolor=\"#f8f8f0\" link=\"#000078\" alink=\"#ff0022\" vlink=\"#787878\">\n"
687 #define BANNER "<strong>Internet J<small>UNK<i><font color=\"red\">BUSTER</font></i></small></strong>"
690 #define FORCE_PREFIX "/IJB-FORCE-LOAD"
691 #endif /* def FORCE_LOAD */
693 #define HOME_PAGE_URL "http://ijbswa.sourceforge.net/"
694 #define REDIRECT_URL HOME_PAGE_URL "redirect.php?v=" VERSION "&to="
696 static const char CFAIL[] =
697 "HTTP/1.0 503 Connect failed\n"
698 "Content-Type: text/html\n\n"
701 "<title>Internet Junkbuster: Connect failed</title>\n"
707 "TCP connection to '%s' failed: %s.\n<br>"
711 static const char CNXDOM[] =
712 "HTTP/1.0 404 Non-existent domain\n"
713 "Content-Type: text/html\n\n"
716 "<title>Internet Junkbuster: Non-existent domain</title>\n"
722 "No such domain: %s\n"
726 static const char CNOBANNER[] =
727 "HTTP/1.0 200 No Banner\n"
728 "Content-Type: text/html\n\n"
731 "<title>Internet Junkbuster: No Banner</title>\n"
737 "You asked for a banner that this proxy can't produce because either configuration does not permit.\n<br>"
738 "or the URL didn't end with .gif\n"
742 static const char CSUCCEED[] =
743 "HTTP/1.0 200 Connection established\n"
744 "Proxy-Agent: IJ/" VERSION "\n\n";
746 static const char CHEADER[] =
747 "HTTP/1.0 400 Invalid header received from browser\n\n";
749 static const char SHEADER[] =
750 "HTTP/1.0 502 Invalid header received from server\n\n";
752 #ifdef IMAGE_BLOCKING
755 * Hint: You can encode your own GIFs like that:
756 * perl -e 'while (read STDIN, $c, 1) { printf("\\%.3o,", unpack("C", $c)); }'
759 static const char BLANKGIF[] =
760 "HTTP/1.0 200 OK\r\n"
761 "Pragma: no-cache\r\n"
762 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
763 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
764 "Content-type: image/gif\r\n\r\n"
765 "GIF89a\001\000\001\000\200\000\000\377\377\377\000\000"
766 "\000!\371\004\001\000\000\000\000,\000\000\000\000\001"
767 "\000\001\000\000\002\002D\001\000;";
769 static const char JBGIF[] =
770 "HTTP/1.0 200 OK\r\n"
771 "Pragma: no-cache\r\n"
772 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
773 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
774 "Content-type: image/gif\r\n\r\n"
775 "GIF89aD\000\013\000\360\000\000\000\000\000\377\377\377!"
776 "\371\004\001\000\000\001\000,\000\000\000\000D\000\013\000"
777 "\000\002a\214\217\251\313\355\277\000\200G&K\025\316hC\037"
778 "\200\234\230Y\2309\235S\230\266\206\372J\253<\3131\253\271"
779 "\270\215\342\254\013\203\371\202\264\334P\207\332\020o\266"
780 "N\215I\332=\211\312\3513\266:\026AK)\364\370\365aobr\305"
781 "\372\003S\275\274k2\354\254z\347?\335\274x\306^9\374\276"
784 #endif /* def IMAGE_BLOCKING */
786 #if defined(FAST_REDIRECTS) || defined(IMAGE_BLOCKING)
788 static const char HTTP_REDIRECT_TEMPLATE[] =
789 "HTTP/1.0 302 Local Redirect from Junkbuster\r\n"
790 "Pragma: no-cache\r\n"
791 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
792 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
793 "Location: %s\r\n\r\n";
795 #endif /* defined(FAST_REDIRECTS) || defined(IMAGE_BLOCKING) */
801 #endif /* ndef _PROJECT_H */