changeset 26534:5172ebcc8673

Reorder functions to remove prototypes
author Paul Aurich <paul@darkrain42.org>
date Sat, 04 Apr 2009 05:15:18 +0000
parents e7bbcc1e2778
children ecf6fd808d23
files libpurple/protocols/jabber/bosh.c
diffstat 1 files changed, 101 insertions(+), 106 deletions(-) [+]
line wrap: on
line diff
--- 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, "<body "
+	                "rid='%" G_GUINT64_FORMAT "' "
+	                "sid='%s' "
+	                "to='%s' "
+	                "xml:lang='en' "
+	                "xmlns='http://jabber.org/protocol/httpbind' "
+	                "xmlns:xmpp='urn:xmpp:xbosh'",
+	                ++conn->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, "</body>");
+	}
+
+	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, "<body "
-	                "rid='%" G_GUINT64_FORMAT "' "
-	                "sid='%s' "
-	                "to='%s' "
-	                "xml:lang='en' "
-	                "xmlns='http://jabber.org/protocol/httpbind' "
-	                "xmlns:xmpp='urn:xmpp:xbosh'",
-	                ++conn->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, "</body>");
-	}
-
-	http_connection_send_request(chosen, packet);
-}
-
-static void
 connection_common_established_cb(PurpleHTTPConnection *conn)
 {
 	/* Indicate we're ready and reset some variables */