changeset 25664:d0ac3c438b71

Check remote JID's capabilities for audio and video XEP support.
author Mike Ruprecht <maiku@soc.pidgin.im>
date Sat, 31 May 2008 20:15:34 +0000
parents de644f7e3958
children 1f085713c281
files libpurple/protocols/jabber/buddy.c libpurple/protocols/jabber/buddy.h libpurple/protocols/jabber/disco.c libpurple/protocols/jabber/jabber.c
diffstat 4 files changed, 65 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/buddy.c	Sat May 31 06:45:42 2008 +0000
+++ b/libpurple/protocols/jabber/buddy.c	Sat May 31 20:15:34 2008 +0000
@@ -2491,5 +2491,30 @@
 			js);
 }
 
+gboolean
+jabber_buddy_has_capability(JabberBuddy *jb, const gchar *cap)
+{
+	JabberBuddyResource *jbr = jabber_buddy_find_resource(jb, NULL);
+	const GList *iter = NULL;
+	
+	if (!jbr) {
+		purple_debug_error("jabber", 
+				   "Unable to find caps: buddy might be offline\n");
+		return FALSE;
+	}
+	
+	if (!jbr->caps) {
+		purple_debug_error("jabber",
+				   "Unable to find caps: nothing known about buddy\n");
+		return FALSE;
+	}
+	
+	for (iter = jbr->caps->features ; iter ; iter = g_list_next(iter)) {
+		if (strcmp(iter->data, cap) == 0)
+			return TRUE;
+	}
+	
+	return FALSE;
+}
 
 
--- a/libpurple/protocols/jabber/buddy.h	Sat May 31 06:45:42 2008 +0000
+++ b/libpurple/protocols/jabber/buddy.h	Sat May 31 20:15:34 2008 +0000
@@ -99,6 +99,8 @@
 void jabber_buddy_get_info_chat(PurpleConnection *gc, int id,
 		const char *resource);
 
+gboolean jabber_buddy_has_capability(JabberBuddy *jb, const gchar *cap);
+
 GList *jabber_blist_node_menu(PurpleBlistNode *node);
 
 void jabber_set_info(PurpleConnection *gc, const char *info);
--- a/libpurple/protocols/jabber/disco.c	Sat May 31 06:45:42 2008 +0000
+++ b/libpurple/protocols/jabber/disco.c	Sat May 31 20:15:34 2008 +0000
@@ -142,6 +142,7 @@
 						SUPPORT_FEATURE(feat->namespace);
 				}
 			}
+#ifdef USE_VV
 		} else if (node && !strcmp(node, CAPS0115_NODE "#voice-v1")) {
 			SUPPORT_FEATURE("http://www.google.com/session");
 			SUPPORT_FEATURE("http://www.google.com/transport/p2p");
@@ -150,7 +151,9 @@
 			SUPPORT_FEATURE("http://www.xmpp.org/extensions/xep-0166.html");
 			SUPPORT_FEATURE("http://www.xmpp.org/extensions/xep-0180.html");
 			SUPPORT_FEATURE("http://www.xmpp.org/extensions/xep-0167.html");
+			SUPPORT_FEATURE("http://www.xmpp.org/extensions/xep-0176.html");
 			SUPPORT_FEATURE("http://www.xmpp.org/extensions/xep-0177.html");
+#endif
 		} else {
 			const char *ext = NULL;
 			unsigned pos;
--- a/libpurple/protocols/jabber/jabber.c	Sat May 31 06:45:42 2008 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Sat May 31 20:15:34 2008 +0000
@@ -60,6 +60,11 @@
 
 #ifdef USE_VV
 #include <gst/farsight/fs-conference-iface.h>
+
+#define XEP_0167_CAP "http://www.xmpp.org/extensions/xep-0167.html"
+#define XEP_0180_CAP "http://www.xmpp.org/extensions/xep-0180.html"
+#define GTALK_CAP "http://www.google.com/session/phone"
+
 #endif
 
 #define JABBER_CONNECT_STEPS (js->gsc ? 9 : 5)
@@ -2640,10 +2645,37 @@
 gboolean jabber_can_do_media(PurpleConnection *gc, const char *who, 
                              PurpleMediaStreamType type)
 {
-	if (type == PURPLE_MEDIA_AUDIO)
-		return TRUE;
-	else
+	JabberStream *js = (JabberStream *) gc->proto_data;
+	JabberBuddy *jb = jabber_buddy_find(js, who, FALSE);
+	
+	if (!jb) {
+		purple_debug_error("jabber", "Could not find buddy\n");
 		return FALSE;
+	}
+#if 0	/* These can be added once we support video */
+	/* XMPP will only support two-way media, AFAIK... */
+	if (type == (PURPLE_MEDIA_AUDIO | PURPLE_MEDIA_VIDEO)) {
+		purple_debug_info("jabber", 
+				  "Checking audio/video XEP support for %s\n", who);
+		return (jabber_buddy_has_capability(jb, XEP_0167_CAP) ||
+				jabber_buddy_has_capability(jb, GTALK_CAP)) && 
+				jabber_buddy_has_capability(jb, XEP_0180_CAP);
+	} else 
+#endif
+	if (type == (PURPLE_MEDIA_AUDIO)) {
+		purple_debug_info("jabber", 
+				  "Checking audio XEP support for %s\n", who);
+		return jabber_buddy_has_capability(jb, XEP_0167_CAP) ||
+				jabber_buddy_has_capability(jb, GTALK_CAP);
+	}
+#if 0
+	 else if (type == (PURPLE_MEDIA_VIDEO)) {
+		purple_debug_info("jabber", 
+				  "Checking video XEP support for %s\n", who);
+		return jabber_buddy_has_capability(jb, XEP_0180_CAP);
+	}
+#endif
+	return FALSE;
 }