pidgin: 5b9ae21a: Add support for Url/Url1 in MSN objects,..

qulogic at pidgin.im qulogic at pidgin.im
Sat Jul 31 19:50:47 EDT 2010


----------------------------------------------------------------------
Revision: 5b9ae21a0927d9a160964bfb1cad7a43253fba0d
Parent:   70890f22a16b47ce488e92c42368250c57bf0518
Author:   qulogic at pidgin.im
Date:     07/31/10 19:39:40
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/5b9ae21a0927d9a160964bfb1cad7a43253fba0d

Changelog: 

Add support for Url/Url1 in MSN objects, which are used for buddy
icons when you're on the website.

Changes against parent 70890f22a16b47ce488e92c42368250c57bf0518

  patched  ChangeLog
  patched  libpurple/protocols/msn/object.c
  patched  libpurple/protocols/msn/object.h
  patched  libpurple/protocols/msn/slp.c

-------------- next part --------------
============================================================
--- ChangeLog	48d45d2fd339d9b58ff22c9ae442a81a2372af6f
+++ ChangeLog	33fb7bf057c9489ad9373fc85febcc6d558c1171
@@ -22,6 +22,10 @@ version 2.7.3 (??/??/????):
 	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)
============================================================
--- libpurple/protocols/msn/object.c	0f2aece179ef8451e397f8243b64eec2e8bfab43
+++ libpurple/protocols/msn/object.c	58d6becfebe46f3b6f5eaebc6ac2531eda388738
@@ -96,17 +96,31 @@ msn_object_new_from_string(const char *s
 	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 @@ msn_object_set_sha1c(MsnObject *obj, con
 	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 @@ msn_object_get_sha1(const MsnObject *obj
 	}
 }
 
+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)
 {
============================================================
--- libpurple/protocols/msn/object.h	f5a5dae07ab4241782ca9e84c8e5e6f9f85924a4
+++ libpurple/protocols/msn/object.h	d9a228031d82ecd97c39c46eaa06a126c1c484de
@@ -50,6 +50,8 @@ typedef struct
 	char *friendly;
 	char *sha1d;
 	char *sha1c;
+	char *url;
+	char *url1;
 } MsnObject;
 
 /**
@@ -155,6 +157,20 @@ void msn_object_set_image(MsnObject *obj
 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(
  */
 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 */
============================================================
--- libpurple/protocols/msn/slp.c	ba3469991932a7a862d9b0f4019a9fef5fb162e3
+++ libpurple/protocols/msn/slp.c	e6a651f5bb0e8a5fbe054a5382a46e32a85659c8
@@ -39,6 +39,11 @@ static void request_user_display(MsnUser
 
 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
 }
 
 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 @@ request_user_display(MsnUser *user)
 	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
 	{


More information about the Commits mailing list