/pidgin/main: 528ddb11791c: Drop purple_util_get_image_extension...

Tomasz Wasilczyk twasilczyk at pidgin.im
Fri Apr 11 19:46:30 EDT 2014


Changeset: 528ddb11791c4bc9f1a9f15ec2bdc9a21fbca0ce
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2014-04-12 01:46 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/528ddb11791c

Description:

Drop purple_util_get_image_extension and purple_util_get_image_filename

diffstat:

 libpurple/buddyicon.c                 |   2 +-
 libpurple/log.c                       |   7 ++---
 libpurple/plugins/perl/common/Util.xs |   9 --------
 libpurple/protocols/bonjour/buddy.c   |  13 +----------
 libpurple/util.c                      |  38 -----------------------------------
 libpurple/util.h                      |  23 ---------------------
 6 files changed, 6 insertions(+), 86 deletions(-)

diffs (174 lines):

diff --git a/libpurple/buddyicon.c b/libpurple/buddyicon.c
--- a/libpurple/buddyicon.c
+++ b/libpurple/buddyicon.c
@@ -57,7 +57,7 @@ static GHashTable *account_cache = NULL;
  * shared across all accounts.
  *
  * Key is the filename for this image as constructed by
- * purple_util_get_image_filename().  So it is the base16 encoded
+ * purple_image_generate_filename().  So it is the base16 encoded
  * sha-1 hash plus an appropriate file extension.  For example:
  *   "0f4972d17d1e70e751c43c90c948e72efbff9796.gif"
  *
