diff libpurple/protocols/msn/user.c @ 16390:4fc51a87ce42

Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
author Richard Laager <rlaager@wiktel.com>
date Wed, 25 Apr 2007 21:48:56 +0000
parents 32c366eeeb99
children 133932a97faa f3874ba27a27 7c0a2ef88018
line wrap: on
line diff
--- a/libpurple/protocols/msn/user.c	Wed Apr 25 01:19:24 2007 +0000
+++ b/libpurple/protocols/msn/user.c	Wed Apr 25 21:48:56 2007 +0000
@@ -151,23 +151,20 @@
 }
 
 void
-msn_user_set_buddy_icon(MsnUser *user, const char *filename)
+msn_user_set_buddy_icon(MsnUser *user, PurpleStoredImage *img)
 {
-	struct stat st;
-	FILE *fp;
 	MsnObject *msnobj = msn_user_get_object(user);
 
 	g_return_if_fail(user != NULL);
 
-	if (filename == NULL || g_stat(filename, &st) == -1)
-	{
+	if (img == NULL)
 		msn_user_set_object(user, NULL);
-	}
-	else if ((fp = g_fopen(filename, "rb")) != NULL)
+	else
 	{
 		PurpleCipherContext *ctx;
 		char *buf;
-		gsize len;
+		gconstpointer data = purple_imgstore_get_data(img);
+		size_t size = purple_imgstore_get_size(img);
 		char *base64;
 		unsigned char digest[20];
 
@@ -182,26 +179,20 @@
 			msn_user_set_object(user, msnobj);
 		}
 
-		msn_object_set_real_location(msnobj, filename);
-
-		buf = g_malloc(st.st_size);
-		len = fread(buf, 1, st.st_size, fp);
-
-		fclose(fp);
+		msn_object_set_image(msnobj, img);
 
 		/* Compute the SHA1D field. */
 		memset(digest, 0, sizeof(digest));
 
 		ctx = purple_cipher_context_new_by_name("sha1", NULL);
-		purple_cipher_context_append(ctx, (const guchar *)buf, st.st_size);
+		purple_cipher_context_append(ctx, data, size);
 		purple_cipher_context_digest(ctx, sizeof(digest), digest, NULL);
-		g_free(buf);
 
 		base64 = purple_base64_encode(digest, sizeof(digest));
 		msn_object_set_sha1d(msnobj, base64);
 		g_free(base64);
 
-		msn_object_set_size(msnobj, st.st_size);
+		msn_object_set_size(msnobj, size);
 
 		/* Compute the SHA1C field. */
 		buf = g_strdup_printf(
@@ -216,7 +207,7 @@
 		memset(digest, 0, sizeof(digest));
 
 		purple_cipher_context_reset(ctx, NULL);
-		purple_cipher_context_append(ctx, (const guchar *)buf, strlen(buf));
+		purple_cipher_context_append(ctx, data, strlen((char *)data));
 		purple_cipher_context_digest(ctx, sizeof(digest), digest, NULL);
 		purple_cipher_context_destroy(ctx);
 		g_free(buf);
@@ -225,11 +216,6 @@
 		msn_object_set_sha1c(msnobj, base64);
 		g_free(base64);
 	}
-	else
-	{
-		purple_debug_error("msn", "Unable to open buddy icon %s!\n", filename);
-		msn_user_set_object(user, NULL);
-	}
 }
 
 void