cpw.malu.xmpp.jingle_ft: cef5a96c: Updated Jingle IBB to version :1

malu at pidgin.im malu at pidgin.im
Mon Apr 19 14:55:51 EDT 2010


-----------------------------------------------------------------
Revision: cef5a96ccf8d5b3a31bf8124d64acf45f4ae7290
Ancestor: 4a7d67a4700b7eb72cae56ed12169034171dff7b
Author: malu at pidgin.im
Date: 2010-04-19T18:51:55
Branch: im.pidgin.cpw.malu.xmpp.jingle_ft
URL: http://d.pidgin.im/viewmtn/revision/info/cef5a96ccf8d5b3a31bf8124d64acf45f4ae7290

Modified files:
        libpurple/protocols/jabber/ibb.c
        libpurple/protocols/jabber/ibb.h
        libpurple/protocols/jabber/jabber.c
        libpurple/protocols/jabber/jingle/file-transfer.c
        libpurple/protocols/jabber/jingle/ibbs.c
        libpurple/protocols/jabber/jingle/ibbs.h
        libpurple/protocols/jabber/jingle/jingle.h
        libpurple/protocols/jabber/jingle/session.c
        libpurple/protocols/jabber/jingle/session.h

ChangeLog: 

Updated Jingle IBB to version :1

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/ibb.c	2d02572af83eb802ed28684d64cb65988c04aead
+++ libpurple/protocols/jabber/ibb.c	f6b5e1df23bafdbb210d1a2b3f59a5434dd18496
@@ -140,13 +140,6 @@ jabber_ibb_session_get_state(const Jabbe
 	return sess->state;
 }
 
-void
-jabber_ibb_session_set_state(JabberIBBSession *sess, 
-	JabberIBBSessionState state)
-{
-	sess->state = state;
-}
-
 gsize
 jabber_ibb_session_get_block_size(const JabberIBBSession *sess)
 {
============================================================
--- libpurple/protocols/jabber/ibb.h	f14b7f47ffdf790f699d512b41f2488ff0065fb2
+++ libpurple/protocols/jabber/ibb.h	0d642a447c408bdd4fe7c4fffb41ab8944477f9b
@@ -103,8 +103,6 @@ JabberIBBSessionState jabber_ibb_session
 guint16 jabber_ibb_session_get_recv_seq(const JabberIBBSession *sess);
 
 JabberIBBSessionState jabber_ibb_session_get_state(const JabberIBBSession *sess);
-void jabber_ibb_session_set_state(JabberIBBSession *sess, 
-	JabberIBBSessionState state);
 
 gsize jabber_ibb_session_get_block_size(const JabberIBBSession *sess);
 void jabber_ibb_session_set_block_size(JabberIBBSession *sess, gsize size);
============================================================
--- libpurple/protocols/jabber/jabber.c	6dd7bdbe5973ad741c527f4fb99433e5df528870
+++ libpurple/protocols/jabber/jabber.c	7195d34a061333f6a4db9d6ec4220e0ae81fed90
@@ -69,6 +69,7 @@
 
 #include "jingle/jingle.h"
 #include "jingle/rtp.h"
+#include "jingle/ibbs.h"
 
 #define PING_TIMEOUT 60
 
@@ -3665,7 +3666,8 @@ jabber_do_init(void)
 	jabber_add_feature(JINGLE_APP_FT, 0);
 	jabber_add_feature(JINGLE_TRANSPORT_S5B, 0);
 	jabber_add_feature(JINGLE_TRANSPORT_IBB, 0);
-               
+	jingle_ibbs_init();
+	    
 	jabber_auth_init();
 }
 
@@ -3687,6 +3689,8 @@ jabber_do_uninit(void)
 	jabber_features_destroy();
 	jabber_identities_destroy();
 
+	jingle_ibbs_unint();
+	
 	g_hash_table_destroy(jabber_cmds);
 	jabber_cmds = NULL;
 }
