X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=loadcfg.c;h=338e8ceda6265e8e12a29c356a5b0c50c77f184c;hp=94cf087f6c712950cab7090e755a5d29494b261f;hb=df84e4eef1fa09173aabc261157c6baec44c8b2d;hpb=ddc15f410cf7e878f7a40635daa645b08e17e92c diff --git a/loadcfg.c b/loadcfg.c index 94cf087f..338e8ced 100644 --- a/loadcfg.c +++ b/loadcfg.c @@ -1,4 +1,4 @@ -const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.102 2009/05/16 13:27:20 fabiankeil Exp $"; +const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.112 2011/03/03 14:38:36 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/loadcfg.c,v $ @@ -111,7 +111,7 @@ const char *configfile = NULL; * so we will make argc and argv global. */ int Argc = 0; -const char **Argv = NULL; +char * const * Argv = NULL; static struct file_list *current_configfile = NULL; @@ -133,9 +133,11 @@ static struct file_list *current_configfile = NULL; #define hash_admin_address 4112573064ul /* "admin-address" */ #define hash_allow_cgi_request_crunching 258915987ul /* "allow-cgi-request-crunching" */ #define hash_buffer_limit 1881726070ul /* "buffer-limit */ +#define hash_compression_level 2464423563ul /* "compression-level" */ #define hash_confdir 1978389ul /* "confdir" */ #define hash_connection_sharing 1348841265ul /* "connection-sharing" */ #define hash_debug 78263ul /* "debug" */ +#define hash_default_server_timeout 2530089913ul /* "default-server-timeout" */ #define hash_deny_access 1227333715ul /* "deny-access" */ #define hash_enable_edit_actions 2517097536ul /* "enable-edit-actions" */ #define hash_enable_remote_toggle 2979744683ul /* "enable-remote-toggle" */ @@ -147,6 +149,7 @@ static struct file_list *current_configfile = NULL; #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */ #define hash_forward_socks5 3963965522ul /* "forward-socks5" */ #define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */ +#define hash_handle_as_empty_returns_ok 1444873247ul /* "handle-as-empty-doc-returns-ok" */ #define hash_hostname 10308071ul /* "hostname" */ #define hash_keep_alive_timeout 3878599515ul /* "keep-alive-timeout" */ #define hash_listen_address 1255650842ul /* "listen-address" */ @@ -246,11 +249,6 @@ static void unload_configfile (void * data) list_remove_all(config->trust_info); #endif /* def FEATURE_TRUST */ - for (i = 0; i < MAX_AF_FILES; i++) - { - freez(config->re_filterfile[i]); - } - freez(config); } @@ -295,7 +293,7 @@ void unload_current_config_file(void) *********************************************************************/ struct configuration_spec * load_config(void) { - char buf[BUFFER_SIZE]; + char *buf = NULL; char *p, *q; FILE *configfp = NULL; struct configuration_spec * config = NULL; @@ -358,6 +356,7 @@ struct configuration_spec * load_config(void) config->max_client_connections = 0; config->socket_timeout = 300; /* XXX: Should be a macro. */ #ifdef FEATURE_CONNECTION_KEEP_ALIVE + config->default_server_timeout = 0; config->keep_alive_timeout = DEFAULT_KEEP_ALIVE_TIMEOUT; config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE; config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING; @@ -365,6 +364,13 @@ struct configuration_spec * load_config(void) config->feature_flags &= ~RUNTIME_FEATURE_CGI_TOGGLE; config->feature_flags &= ~RUNTIME_FEATURE_SPLIT_LARGE_FORMS; config->feature_flags &= ~RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS; + config->feature_flags &= ~RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK; +#ifdef FEATURE_COMPRESSION + /* + * XXX: Run some benchmarks to see if there are better default values. + */ + config->compression_level = 1; +#endif configfp = fopen(configfile, "r"); if (NULL == configfp) @@ -374,7 +380,7 @@ struct configuration_spec * load_config(void) /* Never get here - LOG_LEVEL_FATAL causes program exit */ } - while (read_config_line(buf, sizeof(buf), configfp, &linenum) != NULL) + while (read_config_line(configfp, &linenum, &buf) != NULL) { char cmd[BUFFER_SIZE]; char arg[BUFFER_SIZE]; @@ -405,11 +411,15 @@ struct configuration_spec * load_config(void) } /* Copy the argument into arg */ - strlcpy(arg, p, sizeof(arg)); + if (strlcpy(arg, p, sizeof(arg)) >= sizeof(arg)) + { + log_error(LOG_LEVEL_FATAL, "Config line too long: %s", buf); + } /* Should never happen, but check this anyway */ if (*cmd == '\0') { + freez(buf); continue; } @@ -497,10 +507,36 @@ struct configuration_spec * load_config(void) config->confdir = make_path( NULL, arg); break; +/* ************************************************************************* + * compression-level 0-9 + * *************************************************************************/ +#ifdef FEATURE_COMPRESSION + case hash_compression_level : + if (*arg != '\0') + { + int compression_level = atoi(arg); + if (-1 <= compression_level && compression_level <= 9) + { + config->compression_level = compression_level;; + } + else + { + log_error(LOG_LEVEL_FATAL, + "Invalid compression-level value: %s", arg); + } + } + else + { + log_error(LOG_LEVEL_FATAL, + "Invalid compression-level directive. Compression value missing"); + } + break; +#endif + /* ************************************************************************* * connection-sharing (0|1) * *************************************************************************/ -#ifdef FEATURE_CONNECTION_KEEP_ALIVE +#ifdef FEATURE_CONNECTION_SHARING case hash_connection_sharing : if ((*arg != '\0') && (0 != atoi(arg))) { @@ -521,6 +557,27 @@ struct configuration_spec * load_config(void) config->debug |= atoi(arg); break; +/* ************************************************************************* + * default-server-timeout timeout + * *************************************************************************/ +#ifdef FEATURE_CONNECTION_KEEP_ALIVE + case hash_default_server_timeout : + if (*arg != '\0') + { + int timeout = atoi(arg); + if (0 < timeout) + { + config->default_server_timeout = (unsigned int)timeout; + } + else + { + log_error(LOG_LEVEL_FATAL, + "Invalid default-server-timeout value: %s", arg); + } + } + break; +#endif + /* ************************************************************************* * deny-access source-ip[/significant-bits] [dest-ip[/significant-bits]] * *************************************************************************/ @@ -888,6 +945,26 @@ struct configuration_spec * load_config(void) config->forwarded_connect_retries = atoi(arg); break; +/* ************************************************************************* + * handle-as-empty-doc-returns-ok 0|1 + * + * Workaround for firefox hanging on blocked javascript pages. + * Block with the "+handle-as-empty-document" flag and set the + * "handle-as-empty-doc-returns-ok" run-time config flag so that + * Privoxy returns a 200/OK status instead of a 403/Forbidden status + * to the browser for blocked pages. + ***************************************************************************/ + case hash_handle_as_empty_returns_ok: + if ((*arg != '\0') && (0 != atoi(arg))) + { + config->feature_flags |= RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK; + } + else + { + config->feature_flags &= ~RUNTIME_FEATURE_EMPTY_DOC_RETURNS_OK; + } + break; + /* ************************************************************************* * hostname hostname-to-show-on-cgi-pages * *************************************************************************/ @@ -942,7 +1019,7 @@ struct configuration_spec * load_config(void) * In logdir by default * *************************************************************************/ case hash_logfile : - if (!no_daemon) + if (daemon_mode) { logfile = make_path(config->logdir, arg); if (NULL == logfile) @@ -1299,7 +1376,7 @@ struct configuration_spec * load_config(void) /* Save the argument for the show-status page. */ savearg(cmd, arg, config); - + freez(buf); } /* end while ( read_config_line(...) ) */ fclose(configfp); @@ -1308,7 +1385,7 @@ struct configuration_spec * load_config(void) freez(config->logfile); - if (!no_daemon) + if (daemon_mode) { if (NULL != logfile) { @@ -1322,6 +1399,16 @@ struct configuration_spec * load_config(void) } #ifdef FEATURE_CONNECTION_KEEP_ALIVE + if (config->default_server_timeout > config->keep_alive_timeout) + { + log_error(LOG_LEVEL_ERROR, + "Reducing the default-server-timeout from %d to the keep-alive-timeout %d.", + config->default_server_timeout, config->keep_alive_timeout); + config->default_server_timeout = config->keep_alive_timeout; + } +#endif /* def FEATURE_CONNECTION_KEEP_ALIVE */ + +#ifdef FEATURE_CONNECTION_SHARING if (config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE) { if (config->multi_threaded) @@ -1343,7 +1430,13 @@ struct configuration_spec * load_config(void) "Config option single-threaded disables connection keep-alive."); } } -#endif + else if ((config->feature_flags & RUNTIME_FEATURE_CONNECTION_SHARING)) + { + log_error(LOG_LEVEL_ERROR, "Config option connection-sharing " + "has no effect if keep-alive-timeout isn't set."); + config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_SHARING; + } +#endif /* def FEATURE_CONNECTION_SHARING */ if (NULL == config->proxy_args) { @@ -1423,8 +1516,9 @@ struct configuration_spec * load_config(void) #if defined(_WIN32) && !defined (_WIN_CONSOLE) g_default_actions_file = config->actions_file[1]; /* FIXME Hope this is default.action */ - g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */ - g_re_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */ + g_user_actions_file = config->actions_file[2]; /* FIXME Hope this is user.action */ + g_default_filterfile = config->re_filterfile[0]; /* FIXME Hope this is default.filter */ + g_user_filterfile = config->re_filterfile[1]; /* FIXME Hope this is user.filter */ #ifdef FEATURE_TRUST g_trustfile = config->trustfile;