3 #define PROJECT_H_VERSION "$Id: project.h,v 1.5 2001/05/26 00:28:36 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.5 2001/05/26 00:28:36 jongfoster
40 * Automatic reloading of config file.
41 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
42 * Most of the global variables have been moved to a new
43 * struct configuration_spec, accessed through csp->config->globalname
44 * Most of the globals remaining are used by the Win32 GUI.
46 * Revision 1.4 2001/05/22 18:46:04 oes
48 * - Enabled filtering banners by size rather than URL
49 * by adding patterns that replace all standard banner
50 * sizes with the "Junkbuster" gif to the re_filterfile
52 * - Enabled filtering WebBugs by providing a pattern
53 * which kills all 1x1 images
55 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
56 * which is selected by the (nonstandard and therefore
57 * capital) letter 'U' in the option string.
58 * It causes the quantifiers to be ungreedy by default.
59 * Appending a ? turns back to greedy (!).
61 * - Added a new interceptor ijb-send-banner, which
62 * sends back the "Junkbuster" gif. Without imagelist or
63 * MSIE detection support, or if tinygif = 1, or the
64 * URL isn't recognized as an imageurl, a lame HTML
65 * explanation is sent instead.
67 * - Added new feature, which permits blocking remote
68 * script redirects and firing back a local redirect
70 * The feature is conditionally compiled, i.e. it
71 * can be disabled with --disable-fast-redirects,
72 * plus it must be activated by a "fast-redirects"
73 * line in the config file, has its own log level
74 * and of course wants to be displayed by show-proxy-args
75 * Note: Boy, all the #ifdefs in 1001 locations and
76 * all the fumbling with configure.in and acconfig.h
77 * were *way* more work than the feature itself :-(
79 * - Because a generic redirect template was needed for
80 * this, tinygif = 3 now uses the same.
82 * - Moved GIFs, and other static HTTP response templates
87 * - Removed some >400 CRs again (Jon, you really worked
90 * Revision 1.3 2001/05/20 01:21:20 jongfoster
91 * Version 2.9.4 checkin.
92 * - Merged popupfile and cookiefile, and added control over PCRS
93 * filtering, in new "permissionsfile".
94 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
95 * file error you now get a message box (in the Win32 GUI) rather
96 * than the program exiting with no explanation.
97 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
99 * - Removed tabs from "config"
100 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
101 * - Bumped up version number.
103 * Revision 1.2 2001/05/17 23:01:01 oes
104 * - Cleaned CRLF's from the sources and related files
106 * Revision 1.1.1.1 2001/05/15 13:59:03 oes
107 * Initial import of version 2.9.3 source tree
110 *********************************************************************/
113 /* Declare struct FILE for vars and funcs. */
116 /* Need time_t for file_list */
120 * Include appropriate regular expression libraries.
122 * PCRS ==> Include pcre
123 * REGEX && PCRE ==> Include pcre and pcreposix
124 * REGEX && !PCRE ==> Include gnu_regex
126 * STATIC ==> Use #include "pcre.h" (compiling at same time)
127 * !STATIC ==> Use #include <pcre.h> (System library)
130 #if (defined(REGEX) && defined(PCRE)) || defined(PCRS)
136 #endif /* (defined(REGEX) && defined(PCRE)) || defined(PCRS) */
138 #if defined(REGEX) && defined(PCRE)
140 # include "pcreposix.h"
142 # include <pcreposix.h>
144 #endif /* defined(REGEX) && defined(PCRE) */
146 #if defined(REGEX) && !defined(PCRE)
147 # include "gnu_regex.h"
152 #endif /* def PCRS */
156 #endif /* def AMIGA */
164 /* Default IP and port to listen on */
165 #define HADDR_DEFAULT "127.0.0.1"
166 #define HADDR_PORT 8000
169 /* Need this for struct gateway */
172 /* Need this for struct client_state */
173 struct configuration_spec;
184 char *hostport; /* "host[:port]" */
190 /* generic attributes */
192 int (*conn)(const struct gateway *, struct http_request *, struct client_state *);
195 /* domain specific attributes */
228 #define IOB_PEEK(CSP) ((CSP->iob->cur > CSP->iob->eod) ? (CSP->iob->eod - CSP->iob->cur) : 0)
229 #define IOB_RESET(CSP) if(CSP->iob->buf) free(CSP->iob->buf); memset(CSP->iob, '\0', sizeof(CSP->iob));
232 /* Constants defining bitmask for csp->accept_types */
234 #ifdef DETECT_MSIE_IMAGES
236 /* MSIE detected by user-agent string */
237 #define ACCEPT_TYPE_IS_MSIE 0x0001
240 * *If* this is MSIE, it wants an image. (Or this is a shift-reload, or
241 * it's got an image from this URL before... yuck!)
242 * Only meaningful if ACCEPT_TYPE_IS_MSIE set
244 #define ACCEPT_TYPE_MSIE_IMAGE 0x0002
247 * *If* this is MSIE, it wants a HTML document.
248 * Only meaningful if ACCEPT_TYPE_IS_MSIE set
250 #define ACCEPT_TYPE_MSIE_HTML 0x0004
252 #endif /* def DETECT_MSIE_IMAGES */
257 struct configuration_spec * config;
265 /* 1 if this URL was rejected, 0 otherwise. Allows actual stats inc to
266 * occur in main thread only for thread-safety.
269 #endif /* def STATISTICS */
273 #endif /* def FORCE_LOAD */
277 #endif /* def TOGGLE */
283 #if defined(DETECT_MSIE_IMAGES)
284 /* Types the client will accept.
285 * Bitmask - see ACCEPT_TYPE_XXX constants.
288 #endif /* defined(DETECT_MSIE_IMAGES) */
290 const struct gateway *gw;
291 struct http_request http[1];
295 struct list headers[1];
296 struct list cookie_list[1];
297 #if defined(PCRS) || defined(KILLPOPUPS)
299 #endif /* defined(PCRS) || defined(KILLPOPUPS) */
305 /* files associated with this client */
306 struct file_list *blist; /* blockfile */
307 struct file_list *flist; /* forwardfile */
308 struct file_list *permissions_list;
312 struct file_list *alist; /* aclfile */
313 #endif /* def ACL_FILES */
315 #ifdef USE_IMAGE_LIST
316 struct file_list *ilist; /* imagefile */
317 #endif /* def USE_IMAGE_LIST */
320 struct file_list *rlist; /* Perl re_filterfile */
321 size_t content_length; /* Length after processing */
322 #endif /* def PCRS */
325 struct file_list *tlist; /* trustfile */
326 #endif /* def TRUST_FILES */
328 struct client_state *next;
336 char *(*parser)(const struct parsers *, char *, struct client_state *);
344 char *(*interceptor)(struct http_request *http, struct client_state *csp);
348 /* this allows the proxy to permit/block access to any host and/or path */
371 * this is a pointer to the data structures associated with the file.
372 * Read-only once the structure has been created.
376 /* Normally NULL. When we are finished with file (i.e. when we have
377 * loaded a new one), set to a pointer to an unloader function.
378 * Unloader will be called by sweep() (called from main loop) when
379 * all clients using this file are done. This prevents threading
382 void (*unloader)(void *);
384 /* Used internally by sweep(). Do not access from elsewhere. */
387 #ifndef SPLIT_PROXY_ARGS
388 /* String to be displayed as part of show-proxy-args display.
389 * Read-only once the structure has been created.
392 #endif /* ndef SPLIT_PROXY_ARGS */
394 /* Following variables allow us to check if file has been changed.
395 * Read-only once the structure has been created.
400 /* Pointer to next entry in the linked list of all "file_list"s.
401 * This linked list is so that sweep() can navigate it.
402 * Since sweep() can remove items from the list, we must be careful
403 * to only access this value from main thread (when we know sweep
406 struct file_list *next;
412 struct url_spec url[1];
414 struct block_spec *next;
418 #define PERMIT_COOKIE_SET 0x0001
419 #define PERMIT_COOKIE_READ 0x0002
420 #define PERMIT_RE_FILTER 0x0004
421 #define PERMIT_POPUPS 0x0008
423 struct permissions_spec
425 struct url_spec url[1];
427 struct permissions_spec * next;
432 struct url_spec url[1];
434 struct gateway gw[1];
435 struct forward_spec *next;
440 struct re_filterfile_spec
442 struct list patterns[1];
443 /* See README.re_filter */
446 #endif /* def PCRS */
450 #define ACL_PERMIT 1 /* accept connection request */
451 #define ACL_DENY 2 /* reject connection request */
453 struct access_control_addr
460 struct access_control_list
462 struct access_control_addr src[1];
463 struct access_control_addr dst[1];
466 struct access_control_list *next;
468 #endif /* def ACL_FILES */
470 /* Maximum number of loaders (permissions, block, forward, acl...) */
474 * Data loaded from the configuration file.
476 * (Anomaly: toggle is still handled through a global, not this structure)
478 struct configuration_spec
483 #if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST)
485 const char *tinygifurl;
486 #endif /* defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) */
490 const char *blockfile;
491 const char *permissions_file;
492 const char *forwardfile;
496 #endif /* def ACL_FILES */
498 #ifdef USE_IMAGE_LIST
499 const char *imagefile;
500 #endif /* def USE_IMAGE_LIST */
503 const char *re_filterfile;
504 #endif /* def PCRS */
507 * Permissions to use for URLs not in the permissions list.
509 int default_permissions;
512 const char * jarfile;
514 #endif /* def JAR_FILES */
516 const char *referrer;
522 struct list wafer_list[1];
523 struct list xtra_list[1];
526 * Port and IP to bind to.
527 * Defaults to HADDR_DEFAULT:HADDR_PORT == 127.0.0.1:8000
532 #ifndef SPLIT_PROXY_ARGS
533 const char *suppress_message;
534 #endif /* ndef SPLIT_PROXY_ARGS */
536 #ifndef SPLIT_PROXY_ARGS
537 /* suppress listing sblock and simage */
538 int suppress_blocklists;
539 #endif /* ndef SPLIT_PROXY_ARGS */
541 #ifdef FAST_REDIRECTS
543 #endif /* def FAST_REDIRECTS */
546 const char * trustfile;
548 struct list trust_info[1];
549 struct url_spec *trust_list[64];
550 #endif /* def TRUST_FILES */
552 struct proxy_args proxy_args[1];
554 struct file_list *config_file_list;
556 int (*loaders[NLOADERS])(struct client_state *);
558 int need_bind; /* bool, nonzero if we need to bind() to the new port */
562 #define SZ(X) (sizeof(X) / sizeof(*X))
564 #define WHITEBG "<body bgcolor=\"#ffffff\" link=\"#000078\" alink=\"#ff0022\" vlink=\"#787878\">\n"
565 #define BODY "<body bgcolor=\"#f8f8f0\" link=\"#000078\" alink=\"#ff0022\" vlink=\"#787878\">\n"
566 #define BANNER "<strong>Internet J<small>UNK<i><font color=\"red\">BUSTER</font></i></small></strong>"
569 #define FORCE_PREFIX "/IJB-FORCE-LOAD"
570 #endif /* def FORCE_LOAD */
572 #define HOME_PAGE_URL "http://ijbswa.sourceforge.net/"
573 #define REDIRECT_URL HOME_PAGE_URL "redirect.php?v=" VERSION "&to="
575 static const char CFAIL[] =
576 "HTTP/1.0 503 Connect failed\n"
577 "Content-Type: text/html\n\n"
580 "<title>Internet Junkbuster: Connect failed</title>\n"
586 "TCP connection to '%s' failed: %s.\n<br>"
590 static const char CNXDOM[] =
591 "HTTP/1.0 404 Non-existent domain\n"
592 "Content-Type: text/html\n\n"
595 "<title>Internet Junkbuster: Non-existent domain</title>\n"
601 "No such domain: %s\n"
605 static const char CNOBANNER[] =
606 "HTTP/1.0 200 No Banner\n"
607 "Content-Type: text/html\n\n"
610 "<title>Internet Junkbuster: No Banner</title>\n"
616 "You asked for a banner that this proxy can't produce because either configuration does not permit.\n<br>"
617 "or the URL didn't end with .gif\n"
621 static const char CSUCCEED[] =
622 "HTTP/1.0 200 Connection established\n"
623 "Proxy-Agent: IJ/" VERSION "\n\n";
625 static const char CHEADER[] =
626 "HTTP/1.0 400 Invalid header received from browser\n\n";
628 static const char SHEADER[] =
629 "HTTP/1.0 502 Invalid header received from server\n\n";
631 #if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST)
634 * Hint: You can encode your own GIFs like that:
635 * perl -e 'while (read STDIN, $c, 1) { printf("\\%.3o,", unpack("C", $c)); }'
638 static const char BLANKGIF[] =
639 "HTTP/1.0 200 OK\r\n"
640 "Pragma: no-cache\r\n"
641 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
642 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
643 "Content-type: image/gif\r\n\r\n"
644 "GIF89a\001\000\001\000\200\000\000\377\377\377\000\000"
645 "\000!\371\004\001\000\000\000\000,\000\000\000\000\001"
646 "\000\001\000\000\002\002D\001\000;";
648 static const char JBGIF[] =
649 "HTTP/1.0 200 OK\r\n"
650 "Pragma: no-cache\r\n"
651 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
652 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
653 "Content-type: image/gif\r\n\r\n"
654 "GIF89aD\000\013\000\360\000\000\000\000\000\377\377\377!"
655 "\371\004\001\000\000\001\000,\000\000\000\000D\000\013\000"
656 "\000\002a\214\217\251\313\355\277\000\200G&K\025\316hC\037"
657 "\200\234\230Y\2309\235S\230\266\206\372J\253<\3131\253\271"
658 "\270\215\342\254\013\203\371\202\264\334P\207\332\020o\266"
659 "N\215I\332=\211\312\3513\266:\026AK)\364\370\365aobr\305"
660 "\372\003S\275\274k2\354\254z\347?\335\274x\306^9\374\276"
663 #endif /* defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) */
665 #if defined(FAST_REDIRECTS) || defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST)
667 static const char HTTP_REDIRECT_TEMPLATE[] =
668 "HTTP/1.0 302 Local Redirect from Junkbuster\r\n"
669 "Pragma: no-cache\r\n"
670 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
671 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
674 #endif /* defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) */
680 #endif /* ndef _PROJECT_H */