3 #define PROJECT_H_VERSION "$Id: project.h,v 1.6 2001/05/27 22:17: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.6 2001/05/27 22:17:04 oes
41 * - re_process_buffer no longer writes the modified buffer
42 * to the client, which was very ugly. It now returns the
43 * buffer, which it is then written by chat.
45 * - content_length now adjusts the Content-Length: header
46 * for modified documents rather than crunch()ing it.
47 * (Length info in csp->content_length, which is 0 for
48 * unmodified documents)
50 * - For this to work, sed() is called twice when filtering.
52 * Revision 1.5 2001/05/26 00:28:36 jongfoster
53 * Automatic reloading of config file.
54 * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
55 * Most of the global variables have been moved to a new
56 * struct configuration_spec, accessed through csp->config->globalname
57 * Most of the globals remaining are used by the Win32 GUI.
59 * Revision 1.4 2001/05/22 18:46:04 oes
61 * - Enabled filtering banners by size rather than URL
62 * by adding patterns that replace all standard banner
63 * sizes with the "Junkbuster" gif to the re_filterfile
65 * - Enabled filtering WebBugs by providing a pattern
66 * which kills all 1x1 images
68 * - Added support for PCRE_UNGREEDY behaviour to pcrs,
69 * which is selected by the (nonstandard and therefore
70 * capital) letter 'U' in the option string.
71 * It causes the quantifiers to be ungreedy by default.
72 * Appending a ? turns back to greedy (!).
74 * - Added a new interceptor ijb-send-banner, which
75 * sends back the "Junkbuster" gif. Without imagelist or
76 * MSIE detection support, or if tinygif = 1, or the
77 * URL isn't recognized as an imageurl, a lame HTML
78 * explanation is sent instead.
80 * - Added new feature, which permits blocking remote
81 * script redirects and firing back a local redirect
83 * The feature is conditionally compiled, i.e. it
84 * can be disabled with --disable-fast-redirects,
85 * plus it must be activated by a "fast-redirects"
86 * line in the config file, has its own log level
87 * and of course wants to be displayed by show-proxy-args
88 * Note: Boy, all the #ifdefs in 1001 locations and
89 * all the fumbling with configure.in and acconfig.h
90 * were *way* more work than the feature itself :-(
92 * - Because a generic redirect template was needed for
93 * this, tinygif = 3 now uses the same.
95 * - Moved GIFs, and other static HTTP response templates
100 * - Removed some >400 CRs again (Jon, you really worked
103 * Revision 1.3 2001/05/20 01:21:20 jongfoster
104 * Version 2.9.4 checkin.
105 * - Merged popupfile and cookiefile, and added control over PCRS
106 * filtering, in new "permissionsfile".
107 * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
108 * file error you now get a message box (in the Win32 GUI) rather
109 * than the program exiting with no explanation.
110 * - Made killpopup use the PCRS MIME-type checking and HTTP-header
112 * - Removed tabs from "config"
113 * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
114 * - Bumped up version number.
116 * Revision 1.2 2001/05/17 23:01:01 oes
117 * - Cleaned CRLF's from the sources and related files
119 * Revision 1.1.1.1 2001/05/15 13:59:03 oes
120 * Initial import of version 2.9.3 source tree
123 *********************************************************************/
126 /* Declare struct FILE for vars and funcs. */
129 /* Need time_t for file_list */
133 * Include appropriate regular expression libraries.
135 * PCRS ==> Include pcre
136 * REGEX && PCRE ==> Include pcre and pcreposix
137 * REGEX && !PCRE ==> Include gnu_regex
139 * STATIC ==> Use #include "pcre.h" (compiling at same time)
140 * !STATIC ==> Use #include <pcre.h> (System library)
143 #if (defined(REGEX) && defined(PCRE)) || defined(PCRS)
149 #endif /* (defined(REGEX) && defined(PCRE)) || defined(PCRS) */
151 #if defined(REGEX) && defined(PCRE)
153 # include "pcreposix.h"
155 # include <pcreposix.h>
157 #endif /* defined(REGEX) && defined(PCRE) */
159 #if defined(REGEX) && !defined(PCRE)
160 # include "gnu_regex.h"
165 #endif /* def PCRS */
169 #endif /* def AMIGA */
177 /* Default IP and port to listen on */
178 #define HADDR_DEFAULT "127.0.0.1"
179 #define HADDR_PORT 8000
182 /* Need this for struct gateway */
185 /* Need this for struct client_state */
186 struct configuration_spec;
197 char *hostport; /* "host[:port]" */
203 /* generic attributes */
205 int (*conn)(const struct gateway *, struct http_request *, struct client_state *);
208 /* domain specific attributes */
217 /* Generic linked list of strings */
235 #define IOB_PEEK(CSP) ((CSP->iob->cur > CSP->iob->eod) ? (CSP->iob->eod - CSP->iob->cur) : 0)
236 #define IOB_RESET(CSP) if(CSP->iob->buf) free(CSP->iob->buf); memset(CSP->iob, '\0', sizeof(CSP->iob));
239 /* Constants defining bitmask for csp->accept_types */
241 #ifdef DETECT_MSIE_IMAGES
243 /* MSIE detected by user-agent string */
244 #define ACCEPT_TYPE_IS_MSIE 0x0001
247 * *If* this is MSIE, it wants an image. (Or this is a shift-reload, or
248 * it's got an image from this URL before... yuck!)
249 * Only meaningful if ACCEPT_TYPE_IS_MSIE set
251 #define ACCEPT_TYPE_MSIE_IMAGE 0x0002
254 * *If* this is MSIE, it wants a HTML document.
255 * Only meaningful if ACCEPT_TYPE_IS_MSIE set
257 #define ACCEPT_TYPE_MSIE_HTML 0x0004
259 #endif /* def DETECT_MSIE_IMAGES */
264 /* The proxy's configuration */
265 struct configuration_spec * config;
268 /* The permissions that the current URL has */
272 /* socket to talk to client (web browser) */
275 /* socket to talk to server (web server or proxy) */
280 /* 1 if this URL was rejected, 0 otherwise. Allows actual stats inc to
281 * occur in main thread only for thread-safety.
284 #endif /* def STATISTICS */
288 #endif /* def FORCE_LOAD */
292 #endif /* def TOGGLE */
295 * Client PC's IP address, as reported by the accept()_ function.
296 * Both as string and number
302 /* The referer in this request, if one was specified. */
304 #endif /* def TRUST_FILES */
306 #if defined(DETECT_MSIE_IMAGES)
307 /* Types the client will accept.
308 * Bitmask - see ACCEPT_TYPE_XXX constants.
311 #endif /* defined(DETECT_MSIE_IMAGES) */
313 /* The URL that was requested */
314 struct http_request http[1];
316 /* An I/O buffer used for buffering data read from the client */
319 /* List of all headers for this request */
320 struct list headers[1];
322 /* List of all cookies for this request */
323 struct list cookie_list[1];
325 #if defined(PCRS) || defined(KILLPOPUPS)
326 /* Nonzero if this has a text MIME type */
328 #endif /* defined(PCRS) || defined(KILLPOPUPS) */
330 /* The "X-Forwarded-For:" header sent by the client */
334 * Nonzero if this client is processing data.
335 * Set to zero when the thread associated with this structure dies.
339 /* files associated with this client */
340 struct file_list *flist; /* forwardfile */
341 struct file_list *permissions_list;
345 struct file_list *alist; /* aclfile */
346 #endif /* def ACL_FILES */
349 struct file_list *rlist; /* Perl re_filterfile */
350 size_t content_length; /* Length after processing */
351 #endif /* def PCRS */
354 struct file_list *tlist; /* trustfile */
355 #endif /* def TRUST_FILES */
357 struct client_state *next;
365 char *(*parser)(const struct parsers *, char *, struct client_state *);
373 char *(*interceptor)(struct http_request *http, struct client_state *csp);
399 * this is a pointer to the data structures associated with the file.
400 * Read-only once the structure has been created.
404 /* Normally NULL. When we are finished with file (i.e. when we have
405 * loaded a new one), set to a pointer to an unloader function.
406 * Unloader will be called by sweep() (called from main loop) when
407 * all clients using this file are done. This prevents threading
410 void (*unloader)(void *);
412 /* Used internally by sweep(). Do not access from elsewhere. */
415 #ifndef SPLIT_PROXY_ARGS
416 /* String to be displayed as part of show-proxy-args display.
417 * Read-only once the structure has been created.
420 #endif /* ndef SPLIT_PROXY_ARGS */
422 /* Following variables allow us to check if file has been changed.
423 * Read-only once the structure has been created.
428 /* Pointer to next entry in the linked list of all "file_list"s.
429 * This linked list is so that sweep() can navigate it.
430 * Since sweep() can remove items from the list, we must be careful
431 * to only access this value from main thread (when we know sweep
434 struct file_list *next;
441 struct url_spec url[1];
443 struct block_spec *next;
445 #endif /* def TRUST_FILES */
448 #define PERMIT_COOKIE_SET 0x0001U
449 #define PERMIT_COOKIE_READ 0x0002U
450 #define PERMIT_RE_FILTER 0x0004U
451 #define PERMIT_POPUPS 0x0008U
452 #define PERMIT_REFERER 0x0010U /* sic - follow HTTP, not English */
453 #define PERMIT_FAST_REDIRECTS 0x0020U
454 #define PERMIT_BLOCK 0x0040U
455 #define PERMIT_IMAGE 0x0080U
457 #define PERMIT_USER_AGENT PERMIT_COOKIE_SET /* FIXME Alias this for now */
459 #define PERMIT_MASK_ALL (~0U)
461 #define PERMIT_MOST_COMPATIBLE (PERMIT_COOKIE_SET | PERMIT_COOKIE_READ | \
462 PERMIT_REFERER | PERMIT_POPUPS | PERMIT_USER_AGENT)
464 struct permissions_spec
466 struct url_spec url[1];
467 unsigned mask; /* a bit set to "0" = remove permission */
468 unsigned add; /* a bit set to "1" = add permission */
469 struct permissions_spec * next;
475 struct url_spec url[1];
476 struct gateway gw[1];
477 struct forward_spec *next;
482 struct re_filterfile_spec
484 struct list patterns[1];
485 /* See README.re_filter */
488 #endif /* def PCRS */
492 #define ACL_PERMIT 1 /* accept connection request */
493 #define ACL_DENY 2 /* reject connection request */
495 struct access_control_addr
502 struct access_control_list
504 struct access_control_addr src[1];
505 struct access_control_addr dst[1];
508 struct access_control_list *next;
510 #endif /* def ACL_FILES */
513 /* Maximum number of loaders (permissions, block, forward, acl...) */
517 * Data loaded from the configuration file.
519 * (Anomaly: toggle is still handled through a global, not this structure)
521 struct configuration_spec
526 #ifdef IMAGE_BLOCKING
528 const char *tinygifurl;
529 #endif /* def IMAGE_BLOCKING */
533 const char *permissions_file;
534 const char *forwardfile;
538 #endif /* def ACL_FILES */
541 const char *re_filterfile;
542 #endif /* def PCRS */
545 * Permissions to use for URLs not in the permissions list.
547 int default_permissions;
550 const char * jarfile;
552 #endif /* def JAR_FILES */
554 const char *referrer;
560 struct list wafer_list[1];
561 struct list xtra_list[1];
564 * Port and IP to bind to.
565 * Defaults to HADDR_DEFAULT:HADDR_PORT == 127.0.0.1:8000
570 #ifndef SPLIT_PROXY_ARGS
571 const char *suppress_message;
572 #endif /* ndef SPLIT_PROXY_ARGS */
574 #ifndef SPLIT_PROXY_ARGS
575 /* suppress listing config files */
576 int suppress_blocklists;
577 #endif /* ndef SPLIT_PROXY_ARGS */
580 const char * trustfile;
582 struct list trust_info[1];
583 struct url_spec *trust_list[64];
584 #endif /* def TRUST_FILES */
586 /* Various strings for show-proxy-args */
587 char *proxy_args_header;
588 char *proxy_args_invocation;
589 char *proxy_args_gateways;
590 char *proxy_args_trailer;
592 /* the configuration file object. */
593 struct file_list *config_file_list;
595 /* List of loaders */
596 int (*loaders[NLOADERS])(struct client_state *);
598 /* bool, nonzero if we need to bind() to the new port */
603 #define SZ(X) (sizeof(X) / sizeof(*X))
605 #define WHITEBG "<body bgcolor=\"#ffffff\" link=\"#000078\" alink=\"#ff0022\" vlink=\"#787878\">\n"
606 #define BODY "<body bgcolor=\"#f8f8f0\" link=\"#000078\" alink=\"#ff0022\" vlink=\"#787878\">\n"
607 #define BANNER "<strong>Internet J<small>UNK<i><font color=\"red\">BUSTER</font></i></small></strong>"
610 #define FORCE_PREFIX "/IJB-FORCE-LOAD"
611 #endif /* def FORCE_LOAD */
613 #define HOME_PAGE_URL "http://ijbswa.sourceforge.net/"
614 #define REDIRECT_URL HOME_PAGE_URL "redirect.php?v=" VERSION "&to="
616 static const char CFAIL[] =
617 "HTTP/1.0 503 Connect failed\n"
618 "Content-Type: text/html\n\n"
621 "<title>Internet Junkbuster: Connect failed</title>\n"
627 "TCP connection to '%s' failed: %s.\n<br>"
631 static const char CNXDOM[] =
632 "HTTP/1.0 404 Non-existent domain\n"
633 "Content-Type: text/html\n\n"
636 "<title>Internet Junkbuster: Non-existent domain</title>\n"
642 "No such domain: %s\n"
646 static const char CNOBANNER[] =
647 "HTTP/1.0 200 No Banner\n"
648 "Content-Type: text/html\n\n"
651 "<title>Internet Junkbuster: No Banner</title>\n"
657 "You asked for a banner that this proxy can't produce because either configuration does not permit.\n<br>"
658 "or the URL didn't end with .gif\n"
662 static const char CSUCCEED[] =
663 "HTTP/1.0 200 Connection established\n"
664 "Proxy-Agent: IJ/" VERSION "\n\n";
666 static const char CHEADER[] =
667 "HTTP/1.0 400 Invalid header received from browser\n\n";
669 static const char SHEADER[] =
670 "HTTP/1.0 502 Invalid header received from server\n\n";
672 #ifdef IMAGE_BLOCKING
675 * Hint: You can encode your own GIFs like that:
676 * perl -e 'while (read STDIN, $c, 1) { printf("\\%.3o,", unpack("C", $c)); }'
679 static const char BLANKGIF[] =
680 "HTTP/1.0 200 OK\r\n"
681 "Pragma: no-cache\r\n"
682 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
683 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
684 "Content-type: image/gif\r\n\r\n"
685 "GIF89a\001\000\001\000\200\000\000\377\377\377\000\000"
686 "\000!\371\004\001\000\000\000\000,\000\000\000\000\001"
687 "\000\001\000\000\002\002D\001\000;";
689 static const char JBGIF[] =
690 "HTTP/1.0 200 OK\r\n"
691 "Pragma: no-cache\r\n"
692 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
693 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
694 "Content-type: image/gif\r\n\r\n"
695 "GIF89aD\000\013\000\360\000\000\000\000\000\377\377\377!"
696 "\371\004\001\000\000\001\000,\000\000\000\000D\000\013\000"
697 "\000\002a\214\217\251\313\355\277\000\200G&K\025\316hC\037"
698 "\200\234\230Y\2309\235S\230\266\206\372J\253<\3131\253\271"
699 "\270\215\342\254\013\203\371\202\264\334P\207\332\020o\266"
700 "N\215I\332=\211\312\3513\266:\026AK)\364\370\365aobr\305"
701 "\372\003S\275\274k2\354\254z\347?\335\274x\306^9\374\276"
704 #endif /* def IMAGE_BLOCKING */
706 #if defined(FAST_REDIRECTS) || defined(IMAGE_BLOCKING)
708 static const char HTTP_REDIRECT_TEMPLATE[] =
709 "HTTP/1.0 302 Local Redirect from Junkbuster\r\n"
710 "Pragma: no-cache\r\n"
711 "Last-Modified: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
712 "Expires: Thu Jul 31, 1997 07:42:22 pm GMT\r\n"
715 #endif /* defined(FAST_REDIRECTS) || defined(IMAGE_BLOCKING) */
721 #endif /* ndef _PROJECT_H */