X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=jcc.c;h=317d87cf809d44a4d12634321e69bb44f82f3b3a;hp=35d4a321c0fbb84c6b393c1c801fd6e264371417;hb=74fec84a0663bc797225261a69859d835871873f;hpb=d19ac9846ff30aaf523f4d55202a35db70d447a6 diff --git a/jcc.c b/jcc.c index 35d4a321..317d87cf 100644 --- a/jcc.c +++ b/jcc.c @@ -1,4 +1,4 @@ -const char jcc_rcs[] = "$Id: jcc.c,v 1.323 2010/07/21 14:32:00 fabiankeil Exp $"; +const char jcc_rcs[] = "$Id: jcc.c,v 1.329 2010/09/14 07:14:15 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jcc.c,v $ @@ -1521,9 +1521,7 @@ static void chat(struct client_state *csp) const struct forward_spec *fwd; struct http_request *http; long len = 0; /* for buffer sizes (and negative error codes) */ - - /* Function that does the content filtering for the current request */ - filter_function_ptr content_filter = NULL; + int buffer_and_filter_content = 0; /* Skeleton for HTTP response, if we should intercept the request */ struct http_response *rsp; @@ -1789,9 +1787,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; @@ -2044,11 +2047,11 @@ static void chat(struct client_state *csp) * now is the time to apply content modification * and send the result to the client. */ - if (content_filter) + if (buffer_and_filter_content) { - p = execute_content_filter(csp, content_filter); + p = execute_content_filters(csp); /* - * If the content filter fails, use the original + * If content filtering fails, use the original * buffer and length. * (see p != NULL ? p : csp->iob->cur below) */ @@ -2110,7 +2113,7 @@ static void chat(struct client_state *csp) */ if (server_body || http->ssl) { - if (content_filter) + if (buffer_and_filter_content) { /* * If there is no memory left for buffering the content, or the buffer limit @@ -2158,7 +2161,7 @@ static void chat(struct client_state *csp) */ byte_count = (unsigned long long)flushed; freez(hdr); - content_filter = NULL; + buffer_and_filter_content = 0; server_body = 1; } } @@ -2294,6 +2297,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)) @@ -2312,12 +2328,12 @@ static void chat(struct client_state *csp) if (!http->ssl) /* We talk plaintext */ { - content_filter = get_filter_function(csp); + buffer_and_filter_content = content_requires_filtering(csp); } /* * Only write if we're not buffering for content modification */ - if (!content_filter) + if (!buffer_and_filter_content) { /* * Write the server's (modified) header to @@ -3437,12 +3453,14 @@ static void listen_loop(void) exit(1); } #endif - freez(csp); + freez(csp_list); continue; } else { - log_error(LOG_LEVEL_CONNECT, "accepted connection from %s", csp->ip_addr_str); + log_error(LOG_LEVEL_CONNECT, + "accepted connection from %s on socket %d", + csp->ip_addr_str, csp->cfd); } #ifdef FEATURE_TOGGLE @@ -3464,7 +3482,7 @@ static void listen_loop(void) log_error(LOG_LEVEL_CONNECT, "Connection from %s dropped due to ACL", csp->ip_addr_str); close_socket(csp->cfd); freez(csp->ip_addr_str); - freez(csp); + freez(csp_list); continue; } #endif /* def FEATURE_ACL */ @@ -3479,7 +3497,7 @@ static void listen_loop(void) strlen(TOO_MANY_CONNECTIONS_RESPONSE)); close_socket(csp->cfd); freez(csp->ip_addr_str); - freez(csp); + freez(csp_list); continue; }