Add the config option default-server-timeout to control the assumed default server...
[privoxy.git] / loadcfg.c
index 94cf087..33e331e 100644 (file)
--- 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.106 2009/09/10 14:45:17 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;
 
@@ -136,6 +136,7 @@ static struct file_list *current_configfile = NULL;
 #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" */
@@ -358,6 +359,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;
@@ -500,7 +502,7 @@ struct configuration_spec * load_config(void)
 /* *************************************************************************
  * 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 +523,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]]
  * *************************************************************************/
@@ -1322,6 +1345,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 +1376,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)
    {