/pidgin/main: a7bfc2479cbd: imgstore: unref silc; fix inline ima...
Tomasz Wasilczyk
twasilczyk at pidgin.im
Fri Apr 11 19:13:30 EDT 2014
Changeset: a7bfc2479cbda177bd8d978cf7e84f61d062835c
Author: Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date: 2014-04-12 01:13 +0200
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/a7bfc2479cbd
Description:
imgstore: unref silc; fix inline images in silc
diffstat:
libpurple/protocols/silc/buddy.c | 26 +++++++++----------
libpurple/protocols/silc/ops.c | 42 ++++++++++++++++----------------
libpurple/protocols/silc/silc.c | 8 +++---
libpurple/protocols/silc/silcpurple.h | 5 +---
libpurple/protocols/silc/util.c | 45 +++++++++-------------------------
pidgin/gtkconv.c | 6 +---
6 files changed, 52 insertions(+), 80 deletions(-)
diffs (truncated from 310 to 300 lines):
diff --git a/libpurple/protocols/silc/buddy.c b/libpurple/protocols/silc/buddy.c
--- a/libpurple/protocols/silc/buddy.c
+++ b/libpurple/protocols/silc/buddy.c
@@ -1729,14 +1729,13 @@ GList *silcpurple_buddy_menu(PurpleBuddy
return m;
}
-void silcpurple_buddy_set_icon(PurpleConnection *gc, PurpleStoredImage *img)
+void silcpurple_buddy_set_icon(PurpleConnection *gc, PurpleImage *img)
{
SilcPurple sg = purple_connection_get_protocol_data(gc);
SilcClient client = sg->client;
SilcClientConnection conn = sg->conn;
SilcMime mime;
- char type[32];
- const char *t;
+ const gchar *type;
/* Remove */
if (!img) {
@@ -1745,24 +1744,23 @@ void silcpurple_buddy_set_icon(PurpleCon
return;
}
+ type = purple_image_get_mimetype(img);
+ if (type == NULL)
+ return;
+ if (g_strcmp0(purple_image_get_extension(img), "ico") == 0)
+ return;
+
/* Add */
mime = silc_mime_alloc();
if (!mime)
return;
- t = purple_imgstore_get_extension(img);
- if (!t || !strcmp(t, "icon")) {
- silc_mime_free(mime);
- return;
- }
- if (!strcmp(t, "jpg"))
- t = "jpeg";
- g_snprintf(type, sizeof(type), "image/%s", t);
silc_mime_add_field(mime, "Content-Type", type);
- silc_mime_add_data(mime, purple_imgstore_get_data(img), purple_imgstore_get_size(img));
+ silc_mime_add_data(mime, purple_image_get_data(img),
+ purple_image_get_size(img));
- silc_client_attribute_add(client, conn,
- SILC_ATTRIBUTE_USER_ICON, mime, sizeof(*mime));
+ silc_client_attribute_add(client, conn, SILC_ATTRIBUTE_USER_ICON,
+ mime, sizeof(*mime));
silc_mime_free(mime);
}
diff --git a/libpurple/protocols/silc/ops.c b/libpurple/protocols/silc/ops.c
--- a/libpurple/protocols/silc/ops.c
+++ b/libpurple/protocols/silc/ops.c
@@ -18,12 +18,12 @@
*/
#include "internal.h"
+#include "image-store.h"
PURPLE_BEGIN_IGNORE_CAST_ALIGN
#include "silc.h"
PURPLE_END_IGNORE_CAST_ALIGN
#include "silcclient.h"
#include "silcpurple.h"
-#include "imgstore.h"
#include "wb.h"
static void
@@ -182,12 +182,10 @@ silcpurple_mime_message(SilcClient clien
}
/* Image */
- if (strstr(type, "image/png") ||
- strstr(type, "image/jpeg") ||
- strstr(type, "image/gif") ||
- strstr(type, "image/tiff")) {
+ if (purple_str_has_prefix(type, "image/")) {
char tmp[32];
- int imgid;
+ PurpleImage *img;
+ guint img_id;
/* Get channel chat (if message is for channel) */
if (key && channel) {
@@ -208,24 +206,26 @@ silcpurple_mime_message(SilcClient clien
if (channel && !chat)
goto out;
- imgid = purple_imgstore_new_with_id(g_memdup(data, data_len), data_len, "");
- if (imgid) {
- cflags |= PURPLE_MESSAGE_IMAGES | PURPLE_MESSAGE_RECV;
- g_snprintf(tmp, sizeof(tmp),
- "<IMG SRC=\"" PURPLE_STORED_IMAGE_PROTOCOL "%d\">",
- imgid);
+ img = purple_image_new_from_data(g_memdup(data, data_len), data_len);
+ if (!img)
+ goto out;
+ img_id = purple_image_store_add_temporary(img);
+ if (!img_id)
+ goto out;
- if (channel)
- purple_serv_got_chat_in(gc, purple_chat_conversation_get_id(chat),
- sender->nickname, cflags,
- tmp, time(NULL));
- else
- purple_serv_got_im(gc, sender->nickname,
- tmp, cflags, time(NULL));
+ cflags |= PURPLE_MESSAGE_IMAGES | PURPLE_MESSAGE_RECV;
+ g_snprintf(tmp, sizeof(tmp), "<img src=\""
+ PURPLE_IMAGE_STORE_PROTOCOL "%u\">", img_id);
- purple_imgstore_unref_by_id(imgid);
- ret = TRUE;
+ if (channel) {
+ purple_serv_got_chat_in(gc,
+ purple_chat_conversation_get_id(chat),
+ sender->nickname, cflags, tmp, time(NULL));
+ } else {
+ purple_serv_got_im(gc, sender->nickname,
+ tmp, cflags, time(NULL));
}
+
goto out;
}
diff --git a/libpurple/protocols/silc/silc.c b/libpurple/protocols/silc/silc.c
--- a/libpurple/protocols/silc/silc.c
+++ b/libpurple/protocols/silc/silc.c
@@ -248,7 +248,7 @@ silcpurple_connect_cb(SilcClient client,
SilcPurple sg;
SilcUInt32 mask;
char tz[16];
- PurpleStoredImage *img;
+ PurpleImage *img;
#ifdef HAVE_SYS_UTSNAME_H
struct utsname u;
#endif
@@ -305,7 +305,7 @@ silcpurple_connect_cb(SilcClient client,
/* Set our buddy icon */
img = purple_buddy_icons_find_account_icon(sg->account);
silcpurple_buddy_set_icon(gc, img);
- purple_imgstore_unref(img);
+ g_object_unref(img);
return;
break;
@@ -718,7 +718,8 @@ silcpurple_close(PurpleConnection *gc)
silc_dlist_uninit(sg->tasks);
#endif /* __SILC_TOOLKIT_VERSION */
- purple_timeout_remove(sg->scheduler);
+ if (sg->scheduler)
+ purple_timeout_remove(sg->scheduler);
purple_debug_info("silc", "Scheduling destruction of SilcPurple %p\n", sg);
purple_timeout_add(1, (GSourceFunc)silcpurple_close_final, sg);
@@ -1499,7 +1500,6 @@ silcpurple_send_im(PurpleConnection *gc,
g_free(tmp);
return 0;
}
-
silc_dlist_start(clients);
client_entry = silc_dlist_get(clients);
diff --git a/libpurple/protocols/silc/silcpurple.h b/libpurple/protocols/silc/silcpurple.h
--- a/libpurple/protocols/silc/silcpurple.h
+++ b/libpurple/protocols/silc/silcpurple.h
@@ -35,8 +35,6 @@
#include "server.h"
#include "util.h"
-#include "imgstore.h" /* TODO: temp */
-
#undef SILC_VERSION
#define SILC_VERSION(a, b, c) (((a) << 24) + ((b) << 16) + ((c) << 8))
@@ -153,8 +151,7 @@ void silcpurple_chat_chauth_show(SilcPur
void silcpurple_parse_attrs(SilcDList attrs, char **moodstr, char **statusstr,
char **contactstr, char **langstr, char **devicestr,
char **tzstr, char **geostr);
-void silcpurple_buddy_set_icon(PurpleConnection *gc, PurpleStoredImage *img);
-char *silcpurple_file2mime(const char *filename);
+void silcpurple_buddy_set_icon(PurpleConnection *gc, PurpleImage *img);
SilcDList silcpurple_image_message(const char *msg, SilcMessageFlags *mflags);
#ifdef _WIN32
diff --git a/libpurple/protocols/silc/util.c b/libpurple/protocols/silc/util.c
--- a/libpurple/protocols/silc/util.c
+++ b/libpurple/protocols/silc/util.c
@@ -19,12 +19,13 @@
#include "internal.h"
#include "glibcompat.h"
+#include "image-store.h"
+
PURPLE_BEGIN_IGNORE_CAST_ALIGN
#include "silc.h"
PURPLE_END_IGNORE_CAST_ALIGN
#include "silcclient.h"
#include "silcpurple.h"
-#include "imgstore.h"
/**************************** Utility Routines *******************************/
@@ -648,29 +649,6 @@ silcpurple_parse_attrs(SilcDList attrs,
geo.accuracy ? geo.accuracy : "");
}
-/* Returns MIME type of filetype */
-
-char *silcpurple_file2mime(const char *filename)
-{
- const char *ct;
-
- ct = strrchr(filename, '.');
- if (!ct)
- return NULL;
- else if (!g_ascii_strcasecmp(".png", ct))
- return g_strdup("image/png");
- else if (!g_ascii_strcasecmp(".jpg", ct))
- return g_strdup("image/jpeg");
- else if (!g_ascii_strcasecmp(".jpeg", ct))
- return g_strdup("image/jpeg");
- else if (!g_ascii_strcasecmp(".gif", ct))
- return g_strdup("image/gif");
- else if (!g_ascii_strcasecmp(".tiff", ct))
- return g_strdup("image/tiff");
-
- return NULL;
-}
-
/* Checks if message has images, and assembles MIME message if it has.
If only one image is present, creates simple MIME image message. If
there are multiple images and/or text with images multipart MIME
@@ -682,14 +660,13 @@ SilcDList silcpurple_image_message(const
SilcDList list, parts = NULL;
const char *start, *end, *last;
GData *attribs;
- char *type;
gboolean images = FALSE;
last = msg;
while (last && *last && purple_markup_find_tag("img", last, &start,
&end, &attribs)) {
- PurpleStoredImage *image = NULL;
- const char *id;
+ PurpleImage *image = NULL;
+ const gchar *uri;
/* Check if there is text before image */
if (start - last) {
@@ -713,22 +690,24 @@ SilcDList silcpurple_image_message(const
silc_dlist_add(parts, p);
}
- id = g_datalist_get_data(&attribs, "id");
- if (id && (image = purple_imgstore_find_by_id(atoi(id)))) {
- unsigned long imglen = purple_imgstore_get_size(image);
- gconstpointer img = purple_imgstore_get_data(image);
+ uri = g_datalist_get_data(&attribs, "src");
+ if (uri)
+ image = purple_image_store_get_from_uri(uri);
+ if (uri) {
+ unsigned long imglen = purple_image_get_size(image);
+ gconstpointer img = purple_image_get_data(image);
+ const gchar *type;
p = silc_mime_alloc();
/* Add content type */
- type = silcpurple_file2mime(purple_imgstore_get_filename(image));
+ type = purple_image_get_mimetype(image);
if (!type) {
g_datalist_clear(&attribs);
last = end + 1;
continue;
}
silc_mime_add_field(p, "Content-Type", type);
- g_free(type);
/* Add content transfer encoding */
silc_mime_add_field(p, "Content-Transfer-Encoding", "binary");
diff --git a/pidgin/gtkconv.c b/pidgin/gtkconv.c
--- a/pidgin/gtkconv.c
+++ b/pidgin/gtkconv.c
@@ -641,17 +641,15 @@ send_cb(GtkWidget *widget, PidginConvers
return;
buf = pidgin_webview_get_body_html(PIDGIN_WEBVIEW(gtkconv->entry));
+ g_return_if_fail(buf != NULL);
gtk_widget_grab_focus(gtkconv->entry);
purple_idle_touch();
More information about the Commits
mailing list