soc.2008.xmpp: fde45023: * moving BOSH interfacing from jabber_se...

tfar at soc.pidgin.im tfar at soc.pidgin.im
Sat Aug 16 17:31:11 EDT 2008


-----------------------------------------------------------------
Revision: fde45023597a8c8984831ed9961f685d8e42c1fe
Ancestor: de95a7afc369e5877464e0098ab59e236d09bca9
Author: tfar at soc.pidgin.im
Date: 2008-08-15T16:35:32
Branch: im.pidgin.soc.2008.xmpp
URL: http://d.pidgin.im/viewmtn/revision/info/fde45023597a8c8984831ed9961f685d8e42c1fe

Modified files:
        libpurple/protocols/jabber/bosh.c
        libpurple/protocols/jabber/jabber.c

ChangeLog: 

* moving BOSH interfacing from jabber_send to jabber_send_raw
* sending BOSH stream restart after successful SASL login

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/bosh.c	ae5225332327f85b40924d5e65d096f0569e3da6
+++ libpurple/protocols/jabber/bosh.c	3505a65458d048596e48d1639a6c29d8337822c6
@@ -56,10 +56,56 @@ void jabber_bosh_connection_init(PurpleB
 	conn->conn_a->userdata = conn;
 }
 
-void jabber_bosh_connection_auth_response(PurpleBOSHConnection *conn, xmlnode *node) {
+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) {
 	char *version;
 	if (xmlnode_get_attrib(node, "sid")) {
@@ -83,11 +129,6 @@ void jabber_bosh_connection_boot_respons
 	}
 }
 
-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");
============================================================
--- libpurple/protocols/jabber/jabber.c	8e349ced3bc11f30abe05f18ff77f2182d856b69
+++ libpurple/protocols/jabber/jabber.c	82de4807d22e398f07e4691a03b3310a0fd0d1dd
@@ -346,26 +346,35 @@ void jabber_send_raw(JabberStream *js, c
 	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 @@ void jabber_send(JabberStream *js, xmlno
 	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) 


More information about the Commits mailing list