3 #define PROJECT_H_VERSION "$Id: project.h,v 1.4 2001/05/22 18:46:04 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.4 2001/05/22 18:46:04 oes
41 * - Enabled filtering banners by size rather than URL
42 * by adding patterns that replace all standard banner
43 * sizes with the "Junkbuster" gif to the re_filterfile
45 * - Enabled filtering WebBugs by providing a pattern
46 * which kills all 1x1 images
48 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
49 * which is selected by the (nonstandard and therefore
50 * capital) letter 'U' in the option string.
51 * It causes the quantifiers to be ungreedy by default.
52 * Appending a ? turns back to greedy (!).
54 * - Added a new interceptor ijb-send-banner, which
55 * sends back the "Junkbuster" gif. Without imagelist or
56 * MSIE detection support, or if tinygif = 1, or the
57 * URL isn't recognized as an imageurl, a lame HTML
58 * explanation is sent instead.
60 * - Added new feature, which permits blocking remote
61 * script redirects and firing back a local redirect
63 * The feature is conditionally compiled, i.e. it
64 * can be disabled with --disable-fast-redirects,
65 * plus it must be activated by a "fast-redirects"
66 * line in the config file, has its own log level
67 * and of course wants to be displayed by show-proxy-args
68 * Note: Boy, all the #ifdefs in 1001 locations and
69 * all the fumbling with configure.in and acconfig.h
70 * were *way* more work than the feature itself :-(
72 * - Because a generic redirect template was needed for
73 * this, tinygif = 3 now uses the same.
75 * - Moved GIFs, and other static HTTP response templates
80 * - Removed some >400 CRs again (Jon, you really worked
83 * Revision 1.3 2001/05/20 01:21:20 jongfoster
84 * Version 2.9.4 checkin.
85 * - Merged popupfile and cookiefile, and added control over PCRS
86 * filtering, in new "permissionsfile".
87 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
88 * file error you now get a message box (in the Win32 GUI) rather
89 * than the program exiting with no explanation.
90 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
92 * - Removed tabs from "config"
93 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
94 * - Bumped up version number.
96 * Revision 1.2 2001/05/17 23:01:01 oes
97 * - Cleaned CRLF's from the sources and related files
99 * Revision 1.1.1.1 2001/05/15 13:59:03 oes
100 * Initial import of version 2.9.3 source tree
103 *********************************************************************/
106 /* Declare struct FILE for vars and funcs. */
109 /* Need time_t for file_list */
113 * Include appropriate regular expression libraries.
115 * PCRS ==> Include pcre
116 * REGEX && PCRE ==> Include pcre and pcreposix
117 * REGEX && !PCRE ==> Include gnu_regex
119 * STATIC ==> Use #include "pcre.h" (compiling at same time)
120 * !STATIC ==> Use #include <pcre.h> (System library)
123 #if (defined(REGEX) && defined(PCRE)) || defined(PCRS)
129 #endif /* (defined(REGEX) && defined(PCRE)) || defined(PCRS) */
131 #if defined(REGEX) && defined(PCRE)
133 # include "pcreposix.h"
135 # include <pcreposix.h>
137 #endif /* defined(REGEX) && defined(PCRE) */
139 #if defined(REGEX) && !defined(PCRE)
140 # include "gnu_regex.h"
145 #endif /* def PCRS */
149 #endif /* def AMIGA */
157 /* Default IP and port to listen on */
158 #define HADDR_DEFAULT "127.0.0.1"
159 #define HADDR_PORT 8000
162 /* Need this for struct gateway */
165 /* Need this for struct client_state */
166 struct configuration_spec;
177 char *hostport; /* "host[:port]" */
183 /* generic attributes */
185 int (*conn)(const struct gateway *, struct http_request *, struct client_state *);
188 /* domain specific attributes */
221 #define IOB_PEEK(CSP) ((CSP->iob->cur > CSP->iob->eod) ? (CSP->iob->eod - CSP->iob->cur) : 0)
222 #define IOB_RESET(CSP) if(CSP->iob->buf) free(CSP->iob->buf); memset(CSP->iob, '\0', sizeof(CSP->iob));
225 /* Constants defining bitmask for csp->accept_types */
227 #ifdef DETECT_MSIE_IMAGES
229 /* MSIE detected by user-agent string */
230 #define ACCEPT_TYPE_IS_MSIE 0x0001
233 * *If* this is MSIE, it wants an image. (Or this is a shift-reload, or
234 * it's got an image from this URL before... yuck!)
235 * Only meaningful if ACCEPT_TYPE_IS_MSIE set
237 #define ACCEPT_TYPE_MSIE_IMAGE 0x0002
240 * *If* this is MSIE, it wants a HTML document.
241 * Only meaningful if ACCEPT_TYPE_IS_MSIE set
243 #define ACCEPT_TYPE_MSIE_HTML 0x0004
245 #endif /* def DETECT_MSIE_IMAGES */
250 struct configuration_spec * config;
258 /* 1 if this URL was rejected, 0 otherwise. Allows actual stats inc to
259 * occur in main thread only for thread-safety.
262 #endif /* def STATISTICS */
266 #endif /* def FORCE_LOAD */
270 * by haroon - most of credit to srt19170
271 * We add an "on/off" toggle here that is used to effectively toggle
272 * the Junkbuster off or on
281 #if defined(DETECT_MSIE_IMAGES)
282 /* Types the client will accept.
283 * Bitmask - see ACCEPT_TYPE_XXX constants.
286 #endif /* defined(DETECT_MSIE_IMAGES) */
288 const struct gateway *gw;
289 struct http_request http[1];
293 struct list headers[1];
294 struct list cookie_list[1];
295 #if defined(PCRS) || defined(KILLPOPUPS)
297 #endif /* defined(PCRS) || defined(KILLPOPUPS) */
303 /* files associated with this client */
304 struct file_list *blist; /* blockfile */
305 struct file_list *flist; /* forwardfile */
306 struct file_list *permissions_list;
310 struct file_list *alist; /* aclfile */
311 #endif /* def ACL_FILES */
313 #ifdef USE_IMAGE_LIST
314 struct file_list *ilist; /* imagefile */
315 #endif /* def USE_IMAGE_LIST */
318 struct file_list *rlist; /* Perl re_filterfile */
319 #endif /* def PCRS */
322 struct file_list *tlist; /* trustfile */
323 #endif /* def TRUST_FILES */
325 struct client_state *next;
333 char *(*parser)(const struct parsers *, char *, struct client_state *);
341 char *(*interceptor)(struct http_request *http, struct client_state *csp);
345 /* this allows the proxy to permit/block access to any host and/or path */
368 * this is a pointer to the data structures associated with the file.
369 * Read-only once the structure has been created.
373 /* Normally NULL. When we are finished with file (i.e. when we have
374 * loaded a new one), set to a pointer to an unloader function.
375 * Unloader will be called by sweep() (called from main loop) when
376 * all clients using this file are done. This prevents threading
379 void (*unloader)(void *);
381 /* Used internally by sweep(). Do not access from elsewhere. */
384 #ifndef SPLIT_PROXY_ARGS
385 /* String to be displayed as part of show-proxy-args display.
386 * Read-only once the structure has been created.
389 #endif /* ndef SPLIT_PROXY_ARGS */
391 /* Following variables allow us to check if file has been changed.
392 * Read-only once the structure has been created.
397 /* Pointer to next entry in the linked list of all "file_list"s.
398 * This linked list is so that sweep() can navigate it.
399 * Since sweep() can remove items from the list, we must be careful
400 * to only access this value from main thread (when we know sweep
403 struct file_list *next;
409 struct url_spec url[1];
411 struct block_spec *next;
415 #define PERMIT_COOKIE_SET 0x0001
416 #define PERMIT_COOKIE_READ 0x0002
417 #define PERMIT_RE_FILTER 0x0004
418 #define PERMIT_POPUPS 0x0008
420 struct permissions_spec
422 struct url_spec url[1];
424 struct permissions_spec * next;
429 struct url_spec url[1];
431 struct gateway gw[1];
432 struct forward_spec *next;
437 struct re_filterfile_spec
439 struct list patterns[1];
440 /* See README.re_filter */
443 #endif /* def PCRS */
447 #define ACL_PERMIT 1 /* accept connection request */
448 #define ACL_DENY 2 /* reject connection request */
450 struct access_control_addr
457 struct access_control_list
459 struct access_control_addr src[1];
460 struct access_control_addr dst[1];
463 struct access_control_list *next;
465 #endif /* def ACL_FILES */
467 /* Maximum number of loaders (permissions, block, forward, acl...) */
471 * Data loaded from the configuration file.
473 * (Anomaly: toggle is still handled through a global, not this structure)
475 struct configuration_spec
480 #if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST)
482 const char *tinygifurl;
483 #endif /* defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) */
487 const char *blockfile;
488 const char *permissions_file;
489 const char *forwardfile;
493 #endif /* def ACL_FILES */
495 #ifdef USE_IMAGE_LIST
496 const char *imagefile;
497 #endif /* def USE_IMAGE_LIST */
500 const char *re_filterfile;
501 #endif /* def PCRS */
504 * Permissions to use for URLs not in the permissions list.
506 int default_permissions;
509 const char * jarfile;
511 #endif /* def JAR_FILES */
513 const char *referrer;
519 struct list wafer_list[1];
520 struct list xtra_list[1];
523 * Port and IP to bind to.
524 * Defaults to HADDR_DEFAULT:HADDR_PORT == 127.0.0.1:8000
529 #ifndef SPLIT_PROXY_ARGS
530 const char *suppress_message;
531 #endif /* ndef SPLIT_PROXY_ARGS */
533 #ifndef SPLIT_PROXY_ARGS
534 /* suppress listing sblock and simage */
535 int suppress_blocklists;
536 #endif /* ndef SPLIT_PROXY_ARGS */
538 #ifdef FAST_REDIRECTS
540 #endif /* def FAST_REDIRECTS */
543 const char * trustfile;
545 struct list trust_info[1];
546 struct url_spec *trust_list[64];
547 #endif /* def TRUST_FILES */
549 struct proxy_args proxy_args[1];
551 struct file_list *config_file_list;
553 int (*loaders[NLOADERS])(struct client_state *);
555 int need_bind; /* bool, nonzero if we need to bind() to the new port */
559 #define SZ(X) (sizeof(X) / sizeof(*X))
561 #define WHITEBG "<body bgcolor=\"#ffffff\" link=\"#000078\" alink=\"#ff0022\" vlink=\"#787878\">\n"
562 #define BODY "<body bgcolor=\"#f8f8f0\" link=\"#000078\" alink=\"#ff0022\" vlink=\"#787878\">\n"
563 #define BANNER "<strong>Internet J<small>UNK<i><font color=\"red\">BUSTER</font></i></small></strong>"
566 #define FORCE_PREFIX "/IJB-FORCE-LOAD"
567 #endif /* def FORCE_LOAD */
569 #define HOME_PAGE_URL "http://ijbswa.sourceforge.net/"
570 #define REDIRECT_URL HOME_PAGE_URL "redirect.php?v=" VERSION "&to="
572 static const char CFAIL[] =
573 "HTTP/1.0 503 Connect failed\n"
574 "Content-Type: text/html\n\n"
577 "<title>Internet Junkbuster: Connect failed</title>\n"
583 "TCP connection to '%s' failed: %s.\n<br>"
587 static const char CNXDOM[] =
588 "HTTP/1.0 404 Non-existent domain\n"
589 "Content-Type: text/html\n\n"
592 "<title>Internet Junkbuster: Non-existent domain</title>\n"
598 "No such domain: %s\n"
602 static const char CNOBANNER[] =
603 "HTTP/1.0 200 No Banner\n"
604 "Content-Type: text/html\n\n"
607 "<title>Internet Junkbuster: No Banner</title>\n"
613 "You asked for a banner that this proxy can't produce because either configuration does not permit.\n<br>"
614 "or the URL didn't end with .gif\n"
618 static const char CSUCCEED[] =
619 "HTTP/1.0 200 Connection established\n"
620 "Proxy-Agent: IJ/" VERSION "\n\n";
622 static const char CHEADER[] =
623 "HTTP/1.0 400 Invalid header received from browser\n\n";
625 static const char SHEADER[] =
626 "HTTP/1.0 502 Invalid header received from server\n\n";
628 #if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST)
631 * Hint: You can encode your own GIFs like that:
632 * perl -e 'while (read STDIN, $c, 1) { printf("\\%.3o,", unpack("C", $c)); }'
635 static const char BLANKGIF[] =
636 "HTTP/1.0 200 OK\r\n"
637 "Pragma: no-cache\r\n"
638 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
639 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
640 "Content-type: image/gif\r\n\r\n"
641 "GIF89a\001\000\001\000\200\000\000\377\377\377\000\000"
642 "\000!\371\004\001\000\000\000\000,\000\000\000\000\001"
643 "\000\001\000\000\002\002D\001\000;";
645 static const char JBGIF[] =
646 "HTTP/1.0 200 OK\r\n"
647 "Pragma: no-cache\r\n"
648 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
649 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
650 "Content-type: image/gif\r\n\r\n"
651 "GIF89aD\000\013\000\360\000\000\000\000\000\377\377\377!"
652 "\371\004\001\000\000\001\000,\000\000\000\000D\000\013\000"
653 "\000\002a\214\217\251\313\355\277\000\200G&K\025\316hC\037"
654 "\200\234\230Y\2309\235S\230\266\206\372J\253<\3131\253\271"
655 "\270\215\342\254\013\203\371\202\264\334P\207\332\020o\266"
656 "N\215I\332=\211\312\3513\266:\026AK)\364\370\365aobr\305"
657 "\372\003S\275\274k2\354\254z\347?\335\274x\306^9\374\276"
660 #endif /* defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) */
662 #if defined(FAST_REDIRECTS) || defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST)
664 static const char HTTP_REDIRECT_TEMPLATE[] =
665 "HTTP/1.0 302 Local Redirect from Junkbuster\r\n"
666 "Pragma: no-cache\r\n"
667 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
668 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
671 #endif /* defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) */
677 #endif /* ndef _PROJECT_H */