changeset 25667:41d6d4217d21

Further decoupled Jingle code from jabber.c: * Removed unnecessary Jingle functions from the header * Moved JingleSession structure to jingle.c * Created functions to remove jabber.c's dependence on JingleSession: - jabber_jingle_session_terminate_session_media - jabber_jingle_session_terminate_sessions
author Mike Ruprecht <maiku@soc.pidgin.im>
date Mon, 02 Jun 2008 21:58:39 +0000
parents e73b03097664
children 2ebe89114923
files libpurple/protocols/jabber/jabber.c libpurple/protocols/jabber/jingle.c libpurple/protocols/jabber/jingle.h
diffstat 3 files changed, 69 insertions(+), 99 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/jabber.c	Mon Jun 02 20:59:20 2008 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Mon Jun 02 21:58:39 2008 +0000
@@ -1254,16 +1254,8 @@
 	JabberStream *js = gc->proto_data;
 
 #ifdef USE_VV
-	/* Close all of the open media sessions on this stream */
-	GList *values = g_hash_table_get_values(js->sessions);
-	GList *iter = values;
-
-	for (; iter; iter = iter->next) {
-		JingleSession *session = (JingleSession *)iter->data;
-		purple_media_hangup(session->media);
-	}
-
-	g_list_free(values);
+	/* Close all of the open Jingle sessions on this stream */
+	jabber_jingle_session_terminate_sessions(js);
 #endif
 
 	/* Don't perform any actions on the ssl connection
@@ -1889,19 +1881,12 @@
 	JabberID *jid;
 	JabberBuddy *jb;
 	JabberBuddyResource *jbr;
-#ifdef USE_VV
-	JingleSession *session;
-#endif
+
 	if(!(jid = jabber_id_new(who)))
 		return;
 
 #ifdef USE_VV
-	session = jabber_jingle_session_find_by_jid(js, who);
-
-	if (session) {
-		purple_media_hangup(session->media);
-	}
-
+	jabber_jingle_session_terminate_session_media(js, who);
 #endif
 	if((jb = jabber_buddy_find(js, who, TRUE)) &&
 			(jbr = jabber_buddy_find_resource(jb, jid->resource))) {
--- a/libpurple/protocols/jabber/jingle.c	Mon Jun 02 20:59:20 2008 +0000
+++ b/libpurple/protocols/jabber/jingle.c	Mon Jun 02 21:58:39 2008 +0000
@@ -31,6 +31,16 @@
 
 #include <gst/farsight/fs-candidate.h>
 
+typedef struct {
+	char *id;
+	JabberStream *js;
+	PurpleMedia *media;
+	char *remote_jid;
+	char *initiator;
+	gboolean is_initiator;
+	gboolean session_started;
+} JingleSession;
+
 static gboolean
 jabber_jingle_session_equal(gconstpointer a, gconstpointer b)
 {
@@ -69,13 +79,13 @@
 	return sess;
 }
 
-JabberStream *
+static JabberStream *
 jabber_jingle_session_get_js(const JingleSession *sess)
 {
 	return sess->js;
 }
 
-JingleSession *
+static JingleSession *
 jabber_jingle_session_create(JabberStream *js)
 {
 	JingleSession *sess = jabber_jingle_session_create_internal(js, NULL);
@@ -83,7 +93,7 @@
 	return sess;
 }
 
-JingleSession *
+static JingleSession *
 jabber_jingle_session_create_by_id(JabberStream *js, const char *id)
 {
 	JingleSession *sess = jabber_jingle_session_create_internal(js, id);
@@ -91,13 +101,13 @@
 	return sess;
 }
 
-const char *
+static const char *
 jabber_jingle_session_get_id(const JingleSession *sess)
 {
 	return sess->id;
 }
 
-void
+static void
 jabber_jingle_session_destroy(JingleSession *sess)
 {
 	g_hash_table_remove(sess->js->sessions, sess->id);
@@ -106,7 +116,7 @@
 	g_free(sess);
 }
 
-JingleSession *
+static JingleSession *
 jabber_jingle_session_find_by_id(JabberStream *js, const char *id)
 {
 	purple_debug_info("jingle", "find_by_id %s\n", id);
@@ -117,7 +127,8 @@
 	return (JingleSession *) g_hash_table_lookup(js->sessions, id);
 }
 
-JingleSession *jabber_jingle_session_find_by_jid(JabberStream *js, const char *jid)
+static JingleSession *
+jabber_jingle_session_find_by_jid(JabberStream *js, const char *jid)
 {
 	GList *values = g_hash_table_get_values(js->sessions);
 	GList *iter = values;
@@ -139,7 +150,7 @@
 	return NULL;	
 }
 
-GList *
+static GList *
 jabber_jingle_get_codecs(const xmlnode *description)
 {
 	GList *codecs = NULL;
@@ -162,7 +173,7 @@
 	return codecs;
 }
 
-GList *
+static GList *
 jabber_jingle_get_candidates(const xmlnode *transport)
 {
 	GList *candidates = NULL;
@@ -192,45 +203,45 @@
 	return candidates;
 }
 
-PurpleMedia *
+static PurpleMedia *
 jabber_jingle_session_get_media(const JingleSession *sess)
 {
 	return sess->media;
 }
 
-void
+static void
 jabber_jingle_session_set_media(JingleSession *sess, PurpleMedia *media)
 {
 	sess->media = media;
 }
 
-const char *
+static const char *
 jabber_jingle_session_get_remote_jid(const JingleSession *sess)
 {
 	return sess->remote_jid;
 }
 
-void
+static void
 jabber_jingle_session_set_remote_jid(JingleSession *sess, 
 									 const char *remote_jid)
 {
 	sess->remote_jid = strdup(remote_jid);
 }
 
-const char *
+static const char *
 jabber_jingle_session_get_initiator(const JingleSession *sess)
 {
 	return sess->initiator;
 }
 
-void
+static void
 jabber_jingle_session_set_initiator(JingleSession *sess,
 									const char *initiator)
 {
 	sess->initiator = g_strdup(initiator);
 }
 
-gboolean
+static gboolean
 jabber_jingle_session_is_initiator(const JingleSession *sess)
 {
 	return sess->is_initiator;
@@ -254,7 +265,7 @@
 	return jingle;
 }
 
-xmlnode *
+static xmlnode *
 jabber_jingle_session_create_terminate(const JingleSession *sess,
 									   const char *reasoncode,
 									   const char *reasontext)
@@ -270,7 +281,7 @@
 	return jingle;
 }
 
-xmlnode *
+static xmlnode *
 jabber_jingle_session_create_description(const JingleSession *sess)
 {
     GList *codecs = purple_media_get_local_audio_codecs(sess->media);
@@ -372,7 +383,7 @@
 /* split into two separate methods, one to generate session-accept
 	(includes codecs) and one to generate transport-info (includes transports
 	candidates) */
