libpurple/protocols/gg/avatar.c

Tue, 14 Dec 2021 01:57:01 -0600

author
Elliott Sales de Andrade <qulogic@pidgin.im>
date
Tue, 14 Dec 2021 01:57:01 -0600
changeset 41214
b0b7d118475f
parent 41213
0b5c475770e2
child 41216
5c4269ad7ee4
permissions
-rw-r--r--

Use accessor for SoupMessage->request_headers

33348
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33343
diff changeset
1 /* purple
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33343
diff changeset
2 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33343
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: 33343
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: 33343
diff changeset
5 * source distribution.
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33343
diff changeset
6 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33343
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: 33343
diff changeset
8 * by Tomek Wasilczyk (http://www.wasilczyk.pl).
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33343
diff changeset
9 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33343
diff changeset
10 * Previously implemented by:
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33343
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: 33343
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: 33343
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: 33343
diff changeset
14 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33343
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: 33343
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: 33343
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: 33343
diff changeset
18 * (at your option) any later version.
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33343
diff changeset
19 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33343
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: 33343
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: 33343
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: 33343
diff changeset
23 * GNU General Public License for more details.
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33343
diff changeset
24 *
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33343
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: 33343
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: 33343
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: 33343
diff changeset
28 */
2394cd23ce8f Gadu-Gadu: add GSoC copyright note
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33343
diff changeset
29
33313
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
30 #include "avatar.h"
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
31
40756
3a58ef28ee44 Implement mitigation for GHSL-2021-045
Gary Kramlich <grim@reaperworld.com>
parents: 40708
diff changeset
32 #include "libpurple/glibcompat.h"
41212
9f0f4c23132e Use accessor for SoupMessage->status_code
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40756
diff changeset
33 #include "libpurple/soupcompat.h"
40756
3a58ef28ee44 Implement mitigation for GHSL-2021-045
Gary Kramlich <grim@reaperworld.com>
parents: 40708
diff changeset
34
33313
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
35 #include "gg.h"
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
36 #include "utils.h"
33333
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
37 #include "oauth/oauth-purple.h"
33313
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
38
35354
aa1f0e988567 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35353
diff changeset
39 /* Common */
33313
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
40
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
41 #define GGP_AVATAR_USERAGENT "GG Client build 11.0.0.7562"
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
42 #define GGP_AVATAR_SIZE_MAX 1048576
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
43
35354
aa1f0e988567 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35353
diff changeset
44 /* Buddy avatars updating */
33313
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
45
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
46 typedef struct
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
47 {
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
48 uin_t uin;
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
49 time_t timestamp;
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
50 PurpleConnection *gc;
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
51 } ggp_avatar_buddy_update_req;
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
52
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
53 #define GGP_AVATAR_BUDDY_URL "http://avatars.gg.pl/%u/s,big"
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
54
35354
aa1f0e988567 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35353
diff changeset
55 /* Own avatar setting */
33333
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
56
40024
dad0e4c75135 Remove extra indirection with ggp_avatar_session_data.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40023
diff changeset
57 struct _ggp_avatar_session_data {
dad0e4c75135 Remove extra indirection with ggp_avatar_session_data.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40023
diff changeset
58 PurpleImage *own_img;
dad0e4c75135 Remove extra indirection with ggp_avatar_session_data.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40023
diff changeset
59 };
33333
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
60
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
61 #define GGP_AVATAR_RESPONSE_MAX 10240
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
62
33313
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
63 /*******************************************************************************
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
64 * Common.
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
65 ******************************************************************************/
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
66
40011
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
67 static inline ggp_avatar_session_data *
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
68 ggp_avatar_get_avdata(PurpleConnection *gc)
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
69 {
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
70 GGPInfo *accdata = purple_connection_get_protocol_data(gc);
40024
dad0e4c75135 Remove extra indirection with ggp_avatar_session_data.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40023
diff changeset
71 return accdata->avatar_data;
40011
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
72 }
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
73
33313
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
74 void ggp_avatar_setup(PurpleConnection *gc)
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
75 {
40024
dad0e4c75135 Remove extra indirection with ggp_avatar_session_data.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40023
diff changeset
76 GGPInfo *info = purple_connection_get_protocol_data(gc);
33313
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
77
40024
dad0e4c75135 Remove extra indirection with ggp_avatar_session_data.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40023
diff changeset
78 info->avatar_data = g_new0(ggp_avatar_session_data, 1);
33313
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
79 }
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
80
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
81 void ggp_avatar_cleanup(PurpleConnection *gc)
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
82 {
40024
dad0e4c75135 Remove extra indirection with ggp_avatar_session_data.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40023
diff changeset
83 GGPInfo *info = purple_connection_get_protocol_data(gc);
33313
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
84
40024
dad0e4c75135 Remove extra indirection with ggp_avatar_session_data.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40023
diff changeset
85 g_free(info->avatar_data);
33313
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
86 }
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
87
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
88 /*******************************************************************************
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
89 * Buddy avatars updating.
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
90 ******************************************************************************/
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
91
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
92 void ggp_avatar_buddy_remove(PurpleConnection *gc, uin_t uin)
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
93 {
34419
8446175c6c08 Gadu-Gadu: make gg prpl less verbose in non-verbose mode
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34378
diff changeset
94 if (purple_debug_is_verbose()) {
8446175c6c08 Gadu-Gadu: make gg prpl less verbose in non-verbose mode
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34378
diff changeset
95 purple_debug_misc("gg", "ggp_avatar_buddy_remove(%p, %u)\n", gc, uin);
8446175c6c08 Gadu-Gadu: make gg prpl less verbose in non-verbose mode
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34378
diff changeset
96 }
33328
c71e5e8976ba Gadu-Gadu: avatar removal is possible, so lets handle it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
97
c71e5e8976ba Gadu-Gadu: avatar removal is possible, so lets handle it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
98 purple_buddy_icons_set_for_user(purple_connection_get_account(gc),
c71e5e8976ba Gadu-Gadu: avatar removal is possible, so lets handle it
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33313
diff changeset
99 ggp_uin_to_str(uin), NULL, 0, NULL);
33313
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
100 }
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
101
40011
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
102 static void
40019
5bf1b06ebd65 Convert GG avatar fetching to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40011
diff changeset
103 ggp_avatar_buddy_update_received(G_GNUC_UNUSED SoupSession *session,
5bf1b06ebd65 Convert GG avatar fetching to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40011
diff changeset
104 SoupMessage *msg, gpointer _pending_update)
40011
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
105 {
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
106 ggp_avatar_buddy_update_req *pending_update = _pending_update;
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
107 PurpleBuddy *buddy;
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
108 PurpleAccount *account;
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
109 PurpleConnection *gc = pending_update->gc;
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
110 gchar timestamp_str[20];
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
111 const gchar *got_data;
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
112 size_t got_len;
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
113
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
114 PURPLE_ASSERT_CONNECTION_IS_VALID(gc);
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
115
41212
9f0f4c23132e Use accessor for SoupMessage->status_code
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40756
diff changeset
116 if (!SOUP_STATUS_IS_SUCCESSFUL(soup_message_get_status(msg))) {
40011
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
117 purple_debug_error("gg",
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
118 "ggp_avatar_buddy_update_received: bad response "
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
119 "while getting avatar for %u: %s",
41213
0b5c475770e2 Use accessor for SoupMessage->reason_phrase
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 41212
diff changeset
120 pending_update->uin,
0b5c475770e2 Use accessor for SoupMessage->reason_phrase
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 41212
diff changeset
121 soup_message_get_reason_phrase(msg));
40011
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
122 g_free(pending_update);
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
123 return;
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
124 }
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
125
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
126 account = purple_connection_get_account(gc);
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
127 buddy = purple_blist_find_buddy(account,
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
128 ggp_uin_to_str(pending_update->uin));
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
129
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
130 if (!buddy) {
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
131 purple_debug_warning(
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
132 "gg", "ggp_avatar_buddy_update_received: buddy %u disappeared",
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
133 pending_update->uin);
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
134 g_free(pending_update);
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
135 return;
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
136 }
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
137
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
138 g_snprintf(timestamp_str, sizeof(timestamp_str), "%lu",
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
139 pending_update->timestamp);
40019
5bf1b06ebd65 Convert GG avatar fetching to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40011
diff changeset
140 got_data = msg->response_body->data;
5bf1b06ebd65 Convert GG avatar fetching to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40011
diff changeset
141 got_len = msg->response_body->length;
40011
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
142 purple_buddy_icons_set_for_user(account, purple_buddy_get_name(buddy),
40756
3a58ef28ee44 Implement mitigation for GHSL-2021-045
Gary Kramlich <grim@reaperworld.com>
parents: 40708
diff changeset
143 g_memdup2(got_data, got_len), got_len,
40011
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
144 timestamp_str);
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
145
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
146 purple_debug_info("gg",
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
147 "ggp_avatar_buddy_update_received: got avatar for buddy "
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
148 "%u [ts=%lu]",
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
149 pending_update->uin, pending_update->timestamp);
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
150 g_free(pending_update);
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
151 }
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
152
40023
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
153 void
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
154 ggp_avatar_buddy_update(PurpleConnection *gc, uin_t uin, time_t timestamp)
33313
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
155 {
40019
5bf1b06ebd65 Convert GG avatar fetching to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40011
diff changeset
156 GGPInfo *info = purple_connection_get_protocol_data(gc);
5bf1b06ebd65 Convert GG avatar fetching to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40011
diff changeset
157 gchar *url;
5bf1b06ebd65 Convert GG avatar fetching to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40011
diff changeset
158 SoupMessage *req;
33313
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
159 ggp_avatar_buddy_update_req *pending_update;
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
160 PurpleBuddy *buddy;
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
161 PurpleAccount *account = purple_connection_get_account(gc);
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
162 time_t old_timestamp;
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
163 const char *old_timestamp_str;
34232
a5517f235e0f HTTP: migrate purple_util_fetch_url_request to new API for GG prpl
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33865
diff changeset
164
40023
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
165 if (purple_debug_is_verbose()) {
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
166 purple_debug_misc("gg", "ggp_avatar_buddy_update(%p, %u, %lu)", gc, uin,
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
167 timestamp);
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
168 }
34232
a5517f235e0f HTTP: migrate purple_util_fetch_url_request to new API for GG prpl
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33865
diff changeset
169
40023
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
170 buddy = purple_blist_find_buddy(account, ggp_uin_to_str(uin));
35353
1f5964260577 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35351
diff changeset
171
35360
29d788c72350 Style: fix gg braces (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35354
diff changeset
172 if (!buddy) {
40023
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
173 if (ggp_str_to_uin(purple_account_get_username(account)) == uin) {
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
174 purple_debug_misc(
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
175 "gg",
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
176 "ggp_avatar_buddy_update(%p): own avatar update requested, "
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
177 "but we don't have ourselves on buddy list",
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
178 gc);
35360
29d788c72350 Style: fix gg braces (part 1)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35354
diff changeset
179 } else {
33313
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
180 purple_debug_warning("gg",
40023
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
181 "ggp_avatar_buddy_update(%p): %u update "
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
182 "requested, but he's not on buddy list",
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
183 gc, uin);
33313
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
184 }
40023
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
185 return;
33313
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
186 }
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
187
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
188 old_timestamp_str = purple_buddy_icons_get_checksum_for_user(buddy);
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
189 old_timestamp = old_timestamp_str ? g_ascii_strtoull(
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
190 old_timestamp_str, NULL, 10) : 0;
40023
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
191 if (old_timestamp == timestamp) {
34419
8446175c6c08 Gadu-Gadu: make gg prpl less verbose in non-verbose mode
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34378
diff changeset
192 if (purple_debug_is_verbose()) {
8446175c6c08 Gadu-Gadu: make gg prpl less verbose in non-verbose mode
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34378
diff changeset
193 purple_debug_misc("gg",
40023
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
194 "ggp_avatar_buddy_update(%p): %u have up to date "
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
195 "avatar with ts=%lu",
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
196 gc, uin, timestamp);
34419
8446175c6c08 Gadu-Gadu: make gg prpl less verbose in non-verbose mode
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34378
diff changeset
197 }
40023
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
198 return;
33313
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
199 }
40023
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
200 if (old_timestamp > timestamp) {
33313
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
201 purple_debug_warning("gg",
40023
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
202 "ggp_avatar_buddy_update(%p): saved timestamp for "
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
203 "%u is newer than received (%lu > %lu)",
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
204 gc, uin, old_timestamp, timestamp);
33313
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
205 }
35353
1f5964260577 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35351
diff changeset
206
33313
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
207 purple_debug_info("gg",
40023
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
208 "ggp_avatar_buddy_update(%p): updating %u with ts=%lu...",
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
209 gc, uin, timestamp);
33313
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
210
40023
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
211 pending_update = g_new(ggp_avatar_buddy_update_req, 1);
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
212 pending_update->uin = uin;
a35b3942a698 Remove manual queuing of GG avatar fetching.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40019
diff changeset
213 pending_update->timestamp = timestamp;
33313
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
214 pending_update->gc = gc;
34232
a5517f235e0f HTTP: migrate purple_util_fetch_url_request to new API for GG prpl
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33865
diff changeset
215
40019
5bf1b06ebd65 Convert GG avatar fetching to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40011
diff changeset
216 url = g_strdup_printf(GGP_AVATAR_BUDDY_URL, pending_update->uin);
5bf1b06ebd65 Convert GG avatar fetching to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40011
diff changeset
217 req = soup_message_new("GET", url);
5bf1b06ebd65 Convert GG avatar fetching to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40011
diff changeset
218 g_free(url);
41214
b0b7d118475f Use accessor for SoupMessage->request_headers
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 41213
diff changeset
219 soup_message_headers_replace(soup_message_get_request_headers(req),
b0b7d118475f Use accessor for SoupMessage->request_headers
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 41213
diff changeset
220 "User-Agent", GGP_AVATAR_USERAGENT);
40019
5bf1b06ebd65 Convert GG avatar fetching to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40011
diff changeset
221 // purple_http_request_set_max_len(req, GGP_AVATAR_SIZE_MAX);
5bf1b06ebd65 Convert GG avatar fetching to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40011
diff changeset
222 soup_session_queue_message(
5bf1b06ebd65 Convert GG avatar fetching to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40011
diff changeset
223 info->http, req, ggp_avatar_buddy_update_received, pending_update);
33313
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
224 }
5a0c6582d5b1 Gadu-Gadu: refactoring of buddy avatars handling. Fixes #13739, #14305
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
diff changeset
225
33333
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
226 /*******************************************************************************
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
227 * Own avatar setting.
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
228 ******************************************************************************/
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
229
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
230 /**
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
231 * TODO: use new, GG11 method, when IMToken will be provided by libgadu.
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
232 *
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
233 * POST https://avatars.mpa.gg.pl/avatars/user,<uin>/0
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
234 * Authorization: IMToken 0123456789abcdef0123456789abcdef01234567
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
235 * photo=<avatar content>
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
236 */
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
237
40011
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
238 static void
40019
5bf1b06ebd65 Convert GG avatar fetching to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40011
diff changeset
239 ggp_avatar_own_sent(G_GNUC_UNUSED SoupSession *session, SoupMessage *msg,
5bf1b06ebd65 Convert GG avatar fetching to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40011
diff changeset
240 gpointer user_data)
33333
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
241 {
40019
5bf1b06ebd65 Convert GG avatar fetching to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40011
diff changeset
242 PurpleConnection *gc = user_data;
35353
1f5964260577 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35351
diff changeset
243
36068
e9b9320a985a Drop PURPLE_CONNECTION_IS_VALID in favor of (temporary) PURPLE_ASSERT_CONNECTION_IS_VALID
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
244 PURPLE_ASSERT_CONNECTION_IS_VALID(gc);
35351
b48e08029b65 Style: fix gg (partially)
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34999
diff changeset
245
41212
9f0f4c23132e Use accessor for SoupMessage->status_code
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40756
diff changeset
246 if (!SOUP_STATUS_IS_SUCCESSFUL(soup_message_get_status(msg))) {
40019
5bf1b06ebd65 Convert GG avatar fetching to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40011
diff changeset
247 purple_debug_error("gg", "ggp_avatar_own_sent: avatar not sent. %s\n",
41213
0b5c475770e2 Use accessor for SoupMessage->reason_phrase
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 41212
diff changeset
248 soup_message_get_reason_phrase(msg));
33333
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
249 return;
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
250 }
40011
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
251 purple_debug_info("gg", "ggp_avatar_own_sent: %s\n",
40019
5bf1b06ebd65 Convert GG avatar fetching to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40011
diff changeset
252 msg->response_body->data);
33333
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
253 }
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
254
35819
cc375b914104 imgstore: remove refs from gg prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35360
diff changeset
255 static void
cc375b914104 imgstore: remove refs from gg prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35360
diff changeset
256 ggp_avatar_own_got_token(PurpleConnection *gc, const gchar *token,
cc375b914104 imgstore: remove refs from gg prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35360
diff changeset
257 gpointer _img)
33333
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
258 {
40019
5bf1b06ebd65 Convert GG avatar fetching to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40011
diff changeset
259 GGPInfo *info = purple_connection_get_protocol_data(gc);
40024
dad0e4c75135 Remove extra indirection with ggp_avatar_session_data.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40023
diff changeset
260 ggp_avatar_session_data *avdata = ggp_avatar_get_avdata(gc);
40019
5bf1b06ebd65 Convert GG avatar fetching to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40011
diff changeset
261 SoupMessage *req;
41214
b0b7d118475f Use accessor for SoupMessage->request_headers
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 41213
diff changeset
262 SoupMessageHeaders *headers;
35819
cc375b914104 imgstore: remove refs from gg prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35360
diff changeset
263 PurpleImage *img = _img;
40019
5bf1b06ebd65 Convert GG avatar fetching to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40011
diff changeset
264 gchar *img_data, *uin_str;
33333
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
265 PurpleAccount *account = purple_connection_get_account(gc);
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
266 uin_t uin = ggp_str_to_uin(purple_account_get_username(account));
34232
a5517f235e0f HTTP: migrate purple_util_fetch_url_request to new API for GG prpl
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33865
diff changeset
267
40024
dad0e4c75135 Remove extra indirection with ggp_avatar_session_data.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40023
diff changeset
268 if (img != avdata->own_img) {
33333
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
269 purple_debug_warning("gg", "ggp_avatar_own_got_token: "
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
270 "avatar was changed in meantime\n");
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
271 return;
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
272 }
40024
dad0e4c75135 Remove extra indirection with ggp_avatar_session_data.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40023
diff changeset
273 avdata->own_img = NULL;
34232
a5517f235e0f HTTP: migrate purple_util_fetch_url_request to new API for GG prpl
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33865
diff changeset
274
38341
3da74e727e78 Remove purple_base64_encode/decode() wrappers
Mike Ruprecht <cmaiku@gmail.com>
parents: 38298
diff changeset
275 img_data = g_base64_encode(purple_image_get_data(img),
38298
f0a8f63f9312 rename purple_image_get_size to purple_image_get_data_size and deal with the fallout
Gary Kramlich <grim@reaperworld.com>
parents: 36068
diff changeset
276 purple_image_get_data_size(img));
40019
5bf1b06ebd65 Convert GG avatar fetching to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40011
diff changeset
277 uin_str = g_strdup_printf("%d", uin);
34232
a5517f235e0f HTTP: migrate purple_util_fetch_url_request to new API for GG prpl
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33865
diff changeset
278
33333
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
279 purple_debug_misc("gg", "ggp_avatar_own_got_token: "
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
280 "uploading new avatar...\n");
34232
a5517f235e0f HTTP: migrate purple_util_fetch_url_request to new API for GG prpl
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33865
diff changeset
281
40019
5bf1b06ebd65 Convert GG avatar fetching to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40011
diff changeset
282 req = soup_form_request_new("POST", "http://avatars.nowe.gg/upload", "uin",
5bf1b06ebd65 Convert GG avatar fetching to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40011
diff changeset
283 uin_str, "photo", img_data, NULL);
5bf1b06ebd65 Convert GG avatar fetching to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40011
diff changeset
284 // purple_http_request_set_max_len(req, GGP_AVATAR_RESPONSE_MAX);
41214
b0b7d118475f Use accessor for SoupMessage->request_headers
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 41213
diff changeset
285 headers = soup_message_get_request_headers(req);
b0b7d118475f Use accessor for SoupMessage->request_headers
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 41213
diff changeset
286 soup_message_headers_replace(headers, "Authorization", token);
b0b7d118475f Use accessor for SoupMessage->request_headers
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 41213
diff changeset
287 soup_message_headers_replace(headers, "From", "avatars to avatars");
40019
5bf1b06ebd65 Convert GG avatar fetching to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40011
diff changeset
288 soup_session_queue_message(info->http, req, ggp_avatar_own_sent, gc);
5bf1b06ebd65 Convert GG avatar fetching to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40011
diff changeset
289 g_free(img_data);
5bf1b06ebd65 Convert GG avatar fetching to libsoup.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40011
diff changeset
290 g_free(uin_str);
33333
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
291 }
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
292
40011
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
293 void
40708
53a26c29d26c Move the PurpleProtocolServer interface to its own file.
Gary Kramlich <grim@reaperworld.com>
parents: 40474
diff changeset
294 ggp_avatar_own_set(PurpleProtocolServer *protocol_server, PurpleConnection *gc,
53a26c29d26c Move the PurpleProtocolServer interface to its own file.
Gary Kramlich <grim@reaperworld.com>
parents: 40474
diff changeset
295 PurpleImage *img)
33333
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
296 {
40024
dad0e4c75135 Remove extra indirection with ggp_avatar_session_data.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40023
diff changeset
297 ggp_avatar_session_data *avdata;
34232
a5517f235e0f HTTP: migrate purple_util_fetch_url_request to new API for GG prpl
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33865
diff changeset
298
36068
e9b9320a985a Drop PURPLE_CONNECTION_IS_VALID in favor of (temporary) PURPLE_ASSERT_CONNECTION_IS_VALID
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
299 PURPLE_ASSERT_CONNECTION_IS_VALID(gc);
34232
a5517f235e0f HTTP: migrate purple_util_fetch_url_request to new API for GG prpl
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33865
diff changeset
300
40011
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
301 purple_debug_info("gg", "ggp_avatar_own_set(%p, %p)", gc, img);
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
302
40024
dad0e4c75135 Remove extra indirection with ggp_avatar_session_data.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40023
diff changeset
303 avdata = ggp_avatar_get_avdata(gc);
40011
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
304
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
305 if (img == NULL) {
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
306 purple_debug_warning("gg", "ggp_avatar_own_set: avatar removing is "
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
307 "probably not possible within old protocol");
34232
a5517f235e0f HTTP: migrate purple_util_fetch_url_request to new API for GG prpl
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33865
diff changeset
308 return;
a5517f235e0f HTTP: migrate purple_util_fetch_url_request to new API for GG prpl
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33865
diff changeset
309 }
40011
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
310
40024
dad0e4c75135 Remove extra indirection with ggp_avatar_session_data.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 40023
diff changeset
311 avdata->own_img = img;
40011
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
312
3225e0bb6cea Re-arrange GG avatar file to avoid prototypes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38433
diff changeset
313 ggp_oauth_request(gc, ggp_avatar_own_got_token, img, NULL, NULL);
33333
b20aed44c357 Gadu-Gadu: setting own buddy icon
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33328
diff changeset
314 }

mercurial