/pidgin/main: 0cb189ba00f2: HTTP: refine content length calculation

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Tue Jul 30 04:12:30 EDT 2013


Changeset: 0cb189ba00f21614284b2d975c2c8a82b59767b5
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2013-07-30 10:12 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/0cb189ba00f2

Description:

HTTP: refine content length calculation

diffstat:

 libpurple/http.c |  37 ++++++++++++++++++++-----------------
 1 files changed, 20 insertions(+), 17 deletions(-)

diffs (84 lines):

diff --git a/libpurple/http.c b/libpurple/http.c
--- a/libpurple/http.c
+++ b/libpurple/http.c
@@ -114,7 +114,6 @@ struct _PurpleHttpConnection
 	gboolean contents_reader_requested;
 
 	int redirects_count;
-	int data_length_got;
 
 	int length_expected, length_got;
 
@@ -917,15 +916,20 @@ static gboolean _purple_http_recv_header
 static gboolean _purple_http_recv_body_data(PurpleHttpConnection *hc,
 	const gchar *buf, int len)
 {
-	int current_offset = hc->data_length_got;
-
+	int current_offset = hc->length_got;
+
+	if (hc->length_expected >= 0 &&
+		len + hc->length_got > hc->length_expected)
+	{
+		len = hc->length_expected - hc->length_got;
+	}
 	if (hc->request->max_length >= 0) {
-		if (hc->data_length_got + len > hc->request->max_length) {
-			len = hc->request->max_length - hc->data_length_got;
-			hc->length_expected = hc->length_got;
+		if (hc->length_got + len > hc->request->max_length) {
+			len = hc->request->max_length - hc->length_got;
+			hc->length_expected = hc->request->max_length;
 		}
 	}
-	hc->data_length_got += len;
+	hc->length_got += len;
 
 	if (len == 0)
 		return TRUE;
@@ -1043,15 +1047,7 @@ static gboolean _purple_http_recv_body(P
 	const gchar *buf, int len)
 {
 	if (hc->is_chunked)
-	{
-		hc->length_got += len;
 		return _purple_http_recv_body_chunked(hc, buf, len);
-	}
-
-	if (hc->length_expected >= 0 &&
-		len + hc->length_got > hc->length_expected)
-		len = hc->length_expected - hc->length_got;
-	hc->length_got += len;
 
 	return _purple_http_recv_body_data(hc, buf, len);
 }
@@ -1126,12 +1122,20 @@ static gboolean _purple_http_recv_loopbo
 			return FALSE;
 	}
 
-	if (hc->is_chunked && hc->chunks_done)
+	if (hc->is_chunked && hc->chunks_done && hc->length_expected < 0)
 		hc->length_expected = hc->length_got;
 
 	if (hc->length_expected >= 0 && hc->length_got >= hc->length_expected) {
 		const gchar *redirect;
 
+		if (hc->is_chunked && !hc->chunks_done) {
+			if (purple_debug_is_verbose()) {
+				purple_debug_misc("http",
+					"I need the terminating empty chunk\n");
+			}
+			return TRUE;
+		}
+
 		if (!hc->headers_got) {
 			hc->response->code = 0;
 			purple_debug_warning("http", "No headers got\n");
@@ -1427,7 +1431,6 @@ static gboolean _purple_http_reconnect(P
 		g_string_free(hc->response->contents, TRUE);
 	hc->response->contents = NULL;
 	hc->length_got = 0;
-	hc->data_length_got = 0;
 	hc->length_expected = -1;
 	hc->is_chunked = FALSE;
 	hc->in_chunk = FALSE;



More information about the Commits mailing list