changeset 26284:4f47eeaa1414

Add functions for more easily creating session-terminate packets.
author Mike Ruprecht <maiku@soc.pidgin.im>
date Tue, 17 Mar 2009 04:40:25 +0000
parents abcc94ace5ea
children b1c4fcc5b814 3824cd706fa3
files libpurple/protocols/jabber/jingle/rtp.c libpurple/protocols/jabber/jingle/session.c libpurple/protocols/jabber/jingle/session.h
diffstat 3 files changed, 41 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/jingle/rtp.c	Tue Mar 17 02:48:43 2009 +0000
+++ b/libpurple/protocols/jabber/jingle/rtp.c	Tue Mar 17 04:40:25 2009 +0000
@@ -372,8 +372,8 @@
 	if ((type == PURPLE_MEDIA_STATE_CHANGED_REJECTED ||
 			type == PURPLE_MEDIA_STATE_CHANGED_HANGUP) &&
 			sid == NULL && name == NULL) {
-		jabber_iq_send(jingle_session_to_packet(session,
-				JINGLE_SESSION_TERMINATE));
+		jabber_iq_send(jingle_session_terminate_packet(
+				session, "success"));
 		g_object_unref(session);
 	}
 }
@@ -616,8 +616,8 @@
 
 			if (jingle_rtp_init_media(content) == FALSE) {
 				/* XXX: send error */
-				jabber_iq_send(jingle_session_to_packet(session,
-						 JINGLE_SESSION_TERMINATE));
+				jabber_iq_send(jingle_session_terminate_packet(
+						session, "general-error"));
 				g_object_unref(session);
 				break;
 			}
--- a/libpurple/protocols/jabber/jingle/session.c	Tue Mar 17 02:48:43 2009 +0000
+++ b/libpurple/protocols/jabber/jingle/session.c	Tue Mar 17 04:40:25 2009 +0000
@@ -590,3 +590,38 @@
 	session->priv->state = TRUE;
 }
 
+JabberIq *
+jingle_session_terminate_packet(JingleSession *session, const gchar *reason)
+{
+	JabberIq *iq = jingle_session_to_packet(session,
+			JINGLE_SESSION_TERMINATE);
+	xmlnode *jingle = xmlnode_get_child(iq->node, "jingle");
+
+	if (reason != NULL) {
+		JabberIq *reason_node;
+		reason_node = xmlnode_new_child(jingle, "reason");
+		xmlnode_new_child(reason_node, reason);
+	}
+	return iq;
+}
+
+JabberIq *
+jingle_session_redirect_packet(JingleSession *session, const gchar *sid)
+{
+	JabberIq *iq = jingle_session_terminate_packet(session,
+			"alternative-session");
+	xmlnode *alt_session;
+
+	if (sid == NULL)
+		return iq;
+
+	alt_session = xmlnode_get_child(iq->node,
+			"jingle/reason/alternative-session");
+
+	if (alt_session != NULL) {
+		xmlnode *sid_node = xmlnode_new_child(alt_session, "sid");
+		xmlnode_insert_data(sid_node, sid, -1);
+	}
+	return iq;
+}
+
--- a/libpurple/protocols/jabber/jingle/session.h	Tue Mar 17 02:48:43 2009 +0000
+++ b/libpurple/protocols/jabber/jingle/session.h	Tue Mar 17 04:40:25 2009 +0000
@@ -102,6 +102,8 @@
 void jingle_session_remove_pending_content(JingleSession *session, const gchar *name, const gchar *creator);
 void jingle_session_accept_content(JingleSession *session, const gchar *name, const gchar *creator);
 void jingle_session_accept_session(JingleSession *session);
+JabberIq *jingle_session_terminate_packet(JingleSession *session, const gchar *reason);
+JabberIq *jingle_session_redirect_packet(JingleSession *session, const gchar *sid);
 
 #ifdef __cplusplus
 }