Mercurial > pidgin.yaz
changeset 31582:bb91133708fe
jabber: Make the BOSH parsing a little more resilient and add more diagnostic output
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Mon, 10 Jan 2011 03:34:00 +0000 |
parents | dbd0012e72cb |
children | 6826925abd6d |
files | libpurple/protocols/jabber/bosh.c |
diffstat | 1 files changed, 31 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/jabber/bosh.c Mon Jan 10 03:25:42 2011 +0000 +++ b/libpurple/protocols/jabber/bosh.c Mon Jan 10 03:34:00 2011 +0000 @@ -111,6 +111,25 @@ }; +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 @@ { 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 @@ 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 @@ 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 @@ 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; }