changeset 26399:85c571d11417

Stop sending multiple session-initiate packets.
author Mike Ruprecht <maiku@soc.pidgin.im>
date Fri, 20 Mar 2009 06:18:03 +0000
parents bd9fa96c47dc
children 007cd8dad384
files libpurple/protocols/jabber/jingle/rtp.c
diffstat 1 files changed, 29 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/jingle/rtp.c	Fri Mar 20 02:09:44 2009 +0000
+++ b/libpurple/protocols/jabber/jingle/rtp.c	Fri Mar 20 06:18:03 2009 +0000
@@ -335,15 +335,14 @@
 	}
 }
 
-static void jingle_rtp_send_initiate(JingleSession *session);
-static void jingle_rtp_send_accept(JingleSession *session);
+static void jingle_rtp_ready(JingleSession *session);
 
 static void
 jingle_rtp_accepted_cb(PurpleMedia *media, gchar *sid, gchar *name,
 		JingleSession *session)
 {
 	purple_debug_info("jingle-rtp", "jingle_rtp_accepted_cb\n");
-	jingle_rtp_send_accept(session);
+	jingle_rtp_ready(session);
 }
 
 static void
@@ -377,8 +376,7 @@
 	jingle_content_set_pending_transport(content, transport);
 	jingle_content_accept_transport(content);
 
-	jingle_rtp_send_initiate(session);
-	jingle_rtp_send_accept(session);
+	jingle_rtp_ready(session);
 }
 
 static void
@@ -387,8 +385,7 @@
 {
 	purple_debug_info("jingle-rtp", "jingle_rtp_codecs_changed_cb: "
 			"session_id: %s jingle_session: %p\n", sid, session);
-	jingle_rtp_send_initiate(session);
-	jingle_rtp_send_accept(session);
+	jingle_rtp_ready(session);
 }
 
 static void
@@ -453,35 +450,33 @@
 }
 
 static void
-jingle_rtp_send_initiate(JingleSession *session)
+jingle_rtp_ready(JingleSession *session)
 {
 	PurpleMedia *media = jingle_rtp_get_media(session);
 
-	if (jingle_session_is_initiator(session) == TRUE &&
+	if (purple_media_candidates_prepared(media, NULL, NULL) &&
 			purple_media_codecs_ready(media, NULL) &&
-			purple_media_candidates_prepared(media, NULL, NULL)) {
-		JabberIq *iq = jingle_session_to_packet(
-				session, JINGLE_SESSION_INITIATE);
-		jabber_iq_set_callback(iq,
-				jingle_rtp_initiate_ack_cb, session);
-		jabber_iq_send(iq);
-		g_signal_connect(G_OBJECT(media), "new-candidate",
-				G_CALLBACK(jingle_rtp_new_candidate_cb),
+			(jingle_session_is_initiator(session) == TRUE ||
+			purple_media_accepted(media, NULL, NULL))) {
+		if (jingle_session_is_initiator(session)) {
+			JabberIq *iq = jingle_session_to_packet(
+					session, JINGLE_SESSION_INITIATE);
+			jabber_iq_set_callback(iq,
+					jingle_rtp_initiate_ack_cb, session);
+			jabber_iq_send(iq);
+		} else {
+			jabber_iq_send(jingle_session_to_packet(session,
+					JINGLE_SESSION_ACCEPT));
+		}
+
+		g_signal_handlers_disconnect_by_func(G_OBJECT(media),
+				G_CALLBACK(jingle_rtp_accepted_cb), session);
+		g_signal_handlers_disconnect_by_func(G_OBJECT(media),
+				G_CALLBACK(jingle_rtp_candidates_prepared_cb),
 				session);
-	}
-}
-
-static void
-jingle_rtp_send_accept(JingleSession *session)
-{
-	PurpleMedia *media = jingle_rtp_get_media(session);
-
-	if (jingle_session_is_initiator(session) == FALSE &&
-			purple_media_codecs_ready(media, NULL) &&
-			purple_media_accepted(media, NULL, NULL) &&
-			purple_media_candidates_prepared(media, NULL, NULL)) {
-		jabber_iq_send(jingle_session_to_packet(session,
-				JINGLE_SESSION_ACCEPT));
+		g_signal_handlers_disconnect_by_func(G_OBJECT(media),
+				G_CALLBACK(jingle_rtp_codecs_changed_cb),
+				session);
 		g_signal_connect(G_OBJECT(media), "new-candidate",
 				G_CALLBACK(jingle_rtp_new_candidate_cb),
 				session);
@@ -508,8 +503,9 @@
 	purple_media_set_prpl_data(media, session);
 
 	/* connect callbacks */
-	g_signal_connect(G_OBJECT(media), "accepted",
-				 G_CALLBACK(jingle_rtp_accepted_cb), session);
+	if (jingle_session_is_initiator(session) == FALSE)
+		g_signal_connect(G_OBJECT(media), "accepted",
+				G_CALLBACK(jingle_rtp_accepted_cb), session);
 	g_signal_connect(G_OBJECT(media), "candidates-prepared",
 				 G_CALLBACK(jingle_rtp_candidates_prepared_cb), session);
 	g_signal_connect(G_OBJECT(media), "codecs-changed",