changeset 16488:5f57cd067579

merge of '11e5b1fa24c811784613e66b0a9e73aa3b2a82ca' and 'f051493af8a1173b1310c2e130013cda126fa6ce'
author Daniel Atallah <daniel.atallah@gmail.com>
date Fri, 27 Apr 2007 03:46:47 +0000
parents b8b2e35ec7c6 (diff) dec693050305 (current diff)
children ce6b4346e56d 15f79c0cd0b9 74daf9fc9cf3
files
diffstat 5 files changed, 21 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/silc/buddy.c	Fri Apr 27 03:41:50 2007 +0000
+++ b/libpurple/protocols/silc/buddy.c	Fri Apr 27 03:46:47 2007 +0000
@@ -987,8 +987,10 @@
 					const unsigned char *data;
 					SilcUInt32 data_len;
 					data = silc_mime_get_data(m, &data_len);
-					if (data)
-						purple_buddy_icons_set_for_user(purple_buddy_get_account(r->b), purple_buddy_get_name(r->b), g_memdup(data, data_len), data_len);
+					if (data) {
+						/* TODO: Check if SILC gives us something to use as the checksum instead */
+						purple_buddy_icons_set_for_user(purple_buddy_get_account(r->b), purple_buddy_get_name(r->b), g_memdup(data, data_len), data_len, NULL);
+					}
 				}
 				silc_mime_free(m);
 			}
@@ -1681,48 +1683,31 @@
 }
 
 #ifdef SILC_ATTRIBUTE_USER_ICON
-void silcpurple_buddy_set_icon(PurpleConnection *gc, const char *iconfile)
+void silcpurple_buddy_set_icon(PurpleConnection *gc, PurpleStoredImage *img)
 {
 	SilcPurple sg = gc->proto_data;
 	SilcClient client = sg->client;
 	SilcClientConnection conn = sg->conn;
 	SilcMime mime;
-	PurpleBuddyIcon ic;
 	char type[32];
 	unsigned char *icon;
 	const char *t;
-	struct stat st;
-	FILE *fp;
 	SilcAttributeObjMime obj;
 
 	/* Remove */
-	if (!iconfile) {
+	if (!img) {
 		silc_client_attribute_del(client, conn,
 					  SILC_ATTRIBUTE_USER_ICON, NULL);
 		return;
 	}
 
 	/* Add */
-	if (g_stat(iconfile, &st) < 0)
-		return;
-	fp = g_fopen(iconfile, "rb");
-	if (!fp)
-		return;
-	ic.data = g_malloc(st.st_size);
-	if (!ic.data)
+	mime = silc_mime_alloc();
+	if (!mime)
 		return;
-	ic.len = fread(ic.data, 1, st.st_size, fp);
-	fclose(fp);
 
-	mime = silc_mime_alloc();
-	if (!mime) {
-		g_free(ic.data);
-		return;
-	}
-
-	t = purple_buddy_icon_get_type((const PurpleBuddyIcon *)&ic);
+	t = purple_util_get_image_extension(purple_imgstore_get_data(img), purple_imgstore_get_size(img));
 	if (!t || !strcmp(t, "icon")) {
-		g_free(ic.data);
 		silc_mime_free(mime);
 		return;
 	}
@@ -1730,7 +1715,7 @@
 		t = "jpeg";
 	g_snprintf(type, sizeof(type), "image/%s", t);
 	silc_mime_add_field(mime, "Content-Type", type);
-	silc_mime_add_data(mime, ic.data, ic.len);
+	silc_mime_add_data(mime, purple_imgstore_get_data(img), purple_imgstore_get_size(img));
 
 	obj.mime = icon = silc_mime_encode(mime, &obj.mime_len);
 	if (obj.mime)
@@ -1738,7 +1723,6 @@
 					  SILC_ATTRIBUTE_USER_ICON, &obj, sizeof(obj));
 
 	silc_free(icon);
-	g_free(ic.data);
 	silc_mime_free(mime);
 }
 #endif
