/pidgin/main: c7c855c36c9b: imgstore: unref msn

Tomasz Wasilczyk twasilczyk at pidgin.im
Fri Apr 11 14:08:29 EDT 2014


Changeset: c7c855c36c9b0c3112d8aa2a3cf6b75096130ed6
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2014-04-11 20:08 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/c7c855c36c9b

Description:

imgstore: unref msn

diffstat:

 libpurple/protocols/msn/msn.c         |  20 ++++++++++++--------
 libpurple/protocols/msn/object.c      |  21 ++++++++++++---------
 libpurple/protocols/msn/object.h      |  10 ++++------
 libpurple/protocols/msn/session.c     |   4 ++--
 libpurple/protocols/msn/slp.c         |   6 +++---
 libpurple/protocols/msn/slpcall.c     |  12 ++++++------
 libpurple/protocols/msn/slpmsg.c      |  21 ++++++++++++---------
 libpurple/protocols/msn/slpmsg.h      |   8 +++-----
 libpurple/protocols/msn/switchboard.c |  14 +++++++++-----
 libpurple/protocols/msn/user.c        |   2 +-
 libpurple/protocols/msn/user.h        |   3 ++-
 11 files changed, 66 insertions(+), 55 deletions(-)

diffs (truncated from 439 to 300 lines):

diff --git a/libpurple/protocols/msn/msn.c b/libpurple/protocols/msn/msn.c
--- a/libpurple/protocols/msn/msn.c
+++ b/libpurple/protocols/msn/msn.c
@@ -55,7 +55,7 @@
 
 #if PHOTO_SUPPORT
 #define MAX_HTTP_BUDDYICON_BYTES (200 * 1024)
-#include "imgstore.h"
+#include "image-store.h"
 #endif
 
 typedef struct
