X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=loadcfg.c;h=d92dfa1983ca7efa9e40cb3cc4bbf824779c7f3f;hp=f29d665482c565b5cc25a3369aa6df7cb6a29acb;hb=5e64295a7ed3662f734abfb34d50a0f1a9dc5377;hpb=c75584ebcc79f939fb4ec9c8f842cef6692640c7 diff --git a/loadcfg.c b/loadcfg.c index f29d6654..d92dfa19 100644 --- a/loadcfg.c +++ b/loadcfg.c @@ -1,7 +1,7 @@ -const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.1 2001/05/13 21:57:06 administrator Exp $"; +const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.12 2001/06/05 20:04:09 jongfoster Exp $"; /********************************************************************* * - * File : $Source: /home/administrator/cvs/ijb/loadcfg.c,v $ + * File : $Source: /cvsroot/ijbswa/current/loadcfg.c,v $ * * Purpose : Loads settings from the configuration file into * global variables. This file contains both the @@ -35,6 +35,176 @@ const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.1 2001/05/13 21:57:06 administrat * * Revisions : * $Log: loadcfg.c,v $ + * Revision 1.12 2001/06/05 20:04:09 jongfoster + * Now uses _snprintf() in place of snprintf() under Win32. + * + * Revision 1.11 2001/06/04 18:31:58 swa + * files are now prefixed with either `confdir' or `logdir'. + * `make redhat-dist' replaces both entries confdir and logdir + * with redhat values + * + * Revision 1.10 2001/06/03 19:11:54 oes + * introduced confdir option + * + * Revision 1.10 2001/06/03 11:03:48 oes + * Makefile/in + * + * introduced cgi.c + * + * actions.c: + * + * adapted to new enlist_unique arg format + * + * conf loadcfg.c + * + * introduced confdir option + * + * filters.c filtrers.h + * + * extracted-CGI relevant stuff + * + * jbsockets.c + * + * filled comment + * + * jcc.c + * + * support for new cgi mechansim + * + * list.c list.h + * + * functions for new list type: "map" + * extended enlist_unique + * + * miscutil.c .h + * introduced bindup() + * + * parsers.c parsers.h + * + * deleted const struct interceptors + * + * pcrs.c + * added FIXME + * + * project.h + * + * added struct map + * added struct http_response + * changes struct interceptors to struct cgi_dispatcher + * moved HTML stuff to cgi.h + * + * re_filterfile: + * + * changed + * + * showargs.c + * NO TIME LEFT + * + * Revision 1.9 2001/06/01 20:06:24 jongfoster + * Removed support for "tinygif" option - moved to actions file. + * + * Revision 1.8 2001/05/31 21:27:13 jongfoster + * Removed many options from the config file and into the + * "actions" file: add_forwarded, suppress_vanilla_wafer, + * wafer, add_header, user_agent, referer, from + * Also globally replaced "permission" with "action". + * + * Revision 1.7 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.6 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.5 2001/05/25 22:34:30 jongfoster + * Hard tabs->Spaces + * + * Revision 1.4 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.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. + * + * Revision 1.2 2001/05/17 23:01:01 oes + * - Cleaned CRLF's from the sources and related files + * + * Revision 1.1.1.1 2001/05/15 13:58:58 oes + * Initial import of version 2.9.3 source tree + * * *********************************************************************/ @@ -65,6 +235,9 @@ const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.1 2001/05/13 21:57:06 administrat # include "w32log.h" # endif /* ndef _WIN_CONSOLE */ +/* VC++ has "_snprintf", not "snprintf" */ +#define snprintf _snprintf + #else /* ifndef _WIN32 */ # include @@ -76,6 +249,7 @@ const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.1 2001/05/13 21:57:06 administrat #endif #include "loadcfg.h" +#include "list.h" #include "jcc.h" #include "filters.h" #include "loaders.h" @@ -100,765 +274,588 @@ const char loadcfg_h_rcs[] = LOADCFG_H_VERSION; #define ijb_isupper(__X) isupper((int)(unsigned char)(__X)) #define ijb_tolower(__X) tolower((int)(unsigned char)(__X)) -static const char VANILLA_WAFER[] = - "NOTICE=TO_WHOM_IT_MAY_CONCERN_" - "Do_not_send_me_any_copyrighted_information_other_than_the_" - "document_that_I_am_requesting_or_any_of_its_necessary_components._" - "In_particular_do_not_send_me_any_cookies_that_" - "are_subject_to_a_claim_of_copyright_by_anybody._" - "Take_notice_that_I_refuse_to_be_bound_by_any_license_condition_" - "(copyright_or_otherwise)_applying_to_any_cookie._"; - #ifdef TOGGLE /* by haroon - indicates if ijb is enabled */ int g_bToggleIJB = 1; /* JunkBusters is enabled by default. */ #endif -int debug = 0; -int multi_threaded = 1; - -#if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) -int tinygif = 0; -const char *tinygifurl = NULL; -#endif /* defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) */ - -const char *logfile = NULL; - +/* The filename of the configfile */ const char *configfile = NULL; -const char *blockfile = NULL; -const char *cookiefile = NULL; -const char *forwardfile = NULL; - -#ifdef ACL_FILES -const char *aclfile = NULL; -#endif /* def ACL_FILES */ - -#ifdef USE_IMAGE_LIST -const char *imagefile = NULL; -#endif /* def USE_IMAGE_LIST */ - -#ifdef KILLPOPUPS -const char *popupfile = NULL; -int kill_all_popups = 0; /* Not recommended really ... */ -#endif /* def KILLPOPUPS */ - -#ifdef PCRS -const char *re_filterfile = NULL; -int re_filter_all = 0; -#endif /* def PCRS */ - -#ifdef TRUST_FILES -const char *trustfile = NULL; -#endif /* def TRUST_FILES */ - -#ifdef JAR_FILES -const char *jarfile = NULL; -FILE *jar = NULL; -#endif /* def JAR_FILES */ - -const char *referrer = NULL; -const char *uagent = NULL; -const char *from = NULL; - -#ifndef SPLIT_PROXY_ARGS -const char *suppress_message = NULL; -#endif /* ndef SPLIT_PROXY_ARGS */ - -int suppress_vanilla_wafer = 0; -int add_forwarded = 0; - -struct list wafer_list[1]; -struct list xtra_list[1]; - -#ifdef TRUST_FILES -struct list trust_info[1]; -struct url_spec *trust_list[64]; -#endif /* def TRUST_FILES */ - -/* - * Port and IP to bind to. - * Defaults to HADDR_DEFAULT:HADDR_PORT == 127.0.0.1:8000 - */ -const char *haddr = NULL; -int hport = 0; - -#ifndef SPLIT_PROXY_ARGS -int suppress_blocklists = 0; /* suppress listing sblock and simage */ -#endif /* ndef SPLIT_PROXY_ARGS */ - -struct proxy_args proxy_args[1]; - -int configret = 0; -int config_changed = 0; - - /* * The load_config function is now going to call `init_proxy_args', - * so it will need argc and argv. Since load_config will also be - * a signal handler, we need to have these globally available. + * so it will need argc and argv. So we need to have these + * globally available. */ int Argc = 0; const char **Argv = NULL; +static struct file_list *current_configfile = NULL; + /* * This takes the "cryptic" hash of each keyword and aliases them to * something a little more readable. This also makes changing the * hash values easier if they should change or the hash algorthm changes. * Use the included "hash" program to find out what the hash will be - * for any string supplied on the command line. + * for any string supplied on the command line. (Or just put it in the + * config file and read the number from the error message in the log). */ -#define hash_trustfile 56494766ul -#define hash_trust_info_url 449869467ul -#define hash_debug 78263ul -#define hash_tinygif 2227702ul -#define hash_add_forwarded_header 3191044770ul -#define hash_single_threaded 4250084780ul -#define hash_suppress_vanilla_wafer 3121233547ul -#define hash_wafer 89669ul -#define hash_add_header 237434619ul -#define hash_cookiefile 247469766ul -#define hash_logfile 2114766ul -#define hash_blockfile 48845391ul -#define hash_imagefile 51447891ul -#define hash_jarfile 2046641ul -#define hash_listen_address 1255650842ul + +#define hash_aclfile 1908516ul +#define hash_actions_file 3825730796ul /* FIXME "permissionsfile" */ +#define hash_debug 78263ul +#define hash_confdir 1978389lu +#define hash_logdir 422889lu #define hash_forwardfile 1268669141ul -#define hash_aclfile 1908516ul -#define hash_popupfile 54623516ul -#define hash_kill_all_popups 2311539906ul +#define hash_jarfile 2046641ul +#define hash_listen_address 1255650842ul +#define hash_logfile 2114766ul #define hash_re_filterfile 3877522444ul -#define hash_re_filter_all 3877521376ul -#define hash_user_agent 283326691ul -#define hash_referrer 10883969ul -#define hash_referer 2176719ul -#define hash_from 16264ul -#define hash_hide_console 2048809870ul -#define hash_include_stats 2174146548ul +#define hash_single_threaded 4250084780ul #define hash_suppress_blocklists 1948693308ul -#define hash_toggle 447966ul +#define hash_toggle 447966ul +#define hash_trust_info_url 449869467ul +#define hash_trustfile 56494766ul + +#define hash_hide_console 2048809870ul #define hash_activity_animation 1817904738ul -#define hash_log_messages 2291744899ul -#define hash_log_highlight_messages 4032101240ul +#define hash_close_button_minimizes 3651284693ul #define hash_log_buffer_size 2918070425ul -#define hash_log_max_lines 2868344173ul #define hash_log_font_name 2866730124ul #define hash_log_font_size 2866731014ul -#define hash_show_on_task_bar 215410365ul -#define hash_close_button_minimizes 3651284693ul +#define hash_log_highlight_messages 4032101240ul +#define hash_log_max_lines 2868344173ul +#define hash_log_messages 2291744899ul +#define hash_show_on_task_bar 215410365ul /********************************************************************* * - * Function : load_config + * Function : unload_configfile * - * Description : Load the config file and all parameters. + * Description : Free the config structure and all components. * * Parameters : - * 1 : signum : this can be the signal SIGHUP or 0 (if from main). - * In any case, we just ignore this and reload the config file. + * 1 : data: struct configuration_spec to unload * - * Returns : configret : 0 => Ok, everything else is an error. - * Note: we use configret since a signal handler cannot - * return a value, and this function does double duty. - * Ie. Is is called from main and from signal( SIGHUP ); + * Returns : N/A * *********************************************************************/ -void load_config( int signum ) +void unload_configfile (void * data) { - char buf[BUFSIZ]; - char *p, *q; - FILE *configfp = NULL; + struct configuration_spec * config = (struct configuration_spec *)data; - configret = 0; - config_changed = 1; - - log_error(LOG_LEVEL_INFO, "loading configuration file '%s':", configfile); +#ifdef JAR_FILES + if ( NULL != config->jar ) + { + fclose( config->jar ); + config->jar = NULL; + } +#endif /* def JAR_FILES */ - init_proxy_args(Argc, Argv); + freez((char *)config->confdir); + freez((char *)config->logdir); + freez((char *)config->haddr); + freez((char *)config->logfile); - /* (Waste of memory [not quite a "leak"] here. The - * last blockfile/popupfile/... etc will not be - * unloaded until we load a new one. If the - * block/popup/... feature has been disabled in - * the new config file, then we're wasting some - * memory we could otherwise reclaim. - */ + freez((char *)config->actions_file); + freez((char *)config->forwardfile); - /* Disable all loaders. */ - remove_all_loaders(); +#ifdef ACL_FILES + freez((char *)config->aclfile); +#endif /* def ACL_FILES */ - /* - * Reset to as close to startup state as we can. - * But leave changing the logfile until after we're done loading. - */ +#ifdef JAR_FILES + freez((char *)config->jarfile); +#endif /* def JAR_FILES */ - #ifdef JAR_FILES - if ( NULL != jar ) - { - fclose( jar ); - jar = NULL; - } - #endif /* def JAR_FILES */ +#ifndef SPLIT_PROXY_ARGS + freez((char *)config->suppress_message); +#endif /* ndef SPLIT_PROXY_ARGS */ - debug = 0; - multi_threaded = 1; +#ifdef PCRS + freez((char *)config->re_filterfile); +#endif /* def PCRS */ -#if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) - tinygif = 0; - freez((char *)tinygifurl); -#endif /* defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) */ +} - suppress_vanilla_wafer = 0; - add_forwarded = 0; - hport = HADDR_PORT; -#ifdef _WIN_CONSOLE - hideConsole = 0; -#endif /*def _WIN_CONSOLE*/ +/********************************************************************* + * + * Function : load_config + * + * Description : Load the config file and all parameters. + * + * Parameters : + * 1 : csp = Client state (the config member will be + * filled in by this function). + * + * Returns : 0 => Ok, everything else is an error. + * + *********************************************************************/ +struct configuration_spec * load_config(void) +{ + char buf[BUFSIZ]; + char *p, *q; + FILE *configfp = NULL; + struct configuration_spec * config = NULL; + struct client_state * fake_csp; + struct file_list *fs; -#ifdef PCRS - re_filter_all = 0; -#endif /* def PCRS */ + if (!check_file_changed(current_configfile, configfile, &fs)) + { + /* No need to load */ + return ((struct configuration_spec *)current_configfile->f); + } + if (!fs) + { + log_error(LOG_LEVEL_FATAL, "can't check configuration file '%s': %E", + configfile); + } -#ifdef KILLPOPUPS - kill_all_popups = 0; -#endif /* def KILLPOPUPS */ + log_error(LOG_LEVEL_INFO, "loading configuration file '%s':", configfile); #ifdef TOGGLE g_bToggleIJB = 1; #endif -#ifdef STATISTICS - urls_read = 0; - urls_rejected = 0; -#endif /* def STATISTICS */ + fs->f = config = (struct configuration_spec *)zalloc(sizeof(*config)); -#ifndef SPLIT_PROXY_ARGS - suppress_blocklists = 0; -#endif /* ndef SPLIT_PROXY_ARGS */ + if (config==NULL) + { + freez(fs->filename); + freez(fs); + log_error(LOG_LEVEL_FATAL, "can't allocate memory for configuration"); + /* Never get here - LOG_LEVEL_FATAL causes program exit */ + } - freez((char *)from); - freez((char *)haddr); - freez((char *)uagent); - freez((char *)referrer); - freez((char *)logfile); + /* + * This is backwards from how it's usually done. + * Following the usual pattern, "fs" would be stored in a member + * variable in "csp", and then we'd access "config" from "fs->f", + * using a cast. However, "config" is used so often that a + * cast each time would be very ugly, and the extra indirection + * would waste CPU cycles. Therefore we store "config" in + * "csp->config", and "fs" in "csp->config->config_file_list". + */ + config->config_file_list = fs; + init_proxy_args(Argc, Argv, config); - freez((char *)blockfile); - freez((char *)cookiefile); - freez((char *)forwardfile); + /* + * Set to defaults + */ -#ifdef ACL_FILES - freez((char *)aclfile); -#endif /* def ACL_FILES */ + config->multi_threaded = 1; + config->hport = HADDR_PORT; -#ifdef USE_IMAGE_LIST - freez((char *)imagefile); -#endif /* def USE_IMAGE_LIST */ + if ((configfp = fopen(configfile, "r")) == NULL) + { + log_error(LOG_LEVEL_FATAL, "can't open configuration file '%s': %E", + configfile); + /* Never get here - LOG_LEVEL_FATAL causes program exit */ + } -#ifdef JAR_FILES - freez((char *)jarfile); -#endif /* def JAR_FILES */ + while (read_config_line(buf, sizeof(buf), configfp, fs) != NULL) + { + char cmd[BUFSIZ]; + char arg[BUFSIZ]; + char tmp[BUFSIZ]; -#ifdef KILLPOPUPS - freez((char *)popupfile); -#endif /* def KILLPOPUPS */ + strcpy(tmp, buf); -#ifndef SPLIT_PROXY_ARGS - freez((char *)suppress_message); -#endif /* ndef SPLIT_PROXY_ARGS */ + /* Copy command (i.e. up to space or tab) into cmd */ + p = buf; + q = cmd; + while (*p && (*p != ' ') && (*p != '\t')) + { + *q++ = *p++; + } + *q = '\0'; -#ifdef TRUST_FILES - freez((char *)trustfile); -#endif /* def TRUST_FILES */ + /* Skip over the whitespace in buf */ + while (*p && ((*p == ' ') || (*p == '\t'))) + { + p++; + } -#ifdef PCRS - freez((char *)re_filterfile); -#endif /* def PCRS */ + /* Copy the argument into arg */ + strcpy(arg, p); - if (NULL != configfile) - { - if ((configfp = fopen(configfile, "r")) == NULL) + /* Should never happen, but check this anyway */ + if (*cmd == '\0') { - log_error(LOG_LEVEL_ERROR, "can't open configuration file '%s': %E", - configfile); - configret = 1; - return; + continue; } - } - if (NULL != configfp) - { - memset (buf, 'j', sizeof(buf)); - while (read_config_line(buf, sizeof(buf), configfp, NULL) != NULL) + /* Make sure the command field is lower case */ + for (p=cmd; *p; p++) { - char cmd[BUFSIZ]; - char arg[BUFSIZ]; - char tmp[BUFSIZ]; - - strcpy(tmp, buf); - - /* Copy command (i.e. up to space or tab) into cmd */ - p = buf; - q = cmd; - while (*p && (*p != ' ') && (*p != '\t')) + if (ijb_isupper(*p)) { - *q++ = *p++; + *p = ijb_tolower(*p); } - *q = '\0'; + } - /* Skip over the whitespace in buf */ - while (*p && ((*p == ' ') || (*p == '\t'))) - { - p++; - } + /* Save the argument for show-proxy-args */ + savearg(cmd, arg, config); - /* Copy the argument into arg */ - strcpy(arg, p); - /* Should never happen, but check this anyway */ - if (*cmd == '\0') - { + switch( hash_string( cmd ) ) + { +#ifdef TRUST_FILES + case hash_trustfile : + freez((char *)config->trustfile); + config->trustfile = make_path(config->confdir, arg); continue; - } - /* Make sure the command field is lower case */ - for (p=cmd; *p; p++) - { - if (ijb_isupper(*p)) - { - *p = ijb_tolower(*p); - } - } + case hash_trust_info_url : + enlist(config->trust_info, arg); + continue; +#endif /* def TRUST_FILES */ - /* Save the argument for show-proxy-args */ - savearg(cmd, arg); + case hash_debug : + config->debug |= atoi(arg); + continue; + case hash_confdir : + freez((char *)config->confdir); + config->confdir = strdup(arg); + continue; - switch( hash_string( cmd ) ) - { -#ifdef TRUST_FILES - case hash_trustfile : - freez((char *)trustfile); - trustfile = strdup(arg); - continue; - - case hash_trust_info_url : - enlist(trust_info, arg); - continue; -#endif /* def TRUST_FILES */ + case hash_logdir : + freez((char *)config->logdir); + config->logdir = strdup(arg); + continue; - case hash_debug : - debug |= atoi(arg); - continue; - -#if defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) - case hash_tinygif : - freez((char *)tinygifurl); - tinygif = atoi(arg); - if(3 == tinygif) - { - p = arg; - while((*p >= '0') && (*p <= '9')) - { - p++; - } - while((*p == ' ') || (*p == '\t')) - { - p++; - } - if (*p) - { - q = malloc(strlen(p) + 5); - if (q) - { - strcpy(q, p); - strcat(q, "\r\n\r\n"); - tinygifurl = q; - } - } - } - if ((tinygif != 1) && - (tinygif != 2) && - ((tinygif != 3) || (tinygifurl==NULL)) ) - { - log_error(LOG_LEVEL_ERROR, "tinygif setting invalid."); - } - continue; -#endif /* defined(DETECT_MSIE_IMAGES) || defined(USE_IMAGE_LIST) */ - - case hash_add_forwarded_header : - add_forwarded = 1; - continue; - - case hash_single_threaded : - multi_threaded = 0; - continue; - - case hash_suppress_vanilla_wafer : - suppress_vanilla_wafer = 1; - continue; - - case hash_wafer : - enlist(wafer_list, arg); - continue; - - case hash_add_header : - enlist(xtra_list, arg); - continue; - - case hash_cookiefile : - freez((char *)cookiefile); - cookiefile = strdup(arg); - continue; - - case hash_logfile : - freez((char *)logfile); - logfile = strdup(arg); - continue; - - case hash_blockfile : - freez((char *)blockfile); - blockfile = strdup(arg); - continue; - -#ifdef USE_IMAGE_LIST - case hash_imagefile : - freez((char *)imagefile); - imagefile = strdup(arg); - continue; -#endif /* def USE_IMAGE_LIST */ + case hash_single_threaded : + config->multi_threaded = 0; + continue; + + case hash_actions_file : + freez((char *)config->actions_file); + config->actions_file = make_path(config->confdir, arg); + continue; + + case hash_logfile : + freez((char *)config->logfile); + config->logfile = make_path(config->logdir, arg); + continue; #ifdef JAR_FILES - case hash_jarfile : - freez((char *)jarfile); - jarfile = strdup(arg); - continue; + case hash_jarfile : + freez((char *)config->jarfile); + config->jarfile = make_path(config->logdir, arg); + continue; #endif /* def JAR_FILES */ - case hash_listen_address : - freez((char *)haddr); - haddr = strdup(arg); - continue; + case hash_listen_address : + freez((char *)config->haddr); + config->haddr = strdup(arg); + continue; - case hash_forwardfile : - freez((char *)forwardfile); - forwardfile = strdup(arg); - continue; + case hash_forwardfile : + freez((char *)config->forwardfile); + config->forwardfile = make_path(config->confdir, arg); + continue; #ifdef ACL_FILES - case hash_aclfile : - freez((char *)aclfile); - aclfile = strdup(arg); - continue; + case hash_aclfile : + freez((char *)config->aclfile); + config->aclfile = make_path(config->confdir, arg); + continue; #endif /* def ACL_FILES */ -#ifdef KILLPOPUPS - case hash_popupfile : - freez((char *)popupfile); - popupfile = strdup(arg); - continue; - - case hash_kill_all_popups : - kill_all_popups = 1; - continue; -#endif /* def KILLPOPUPS */ - #ifdef PCRS - case hash_re_filterfile : - freez((char *)re_filterfile); - re_filterfile = strdup(arg); - continue; - - case hash_re_filter_all : - re_filter_all = 1; - log_error(LOG_LEVEL_REF, "re_filter policy is %s.", - re_filter_all ? "RADICAL" : "SEMI-SMART"); - continue; + case hash_re_filterfile : + freez((char *)config->re_filterfile); + config->re_filterfile = strdup(arg); + continue; #endif /* def PCRS */ - case hash_user_agent : - freez((char *)uagent); - uagent = strdup(arg); - continue; - - /* - * Offer choice of correct spelling according to dictionary, - * or the misspelling used in the HTTP spec. - */ - case hash_referrer : - case hash_referer : - freez((char *)referrer); - referrer = strdup(arg); - continue; - - case hash_from : - freez((char *)from); - from = strdup(arg); - continue; - #ifdef _WIN_CONSOLE - case hash_hide_console : - hideConsole = 1; - continue; + case hash_hide_console : + hideConsole = 1; + continue; #endif /*def _WIN_CONSOLE*/ #ifndef SPLIT_PROXY_ARGS - case hash_suppress_blocklists : - if (arg[0] != '\0') - { - suppress_message = strdup(arg); - } - else - { - /* There will be NO reference in proxy-args. */ - suppress_message = NULL; - } - - suppress_blocklists = 1; - continue; + case hash_suppress_blocklists : + if (arg[0] != '\0') + { + config->suppress_message = strdup(arg); + } + else + { + /* There will be NO reference in proxy-args. */ + config->suppress_message = NULL; + } + + config->suppress_blocklists = 1; + continue; #endif /* ndef SPLIT_PROXY_ARGS */ #ifdef TOGGLE - case hash_toggle : - g_bToggleIJB = atoi(arg); - continue; + case hash_toggle : + g_bToggleIJB = atoi(arg); + continue; #endif /* def TOGGLE */ #if defined(_WIN32) && ! defined(_WIN_CONSOLE) - case hash_activity_animation : - g_bShowActivityAnimation = atoi(arg); - continue; + case hash_activity_animation : + g_bShowActivityAnimation = atoi(arg); + continue; - case hash_log_messages : - g_bLogMessages = atoi(arg); - continue; + case hash_log_messages : + g_bLogMessages = atoi(arg); + continue; - case hash_log_highlight_messages : - g_bHighlightMessages = atoi(arg); - continue; + case hash_log_highlight_messages : + g_bHighlightMessages = atoi(arg); + continue; - case hash_log_buffer_size : - g_bLimitBufferSize = atoi(arg); - continue; + case hash_log_buffer_size : + g_bLimitBufferSize = atoi(arg); + continue; - case hash_log_max_lines : - g_nMaxBufferLines = atoi(arg); - continue; + case hash_log_max_lines : + g_nMaxBufferLines = atoi(arg); + continue; - case hash_log_font_name : - strcpy( g_szFontFaceName, arg ); - continue; + case hash_log_font_name : + strcpy( g_szFontFaceName, arg ); + continue; - case hash_log_font_size : - g_nFontSize = atoi(arg); - continue; + case hash_log_font_size : + g_nFontSize = atoi(arg); + continue; - case hash_show_on_task_bar : - g_bShowOnTaskBar = atoi(arg); - continue; + case hash_show_on_task_bar : + g_bShowOnTaskBar = atoi(arg); + continue; - case hash_close_button_minimizes : - g_bCloseHidesWindow = atoi(arg); - continue; + case hash_close_button_minimizes : + g_bCloseHidesWindow = atoi(arg); + continue; #endif /* defined(_WIN32) && ! defined(_WIN_CONSOLE) */ - /* Warnings about unsupported features */ + /* Warnings about unsupported features */ -#ifndef TRUST_FILES - case hash_trustfile : - case hash_trust_info_url : -#endif /* ndef TRUST_FILES */ -#ifndef USE_IMAGE_LIST - case hash_imagefile : -#endif /* ndef USE_IMAGE_LIST */ #ifndef PCRS - case hash_re_filterfile : - case hash_re_filter_all : + case hash_re_filterfile : #endif /* ndef PCRS */ #ifndef TOGGLE - case hash_toggle : + case hash_toggle : #endif /* ndef TOGGLE */ #if defined(_WIN_CONSOLE) || ! defined(_WIN32) - case hash_activity_animation : - case hash_log_messages : - case hash_log_highlight_messages : - case hash_log_buffer_size : - case hash_log_max_lines : - case hash_log_font_name : - case hash_log_font_size : - case hash_show_on_task_bar : - case hash_close_button_minimizes : + case hash_activity_animation : + case hash_log_messages : + case hash_log_highlight_messages : + case hash_log_buffer_size : + case hash_log_max_lines : + case hash_log_font_name : + case hash_log_font_size : + case hash_show_on_task_bar : + case hash_close_button_minimizes : #endif /* defined(_WIN_CONSOLE) || ! defined(_WIN32) */ #ifndef _WIN_CONSOLE - case hash_hide_console : + case hash_hide_console : #endif /* ndef _WIN_CONSOLE */ -#if !defined(DETECT_MSIE_IMAGES) && !defined(USE_IMAGE_LIST) - case hash_tinygif : -#endif /* !defined(DETECT_MSIE_IMAGES) && !defined(USE_IMAGE_LIST) */ -#ifndef KILLPOPUPS - case hash_popupfile : - case hash_kill_all_popups : -#endif /* ndef KILLPOPUPS */ #ifndef JAR_FILES - case hash_jarfile : + case hash_jarfile : #endif /* ndef JAR_FILES */ #ifndef ACL_FILES - case hash_aclfile : + case hash_aclfile : #endif /* ndef ACL_FILES */ - #ifdef SPLIT_PROXY_ARGS - case hash_suppress_blocklists : + case hash_suppress_blocklists : #endif /* def SPLIT_PROXY_ARGS */ - log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); - continue; - - default : - log_error(LOG_LEVEL_ERROR, "Unrecognized directive (%lulu) in " - "configuration file: \"%s\"", hash_string( cmd ), buf); - p = malloc( BUFSIZ ); - if (p != NULL) - { - sprintf( p, "
\nWARNING: unrecognized directive : %s

