changeset 25050:a03a953ba63d

* moving BOSH interfacing from jabber_send to jabber_send_raw * sending BOSH stream restart after successful SASL login
author Tobias Markmann <tfar@soc.pidgin.im>
date Fri, 15 Aug 2008 16:35:32 +0000
parents f775f6021654
children 5f70e13db5cc
files libpurple/protocols/jabber/bosh.c libpurple/protocols/jabber/jabber.c
diffstat 2 files changed, 78 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/bosh.c	Fri Aug 15 14:02:21 2008 +0000
+++ b/libpurple/protocols/jabber/bosh.c	Fri Aug 15 16:35:32 2008 +0000
@@ -56,8 +56,54 @@
 	conn->conn_a->userdata = conn;
 }
 
+void jabber_bosh_connection_stream_restart(PurpleBOSHConnection *conn) {
+	/*
+	<body rid='1573741824'
+	      sid='SomeSID'
+	      to='jabber.org'
+	      xml:lang='en'
+	      xmpp:restart='true'
+	      xmlns='http://jabber.org/protocol/httpbind'
+	      xmlns:xmpp='urn:xmpp:xbosh'/>
+	*/
+	xmlnode *restart = xmlnode_new("body");
+	char *tmp = NULL;
+	conn->rid++;
+	xmlnode_set_attrib(restart, "rid", tmp = g_strdup_printf("%d", conn->rid));
+	g_free(tmp);
+	xmlnode_set_attrib(restart, "sid", conn->sid);
+	xmlnode_set_attrib(restart, "to", conn->js->user->domain);
+	xmlnode_set_attrib(restart, "xml:lang", "en");
+	xmlnode_set_attrib(restart, "xmpp:restart", "true");
+	xmlnode_set_attrib(restart, "xmlns", "http://jabber.org/protocol/httpbind");
+	xmlnode_set_attrib(restart, "xmlns:xmpp", "urn:xmpp:xbosh"); 
+	
+	jabber_bosh_connection_send_native(conn, restart);
+}
+
+void jabber_bosh_connection_received(PurpleBOSHConnection *conn, xmlnode *node) {
+	
+	xmlnode_free(node);
+}
+
 void jabber_bosh_connection_auth_response(PurpleBOSHConnection *conn, xmlnode *node) {
-
+	xmlnode *child = node->child;
+	
+	while(child != NULL && child->type != XMLNODE_TYPE_TAG) {
+		child = child->next;	
+	}
+	
+	if (child != NULL && child->type == XMLNODE_TYPE_TAG) {
+		JabberStream *js = conn->js;
+		if (!strcmp(child->name, "success")) {
+			jabber_bosh_connection_stream_restart(conn);
+			jabber_process_packet(js, &child);
+		} else {
+			js->state = JABBER_STREAM_AUTHENTICATING;
+			conn->receive_cb = jabber_bosh_connection_received;
+			jabber_process_packet(js, &child);
+		}
+	} else printf("\n!! no child!!\n");
 }
 
 void jabber_bosh_connection_boot_response(PurpleBOSHConnection *conn, xmlnode *node) {
@@ -83,11 +129,6 @@
 	}
 }
 
-void jabber_bosh_connection_received(PurpleBOSHConnection *conn, xmlnode *node) {
-	xmlnode_free(node);
-}
-
-
 static void jabber_bosh_connection_boot(PurpleBOSHConnection *conn) {
 	char *tmp;
 	xmlnode *init = xmlnode_new("body");
--- a/libpurple/protocols/jabber/jabber.c	Fri Aug 15 14:02:21 2008 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Fri Aug 15 16:35:32 2008 +0000
@@ -346,26 +346,35 @@
 	if (len == -1)
 		len = strlen(data);
 
-	if (js->writeh == 0)
-		ret = jabber_do_send(js, data, len);
-	else {
-		ret = -1;
-		errno = EAGAIN;
-	}
+	if (js->use_bosh) {
+		xmlnode *xnode = xmlnode_from_str(data, len);
+		if (xnode) jabber_bosh_connection_send(&(js->bosh), xnode);
+		else {
+			purple_connection_error_reason(js->gc, PURPLE_CONNECTION_ERROR_OTHER_ERROR,
+							_("Someone tried to send non-XML in a Jabber world."));
+		}
+	} else {
+		if (js->writeh == 0)
+			ret = jabber_do_send(js, data, len);
+		else {
+			ret = -1;
+			errno = EAGAIN;
+		}
 
-	if (ret < 0 && errno != EAGAIN)
-		purple_connection_error_reason (js->gc,
-			PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
-			_("Write error"));
-	else if (ret < len) {
-		if (ret < 0)
-			ret = 0;
-		if (js->writeh == 0)
-			js->writeh = purple_input_add(
-				js->gsc ? js->gsc->fd : js->fd,
-				PURPLE_INPUT_WRITE, jabber_send_cb, js);
-		purple_circ_buffer_append(js->write_buffer,
-			data + ret, len - ret);
+		if (ret < 0 && errno != EAGAIN)
+			purple_connection_error_reason (js->gc,
+				PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
+				_("Write error"));
+		else if (ret < len) {
+			if (ret < 0)
+				ret = 0;
+			if (js->writeh == 0)
+				js->writeh = purple_input_add(
+					js->gsc ? js->gsc->fd : js->fd,
+					PURPLE_INPUT_WRITE, jabber_send_cb, js);
+			purple_circ_buffer_append(js->write_buffer,
+				data + ret, len - ret);
+		}
 	}
 	return;
 }
@@ -388,13 +397,9 @@
 	if(NULL == packet)
 		return;
 
-	if (js->use_bosh) {
-		jabber_bosh_connection_send(&(js->bosh), packet);
-	} else {
-		txt = xmlnode_to_str(packet, &len);
-		jabber_send_raw(js, txt, len);
-		g_free(txt);
-	}
+	txt = xmlnode_to_str(packet, &len);
+	jabber_send_raw(js, txt, len);
+	g_free(txt);
 }
 
 static void jabber_pong_cb(JabberStream *js, xmlnode *packet, gpointer timeout)