X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=parsers.c;h=96fab7f68cb4effd93c75a02f08e426ea0f41156;hp=2f3b4f42a047e02d31528b3ad4ca8adc404b5e4a;hb=82c493b884fe1157749712c0bfbdd6e2a1455a97;hpb=5ef6a84243b94b2a219048d44c3cb45193abd27f diff --git a/parsers.c b/parsers.c index 2f3b4f42..96fab7f6 100644 --- a/parsers.c +++ b/parsers.c @@ -1,4 +1,4 @@ -const char parsers_rcs[] = "$Id: parsers.c,v 1.264 2012/11/11 12:41:12 fabiankeil Exp $"; +const char parsers_rcs[] = "$Id: parsers.c,v 1.269 2012/11/24 14:09:11 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/parsers.c,v $ @@ -137,6 +137,7 @@ static jb_err server_keep_alive(struct client_state *csp, char **header); static jb_err server_proxy_connection(struct client_state *csp, char **header); static jb_err client_keep_alive(struct client_state *csp, char **header); static jb_err client_save_content_length(struct client_state *csp, char **header); +static jb_err client_proxy_connection(struct client_state *csp, char **header); #endif /* def FEATURE_CONNECTION_KEEP_ALIVE */ static jb_err client_host_adder (struct client_state *csp); @@ -184,11 +185,12 @@ static const struct parsers client_patterns[] = { #ifdef FEATURE_CONNECTION_KEEP_ALIVE { "Keep-Alive:", 11, client_keep_alive }, { "Content-Length:", 15, client_save_content_length }, + { "Proxy-Connection:", 17, client_proxy_connection }, #else { "Keep-Alive:", 11, crumble }, + { "Proxy-Connection:", 17, crumble }, #endif { "connection:", 11, client_connection }, - { "proxy-connection:", 17, crumble }, { "max-forwards:", 13, client_max_forwards }, { "Accept-Language:", 16, client_accept_language }, { "if-none-match:", 14, client_if_none_match }, @@ -196,6 +198,9 @@ static const struct parsers client_patterns[] = { { "Request-Range:", 14, client_range }, { "If-Range:", 9, client_range }, { "X-Filter:", 9, client_x_filter }, +#if 0 + { "Transfer-Encoding:", 18, client_transfer_encoding }, +#endif { "*", 0, crunch_client_header }, { "*", 0, filter_header }, { NULL, 0, NULL } @@ -738,31 +743,6 @@ jb_err decompress_iob(struct client_state *csp) #endif /* defined(FEATURE_ZLIB) */ -/********************************************************************* - * - * Function : string_move - * - * Description : memmove wrapper to move the last part of a string - * towards the beginning, overwriting the part in - * the middle. strlcpy() can't be used here as the - * strings overlap. - * - * Parameters : - * 1 : dst = Destination to overwrite - * 2 : src = Source to move. - * - * Returns : N/A - * - *********************************************************************/ -static void string_move(char *dst, char *src) -{ - assert(dst < src); - - /* +1 to copy the terminating nul as well. */ - memmove(dst, src, strlen(src)+1); -} - - /********************************************************************* * * Function : normalize_lws @@ -1251,6 +1231,7 @@ jb_err update_server_headers(struct client_state *csp) log_error(LOG_LEVEL_HEADER, "Content modified with no Content-Length header set. " "Created: %s.", header); + csp->flags |= CSP_FLAG_SERVER_CONTENT_LENGTH_SET; } } #endif /* def FEATURE_CONNECTION_KEEP_ALIVE */ @@ -1965,6 +1946,74 @@ static jb_err client_connection(struct client_state *csp, char **header) } +#ifdef FEATURE_CONNECTION_KEEP_ALIVE +/********************************************************************* + * + * Function : client_proxy_connection + * + * Description : Sets the CLIENT_CONNECTION_KEEP_ALIVE flag when + * appropriate and removes the Proxy-Connection + * header. + * + * Parameters : + * 1 : csp = Current client state (buffers, headers, etc...) + * 2 : header = On input, pointer to header to modify. + * On output, pointer to the modified header, or NULL + * to remove the header. This function frees the + * original string if necessary. + * + * Returns : JB_ERR_OK + * + *********************************************************************/ +static jb_err client_proxy_connection(struct client_state *csp, char **header) +{ + if (0 == (csp->flags & CSP_FLAG_CLIENT_CONNECTION_KEEP_ALIVE) + && (csp->http->ssl == 0) + && (NULL == strstr(*header, "close"))) + { + log_error(LOG_LEVEL_HEADER, + "The client connection can be kept alive due to: %s", *header); + csp->flags |= CSP_FLAG_CLIENT_CONNECTION_KEEP_ALIVE; + } + crumble(csp, header); + + return JB_ERR_OK; +} +#endif /* def FEATURE_CONNECTION_KEEP_ALIVE */ + + +/********************************************************************* + * + * Function : client_transfer_encoding + * + * Description : Raise the CSP_FLAG_CHUNKED_CLIENT_BODY flag if + * the request body is "chunked" + * + * XXX: Currently not called through sed() as we + * need the flag earlier on. Should be fixed. + * + * Parameters : + * 1 : csp = Current client state (buffers, headers, etc...) + * 2 : header = On input, pointer to header to modify. + * On output, pointer to the modified header, or NULL + * to remove the header. This function frees the + * original string if necessary. + * + * Returns : JB_ERR_OK on success, or + * + *********************************************************************/ +jb_err client_transfer_encoding(struct client_state *csp, char **header) +{ + if (strstr(*header, "chunked")) + { + csp->flags |= CSP_FLAG_CHUNKED_CLIENT_BODY; + log_error(LOG_LEVEL_HEADER, "Expecting chunked client body"); + } + + return JB_ERR_OK; +} + + /********************************************************************* * * Function : crumble @@ -3881,7 +3930,12 @@ static jb_err server_set_cookie(struct client_state *csp, char **header) time_t now; time_t cookie_time; long cookie_lifetime = 0; - int expiry_date_acceptable = 0; + enum + { + NO_EXPIRY_DATE_SPECIFIED, + EXPIRY_DATE_ACCEPTABLE, + EXPIRY_DATE_UNACCEPTABLE + } expiry_date_status = NO_EXPIRY_DATE_SPECIFIED; /* A variable to store the tag we're working on */ char *cur_tag; @@ -3962,7 +4016,7 @@ static jb_err server_set_cookie(struct client_state *csp, char **header) log_error(LOG_LEVEL_ERROR, "Can't parse \'%s\', send by %s. Unsupported time format?", cur_tag, csp->http->url); string_move(cur_tag, next_tag); - expiry_date_acceptable = 0; + expiry_date_status = EXPIRY_DATE_UNACCEPTABLE; } else { @@ -4006,7 +4060,7 @@ static jb_err server_set_cookie(struct client_state *csp, char **header) "Cookie \'%s\' is already expired and can pass unmodified.", *header); /* Just in case some clown sets more then one expiration date */ cur_tag = next_tag; - expiry_date_acceptable = 1; + expiry_date_status = EXPIRY_DATE_ACCEPTABLE; } else if ((cookie_lifetime != 0) && (cookie_time < (now + cookie_lifetime))) { @@ -4014,7 +4068,7 @@ static jb_err server_set_cookie(struct client_state *csp, char **header) "Its lifetime is below the limit.", *header); /* Just in case some clown sets more then one expiration date */ cur_tag = next_tag; - expiry_date_acceptable = 1; + expiry_date_status = EXPIRY_DATE_ACCEPTABLE; } else { @@ -4025,7 +4079,7 @@ static jb_err server_set_cookie(struct client_state *csp, char **header) string_move(cur_tag, next_tag); /* That changed the header, need to issue a log message */ - expiry_date_acceptable = 0; + expiry_date_status = EXPIRY_DATE_UNACCEPTABLE; /* * Note that the next tag has now been moved to *cur_tag, @@ -4042,19 +4096,19 @@ static jb_err server_set_cookie(struct client_state *csp, char **header) } } - if (!expiry_date_acceptable) + if (expiry_date_status != EXPIRY_DATE_ACCEPTABLE) { assert(NULL != *header); - if (cookie_lifetime == 0) - { - log_error(LOG_LEVEL_HEADER, "Cookie rewritten to a temporary one: %s", - *header); - } - else + if (cookie_lifetime != 0) { add_cookie_expiry_date(header, cookie_lifetime); log_error(LOG_LEVEL_HEADER, "Cookie rewritten to: %s", *header); } + else if (expiry_date_status != NO_EXPIRY_DATE_SPECIFIED) + { + log_error(LOG_LEVEL_HEADER, + "Cookie rewritten to a temporary one: %s", *header); + } } }