/pidgin/main: 268a9d3b3fd7: imgstore: unref xmpp
Tomasz Wasilczyk
twasilczyk at pidgin.im
Thu Apr 10 19:38:43 EDT 2014
Changeset: 268a9d3b3fd725c8522f00bb753f2dbaa1d318a1
Author: Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date: 2014-04-11 01:38 +0200
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/268a9d3b3fd7
Description:
imgstore: unref xmpp
diffstat:
libpurple/protocols/jabber/buddy.c | 41 ++++++++++++++++++--------------
libpurple/protocols/jabber/buddy.h | 2 +-
libpurple/protocols/jabber/jabber.c | 11 ++++----
libpurple/protocols/jabber/jabber.h | 2 -
libpurple/protocols/jabber/message.c | 34 ++++++++------------------
libpurple/protocols/jabber/useravatar.c | 24 ++++++++++--------
libpurple/protocols/jabber/useravatar.h | 4 +-
7 files changed, 55 insertions(+), 63 deletions(-)
diffs (truncated from 327 to 300 lines):
diff --git a/libpurple/protocols/jabber/buddy.c b/libpurple/protocols/jabber/buddy.c
--- a/libpurple/protocols/jabber/buddy.c
+++ b/libpurple/protocols/jabber/buddy.c
@@ -22,7 +22,7 @@
*/
#include "internal.h"
#include "debug.h"
-#include "imgstore.h"
+#include "image-store.h"
#include "prpl.h"
#include "notify.h"
#include "request.h"
@@ -51,7 +51,7 @@ typedef struct {
GSList *ids;
GHashTable *resources;
guint timeout_handle;
- GSList *vcard_imgids;
+ GSList *vcard_images;
PurpleNotifyUserInfo *user_info;
long last_seconds;
gchar *last_message;
@@ -459,7 +459,7 @@ static PurpleXmlNode *insert_tag_to_pare
*/
void jabber_set_info(PurpleConnection *gc, const char *info)
{
- PurpleStoredImage *img;
+ PurpleImage *img;
JabberIq *iq;
JabberStream *js = purple_connection_get_protocol_data(gc);
PurpleXmlNode *vc_node;
@@ -468,14 +468,14 @@ void jabber_set_info(PurpleConnection *g
/* if we haven't grabbed the remote vcard yet, we can't
* assume that what we have here is correct */
if(!js->vcard_fetched) {
- PurpleStoredImage *image;
+ PurpleImage *image;
g_free(js->initial_avatar_hash);
image = purple_buddy_icons_find_account_icon(purple_connection_get_account(gc));
if (image != NULL) {
- js->initial_avatar_hash =
- jabber_calculate_data_hash(purple_imgstore_get_data(image),
- purple_imgstore_get_size(image), "sha1");
- purple_imgstore_unref(image);
+ js->initial_avatar_hash = jabber_calculate_data_hash(
+ purple_image_get_data(image),
+ purple_image_get_size(image), "sha1");
+ g_object_unref(image);
} else {
js->initial_avatar_hash = NULL;
}
@@ -513,8 +513,8 @@ void jabber_set_info(PurpleConnection *g
purple_xmlnode_set_attrib(vc_node, tag_attr->attr, tag_attr->value);
}
- avatar_data = purple_imgstore_get_data(img);
- avatar_len = purple_imgstore_get_size(img);
+ avatar_data = purple_image_get_data(img);
+ avatar_len = purple_image_get_size(img);
/* Get rid of an old PHOTO if one exists.
* TODO: This may want to be modified to remove all old PHOTO
* children, at the moment some people have managed to get
@@ -533,7 +533,7 @@ void jabber_set_info(PurpleConnection *g
purple_xmlnode_insert_data(binval, enc, -1);
g_free(enc);
- purple_imgstore_unref(img);
+ g_object_unref(img);
} else if (vc_node) {
PurpleXmlNode *photo;
/* TODO: Remove all PHOTO children? (see above note) */
@@ -552,7 +552,7 @@ void jabber_set_info(PurpleConnection *g
}
}
-void jabber_set_buddy_icon(PurpleConnection *gc, PurpleStoredImage *img)
+void jabber_set_buddy_icon(PurpleConnection *gc, PurpleImage *img)
{
PurpleAccount *account = purple_connection_get_account(gc);
@@ -877,9 +877,9 @@ static void jabber_buddy_info_show_if_re
purple_notify_userinfo(jbi->js->gc, jbi->jid, user_info, NULL, NULL);
- while (jbi->vcard_imgids) {
- purple_imgstore_unref_by_id(GPOINTER_TO_INT(jbi->vcard_imgids->data));
- jbi->vcard_imgids = g_slist_delete_link(jbi->vcard_imgids, jbi->vcard_imgids);
+ while (jbi->vcard_images) {
+ g_object_unref(jbi->vcard_images->data);
+ jbi->vcard_images = g_slist_delete_link(jbi->vcard_images, jbi->vcard_images);
}
jbi->js->pending_buddy_info_requests = g_slist_remove(jbi->js->pending_buddy_info_requests, jbi);
@@ -1200,12 +1200,17 @@ static void jabber_vcard_parse(JabberStr
data = purple_base64_decode(bintext, &size);
if (data) {
+ PurpleImage *img;
+ guint img_id;
char *img_text;
char *hash;
- jbi->vcard_imgids = g_slist_prepend(jbi->vcard_imgids, GINT_TO_POINTER(purple_imgstore_new_with_id(g_memdup(data, size), size, "logo.png")));
- img_text = g_strdup_printf("<img src='" PURPLE_STORED_IMAGE_PROTOCOL "%d'>",
- GPOINTER_TO_INT(jbi->vcard_imgids->data));
+ img = purple_image_new_from_data(g_memdup(data, size), size);
+ img_id = purple_image_store_add(img);
+
+ jbi->vcard_images = g_slist_prepend(jbi->vcard_images, img);
+ img_text = g_strdup_printf("<img src='"
+ PURPLE_IMAGE_STORE_PROTOCOL "%u'>", img_id);
purple_notify_user_info_add_pair_html(user_info, (photo ? _("Photo") : _("Logo")), img_text);
diff --git a/libpurple/protocols/jabber/buddy.h b/libpurple/protocols/jabber/buddy.h
--- a/libpurple/protocols/jabber/buddy.h
+++ b/libpurple/protocols/jabber/buddy.h
@@ -104,7 +104,7 @@ GList *jabber_blist_node_menu(PurpleBlis
void jabber_set_info(PurpleConnection *gc, const char *info);
void jabber_setup_set_info(PurplePluginAction *action);
-void jabber_set_buddy_icon(PurpleConnection *gc, PurpleStoredImage *img);
+void jabber_set_buddy_icon(PurpleConnection *gc, PurpleImage *img);
void jabber_user_search(JabberStream *js, const char *directory);
void jabber_user_search_begin(PurplePluginAction *);
diff --git a/libpurple/protocols/jabber/jabber.c b/libpurple/protocols/jabber/jabber.c
--- a/libpurple/protocols/jabber/jabber.c
+++ b/libpurple/protocols/jabber/jabber.c
@@ -32,7 +32,6 @@
#include "debug.h"
#include "dnssrv.h"
#include "http.h"
-#include "imgstore.h"
#include "message.h"
#include "notify.h"
#include "pluginpref.h"
@@ -1083,7 +1082,7 @@ jabber_login(PurpleAccount *account)
{
PurpleConnection *gc = purple_account_get_connection(account);
JabberStream *js;
- PurpleStoredImage *image;
+ PurpleImage *image;
purple_connection_set_flags(gc, PURPLE_CONNECTION_FLAG_HTML | PURPLE_CONNECTION_FLAG_ALLOW_CUSTOM_SMILEY);
js = jabber_stream_new(account);
@@ -1101,10 +1100,10 @@ jabber_login(PurpleAccount *account)
*/
image = purple_buddy_icons_find_account_icon(account);
if (image != NULL) {
- js->initial_avatar_hash =
- jabber_calculate_data_hash(purple_imgstore_get_data(image),
- purple_imgstore_get_size(image), "sha1");
- purple_imgstore_unref(image);
+ js->initial_avatar_hash = jabber_calculate_data_hash(
+ purple_image_get_data(image),
+ purple_image_get_size(image), "sha1");
+ g_object_unref(image);
}
jabber_stream_connect(js);
diff --git a/libpurple/protocols/jabber/jabber.h b/libpurple/protocols/jabber/jabber.h
--- a/libpurple/protocols/jabber/jabber.h
+++ b/libpurple/protocols/jabber/jabber.h
@@ -54,8 +54,6 @@ typedef enum {
typedef struct _JabberStream JabberStream;
-#include "imgstore.h" /* TODO: temp */
-
#include <libxml/parser.h>
#include <glib.h>
#include "circularbuffer.h"
diff --git a/libpurple/protocols/jabber/message.c b/libpurple/protocols/jabber/message.c
--- a/libpurple/protocols/jabber/message.c
+++ b/libpurple/protocols/jabber/message.c
@@ -833,22 +833,6 @@ void jabber_message_parse(JabberStream *
jabber_message_free(jm);
}
-static const gchar *
-jabber_message_get_mimetype_from_ext(const gchar *ext)
-{
- if (strcmp(ext, "png") == 0) {
- return "image/png";
- } else if (strcmp(ext, "gif") == 0) {
- return "image/gif";
- } else if (strcmp(ext, "jpg") == 0) {
- return "image/jpeg";
- } else if (strcmp(ext, "tif") == 0) {
- return "image/tif";
- } else {
- return "image/x-icon"; /* or something... */
- }
-}
-
static gboolean
jabber_conv_support_custom_smileys(JabberStream *js,
PurpleConversation *conv,
@@ -927,7 +911,7 @@ jabber_message_smileyfy_xhtml(JabberMess
for (it = found_smileys; it; it = it_next) {
PurpleSmiley *smiley = it->data;
- PurpleStoredImage *smiley_image;
+ PurpleImage *smiley_image;
gboolean valid = TRUE;
it_next = g_list_next(it);
@@ -937,7 +921,7 @@ jabber_message_smileyfy_xhtml(JabberMess
valid = FALSE;
purple_debug_warning("jabber", "broken smiley %s",
purple_smiley_get_shortcut(smiley));
- } else if (purple_imgstore_get_size(smiley_image) >
+ } else if (purple_image_get_size(smiley_image) >
JABBER_DATA_MAX_SIZE)
{
has_too_large_smiley = TRUE;
@@ -963,7 +947,7 @@ jabber_message_smileyfy_xhtml(JabberMess
for (it = found_smileys; it; it = g_list_next(it)) {
PurpleSmiley *smiley = it->data;
- PurpleStoredImage *smiley_image;
+ PurpleImage *smiley_image;
const gchar *shortcut = purple_smiley_get_shortcut(smiley);
const gchar *mimetype;
JabberData *jdata;
@@ -975,12 +959,16 @@ jabber_message_smileyfy_xhtml(JabberMess
smiley_image = purple_smiley_get_image(smiley);
g_assert(smiley_image != NULL);
- mimetype = jabber_message_get_mimetype_from_ext(
- purple_imgstore_get_extension(smiley_image));
+ mimetype = purple_image_get_mimetype(smiley_image);
+ if (!mimetype) {
+ purple_debug_error("jabber",
+ "unknown mime type for image");
+ continue;
+ }
jdata = jabber_data_create_from_data(
- purple_imgstore_get_data(smiley_image),
- purple_imgstore_get_size(smiley_image),
+ purple_image_get_data(smiley_image),
+ purple_image_get_size(smiley_image),
mimetype, FALSE, jm->js);
purple_debug_info("jabber", "cache local smiley alt=%s, cid=%s",
diff --git a/libpurple/protocols/jabber/useravatar.c b/libpurple/protocols/jabber/useravatar.c
--- a/libpurple/protocols/jabber/useravatar.c
+++ b/libpurple/protocols/jabber/useravatar.c
@@ -87,7 +87,7 @@ remove_avatar_0_12_nodes(JabberStream *j
jabber_pep_delete_node(js, NS_AVATAR_0_12_DATA);
}
-void jabber_avatar_set(JabberStream *js, PurpleStoredImage *img)
+void jabber_avatar_set(JabberStream *js, PurpleImage *img)
{
PurpleXmlNode *publish, *metadata, *item;
@@ -130,8 +130,8 @@ void jabber_avatar_set(JabberStream *js,
} ihdr;
} *png = NULL;
- if (purple_imgstore_get_size(img) > sizeof(*png))
- png = purple_imgstore_get_data(img);
+ if (purple_image_get_size(img) > sizeof(*png))
+ png = purple_image_get_data(img);
/* check if the data is a valid png file (well, at least to some extent) */
if(png && png->signature[0] == 0x89 &&
@@ -154,11 +154,12 @@ void jabber_avatar_set(JabberStream *js,
char *lengthstring, *widthstring, *heightstring;
/* compute the sha1 hash */
- char *hash = jabber_calculate_data_hash(purple_imgstore_get_data(img),
- purple_imgstore_get_size(img),
- "sha1");
- char *base64avatar = purple_base64_encode(purple_imgstore_get_data(img),
- purple_imgstore_get_size(img));
+ char *hash = jabber_calculate_data_hash(
+ purple_image_get_data(img),
+ purple_image_get_size(img), "sha1");
+ char *base64avatar = purple_base64_encode(
+ purple_image_get_data(img),
+ purple_image_get_size(img));
publish = purple_xmlnode_new("publish");
purple_xmlnode_set_attrib(publish, "node", NS_AVATAR_1_1_DATA);
@@ -176,7 +177,7 @@ void jabber_avatar_set(JabberStream *js,
g_free(base64avatar);
lengthstring = g_strdup_printf("%" G_GSIZE_FORMAT,
- purple_imgstore_get_size(img));
+ purple_image_get_size(img));
widthstring = g_strdup_printf("%u", width);
heightstring = g_strdup_printf("%u", height);
@@ -237,9 +238,10 @@ do_got_own_avatar_cb(JabberStream *js, c
*/
if ((!items || !metadata) ||
!purple_strequal(server_hash, js->initial_avatar_hash)) {
More information about the Commits
mailing list