pidgin: c64a1adc: Each PurpleSmiley has a PurpleStoredImag...

qulogic at pidgin.im qulogic at pidgin.im
Fri Jan 1 04:01:01 EST 2010


-----------------------------------------------------------------
Revision: c64a1adc8bda2b4aeaae1f273541afbc4f71b810
Ancestor: 3d02401cf232459fc80c0837d31e05fae7ae5467
Author: qulogic at pidgin.im
Date: 2009-12-31T05:24:31
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/c64a1adc8bda2b4aeaae1f273541afbc4f71b810

Modified files:
        libpurple/protocols/msn/slp.c

ChangeLog: 

Each PurpleSmiley has a PurpleStoredImage behind it, so there's no need to
go and create a new one when someone asks for one.

Also, ignore requests for smileys that don't exist in the image store.

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/slp.c	b9b135713b7e49a4c7a2c5e4f2209d5a7b4cf1d9
+++ libpurple/protocols/msn/slp.c	76b6cdeaea8a7b857e42223d66e47fd2fb29bbd2
@@ -276,6 +276,38 @@ send_decline(MsnSlpCall *slpcall, const 
 	msn_slplink_queue_slpmsg(slplink, slpmsg);
 }
 
+/* XXX: this could be improved if we tracked custom smileys
+ * per-protocol, per-account, per-session or (ideally) per-conversation
+ */
+static PurpleStoredImage *
+find_valid_emoticon(PurpleAccount *account, const char *path)
+{
+	GList *smileys;
+
+	if (!purple_account_get_bool(account, "custom_smileys", TRUE))
+		return NULL;
+
+	smileys = purple_smileys_get_all();
+
+	for (; smileys; smileys = g_list_delete_link(smileys, smileys)) {
+		PurpleSmiley *smiley;
+		PurpleStoredImage *img;
+
+		smiley = smileys->data;
+		img = purple_smiley_get_stored_image(smiley);
+
+		if (purple_strequal(path, purple_imgstore_get_filename(img))) {
+			g_list_free(smileys);
+			return img;
+		}
+
+		purple_imgstore_unref(img);
+	}
+
+	purple_debug_error("msn", "Received illegal request for file %s\n", path);
+	return NULL;
+}
+
 #define MAX_FILE_NAME_LEN 0x226
 
 static void
@@ -313,11 +345,7 @@ got_sessionreq(MsnSlpCall *slpcall, cons
 		g_free(msnobj_data);
 
 		if (type == MSN_OBJECT_EMOTICON) {
-			char *path;
-			path = g_build_filename(purple_smileys_get_storing_dir(),
-					obj->location, NULL);
-			img = purple_imgstore_new_from_file(path);
-			g_free(path);
+			img = find_valid_emoticon(slplink->session->account, obj->location);
 		} else if (type == MSN_OBJECT_USERTILE) {
 			img = msn_object_get_image(obj);
 			if (img)


More information about the Commits mailing list