changeset 26124:f10034e0321b

Get rid of the medias variable in JabberStream.
author Mike Ruprecht <maiku@soc.pidgin.im>
date Wed, 25 Feb 2009 03:48:34 +0000
parents 75a02ffb0139
children a773b465935e
files libpurple/protocols/jabber/jabber.h libpurple/protocols/jabber/jingle/rtp.c
diffstat 2 files changed, 14 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/jabber.h	Wed Feb 25 03:28:27 2009 +0000
+++ b/libpurple/protocols/jabber/jabber.h	Wed Feb 25 03:48:34 2009 +0000
@@ -248,9 +248,6 @@
 
 	/* keep a hash table of JingleSessions */
 	GHashTable *sessions;
-#ifdef USE_VV
-	GHashTable *medias;
-#endif
 
 	/* maybe this should only be present when USE_VV? */
 	gchar *stun_ip;
--- a/libpurple/protocols/jabber/jingle/rtp.c	Wed Feb 25 03:28:27 2009 +0000
+++ b/libpurple/protocols/jabber/jingle/rtp.c	Wed Feb 25 03:48:34 2009 +0000
@@ -176,11 +176,20 @@
 jingle_rtp_get_media(JingleSession *session)
 {
 	JabberStream *js = jingle_session_get_js(session);
-	gchar *sid = jingle_session_get_sid(session);
+	PurpleMedia *media = NULL;
+	GList *iter = purple_media_manager_get_media_by_connection(
+			purple_media_manager_get(), js->gc);
 
-	PurpleMedia *media = (PurpleMedia *) (js->medias) ?
-			  g_hash_table_lookup(js->medias, sid) : NULL;
-	g_free(sid);
+	for (; iter; iter = g_list_delete_link(iter, iter)) {
+		JingleSession *media_session =
+				purple_media_get_prpl_data(iter->data);
+		if (media_session == session) {
+			media = iter->data;
+			break;
+		}
+	}
+	if (iter != NULL)
+		g_list_free(iter);
 
 	return media;
 }
@@ -305,11 +314,7 @@
 
 	if (!strcmp(xmlnode_get_attrib(packet, "type"), "error") ||
 			xmlnode_get_child(packet, "error")) {
-		gchar *sid = jingle_session_get_sid(session);
 		purple_media_end(jingle_rtp_get_media(session), NULL, NULL);
-		g_hash_table_remove(jingle_session_get_js(
-				session)->medias, sid);
-		g_free(sid);
 		g_object_unref(session);
 		return;
 	}
@@ -367,11 +372,8 @@
 	if ((type == PURPLE_MEDIA_STATE_CHANGED_REJECTED ||
 			type == PURPLE_MEDIA_STATE_CHANGED_HANGUP) &&
 			sid == NULL && name == NULL) {
-		gchar *sid = jingle_session_get_sid(session);
 		jabber_iq_send(jingle_session_to_packet(session,
 				JINGLE_SESSION_TERMINATE));
-		g_hash_table_remove(jingle_session_get_js(session)->medias, sid);
-		g_free(sid);
 		g_object_unref(session);
 	}
 }
@@ -382,7 +384,6 @@
 	JingleSession *session = jingle_content_get_session(content);
 	JabberStream *js = jingle_session_get_js(session);
 	gchar *remote_jid = jingle_session_get_remote_jid(session);
-	gchar *sid = jingle_session_get_sid(session);
 
 	PurpleMedia *media = purple_media_manager_create_media(purple_media_manager_get(), 
 						  js->gc, "fsrtpconference", remote_jid,
@@ -394,13 +395,7 @@
 		return NULL;
 	}
 
-	/* insert it into the hash table */
-	if (!js->medias) {
-		purple_debug_info("jingle-rtp", "Creating hash table for media\n");
-		js->medias = g_hash_table_new(g_str_hash, g_str_equal);
-	}
-	purple_debug_info("jingle-rtp", "inserting media with sid: %s into table\n", sid);
-	g_hash_table_insert(js->medias, sid, media);
+	purple_media_set_prpl_data(media, session);
 
 	/* connect callbacks */
 	g_signal_connect(G_OBJECT(media), "accepted",
@@ -646,11 +641,7 @@
 			PurpleMedia *media = jingle_rtp_get_media(session);
 
 			if (media != NULL) {
-				gchar *sid = jingle_session_get_sid(session);
 				purple_media_end(media, NULL, NULL);
-				g_hash_table_remove(jingle_session_get_js(
-						session)->medias, sid);
-				g_free(sid);
 			}
 
 			g_object_unref(session);