--- 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 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 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], "<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 @@ /*------------------------------------------------------------------------ - * 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); }