--- a/libpurple/protocols/silc/silc.c	Fri Apr 27 03:41:50 2007 +0000
+++ b/libpurple/protocols/silc/silc.c	Fri Apr 27 03:46:47 2007 +0000
@@ -194,7 +194,7 @@
 		SilcUInt32 mask;
 		const char *tmp;
 #ifdef SILC_ATTRIBUTE_USER_ICON
-		char *icon;
+		PurpleStoredImage *img;
 #endif
 #ifdef HAVE_SYS_UTSNAME_H
 		struct utsname u;
@@ -233,9 +233,9 @@
 
 #ifdef SILC_ATTRIBUTE_USER_ICON
 		/* Set our buddy icon */
-		icon = purple_buddy_icons_get_full_path(purple_account_get_buddy_icon(account));
-		silcpurple_buddy_set_icon(gc, icon);
-		g_free(icon);
+		img = purple_buddy_icons_find_account_icon(account);
+		silcpurple_buddy_set_icon(gc, img);
+		purple_imgstore_unref(img);
 #endif
 	}
 
--- a/libpurple/protocols/silc/silcpurple.h	Fri Apr 27 03:41:50 2007 +0000
+++ b/libpurple/protocols/silc/silcpurple.h	Fri Apr 27 03:46:47 2007 +0000
@@ -145,7 +145,7 @@
 					 char **contactstr, char **langstr, char **devicestr,
 					 char **tzstr, char **geostr);
 #ifdef SILC_ATTRIBUTE_USER_ICON
-void silcpurple_buddy_set_icon(PurpleConnection *gc, const char *iconfile);
+void silcpurple_buddy_set_icon(PurpleConnection *gc, PurpleStoredImage *img);
 #endif
 #ifdef HAVE_SILCMIME_H
 char *silcpurple_file2mime(const char *filename);
--- a/libpurple/util.c	Fri Apr 27 03:41:50 2007 +0000
+++ b/libpurple/util.c	Fri Apr 27 03:46:47 2007 +0000
@@ -2570,7 +2570,7 @@
 }
 
 const char *
-purple_util_get_image_extension(gpointer data, size_t len)
+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);
@@ -2667,7 +2667,7 @@
 gboolean
 purple_running_osx(void)
 {
-#if defined(__APPLE__)	
+#if defined(__APPLE__)
 	return TRUE;
 #else
 	return FALSE;
@@ -4207,7 +4207,7 @@
 	signal(SIGABRT, SIG_DFL);	/* 6:  abort program */
 
 #ifdef SIGPOLL
-	signal(SIGPOLL,  SIG_DFL);	/* 7:  pollable event (POSIX) */	
+	signal(SIGPOLL,  SIG_DFL);	/* 7:  pollable event (POSIX) */
 #endif /* SIGPOLL */
 
 #ifdef SIGEMT
@@ -4223,7 +4223,7 @@
 	signal(SIGTERM, SIG_DFL);	/* 15: software termination signal */
 	signal(SIGCHLD, SIG_DFL);	/* 20: child status has changed */
 	signal(SIGXCPU, SIG_DFL);	/* 24: exceeded CPU time limit */
-	signal(SIGXFSZ, SIG_DFL);	/* 25: exceeded file size limit */	
+	signal(SIGXFSZ, SIG_DFL);	/* 25: exceeded file size limit */
 #endif /* HAVE_SIGNAL_H */
 #endif /* !_WIN32 */
 }
--- a/libpurple/util.h	Fri Apr 27 03:41:50 2007 +0000
+++ b/libpurple/util.h	Fri Apr 27 03:46:47 2007 +0000
@@ -469,7 +469,7 @@
  * the first character of the entity. If given an unrecognized entity, the function
  * returns @c NULL.
  *
- * Note that this function, unlike purple_unescape_html(), does not search 
+ * Note that this function, unlike purple_unescape_html(), does not search
  * the string for the entity, does not replace the entity, and does not
  * return a newly allocated string.
  *
@@ -606,7 +606,7 @@
  * @return The appropriate extension, or "icon" if unknown.
  */
 const char *
-purple_util_get_image_extension(gpointer data, size_t len);
+purple_util_get_image_extension(gconstpointer data, size_t len);
 
 /*@}*/