Each PurpleSmiley has a PurpleStoredImage behind it, so there's no need to
authorElliott Sales de Andrade <qulogic@pidgin.im>
Thu, 31 Dec 2009 05:24:31 +0000
changeset7e381f84b894 pushlog
parent 04759f21ffea
child 8dbae388c51d
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.
libpurple/protocols/msn/slp.c
     1.1 --- a/libpurple/protocols/msn/slp.c
     1.2 +++ b/libpurple/protocols/msn/slp.c
     1.3 @@ -276,6 +276,38 @@
     1.4  	msn_slplink_queue_slpmsg(slplink, slpmsg);
     1.5  }
     1.6  
     1.7 +/* XXX: this could be improved if we tracked custom smileys
     1.8 + * per-protocol, per-account, per-session or (ideally) per-conversation
     1.9 + */
    1.10 +static PurpleStoredImage *
    1.11 +find_valid_emoticon(PurpleAccount *account, const char *path)
    1.12 +{
    1.13 +	GList *smileys;
    1.14 +
    1.15 +	if (!purple_account_get_bool(account, "custom_smileys", TRUE))
    1.16 +		return NULL;
    1.17 +
    1.18 +	smileys = purple_smileys_get_all();
    1.19 +
    1.20 +	for (; smileys; smileys = g_list_delete_link(smileys, smileys)) {
    1.21 +		PurpleSmiley *smiley;
    1.22 +		PurpleStoredImage *img;
    1.23 +
    1.24 +		smiley = smileys->data;
    1.25 +		img = purple_smiley_get_stored_image(smiley);
    1.26 +
    1.27 +		if (purple_strequal(path, purple_imgstore_get_filename(img))) {
    1.28 +			g_list_free(smileys);
    1.29 +			return img;
    1.30 +		}
    1.31 +
    1.32 +		purple_imgstore_unref(img);
    1.33 +	}
    1.34 +
    1.35 +	purple_debug_error("msn", "Received illegal request for file %s\n", path);
    1.36 +	return NULL;
    1.37 +}
    1.38 +
    1.39  #define MAX_FILE_NAME_LEN 0x226
    1.40  
    1.41  static void
    1.42 @@ -313,11 +345,7 @@
    1.43  		g_free(msnobj_data);
    1.44  
    1.45  		if (type == MSN_OBJECT_EMOTICON) {
    1.46 -			char *path;
    1.47 -			path = g_build_filename(purple_smileys_get_storing_dir(),
    1.48 -					obj->location, NULL);
    1.49 -			img = purple_imgstore_new_from_file(path);
    1.50 -			g_free(path);
    1.51 +			img = find_valid_emoticon(slplink->session->account, obj->location);
    1.52  		} else if (type == MSN_OBJECT_USERTILE) {
    1.53  			img = msn_object_get_image(obj);
    1.54  			if (img)