3 #define PROJECT_H_VERSION "$Id: project.h,v 1.8 2001/05/29 20:09:15 joergs 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.8 2001/05/29 20:09:15 joergs
40 * HTTP_REDIRECT_TEMPLATE fixed.
42 * Revision 1.7 2001/05/29 09:50:24 jongfoster
43 * Unified blocklist/imagelist/permissionslist.
44 * File format is still under discussion, but the internal changes
47 * Also modified interceptor behaviour:
48 * - We now intercept all URLs beginning with one of the following
49 * prefixes (and *only* these prefixes):
51 * * http://ijbswa.sf.net/config/
52 * * http://ijbswa.sourceforge.net/config/
53 * - New interceptors "home page" - go to http://i.j.b/ to see it.
54 * - Internal changes so that intercepted and fast redirect pages
55 * are not replaced with an image.
56 * - Interceptors now have the option to send a binary page direct
57 * to the client. (i.e. ijb-send-banner uses this)
58 * - Implemented show-url-info interceptor. (Which is why I needed
59 * the above interceptors changes - a typical URL is
60 * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
61 * The previous mechanism would not have intercepted that, and
62 * if it had been intercepted then it then it would have replaced
65 * Revision 1.6 2001/05/27 22:17:04 oes
67 * - re_process_buffer no longer writes the modified buffer
68 * to the client, which was very ugly. It now returns the
69 * buffer, which it is then written by chat.
71 * - content_length now adjusts the Content-Length: header
72 * for modified documents rather than crunch()ing it.
73 * (Length info in csp->content_length, which is 0 for
74 * unmodified documents)
76 * - For this to work, sed() is called twice when filtering.
78 * Revision 1.5 2001/05/26 00:28:36 jongfoster
79 * Automatic reloading of config file.
80 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
81 * Most of the global variables have been moved to a new
82 * struct configuration_spec, accessed through csp->config->globalname
83 * Most of the globals remaining are used by the Win32 GUI.
85 * Revision 1.4 2001/05/22 18:46:04 oes
87 * - Enabled filtering banners by size rather than URL
88 * by adding patterns that replace all standard banner
89 * sizes with the "Junkbuster" gif to the re_filterfile
91 * - Enabled filtering WebBugs by providing a pattern
92 * which kills all 1x1 images
94 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
95 * which is selected by the (nonstandard and therefore
96 * capital) letter 'U' in the option string.
97 * It causes the quantifiers to be ungreedy by default.
98 * Appending a ? turns back to greedy (!).
100 * - Added a new interceptor ijb-send-banner, which
101 * sends back the "Junkbuster" gif. Without imagelist or
102 * MSIE detection support, or if tinygif = 1, or the
103 * URL isn't recognized as an imageurl, a lame HTML
104 * explanation is sent instead.
106 * - Added new feature, which permits blocking remote
107 * script redirects and firing back a local redirect
109 * The feature is conditionally compiled, i.e. it
110 * can be disabled with --disable-fast-redirects,
111 * plus it must be activated by a "fast-redirects"
112 * line in the config file, has its own log level
113 * and of course wants to be displayed by show-proxy-args
114 * Note: Boy, all the #ifdefs in 1001 locations and
115 * all the fumbling with configure.in and acconfig.h
116 * were *way* more work than the feature itself :-(
118 * - Because a generic redirect template was needed for
119 * this, tinygif = 3 now uses the same.
121 * - Moved GIFs, and other static HTTP response templates
126 * - Removed some >400 CRs again (Jon, you really worked
129 * Revision 1.3 2001/05/20 01:21:20 jongfoster
130 * Version 2.9.4 checkin.
131 * - Merged popupfile and cookiefile, and added control over PCRS
132 * filtering, in new "permissionsfile".
133 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
134 * file error you now get a message box (in the Win32 GUI) rather
135 * than the program exiting with no explanation.
136 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
138 * - Removed tabs from "config"
139 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
140 * - Bumped up version number.
142 * Revision 1.2 2001/05/17 23:01:01 oes
143 * - Cleaned CRLF's from the sources and related files
145 * Revision 1.1.1.1 2001/05/15 13:59:03 oes
146 * Initial import of version 2.9.3 source tree
149 *********************************************************************/
152 /* Declare struct FILE for vars and funcs. */
155 /* Need time_t for file_list */
159 * Include appropriate regular expression libraries.
161 * PCRS ==> Include pcre
162 * REGEX && PCRE ==> Include pcre and pcreposix
163 * REGEX && !PCRE ==> Include gnu_regex
165 * STATIC ==> Use #include "pcre.h" (compiling at same time)
166 * !STATIC ==> Use #include <pcre.h> (System library)
169 #if (defined(REGEX) && defined(PCRE)) || defined(PCRS)
175 #endif /* (defined(REGEX) && defined(PCRE)) || defined(PCRS) */
177 #if defined(REGEX) && defined(PCRE)
179 # include "pcreposix.h"
181 # include <pcreposix.h>
183 #endif /* defined(REGEX) && defined(PCRE) */
185 #if defined(REGEX) && !defined(PCRE)
186 # include "gnu_regex.h"
191 #endif /* def PCRS */
195 #endif /* def AMIGA */
203 /* Default IP and port to listen on */
204 #define HADDR_DEFAULT "127.0.0.1"
205 #define HADDR_PORT 8000
208 /* Need this for struct gateway */
211 /* Need this for struct client_state */
212 struct configuration_spec;
223 char *hostport; /* "host[:port]" */
229 /* generic attributes */
231 int (*conn)(const struct gateway *, struct http_request *, struct client_state *);
234 /* domain specific attributes */
243 /* Generic linked list of strings */
261 #define IOB_PEEK(CSP) ((CSP->iob->cur > CSP->iob->eod) ? (CSP->iob->eod - CSP->iob->cur) : 0)
262 #define IOB_RESET(CSP) if(CSP->iob->buf) free(CSP->iob->buf); memset(CSP->iob, '\0', sizeof(CSP->iob));
265 /* Constants defining bitmask for csp->accept_types */
267 #ifdef DETECT_MSIE_IMAGES
269 /* MSIE detected by user-agent string */
270 #define ACCEPT_TYPE_IS_MSIE 0x0001
273 * *If* this is MSIE, it wants an image. (Or this is a shift-reload, or
274 * it's got an image from this URL before... yuck!)
275 * Only meaningful if ACCEPT_TYPE_IS_MSIE set
277 #define ACCEPT_TYPE_MSIE_IMAGE 0x0002
280 * *If* this is MSIE, it wants a HTML document.
281 * Only meaningful if ACCEPT_TYPE_IS_MSIE set
283 #define ACCEPT_TYPE_MSIE_HTML 0x0004
285 #endif /* def DETECT_MSIE_IMAGES */
290 /* The proxy's configuration */
291 struct configuration_spec * config;
294 /* The permissions that the current URL has */
298 /* socket to talk to client (web browser) */
301 /* socket to talk to server (web server or proxy) */
306 /* 1 if this URL was rejected, 0 otherwise. Allows actual stats inc to
307 * occur in main thread only for thread-safety.
310 #endif /* def STATISTICS */
314 #endif /* def FORCE_LOAD */
318 #endif /* def TOGGLE */
321 * Client PC's IP address, as reported by the accept()_ function.
322 * Both as string and number
328 /* The referer in this request, if one was specified. */
330 #endif /* def TRUST_FILES */
332 #if defined(DETECT_MSIE_IMAGES)
333 /* Types the client will accept.
334 * Bitmask - see ACCEPT_TYPE_XXX constants.
337 #endif /* defined(DETECT_MSIE_IMAGES) */
339 /* The URL that was requested */
340 struct http_request http[1];
342 /* An I/O buffer used for buffering data read from the client */
345 /* List of all headers for this request */
346 struct list headers[1];
348 /* List of all cookies for this request */
349 struct list cookie_list[1];
351 #if defined(PCRS) || defined(KILLPOPUPS)
352 /* Nonzero if this has a text MIME type */
354 #endif /* defined(PCRS) || defined(KILLPOPUPS) */
356 /* The "X-Forwarded-For:" header sent by the client */
360 * Nonzero if this client is processing data.
361 * Set to zero when the thread associated with this structure dies.
365 /* files associated with this client */
366 struct file_list *flist; /* forwardfile */
367 struct file_list *permissions_list;
371 struct file_list *alist; /* aclfile */
372 #endif /* def ACL_FILES */
375 struct file_list *rlist; /* Perl re_filterfile */
376 size_t content_length; /* Length after processing */
377 #endif /* def PCRS */
380 struct file_list *tlist; /* trustfile */
381 #endif /* def TRUST_FILES */
383 struct client_state *next;
391 char *(*parser)(const struct parsers *, char *, struct client_state *);
399 char *(*interceptor)(struct http_request *http, struct client_state *csp);
425 * this is a pointer to the data structures associated with the file.
426 * Read-only once the structure has been created.
430 /* Normally NULL. When we are finished with file (i.e. when we have
431 * loaded a new one), set to a pointer to an unloader function.
432 * Unloader will be called by sweep() (called from main loop) when
433 * all clients using this file are done. This prevents threading
436 void (*unloader)(void *);
438 /* Used internally by sweep(). Do not access from elsewhere. */
441 #ifndef SPLIT_PROXY_ARGS
442 /* String to be displayed as part of show-proxy-args display.
443 * Read-only once the structure has been created.
446 #endif /* ndef SPLIT_PROXY_ARGS */
448 /* Following variables allow us to check if file has been changed.
449 * Read-only once the structure has been created.
454 /* Pointer to next entry in the linked list of all "file_list"s.
455 * This linked list is so that sweep() can navigate it.
456 * Since sweep() can remove items from the list, we must be careful
457 * to only access this value from main thread (when we know sweep
460 struct file_list *next;
467 struct url_spec url[1];
469 struct block_spec *next;
471 #endif /* def TRUST_FILES */
474 #define PERMIT_COOKIE_SET 0x0001U
475 #define PERMIT_COOKIE_READ 0x0002U
476 #define PERMIT_RE_FILTER 0x0004U
477 #define PERMIT_POPUPS 0x0008U
478 #define PERMIT_REFERER 0x0010U /* sic - follow HTTP, not English */
479 #define PERMIT_FAST_REDIRECTS 0x0020U
480 #define PERMIT_BLOCK 0x0040U
481 #define PERMIT_IMAGE 0x0080U
483 #define PERMIT_USER_AGENT PERMIT_COOKIE_SET /* FIXME Alias this for now */
485 #define PERMIT_MASK_ALL (~0U)
487 #define PERMIT_MOST_COMPATIBLE (PERMIT_COOKIE_SET | PERMIT_COOKIE_READ | \
488 PERMIT_REFERER | PERMIT_POPUPS | PERMIT_USER_AGENT)
490 struct permissions_spec
492 struct url_spec url[1];
493 unsigned mask; /* a bit set to "0" = remove permission */
494 unsigned add; /* a bit set to "1" = add permission */
495 struct permissions_spec * next;
501 struct url_spec url[1];
502 struct gateway gw[1];
503 struct forward_spec *next;
508 struct re_filterfile_spec
510 struct list patterns[1];
511 /* See README.re_filter */
514 #endif /* def PCRS */
518 #define ACL_PERMIT 1 /* accept connection request */
519 #define ACL_DENY 2 /* reject connection request */
521 struct access_control_addr
528 struct access_control_list
530 struct access_control_addr src[1];
531 struct access_control_addr dst[1];
534 struct access_control_list *next;
536 #endif /* def ACL_FILES */
539 /* Maximum number of loaders (permissions, block, forward, acl...) */
543 * Data loaded from the configuration file.
545 * (Anomaly: toggle is still handled through a global, not this structure)
547 struct configuration_spec
552 #ifdef IMAGE_BLOCKING
554 const char *tinygifurl;
555 #endif /* def IMAGE_BLOCKING */
559 const char *permissions_file;
560 const char *forwardfile;
564 #endif /* def ACL_FILES */
567 const char *re_filterfile;
568 #endif /* def PCRS */
571 * Permissions to use for URLs not in the permissions list.
573 int default_permissions;
576 const char * jarfile;
578 #endif /* def JAR_FILES */
580 const char *referrer;
586 struct list wafer_list[1];
587 struct list xtra_list[1];
590 * Port and IP to bind to.
591 * Defaults to HADDR_DEFAULT:HADDR_PORT == 127.0.0.1:8000
596 #ifndef SPLIT_PROXY_ARGS
597 const char *suppress_message;
598 #endif /* ndef SPLIT_PROXY_ARGS */
600 #ifndef SPLIT_PROXY_ARGS
601 /* suppress listing config files */
602 int suppress_blocklists;
603 #endif /* ndef SPLIT_PROXY_ARGS */
606 const char * trustfile;
608 struct list trust_info[1];
609 struct url_spec *trust_list[64];
610 #endif /* def TRUST_FILES */
612 /* Various strings for show-proxy-args */
613 char *proxy_args_header;
614 char *proxy_args_invocation;
615 char *proxy_args_gateways;
616 char *proxy_args_trailer;
618 /* the configuration file object. */
619 struct file_list *config_file_list;
621 /* List of loaders */
622 int (*loaders[NLOADERS])(struct client_state *);
624 /* bool, nonzero if we need to bind() to the new port */
629 #define SZ(X) (sizeof(X) / sizeof(*X))
631 #define WHITEBG "<body bgcolor=\"#ffffff\" link=\"#000078\" alink=\"#ff0022\" vlink=\"#787878\">\n"
632 #define BODY "<body bgcolor=\"#f8f8f0\" link=\"#000078\" alink=\"#ff0022\" vlink=\"#787878\">\n"
633 #define BANNER "<strong>Internet J<small>UNK<i><font color=\"red\">BUSTER</font></i></small></strong>"
636 #define FORCE_PREFIX "/IJB-FORCE-LOAD"
637 #endif /* def FORCE_LOAD */
639 #define HOME_PAGE_URL "http://ijbswa.sourceforge.net/"
640 #define REDIRECT_URL HOME_PAGE_URL "redirect.php?v=" VERSION "&to="
642 static const char CFAIL[] =
643 "HTTP/1.0 503 Connect failed\n"
644 "Content-Type: text/html\n\n"
647 "<title>Internet Junkbuster: Connect failed</title>\n"
653 "TCP connection to '%s' failed: %s.\n<br>"
657 static const char CNXDOM[] =
658 "HTTP/1.0 404 Non-existent domain\n"
659 "Content-Type: text/html\n\n"
662 "<title>Internet Junkbuster: Non-existent domain</title>\n"
668 "No such domain: %s\n"
672 static const char CNOBANNER[] =
673 "HTTP/1.0 200 No Banner\n"
674 "Content-Type: text/html\n\n"
677 "<title>Internet Junkbuster: No Banner</title>\n"
683 "You asked for a banner that this proxy can't produce because either configuration does not permit.\n<br>"
684 "or the URL didn't end with .gif\n"
688 static const char CSUCCEED[] =
689 "HTTP/1.0 200 Connection established\n"
690 "Proxy-Agent: IJ/" VERSION "\n\n";
692 static const char CHEADER[] =
693 "HTTP/1.0 400 Invalid header received from browser\n\n";
695 static const char SHEADER[] =
696 "HTTP/1.0 502 Invalid header received from server\n\n";
698 #ifdef IMAGE_BLOCKING
701 * Hint: You can encode your own GIFs like that:
702 * perl -e 'while (read STDIN, $c, 1) { printf("\\%.3o,", unpack("C", $c)); }'
705 static const char BLANKGIF[] =
706 "HTTP/1.0 200 OK\r\n"
707 "Pragma: no-cache\r\n"
708 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
709 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
710 "Content-type: image/gif\r\n\r\n"
711 "GIF89a\001\000\001\000\200\000\000\377\377\377\000\000"
712 "\000!\371\004\001\000\000\000\000,\000\000\000\000\001"
713 "\000\001\000\000\002\002D\001\000;";
715 static const char JBGIF[] =
716 "HTTP/1.0 200 OK\r\n"
717 "Pragma: no-cache\r\n"
718 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
719 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
720 "Content-type: image/gif\r\n\r\n"
721 "GIF89aD\000\013\000\360\000\000\000\000\000\377\377\377!"
722 "\371\004\001\000\000\001\000,\000\000\000\000D\000\013\000"
723 "\000\002a\214\217\251\313\355\277\000\200G&K\025\316hC\037"
724 "\200\234\230Y\2309\235S\230\266\206\372J\253<\3131\253\271"
725 "\270\215\342\254\013\203\371\202\264\334P\207\332\020o\266"
726 "N\215I\332=\211\312\3513\266:\026AK)\364\370\365aobr\305"
727 "\372\003S\275\274k2\354\254z\347?\335\274x\306^9\374\276"
730 #endif /* def IMAGE_BLOCKING */
732 #if defined(FAST_REDIRECTS) || defined(IMAGE_BLOCKING)
734 static const char HTTP_REDIRECT_TEMPLATE[] =
735 "HTTP/1.0 302 Local Redirect from Junkbuster\r\n"
736 "Pragma: no-cache\r\n"
737 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
738 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
739 "Location: %s\r\n\r\n";
741 #endif /* defined(FAST_REDIRECTS) || defined(IMAGE_BLOCKING) */
747 #endif /* ndef _PROJECT_H */