Fix a cast.
[privoxy.git] / jcc.c
diff --git a/jcc.c b/jcc.c
index ac7cadd..31952a1 100644 (file)
--- a/jcc.c
+++ b/jcc.c
@@ -1,4 +1,4 @@
-const char jcc_rcs[] = "$Id: jcc.c,v 1.321 2010/07/12 16:01:23 fabiankeil Exp $";
+const char jcc_rcs[] = "$Id: jcc.c,v 1.324 2010/07/21 14:35:09 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/jcc.c,v $
@@ -120,7 +120,7 @@ const char jcc_h_rcs[] = JCC_H_VERSION;
 const char project_h_rcs[] = PROJECT_H_VERSION;
 
 int daemon_mode = 1;
-struct client_state  clients[1];
+struct client_states clients[1];
 struct file_list     files[1];
 
 #ifdef FEATURE_STATISTICS
@@ -1615,12 +1615,8 @@ static void chat(struct client_state *csp)
    if (crunch_response_triggered(csp, crunchers_all))
    {
       /*
-       * Yes. The client got the crunch response
-       * and we are done here after cleaning up.
+       * Yes. The client got the crunch response and we're done here.
        */
-      /* XXX: why list_remove_all()? */
-      list_remove_all(csp->headers);
-
       return;
    }
 
@@ -1793,9 +1789,14 @@ static void chat(struct client_state *csp)
          && ((csp->iob->eod - csp->iob->cur) >= 5)
          && !memcmp(csp->iob->eod-5, "0\r\n\r\n", 5))
       {
+         /*
+          * XXX: This check should be obsolete now,
+          *      but let's wait a while to be sure.
+          */
          log_error(LOG_LEVEL_CONNECT,
-            "Looks like we read the last chunk together with "
-            "the server headers. We better stop reading.");
+            "Looks like we got the last chunk together with "
+            "the server headers but didn't detect it earlier. "
+            "We better stop reading.");
          byte_count = (unsigned long long)(csp->iob->eod - csp->iob->cur);
          csp->expected_content_length = byte_count;
          csp->flags |= CSP_FLAG_CONTENT_LENGTH_SET;
@@ -2298,6 +2299,19 @@ static void chat(struct client_state *csp)
                log_error(LOG_LEVEL_FATAL, "Out of memory parsing server header");
             }
 
+            if ((csp->flags & CSP_FLAG_CHUNKED)
+               && !(csp->flags & CSP_FLAG_CONTENT_LENGTH_SET)
+               && ((csp->iob->eod - csp->iob->cur) >= 5)
+               && !memcmp(csp->iob->eod-5, "0\r\n\r\n", 5))
+            {
+               log_error(LOG_LEVEL_CONNECT,
+                  "Looks like we got the last chunk together with "
+                  "the server headers. We better stop reading.");
+               byte_count = (unsigned long long)(csp->iob->eod - csp->iob->cur);
+               csp->expected_content_length = byte_count;
+               csp->flags |= CSP_FLAG_CONTENT_LENGTH_SET;
+            }
+
             csp->server_connection.response_received = time(NULL);
 
             if (crunch_response_triggered(csp, crunchers_light))
@@ -3345,6 +3359,7 @@ void w32_service_listen_loop(void *p)
  *********************************************************************/
 static void listen_loop(void)
 {
+   struct client_states *csp_list = NULL;
    struct client_state *csp = NULL;
    jb_socket bfd;
    struct configuration_spec *config;
@@ -3394,11 +3409,14 @@ static void listen_loop(void)
       }
 #endif
 
-      if ( NULL == (csp = (struct client_state *) zalloc(sizeof(*csp))) )
+      csp_list = (struct client_states *)zalloc(sizeof(*csp_list));
+      if (NULL == csp_list)
       {
-         log_error(LOG_LEVEL_FATAL, "malloc(%d) for csp failed: %E", sizeof(*csp));
+         log_error(LOG_LEVEL_FATAL,
+            "malloc(%d) for csp_list failed: %E", sizeof(*csp_list));
          continue;
       }
+      csp = &csp_list->csp;
 
       csp->flags |= CSP_FLAG_ACTIVE;
       csp->server_connection.sfd = JB_INVALID_SOCKET;
@@ -3484,8 +3502,8 @@ static void listen_loop(void)
       }
 
       /* add it to the list of clients */
-      csp->next = clients->next;
-      clients->next = csp;
+      csp_list->next = clients->next;
+      clients->next = csp_list;
 
       if (config->multi_threaded)
       {