changeset 30318:76049fde7ad2

Add support for Url/Url1 in MSN objects, which are used for buddy icons when you're on the website.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sat, 31 Jul 2010 23:39:40 +0000
parents ea96292336f0
children e9fbbfe1ab70 e53f81486d57
files ChangeLog libpurple/protocols/msn/object.c libpurple/protocols/msn/object.h libpurple/protocols/msn/slp.c
diffstat 4 files changed, 129 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat Jul 31 20:47:31 2010 +0000
+++ b/ChangeLog	Sat Jul 31 23:39:40 2010 +0000
@@ -22,6 +22,10 @@
 	IRC:
 	* Fix non-ASCII arguments to /mode et al.  (thanks to Max Ulidtko)
 
+	MSN:
+	* Support for web-based buddy icons, used when a buddy logs in to the
+	  messenger on the Live website.
+
 	MXit:
 	* Fix filename for the Shocked emoticon. (#12364)
 	* Implement the new naming conventions where possible. (MXitId, etc)
--- a/libpurple/protocols/msn/object.c	Sat Jul 31 20:47:31 2010 +0000
+++ b/libpurple/protocols/msn/object.c	Sat Jul 31 23:39:40 2010 +0000
@@ -96,15 +96,29 @@
 	GET_STRING_TAG(friendly, "Friendly");
 	GET_STRING_TAG(sha1d,    "SHA1D");
 	GET_STRING_TAG(sha1c,    "SHA1C");
+	GET_STRING_TAG(url,      "Url");
+	GET_STRING_TAG(url1,     "Url1");
 
 	/* If we are missing any of the required elements then discard the object */
-	/* SHA1C is not always sent anymore */
 	if (obj->creator == NULL || obj->size == 0 || obj->type == 0
-			|| obj->location == NULL || obj->friendly == NULL
-			|| obj->sha1d == NULL /*|| obj->sha1c == NULL*/) {
+	 || obj->sha1d == NULL) {
 		purple_debug_error("msn", "Discarding invalid msnobj: '%s'\n", str);
 		msn_object_destroy(obj);
-		obj = NULL;
+		return NULL;
+	}
+
+	if (obj->location == NULL || obj->friendly == NULL) {
+		/* Location/friendly are required for non-buddyicon objects */
+		if (obj->type != MSN_OBJECT_USERTILE) {
+			purple_debug_error("msn", "Discarding invalid msnobj: '%s'\n", str);
+			msn_object_destroy(obj);
+			return NULL;
+		/* Buddy icon object can contain Url/Url1 instead */
+		} else if (obj->url == NULL || obj->url1 == NULL) {
+			purple_debug_error("msn", "Discarding invalid msnobj: '%s'\n", str);
+			msn_object_destroy(obj);
+			return NULL;
+		}
 	}
 
 	return obj;
@@ -284,6 +298,24 @@
 	obj->sha1c = g_strdup(sha1c);
 }
 
+void
+msn_object_set_url(MsnObject *obj, const char *url)
+{
+	g_return_if_fail(obj != NULL);
+
+	g_free(obj->url);
+	obj->url = g_strdup(url);
+}
+
+void
+msn_object_set_url1(MsnObject *obj, const char *url)
+{
+	g_return_if_fail(obj != NULL);
+
+	g_free(obj->url1);
+	obj->url1 = g_strdup(url);
+}
+
 const char *
 msn_object_get_creator(const MsnObject *obj)
 {
@@ -352,6 +384,22 @@
 	}
 }
 
