changeset 28534:738cd1adb3cf

jabber: Determine if a buddy can receive a file transfer (when we have received caps for all online caps). This will still allow file transfer to clients that don't advertise caps. Disables the file transfer option for gmail buddies Refs #1507
author Marcus Lundblad <ml@update.uu.se>
date Thu, 12 Nov 2009 23:24:43 +0000
parents 52eef06b1829
children 43d5face5d9b f85510c955e4
files ChangeLog libpurple/protocols/jabber/buddy.c libpurple/protocols/jabber/buddy.h libpurple/protocols/jabber/jabber.c libpurple/protocols/jabber/jabber.h libpurple/protocols/jabber/libxmpp.c
diffstat 6 files changed, 56 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Nov 11 05:40:13 2009 +0000
+++ b/ChangeLog	Thu Nov 12 23:24:43 2009 +0000
@@ -42,6 +42,8 @@
 	  account's domain, and use that for voice and video if found and the user 
 	  didn't set one manually in prefs.
 	* Fix a crash when adding a buddy without an '@'.
+	* Don't show the option to send a file to a buddy if we know for certain
+	  they don't support any file transfer method supported by libpurple.
 
 	Yahoo:
 	* Fix sending /buzz.
--- a/libpurple/protocols/jabber/buddy.c	Wed Nov 11 05:40:13 2009 +0000
+++ b/libpurple/protocols/jabber/buddy.c	Thu Nov 12 23:24:43 2009 +0000
@@ -2341,6 +2341,12 @@
 }
 
 gboolean
+jabber_resource_know_capabilities(const JabberBuddyResource *jbr)
+{
+	return jbr->caps.info != NULL;
+}
+
+gboolean
 jabber_resource_has_capability(const JabberBuddyResource *jbr, const gchar *cap)
 {
 	const GList *node = NULL;
--- a/libpurple/protocols/jabber/buddy.h	Wed Nov 11 05:40:13 2009 +0000
+++ b/libpurple/protocols/jabber/buddy.h	Thu Nov 12 23:24:43 2009 +0000
@@ -123,6 +123,7 @@
 
 void jabber_vcard_fetch_mine(JabberStream *js);
 
+gboolean jabber_resource_know_capabilities(const JabberBuddyResource *jbr);
 gboolean jabber_resource_has_capability(const JabberBuddyResource *jbr,
 										const gchar *cap);
 gboolean jabber_buddy_has_capability(const JabberBuddy *jb, const gchar *cap);
--- a/libpurple/protocols/jabber/jabber.c	Wed Nov 11 05:40:13 2009 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Thu Nov 12 23:24:43 2009 +0000
@@ -52,6 +52,7 @@
 #include "data.h"
 #include "disco.h"
 #include "google.h"
+#include "ibb.h"
 #include "iq.h"
 #include "jutil.h"
 #include "message.h"
@@ -3224,6 +3225,50 @@
 #endif
 }
 
+gboolean jabber_can_receive_file(PurpleConnection *gc, const char *who)
+{
+	JabberStream *js = gc->proto_data;
+
+	if (js) {
+		JabberBuddy *jb = jabber_buddy_find(js, who, FALSE);
+		GList *iter;
+		gboolean has_resources_without_caps = FALSE;
+
+		/* find out if there is any resources without caps */
+		for (iter = jb->resources; iter ; iter = g_list_next(iter)) {
+			JabberBuddyResource *jbr = (JabberBuddyResource *) iter->data;
+
+			if (!jabber_resource_know_capabilities(jbr)) {
+				has_resources_without_caps = TRUE;
+			}
+		}
+
+		if (has_resources_without_caps) {
+			/* there is at least one resource which we don't have caps for, 
+			 let's assume they can receive files... */
+			return TRUE;
+		} else {
+			/* we have caps for all the resources, see if at least one has
+			 right caps */
+			for (iter = jb->resources; iter ; iter = g_list_next(iter)) {
+				JabberBuddyResource *jbr = (JabberBuddyResource *) iter->data;
+
+				if (jabber_resource_has_capability(jbr,
+						"http://jabber.org/protocol/si/profile/file-transfer")
+			    	&& (jabber_resource_has_capability(jbr,
+			    			"http://jabber.org/protocol/bytestreams")
+			        	|| jabber_resource_has_capability(jbr,
+				           		XEP_0047_NAMESPACE))) {
+					return TRUE;
+				}
+			}
+			return FALSE;
+		}
+	} else {
+		return TRUE;
+	}
+}
+
 void jabber_register_commands(void)
 {
 	PurpleCmdId id;
--- a/libpurple/protocols/jabber/jabber.h	Wed Nov 11 05:40:13 2009 +0000
+++ b/libpurple/protocols/jabber/jabber.h	Thu Nov 12 23:24:43 2009 +0000
@@ -368,6 +368,7 @@
 gboolean jabber_initiate_media(PurpleAccount *account, const char *who,
 		PurpleMediaSessionType type);
 PurpleMediaCaps jabber_get_media_caps(PurpleAccount *account, const char *who);
+gboolean jabber_can_receive_file(PurpleConnection *gc, const gchar *who);
 
 void jabber_register_commands(void);
 void jabber_unregister_commands(void);
--- a/libpurple/protocols/jabber/libxmpp.c	Wed Nov 11 05:40:13 2009 +0000
+++ b/libpurple/protocols/jabber/libxmpp.c	Thu Nov 12 23:24:43 2009 +0000
@@ -111,7 +111,7 @@
 	jabber_roomlist_get_list,		/* roomlist_get_list */
 	jabber_roomlist_cancel,			/* roomlist_cancel */
 	NULL,							/* roomlist_expand_category */
-	NULL,							/* can_receive_file */
+	jabber_can_receive_file,		/* can_receive_file */
 	jabber_si_xfer_send,			/* send_file */
 	jabber_si_new_xfer,				/* new_xfer */
 	jabber_offline_message,			/* offline_message */