changeset 25695:13936e4405b7

Added better Farsight error handling.
author Mike Ruprecht <maiku@soc.pidgin.im>
date Fri, 27 Jun 2008 21:39:56 +0000
parents 72e738dac5f7
children 86f05fa8a90a
files libpurple/media.c libpurple/media.h libpurple/protocols/jabber/jingle.c pidgin/gtkconv.c
diffstat 4 files changed, 74 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/media.c	Fri Jun 27 18:44:49 2008 +0000
+++ b/libpurple/media.c	Fri Jun 27 21:39:56 2008 +0000
@@ -379,15 +379,30 @@
 	g_hash_table_insert(media->priv->sessions, g_strdup(session->id), session);
 }
 
+static gboolean
+purple_media_remove_session(PurpleMedia *media, PurpleMediaSession *session)
+{
+	return g_hash_table_remove(media->priv->sessions, session->id);
+}
+
 static FsParticipant *
 purple_media_add_participant(PurpleMedia *media, const gchar *name)
 {
 	FsParticipant *participant = purple_media_get_participant(media, name);
+	GError *err = NULL;
 
 	if (participant)
 		return participant;
 
-	participant = fs_conference_new_participant(media->priv->conference, g_strdup(name), NULL);
+	participant = fs_conference_new_participant(media->priv->conference,
+						    g_strdup(name), &err);
+
+	if (err) {
+		purple_debug_error("media", "Error creating participant: %s\n",
+				   err->message);
+		g_error_free(err);
+		return NULL;
+	}
 
 	if (!media->priv->participants) {
 		purple_debug_info("media", "Creating hash table for participants\n");
@@ -988,13 +1003,31 @@
 		purple_media_add_session(media, session);
 	}
 
-	participant = purple_media_add_participant(media, who);
+	if (!(participant = purple_media_add_participant(media, who))) {
+		purple_media_remove_session(media, session);
+		g_free(session);
+		return FALSE;
+	}
 
 	stream = purple_media_session_get_stream(session, who);
 
 	if (!stream) {
+		GError *err = NULL;
+
 		stream = fs_session_new_stream(session->session, participant, 
-					       type_direction, transmitter, 0, NULL, NULL);
+					       type_direction, transmitter, 0,
+					       NULL, &err);
+
+		if (err) {
+			purple_debug_error("media", "Error creating stream: %s\n",
+					   err->message);
+			g_error_free(err);
+			g_object_unref(participant);
+			purple_media_remove_session(media, session);
+			g_free(session);
+			return FALSE;
+		}
+
 		purple_media_insert_stream(session, who, stream);
 		/* callback for new local candidate (new local candidate retreived) */
 		g_signal_connect(G_OBJECT(stream),
@@ -1091,8 +1124,16 @@
 	PurpleMediaSession *session = purple_media_get_session(media, sess_id);
 	FsStream *stream = purple_media_session_get_stream(session, name);
 	GList *candidates = remote_candidates;
-	for (; candidates; candidates = candidates->next)
-		fs_stream_add_remote_candidate(stream, candidates->data, NULL);
+	for (; candidates; candidates = candidates->next) {
+		GError *err = NULL;
+		fs_stream_add_remote_candidate(stream, candidates->data, &err);
+
+		if (err) {
+			purple_debug_error("media", "Error adding remote candidate: %s\n",
+					   err->message);
+			g_error_free(err);
+		}
+	}
 }
 
 FsCandidate *
@@ -1109,12 +1150,22 @@
 	return session->remote_candidate;
 }
 
-void
+gboolean
 purple_media_set_remote_codecs(PurpleMedia *media, const gchar *sess_id, const gchar *name, GList *codecs)
 {
 	PurpleMediaSession *session = purple_media_get_session(media, sess_id);
 	FsStream *stream = purple_media_session_get_stream(session, name);
-	fs_stream_set_remote_codecs(stream, codecs, NULL);
+	GError *err = NULL;
+
+	fs_stream_set_remote_codecs(stream, codecs, &err);
+
+	if (err) {
+		purple_debug_error("media", "Error setting remote codecs: %s\n",
+				   err->message);
+		g_error_free(err);
+		return FALSE;
+	}
+	return TRUE;
 }
 
 gboolean
--- a/libpurple/media.h	Fri Jun 27 18:44:49 2008 +0000
+++ b/libpurple/media.h	Fri Jun 27 21:39:56 2008 +0000
@@ -134,7 +134,8 @@
 GList *purple_media_get_local_candidates(PurpleMedia *media, const gchar *sess_id, const gchar *name);
 FsCandidate *purple_media_get_local_candidate(PurpleMedia *media, const gchar *sess_id, const gchar *name);
 FsCandidate *purple_media_get_remote_candidate(PurpleMedia *media, const gchar *sess_id, const gchar *name);
-void purple_media_set_remote_codecs(PurpleMedia *media, const gchar *sess_id, const gchar *name, GList *codecs);
+gboolean purple_media_set_remote_codecs(PurpleMedia *media, const gchar *sess_id,
+					const gchar *name, GList *codecs);
 
 gboolean purple_media_candidates_prepared(PurpleMedia *media, const gchar *name);
 
--- a/libpurple/protocols/jabber/jingle.c	Fri Jun 27 18:44:49 2008 +0000
+++ b/libpurple/protocols/jabber/jingle.c	Fri Jun 27 21:39:56 2008 +0000
@@ -253,7 +253,9 @@
 	GList *contents = g_hash_table_get_values(sess->contents);
 	g_hash_table_remove(sess->js->sessions, sess->id);
 	g_free(sess->id);
-	g_object_unref(sess->media);
+
+	if (sess->media)
+		g_object_unref(sess->media);
 
 	for (; contents; contents = contents->next)
 		jabber_jingle_session_destroy_content(contents->data);
@@ -1187,10 +1189,13 @@
 
 		purple_debug_info("jingle", "Setting remote codecs on stream\n");
 
-		purple_media_set_remote_codecs(session->media,
-					       xmlnode_get_attrib(content, "name"),
-					       jabber_jingle_session_get_remote_jid(session),
-					       remote_codecs);
+		if (!purple_media_set_remote_codecs(session->media,
+						    xmlnode_get_attrib(content, "name"),
+						    jabber_jingle_session_get_remote_jid(session),
+						    remote_codecs)) {
+			purple_media_reject(jabber_jingle_session_get_media(session));
+			return;
+		}
 
 		codec_intersection = purple_media_get_negotiated_codecs(session->media,
 									xmlnode_get_attrib(content, "name"));
--- a/pidgin/gtkconv.c	Fri Jun 27 18:44:49 2008 +0000
+++ b/pidgin/gtkconv.c	Fri Jun 27 21:39:56 2008 +0000
@@ -7707,7 +7707,8 @@
 				    purple_conversation_get_name(conv),
 				    PURPLE_MEDIA_VIDEO);
 
-	purple_media_wait(media);
+	if (media)
+		purple_media_wait(media);
 }
 
 static void
@@ -7722,7 +7723,8 @@
 				    purple_conversation_get_name(conv),
 				    PURPLE_MEDIA_AUDIO | PURPLE_MEDIA_VIDEO);
 
-	purple_media_wait(media);
+	if (media)
+		purple_media_wait(media);
 }
 
 static void