@@ -1479,7 +1479,7 @@ static GSList* msn_msg_grab_emoticons(co
 
 	for (it = smileys; it; it = g_list_next(it)) {
 		PurpleSmiley *smiley = it->data;
-		PurpleStoredImage *img;
+		PurpleImage *img;
 
 		img = purple_smiley_get_image(smiley);
 
@@ -2161,7 +2161,7 @@ msn_convo_closed(PurpleConnection *gc, c
 }
 
 static void
-msn_set_buddy_icon(PurpleConnection *gc, PurpleStoredImage *img)
+msn_set_buddy_icon(PurpleConnection *gc, PurpleImage *img)
 {
 	MsnSession *session;
 	MsnUser *user;
@@ -2725,7 +2725,6 @@ msn_got_photo(PurpleHttpConnection *http
 	gpointer _info2_data)
 {
 	MsnGetInfoStepTwoData *info2_data = _info2_data;
-	int id = -1;
 
 	/* Unmarshall the saved state */
 	MsnGetInfoData *info_data = info2_data->info_data;
@@ -2737,14 +2736,21 @@ msn_got_photo(PurpleHttpConnection *http
 	/* Try to put the photo in there too, if there's one and is readable */
 	if (response && purple_http_response_is_successful(response))
 	{
+		PurpleImage *img;
 		char buf[1024];
 		const gchar *photo_data;
 		size_t len;
+		guint img_id;
 
 		photo_data = purple_http_response_get_data(response, &len);
 		purple_debug_info("msn", "%s is %" G_GSIZE_FORMAT " bytes\n", photo_url_text, len);
-		id = purple_imgstore_new_with_id(g_memdup(photo_data, len), len, NULL);
-		g_snprintf(buf, sizeof(buf), "<img id=\"%d\"><br>", id);
+
+		img = purple_image_new_from_data(g_memdup(photo_data, len), len);
+		img_id = purple_image_store_add_temporary(img);
+		g_object_unref(img);
+
+		g_snprintf(buf, sizeof(buf), "<img id=\""
+			PURPLE_IMAGE_STORE_PROTOCOL "%u\"><br>", img_id);
 		purple_notify_user_info_prepend_pair_html(user_info, NULL, buf);
 	}
 
@@ -2760,8 +2766,6 @@ msn_got_photo(PurpleHttpConnection *http
 #if PHOTO_SUPPORT
 	g_free(photo_url_text);
 	g_free(info2_data);
-	if (id != -1)
-		purple_imgstore_unref_by_id(id);
 #endif
 }
 
diff --git a/libpurple/protocols/msn/object.c b/libpurple/protocols/msn/object.c
--- a/libpurple/protocols/msn/object.c
+++ b/libpurple/protocols/msn/object.c
@@ -125,7 +125,7 @@ msn_object_new_from_string(const char *s
 }
 
 MsnObject*
-msn_object_new_from_image(PurpleStoredImage *img, const char *location,
+msn_object_new_from_image(PurpleImage *img, const char *location,
 		const char *creator, MsnObjectType type)
 {
 	MsnObject *msnobj;
@@ -140,10 +140,10 @@ msn_object_new_from_image(PurpleStoredIm
 	msnobj = NULL;
 
 	if (img == NULL)
-		return msnobj;
+		return NULL;
 
-	size = purple_imgstore_get_size(img);
-	data = purple_imgstore_get_data(img);
+	size = purple_image_get_size(img);
+	data = purple_image_get_data(img);
 
 	/* New object */
 	msnobj = msn_object_new();
@@ -208,7 +208,8 @@ msn_object_destroy(MsnObject *obj, gbool
 	g_free(obj->url);
 	g_free(obj->url1);
 
-	purple_imgstore_unref(obj->img);
+	if (obj->img)
+		g_object_unref(obj->img);
 
 	if (obj->local)
 		local_objs = g_list_remove(local_objs, obj);
@@ -435,18 +436,20 @@ msn_object_set_local(MsnObject *obj)
 }
 
 void
-msn_object_set_image(MsnObject *obj, PurpleStoredImage *img)
+msn_object_set_image(MsnObject *obj, PurpleImage *img)
 {
 	g_return_if_fail(obj != NULL);
 	g_return_if_fail(img != NULL);
 
 	/* obj->local = TRUE; */
 
-	purple_imgstore_unref(obj->img);
-	obj->img = purple_imgstore_ref(img);
+	if (obj->img)
+		g_object_unref(obj->img);
+	g_object_ref(img);
+	obj->img = img;
 }
 
-PurpleStoredImage *
+PurpleImage *
 msn_object_get_image(const MsnObject *obj)
 {
 	MsnObject *local_obj;
diff --git a/libpurple/protocols/msn/object.h b/libpurple/protocols/msn/object.h
--- a/libpurple/protocols/msn/object.h
+++ b/libpurple/protocols/msn/object.h
@@ -36,8 +36,6 @@ typedef enum
 
 #include "internal.h"
 
-#include "imgstore.h"
-
 typedef struct
 {
 	gboolean local;
@@ -45,7 +43,7 @@ typedef struct
 	char *creator;
 	int size;
 	MsnObjectType type;
-	PurpleStoredImage *img;
+	PurpleImage *img;
 	char *location;
 	char *friendly;
 	char *sha1d;
@@ -80,7 +78,7 @@ MsnObject *msn_object_new_from_string(co
  *
  * @return A new MsnObject structure
  */
-MsnObject *msn_object_new_from_image(PurpleStoredImage *img,
+MsnObject *msn_object_new_from_image(PurpleImage *img,
 		const char *location, const char *creator, MsnObjectType type);
 
 /**
@@ -155,7 +153,7 @@ void msn_object_set_sha1c(MsnObject *obj
  * @param obj The object.
  * @param img The image to associate.
  */
-void msn_object_set_image(MsnObject *obj, PurpleStoredImage *img);
+void msn_object_set_image(MsnObject *obj, PurpleImage *img);
 
 /**
  * Sets the url field in a MsnObject.
@@ -250,7 +248,7 @@ const char *msn_object_get_sha1(const Ms
  *
  * @return The associated image.
  */
-PurpleStoredImage *msn_object_get_image(const MsnObject *obj);
+PurpleImage *msn_object_get_image(const MsnObject *obj);
 
 /**
  * Returns a MsnObject's url value.
diff --git a/libpurple/protocols/msn/session.c b/libpurple/protocols/msn/session.c
--- a/libpurple/protocols/msn/session.c
+++ b/libpurple/protocols/msn/session.c
@@ -469,7 +469,7 @@ msn_session_finish_login(MsnSession *ses
 {
 	PurpleAccount *account;
 	PurpleConnection *gc;
-	PurpleStoredImage *img;
+	PurpleImage *img;
 
 	if (!session->logged_in) {
 		account = session->account;
@@ -479,7 +479,7 @@ msn_session_finish_login(MsnSession *ses
 		/* TODO: Do we really want to call this if img is NULL? */
 		msn_user_set_buddy_icon(session->user, img);
 		if (img != NULL)
-			purple_imgstore_unref(img);
+			g_object_unref(img);
 
 		session->logged_in = TRUE;
 		purple_connection_set_state(gc, PURPLE_CONNECTION_CONNECTED);
diff --git a/libpurple/protocols/msn/slp.c b/libpurple/protocols/msn/slp.c
--- a/libpurple/protocols/msn/slp.c
+++ b/libpurple/protocols/msn/slp.c
@@ -210,9 +210,9 @@ request_own_user_display(MsnUser *user)
 	my_obj = msn_user_get_object(user);
 
 	if (my_obj != NULL) {
-		PurpleStoredImage *img = msn_object_get_image(my_obj);
-		data = purple_imgstore_get_data(img);
-		len = purple_imgstore_get_size(img);
+		PurpleImage *img = msn_object_get_image(my_obj);
+		data = purple_image_get_data(img);
+		len = purple_image_get_size(img);
 		info = msn_object_get_sha1(my_obj);
 	}
 
diff --git a/libpurple/protocols/msn/slpcall.c b/libpurple/protocols/msn/slpcall.c
--- a/libpurple/protocols/msn/slpcall.c
+++ b/libpurple/protocols/msn/slpcall.c
@@ -235,7 +235,7 @@ get_token(const char *str, const char *s
  *
  * Note: it should be tracked on the msn prpl side.
  */
-static PurpleStoredImage *
+static PurpleImage *
 find_valid_emoticon(PurpleAccount *account, const char *path)
 {
 	GList *smileys, *it;
@@ -249,11 +249,11 @@ find_valid_emoticon(PurpleAccount *accou
 		PurpleSmiley *smiley = it->data;
 
 		if (g_strcmp0(path, purple_smiley_get_path(smiley)) == 0) {
-			PurpleStoredImage *img;
+			PurpleImage *img;
 
 			g_list_free(smileys);
 			img = purple_smiley_get_image(smiley);
-			purple_imgstore_ref(img);
+			g_object_ref(img);
 			return img;
 		}
 	}
@@ -469,7 +469,7 @@ got_sessionreq(MsnSlpCall *slpcall, cons
 		MsnSlpMessage *slpmsg;
 		MsnObject *obj;
 		char *msnobj_data;
-		PurpleStoredImage *img = NULL;
+		PurpleImage *img = NULL;
 		int type;
 
 		/* Send Ok */
@@ -492,7 +492,7 @@ got_sessionreq(MsnSlpCall *slpcall, cons
 		} else if (type == MSN_OBJECT_USERTILE) {
 			img = msn_object_get_image(obj);
 			if (img)
-				purple_imgstore_ref(img);
+				g_object_ref(img);
 		}
 		msn_object_destroy(obj, FALSE);
 
@@ -504,7 +504,7 @@ got_sessionreq(MsnSlpCall *slpcall, cons
 			/* DATA */
 			slpmsg = msn_slpmsg_obj_new(slpcall, img);
 			msn_slplink_queue_slpmsg(slplink, slpmsg);
-			purple_imgstore_unref(img);
+			g_object_unref(img);
 
 			accepted = TRUE;
 
diff --git a/libpurple/protocols/msn/slpmsg.c b/libpurple/protocols/msn/slpmsg.c
--- a/libpurple/protocols/msn/slpmsg.c
+++ b/libpurple/protocols/msn/slpmsg.c
@@ -68,12 +68,14 @@ msn_slpmsg_destroy(MsnSlpMessage *slpmsg
 
 	slplink = slpmsg->slplink;
 
-	purple_imgstore_unref(slpmsg->img);
 
-	/* We don't want to free the data of the PurpleStoredImage,
-	 * but to avoid code duplication, it's sharing buffer. */
-	if (slpmsg->img == NULL)
+	if (slpmsg->img)
+		g_object_unref(slpmsg->img);
+	else {
+		/* We don't want to free the data of the PurpleImage,
+		 * but to avoid code duplication, it's sharing buffer. */
 		g_free(slpmsg->buffer);
+	}
 
 	for (cur = slpmsg->parts; cur != NULL; cur = g_list_delete_link(cur, cur))
 	{
@@ -125,16 +127,17 @@ msn_slpmsg_set_body(MsnSlpMessage *slpms
 }
 
 void
-msn_slpmsg_set_image(MsnSlpMessage *slpmsg, PurpleStoredImage *img)
+msn_slpmsg_set_image(MsnSlpMessage *slpmsg, PurpleImage *img)
 {
 	/* We can only have one data source at a time. */



More information about the Commits mailing list