diff -r c7c855c36c9b -r 261f7d7810dd libpurple/protocols/mxit/markup.c
--- a/libpurple/protocols/mxit/markup.c Fri Apr 11 20:08:22 2014 +0200
+++ b/libpurple/protocols/mxit/markup.c Fri Apr 11 20:51:11 2014 +0200
@@ -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 @@
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 @@
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_id );
+ g_snprintf(tag, sizeof(tag), "
",
+ img_id);
g_string_insert( mx->msg, start, tag );
}
@@ -471,16 +475,15 @@
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 @@
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 @@
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 @@
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 @@
* 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 @@
tagstack = g_list_remove( tagstack, tag );
g_free( tag );
}
- }
- else if ( purple_str_has_prefix( &message[i], "
iimages, emoticon_entry_free, NULL );
- g_hash_table_destroy ( session->iimages );
+ g_hash_table_destroy(session->inline_images);
}