/pidgin/main: b5d03ca6a680: Gadu-Gadu: use remote features of Pu...
Tomasz Wasilczyk
twasilczyk at pidgin.im
Sun Apr 13 13:41:50 EDT 2014
Changeset: b5d03ca6a680a6bf57a9198405f47dcf2e692477
Author: Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date: 2014-04-13 19:41 +0200
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/b5d03ca6a680
Description:
Gadu-Gadu: use remote features of PurpleImage instead of handling image queue
diffstat:
libpurple/image.c | 13 +++
libpurple/protocols/gg/image-prpl.c | 114 +++++++++----------------------
libpurple/protocols/gg/image-prpl.h | 10 +--
libpurple/protocols/gg/message-prpl.c | 122 +++------------------------------
4 files changed, 60 insertions(+), 199 deletions(-)
diffs (truncated from 451 to 300 lines):
diff --git a/libpurple/image.c b/libpurple/image.c
--- a/libpurple/image.c
+++ b/libpurple/image.c
@@ -419,6 +419,19 @@ purple_image_get_friendly_filename(Purpl
priv->friendly_filename = g_strdup(newname);
}
+ if (G_UNLIKELY(priv->is_ready &&
+ strchr(priv->friendly_filename, '.') == NULL))
+ {
+ const gchar *ext = purple_image_get_extension(image);
+ gchar *tmp;
+ if (!ext)
+ return priv->friendly_filename;
+
+ tmp = g_strdup_printf("%s.%s", priv->friendly_filename, ext);
+ g_free(priv->friendly_filename);
+ priv->friendly_filename = tmp;
+ }
+
return priv->friendly_filename;
}
diff --git a/libpurple/protocols/gg/image-prpl.c b/libpurple/protocols/gg/image-prpl.c
--- a/libpurple/protocols/gg/image-prpl.c
+++ b/libpurple/protocols/gg/image-prpl.c
@@ -39,8 +39,7 @@
struct _ggp_image_session_data
{
- GHashTable *got_images;
- GHashTable *incoming_images;
+ GHashTable *recv_images;
GHashTable *sent_images;
};
@@ -50,17 +49,6 @@ typedef struct
gchar *conv_name; /* TODO: callback */
} ggp_image_sent;
-typedef struct
-{
- GList *listeners;
-} ggp_image_requested;
-
-typedef struct
-{
- ggp_image_request_cb cb;
- gpointer user_data;
-} ggp_image_requested_listener;
-
static void ggp_image_sent_free(gpointer _sent_image)
{
ggp_image_sent *sent_image = _sent_image;
@@ -69,13 +57,6 @@ static void ggp_image_sent_free(gpointer
g_free(sent_image);
}
-static void ggp_image_requested_free(gpointer data)
-{
- ggp_image_requested *req = data;
- g_list_free_full(req->listeners, g_free);
- g_free(req);
-}
-
static uint64_t ggp_image_params_to_id(uint32_t crc32, uint32_t size)
{
return ((uint64_t)crc32 << 32) | size;
@@ -95,11 +76,8 @@ void ggp_image_setup(PurpleConnection *g
accdata->image_data = sdata;
- sdata->got_images = g_hash_table_new_full(
+ sdata->recv_images = g_hash_table_new_full(
g_int64_hash, g_int64_equal, g_free, g_object_unref);
- sdata->incoming_images = g_hash_table_new_full(
- g_int64_hash, g_int64_equal, g_free,
- ggp_image_requested_free);
sdata->sent_images = g_hash_table_new_full(
g_int64_hash, g_int64_equal, g_free,
ggp_image_sent_free);
@@ -109,8 +87,7 @@ void ggp_image_cleanup(PurpleConnection
{
ggp_image_session_data *sdata = ggp_image_get_sdata(gc);
- g_hash_table_destroy(sdata->got_images);
- g_hash_table_destroy(sdata->incoming_images);
+ g_hash_table_destroy(sdata->recv_images);
g_hash_table_destroy(sdata->sent_images);
g_free(sdata);
}
@@ -160,43 +137,28 @@ void ggp_image_recv(PurpleConnection *gc
{
ggp_image_session_data *sdata = ggp_image_get_sdata(gc);
PurpleImage *img;
- ggp_image_requested *req;
- GList *it;
uint64_t id;
- img = purple_image_new_from_data(
- g_memdup(image_reply->image, image_reply->size),
- image_reply->size);
- purple_image_set_friendly_filename(img, image_reply->filename);
-
id = ggp_image_params_to_id(image_reply->crc32, image_reply->size);
+ img = g_hash_table_lookup(sdata->recv_images, &id);
+ if (!img) {
+ purple_debug_warning("gg", "ggp_image_recv: "
+ "image " GGP_IMAGE_ID_FORMAT " wasn't requested\n",
+ id);
+ return;
+ }
purple_debug_info("gg", "ggp_image_recv: got image "
"[crc=%u, size=%u, filename=%s, id=" GGP_IMAGE_ID_FORMAT "]",
image_reply->crc32, image_reply->size,
image_reply->filename, id);
- g_object_ref(img);
- g_hash_table_insert(sdata->got_images, ggp_uint64dup(id), img);
+ purple_image_set_friendly_filename(img, image_reply->filename);
- req = g_hash_table_lookup(sdata->incoming_images, &id);
- if (!req) {
- purple_debug_warning("gg", "ggp_image_recv: "
- "image " GGP_IMAGE_ID_FORMAT " wasn't requested\n",
- id);
- g_object_unref(img);
- return;
- }
-
- it = g_list_first(req->listeners);
- while (it) {
- ggp_image_requested_listener *listener = it->data;
- it = g_list_next(it);
-
- listener->cb(gc, id, img, listener->user_data);
- }
- g_object_unref(img);
- g_hash_table_remove(sdata->incoming_images, &id);
+ purple_image_transfer_write(img,
+ g_memdup(image_reply->image, image_reply->size),
+ image_reply->size);
+ purple_image_transfer_close(img);
}
void ggp_image_send(PurpleConnection *gc,
@@ -259,13 +221,12 @@ void ggp_image_send(PurpleConnection *gc
}
}
-void ggp_image_request(PurpleConnection *gc, uin_t uin, uint64_t id,
- ggp_image_request_cb cb, gpointer user_data)
+PurpleImage *
+ggp_image_request(PurpleConnection *gc, uin_t uin, uint64_t id)
{
GGPInfo *accdata = purple_connection_get_protocol_data(gc);
ggp_image_session_data *sdata = ggp_image_get_sdata(gc);
- ggp_image_requested *req;
- ggp_image_requested_listener *listener;
+ PurpleImage *img;
uint32_t crc = id >> 32;
uint32_t size = id;
@@ -276,33 +237,24 @@ void ggp_image_request(PurpleConnection
tmp = crc;
crc = size;
size = tmp;
+ id = ggp_image_params_to_id(crc, size);
}
- req = g_hash_table_lookup(sdata->incoming_images, &id);
- if (!req) {
- req = g_new0(ggp_image_requested, 1);
- g_hash_table_insert(sdata->incoming_images,
- ggp_uint64dup(id), req);
+ img = g_hash_table_lookup(sdata->recv_images, &id);
+ if (img) {
purple_debug_info("gg", "ggp_image_request: "
- "requesting image " GGP_IMAGE_ID_FORMAT "\n", id);
- if (gg_image_request(accdata->session, uin, size, crc) != 0)
- purple_debug_error("gg", "ggp_image_request: failed\n");
- } else {
- purple_debug_info("gg", "ggp_image_request: "
- "image " GGP_IMAGE_ID_FORMAT " already requested\n",
- id);
+ "image " GGP_IMAGE_ID_FORMAT " got from cache", id);
+ return img;
}
- listener = g_new0(ggp_image_requested_listener, 1);
- listener->cb = cb;
- listener->user_data = user_data;
- req->listeners = g_list_append(req->listeners, listener);
+
+ img = purple_image_transfer_new();
+ g_hash_table_insert(sdata->recv_images, ggp_uint64dup(id), img);
+
+ purple_debug_info("gg", "ggp_image_request: requesting image "
+ GGP_IMAGE_ID_FORMAT, id);
+ if (gg_image_request(accdata->session, uin, size, crc) != 0)
+ purple_debug_error("gg", "ggp_image_request: failed");
+
+ return img;
}
-
-PurpleImage *
-ggp_image_get_cached(PurpleConnection *gc, uint64_t id)
-{
- ggp_image_session_data *sdata = ggp_image_get_sdata(gc);
-
- return g_hash_table_lookup(sdata->got_images, &id);
-}
diff --git a/libpurple/protocols/gg/image-prpl.h b/libpurple/protocols/gg/image-prpl.h
--- a/libpurple/protocols/gg/image-prpl.h
+++ b/libpurple/protocols/gg/image-prpl.h
@@ -45,10 +45,6 @@ typedef enum
GGP_IMAGE_PREPARE_TOO_BIG
} ggp_image_prepare_result;
-typedef void
-(*ggp_image_request_cb)(PurpleConnection *gc, uint64_t id, PurpleImage *image,
- gpointer user_data);
-
void
ggp_image_setup(PurpleConnection *gc);
@@ -66,11 +62,7 @@ void
ggp_image_send(PurpleConnection *gc,
const struct gg_event_image_request *image_request);
-void
-ggp_image_request(PurpleConnection *gc, uin_t uin, uint64_t id,
- ggp_image_request_cb cb, gpointer user_data);
-
PurpleImage *
-ggp_image_get_cached(PurpleConnection *gc, uint64_t id);
+ggp_image_request(PurpleConnection *gc, uin_t uin, uint64_t id);
#endif /* _GGP_IMAGE_H */
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
@@ -41,10 +41,6 @@
#define GGP_GG10_DEFAULT_FORMAT_REPLACEMENT "<span>"
#define GGP_GG11_FORCE_COMPAT FALSE
-/* TODO: we don't need "pending images" anymore */
-#define GGP_IMAGE_REPLACEMENT "<img id=\"gg-pending-image-" GGP_IMAGE_ID_FORMAT "\">"
-#define GGP_IMAGE_DESTINATION "<img src=\"" PURPLE_IMAGE_STORE_PROTOCOL "%u\">"
-
typedef struct
{
enum
@@ -58,7 +54,6 @@ typedef struct
gchar *text;
time_t time;
uint64_t chat_id;
- GList *pending_images;
PurpleConnection *gc;
} ggp_message_got_data;
@@ -73,7 +68,6 @@ static ggp_message_global_data global_da
struct _ggp_message_session_data
{
- GList *pending_messages;
};
typedef struct
@@ -91,8 +85,6 @@ static void ggp_font_free(gpointer font)
static PurpleIMConversation * ggp_message_get_conv(PurpleConnection *gc,
uin_t uin);
static void ggp_message_got_data_free(ggp_message_got_data *msg);
-static gboolean ggp_message_request_images(PurpleConnection *gc,
- ggp_message_got_data *msg);
static void ggp_message_got_display(PurpleConnection *gc,
ggp_message_got_data *msg);
static void ggp_message_format_from_gg(ggp_message_got_data *msg,
@@ -135,8 +127,6 @@ void ggp_message_cleanup(PurpleConnectio
{
ggp_message_session_data *sdata = ggp_message_get_sdata(gc);
- g_list_free_full(sdata->pending_messages,
- (GDestroyNotify)ggp_message_got_data_free);
g_free(sdata);
}
@@ -187,82 +177,10 @@ static PurpleIMConversation * ggp_messag
static void ggp_message_got_data_free(ggp_message_got_data *msg)
{
- g_list_free_full(msg->pending_images, g_free);
g_free(msg->text);
g_free(msg);
}
-static void
-ggp_message_request_images_got(PurpleConnection *gc, uint64_t id,
- PurpleImage *image, gpointer _msg)
More information about the Commits
mailing list