changeset 25991:71835e00c0fc

Rename a few functions and drop some data members. The connect/disconnect callbacks were mismatched and I kept confusing myself.
author Paul Aurich <paul@darkrain42.org>
date Sun, 15 Mar 2009 05:10:46 +0000
parents 1c450685dbc6
children c3c2e8b64539
files libpurple/protocols/jabber/bosh.c
diffstat 1 files changed, 21 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/bosh.c	Sun Mar 15 04:49:00 2009 +0000
+++ b/libpurple/protocols/jabber/bosh.c	Sun Mar 15 05:10:46 2009 +0000
@@ -32,8 +32,6 @@
 
 typedef struct _PurpleHTTPConnection PurpleHTTPConnection;
 
-typedef void (*PurpleHTTPConnectionConnectFunction)(PurpleHTTPConnection *conn);
-typedef void (*PurpleHTTPConnectionDisconnectFunction)(PurpleHTTPConnection *conn);
 typedef void (*PurpleBOSHConnectionConnectFunction)(PurpleBOSHConnection *conn);
 typedef void (*PurpleBOSHConnectionReceiveFunction)(PurpleBOSHConnection *conn, xmlnode *node);
 
@@ -73,8 +71,6 @@
 struct _PurpleHTTPConnection {
     int fd;
 	gboolean ready;
-    char *host;
-    int port;
     int ie_handle;
 	int requests; /* number of outstanding HTTP requests */
 
@@ -83,9 +79,6 @@
     gsize handled_len;
     gsize body_len;
 
-    int pih; /* what? */
-    PurpleHTTPConnectionConnectFunction connect_cb;
-    PurpleHTTPConnectionConnectFunction disconnect_cb;
     PurpleBOSHConnection *bosh;
 };
 
@@ -94,10 +87,8 @@
 static void jabber_bosh_connection_received(PurpleBOSHConnection *conn, xmlnode *node);
 static void jabber_bosh_connection_send_native(PurpleBOSHConnection *conn, PurpleBOSHPacketType, xmlnode *node);
 
-static void jabber_bosh_http_connection_connect(PurpleHTTPConnection *conn);
-static void jabber_bosh_connection_connected(PurpleHTTPConnection *conn);
-static void jabber_bosh_http_connection_disconnected(PurpleHTTPConnection *conn);
-static void jabber_bosh_http_connection_send_request(PurpleHTTPConnection *conn, const GString *req);
+static void http_connection_connect(PurpleHTTPConnection *conn);
+static void http_connection_send_request(PurpleHTTPConnection *conn, const GString *req);
 
 void jabber_bosh_init(void)
 {
@@ -129,8 +120,6 @@
 {
 	PurpleHTTPConnection *conn = g_new0(PurpleHTTPConnection, 1);
 	conn->bosh = bosh;
-	conn->host = g_strdup(bosh->host);
-	conn->port = bosh->port;
 	conn->fd = -1;
 	conn->ready = FALSE;
 
@@ -140,8 +129,6 @@
 static void
 jabber_bosh_http_connection_destroy(PurpleHTTPConnection *conn)
 {
-	g_free(conn->host);
-
 	if (conn->buf)
 		g_string_free(conn->buf, TRUE);
 
@@ -365,9 +352,7 @@
 		if (!conn->connections[i]) {
 			conn->connections[i] = jabber_bosh_http_connection_init(conn);
 
-			conn->connections[i]->connect_cb = jabber_bosh_connection_connected;
-			conn->connections[i]->disconnect_cb = jabber_bosh_http_connection_disconnected;
-			jabber_bosh_http_connection_connect(conn->connections[i]);
+			http_connection_connect(conn->connections[i]);
 			return NULL;
 		}
 	}
@@ -396,7 +381,7 @@
 	                ++conn->rid);
 
 	conn->receive_cb = boot_response_cb;
-	jabber_bosh_http_connection_send_request(conn->connections[0], buf);
+	http_connection_send_request(conn->connections[0], buf);
 	g_string_free(buf, TRUE);
 }
 
@@ -506,10 +491,11 @@
 
 	g_free(buf);
 
