Add get_expected_content_length()
authorFabian Keil <fk@fabiankeil.de>
Tue, 4 Sep 2012 08:33:31 +0000 (08:33 +0000)
committerFabian Keil <fk@fabiankeil.de>
Tue, 4 Sep 2012 08:33:31 +0000 (08:33 +0000)
parsers.c
parsers.h

index 575d73f..828eea1 100644 (file)
--- 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
index 60fef21..44dbcc7 100644 (file)
--- 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);