/pidgin/main: 261f7d7810dd: imgstore: unref mxit
Tomasz Wasilczyk
twasilczyk at pidgin.im
Fri Apr 11 14:51:20 EDT 2014
Changeset: 261f7d7810dde6638906ce4981a8fe1757e7fa3f
Author: Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date: 2014-04-11 20:51 +0200
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/261f7d7810dd
Description:
imgstore: unref mxit
diffstat:
libpurple/protocols/mxit/formcmds.c | 28 ++++-----
libpurple/protocols/mxit/login.c | 2 +-
libpurple/protocols/mxit/markup.c | 89 ++++++++++++--------------------
libpurple/protocols/mxit/mxit.c | 17 ++++--
libpurple/protocols/mxit/mxit.h | 4 +-
libpurple/protocols/mxit/profile.c | 10 ++-
libpurple/protocols/mxit/protocol.c | 7 ++-
libpurple/protocols/mxit/roster.c | 4 +
libpurple/protocols/mxit/roster.h | 3 +-
libpurple/protocols/mxit/splashscreen.c | 18 +++---
10 files changed, 88 insertions(+), 94 deletions(-)
diffs (truncated from 486 to 300 lines):
diff --git a/libpurple/protocols/mxit/formcmds.c b/libpurple/protocols/mxit/formcmds.c
--- a/libpurple/protocols/mxit/formcmds.c
+++ b/libpurple/protocols/mxit/formcmds.c
@@ -27,6 +27,7 @@
#include "internal.h"
#include "debug.h"
#include "http.h"
+#include "image-store.h"
#include "protocol.h"
#include "mxit.h"
@@ -81,8 +82,7 @@ mxit_cb_ii_returned(PurpleHttpConnection
gpointer _iireq)
{
struct ii_url_request* iireq = _iireq;
- int* intptr = NULL;
- int id;
+ PurpleImage *img;
const gchar* data;
size_t len;
@@ -97,19 +97,15 @@ mxit_cb_ii_returned(PurpleHttpConnection
}
/* lets first see if we don't have the inline image already in cache */
- if (g_hash_table_lookup(iireq->mx->session->iimages, iireq->url)) {
+ if (g_hash_table_lookup(iireq->mx->session->inline_images, iireq->url)) {
/* inline image found in the cache, so we just ignore this reply */
goto done;
}
/* we now have the inline image, store a copy in the imagestore */
data = purple_http_response_get_data(response, &len);
- id = purple_imgstore_new_with_id(g_memdup(data, len), len, NULL);
-
- /* map the inline image id to purple image id */
- intptr = g_malloc(sizeof(int));
- *intptr = id;
- g_hash_table_insert(iireq->mx->session->iimages, iireq->url, intptr);
+ img = purple_image_new_from_data(g_memdup(data, len), len);
+ g_hash_table_insert(iireq->mx->session->inline_images, iireq->url, img);
iireq->mx->flags |= PURPLE_MESSAGE_IMAGES;
@@ -326,16 +322,18 @@ static void command_image(struct RXMsgDa
const char* reply;
guchar* rawimg;
gsize rawimglen;
- int imgid;
img = g_hash_table_lookup(hash, "dat");
if (img) {
+ PurpleImage *pimg;
+ guint pimg_id;
+
rawimg = purple_base64_decode(img, &rawimglen);
//purple_util_write_data_to_file_absolute("/tmp/mxitinline.png", (char*) rawimg, rawimglen);
- imgid = purple_imgstore_new_with_id(rawimg, rawimglen, NULL);
- g_string_append_printf(msg,
- "<img src=\"" PURPLE_STORED_IMAGE_PROTOCOL "%i\">",
- imgid);
+ pimg = purple_image_new_from_data(rawimg, rawimglen);
+ pimg_id = purple_image_store_add(pimg);
+ g_string_append_printf(msg, "<img src=\""
+ PURPLE_IMAGE_STORE_PROTOCOL "%u\">", pimg_id);
mx->flags |= PURPLE_MESSAGE_IMAGES;
}
else {
@@ -351,7 +349,7 @@ static void command_image(struct RXMsgDa
mx->got_img = TRUE;
/* lets first see if we don't have the inline image already in cache */
- if (g_hash_table_lookup(mx->session->iimages, iireq->url)) {
+ if (g_hash_table_lookup(mx->session->inline_images, iireq->url)) {
/* inline image found in the cache, so we do not have to request it from the web */
g_free(iireq);
}
diff --git a/libpurple/protocols/mxit/login.c b/libpurple/protocols/mxit/login.c
--- a/libpurple/protocols/mxit/login.c
+++ b/libpurple/protocols/mxit/login.c
@@ -87,7 +87,7 @@ static struct MXitSession* mxit_create_o
g_strlcpy( session->clientkey, purple_account_get_string( account, MXIT_CONFIG_CLIENTKEY, "" ), sizeof( session->clientkey ) );
g_strlcpy( session->dialcode, purple_account_get_string( account, MXIT_CONFIG_DIALCODE, "" ), sizeof( session->dialcode ) );
session->http = purple_account_get_bool( account, MXIT_CONFIG_USE_HTTP, FALSE );
- session->iimages = g_hash_table_new( g_str_hash, g_str_equal );
+ session->inline_images = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_object_unref);
session->rx_state = RX_STATE_RLEN;
session->http_interval = MXIT_HTTP_POLL_MIN;
session->http_last_poll = mxit_now_milli();
diff --git a/libpurple/protocols/mxit/markup.c b/libpurple/protocols/mxit/markup.c
--- a/libpurple/protocols/mxit/markup.c
+++ b/libpurple/protocols/mxit/markup.c
@@ -26,6 +26,7 @@
#include "internal.h"
#include "debug.h"
#include "http.h"
+#include "image-store.h"
#include "protocol.h"
#include "mxit.h"
@@ -378,12 +379,13 @@ void mxit_show_message( struct RXMsgData
int emo_ofs;
char* ii;
char tag[64];
- int* img_id;
if ( mx->got_img ) {
/* search and replace all emoticon tags with proper image tags */
while ( ( pos = strstr( mx->msg->str, MXIT_II_TAG ) ) != NULL ) {
+ PurpleImage *img;
+
start = pos - mx->msg->str; /* offset at which MXIT_II_TAG starts */
emo_ofs = start + strlen( MXIT_II_TAG ); /* offset at which EMO's ID starts */
end = emo_ofs + 1; /* offset at which MXIT_II_TAG ends */
@@ -400,16 +402,18 @@ void mxit_show_message( struct RXMsgData
g_string_erase( mx->msg, start, ( end - start ) + 1 );
/* find the image entry */
- img_id = (int*) g_hash_table_lookup( mx->session->iimages, ii );
- if ( !img_id ) {
+ img = g_hash_table_lookup(mx->session->inline_images, ii);
+ if (img == NULL) {
/* inline image not found, so we will just skip it */
purple_debug_error( MXIT_PLUGIN_ID, "inline image NOT found (%s)\n", ii );
- }
- else {
+ } else {
+ guint img_id;
+
+ img_id = purple_image_store_add_temporary(img);
/* insert img tag */
- g_snprintf( tag, sizeof( tag ),
- "<img src=\"" PURPLE_STORED_IMAGE_PROTOCOL "%i\">",
- *img_id );
+ g_snprintf(tag, sizeof(tag), "<img src=\""
+ PURPLE_IMAGE_STORE_PROTOCOL "%u\">",
+ img_id);
g_string_insert( mx->msg, start, tag );
}
@@ -471,16 +475,15 @@ static void parse_emoticon_str( const ch
static void emoticon_returned(PurpleHttpConnection *http_conn,
PurpleHttpResponse *response, gpointer user_data)
{
+ PurpleImage *img;
struct RXMsgData* mx = (struct RXMsgData*) user_data;
const gchar* data;
size_t len;
unsigned int pos = 0;
- int id;
char* str;
int em_size = 0;
char* em_data = NULL;
char* em_id = NULL;
- int* intptr = NULL;
int res;
purple_debug_info( MXIT_PLUGIN_ID, "emoticon_returned\n" );
@@ -576,7 +579,7 @@ static void emoticon_returned(PurpleHttp
strcpy( em_id, emo );
}
- if ( g_hash_table_lookup( mx->session->iimages, em_id ) ) {
+ if (g_hash_table_lookup(mx->session->inline_images, em_id)) {
/* emoticon found in the table, so ignore this one */
g_free( em_id );
goto done;
@@ -586,13 +589,9 @@ static void emoticon_returned(PurpleHttp
em_data = g_malloc( em_size );
memcpy( em_data, &data[pos], em_size );
- /* we now have the emoticon, store it in the imagestore */
- id = purple_imgstore_new_with_id( em_data, em_size, NULL );
-
- /* map the mxit emoticon id to purple image id */
- intptr = g_malloc( sizeof( int ) );
- *intptr = id;
- g_hash_table_insert( mx->session->iimages, em_id, intptr );
+ /* map the mxit emoticon id to purple image */
+ img = purple_image_new_from_data(em_data, em_size);
+ g_hash_table_insert(mx->session->inline_images, em_id, img);
mx->flags |= PURPLE_MESSAGE_IMAGES;
done:
@@ -886,7 +885,7 @@ void mxit_parse_markup( struct RXMsgData
if ( tmpstr1[0] != '\0' ) {
mx->got_img = TRUE;
- if ( g_hash_table_lookup( mx->session->iimages, tmpstr1 ) ) {
+ if (g_hash_table_lookup(mx->session->inline_images, tmpstr1)) {
/* emoticon found in the cache, so we do not have to request it from the WAPsite */
}
else {
@@ -1007,21 +1006,22 @@ void mxit_parse_markup( struct RXMsgData
* Insert an inline image command.
*
* @param mx The message text as processed so far.
- * @oaram id The imgstore ID of the inline image.
+ * @oaram id The image store ID of the inline image.
*/
-static void inline_image_add( GString* mx, int id )
+static void
+inline_image_add(GString* mx, guint id)
{
- PurpleStoredImage *image;
+ PurpleImage *image;
gconstpointer img_data;
gsize img_size;
gchar* enc;
- image = purple_imgstore_find_by_id( id );
- if ( image == NULL )
+ image = purple_image_store_get(id);
+ if (image == NULL)
return;
- img_data = purple_imgstore_get_data( image );
- img_size = purple_imgstore_get_size( image );
+ img_data = purple_image_get_data(image);
+ img_size = purple_image_get_size(image);
enc = purple_base64_encode( img_data, img_size );
@@ -1132,12 +1132,15 @@ char* mxit_convert_markup_tx( const char
tagstack = g_list_remove( tagstack, tag );
g_free( tag );
}
- }
- else if ( purple_str_has_prefix( &message[i], "<IMG SRC=" PURPLE_STORED_IMAGE_PROTOCOL) ) {
+ } else if (purple_str_has_prefix(&message[i],
+ "<img src=\"" PURPLE_IMAGE_STORE_PROTOCOL))
+ {
/* inline image */
- int imgid;
+ guint imgid;
- if ( sscanf( &message[i+sizeof("<IMG SRC=" PURPLE_STORED_IMAGE_PROTOCOL)-1], "%i", &imgid ) ) {
+ if (sscanf(&message[i + sizeof("<img src=\""
+ PURPLE_IMAGE_STORE_PROTOCOL)-1], "%u", &imgid))
+ {
inline_image_add( mx, imgid );
*msgtype = CP_MSGTYPE_COMMAND; /* inline image must be sent as a MXit command */
}
@@ -1189,35 +1192,11 @@ char* mxit_convert_markup_tx( const char
/*------------------------------------------------------------------------
- * Free an emoticon entry.
- *
- * @param key MXit emoticon ID
- * @param value Imagestore ID for emoticon
- * @param user_data NULL (unused)
- * @return TRUE
- */
-static gboolean emoticon_entry_free( gpointer key, gpointer value, gpointer user_data )
-{
- int* imgid = value;
-
- /* key is a string */
- g_free( key );
-
- /* value is 'id' in imagestore */
- purple_imgstore_unref_by_id( *imgid );
- g_free( value );
-
- return TRUE;
-}
-
-
-/*------------------------------------------------------------------------
* Free all entries in the emoticon cache.
*
* @param session The MXit session object
*/
void mxit_free_emoticon_cache( struct MXitSession* session )
{
- g_hash_table_foreach_remove( session->iimages, emoticon_entry_free, NULL );
- g_hash_table_destroy ( session->iimages );
+ g_hash_table_destroy(session->inline_images);
}
diff --git a/libpurple/protocols/mxit/mxit.c b/libpurple/protocols/mxit/mxit.c
--- a/libpurple/protocols/mxit/mxit.c
+++ b/libpurple/protocols/mxit/mxit.c
@@ -495,6 +495,8 @@ static void mxit_free_buddy( PurpleBuddy
g_free( contact->avatarId );
if ( contact->msg )
g_free( contact->msg );
+ if (contact->image)
+ g_object_unref(contact->image);
g_free( contact );
}
@@ -536,14 +538,17 @@ static void mxit_keepalive( PurpleConnec
* @param gc The connection object
* @param img The buddy icon data
*/
-static void mxit_set_buddy_icon( PurpleConnection *gc, PurpleStoredImage *img )
+static void
+mxit_set_buddy_icon(PurpleConnection *gc, PurpleImage *img)
More information about the Commits
mailing list