+const char *
+msn_object_get_url(const MsnObject *obj)
+{
+	g_return_val_if_fail(obj != NULL, NULL);
+
+	return obj->url;
+}
+
+const char *
+msn_object_get_url1(const MsnObject *obj)
+{
+	g_return_val_if_fail(obj != NULL, NULL);
+
+	return obj->url1;
+}
+
 static MsnObject *
 msn_object_find_local(const char *sha1)
 {
--- a/libpurple/protocols/msn/object.h	Sat Jul 31 20:47:31 2010 +0000
+++ b/libpurple/protocols/msn/object.h	Sat Jul 31 23:39:40 2010 +0000
@@ -50,6 +50,8 @@
 	char *friendly;
 	char *sha1d;
 	char *sha1c;
+	char *url;
+	char *url1;
 } MsnObject;
 
 /**
@@ -155,6 +157,20 @@
 void msn_object_set_image(MsnObject *obj, PurpleStoredImage *img);
 
 /**
+ * Sets the url field in a MsnObject.
+ *
+ * @param url The url value.
+ */
+void msn_object_set_url(MsnObject *obj, const char *url);
+
+/**
+ * Sets the url1 field in a MsnObject.
+ *
+ * @param url1 The url1 value.
+ */
+void msn_object_set_url1(MsnObject *obj, const char *url);
+
+/**
  * Returns a MsnObject's creator value.
  *
  * @param obj The object.
@@ -235,6 +251,24 @@
  */
 PurpleStoredImage *msn_object_get_image(const MsnObject *obj);
 
+/**
+ * Returns a MsnObject's url value.
+ *
+ * @param obj The object.
+ *
+ * @return The url value.
+ */
+const char *msn_object_get_url(const MsnObject *obj);
+
+/**
+ * Returns a MsnObject's url1 value.
+ *
+ * @param obj The object.
+ *
+ * @return The url1 value.
+ */
+const char *msn_object_get_url1(const MsnObject *obj);
+
 void msn_object_set_local(MsnObject *obj);
 
 #endif /* MSN_OBJECT_H */
--- a/libpurple/protocols/msn/slp.c	Sat Jul 31 20:47:31 2010 +0000
+++ b/libpurple/protocols/msn/slp.c	Sat Jul 31 23:39:40 2010 +0000
@@ -39,6 +39,11 @@
 
 static void request_user_display(MsnUser *user);
 
+typedef struct {
+	MsnSession *session;
+	const char *remote_user;
+	const char *sha1;
+} MsnFetchUserDisplayData;
 
 /**************************************************************************
  * Util
@@ -1405,6 +1410,26 @@
 }
 
 static void
+fetched_user_display(PurpleUtilFetchUrlData *url_data, gpointer user_data,
+	const gchar *url_text, gsize len, const gchar *error_message)
+{
+	MsnFetchUserDisplayData *data = user_data;
+	MsnSession *session = data->session;
+
+	session->url_datas = g_slist_remove(session->url_datas, url_data);
+
+	if (url_text) {
+		purple_buddy_icons_set_for_user(session->account, data->remote_user,
+		                                g_memdup(url_text, len), len,
+		                                data->sha1);
+	}
+
+	end_user_display(NULL, session);
+
+	g_free(user_data);
+}
+
+static void
 request_user_display(MsnUser *user)
 {
 	PurpleAccount *account;
@@ -1425,8 +1450,20 @@
 	if (g_ascii_strcasecmp(user->passport,
 						   purple_account_get_username(account)))
 	{
-		msn_slplink_request_object(slplink, info, got_user_display,
-								   end_user_display, obj);
+		const char *url = msn_object_get_url1(obj);
+		if (url) {
+			MsnFetchUserDisplayData *data = g_new0(MsnFetchUserDisplayData, 1);
+			PurpleUtilFetchUrlData *url_data;
+			data->session = session;
+			data->remote_user = user->passport;
+			data->sha1 = info;
+			url_data = purple_util_fetch_url_len(url, TRUE, NULL, TRUE, 200*1024,
+			                                     fetched_user_display, data);
+			session->url_datas = g_slist_prepend(session->url_datas, url_data);
+		} else {
+			msn_slplink_request_object(slplink, info, got_user_display,
+			                           end_user_display, obj);
+		}
 	}
 	else
 	{