From d8982e3498262713258ac2208c71a03af8de2061 Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Wed, 6 Sep 2006 09:23:37 +0000 Subject: [PATCH] Make number of retries in case of forwarded-connect problems a config file option (forwarded-connect-retries) and use 0 as default. --- jcc.c | 12 ++++++++---- loadcfg.c | 27 ++++++++++++++++++++------- project.h | 11 ++++++++++- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/jcc.c b/jcc.c index 644dc2d5..aa6de6b6 100644 --- a/jcc.c +++ b/jcc.c @@ -1,4 +1,4 @@ -const char jcc_rcs[] = "$Id: jcc.c,v 1.99 2006/09/02 15:36:42 fabiankeil Exp $"; +const char jcc_rcs[] = "$Id: jcc.c,v 1.100 2006/09/03 19:42:59 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jcc.c,v $ @@ -33,6 +33,9 @@ const char jcc_rcs[] = "$Id: jcc.c,v 1.99 2006/09/02 15:36:42 fabiankeil Exp $"; * * Revisions : * $Log: jcc.c,v $ + * Revision 1.100 2006/09/03 19:42:59 fabiankeil + * Set random(3) seed. + * * Revision 1.99 2006/09/02 15:36:42 fabiankeil * Follow the OpenBSD port's lead and protect the resolve * functions on OpenBSD as well. @@ -905,7 +908,8 @@ static void chat(struct client_state *csp) int server_body; int ms_iis5_hack = 0; int byte_count = 0; - unsigned int socks_retries = 0; + unsigned int forwarded_connect_retries = 0; + unsigned int max_forwarded_connect_retries = csp->config->forwarded_connect_retries; const struct forward_spec * fwd; struct http_request *http; int len; /* for buffer sizes */ @@ -1265,10 +1269,10 @@ static void chat(struct client_state *csp) /* here we connect to the server, gateway, or the forwarder */ while ( (csp->sfd = forwarded_connect(fwd, http, csp)) - && (errno == EINVAL) && (socks_retries++ < 3)) + && (errno == EINVAL) && (forwarded_connect_retries++ < max_forwarded_connect_retries)) { log_error(LOG_LEVEL_ERROR, "failed request #%u to connect to %s. Trying again.", - socks_retries, http->hostport); + forwarded_connect_retries, http->hostport); } if (csp->sfd == JB_INVALID_SOCKET) diff --git a/loadcfg.c b/loadcfg.c index 831af1cc..eb24cd62 100644 --- a/loadcfg.c +++ b/loadcfg.c @@ -1,7 +1,7 @@ -const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.48.2.7 2006/02/02 17:29:16 david__schmidt Exp $"; +const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.50 2006/07/18 14:48:46 david__schmidt Exp $"; /********************************************************************* * - * File : $Source: /cvsroot/ijbswa/current/Attic/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,10 @@ const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.48.2.7 2006/02/02 17:29:16 david_ * * Revisions : * $Log: loadcfg.c,v $ + * Revision 1.50 2006/07/18 14:48:46 david__schmidt + * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch) + * with what was really the latest development (the v_3_0_branch branch) + * * Revision 1.48.2.7 2006/02/02 17:29:16 david__schmidt * Don't forget to malloc space for the null terminator... * @@ -434,6 +438,7 @@ static struct file_list *current_configfile = NULL; #define hash_forward 2029845ul /* "forward" */ #define hash_forward_socks4 3963965521ul /* "forward-socks4" */ #define hash_forward_socks4a 2639958518ul /* "forward-socks4a" */ +#define hash_forwarded_connect_retries 101465292ul /* "forwarded-connect-retries" */ #define hash_jarfile 2046641ul /* "jarfile" */ #define hash_listen_address 1255650842ul /* "listen-address" */ #define hash_logdir 422889ul /* "logdir" */ @@ -632,11 +637,12 @@ struct configuration_spec * load_config(void) /* * Set to defaults */ - config->multi_threaded = 1; - config->hport = HADDR_PORT; - config->buffer_limit = 4096 * 1024; - config->usermanual = strdup(USER_MANUAL_URL); - config->proxy_args = strdup(""); + config->multi_threaded = 1; + config->hport = HADDR_PORT; + config->buffer_limit = 4096 * 1024; + config->usermanual = strdup(USER_MANUAL_URL); + config->proxy_args = strdup(""); + config->forwarded_connect_retries = 0; if ((configfp = fopen(configfile, "r")) == NULL) { @@ -1115,6 +1121,13 @@ struct configuration_spec * load_config(void) continue; +/* ************************************************************************* + * forwarded-connect-retries n + * *************************************************************************/ + case hash_forwarded_connect_retries : + config->forwarded_connect_retries = atoi(arg); + continue; + /* ************************************************************************* * jarfile jar-file-name * In logdir by default diff --git a/project.h b/project.h index 576e5084..36025dcd 100644 --- a/project.h +++ b/project.h @@ -1,7 +1,7 @@ #ifndef PROJECT_H_INCLUDED #define PROJECT_H_INCLUDED /** Version string. */ -#define PROJECT_H_VERSION "$Id: project.h,v 1.77 2006/08/21 12:50:51 david__schmidt Exp $" +#define PROJECT_H_VERSION "$Id: project.h,v 1.78 2006/08/31 16:25:06 fabiankeil Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/project.h,v $ @@ -37,6 +37,12 @@ * * Revisions : * $Log: project.h,v $ + * Revision 1.78 2006/08/31 16:25:06 fabiankeil + * Work around a buffer overflow that caused Privoxy to + * segfault if too many trusted referrers were used. Good + * enough for now, but should be replaced with a real + * solution after the next release. + * * Revision 1.77 2006/08/21 12:50:51 david__schmidt * Formatting cleanup * @@ -1399,6 +1405,9 @@ struct configuration_spec /** Nonzero to enable multithreading. */ int multi_threaded; + /** Number of retries in case a forwarded connection attempt fails */ + int forwarded_connect_retries; + /** * Bitmask of features that can be enabled/disabled through the config * file. Currently defined bits: -- 2.39.2