# HG changeset patch # User Paul Aurich # Date 1238822118 0 # Node ID 5172ebcc8673b3c0231efd1bda5acc546b2e2a12 # Parent e7bbcc1e2778e6cc9b5f949c1dc7d31acc59ef5e Reorder functions to remove prototypes diff -r e7bbcc1e2778 -r 5172ebcc8673 libpurple/protocols/jabber/bosh.c --- a/libpurple/protocols/jabber/bosh.c Sat Apr 04 05:00:44 2009 +0000 +++ b/libpurple/protocols/jabber/bosh.c Sat Apr 04 05:15:18 2009 +0000 @@ -91,11 +91,6 @@ }; -static void jabber_bosh_connection_stream_restart(PurpleBOSHConnection *conn); -static gboolean jabber_bosh_connection_error_check(PurpleBOSHConnection *conn, xmlnode *node); -static void jabber_bosh_connection_received(PurpleBOSHConnection *conn, xmlnode *node); -static void jabber_bosh_connection_send(PurpleBOSHConnection *conn, PurpleBOSHPacketType type, const char *data); - static void http_connection_connect(PurpleHTTPConnection *conn); static void http_connection_send_request(PurpleHTTPConnection *conn, const GString *req); @@ -223,6 +218,107 @@ return conn->ssl; } +static PurpleHTTPConnection * +find_available_http_connection(PurpleBOSHConnection *conn) +{ + int i; + + /* Easy solution: Does everyone involved support pipelining? Hooray! Just use + * one TCP connection! */ + if (conn->pipelining) + return conn->connections[0]; + + /* First loop, look for a connection that's ready */ + for (i = 0; i < MAX_HTTP_CONNECTIONS; ++i) { + if (conn->connections[i] && conn->connections[i]->ready && + conn->connections[i]->requests == 0) + return conn->connections[i]; + } + + /* Second loop, look for one that's NULL and create a new connection */ + for (i = 0; i < MAX_HTTP_CONNECTIONS; ++i) { + if (!conn->connections[i]) { + conn->connections[i] = jabber_bosh_http_connection_init(conn); + + http_connection_connect(conn->connections[i]); + return NULL; + } + } + + /* None available. */ + return NULL; +} + +static void +jabber_bosh_connection_send(PurpleBOSHConnection *conn, PurpleBOSHPacketType type, + const char *data) +{ + PurpleHTTPConnection *chosen; + GString *packet = NULL; + + chosen = find_available_http_connection(conn); + + if (type != PACKET_NORMAL && !chosen) { + /* + * For non-ordinary traffic, we don't want to 'buffer' it, so use the first + * connection. + */ + chosen = conn->connections[0]; + + if (!chosen->ready) + purple_debug_warning("jabber", "First BOSH connection wasn't ready. Bad " + "things may happen.\n"); + } + + if (type == PACKET_NORMAL && (!chosen || + (conn->max_requests > 0 && conn->requests == conn->max_requests))) { + /* + * For normal data, send up to max_requests requests at a time or there is no + * connection ready (likely, we're currently opening a second connection and + * will send these packets when connected). + */ + if (data) { + int len = data ? strlen(data) : 0; + purple_circ_buffer_append(conn->pending, data, len); + } + return; + } + + packet = g_string_new(""); + + g_string_printf(packet, "rid, + conn->sid, + conn->js->user->domain); + + if (type == PACKET_STREAM_RESTART) + packet = g_string_append(packet, " xmpp:restart='true'/>"); + else { + gsize read_amt; + if (type == PACKET_TERMINATE) + packet = g_string_append(packet, " type='terminate'"); + + packet = g_string_append_c(packet, '>'); + + while ((read_amt = purple_circ_buffer_get_max_read(conn->pending)) > 0) { + packet = g_string_append_len(packet, conn->pending->outptr, read_amt); + purple_circ_buffer_mark_read(conn->pending, read_amt); + } + + if (data) + packet = g_string_append(packet, data); + packet = g_string_append(packet, ""); + } + + http_connection_send_request(chosen, packet); +} + void jabber_bosh_connection_close(PurpleBOSHConnection *conn) { jabber_bosh_connection_send(conn, PACKET_TERMINATE, NULL); @@ -374,37 +470,6 @@ jabber_stream_features_parse(conn->js, packet); } -static PurpleHTTPConnection * -find_available_http_connection(PurpleBOSHConnection *conn) -{ - int i; - - /* Easy solution: Does everyone involved support pipelining? Hooray! Just use - * one TCP connection! */ - if (conn->pipelining) - return conn->connections[0]; - - /* First loop, look for a connection that's ready */ - for (i = 0; i < MAX_HTTP_CONNECTIONS; ++i) { - if (conn->connections[i] && conn->connections[i]->ready && - conn->connections[i]->requests == 0) - return conn->connections[i]; - } - - /* Second loop, look for one that's NULL and create a new connection */ - for (i = 0; i < MAX_HTTP_CONNECTIONS; ++i) { - if (!conn->connections[i]) { - conn->connections[i] = jabber_bosh_http_connection_init(conn); - - http_connection_connect(conn->connections[i]); - return NULL; - } - } - - /* None available. */ - return NULL; -} - static void jabber_bosh_connection_boot(PurpleBOSHConnection *conn) { GString *buf = g_string_new(""); @@ -460,76 +525,6 @@ } static void -jabber_bosh_connection_send(PurpleBOSHConnection *conn, PurpleBOSHPacketType type, - const char *data) -{ - PurpleHTTPConnection *chosen; - GString *packet = NULL; - - chosen = find_available_http_connection(conn); - - if (type != PACKET_NORMAL && !chosen) { - /* - * For non-ordinary traffic, we don't want to 'buffer' it, so use the first - * connection. - */ - chosen = conn->connections[0]; - - if (!chosen->ready) - purple_debug_warning("jabber", "First BOSH connection wasn't ready. Bad " - "things may happen.\n"); - } - - if (type == PACKET_NORMAL && (!chosen || - (conn->max_requests > 0 && conn->requests == conn->max_requests))) { - /* - * For normal data, send up to max_requests requests at a time or there is no - * connection ready (likely, we're currently opening a second connection and - * will send these packets when connected). - */ - if (data) { - int len = data ? strlen(data) : 0; - purple_circ_buffer_append(conn->pending, data, len); - } - return; - } - - packet = g_string_new(""); - - g_string_printf(packet, "rid, - conn->sid, - conn->js->user->domain); - - if (type == PACKET_STREAM_RESTART) - packet = g_string_append(packet, " xmpp:restart='true'/>"); - else { - gsize read_amt; - if (type == PACKET_TERMINATE) - packet = g_string_append(packet, " type='terminate'"); - - packet = g_string_append_c(packet, '>'); - - while ((read_amt = purple_circ_buffer_get_max_read(conn->pending)) > 0) { - packet = g_string_append_len(packet, conn->pending->outptr, read_amt); - purple_circ_buffer_mark_read(conn->pending, read_amt); - } - - if (data) - packet = g_string_append(packet, data); - packet = g_string_append(packet, ""); - } - - http_connection_send_request(chosen, packet); -} - -static void connection_common_established_cb(PurpleHTTPConnection *conn) { /* Indicate we're ready and reset some variables */