diff libpurple/protocols/msn/slp.c @ 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 fc93bc1a546f
children 126317248aaa e53f81486d57
line wrap: on
line diff
--- 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
 	{