pidgin: d193c886: jabber: Make the BOSH parsing a little m...

darkrain42 at pidgin.im darkrain42 at pidgin.im
Mon Jan 10 00:25:47 EST 2011


----------------------------------------------------------------------
Revision: d193c88637acb911483fc65a94ba352d61e64de3
Parent:   76229686d071dc2c68970929786baf65f0b75afd
Author:   darkrain42 at pidgin.im
Date:     01/09/11 22:34:00
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/d193c88637acb911483fc65a94ba352d61e64de3

Changelog: 

jabber: Make the BOSH parsing a little more resilient and add more diagnostic output

Changes against parent 76229686d071dc2c68970929786baf65f0b75afd

  patched  libpurple/protocols/jabber/bosh.c

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/bosh.c	ba6130bd8cadd8ab1ad9173646bf1601b53d5a2a
+++ libpurple/protocols/jabber/bosh.c	0a4594a451a6060b07bef8d97fffbea050956105
@@ -111,6 +111,25 @@ struct _PurpleHTTPConnection {
 
 };
 
+static void
+debug_dump_http_connections(PurpleBOSHConnection *conn)
+{
+	int i;
+
+	g_return_if_fail(conn != NULL);
+
+	for (i = 0; i < NUM_HTTP_CONNECTIONS; ++i) {
+		PurpleHTTPConnection *httpconn = conn->connections[i];
+		if (httpconn == NULL)
+			purple_debug_misc("jabber", "BOSH %p->connections[%d] = (nil)\n",
+			                  conn, i);
+		else
+			purple_debug_misc("jabber", "BOSH %p->connections[%d] = %p, state = %d"
+			                  ", requests = %d\n", conn, i, httpconn,
+			                  httpconn->state, httpconn->requests);
+	}
+}
+
 static void http_connection_connect(PurpleHTTPConnection *conn);
 static void http_connection_send_request(PurpleHTTPConnection *conn,
                                          const GString *req);
@@ -263,18 +282,8 @@ find_available_http_connection(PurpleBOS
 {
 	int i;
 
-	if (purple_debug_is_verbose()) {
-		for (i = 0; i < NUM_HTTP_CONNECTIONS; ++i) {
-			PurpleHTTPConnection *httpconn = conn->connections[i];
-			if (httpconn == NULL)
-				purple_debug_misc("jabber", "BOSH %p->connections[%d] = (nil)\n",
-				                  conn, i);
-			else
-				purple_debug_misc("jabber", "BOSH %p->connections[%d] = %p, state = %d"
-				                  ", requests = %d\n", conn, i, httpconn,
-				                  httpconn->state, httpconn->requests);
-		}
-	}
+	if (purple_debug_is_verbose())
+		debug_dump_http_connections(conn);
 
 	/* Easy solution: Does everyone involved support pipelining? Hooray! Just use
 	 * one TCP connection! */
@@ -612,6 +621,8 @@ connection_common_established_cb(PurpleH
 static void
 connection_common_established_cb(PurpleHTTPConnection *conn)
 {
+	purple_debug_misc("jabber", "bosh: httpconn %p re-connected\n", conn);
+
 	/* Indicate we're ready and reset some variables */
 	conn->state = HTTP_CONN_CONNECTED;
 	if (conn->requests != 0)
@@ -626,6 +637,9 @@ connection_common_established_cb(PurpleH
 	conn->headers_done = FALSE;
 	conn->handled_len = conn->body_len = 0;
 
+	if (purple_debug_is_verbose())
+		debug_dump_http_connections(conn->bosh);
+
 	if (conn->bosh->js->reinit)
 		jabber_bosh_connection_send(conn->bosh, PACKET_NORMAL, NULL);
 	else if (conn->bosh->state == BOSH_CONN_ONLINE) {
@@ -710,26 +724,25 @@ jabber_bosh_http_connection_process(Purp
 
 	cursor = conn->read_buf->str + conn->handled_len;
 
+	/* TODO: Chunked encoding :/ */
 	if (!conn->headers_done) {
-		const char *content_length = purple_strcasestr(cursor, "\r\nContent-Length");
+		const char *content_length = purple_strcasestr(cursor, "\r\nContent-Length:");
 		const char *end_of_headers = strstr(cursor, "\r\n\r\n");
 
 		/* Make sure Content-Length is in headers, not body */
 		if (content_length && (!end_of_headers || content_length < end_of_headers)) {
-			const char *sep;
 			int len;
 
-			if ((sep = strstr(content_length, ": ")) == NULL ||
-					strstr(sep, "\r\n") == NULL)
+			if (strstr(content_length, "\r\n") == NULL)
 				/*
 				 * The packet ends in the middle of the Content-Length line.
 				 * We'll try again later when we have more.
 				 */
 				return;
 
-			len = atoi(sep + 2);
+			len = atoi(content_length + strlen("\r\nContent-Length:"));
 			if (len == 0)
-				purple_debug_warning("jabber", "Found mangled Content-Length header.\n");
+				purple_debug_warning("jabber", "Found mangled Content-Length header, or server returned 0-length response.\n");
 
 			conn->body_len = len;
 		}


More information about the Commits mailing list