/pidgin/main: 86b7a6d3d267: PurpleImage: use purple_image_store_...
Tomasz Wasilczyk
twasilczyk at pidgin.im
Fri Apr 11 17:16:31 EDT 2014
Changeset: 86b7a6d3d2671c2bc3ecf685a1f157634fa4fa61
Author: Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date: 2014-04-11 23:16 +0200
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/86b7a6d3d267
Description:
PurpleImage: use purple_image_store_get_from_uri where possible
diffstat:
libpurple/image-store.c | 10 +++++++++-
libpurple/protocols/gg/message-prpl.c | 12 +++---------
libpurple/protocols/mxit/markup.c | 21 ++++++++-------------
libpurple/protocols/oscar/oscar.c | 10 ++--------
pidgin/gtkwebview.c | 11 ++---------
5 files changed, 24 insertions(+), 40 deletions(-)
diffs (143 lines):
diff --git a/libpurple/image-store.c b/libpurple/image-store.c
--- a/libpurple/image-store.c
+++ b/libpurple/image-store.c
@@ -158,12 +158,16 @@ purple_image_store_get(guint id)
return g_hash_table_lookup(id_to_image, GINT_TO_POINTER(id));
}
+/* TODO: handle PURPLE_IMAGE_STORE_STOCK_PROTOCOL */
PurpleImage *
purple_image_store_get_from_uri(const gchar *uri)
{
guint64 longid;
guint id;
gchar *endptr;
+ gchar endchar;
+
+ g_return_val_if_fail(uri != NULL, NULL);
if (!purple_str_has_prefix(uri, PURPLE_IMAGE_STORE_PROTOCOL))
return NULL;
@@ -173,8 +177,12 @@ purple_image_store_get_from_uri(const gc
return NULL;
longid = g_ascii_strtoull(uri, &endptr, 10);
- if (endptr[0] != '\0')
+ endchar = endptr[0];
+ if (endchar != '\0' && endchar != '"' &&
+ endchar != '\'' && endchar != ' ')
+ {
return NULL;
+ }
id = longid;
if (id != longid)
diff --git a/libpurple/protocols/gg/message-prpl.c b/libpurple/protocols/gg/message-prpl.c
--- a/libpurple/protocols/gg/message-prpl.c
+++ b/libpurple/protocols/gg/message-prpl.c
@@ -576,15 +576,9 @@ gchar * ggp_message_format_to_gg(PurpleC
ggp_image_prepare_result res = -1;
PurpleImage *image = NULL;
- if ((val = g_hash_table_lookup(attribs, "src")) != NULL
- && g_str_has_prefix(val,
- PURPLE_IMAGE_STORE_PROTOCOL))
- {
- guint image_id;
- val += strlen(PURPLE_IMAGE_STORE_PROTOCOL);
- if (sscanf(val, "%u", &image_id) == 1)
- image = purple_image_store_get(image_id);
- }
+ val = g_hash_table_lookup(attribs, "src");
+ if (val)
+ image = purple_image_store_get_from_uri(val);
if (image != NULL)
res = ggp_image_prepare(conv, image, &id);
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
@@ -1005,21 +1005,16 @@ void mxit_parse_markup( struct RXMsgData
/*------------------------------------------------------------------------
* Insert an inline image command.
*
- * @param mx The message text as processed so far.
- * @oaram id The image store ID of the inline image.
+ * @param mx The message text as processed so far.
+ * @oaram image The PurpleImage of the inline image.
*/
static void
-inline_image_add(GString* mx, guint id)
+inline_image_add(GString* mx, PurpleImage *image)
{
- PurpleImage *image;
gconstpointer img_data;
gsize img_size;
gchar* enc;
- image = purple_image_store_get(id);
- if (image == NULL)
- return;
-
img_data = purple_image_get_data(image);
img_size = purple_image_get_size(image);
@@ -1136,12 +1131,12 @@ char* mxit_convert_markup_tx( const char
"<img src=\"" PURPLE_IMAGE_STORE_PROTOCOL))
{
/* inline image */
- guint imgid;
+ PurpleImage *img;
+ img = purple_image_store_get_from_uri(
+ &message[i + sizeof("<img src=\"") - 1]);
- if (sscanf(&message[i + sizeof("<img src=\""
- PURPLE_IMAGE_STORE_PROTOCOL)-1], "%u", &imgid))
- {
- inline_image_add( mx, imgid );
+ if (img) {
+ inline_image_add(mx, img);
*msgtype = CP_MSGTYPE_COMMAND; /* inline image must be sent as a MXit command */
}
}
diff --git a/libpurple/protocols/oscar/oscar.c b/libpurple/protocols/oscar/oscar.c
--- a/libpurple/protocols/oscar/oscar.c
+++ b/libpurple/protocols/oscar/oscar.c
@@ -3011,14 +3011,8 @@ purple_odc_send_im(PeerConnection *conn,
}
src = g_datalist_get_data(&attribs, "src");
-
- if (src != NULL && purple_str_has_caseprefix(src,
- PURPLE_IMAGE_STORE_PROTOCOL))
- {
- guint imgid = atoi(src +
- sizeof(PURPLE_IMAGE_STORE_PROTOCOL) - 1);
- image = purple_image_store_get(imgid);
- }
+ if (src)
+ image = purple_image_store_get_from_uri(src);
/* ... if it refers to a valid purple image ... */
if (image) {
diff --git a/pidgin/gtkwebview.c b/pidgin/gtkwebview.c
--- a/pidgin/gtkwebview.c
+++ b/pidgin/gtkwebview.c
@@ -148,15 +148,8 @@ webview_resource_loading(WebKitWebView *
const gchar *path;
uri = webkit_network_request_get_uri(request);
- if (purple_str_has_prefix(uri, PURPLE_IMAGE_STORE_PROTOCOL)) {
- guint id;
-
- uri += sizeof(PURPLE_IMAGE_STORE_PROTOCOL) - 1;
- id = strtoul(uri, NULL, 10);
-
- img = purple_image_store_get(id);
- if (!img)
- return;
+ if ((img = purple_image_store_get_from_uri(uri)) != NULL) {
+ /* noop */
} else if (purple_str_has_prefix(uri, PURPLE_IMAGE_STORE_STOCK_PROTOCOL)) {
gchar *p_uri, *found;
const gchar *domain, *stock_name;
More information about the Commits
mailing list