libpurple/protocols/gg/image.c

Wed, 21 Aug 2013 14:59:29 +0200

author
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
date
Wed, 21 Aug 2013 14:59:29 +0200
changeset 34304
faf0414a8b51
parent 33865
3f1be2d7ae11
child 34423
637fc4614dcc
child 34622
753f46dd000f
permissions
-rw-r--r--

Fix most of libpurple warnings about -Wsign-compare

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
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
30 #include "image.h"
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 <debug.h>
33368
6aa16fdab83f Fix compilation of older distros. Fixes #15310
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33351
diff changeset
33 #include <glibcompat.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
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
35 #include "gg.h"
33299
b3c4ab3aeb7f Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33298
diff changeset
36 #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
37
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 #define GGP_PENDING_IMAGE_ID_PREFIX "gg-pending-image-"
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
39
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
40 typedef struct
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
41 {
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 uin_t from;
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
43 gchar *text;
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
44 time_t mtime;
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
45 } ggp_image_pending_message;
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
46
33302
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
47 typedef struct
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
48 {
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
49 int id;
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
50 gchar *conv_name;
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
51 } ggp_image_pending_image;
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
52
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
53 static void ggp_image_pending_message_free(gpointer data)
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
54 {
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
55 ggp_image_pending_message *pending_message =
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
56 (ggp_image_pending_message*)data;
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
57 g_free(pending_message->text);
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
58 g_free(pending_message);
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
59 }
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
60
33302
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
61 static void ggp_image_pending_image_free(gpointer data)
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
62 {
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
63 ggp_image_pending_image *pending_image =
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
64 (ggp_image_pending_image*)data;
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
65 g_free(pending_image->conv_name);
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
66 g_free(pending_image);
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
67 }
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
68
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
69 static inline ggp_image_connection_data *
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 ggp_image_get_imgdata(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
71 {
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
72 GGPInfo *accdata = purple_connection_get_protocol_data(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
73 return &accdata->image_data;
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
74 }
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
75
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
76 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
77 {
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
78 ggp_image_connection_data *imgdata = ggp_image_get_imgdata(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
79
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
80 imgdata->pending_messages = NULL;
33302
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
81 imgdata->pending_images = g_hash_table_new_full(NULL, NULL, NULL,
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
82 ggp_image_pending_image_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
83 }
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
33313
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33302
diff changeset
85 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
86 {
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
87 ggp_image_connection_data *imgdata = ggp_image_get_imgdata(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
88
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
89 g_list_free_full(imgdata->pending_messages,
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 &ggp_image_pending_message_free);
33301
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
91 g_hash_table_destroy(imgdata->pending_images);
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
92 }
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
93
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 const char * ggp_image_pending_placeholder(uint32_t id)
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
95 {
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
96 static char buff[50];
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
97
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
98 g_snprintf(buff, 50, "<img id=\"" GGP_PENDING_IMAGE_ID_PREFIX
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
99 "%u\">", id);
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
100
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
101 return buff;
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
102 }
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
103
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
104 void ggp_image_got_im(PurpleConnection *gc, uin_t from, gchar *text,
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
105 time_t mtime)
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
106 {
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
107 ggp_image_connection_data *imgdata = ggp_image_get_imgdata(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
108 ggp_image_pending_message *pending_message =
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
109 g_new(ggp_image_pending_message, 1);
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
110
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
111 purple_debug_info("gg", "ggp_image_got_im: received message with "
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
112 "images from %u: %s\n", from, text);
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
113
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
114 pending_message->from = from;
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
115 pending_message->text = text;
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
116 pending_message->mtime = mtime;
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
117
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
118 imgdata->pending_messages = g_list_append(imgdata->pending_messages,
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
119 pending_message);
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
120 }
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
121
33301
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
122 ggp_image_prepare_result ggp_image_prepare(PurpleConnection *gc, const int id,
33302
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
123 const char *conv_name, struct gg_msg_richtext_image *image_info)
33301
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
124 {
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
125 ggp_image_connection_data *imgdata = ggp_image_get_imgdata(gc);
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
126 PurpleStoredImage *image = purple_imgstore_find_by_id(id);
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
127 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
128 gconstpointer image_data;
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
129 const char *image_filename;
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
130 uint32_t image_crc;
33302
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
131 ggp_image_pending_image *pending_image;
33301
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
132
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
133 if (!image)
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
134 {
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
135 purple_debug_error("gg", "ggp_image_prepare_to_send: image %d "
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
136 "not found in image store\n", id);
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
137 return GGP_IMAGE_PREPARE_FAILURE;
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
138 }
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
139
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
140 image_size = purple_imgstore_get_size(image);
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
141
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
142 if (image_size > 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
143 {
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
144 purple_debug_warning("gg", "ggp_image_prepare_to_send: image "
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
145 "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
146 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
147 }
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
148
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
149 purple_imgstore_ref(image);
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
150 image_data = purple_imgstore_get_data(image);
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
151 image_filename = purple_imgstore_get_filename(image);
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
152 image_crc = gg_crc32(0, image_data, image_size);
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
153
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
154 purple_debug_info("gg", "ggp_image_prepare_to_send: image prepared "
33865
3f1be2d7ae11 Gadu-Gadu: fix some warnings
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33762
diff changeset
155 "[id=%d, crc=%u, size=%" G_GSIZE_FORMAT ", filename=%s]\n",
33301
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
156 id, image_crc, image_size, image_filename);
33302
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
157
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
158 pending_image = g_new(ggp_image_pending_image, 1);
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
159 pending_image->id = id;
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
160 pending_image->conv_name = g_strdup(conv_name);
33301
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
161 g_hash_table_insert(imgdata->pending_images, GINT_TO_POINTER(image_crc),
33302
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
162 pending_image);
33301
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
163
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
164 image_info->unknown1 = 0x0109;
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
165 image_info->size = gg_fix32(image_size);
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
166 image_info->crc32 = gg_fix32(image_crc);
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
167
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
168 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
169 }
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
170
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
171 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
172 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
173 {
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
174 ggp_image_connection_data *imgdata = ggp_image_get_imgdata(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
175 int stored_id;
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
176 const char *imgtag_search;
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
177 gchar *imgtag_replace;
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
178 GList *pending_messages_it;
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
179
33762
7415482377b5 Add TODOs to escape filenames. I don't think these are severe problems,
Mark Doliner <mark@kingant.net>
parents: 33661
diff changeset
180 /* TODO: This PurpleStoredImage will be rendered within the IM window
7415482377b5 Add TODOs to escape filenames. I don't think these are severe problems,
Mark Doliner <mark@kingant.net>
parents: 33661
diff changeset
181 and right-clicking the image will allow the user to save the image
7415482377b5 Add TODOs to escape filenames. I don't think these are severe problems,
Mark Doliner <mark@kingant.net>
parents: 33661
diff changeset
182 to disk. The default filename used in this dialog is the filename
7415482377b5 Add TODOs to escape filenames. I don't think these are severe problems,
Mark Doliner <mark@kingant.net>
parents: 33661
diff changeset
183 that we pass to purple_imgstore_new_with_id(), so we should call
7415482377b5 Add TODOs to escape filenames. I don't think these are severe problems,
Mark Doliner <mark@kingant.net>
parents: 33661
diff changeset
184 g_path_get_basename() and purple_escape_filename() on it before
7415482377b5 Add TODOs to escape filenames. I don't think these are severe problems,
Mark Doliner <mark@kingant.net>
parents: 33661
diff changeset
185 passing it in. This is easy, but it's not clear if there might be
7415482377b5 Add TODOs to escape filenames. I don't think these are severe problems,
Mark Doliner <mark@kingant.net>
parents: 33661
diff changeset
186 other implications because this filename is used elsewhere within
7415482377b5 Add TODOs to escape filenames. I don't think these are severe problems,
Mark Doliner <mark@kingant.net>
parents: 33661
diff changeset
187 this PRPL. */
33661
2ebcb105e606 Rename two functions.
Mark Doliner <mark@kingant.net>
parents: 33368
diff changeset
188 stored_id = purple_imgstore_new_with_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
189 g_memdup(image_reply->image, image_reply->size),
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
190 image_reply->size,
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
191 image_reply->filename);
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
192
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
193 purple_debug_info("gg", "ggp_image_recv: got image "
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
194 "[id=%d, crc=%u, size=%u, filename=\"%s\"]\n",
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
195 stored_id,
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
196 image_reply->crc32,
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
197 image_reply->size,
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
198 image_reply->filename);
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
199
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
200 imgtag_search = ggp_image_pending_placeholder(image_reply->crc32);
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
201 imgtag_replace = g_strdup_printf("<img src=\""
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
202 PURPLE_STORED_IMAGE_PROTOCOL "%u\">", stored_id);
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
203
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
204 pending_messages_it = g_list_first(imgdata->pending_messages);
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
205 while (pending_messages_it)
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
206 {
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
207 ggp_image_pending_message *pending_message =
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
208 (ggp_image_pending_message*)pending_messages_it->data;
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
209 gchar *newText;
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
210
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
211 if (strstr(pending_message->text, imgtag_search) == NULL)
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
212 {
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
213 pending_messages_it = g_list_next(pending_messages_it);
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
214 continue;
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
215 }
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
216
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
217 purple_debug_misc("gg", "ggp_image_recv: found message "
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
218 "containing image: %s\n", pending_message->text);
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
219
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
220 newText = purple_strreplace(pending_message->text,
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
221 imgtag_search, imgtag_replace);
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
222 g_free(pending_message->text);
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
223 pending_message->text = newText;
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
224
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
225 if (strstr(pending_message->text,
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
226 "<img id=\"" GGP_PENDING_IMAGE_ID_PREFIX) == NULL)
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
227 {
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
228 purple_debug_info("gg", "ggp_image_recv: "
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
229 "message is ready to display\n");
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
230 serv_got_im(gc, ggp_uin_to_str(pending_message->from),
33299
b3c4ab3aeb7f Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33298
diff changeset
231 pending_message->text,
b3c4ab3aeb7f Gadu-Gadu: utils refactoring, (partially) fix new account registration
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33298
diff changeset
232 PURPLE_MESSAGE_RECV | PURPLE_MESSAGE_IMAGES,
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
233 pending_message->mtime);
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
234
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
235 ggp_image_pending_message_free(pending_message);
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
236 imgdata->pending_messages = g_list_remove(
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
237 imgdata->pending_messages, pending_message);
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
238 }
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
239
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
240 pending_messages_it = g_list_next(pending_messages_it);
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
241 }
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
242 g_free(imgtag_replace);
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
243 }
33301
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
244
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
245 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
246 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
247 {
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
248 GGPInfo *accdata = purple_connection_get_protocol_data(gc);
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
249 ggp_image_connection_data *imgdata = ggp_image_get_imgdata(gc);
33302
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
250 ggp_image_pending_image *pending_image;
33301
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
251 PurpleStoredImage *image;
33302
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
252 PurpleConversation *conv;
33301
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
253
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
254 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
255 "[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
256 image_request->sender,
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
257 image_request->crc32,
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
258 image_request->size);
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
259
33302
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
260 pending_image = g_hash_table_lookup(imgdata->pending_images,
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
261 GINT_TO_POINTER(image_request->crc32));
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
262
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
263 if (pending_image == NULL)
33301
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
264 {
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
265 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
266 "not found\n");
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
267 return;
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
268 }
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
269
33302
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
270 purple_debug_misc("gg", "ggp_image_send: requested image found "
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
271 "[id=%d, conv=%s]\n",
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
272 pending_image->id,
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
273 pending_image->conv_name);
33301
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
274
33302
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
275 image = purple_imgstore_find_by_id(pending_image->id);
33301
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
276
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
277 if (!image)
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
278 {
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
279 purple_debug_error("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
280 "found, but doesn't exists in image store\n");
33302
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
281 g_hash_table_remove(imgdata->pending_images,
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
282 GINT_TO_POINTER(image_request->crc32));
33301
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
283 return;
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
284 }
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
285
33302
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
286 //TODO: check allowed recipients
33301
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
287 gg_image_reply(accdata->session, image_request->sender,
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
288 purple_imgstore_get_filename(image),
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
289 purple_imgstore_get_data(image),
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
290 purple_imgstore_get_size(image));
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
291 purple_imgstore_unref(image);
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
292
33302
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
293 conv = purple_find_conversation_with_account(
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
294 PURPLE_CONV_TYPE_IM, pending_image->conv_name,
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
295 purple_connection_get_account(gc));
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
296 if (conv != NULL)
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
297 purple_conversation_write(conv, "", _("Image delivered."),
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
298 PURPLE_MESSAGE_NO_LOG | PURPLE_MESSAGE_NOTIFY,
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
299 time(NULL));
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
300
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
301 g_hash_table_remove(imgdata->pending_images,
e094fcb98670 Gadu-Gadu: acknowledgment for sent images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33301
diff changeset
302 GINT_TO_POINTER(image_request->crc32));
33301
3f18ba8aed0f Gadu-Gadu sending images refactoring; notify about too large images
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33299
diff changeset
303 }

mercurial