-xmlnode *
+static xmlnode *
 jabber_jingle_session_create_session_accept(const JingleSession *sess)
 {
 	xmlnode *jingle = 
@@ -401,8 +412,7 @@
 	return jingle;
 }
 
-
-xmlnode *
+static xmlnode *
 jabber_jingle_session_create_transport_info(const JingleSession *sess)
 {
 	xmlnode *jingle = 
@@ -435,7 +445,7 @@
 	return jingle;
 }
 
-xmlnode *
+static xmlnode *
 jabber_jingle_session_create_content_replace(const JingleSession *sess,
 					     FsCandidate *native_candidate,
 					     FsCandidate *remote_candidate)
@@ -470,7 +480,7 @@
 	return jingle;
 }
 
-xmlnode *
+static xmlnode *
 jabber_jingle_session_create_content_accept(const JingleSession *sess)
 {
 	xmlnode *jingle = 
@@ -750,6 +760,30 @@
 }
 
 void
+jabber_jingle_session_terminate_session_media(JabberStream *js, const gchar *who)
+{
+	JingleSession *session;
+
+	session = jabber_jingle_session_find_by_jid(js, who);
+
+	if (session)
+		purple_media_hangup(session->media);
+}
+
+void
+jabber_jingle_session_terminate_sessions(JabberStream *js)
+{
+	GList *values = g_hash_table_get_values(js->sessions);
+
+	for (; values; values = values->next) {
+		JingleSession *session = (JingleSession *)values->data;
+		purple_media_hangup(session->media);
+	}
+
+	g_list_free(values);
+}
+
+void
 jabber_jingle_session_handle_content_replace(JabberStream *js, xmlnode *packet)
 {
 	xmlnode *jingle = xmlnode_get_child(packet, "jingle");
--- a/libpurple/protocols/jabber/jingle.h	Mon Jun 02 20:59:20 2008 +0000
+++ b/libpurple/protocols/jabber/jingle.h	Mon Jun 02 21:58:39 2008 +0000
@@ -24,71 +24,22 @@
 #include <glib.h>
 #include <glib-object.h>
 
+/*
+ * When Jingle content types other than voice and video are implemented,
+ * this #ifdef others surrounding Jingle code should be changed to just
+ * be around the voice and video specific parts.
+ */
 #ifdef USE_VV
 
 G_BEGIN_DECLS
 
-typedef struct {
-	char *id;
-	JabberStream *js;
-	PurpleMedia *media;
-	char *remote_jid;
-	char *initiator;
-	gboolean is_initiator;
-	gboolean session_started;
-} JingleSession;
-
-JingleSession *jabber_jingle_session_create(JabberStream *js);
-JingleSession *jabber_jingle_session_create_by_id(JabberStream *js, 
-												  const char *id);
-
-const char *jabber_jingle_session_get_id(const JingleSession *sess);
-JabberStream *jabber_jingle_session_get_js(const JingleSession *sess);
-
-void jabber_jingle_session_destroy(JingleSession *sess);
-
-JingleSession *jabber_jingle_session_find_by_id(JabberStream *js, const char *id);
-JingleSession *jabber_jingle_session_find_by_jid(JabberStream *js, const char *jid);
-
-PurpleMedia *jabber_jingle_session_get_media(const JingleSession *sess);
-void jabber_jingle_session_set_media(JingleSession *sess, PurpleMedia *media);
-
-const char *jabber_jingle_session_get_remote_jid(const JingleSession *sess);
-
-gboolean jabber_jingle_session_is_initiator(const JingleSession *sess);
-
-void jabber_jingle_session_set_remote_jid(JingleSession *sess, 
-										  const char *remote_jid);
-
-const char *jabber_jingle_session_get_initiator(const JingleSession *sess);
-void jabber_jingle_session_set_initiator(JingleSession *sess, 
-										 const char *initiator);
-
-xmlnode *jabber_jingle_session_create_terminate(const JingleSession *sess,
-												const char *reasoncode,
-												const char *reasontext);
-xmlnode *jabber_jingle_session_create_session_accept(const JingleSession *sess);
-xmlnode *jabber_jingle_session_create_transport_info(const JingleSession *sess);
-xmlnode *jabber_jingle_session_create_content_replace(const JingleSession *sess,
-						      FsCandidate *native_candidate,
-						      FsCandidate *remote_candidate);
-xmlnode *jabber_jingle_session_create_content_accept(const JingleSession *sess);
-xmlnode *jabber_jingle_session_create_description(const JingleSession *sess);
-
-/**
- * Gets a list of Farsight codecs from a Jingle <description> tag
- *
- * @param description
- * @return A GList of FarsightCodecS
-*/
-GList *jabber_jingle_get_codecs(const xmlnode *description);
-
-GList *jabber_jingle_get_candidates(const xmlnode *transport);
-
 PurpleMedia *jabber_jingle_session_initiate_media(PurpleConnection *gc,
 						  const char *who,
 						  PurpleMediaStreamType type);
 
+void jabber_jingle_session_terminate_session_media(JabberStream *js, const gchar *who);
+void jabber_jingle_session_terminate_sessions(JabberStream *js);
+
 /* Jingle message handlers */
 void jabber_jingle_session_handle_content_replace(JabberStream *js, xmlnode *packet);
 void jabber_jingle_session_handle_session_accept(JabberStream *js, xmlnode *packet);