diff libpurple/protocols/jabber/jabber.c @ 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 96ba7fd24177
children 923681c5406e fed4286634e7 f85510c955e4
line wrap: on
line diff
--- 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;