annotate libpurple/protocols/jabber/useravatar.c @ 25355:ba8f51cb3691

Support XEP-0084 (User Avatar) v1.1 alongside v0.12 Publish avatars to both namespaces and support receiving metadata notifications from either one. The fetching of our own avatars needs to be fixed to fetch the metdata for both namespaces. Closes #7732.
author Paul Aurich <paul@darkrain42.org>
date Mon, 26 Jan 2009 03:52:05 +0000
parents 9195955395b6
children c0a27a44ebd6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25351
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
1 /*
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
2 * purple - Jabber Protocol Plugin
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
3 *
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
4 * Purple is the legal property of its developers, whose names are too numerous
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
6 * source distribution.
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
7 *
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
11 * (at your option) any later version.
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
12 *
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
16 * GNU General Public License for more details.
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
17 *
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
21 *
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
22 */
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
23
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
24 #include "internal.h"
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
25
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
26 #include "useravatar.h"
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
27 #include "pep.h"
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
28 #include "debug.h"
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
29
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
30 #define MAX_HTTP_BUDDYICON_BYTES (200 * 1024)
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
31
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
32 static void update_buddy_metadata(JabberStream *js, const char *from, xmlnode *items);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
33
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
34 void jabber_avatar_init(void)
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
35 {
25355
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
36 jabber_add_feature("avatarmeta", NS_AVATAR_0_12_METADATA,
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
37 jabber_pep_namespace_only_when_pep_enabled_cb);
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
38 jabber_add_feature("avatardata", NS_AVATAR_0_12_DATA,
25351
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
39 jabber_pep_namespace_only_when_pep_enabled_cb);
25355
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
40 jabber_pep_register_handler("avatar", NS_AVATAR_0_12_METADATA,
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
41 update_buddy_metadata);
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
42
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
43 jabber_add_feature("urn_avatarmeta", NS_AVATAR_1_1_METADATA,
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
44 jabber_pep_namespace_only_when_pep_enabled_cb);
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
45 jabber_add_feature("urn_avatardata", NS_AVATAR_1_1_DATA,
25351
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
46 jabber_pep_namespace_only_when_pep_enabled_cb);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
47
25355
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
48 jabber_pep_register_handler("urn_avatar", NS_AVATAR_1_1_METADATA,
25351
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
49 update_buddy_metadata);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
50 }
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
51
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
52 void jabber_avatar_set(JabberStream *js, PurpleStoredImage *img)
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
53 {
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
54 xmlnode *publish, *metadata, *item;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
55
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
56 if (!js->pep)
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
57 return;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
58
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
59 if (!img) {
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
60 /* remove the metadata */
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
61 publish = xmlnode_new("publish");
25355
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
62 xmlnode_set_attrib(publish, "node", NS_AVATAR_0_12_METADATA);
25351
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
63
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
64 item = xmlnode_new_child(publish, "item");
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
65 metadata = xmlnode_new_child(item, "metadata");
25355
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
66 xmlnode_set_namespace(metadata, NS_AVATAR_0_12_METADATA);
25351
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
67
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
68 xmlnode_new_child(metadata, "stop");
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
69 /* publish */
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
70 jabber_pep_publish(js, publish);
25355
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
71
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
72 /* Now for the XEP-0084 v1.1 namespace, where we publish an empty
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
73 * metadata node instead of a <stop/> element */
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
74 publish = xmlnode_new("publish");
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
75 xmlnode_set_attrib(publish, "node", NS_AVATAR_1_1_METADATA);
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
76
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
77 item = xmlnode_new_child(publish, "item");
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
78 metadata = xmlnode_new_child(item, "metadata");
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
79 xmlnode_set_namespace(metadata, NS_AVATAR_1_1_METADATA);
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
80
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
81 /* publish */
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
82 jabber_pep_publish(js, publish);
25351
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
83 } else {
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
84 /*
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
85 * TODO: This is pretty gross. The Jabber PRPL really shouldn't
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
86 * do voodoo to try to determine the image type, height
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
87 * and width.
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
88 */
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
89 /* A PNG header, including the IHDR, but nothing else */
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
90 const struct {
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
91 guchar signature[8]; /* must be hex 89 50 4E 47 0D 0A 1A 0A */
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
92 struct {
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
93 guint32 length; /* must be 0x0d */
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
94 guchar type[4]; /* must be 'I' 'H' 'D' 'R' */
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
95 guint32 width;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
96 guint32 height;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
97 guchar bitdepth;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
98 guchar colortype;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
99 guchar compression;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
100 guchar filter;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
101 guchar interlace;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
102 } ihdr;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
103 } *png = purple_imgstore_get_data(img); /* ATTN: this is in network byte order! */
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
104
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
105 /* check if the data is a valid png file (well, at least to some extend) */
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
106 if(png->signature[0] == 0x89 &&
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
107 png->signature[1] == 0x50 &&
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
108 png->signature[2] == 0x4e &&
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
109 png->signature[3] == 0x47 &&
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
110 png->signature[4] == 0x0d &&
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
111 png->signature[5] == 0x0a &&
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
112 png->signature[6] == 0x1a &&
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
113 png->signature[7] == 0x0a &&
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
114 ntohl(png->ihdr.length) == 0x0d &&
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
115 png->ihdr.type[0] == 'I' &&
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
116 png->ihdr.type[1] == 'H' &&
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
117 png->ihdr.type[2] == 'D' &&
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
118 png->ihdr.type[3] == 'R') {
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
119 /* parse PNG header to get the size of the image (yes, this is required) */
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
120 guint32 width = ntohl(png->ihdr.width);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
121 guint32 height = ntohl(png->ihdr.height);
25355
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
122 xmlnode *data, *info, *tmp;
25351
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
123 char *lengthstring, *widthstring, *heightstring;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
124
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
125 /* compute the sha1 hash */
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
126 char *hash = jabber_calculate_data_sha1sum(purple_imgstore_get_data(img), purple_imgstore_get_size(img));
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
127 char *base64avatar;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
128
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
129 publish = xmlnode_new("publish");
25355
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
130 xmlnode_set_attrib(publish, "node", NS_AVATAR_0_12_DATA);
25351
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
131
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
132 item = xmlnode_new_child(publish, "item");
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
133 xmlnode_set_attrib(item, "id", hash);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
134
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
135 data = xmlnode_new_child(item, "data");
25355
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
136 xmlnode_set_namespace(data, NS_AVATAR_0_12_DATA);
25351
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
137
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
138 base64avatar = purple_base64_encode(purple_imgstore_get_data(img),
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
139 purple_imgstore_get_size(img));
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
140 xmlnode_insert_data(data,base64avatar,-1);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
141 g_free(base64avatar);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
142
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
143 /* publish the avatar itself */
25355
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
144 tmp = xmlnode_copy(publish);
25351
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
145 jabber_pep_publish(js, publish);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
146
25355
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
147 /* publish the avatar to the XEP-0084 v1.1 namespace */
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
148 publish = tmp;
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
149 xmlnode_set_attrib(publish, "node", NS_AVATAR_1_1_DATA);
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
150
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
151 item = xmlnode_get_child(publish, "item");
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
152 data = xmlnode_get_child(item, "data");
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
153 xmlnode_set_namespace(data, NS_AVATAR_1_1_DATA);
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
154
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
155 /* publish the avatar itself */
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
156 jabber_pep_publish(js, publish);
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
157
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
158 /* next step: publish the metadata to the old namespace */
25351
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
159 publish = xmlnode_new("publish");
25355
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
160 xmlnode_set_attrib(publish,"node", NS_AVATAR_0_12_METADATA);
25351
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
161
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
162 item = xmlnode_new_child(publish, "item");
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
163 xmlnode_set_attrib(item, "id", hash);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
164
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
165 metadata = xmlnode_new_child(item, "metadata");
25355
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
166 xmlnode_set_namespace(metadata, NS_AVATAR_0_12_METADATA);
25351
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
167
25355
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
168 lengthstring = g_strdup_printf("%" G_GSIZE_FORMAT,
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
169 purple_imgstore_get_size(img));
25351
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
170 widthstring = g_strdup_printf("%u", width);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
171 heightstring = g_strdup_printf("%u", height);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
172
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
173 info = xmlnode_new_child(metadata, "info");
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
174 xmlnode_set_attrib(info, "id", hash);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
175 xmlnode_set_attrib(info, "type", "image/png");
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
176 xmlnode_set_attrib(info, "bytes", lengthstring);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
177 xmlnode_set_attrib(info, "width", widthstring);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
178 xmlnode_set_attrib(info, "height", heightstring);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
179 g_free(lengthstring);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
180 g_free(widthstring);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
181 g_free(heightstring);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
182
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
183 /* publish the metadata */
25355
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
184 tmp = xmlnode_copy(publish);
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
185 jabber_pep_publish(js, publish);
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
186
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
187 /* publish the metadata to the new namespace */
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
188 publish = tmp;
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
189 xmlnode_set_attrib(publish, "node", NS_AVATAR_1_1_METADATA);
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
190
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
191 item = xmlnode_get_child(publish, "item");
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
192 metadata = xmlnode_get_child(item, "metdata");
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
193 xmlnode_set_namespace(metadata, NS_AVATAR_1_1_METADATA);
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
194
25351
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
195 jabber_pep_publish(js, publish);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
196
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
197 g_free(hash);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
198 } else {
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
199 purple_debug_error("jabber", "Cannot set PEP avatar to non-PNG data\n");
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
200 }
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
201 }
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
202 }
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
203
25353
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
204 static void
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
205 do_got_own_avatar_cb(JabberStream *js, const char *from, xmlnode *items)
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
206 {
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
207 xmlnode *item = NULL, *metadata = NULL, *info = NULL;
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
208 PurpleAccount *account = purple_connection_get_account(js->gc);
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
209 const char *current_hash = purple_account_get_string(account, "prpl-jabber_icon_checksum", "");
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
210 const char *server_hash = NULL;
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
211
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
212 if ((item = xmlnode_get_child(items, "item")) &&
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
213 (metadata = xmlnode_get_child(item, "metadata")) &&
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
214 (info = xmlnode_get_child(metadata, "info"))) {
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
215 server_hash = xmlnode_get_attrib(info, "id");
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
216 }
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
217
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
218 /* Publish ours if it's different than the server's */
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
219 if ((!server_hash && current_hash[0] != '\0') ||
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
220 (server_hash && strcmp(server_hash, current_hash))) {
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
221 PurpleStoredImage *img = purple_buddy_icons_find_account_icon(account);
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
222 jabber_avatar_set(js, img);
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
223 purple_imgstore_unref(img);
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
224 }
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
225 }
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
226
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
227 void jabber_avatar_fetch_mine(JabberStream *js)
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
228 {
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
229 char *jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain);
25355
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
230 jabber_pep_request_item(js, jid, NS_AVATAR_0_12_METADATA, NULL,
25353
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
231 do_got_own_avatar_cb);
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
232 g_free(jid);
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
233 }
9195955395b6 Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents: 25352
diff changeset
234
25351
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
235 typedef struct _JabberBuddyAvatarUpdateURLInfo {
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
236 JabberStream *js;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
237 char *from;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
238 char *id;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
239 } JabberBuddyAvatarUpdateURLInfo;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
240
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
241 static void
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
242 do_buddy_avatar_update_fromurl(PurpleUtilFetchUrlData *url_data,
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
243 gpointer user_data, const gchar *url_text,
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
244 gsize len, const gchar *error_message)
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
245 {
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
246 JabberBuddyAvatarUpdateURLInfo *info = user_data;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
247 if(!url_text) {
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
248 purple_debug(PURPLE_DEBUG_ERROR, "jabber",
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
249 "do_buddy_avatar_update_fromurl got error \"%s\"",
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
250 error_message);
25352
b68ac693ae2d Don't leak a JabberBuddyAvatarUpdateURLInfo struct in the error case
Paul Aurich <paul@darkrain42.org>
parents: 25351
diff changeset
251 goto out;
25351
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
252 }
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
253
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
254 purple_buddy_icons_set_for_user(purple_connection_get_account(info->js->gc), info->from, (void*)url_text, len, info->id);
25352
b68ac693ae2d Don't leak a JabberBuddyAvatarUpdateURLInfo struct in the error case
Paul Aurich <paul@darkrain42.org>
parents: 25351
diff changeset
255
b68ac693ae2d Don't leak a JabberBuddyAvatarUpdateURLInfo struct in the error case
Paul Aurich <paul@darkrain42.org>
parents: 25351
diff changeset
256 out:
25351
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
257 g_free(info->from);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
258 g_free(info->id);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
259 g_free(info);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
260 }
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
261
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
262 static void
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
263 do_buddy_avatar_update_data(JabberStream *js, const char *from, xmlnode *items)
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
264 {
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
265 xmlnode *item, *data;
25355
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
266 const char *checksum, *ns;
25351
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
267 char *b64data;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
268 void *img;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
269 size_t size;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
270 if(!items)
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
271 return;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
272
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
273 item = xmlnode_get_child(items, "item");
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
274 if(!item)
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
275 return;
25355
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
276
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
277 data = xmlnode_get_child(item, "data");
25351
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
278 if(!data)
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
279 return;
25355
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
280
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
281 ns = xmlnode_get_namespace(data);
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
282 /* Make sure the namespace is one of the two valid possibilities */
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
283 if (!ns || (strcmp(ns, NS_AVATAR_0_12_DATA) &&
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
284 strcmp(ns, NS_AVATAR_1_1_DATA)))
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
285 return;
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
286
25351
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
287 checksum = xmlnode_get_attrib(item,"id");
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
288 if(!checksum)
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
289 return;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
290
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
291 b64data = xmlnode_get_data(data);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
292 if(!b64data)
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
293 return;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
294
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
295 img = purple_base64_decode(b64data, &size);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
296 if(!img) {
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
297 g_free(b64data);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
298 return;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
299 }
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
300
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
301 purple_buddy_icons_set_for_user(purple_connection_get_account(js->gc), from, img, size, checksum);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
302 g_free(b64data);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
303 }
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
304
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
305 static void
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
306 update_buddy_metadata(JabberStream *js, const char *from, xmlnode *items)
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
307 {
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
308 PurpleBuddy *buddy = purple_find_buddy(purple_connection_get_account(js->gc), from);
25355
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
309 const char *checksum, *ns;
25351
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
310 xmlnode *item, *metadata;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
311 if(!buddy)
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
312 return;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
313
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
314 checksum = purple_buddy_icons_get_checksum_for_user(buddy);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
315 item = xmlnode_get_child(items,"item");
25355
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
316 metadata = xmlnode_get_child(item, "metadata");
25351
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
317 if(!metadata)
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
318 return;
25355
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
319
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
320 ns = xmlnode_get_namespace(metadata);
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
321 /* Make sure the namespace is one of the two valid possibilities */
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
322 if (!ns || (strcmp(ns, NS_AVATAR_0_12_METADATA) &&
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
323 strcmp(ns, NS_AVATAR_1_1_METADATA)))
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
324 return;
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
325
25351
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
326 /* check if we have received a stop */
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
327 if(xmlnode_get_child(metadata, "stop")) {
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
328 purple_buddy_icons_set_for_user(purple_connection_get_account(js->gc), from, NULL, 0, NULL);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
329 } else {
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
330 xmlnode *info, *goodinfo = NULL;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
331 gboolean has_children = FALSE;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
332
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
333 /* iterate over all info nodes to get one we can use */
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
334 for(info = metadata->child; info; info = info->next) {
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
335 if(info->type == XMLNODE_TYPE_TAG)
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
336 has_children = TRUE;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
337 if(info->type == XMLNODE_TYPE_TAG && !strcmp(info->name,"info")) {
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
338 const char *type = xmlnode_get_attrib(info,"type");
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
339 const char *id = xmlnode_get_attrib(info,"id");
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
340
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
341 if(checksum && id && !strcmp(id, checksum)) {
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
342 /* we already have that avatar, so we don't have to do anything */
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
343 goodinfo = NULL;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
344 break;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
345 }
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
346 /* We'll only pick the png one for now. It's a very nice image format anyways. */
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
347 if(type && id && !goodinfo && !strcmp(type, "image/png"))
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
348 goodinfo = info;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
349 }
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
350 }
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
351 if(has_children == FALSE) {
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
352 purple_buddy_icons_set_for_user(purple_connection_get_account(js->gc), from, NULL, 0, NULL);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
353 } else if(goodinfo) {
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
354 const char *url = xmlnode_get_attrib(goodinfo, "url");
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
355 const char *id = xmlnode_get_attrib(goodinfo,"id");
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
356
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
357 /* the avatar might either be stored in a pep node, or on a HTTP(S) URL */
25355
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
358 if(!url) {
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
359 const char *data_ns;
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
360 data_ns = (strcmp(ns, NS_AVATAR_0_12_METADATA) == 0 ?
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
361 NS_AVATAR_0_12_DATA : NS_AVATAR_1_1_DATA);
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
362 jabber_pep_request_item(js, from, data_ns, id,
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
363 do_buddy_avatar_update_data);
ba8f51cb3691 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents: 25353
diff changeset
364 } else {
25351
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
365 PurpleUtilFetchUrlData *url_data;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
366 JabberBuddyAvatarUpdateURLInfo *info = g_new0(JabberBuddyAvatarUpdateURLInfo, 1);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
367 info->js = js;
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
368
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
369 url_data = purple_util_fetch_url_len(url, TRUE, NULL, TRUE,
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
370 MAX_HTTP_BUDDYICON_BYTES,
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
371 do_buddy_avatar_update_fromurl, info);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
372 if (url_data) {
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
373 info->from = g_strdup(from);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
374 info->id = g_strdup(id);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
375 js->url_datas = g_slist_prepend(js->url_datas, url_data);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
376 } else
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
377 g_free(info);
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
378
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
379 }
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
380 }
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
381 }
5dd25c58b65e Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff changeset
382 }