Soften actions files update interval.
[privoxy.git] / jcc.c
diff --git a/jcc.c b/jcc.c
index 7f7206e..6184dc3 100644 (file)
--- a/jcc.c
+++ b/jcc.c
@@ -1,4 +1,4 @@
-const char jcc_rcs[] = "$Id: jcc.c,v 1.98 2006/08/24 11:01:34 fabiankeil Exp $";
+const char jcc_rcs[] = "$Id: jcc.c,v 1.101 2006/09/06 09:23:37 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/jcc.c,v $
@@ -33,6 +33,18 @@ const char jcc_rcs[] = "$Id: jcc.c,v 1.98 2006/08/24 11:01:34 fabiankeil Exp $";
  *
  * Revisions   :
  *    $Log: jcc.c,v $
+ *    Revision 1.101  2006/09/06 09:23:37  fabiankeil
+ *    Make number of retries in case of forwarded-connect problems
+ *    a config file option (forwarded-connect-retries) and use 0 as
+ *    default.
+ *
+ *    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.
+ *
  *    Revision 1.98  2006/08/24 11:01:34  fabiankeil
  *    --user fix. Only use the user as group if no group is specified.
  *    Solves BR 1492612. Thanks to Spinor S. and David Laight.
@@ -901,7 +913,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 */
@@ -984,6 +997,18 @@ static void chat(struct client_state *csp)
       return;
    }
 
+   if (!strncmpic(http->cmd, "GET ftp://", 10))
+   {
+      strcpy(buf, FTP_RESPONSE);
+      write_socket(csp->cfd, buf, strlen(buf));
+
+      log_error(LOG_LEVEL_ERROR, "%s tried to use Privoxy as FTP proxy: %s",
+         csp->ip_addr_str, http->cmd);
+
+      free_http_request(http);
+      return;
+   }
+
    /* decide how to route the HTTP request */
 
    if ((fwd = forward_url(http, csp)) == NULL)
@@ -1261,10 +1286,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)
@@ -1887,6 +1912,9 @@ int main(int argc, const char *argv[])
 #endif
 {
    int argc_pos = 0;
+#ifdef HAVE_RANDOM
+   unsigned int random_seed;
+#endif /* ifdef HAVE_RANDOM */
 #ifdef unix
    struct passwd *pw = NULL;
    struct group *grp = NULL;
@@ -2048,6 +2076,11 @@ int main(int argc, const char *argv[])
    pthread_mutex_init(&log_init_mutex,0);
 #endif /* FEATURE_PTHREAD */
 
+#ifdef HAVE_RANDOM
+   random_seed = (unsigned int)time(NULL);
+   srandom(random_seed);
+#endif /* ifdef HAVE_RANDOM */
+
    /*
     * Unix signal handling
     *