\n", buf ); - proxy_args->invocation = strsav( proxy_args->invocation, p ); - freez( p ); - } - /* - * I decided that I liked this better as a warning than an - * error. - */ - - /* - * configret = 1; - * return; - */ - continue; - } - } - fclose(configfp); - } - - init_error_log(Argv[0], logfile, debug); + log_error(LOG_LEVEL_INFO, "Unsupported directive \"%s\" ignored.", cmd); + continue; - if (cookiefile) - { - add_loader(load_cookiefile); - } + default : + /* + * I decided that I liked this better as a warning than an + * error. To change back to an error, just change log level + * to LOG_LEVEL_FATAL. + */ + log_error(LOG_LEVEL_ERROR, "Unrecognized directive (%lulu) in " + "configuration file: \"%s\"", hash_string( cmd ), buf); + p = malloc( BUFSIZ ); + if (p != NULL) + { + sprintf( p, "
\nWARNING: unrecognized directive : %s

\n", buf ); + config->proxy_args_invocation = strsav( config->proxy_args_invocation, p ); + freez( p ); + } + continue; + } /* end switch( hash_string(cmd) ) */ + } /* end while ( read_config_line(...) ) */ - if (blockfile) - { - add_loader(load_blockfile); - } + fclose(configfp); -#ifdef USE_IMAGE_LIST - if (imagefile) - { - add_loader(load_imagefile); - } -#endif /* def USE_IMAGE_LIST */ + init_error_log(Argv[0], config->logfile, config->debug); -#ifdef TRUST_FILES - if (trustfile) + if (config->actions_file) { - add_loader(load_trustfile); + add_loader(load_actions_file, config); } -#endif /* def TRUST_FILES */ - if (forwardfile) + if (config->forwardfile) { - add_loader(load_forwardfile); + add_loader(load_forwardfile, config); } #ifdef ACL_FILES - if (aclfile) + if (config->aclfile) { - add_loader(load_aclfile); + add_loader(load_aclfile, config); } #endif /* def ACL_FILES */ -#ifdef KILLPOPUPS - if (popupfile) +#ifdef PCRS + if (config->re_filterfile) { - add_loader(load_popupfile); + add_loader(load_re_filterfile, config); } -#endif /* def KILLPOPUPS */ +#endif /* def PCRS */ -#ifdef PCRS - if (re_filterfile) +#ifdef TRUST_FILES + if (config->trustfile) { - add_loader(load_re_filterfile); + add_loader(load_trustfile, config); } -#endif /* def PCRS */ +#endif #ifdef JAR_FILES - if ( NULL != jarfile ) + if ( NULL != config->jarfile ) { - if ( NULL == (jar = fopen(jarfile, "a")) ) + if ( NULL == (config->jar = fopen(config->jarfile, "a")) ) { - log_error(LOG_LEVEL_ERROR, "can't open jarfile '%s': %E", jarfile); - configret = 1; - return; + log_error(LOG_LEVEL_FATAL, "can't open jarfile '%s': %E", config->jarfile); + /* Never get here - LOG_LEVEL_FATAL causes program exit */ } - setbuf(jar, NULL); + setbuf(config->jar, NULL); } #endif /* def JAR_FILES */ - if ( NULL == haddr ) + if ( NULL == config->haddr ) { - haddr = strdup( HADDR_DEFAULT ); + config->haddr = strdup( HADDR_DEFAULT ); } - if ( NULL != haddr ) + if ( NULL != config->haddr ) { - if ((p = strchr(haddr, ':'))) + if ((p = strchr(config->haddr, ':'))) { *p++ = '\0'; if (*p) { - hport = atoi(p); + config->hport = atoi(p); } } - if (hport <= 0) + if (config->hport <= 0) { *--p = ':'; - log_error(LOG_LEVEL_ERROR, "invalid bind port spec %s", haddr); - configret = 1; - return; + log_error(LOG_LEVEL_FATAL, "invalid bind port spec %s", config->haddr); + /* Never get here - LOG_LEVEL_FATAL causes program exit */ } - if (*haddr == '\0') + if (*config->haddr == '\0') { - haddr = NULL; + config->haddr = NULL; } } - if (run_loader(NULL)) + /* + * Want to run all the loaders once now. + * + * Need to set up a fake csp, so they can get to the config. + */ + fake_csp = (struct client_state *) zalloc (sizeof(*fake_csp)); + fake_csp->config = config; + + if (run_loader(fake_csp)) { - configret = 1; - return; + freez(fake_csp); + log_error(LOG_LEVEL_FATAL, "A loader failed while loading config file. Exiting."); + /* Never get here - LOG_LEVEL_FATAL causes program exit */ } + freez(fake_csp); -#ifdef JAR_FILES - /* - * If we're logging cookies in a cookie jar, and the user has not - * supplied any wafers, and the user has not told us to suppress the - * vanilla wafer, then send the vanilla wafer. - */ - if ((jarfile != NULL) - && (wafer_list->next == NULL) - && (suppress_vanilla_wafer == 0)) +#ifndef SPLIT_PROXY_ARGS + if (!suppress_blocklists) { - enlist(wafer_list, VANILLA_WAFER); + fs->proxy_args = strsav(fs->proxy_args, ""); } -#endif /* def JAR_FILES */ +#endif /* ndef SPLIT_PROXY_ARGS */ + +/* FIXME: this is a kludge for win32 */ +#if defined(_WIN32) && !defined (_WIN_CONSOLE) + + g_actions_file = config->actions_file; + g_forwardfile = config->forwardfile; +#ifdef ACL_FILES + g_aclfile = config->aclfile; +#endif /* def ACL_FILES */ +#ifdef PCRS + g_re_filterfile = config->re_filterfile; +#endif +#ifdef TRUST_FILES + g_trustfile = config->trustfile; +#endif + + +#endif /* defined(_WIN32) && !defined (_WIN_CONSOLE) */ +/* FIXME: end kludge */ + + + config->need_bind = 1; + + if (current_configfile) + { + struct configuration_spec * oldcfg = (struct configuration_spec *) + current_configfile->f; + /* + * Check if config->haddr,hport == oldcfg->haddr,hport + * + * The following could be written more compactly as a single, + * (unreadably long) if statement. + */ + config->need_bind = 0; + if (config->hport != oldcfg->hport) + { + config->need_bind = 1; + } + else if (config->haddr == NULL) + { + if (oldcfg->haddr != NULL) + { + config->need_bind = 1; + } + } + else if (oldcfg->haddr == NULL) + { + config->need_bind = 1; + } + else if (0 != strcmp(config->haddr, oldcfg->haddr)) + { + config->need_bind = 1; + } + + current_configfile->unloader = unload_configfile; + } + + fs->next = files->next; + files->next = fs; - end_proxy_args(); + current_configfile = fs; + return (config); }