libpurple/protocols/gg/image-prpl.c

Tue, 19 May 2020 10:29:23 +0000

author
Gary Kramlich <grim@reaperworld.com>
date
Tue, 19 May 2020 10:29:23 +0000
changeset 40417
48c621e76141
parent 40358
e6fe6fc1f516
child 40439
e9838d634d5e
permissions
-rw-r--r--

Merged in default (pull request #697)

simple: Fix search for message headers

Approved-by: Gary Kramlich

33348
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
1 /* purple
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
2 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
3 * Purple is the legal property of its developers, whose names are too numerous
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
4 * to list here. Please refer to the COPYRIGHT file distributed with this
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
5 * source distribution.
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
6 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
7 * Rewritten from scratch during Google Summer of Code 2012
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
8 * by Tomek Wasilczyk (http://www.wasilczyk.pl).
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
9 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
10 * Previously implemented by:
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
11 * - Arkadiusz Miskiewicz <misiek@pld.org.pl> - first implementation (2001);
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
12 * - Bartosz Oler <bartosz@bzimage.us> - reimplemented during GSoC 2005;
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
13 * - Krzysztof Klinikowski <grommasher@gmail.com> - some parts (2009-2011).
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
14 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
15 * This program is free software; you can redistribute it and/or modify
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
16 * it under the terms of the GNU General Public License as published by
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
17 * the Free Software Foundation; either version 2 of the License, or
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
18 * (at your option) any later version.
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
19 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
20 * This program is distributed in the hope that it will be useful,
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
23 * GNU General Public License for more details.
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
24 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
25 * You should have received a copy of the GNU General Public License
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
26 * along with this program; if not, write to the Free Software
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
28 */
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
29
35819
cc375b914104 imgstore: remove refs from gg prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35360
diff changeset
30 #include "image-prpl.h"
33298
519acf37d16e Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
31
519acf37d16e Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
32 #include "gg.h"
33299
b3c4ab3aeb7f Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33298
diff changeset
33 #include "utils.h"
33298
519acf37d16e Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
34
35819
cc375b914104 imgstore: remove refs from gg prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35360
diff changeset
35 #include <image-store.h>
cc375b914104 imgstore: remove refs from gg prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35360
diff changeset
36
34362
758e72362ca4 Gadu-Gadu: code polishing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34361
diff changeset
37 struct _ggp_image_session_data
33298
519acf37d16e Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
38 {
35843
b5d03ca6a680 Gadu-Gadu: use remote features of PurpleImage instead of handling image queue
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35820
diff changeset
39 GHashTable *recv_images;
34365
25e4187ea5a7 Gadu-Gadu: outgoing images works again (not in conferences, yet)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34362
diff changeset
40 GHashTable *sent_images;
34362
758e72362ca4 Gadu-Gadu: code polishing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34361
diff changeset
41 };
33298
519acf37d16e Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
42
33302
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
43 typedef struct
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
44 {
35820
9b4fccc8ceac GG: reference images, not their ids
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
45 PurpleImage *image;
34365
25e4187ea5a7 Gadu-Gadu: outgoing images works again (not in conferences, yet)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34362
diff changeset
46 gchar *conv_name; /* TODO: callback */
25e4187ea5a7 Gadu-Gadu: outgoing images works again (not in conferences, yet)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34362
diff changeset
47 } ggp_image_sent;
33302
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
48
35820
9b4fccc8ceac GG: reference images, not their ids
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
49 static void ggp_image_sent_free(gpointer _sent_image)
35819
cc375b914104 imgstore: remove refs from gg prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35360
diff changeset
50 {
35820
9b4fccc8ceac GG: reference images, not their ids
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
51 ggp_image_sent *sent_image = _sent_image;
9b4fccc8ceac GG: reference images, not their ids
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
52 g_object_unref(sent_image->image);
34365
25e4187ea5a7 Gadu-Gadu: outgoing images works again (not in conferences, yet)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34362
diff changeset
53 g_free(sent_image->conv_name);
25e4187ea5a7 Gadu-Gadu: outgoing images works again (not in conferences, yet)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34362
diff changeset
54 g_free(sent_image);
33302
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
55 }
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
56
34365
25e4187ea5a7 Gadu-Gadu: outgoing images works again (not in conferences, yet)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34362
diff changeset
57 static uint64_t ggp_image_params_to_id(uint32_t crc32, uint32_t size)
25e4187ea5a7 Gadu-Gadu: outgoing images works again (not in conferences, yet)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34362
diff changeset
58 {
25e4187ea5a7 Gadu-Gadu: outgoing images works again (not in conferences, yet)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34362
diff changeset
59 return ((uint64_t)crc32 << 32) | size;
25e4187ea5a7 Gadu-Gadu: outgoing images works again (not in conferences, yet)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34362
diff changeset
60 }
25e4187ea5a7 Gadu-Gadu: outgoing images works again (not in conferences, yet)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34362
diff changeset
61
34362
758e72362ca4 Gadu-Gadu: code polishing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34361
diff changeset
62 static inline ggp_image_session_data *
758e72362ca4 Gadu-Gadu: code polishing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34361
diff changeset
63 ggp_image_get_sdata(PurpleConnection *gc)
33298
519acf37d16e Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
64 {
519acf37d16e Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
65 GGPInfo *accdata = purple_connection_get_protocol_data(gc);
34362
758e72362ca4 Gadu-Gadu: code polishing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34361
diff changeset
66 return accdata->image_data;
33298
519acf37d16e Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
67 }
519acf37d16e Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
68
519acf37d16e Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
69 void ggp_image_setup(PurpleConnection *gc)
519acf37d16e Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
70 {
34362
758e72362ca4 Gadu-Gadu: code polishing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34361
diff changeset
71 GGPInfo *accdata = purple_connection_get_protocol_data(gc);
758e72362ca4 Gadu-Gadu: code polishing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34361
diff changeset
72 ggp_image_session_data *sdata = g_new0(ggp_image_session_data, 1);
35355
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34946
diff changeset
73
34362
758e72362ca4 Gadu-Gadu: code polishing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34361
diff changeset
74 accdata->image_data = sdata;
35355
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34946
diff changeset
75
35843
b5d03ca6a680 Gadu-Gadu: use remote features of PurpleImage instead of handling image queue
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35820
diff changeset
76 sdata->recv_images = g_hash_table_new_full(
35820
9b4fccc8ceac GG: reference images, not their ids
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
77 g_int64_hash, g_int64_equal, g_free, g_object_unref);
34365
25e4187ea5a7 Gadu-Gadu: outgoing images works again (not in conferences, yet)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34362
diff changeset
78 sdata->sent_images = g_hash_table_new_full(
25e4187ea5a7 Gadu-Gadu: outgoing images works again (not in conferences, yet)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34362
diff changeset
79 g_int64_hash, g_int64_equal, g_free,
25e4187ea5a7 Gadu-Gadu: outgoing images works again (not in conferences, yet)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34362
diff changeset
80 ggp_image_sent_free);
33298
519acf37d16e Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
81 }
519acf37d16e Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
82
33313
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33302
diff changeset
83 void ggp_image_cleanup(PurpleConnection *gc)
33298
519acf37d16e Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
84 {
34362
758e72362ca4 Gadu-Gadu: code polishing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34361
diff changeset
85 ggp_image_session_data *sdata = ggp_image_get_sdata(gc);
35355
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34946
diff changeset
86
35843
b5d03ca6a680 Gadu-Gadu: use remote features of PurpleImage instead of handling image queue
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35820
diff changeset
87 g_hash_table_destroy(sdata->recv_images);
34365
25e4187ea5a7 Gadu-Gadu: outgoing images works again (not in conferences, yet)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34362
diff changeset
88 g_hash_table_destroy(sdata->sent_images);
34362
758e72362ca4 Gadu-Gadu: code polishing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34361
diff changeset
89 g_free(sdata);
33298
519acf37d16e Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
90 }
519acf37d16e Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
91
35820
9b4fccc8ceac GG: reference images, not their ids
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
92 ggp_image_prepare_result
9b4fccc8ceac GG: reference images, not their ids
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
93 ggp_image_prepare(PurpleConversation *conv, PurpleImage *image, uint64_t *id)
33298
519acf37d16e Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
94 {
34365
25e4187ea5a7 Gadu-Gadu: outgoing images works again (not in conferences, yet)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34362
diff changeset
95 PurpleConnection *gc = purple_conversation_get_connection(conv);
34362
758e72362ca4 Gadu-Gadu: code polishing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34361
diff changeset
96 ggp_image_session_data *sdata = ggp_image_get_sdata(gc);
33301
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
97 size_t image_size;
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
98 gconstpointer image_data;
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
99 uint32_t image_crc;
34365
25e4187ea5a7 Gadu-Gadu: outgoing images works again (not in conferences, yet)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34362
diff changeset
100 ggp_image_sent *sent_image;
35355
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34946
diff changeset
101
35820
9b4fccc8ceac GG: reference images, not their ids
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
102 g_return_val_if_fail(image, GGP_IMAGE_PREPARE_FAILURE);
35355
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34946
diff changeset
103
38298
f0a8f63f9312 rename purple_image_get_size to purple_image_get_data_size and deal with the fallout
Gary Kramlich <grim@reaperworld.com>
parents: 38281
diff changeset
104 image_size = purple_image_get_data_size(image);
35355
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34946
diff changeset
105
35360
29d788c72350 Style: fix gg braces (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35355
diff changeset
106 if (image_size > GGP_IMAGE_SIZE_MAX) {
34365
25e4187ea5a7 Gadu-Gadu: outgoing images works again (not in conferences, yet)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34362
diff changeset
107 purple_debug_warning("gg", "ggp_image_prepare: image "
33301
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
108 "is too big (max bytes: %d)\n", GGP_IMAGE_SIZE_MAX);
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
109 return GGP_IMAGE_PREPARE_TOO_BIG;
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
110 }
35355
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34946
diff changeset
111
35819
cc375b914104 imgstore: remove refs from gg prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35360
diff changeset
112 g_object_ref(image);
cc375b914104 imgstore: remove refs from gg prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35360
diff changeset
113 image_data = purple_image_get_data(image);
33301
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
114 image_crc = gg_crc32(0, image_data, image_size);
35355
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34946
diff changeset
115
34365
25e4187ea5a7 Gadu-Gadu: outgoing images works again (not in conferences, yet)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34362
diff changeset
116 purple_debug_info("gg", "ggp_image_prepare: image prepared "
35820
9b4fccc8ceac GG: reference images, not their ids
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
117 "[crc=%u, size=%" G_GSIZE_FORMAT "]",
9b4fccc8ceac GG: reference images, not their ids
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
118 image_crc, image_size);
35355
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34946
diff changeset
119
34365
25e4187ea5a7 Gadu-Gadu: outgoing images works again (not in conferences, yet)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34362
diff changeset
120 *id = ggp_image_params_to_id(image_crc, image_size);
34367
cb229d301bb4 Gadu-Gadu: don't unref images after sending it to first recipient
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34366
diff changeset
121
35820
9b4fccc8ceac GG: reference images, not their ids
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
122 g_object_ref(image);
34365
25e4187ea5a7 Gadu-Gadu: outgoing images works again (not in conferences, yet)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34362
diff changeset
123 sent_image = g_new(ggp_image_sent, 1);
35820
9b4fccc8ceac GG: reference images, not their ids
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
124 sent_image->image = image;
34365
25e4187ea5a7 Gadu-Gadu: outgoing images works again (not in conferences, yet)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34362
diff changeset
125 sent_image->conv_name = g_strdup(purple_conversation_get_name(conv));
25e4187ea5a7 Gadu-Gadu: outgoing images works again (not in conferences, yet)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34362
diff changeset
126 g_hash_table_insert(sdata->sent_images, ggp_uint64dup(*id),
25e4187ea5a7 Gadu-Gadu: outgoing images works again (not in conferences, yet)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34362
diff changeset
127 sent_image);
35355
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34946
diff changeset
128
33301
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
129 return GGP_IMAGE_PREPARE_OK;
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
130 }
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
131
33298
519acf37d16e Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
132 void ggp_image_recv(PurpleConnection *gc,
519acf37d16e Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
133 const struct gg_event_image_reply *image_reply)
519acf37d16e Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
134 {
34362
758e72362ca4 Gadu-Gadu: code polishing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34361
diff changeset
135 ggp_image_session_data *sdata = ggp_image_get_sdata(gc);
35819
cc375b914104 imgstore: remove refs from gg prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35360
diff changeset
136 PurpleImage *img;
34361
ddcc82637afa Gadu-Gadu: incoming images works again
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33368
diff changeset
137 uint64_t id;
35355
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34946
diff changeset
138
34365
25e4187ea5a7 Gadu-Gadu: outgoing images works again (not in conferences, yet)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34362
diff changeset
139 id = ggp_image_params_to_id(image_reply->crc32, image_reply->size);
35843
b5d03ca6a680 Gadu-Gadu: use remote features of PurpleImage instead of handling image queue
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35820
diff changeset
140 img = g_hash_table_lookup(sdata->recv_images, &id);
b5d03ca6a680 Gadu-Gadu: use remote features of PurpleImage instead of handling image queue
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35820
diff changeset
141 if (!img) {
b5d03ca6a680 Gadu-Gadu: use remote features of PurpleImage instead of handling image queue
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35820
diff changeset
142 purple_debug_warning("gg", "ggp_image_recv: "
b5d03ca6a680 Gadu-Gadu: use remote features of PurpleImage instead of handling image queue
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35820
diff changeset
143 "image " GGP_IMAGE_ID_FORMAT " wasn't requested\n",
b5d03ca6a680 Gadu-Gadu: use remote features of PurpleImage instead of handling image queue
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35820
diff changeset
144 id);
b5d03ca6a680 Gadu-Gadu: use remote features of PurpleImage instead of handling image queue
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35820
diff changeset
145 return;
b5d03ca6a680 Gadu-Gadu: use remote features of PurpleImage instead of handling image queue
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35820
diff changeset
146 }
35355
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34946
diff changeset
147
33298
519acf37d16e Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
148 purple_debug_info("gg", "ggp_image_recv: got image "
35820
9b4fccc8ceac GG: reference images, not their ids
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
149 "[crc=%u, size=%u, filename=%s, id=" GGP_IMAGE_ID_FORMAT "]",
9b4fccc8ceac GG: reference images, not their ids
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
150 image_reply->crc32, image_reply->size,
9b4fccc8ceac GG: reference images, not their ids
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
151 image_reply->filename, id);
33298
519acf37d16e Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
152
38281
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 37148
diff changeset
153 img = purple_image_new_from_data(
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 37148
diff changeset
154 (const guint8 *)image_reply->image,
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 37148
diff changeset
155 image_reply->size
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 37148
diff changeset
156 );
35843
b5d03ca6a680 Gadu-Gadu: use remote features of PurpleImage instead of handling image queue
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35820
diff changeset
157 purple_image_set_friendly_filename(img, image_reply->filename);
33298
519acf37d16e Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
158
38281
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 37148
diff changeset
159 g_hash_table_insert(sdata->recv_images, &id, img);
33298
519acf37d16e Gadu-Gadu: fix receiving of inline images after 3.x changes; code refactoring here as well
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
160 }
33301
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
161
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
162 void ggp_image_send(PurpleConnection *gc,
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
163 const struct gg_event_image_request *image_request)
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
164 {
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
165 GGPInfo *accdata = purple_connection_get_protocol_data(gc);
34362
758e72362ca4 Gadu-Gadu: code polishing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34361
diff changeset
166 ggp_image_session_data *sdata = ggp_image_get_sdata(gc);
34365
25e4187ea5a7 Gadu-Gadu: outgoing images works again (not in conferences, yet)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34362
diff changeset
167 ggp_image_sent *sent_image;
33302
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
168 PurpleConversation *conv;
34365
25e4187ea5a7 Gadu-Gadu: outgoing images works again (not in conferences, yet)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34362
diff changeset
169 uint64_t id;
34366
62528926bcd2 Handle inline image filenames in the same way as GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34365
diff changeset
170 gchar *gg_filename;
35355
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34946
diff changeset
171
33301
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
172 purple_debug_info("gg", "ggp_image_send: got image request "
33302
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
173 "[uin=%u, crc=%u, size=%u]\n",
33301
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
174 image_request->sender,
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
175 image_request->crc32,
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
176 image_request->size);
35355
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34946
diff changeset
177
34365
25e4187ea5a7 Gadu-Gadu: outgoing images works again (not in conferences, yet)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34362
diff changeset
178 id = ggp_image_params_to_id(image_request->crc32, image_request->size);
35355
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34946
diff changeset
179
34365
25e4187ea5a7 Gadu-Gadu: outgoing images works again (not in conferences, yet)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34362
diff changeset
180 sent_image = g_hash_table_lookup(sdata->sent_images, &id);
35355
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34946
diff changeset
181
34371
75f5a3c3cd67 Gadu-Gadu: more debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34367
diff changeset
182 if (sent_image == NULL && image_request->sender == ggp_str_to_uin(
75f5a3c3cd67 Gadu-Gadu: more debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34367
diff changeset
183 purple_account_get_username(purple_connection_get_account(gc))))
75f5a3c3cd67 Gadu-Gadu: more debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34367
diff changeset
184 {
75f5a3c3cd67 Gadu-Gadu: more debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34367
diff changeset
185 purple_debug_misc("gg", "ggp_image_send: requested image "
75f5a3c3cd67 Gadu-Gadu: more debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34367
diff changeset
186 "not found, but this may be another session request\n");
75f5a3c3cd67 Gadu-Gadu: more debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34367
diff changeset
187 return;
75f5a3c3cd67 Gadu-Gadu: more debug prints
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34367
diff changeset
188 }
35360
29d788c72350 Style: fix gg braces (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35355
diff changeset
189 if (sent_image == NULL) {
33301
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
190 purple_debug_warning("gg", "ggp_image_send: requested image "
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
191 "not found\n");
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
192 return;
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
193 }
35355
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34946
diff changeset
194
33302
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
195 purple_debug_misc("gg", "ggp_image_send: requested image found "
35820
9b4fccc8ceac GG: reference images, not their ids
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
196 "[id=" GGP_IMAGE_ID_FORMAT ", conv=%s]\n",
9b4fccc8ceac GG: reference images, not their ids
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
197 id, sent_image->conv_name);
35355
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34946
diff changeset
198
35820
9b4fccc8ceac GG: reference images, not their ids
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
199 g_return_if_fail(sent_image->image);
35355
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34946
diff changeset
200
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34946
diff changeset
201 /* TODO: check allowed recipients */
34418
c27e31267e8d Gadu-Gadu: fix compilation on 64-bit targets
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34415
diff changeset
202 gg_filename = g_strdup_printf(GGP_IMAGE_ID_FORMAT, id);
33301
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
203 gg_image_reply(accdata->session, image_request->sender,
34366
62528926bcd2 Handle inline image filenames in the same way as GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34365
diff changeset
204 gg_filename,
35820
9b4fccc8ceac GG: reference images, not their ids
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
205 purple_image_get_data(sent_image->image),
38298
f0a8f63f9312 rename purple_image_get_size to purple_image_get_data_size and deal with the fallout
Gary Kramlich <grim@reaperworld.com>
parents: 38281
diff changeset
206 purple_image_get_data_size(sent_image->image));
34366
62528926bcd2 Handle inline image filenames in the same way as GG11
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34365
diff changeset
207 g_free(gg_filename);
35355
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34946
diff changeset
208
34946
76aa2e0f8701 Merged default branch
Ankit Vani <a@nevitus.org>
parents: 34632 34423
diff changeset
209 conv = purple_conversations_find_with_account(
76aa2e0f8701 Merged default branch
Ankit Vani <a@nevitus.org>
parents: 34632 34423
diff changeset
210 sent_image->conv_name,
33302
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
211 purple_connection_get_account(gc));
35360
29d788c72350 Style: fix gg braces (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35355
diff changeset
212 if (conv != NULL) {
34367
cb229d301bb4 Gadu-Gadu: don't unref images after sending it to first recipient
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34366
diff changeset
213 gchar *msg = g_strdup_printf(_("Image delivered to %u."),
cb229d301bb4 Gadu-Gadu: don't unref images after sending it to first recipient
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34366
diff changeset
214 image_request->sender);
36089
c035b9a63457 Use purple_conversation_write_system_message where appropriate
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35843
diff changeset
215 purple_conversation_write_system_message(conv, msg,
c035b9a63457 Use purple_conversation_write_system_message where appropriate
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35843
diff changeset
216 PURPLE_MESSAGE_NO_LOG | PURPLE_MESSAGE_NOTIFY);
34367
cb229d301bb4 Gadu-Gadu: don't unref images after sending it to first recipient
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34366
diff changeset
217 g_free(msg);
cb229d301bb4 Gadu-Gadu: don't unref images after sending it to first recipient
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34366
diff changeset
218 }
33301
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
219 }
34361
ddcc82637afa Gadu-Gadu: incoming images works again
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33368
diff changeset
220
35843
b5d03ca6a680 Gadu-Gadu: use remote features of PurpleImage instead of handling image queue
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35820
diff changeset
221 PurpleImage *
b5d03ca6a680 Gadu-Gadu: use remote features of PurpleImage instead of handling image queue
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35820
diff changeset
222 ggp_image_request(PurpleConnection *gc, uin_t uin, uint64_t id)
34361
ddcc82637afa Gadu-Gadu: incoming images works again
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33368
diff changeset
223 {
ddcc82637afa Gadu-Gadu: incoming images works again
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33368
diff changeset
224 GGPInfo *accdata = purple_connection_get_protocol_data(gc);
34362
758e72362ca4 Gadu-Gadu: code polishing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34361
diff changeset
225 ggp_image_session_data *sdata = ggp_image_get_sdata(gc);
35843
b5d03ca6a680 Gadu-Gadu: use remote features of PurpleImage instead of handling image queue
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35820
diff changeset
226 PurpleImage *img;
34361
ddcc82637afa Gadu-Gadu: incoming images works again
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33368
diff changeset
227 uint32_t crc = id >> 32;
ddcc82637afa Gadu-Gadu: incoming images works again
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33368
diff changeset
228 uint32_t size = id;
35355
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34946
diff changeset
229
35360
29d788c72350 Style: fix gg braces (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35355
diff changeset
230 if (size > GGP_IMAGE_SIZE_MAX && crc <= GGP_IMAGE_SIZE_MAX) {
34361
ddcc82637afa Gadu-Gadu: incoming images works again
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33368
diff changeset
231 uint32_t tmp;
ddcc82637afa Gadu-Gadu: incoming images works again
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33368
diff changeset
232 purple_debug_warning("gg", "ggp_image_request: "
ddcc82637afa Gadu-Gadu: incoming images works again
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33368
diff changeset
233 "crc and size are swapped!\n");
ddcc82637afa Gadu-Gadu: incoming images works again
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33368
diff changeset
234 tmp = crc;
ddcc82637afa Gadu-Gadu: incoming images works again
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33368
diff changeset
235 crc = size;
ddcc82637afa Gadu-Gadu: incoming images works again
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33368
diff changeset
236 size = tmp;
35843
b5d03ca6a680 Gadu-Gadu: use remote features of PurpleImage instead of handling image queue
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35820
diff changeset
237 id = ggp_image_params_to_id(crc, size);
b5d03ca6a680 Gadu-Gadu: use remote features of PurpleImage instead of handling image queue
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35820
diff changeset
238 }
b5d03ca6a680 Gadu-Gadu: use remote features of PurpleImage instead of handling image queue
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35820
diff changeset
239
b5d03ca6a680 Gadu-Gadu: use remote features of PurpleImage instead of handling image queue
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35820
diff changeset
240 img = g_hash_table_lookup(sdata->recv_images, &id);
b5d03ca6a680 Gadu-Gadu: use remote features of PurpleImage instead of handling image queue
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35820
diff changeset
241 if (img) {
b5d03ca6a680 Gadu-Gadu: use remote features of PurpleImage instead of handling image queue
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35820
diff changeset
242 purple_debug_info("gg", "ggp_image_request: "
b5d03ca6a680 Gadu-Gadu: use remote features of PurpleImage instead of handling image queue
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35820
diff changeset
243 "image " GGP_IMAGE_ID_FORMAT " got from cache", id);
b5d03ca6a680 Gadu-Gadu: use remote features of PurpleImage instead of handling image queue
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35820
diff changeset
244 return img;
34361
ddcc82637afa Gadu-Gadu: incoming images works again
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33368
diff changeset
245 }
35355
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34946
diff changeset
246
35843
b5d03ca6a680 Gadu-Gadu: use remote features of PurpleImage instead of handling image queue
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35820
diff changeset
247
38281
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 37148
diff changeset
248 g_hash_table_insert(sdata->recv_images, ggp_uint64dup(id), NULL);
35355
3be5d45ba972 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34946
diff changeset
249
35843
b5d03ca6a680 Gadu-Gadu: use remote features of PurpleImage instead of handling image queue
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35820
diff changeset
250 purple_debug_info("gg", "ggp_image_request: requesting image "
b5d03ca6a680 Gadu-Gadu: use remote features of PurpleImage instead of handling image queue
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35820
diff changeset
251 GGP_IMAGE_ID_FORMAT, id);
b5d03ca6a680 Gadu-Gadu: use remote features of PurpleImage instead of handling image queue
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35820
diff changeset
252 if (gg_image_request(accdata->session, uin, size, crc) != 0)
b5d03ca6a680 Gadu-Gadu: use remote features of PurpleImage instead of handling image queue
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35820
diff changeset
253 purple_debug_error("gg", "ggp_image_request: failed");
34362
758e72362ca4 Gadu-Gadu: code polishing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34361
diff changeset
254
35843
b5d03ca6a680 Gadu-Gadu: use remote features of PurpleImage instead of handling image queue
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35820
diff changeset
255 return img;
34362
758e72362ca4 Gadu-Gadu: code polishing
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34361
diff changeset
256 }

mercurial