-	jabber_bosh_http_connection_send_request(chosen, packet);
+	http_connection_send_request(chosen, packet);
 }
 
-static void jabber_bosh_connection_connected(PurpleHTTPConnection *conn) {
+static void http_connection_connected(PurpleHTTPConnection *conn)
+{
 	conn->ready = TRUE;
 
 	if (conn->bosh->ready) {
@@ -532,7 +518,8 @@
 	jabber_bosh_connection_send(conn, NULL);
 }
 
-static void jabber_bosh_http_connection_disconnected(PurpleHTTPConnection *conn) {
+static void http_connection_disconnected(PurpleHTTPConnection *conn)
+{
 	/*
 	 * Well, then. Fine! I never liked you anyway, server! I was cheating on you
 	 * with AIM!
@@ -544,15 +531,12 @@
 		conn->bosh->pipelining = FALSE;
 
 	/* No! Please! Take me back. It was me, not you! I was weak! */
-	conn->connect_cb = jabber_bosh_connection_connected;
-	jabber_bosh_http_connection_connect(conn);
+	http_connection_connect(conn);
 }
 
 void jabber_bosh_connection_connect(PurpleBOSHConnection *bosh) {
 	PurpleHTTPConnection *conn = bosh->connections[0];
-	conn->connect_cb = jabber_bosh_connection_connected;
-	conn->disconnect_cb = jabber_bosh_http_connection_disconnected;
-	jabber_bosh_http_connection_connect(conn);
+	http_connection_connect(conn);
 }
 
 static void
@@ -648,16 +632,14 @@
 		purple_input_remove(conn->ie_handle);
 		conn->ie_handle = 0;
 
-		if (conn->disconnect_cb)
-			conn->disconnect_cb(conn);
-
+		http_connection_disconnected(conn);
 		return;
 	}
 
 	jabber_bosh_http_connection_process(conn);
 }
 
-static void jabber_bosh_http_connection_callback(gpointer data, gint source, const gchar *error)
+static void http_connection_cb(gpointer data, gint source, const gchar *error)
 {
 	PurpleHTTPConnection *conn = data;
 	PurpleConnection *gc = conn->bosh->js->gc;
@@ -673,19 +655,20 @@
 
 	conn->fd = source;
 
-	if (conn->connect_cb)
-		conn->connect_cb(conn);
+	http_connection_connected(conn);
 
 	conn->ie_handle = purple_input_add(conn->fd, PURPLE_INPUT_READ,
 	        jabber_bosh_http_connection_read, conn);
 }
 
-static void jabber_bosh_http_connection_connect(PurpleHTTPConnection *conn)
+static void http_connection_connect(PurpleHTTPConnection *conn)
 {
-	PurpleConnection *gc = conn->bosh->js->gc;
+	PurpleBOSHConnection *bosh = conn->bosh;
+	PurpleConnection *gc = bosh->js->gc;
 	PurpleAccount *account = purple_connection_get_account(gc);
 
-	if ((purple_proxy_connect(conn, account, conn->host, conn->port, jabber_bosh_http_connection_callback, conn)) == NULL) {
+	if ((purple_proxy_connect(conn, account, bosh->host, bosh->port,
+	                          http_connection_cb, conn)) == NULL) {
 		purple_connection_error_reason(gc,
 		    PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
 		    _("Unable to create socket"));
@@ -693,8 +676,7 @@
 }
 
 static void
-jabber_bosh_http_connection_send_request(PurpleHTTPConnection *conn,
-                                         const GString *req)
+http_connection_send_request(PurpleHTTPConnection *conn, const GString *req)
 {
 	GString *packet = g_string_new("");
 	int ret;
@@ -704,7 +686,7 @@
 	                       "User-Agent: %s\r\n"
 	                       "Content-Encoding: text/xml; charset=utf-8\r\n"
 	                       "Content-Length: %" G_GSIZE_FORMAT "\r\n\r\n",
-	                       conn->bosh->path, conn->host, bosh_useragent,
+	                       conn->bosh->path, conn->bosh->host, bosh_useragent,
 	                       req->len);
 
 	packet = g_string_append(packet, req->str);