Remember connections in case of destination mismatches in chat()
[privoxy.git] / jcc.c
diff --git a/jcc.c b/jcc.c
index cbad64f..8f912ca 100644 (file)
--- a/jcc.c
+++ b/jcc.c
@@ -1,4 +1,4 @@
-const char jcc_rcs[] = "$Id: jcc.c,v 1.400 2012/10/21 12:56:38 fabiankeil Exp $";
+const char jcc_rcs[] = "$Id: jcc.c,v 1.404 2012/10/21 13:04:08 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/jcc.c,v $
@@ -1134,8 +1134,7 @@ static void verify_request_length(struct client_state *csp)
                "Possible pipeline attempt detected. The connection will not "
                "be kept alive and we will only serve the first request.");
             /* Nuke the pipelined requests from orbit, just to be sure. */
-            csp->client_iob->buf[0] = '\0';
-            csp->client_iob->eod = csp->client_iob->cur = csp->client_iob->buf;
+            clear_iob(csp->client_iob);
          }
          else
          {
@@ -1302,6 +1301,9 @@ static jb_err receive_client_request(struct client_state *csp)
    struct list header_list;
    struct list *headers = &header_list;
 
+   /* We don't care if the arriving data is a valid HTTP request or not. */
+   csp->requests_received_total++;
+
    http = csp->http;
 
    memset(buf, 0, sizeof(buf));
@@ -1696,10 +1698,20 @@ static void chat(struct client_state *csp)
    {
       if (csp->server_connection.sfd != JB_INVALID_SOCKET)
       {
-         log_error(LOG_LEVEL_CONNECT,
-            "Closing server socket %u. Opened for %s.",
-            csp->server_connection.sfd, csp->server_connection.host);
-         close_socket(csp->server_connection.sfd);
+#ifdef FEATURE_CONNECTION_SHARING
+         if (csp->config->feature_flags & RUNTIME_FEATURE_CONNECTION_SHARING)
+         {
+            remember_connection(&csp->server_connection);
+         }
+         else
+#endif /* def FEATURE_CONNECTION_SHARING */
+         {
+            log_error(LOG_LEVEL_CONNECT,
+               "Closing server socket %d connected to %s. Total requests: %u.",
+               csp->server_connection.sfd, csp->server_connection.host,
+               csp->server_connection.requests_sent_total);
+            close_socket(csp->server_connection.sfd);
+         }
          mark_connection_closed(&csp->server_connection);
       }
 #endif /* def FEATURE_CONNECTION_KEEP_ALIVE */
@@ -2635,14 +2647,13 @@ static void serve(struct client_state *csp)
             || !(latency < csp->server_connection.keep_alive_timeout))
          {
             log_error(LOG_LEVEL_CONNECT,
-               "Closing connection on server socket %d to %s: "
-               "keep-alive %u, tainted: %u, socket alive %u. %s timeout: %u.",
+               "Closing server socket %d connected to %s: "
+               "Keep-alive %u. Tainted: %u. Socket alive %u. Timeout: %u.",
                csp->server_connection.sfd, csp->server_connection.host,
                0 != (csp->flags & CSP_FLAG_SERVER_CONNECTION_KEEP_ALIVE),
                0 != (csp->flags & CSP_FLAG_SERVER_SOCKET_TAINTED),
                socket_is_still_alive(csp->server_connection.sfd),
-               ((csp->flags & CSP_FLAG_SERVER_KEEP_ALIVE_TIMEOUT_SET) ?
-               "Specified" : "Assumed"), csp->server_connection.keep_alive_timeout);
+               csp->server_connection.keep_alive_timeout);
 #ifdef FEATURE_CONNECTION_SHARING
             if (csp->config->feature_flags & RUNTIME_FEATURE_CONNECTION_SHARING)
             {
@@ -2665,9 +2676,9 @@ static void serve(struct client_state *csp)
          if (((csp->flags & CSP_FLAG_PIPELINED_REQUEST_WAITING) != 0)
             && socket_is_still_alive(csp->cfd))
          {
-            log_error(LOG_LEVEL_CONNECT, "A client request has been "
+            log_error(LOG_LEVEL_CONNECT, "Client request %d has been "
                "pipelined on socket %d and the socket is still alive.",
-               csp->cfd);
+               csp->requests_received_total+1, csp->cfd);
             prepare_csp_for_next_request(csp);
             continue;
          }
@@ -2694,7 +2705,8 @@ static void serve(struct client_state *csp)
             && socket_is_still_alive(csp->cfd))
          {
             log_error(LOG_LEVEL_CONNECT,
-               "Client request arrived in time on socket %d.", csp->cfd);
+               "Client request %u arrived in time on socket %d.",
+               csp->requests_received_total+1, csp->cfd);
             prepare_csp_for_next_request(csp);
          }
          else
@@ -2733,8 +2745,8 @@ static void serve(struct client_state *csp)
       else if (csp->server_connection.sfd != JB_INVALID_SOCKET)
       {
          log_error(LOG_LEVEL_CONNECT,
-            "Closing server socket %d connected to %s. Keep-alive %u. "
-            "Tainted: %u. Socket alive %u. Timeout: %u. "
+            "Closing server socket %d connected to %s. Keep-alive: %u. "
+            "Tainted: %u. Socket alive: %u. Timeout: %u. "
             "Configuration file change detected: %u",
             csp->server_connection.sfd, csp->server_connection.host,
             0 != (csp->flags & CSP_FLAG_SERVER_CONNECTION_KEEP_ALIVE),
@@ -2767,11 +2779,11 @@ static void serve(struct client_state *csp)
    if (csp->cfd != JB_INVALID_SOCKET)
    {
       log_error(LOG_LEVEL_CONNECT, "Closing client socket %d. "
-         "Keep-alive: %u, Socket alive: %u. Data available: %u. "
-         "Configuration file change detected: %u.",
+         "Keep-alive: %u. Socket alive: %u. Data available: %u. "
+         "Configuration file change detected: %u. Requests received: %u.",
          csp->cfd, 0 != (csp->flags & CSP_FLAG_CLIENT_CONNECTION_KEEP_ALIVE),
          socket_is_still_alive(csp->cfd), data_is_available(csp->cfd, 0),
-         config_file_change_detected);
+         config_file_change_detected, csp->requests_received_total);
       drain_and_close_socket(csp->cfd);
    }