============================================================
--- libpurple/protocols/jabber/jingle/file-transfer.c	24d4888a6aed2b09f4f0d33c75e96fc7de80e657
+++ libpurple/protocols/jabber/jingle/file-transfer.c	3bdbe407cf489b03360ecd17600969a8bea01a56
@@ -231,7 +231,8 @@ jingle_file_transfer_ibb_data_recv_callb
 {
 	JingleFT *ft = JINGLE_FT(content);
 	PurpleXfer *xfer = JINGLE_FT_GET_PRIVATE(ft)->xfer;
-
+	JingleSession *session = jingle_content_get_session(content);
+	
 	if (purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_STARTED) { 
 		if (size <= purple_xfer_get_bytes_remaining(xfer)) {
 			purple_debug_info("jingle-ft", 
@@ -289,6 +290,16 @@ static void
 }
 
 static void
+jingle_file_transfer_ibb_opened_callback(JingleContent *content)
+{
+	PurpleXfer *xfer = JINGLE_FT_GET_PRIVATE(JINGLE_FT(content))->xfer;
+
+	purple_xfer_set_write_fnc(xfer, jingle_file_transfer_ibb_write);
+	purple_xfer_start(xfer, -1, NULL, 0);
+	purple_xfer_prpl_ready(xfer);
+}
+
+static void
 jingle_file_transfer_add_ibb_session_to_transport(JabberStream *js,
 	JingleTransport *transport, JingleContent *content, const gchar *jid)
 {
@@ -300,6 +311,8 @@ jingle_file_transfer_add_ibb_session_to_
 			jingle_file_transfer_ibb_data_sent_callback);
 		jingle_ibb_set_error_callback(JINGLE_IBB(transport),
 			jingle_file_transfer_ibb_error_callback);
+		jingle_ibb_set_opened_callback(JINGLE_IBB(transport),
+		    jingle_file_transfer_ibb_opened_callback);
 		JINGLE_FT(content)->priv->ibb_buffer = 
 			purple_circ_buffer_new(jingle_ibb_get_max_data_size(
 				JINGLE_IBB(transport)));
@@ -420,20 +433,21 @@ jingle_file_transfer_xfer_init(PurpleXfe
 		JingleTransport *transport;
 		gchar *jid = NULL, *me = NULL, *sid = NULL;
 		const gchar *transport_type = NULL;
-			
+
 		/* construct JID to send to */
 		JabberBuddy *jb = jabber_buddy_find(js, who, FALSE);
 		JabberBuddyResource *jbr;
-		
+
 		if (!jb) {
-			purple_debug_error("jingle-rtp", "Could not find Jabber buddy\n");
+			purple_debug_error("jingle-ft", "Could not find Jabber buddy\n");
 			return;
 		}
 		jbr = jabber_buddy_find_resource(jb, NULL);
 		if (!jbr) {
-			purple_debug_error("jingle-rtp", "Could not find buddy's resource\n");
+			purple_debug_error("jingle-ft", "Could not find buddy's resource\n");
+			return;
 		}
-		
+
 		if (purple_xfer_get_size(xfer) <= JINGLE_FT_IBB_THRESHOLD &&
 			jabber_resource_has_capability(jbr, JINGLE_TRANSPORT_IBB)) {
 			purple_debug_info("jingle-ft",
@@ -454,7 +468,7 @@ jingle_file_transfer_xfer_init(PurpleXfe
 				"(this shouldn't happen).");
 			return;
 		}
-		
+
 		if ((strchr(who, '/') == NULL) && jbr && (jbr->name != NULL)) {
 			jid = g_strdup_printf("%s/%s", who, jbr->name);
 		} else {
@@ -468,7 +482,7 @@ jingle_file_transfer_xfer_init(PurpleXfe
 		session = jingle_session_create(js, sid, me, jid, TRUE);
 		g_free(sid);
 		g_free(me);
-		
+
 		/* add the content */
 		transport = jingle_transport_create(transport_type);
 		content = jingle_content_create(JINGLE_APP_FT, "initiator", "session",
@@ -484,7 +498,7 @@ jingle_file_transfer_xfer_init(PurpleXfe
 		purple_debug_info("jingle-ft", "setting content %p on xfer %p\n", 
 			content, xfer);
 		xfer->data = content;
-		
+
 		if (JINGLE_IS_IBB(transport)) {
 			/* if it's IBB, send session-intitate directly */
 			jabber_iq_send(jingle_session_to_packet(session, 
@@ -526,10 +540,10 @@ jingle_file_transfer_xfer_init(PurpleXfe
 				jingle_file_transfer_ibb_data_recv_callback);
 			jingle_ibb_set_error_callback(ibb,
 				jingle_file_transfer_ibb_error_callback);
-	
+
 			/* setup read function */
 			purple_xfer_set_read_fnc(xfer, jingle_file_transfer_ibb_read);
-			
+
 			/* start the transfer */
 			purple_xfer_start(xfer, -1, NULL, 0);
 		} else if (JINGLE_IS_S5B(transport)) {
@@ -592,11 +606,8 @@ jingle_file_transfer_terminate_cb(Jabber
                                 JabberIqType type, const char *id,
                                 xmlnode *packet, gpointer data)
 {
-	PurpleXfer *xfer = (PurpleXfer *) data;
-	JingleContent *content = (JingleContent *) xfer->data;
-	JingleSession *session = jingle_content_get_session(content);
+	JingleSession *session = (JingleSession *) data;
 
-	JINGLE_FT(content)->priv->xfer = NULL;
 	g_object_unref(session);
 	g_object_unref(session);
 }
@@ -611,9 +622,10 @@ jingle_file_transfer_cancel_recv(PurpleX
 		JingleTransport *transport = jingle_content_get_transport(content);
 		JabberIq *terminate = 
 			jingle_session_to_packet(session, JINGLE_SESSION_TERMINATE);
+		
+		jabber_iq_set_callback(terminate, jingle_file_transfer_terminate_cb,
+		    session);
 
-		jabber_iq_set_callback(terminate, jingle_file_transfer_terminate_cb, xfer);
-		
 		if (JINGLE_IS_S5B(transport) 
 		    && !jingle_s5b_is_connected(JINGLE_S5B(transport))) {
 			jingle_s5b_stop_connection_attempts(JINGLE_S5B(transport));
@@ -641,7 +653,7 @@ jingle_file_transfer_xfer_end(PurpleXfer
 				jingle_session_terminate_packet(session, "success");
 
 			jabber_iq_set_callback(terminate, jingle_file_transfer_terminate_cb,
-			    xfer);
+			    session);
 			jabber_iq_send(terminate);
 			g_object_unref(session);
 		} else {
@@ -694,14 +706,12 @@ jingle_file_transfer_handle_action_inter
 			
 			/* do stuff here, start the transfer, etc... */
 			if (JINGLE_IS_IBB(transport)) {
+				jingle_ibb_set_opened_callback(JINGLE_IBB(transport),
+				    jingle_file_transfer_ibb_opened_callback);
 				if (xmltransport) {
 					jingle_ibb_handle_transport_accept(JINGLE_IBB(transport),
 					    xmltransport);
 				}
-				/* send first data */
-				purple_xfer_set_write_fnc(xfer, jingle_file_transfer_ibb_write);
-				purple_xfer_start(xfer, -1, NULL, 0);
-				purple_xfer_prpl_ready(xfer);
 			} else if (JINGLE_IS_S5B(transport)) {
 				/* add the receiver's streamhost candidates (this must be done 
 					here since parse is not called on the existing transport */
@@ -744,6 +754,9 @@ jingle_file_transfer_handle_action_inter
 						jingle_file_transfer_cancel_recv);
 					purple_xfer_set_request_denied_fnc(xfer,
 					    jingle_file_transfer_request_denied);
+					purple_debug_info("jingle-ft", 
+					    "setting content %p on xfer %p\n", content, xfer);
+					xfer->data = content;
 					purple_xfer_request(xfer);
 				} else {
 					/* TODO: set a reason code */
@@ -765,11 +778,6 @@ jingle_file_transfer_handle_action_inter
 					jingle_ibb_create_session(ibb, content, sid, who);
 					JINGLE_FT(content)->priv->ibb_buffer =
 						purple_circ_buffer_new(jingle_ibb_get_block_size(ibb));
-
-					if (xmltransport) {
-						jingle_ibb_handle_session_accept(JINGLE_IBB(transport),
-							xmltransport);
-					}
 	
 					purple_xfer_set_read_fnc(xfer, 
 						jingle_file_transfer_ibb_read);
@@ -846,14 +854,13 @@ jingle_file_transfer_handle_action_inter
 				"got transport-accept transport %p\n", transport);
 			
 			if (JINGLE_IS_IBB(transport)) {
-				purple_xfer_set_write_fnc(xfer, jingle_file_transfer_ibb_write);
-
 				if (xmltransport) {
 					jingle_ibb_handle_transport_accept(JINGLE_IBB(transport),
 					    xmltransport);
 				}
 				
 				/* send first data */
+				purple_xfer_set_write_fnc(xfer, jingle_file_transfer_ibb_write);
 				purple_xfer_start(xfer, -1, NULL, 0);
 				purple_xfer_prpl_ready(xfer);
 			}
============================================================
--- libpurple/protocols/jabber/jingle/ibbs.c	49117181bc65e3defa8b134e2aefa0b46066d121
+++ libpurple/protocols/jabber/jingle/ibbs.c	0c6d3eb8b61e8cfa4ee5e9b15dfa32a58a8d020c
@@ -29,6 +29,7 @@ struct _JingleIBBPrivate {
 	JingleIBBSentCallback *sent_cb;
 	JingleIBBDataCallback *recv_cb;
 	JingleIBBErrorCallback *error_cb;
+	JingleIBBOpenedCallback *opened_cb;
 	guint block_size;
 };
 
@@ -111,9 +112,6 @@ jingle_ibb_finalize (GObject *ibb)
 		ibb);
 	
 	if (priv->session) {
-		/* set the session's state to closed, this will prevent IBB from
-		 sending <close/>, since terminate is handled by jingle */
-		jabber_ibb_session_set_state(priv->session, JABBER_IBB_SESSION_CLOSED);
 		jabber_ibb_session_destroy(priv->session);
 		priv->session = NULL;
 	}
@@ -182,7 +180,8 @@ jingle_ibb_to_xml_internal(JingleTranspo
 	purple_debug_info("jingle", "jingle_ibb_to_xml_internal\n");
 
 	if (action == JINGLE_SESSION_INITIATE || action == JINGLE_TRANSPORT_INFO ||
-		action == JINGLE_TRANSPORT_REPLACE || action == JINGLE_TRANSPORT_ACCEPT) {
+		action == JINGLE_TRANSPORT_REPLACE || action == JINGLE_TRANSPORT_ACCEPT ||
+	    action == JINGLE_SESSION_ACCEPT) {
 		JingleIBBPrivate *priv = JINGLE_IBB_GET_PRIVATE(transport);
 		if (priv->session) {
 			gchar *block_size = 
@@ -260,6 +259,26 @@ jingle_ibb_error_callback(JabberIBBSessi
 	}
 }
 
+static void
+jingle_ibb_opened_callback(JabberIBBSession *sess)
+{
+	JingleContent *content = 
+		(JingleContent *) jabber_ibb_session_get_user_data(sess);
+	
+	if (content) {
+		JingleTransport *transport = jingle_content_get_transport(content);
+
+		JingleIBBOpenedCallback *opened_cb = 
+				JINGLE_IBB_GET_PRIVATE(JINGLE_IBB(transport))->opened_cb;
+			
+		if (opened_cb) {
+			opened_cb(content);
+		}
+		g_object_unref(transport);
+	}
+}
+
+
 void
 jingle_ibb_create_session(JingleIBB *ibb, JingleContent *content, 
 	const gchar *sid, const gchar *who)
@@ -278,21 +297,13 @@ jingle_ibb_create_session(JingleIBB *ibb
 		jabber_ibb_session_set_block_size(session, ibb->priv->block_size);
 	}
 
-	if (!jingle_session_is_initiator(sess)) {
-		/* we will set the IBB session to "open" immediatly, since the Jingle
-	 	negotiation defines the "open" state
-		 Note: for the the initiator, this is done when getting a 
-		 session-accept or transport-accept, since the block-size might get
-		 changed by request from the receiver */
-		jabber_ibb_session_set_state(session, JABBER_IBB_SESSION_OPENED);
-	}
-	
 	/* set callbacks... */
 	jabber_ibb_session_set_data_sent_callback(session, 
 		jingle_ibb_data_sent_callback);
 	jabber_ibb_session_set_data_received_callback(session,
 		jingle_ibb_data_recv_callback);
 	jabber_ibb_session_set_error_callback(session, jingle_ibb_error_callback);
+	jabber_ibb_session_set_opened_callback(session, jingle_ibb_opened_callback);
 	purple_debug_info("jingle-ibb", "setting session %p on transport %p\n",
 		session, ibb);
 	JINGLE_IBB_GET_PRIVATE(ibb)->session = session;
@@ -318,6 +329,12 @@ jingle_ibb_set_error_callback(JingleIBB 
 	JINGLE_IBB_GET_PRIVATE(ibb)->error_cb = cb;
 }
 
+void 
+jingle_ibb_set_opened_callback(JingleIBB *ibb, JingleIBBOpenedCallback *cb)
+{
+	JINGLE_IBB_GET_PRIVATE(ibb)->opened_cb = cb;
+}
+
 void
 jingle_ibb_send_data(JingleIBB *ibb, gconstpointer data, gsize size)
 {
@@ -363,7 +380,7 @@ jingle_ibb_handle_session_accept(JingleI
 		jingle_ibb_set_block_size(ibb, atoi(block_size));
 	}
 
-	jabber_ibb_session_set_state(ibb->priv->session, JABBER_IBB_SESSION_OPENED);	
+	jabber_ibb_session_open(ibb->priv->session);
 }
 
 void
@@ -375,5 +392,53 @@ jingle_ibb_handle_transport_accept(Jingl
 		jingle_ibb_set_block_size(ibb, atoi(block_size));
 	}
 
-	jabber_ibb_session_set_state(ibb->priv->session, JABBER_IBB_SESSION_OPENED);
+	jabber_ibb_session_open(ibb->priv->session);
 }
+
+
+static gboolean
+jingle_ibb_open_handler(JabberStream *js, const char *from,
+	const char *id, xmlnode *open)
+{
+	const gchar *sid = xmlnode_get_attrib(open, "sid");
+	GList *sessions = jingle_session_get_all(js);
+	GList *iter;
+	
+	for (iter = sessions ; iter ; iter = g_list_next(iter)) {
+		JingleSession *session = (JingleSession *) sessions->data;
+		/* check if there is an accepted transport of type IBB */
+		GList *contents = jingle_session_get_contents(session);
+		gboolean found_ibb = FALSE;
+		
+		for (; contents ; contents = g_list_next(contents)) {
+			JingleContent *content = (JingleContent *) contents->data;
+			JingleTransport *transport = jingle_content_get_transport(content);
+
+			if (JINGLE_IS_IBB(transport)) {
+				found_ibb = TRUE;
+			}
+
+			g_object_unref(transport);
+		}
+
+		g_list_free(sessions);
+		
+		/* we don't not need to set up any callbacks in this handler, since
+		 that is handled by jingle negotiation */
+		return found_ibb;
+	}
+
+	return FALSE;
+}
+
+void
+jingle_ibbs_init(void)
+{
+	jabber_ibb_register_open_handler(jingle_ibb_open_handler);
+}
+
+void
+jingle_ibbs_unint(void)
+{
+	jabber_ibb_unregister_open_handler(jingle_ibb_open_handler);
+}
============================================================
--- libpurple/protocols/jabber/jingle/ibbs.h	982909d114e53b367770eeff8284a8536db3a5f4
+++ libpurple/protocols/jabber/jingle/ibbs.h	10d88ac3ac93f227d95009440026b1db802d3503
@@ -73,13 +73,15 @@ typedef void (JingleIBBErrorCallback)(Ji
 typedef void (JingleIBBSentCallback)(JingleContent *);
 typedef void (JingleIBBDataCallback)(JingleContent *, gconstpointer, gsize); 
 typedef void (JingleIBBErrorCallback)(JingleContent *);
-
+typedef void (JingleIBBOpenedCallback)(JingleContent *);
+	
 void jingle_ibb_set_data_sent_callback(JingleIBB *ibb, 
 	JingleIBBSentCallback *cb);
 void jingle_ibb_set_data_received_callback(JingleIBB *ibb,
 	JingleIBBDataCallback *cb);
 void jingle_ibb_set_error_callback(JingleIBB *ibb, JingleIBBErrorCallback *cb);
-
+void jingle_ibb_set_opened_callback(JingleIBB *ibb, JingleIBBOpenedCallback *cb);
+	
 /* send a packet of data through the transport */
 void jingle_ibb_send_data(JingleIBB *ibb, gconstpointer data, gsize size);
 
@@ -92,6 +94,9 @@ void jingle_ibb_handle_transport_accept(
 void jingle_ibb_handle_session_accept(JingleIBB *ibb, xmlnode *transport);
 void jingle_ibb_handle_transport_accept(JingleIBB *ibb, xmlnode *transport);
 
+void jingle_ibbs_init(void);
+void jingle_ibbs_unint(void);
+	
 #ifdef __cplusplus
 }
 #endif
============================================================
--- libpurple/protocols/jabber/jingle/jingle.h	0a9892f983d8c5db376b6fc9d9aa6cf80cd07792
+++ libpurple/protocols/jabber/jingle/jingle.h	4eb5ec8dc12d402ada0fba993e07c938b850c9a7
@@ -45,7 +45,7 @@ extern "C" {
 #define JINGLE_APP_XML "urn:xmpp:tmp:jingle:apps:xmlstream"
 #define JINGLE_DTMF "urn:xmpp:jingle:dtmf:0"
 #define JINGLE_TRANSPORT_S5B "urn:xmpp:jingle:transports:s5b:1"
-#define JINGLE_TRANSPORT_IBB "urn:xmpp:jingle:transports:ibb:0"
+#define JINGLE_TRANSPORT_IBB "urn:xmpp:jingle:transports:ibb:1"
 #define JINGLE_TRANSPORT_ICEUDP "urn:xmpp:jingle:transports:ice-udp:1"
 #define JINGLE_TRANSPORT_RAWUDP "urn:xmpp:jingle:transports:raw-udp:1"
 
============================================================
--- libpurple/protocols/jabber/jingle/session.c	0b6b01e0b1a4ceea7b447e8d19a85183223b707c
+++ libpurple/protocols/jabber/jingle/session.c	e1e7bdc109c1275d039ae218de06ec50af90b81b
@@ -398,6 +398,12 @@ jingle_session_find_by_jid(JabberStream 
 			find_by_jid_ghr, (gpointer)jid) : NULL; 
 }
 
+GList *
+jingle_session_get_all(JabberStream *js)
+{
+	return g_hash_table_get_values(js->sessions);
+}
+
 static xmlnode *
 jingle_add_jingle_packet(JingleSession *session,
 			 JabberIq *iq, JingleActionType action)
============================================================
--- libpurple/protocols/jabber/jingle/session.h	5016eb5f0a5e552a229e0c5bfac77fa67b7a8b78
+++ libpurple/protocols/jabber/jingle/session.h	5e44da16f142b24af4b632e0709a7e1d82644736
@@ -89,6 +89,8 @@ JingleSession *jingle_session_find_by_ji
 JingleSession *jingle_session_find_by_sid(JabberStream *js, const gchar *sid);
 JingleSession *jingle_session_find_by_jid(JabberStream *js, const gchar *jid);
 
+GList *jingle_session_get_all(JabberStream *js);
+	
 JabberIq *jingle_session_create_ack(JingleSession *session, const xmlnode *jingle);
 xmlnode *jingle_session_to_xml(JingleSession *session, xmlnode *parent, JingleActionType action);
 JabberIq *jingle_session_to_packet(JingleSession *session, JingleActionType action);


More information about the Commits mailing list