changeset 16562:1f9cba8efdfb

merge of '2ec86531b43742d8242195bf529e7ba77be9d3dc' and 'fb970fdd4f3e27ac176f55bee8baf7074a1a96ef'
author Richard Laager <rlaager@wiktel.com>
date Sat, 28 Apr 2007 02:42:26 +0000
parents 69e36b560549 (diff) f0d399f91756 (current diff)
children fb633ba3fb1e 06ee8064b3d0
files pidgin/plugins/perl/common/GtkUI.pm pidgin/plugins/perl/common/GtkUI.xs
diffstat 1 files changed, 22 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/buddyicon.c	Sat Apr 28 02:59:27 2007 +0000
+++ b/libpurple/buddyicon.c	Sat Apr 28 02:42:26 2007 +0000
@@ -98,7 +98,6 @@
 {
 	PurpleCipherContext *context;
 	gchar digest[41];
-	const char *ext;
 
 	context = purple_cipher_context_new_by_name("sha1", NULL);
 	if (context == NULL)
@@ -116,10 +115,9 @@
 	}
 	purple_cipher_context_destroy(context);
 
-	ext = purple_util_get_image_extension(icon_data, icon_len);
-
 	/* Return the filename */
-	return g_strdup_printf("%s%s%s", digest, ext ? "." : "", ext ? ext : "");
+	return g_strdup_printf("%s.%s", digest,
+	                       purple_util_get_image_extension(icon_data, icon_len));
 }
 
 static void
@@ -850,6 +848,18 @@
 }
 
 static void
+delete_buddy_icon_settings(PurpleBlistNode *node, const char *setting_name)
+{
+	purple_blist_node_remove_setting(node, setting_name);
+
+	if (!strcmp(setting_name, "buddy_icon"))
+	{
+		purple_blist_node_remove_setting(node, "avatar_hash");
+		purple_blist_node_remove_setting(node, "icon_checksum");
+	}
+}
+
+static void
 migrate_buddy_icon(PurpleBlistNode *node, const char *setting_name,
                    const char *dirname, const char *filename)
 {
@@ -877,8 +887,10 @@
 		FILE *file;
 		char *new_filename;
 
-		if (!read_icon_file(path, &icon_data, &icon_len))
+		if (!read_icon_file(path, &icon_data, &icon_len) ||
+		    icon_data == NULL || icon_len > 0)
 		{
+			delete_buddy_icon_settings(node, setting_name);
 			g_free(path);
 			return;
 		}
@@ -888,6 +900,7 @@
 		new_filename = purple_buddy_icon_data_calculate_filename(icon_data, icon_len);
 		if (new_filename == NULL)
 		{
+			delete_buddy_icon_settings(node, setting_name);
 			return;
 		}
 
@@ -910,6 +923,8 @@
 			                   path, strerror(errno));
 			g_free(new_filename);
 			g_free(path);
+
+			delete_buddy_icon_settings(node, setting_name);
 			return;
 		}
 		g_free(path);
@@ -947,16 +962,7 @@
 	else
 	{
 		/* If the icon is gone, drop the setting... */
-		purple_blist_node_remove_setting(node,
-		                                 setting_name);
-
-		if (!strcmp(setting_name, "buddy_icon"))
-		{
-			purple_blist_node_remove_setting(node,
-			                                 "avatar_hash");
-			purple_blist_node_remove_setting(node,
-			                                 "icon_checksum");
-		}
+		delete_buddy_icon_settings(node, setting_name);
 		g_free(path);
 	}
 }
@@ -1050,7 +1056,7 @@
 				{
 					migrate_buddy_icon(node,
 					                   "custom_buddy_icon",
-					                    dirname, filename);
+					                   dirname, filename);
 				}
 				else
 				{