diff --git a/libpurple/log.c b/libpurple/log.c
--- a/libpurple/log.c
+++ b/libpurple/log.c
@@ -832,7 +832,7 @@ convert_image_tags(const PurpleLog *log,
 			char *dir;
 			PurpleImage *image;
 			gconstpointer image_data;
-			char *new_filename = NULL;
+			const gchar *new_filename = NULL;
 			char *path = NULL;
 			size_t image_byte_count;
 
@@ -848,7 +848,7 @@ convert_image_tags(const PurpleLog *log,
 			image_data       = purple_image_get_data(image);
 			image_byte_count = purple_image_get_size(image);
 			dir              = purple_log_get_log_dir(log->type, log->name, log->account);
-			new_filename     = purple_util_get_image_filename(image_data, image_byte_count);
+			new_filename = purple_image_generate_filename(image);
 
 			path = g_build_filename(dir, new_filename, NULL);
 
@@ -883,8 +883,7 @@ convert_image_tags(const PurpleLog *log,
 			}
 
 			/* Write the new image tag */
-			g_string_append_printf(newmsg, "<IMG SRC=\"%s\">", new_filename);
-			g_free(new_filename);
+			g_string_append_printf(newmsg, "<img src=\"%s\">", new_filename);
 			g_free(path);
 		}
 
diff --git a/libpurple/plugins/perl/common/Util.xs b/libpurple/plugins/perl/common/Util.xs
--- a/libpurple/plugins/perl/common/Util.xs
+++ b/libpurple/plugins/perl/common/Util.xs
@@ -426,14 +426,6 @@ purple_util_format_song_info(title, arti
 	const char* album
 	gpointer unused
 
-const char*
-purple_util_get_image_extension(const char *data, size_t length(data))
-	PROTOTYPE: $
-
-gchar_own*
-purple_util_get_image_filename(const char *image_data, size_t length(image_data))
-	PROTOTYPE: $
-
 Purple::XMLNode
 purple_util_read_xml_from_file(filename, description)
 	const char* filename
@@ -443,4 +435,3 @@ gboolean
 purple_util_write_data_to_file_absolute(filename_full, char *data, gssize length(data))
 	const char* filename_full
 	PROTOTYPE: $$
-
diff --git a/libpurple/protocols/bonjour/buddy.c b/libpurple/protocols/bonjour/buddy.c
--- a/libpurple/protocols/bonjour/buddy.c
+++ b/libpurple/protocols/bonjour/buddy.c
@@ -223,21 +223,12 @@ void bonjour_buddy_signed_off(PurpleBudd
  */
 void bonjour_buddy_got_buddy_icon(BonjourBuddy *buddy, gconstpointer data, gsize len) {
 	/* Recalculate the hash instead of using the current phsh to make sure it is accurate for the icon. */
-	char *p, *hash;
+	gchar *hash;
 
 	if (data == NULL || len == 0)
 		return;
 
-	/* Take advantage of the fact that we use a SHA-1 hash of the data as the filename. */
-	hash = purple_util_get_image_filename(data, len);
-
-	/* Get rid of the extension */
-	if (!(p = strchr(hash, '.'))) {
-		g_free(hash);
-		return;
-	}
-
-	*p = '\0';
+	hash = g_compute_checksum_for_data(G_CHECKSUM_SHA1, data, len);
 
 	purple_debug_info("bonjour", "Got buddy icon for %s icon hash='%s' phsh='%s'.\n", buddy->name,
 			  hash, buddy->phsh ? buddy->phsh : "(null)");
diff --git a/libpurple/util.c b/libpurple/util.c
--- a/libpurple/util.c
+++ b/libpurple/util.c
@@ -3173,44 +3173,6 @@ purple_mkstemp(char **fpath, gboolean bi
 	return fp;
 }
 
-const char *
-purple_util_get_image_extension(gconstpointer data, size_t len)
-{
-	g_return_val_if_fail(data != NULL, NULL);
-	g_return_val_if_fail(len   > 0,    NULL);
-
-	if (len >= 4)
-	{
-		if (!strncmp((char *)data, "GIF8", 4))
-			return "gif";
-		else if (!strncmp((char *)data, "\xff\xd8\xff", 3)) /* 4th may be e0 through ef */
-			return "jpg";
-		else if (!strncmp((char *)data, "\x89PNG", 4))
-			return "png";
-		else if (!strncmp((char *)data, "MM", 2) ||
-				 !strncmp((char *)data, "II", 2))
-			return "tif";
-		else if (!strncmp((char *)data, "BM", 2))
-			return "bmp";
-	}
-
-	return "icon";
-}
-
-char *
-purple_util_get_image_filename(gconstpointer image_data, size_t image_len)
-{
-	/* Use a cryptographic hash to avoid the possibility of user A
-	   intentionally causing a collision with user B.  It's not a
-	   horrible problem, but it's something we should try to avoid. */
-	char *checksum = g_compute_checksum_for_data(G_CHECKSUM_SHA1,
-			image_data, image_len);
-	char *filename = g_strdup_printf("%s.%s", checksum,
-	                       purple_util_get_image_extension(image_data, image_len));
-	g_free(checksum);
-	return filename;
-}
-
 gboolean
 purple_program_is_valid(const char *program)
 {
diff --git a/libpurple/util.h b/libpurple/util.h
--- a/libpurple/util.h
+++ b/libpurple/util.h
@@ -880,29 +880,6 @@ PurpleXmlNode *purple_util_read_xml_from
  */
 FILE *purple_mkstemp(char **path, gboolean binary);
 
-/**
- * purple_util_get_image_extension:
- * @data: A pointer to the image data
- * @len:  The length of the image data
- *
- * Returns an extension corresponding to the image data's file type.
- *
- * Returns: The appropriate extension, or "icon" if unknown.
- */
-const char *
-purple_util_get_image_extension(gconstpointer data, size_t len);
-
-/**
- * purple_util_get_image_filename:
- *
- * Returns: A hex encoded version of the SHA-1 hash of the data passed
- *         in with the correct file extention appended.  The file
- *         extension is determined by calling
- *         purple_util_get_image_extension().  This return value must
- *         be g_freed by the caller.
- */
-char *purple_util_get_image_filename(gconstpointer image_data, size_t image_len);
-
 
 /**************************************************************************/
 /* Environment Detection Functions                                        */



More information about the Commits mailing list