From: Fabian Keil Date: Tue, 4 Sep 2012 08:33:31 +0000 (+0000) Subject: Add get_expected_content_length() X-Git-Tag: v_3_0_20~283 X-Git-Url: http://www.privoxy.org/gitweb/%3Ctable?a=commitdiff_plain;h=7fcd2bbc56b5a153530ad4d3a4f86de07f59719f;p=privoxy.git Add get_expected_content_length() --- diff --git a/parsers.c b/parsers.c index 575d73f3..828eea10 100644 --- a/parsers.c +++ b/parsers.c @@ -1,4 +1,4 @@ -const char parsers_rcs[] = "$Id: parsers.c,v 1.247 2012/07/27 17:36:06 fabiankeil Exp $"; +const char parsers_rcs[] = "$Id: parsers.c,v 1.248 2012/09/04 08:32:32 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/parsers.c,v $ @@ -4305,6 +4305,39 @@ static void create_content_length_header(unsigned long long content_length, } +/********************************************************************* + * + * Function : get_expected_content_length + * + * Description : Figures out the content length from a list of headers. + * + * Parameters : + * 1 : headers = List of headers + * + * Returns : Number of bytes to expect + * + *********************************************************************/ +unsigned long long get_expected_content_length(struct list *headers) +{ + const char *content_length_header; + unsigned long long content_length = 0; + + content_length_header = get_header_value(headers, "Content-Length:"); + if (content_length_header != NULL) + { + if (JB_ERR_OK != get_content_length(content_length_header, &content_length)) + { + log_error(LOG_LEVEL_ERROR, + "Failed to get the Content-Length in %s", content_length_header); + /* XXX: The header will be removed later on */ + return 0; + } + } + + return content_length; +} + + /* Local Variables: tab-width: 3 diff --git a/parsers.h b/parsers.h index 60fef213..44dbcc76 100644 --- a/parsers.h +++ b/parsers.h @@ -1,6 +1,6 @@ #ifndef PARSERS_H_INCLUDED #define PARSERS_H_INCLUDED -#define PARSERS_H_VERSION "$Id: parsers.h,v 1.50 2009/05/16 13:27:20 fabiankeil Exp $" +#define PARSERS_H_VERSION "$Id: parsers.h,v 1.51 2011/09/04 11:10:56 fabiankeil Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/parsers.h,v $ @@ -63,6 +63,7 @@ extern jb_err sed(struct client_state *csp, int filter_server_headers); extern jb_err update_server_headers(struct client_state *csp); extern void get_http_time(int time_offset, char *buf, size_t buffer_size); extern jb_err get_destination_from_headers(const struct list *headers, struct http_request *http); +extern unsigned long long get_expected_content_length(struct list *headers); #ifdef FEATURE_FORCE_LOAD extern int strclean(char *string, const char *substring);