+ * Revision 1.87 2002/03/26 22:29:54 swa
+ * we have a new homepage!
+ *
+ * Revision 1.86 2002/03/25 17:04:55 david__schmidt
+ * Workaround for closing the jarfile before load_config() comes around again
+ *
+ * Revision 1.85 2002/03/24 15:23:33 jongfoster
+ * Name changes
+ *
+ * Revision 1.84 2002/03/24 13:25:43 swa
+ * name change related issues
+ *
+ * Revision 1.83 2002/03/16 23:54:06 jongfoster
+ * Adding graceful termination feature, to help look for memory leaks.
+ * If you enable this (which, by design, has to be done by hand
+ * editing config.h) and then go to http://i.j.b/die, then the program
+ * will exit cleanly after the *next* request. It should free all the
+ * memory that was used.
+ *
+ * Revision 1.82 2002/03/13 00:27:05 jongfoster
+ * Killing warnings
+ *
+ * Revision 1.81 2002/03/12 01:42:50 oes
+ * Introduced modular filters
+ *
+ * Revision 1.80 2002/03/11 22:07:05 david__schmidt
+ * OS/2 port maintenance:
+ * - Fixed EMX build - it had decayed a little
+ * - Fixed inexplicable crash during FD_ZERO - must be due to a bad macro.
+ * substituted a memset for now.
+ *
+ * Revision 1.79 2002/03/09 20:03:52 jongfoster
+ * - Making various functions return int rather than size_t.
+ * (Undoing a recent change). Since size_t is unsigned on
+ * Windows, functions like read_socket that return -1 on
+ * error cannot return a size_t.
+ *
+ * THIS WAS A MAJOR BUG - it caused frequent, unpredictable
+ * crashes, and also frequently caused JB to jump to 100%
+ * CPU and stay there. (Because it thought it had just
+ * read ((unsigned)-1) == 4Gb of data...)
+ *
+ * - The signature of write_socket has changed, it now simply
+ * returns success=0/failure=nonzero.
+ *
+ * - Trying to get rid of a few warnings --with-debug on
+ * Windows, I've introduced a new type "jb_socket". This is
+ * used for the socket file descriptors. On Windows, this
+ * is SOCKET (a typedef for unsigned). Everywhere else, it's
+ * an int. The error value can't be -1 any more, so it's
+ * now JB_INVALID_SOCKET (which is -1 on UNIX, and in
+ * Windows it maps to the #define INVALID_SOCKET.)
+ *
+ * - The signature of bind_port has changed.
+ *
+ * Revision 1.78 2002/03/08 21:35:04 oes
+ * Added optional group supplement to --user option. Will now use default group of user if no group given
+ *
+ * Revision 1.77 2002/03/07 03:52:06 oes
+ * - Fixed compiler warnings etc
+ * - Improved handling of failed DNS lookups
+ *
+ * Revision 1.76 2002/03/06 22:54:35 jongfoster
+ * Automated function-comment nitpicking.
+ *
+ * Revision 1.75 2002/03/06 10:02:19 oes
+ * Fixed stupid bug when --user was not given
+ *
+ * Revision 1.74 2002/03/06 00:49:31 jongfoster
+ * Fixing warning on Windows
+ * Making #ifdefs that refer to the same variable consistently
+ * use #ifdef unix rather than mixing #ifdef unix & #ifndef OS2
+ *
+ * Revision 1.73 2002/03/05 23:57:30 hal9
+ * Stray character 's' on line 1618 was breaking build.
+ *
+ * Revision 1.72 2002/03/05 21:33:45 david__schmidt
+ * - Re-enable OS/2 building after new parms were added
+ * - Fix false out of memory report when resolving CGI templates when no IP
+ * address is available of failed attempt (a la no such domain)
+ *
+ * Revision 1.71 2002/03/05 18:13:56 oes
+ * Added --user option
+ *
+ * Revision 1.70 2002/03/05 04:52:42 oes
+ * Deleted non-errlog debugging code
+ *
+ * Revision 1.69 2002/03/04 23:50:00 jongfoster
+ * Splitting off bind_port() call into bind_port_helper(), with
+ * improved logging.
+ *
+ * Revision 1.68 2002/03/04 20:17:32 oes
+ * Fixed usage info
+ *
+ * Revision 1.67 2002/03/04 18:18:57 oes
+ * - Removed _DEBUG mode
+ * - Cleand up cmdline parsing
+ * - Introduced --no-daemon, --pidfile options
+ * - Cleaned up signal handling:
+ * - Terminate cleanly on INT, TERM and ABRT
+ * - Schedule logfile for re-opening on HUP
+ * - Ignore CHLD and PIPE
+ * - Leave the rest with their default handlers
+ * - Uniform handler registration
+ * - Added usage() function
+ * - Played styleguide police
+ *
+ * Revision 1.66 2002/03/03 15:06:55 oes
+ * Re-enabled automatic config reloading
+ *
+ * Revision 1.65 2002/03/03 14:49:11 oes
+ * Fixed CLF logging: Now uses client's original HTTP request
+ *
+ * Revision 1.64 2002/03/03 09:18:03 joergs
+ * Made jumbjuster work on AmigaOS again.
+ *
+ * Revision 1.63 2002/03/02 04:14:50 david__schmidt
+ * Clean up a little CRLF unpleasantness that suddenly appeared
+ *
+ * Revision 1.62 2002/02/20 23:17:23 jongfoster
+ * Detecting some out-of memory conditions and exiting with a log message.
+ *
+ * Revision 1.61 2002/01/17 21:01:52 jongfoster
+ * Moving all our URL and URL pattern parsing code to urlmatch.c.
+ *
+ * Revision 1.60 2001/12/30 14:07:32 steudten
+ * - Add signal handling (unix)
+ * - Add SIGHUP handler (unix)
+ * - Add creation of pidfile (unix)
+ * - Add action 'top' in rc file (RH)
+ * - Add entry 'SIGNALS' to manpage
+ * - Add exit message to logfile (unix)
+ *
+ * Revision 1.59 2001/12/13 14:07:18 oes
+ * Fixed Bug: 503 error page now sent OK
+ *
+ * Revision 1.58 2001/11/30 23:37:24 jongfoster
+ * Renaming the Win32 config file to config.txt - this is almost the
+ * same as the corresponding UNIX name "config"
+ *
+ * Revision 1.57 2001/11/16 00:47:43 jongfoster
+ * Changing the tty-disconnection code to use setsid().
+ *
+ * Revision 1.56 2001/11/13 20:20:54 jongfoster
+ * Tabs->spaces, fixing a bug with missing {} around an if()
+ *
+ * Revision 1.55 2001/11/13 20:14:53 jongfoster
+ * Patch for FreeBSD setpgrp() as suggested by Alexander Lazic
+ *
+ * Revision 1.54 2001/11/07 00:03:14 steudten
+ * Give reliable return value if an error
+ * occurs not just 0 with new daemon mode.
+ *
+ * Revision 1.53 2001/11/05 21:41:43 steudten
+ * Add changes to be a real daemon just for unix os.
+ * (change cwd to /, detach from controlling tty, set
+ * process group and session leader to the own process.
+ * Add DBG() Macro.
+ * Add some fatal-error log message for failed malloc().
+ * Add '-d' if compiled with 'configure --with-debug' to
+ * enable debug output.
+ *
+ * Revision 1.52 2001/10/26 20:11:20 jongfoster
+ * Fixing type mismatch
+ *
+ * Revision 1.51 2001/10/26 17:38:28 oes
+ * Cosmetics
+ *
+ * Revision 1.50 2001/10/25 03:40:48 david__schmidt
+ * Change in porting tactics: OS/2's EMX porting layer doesn't allow multiple
+ * threads to call select() simultaneously. So, it's time to do a real, live,
+ * native OS/2 port. See defines for __EMX__ (the porting layer) vs. __OS2__
+ * (native). Both versions will work, but using __OS2__ offers multi-threading.
+ *
+ * Revision 1.49 2001/10/23 21:41:35 jongfoster
+ * Added call to initialize the (statically-allocated of course)
+ * "out of memory" CGI response.
+ *
+ * Revision 1.48 2001/10/10 19:56:46 jongfoster
+ * Moving some code that wasn't cookie-related out of an #ifdef
+ * FEATURE_COOKIE_JAR
+ *
+ * Revision 1.47 2001/10/10 16:44:36 oes
+ * Added CONNECT destination port limitation check
+ *
+ * Revision 1.46 2001/10/08 15:17:41 oes
+ * Re-enabled SSL forwarding
+ *
+ * Revision 1.45 2001/10/07 15:42:11 oes
+ * Replaced 6 boolean members of csp with one bitmap (csp->flags)
+ *
+ * Moved downgrading of the HTTP version from parse_http_request to
+ * chat(), since we can't decide if it is necessary before we have
+ * determined the actions for the URL. The HTTP command is now
+ * *always* re-built so the repairs need no longer be special-cased.
+ *
+ * filter_popups now gets a csp pointer so it can raise the new
+ * CSP_FLAG_MODIFIED flag.
+ *
+ * Bugfix
+ *
+ * Added configurable size limit for the IOB. If the IOB grows so
+ * large that the next read would exceed the limit, the header
+ * is generated, and the header & unfiltered buffer are flushed
+ * to the client. Chat then continues in non-buffering,
+ * non-filtering body mode.
+ *
+ * Revision 1.44 2001/10/02 18:13:57 oes
+ * Ooops
+ *
+ * Revision 1.43 2001/10/02 15:32:13 oes
+ * Moved generation of hdr
+ *
+ * Revision 1.42 2001/09/21 23:02:02 david__schmidt
+ * Cleaning up 2 compiler warnings on OS/2.
+ *
+ * Revision 1.41 2001/09/16 17:05:14 jongfoster
+ * Removing unused #include showarg.h
+ *
+ * Revision 1.40 2001/09/16 15:41:45 jongfoster
+ * Fixing signed/unsigned comparison warning.
+ *
+ * Revision 1.39 2001/09/16 13:21:27 jongfoster
+ * Changes to use new list functions.
+ *
+ * Revision 1.38 2001/09/16 13:01:46 jongfoster
+ * Removing redundant function call that zeroed zalloc()'d memory.
+ *
+ * Revision 1.37 2001/09/10 11:12:24 oes
+ * Deleted unused variable
+ *
+ * Revision 1.36 2001/09/10 10:56:15 oes
+ * Silenced compiler warnings
+ *
+ * Revision 1.35 2001/07/31 14:44:22 oes
+ * Deleted unused size parameter from filter_popups()
+ *
+ * Revision 1.34 2001/07/30 22:08:36 jongfoster
+ * Tidying up #defines:
+ * - All feature #defines are now of the form FEATURE_xxx
+ * - Permanently turned off WIN_GUI_EDIT
+ * - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
+ *
+ * Revision 1.33 2001/07/29 19:32:00 jongfoster
+ * Renaming _main() [mingw32 only] to real_main(), for ANSI compliance.
+ *
+ * Revision 1.32 2001/07/29 18:47:05 jongfoster
+ * Adding missing #include "loadcfg.h"
+ *
+ * Revision 1.31 2001/07/29 12:17:48 oes
+ * Applied pthread fix by Paul Lieverse
+ *
+ * Revision 1.30 2001/07/25 22:57:13 jongfoster
+ * __BEOS__ no longer overrides FEATURE_PTHREAD.
+ * This is because FEATURE_PTHREAD will soon be widely used, so I
+ * want to keep it simple.
+ *
+ * Revision 1.29 2001/07/24 12:47:06 oes
+ * Applied BeOS support update by Eugenia
+ *
+ * Revision 1.28 2001/07/23 13:26:12 oes
+ * Fixed bug in popup-killing for the first read that caused binary garbage to be sent between headers and body
+ *
+ * Revision 1.27 2001/07/19 19:09:47 haroon
+ * - Added code to take care of the situation where while processing the first
+ * server response (which includes the server header), after finding the end
+ * of the headers we were not looking past the end of the headers for
+ * content modification. I enabled it for filter_popups.
+ * Someone else should look to see if other similar operations should be
+ * done to the discarded portion of the buffer.
+ *
+ * Note 2001/07/20: No, the other content modification mechanisms will process
+ * the whole iob later anyway. --oes
+ *
+ * Revision 1.26 2001/07/18 12:31:36 oes
+ * cosmetics
+ *
+ * Revision 1.25 2001/07/15 19:43:49 jongfoster
+ * Supports POSIX threads.
+ * Also removed some unused #includes.
+ *
+ * Revision 1.24 2001/07/13 14:00:40 oes
+ * - Generic content modification scheme:
+ * Each feature has its own applicability flag that is set
+ * from csp->action->flags.
+ * Replaced the "filtering" int flag , by a function pointer
+ * "content_filter" to the function that will do the content
+ * modification. If it is != NULL, the document will be buffered
+ * and processed through *content_filter, which must set
+ * csp->content_length and return a modified copy of the body
+ * or return NULL (on failiure).
+ * - Changed csp->is_text to the more generic bitmap csp->content_type
+ * which can currently take the valued CT_TEXT or CT_GIF
+ * - Reformatting etc
+ * - Removed all #ifdef PCRS
+ *
+ * Revision 1.23 2001/07/02 02:28:25 iwanttokeepanon
+ * Added "#ifdef ACL_FILES" conditional compilation to line 1291 to exclude
+ * the `block_acl' call. This prevents a compilation error when the user
+ * does not wish to use the "ACL" feature.
+ *
+ * Revision 1.22 2001/06/29 21:45:41 oes
+ * Indentation, CRLF->LF, Tab-> Space
+ *
+ * Revision 1.21 2001/06/29 13:29:36 oes
+ * - Cleaned up, improved comments
+ * - Unified all possible interceptors (CGI,
+ * block, trust, fast_redirect) in one
+ * place, with one (CGI) answer generation
+ * mechansim. Much clearer now.
+ * - Removed the GIF image generation, which
+ * is now done in filters.c:block_url()
+ * - Made error conditions like domain lookup
+ * failiure or (various) problems while talking
+ * to the server use cgi.c:error_response()
+ * instead of generating HTML/HTTP in chat() (yuck!)
+ * - Removed logentry from cancelled commit
+ *
+ * Revision 1.20 2001/06/09 10:55:28 jongfoster
+ * Changing BUFSIZ ==> BUFFER_SIZE
+ *
+ * Revision 1.19 2001/06/07 23:12:52 jongfoster
+ * Replacing function pointer in struct gateway with a directly
+ * called function forwarded_connect().
+ * Replacing struct gateway with struct forward_spec
+ *
+ * Revision 1.18 2001/06/03 19:12:16 oes
+ * introduced new cgi handling
+ *
+ * Revision 1.17 2001/06/01 20:07:23 jongfoster
+ * Now uses action +image-blocker{} rather than config->tinygif
+ *
+ * Revision 1.16 2001/06/01 18:49:17 jongfoster
+ * Replaced "list_share" with "list" - the tiny memory gain was not
+ * worth the extra complexity.
+ *
+ * Revision 1.15 2001/05/31 21:24:47 jongfoster
+ * Changed "permission" to "action" throughout.
+ * Removed DEFAULT_USER_AGENT - it must now be specified manually.
+ * Moved vanilla wafer check into chat(), since we must now
+ * decide whether or not to add it based on the URL.
+ *
+ * Revision 1.14 2001/05/29 20:14:01 joergs
+ * AmigaOS bugfix: PCRS needs a lot of stack, stacksize for child threads
+ * increased.
+ *
+ * Revision 1.13 2001/05/29 09:50:24 jongfoster
+ * Unified blocklist/imagelist/permissionslist.
+ * File format is still under discussion, but the internal changes
+ * are (mostly) done.
+ *
+ * Also modified interceptor behaviour:
+ * - We now intercept all URLs beginning with one of the following
+ * prefixes (and *only* these prefixes):
+ * * http://i.j.b/
+ * * http://ijbswa.sf.net/config/
+ * * http://ijbswa.sourceforge.net/config/
+ * - New interceptors "home page" - go to http://i.j.b/ to see it.
+ * - Internal changes so that intercepted and fast redirect pages
+ * are not replaced with an image.
+ * - Interceptors now have the option to send a binary page direct
+ * to the client. (i.e. ijb-send-banner uses this)
+ * - Implemented show-url-info interceptor. (Which is why I needed
+ * the above interceptors changes - a typical URL is
+ * "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
+ * The previous mechanism would not have intercepted that, and
+ * if it had been intercepted then it then it would have replaced
+ * it with an image.)
+ *
+ * Revision 1.12 2001/05/27 22:17:04 oes
+ *
+ * - re_process_buffer no longer writes the modified buffer
+ * to the client, which was very ugly. It now returns the
+ * buffer, which it is then written by chat.
+ *
+ * - content_length now adjusts the Content-Length: header
+ * for modified documents rather than crunch()ing it.
+ * (Length info in csp->content_length, which is 0 for
+ * unmodified documents)
+ *
+ * - For this to work, sed() is called twice when filtering.
+ *
+ * Revision 1.11 2001/05/26 17:27:53 jongfoster
+ * Added support for CLF and fixed LOG_LEVEL_LOG.
+ * Also did CRLF->LF fix of my previous patch.
+ *
+ * Revision 1.10 2001/05/26 15:26:15 jongfoster
+ * ACL feature now provides more security by immediately dropping
+ * connections from untrusted hosts.
+ *
+ * Revision 1.9 2001/05/26 00:28:36 jongfoster
+ * Automatic reloading of config file.
+ * Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
+ * Most of the global variables have been moved to a new
+ * struct configuration_spec, accessed through csp->config->globalname
+ * Most of the globals remaining are used by the Win32 GUI.
+ *
+ * Revision 1.8 2001/05/25 22:43:18 jongfoster
+ * Fixing minor memory leak and buffer overflow.
+ *
+ * Revision 1.7 2001/05/25 22:34:30 jongfoster
+ * Hard tabs->Spaces
+ *
+ * Revision 1.6 2001/05/23 00:13:58 joergs
+ * AmigaOS support fixed.
+ *
+ * Revision 1.5 2001/05/22 18:46:04 oes
+ *
+ * - Enabled filtering banners by size rather than URL
+ * by adding patterns that replace all standard banner
+ * sizes with the "Junkbuster" gif to the re_filterfile
+ *
+ * - Enabled filtering WebBugs by providing a pattern
+ * which kills all 1x1 images
+ *
+ * - Added support for PCRE_UNGREEDY behaviour to pcrs,
+ * which is selected by the (nonstandard and therefore
+ * capital) letter 'U' in the option string.
+ * It causes the quantifiers to be ungreedy by default.
+ * Appending a ? turns back to greedy (!).
+ *
+ * - Added a new interceptor ijb-send-banner, which
+ * sends back the "Junkbuster" gif. Without imagelist or
+ * MSIE detection support, or if tinygif = 1, or the
+ * URL isn't recognized as an imageurl, a lame HTML
+ * explanation is sent instead.
+ *
+ * - Added new feature, which permits blocking remote
+ * script redirects and firing back a local redirect
+ * to the browser.
+ * The feature is conditionally compiled, i.e. it
+ * can be disabled with --disable-fast-redirects,
+ * plus it must be activated by a "fast-redirects"
+ * line in the config file, has its own log level
+ * and of course wants to be displayed by show-proxy-args
+ * Note: Boy, all the #ifdefs in 1001 locations and
+ * all the fumbling with configure.in and acconfig.h
+ * were *way* more work than the feature itself :-(
+ *
+ * - Because a generic redirect template was needed for
+ * this, tinygif = 3 now uses the same.
+ *
+ * - Moved GIFs, and other static HTTP response templates
+ * to project.h
+ *
+ * - Some minor fixes
+ *
+ * - Removed some >400 CRs again (Jon, you really worked
+ * a lot! ;-)
+ *
+ * Revision 1.4 2001/05/21 19:34:01 jongfoster
+ * Made failure to bind() a fatal error.
+ *
+ * Revision 1.3 2001/05/20 01:21:20 jongfoster
+ * Version 2.9.4 checkin.
+ * - Merged popupfile and cookiefile, and added control over PCRS
+ * filtering, in new "permissionsfile".
+ * - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
+ * file error you now get a message box (in the Win32 GUI) rather
+ * than the program exiting with no explanation.
+ * - Made killpopup use the PCRS MIME-type checking and HTTP-header
+ * skipping.
+ * - Removed tabs from "config"
+ * - Moved duplicated url parsing code in "loaders.c" to a new funcition.
+ * - Bumped up version number.
+ *