libpurple/protocols/jabber/useravatar.c

Tue, 11 Oct 2016 23:32:23 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Tue, 11 Oct 2016 23:32:23 -0500
changeset 38298
f0a8f63f9312
parent 37134
07746c9a04bf
child 38334
cb3f85d86752
permissions
-rw-r--r--

rename purple_image_get_size to purple_image_get_data_size and deal with the fallout

25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
1 /*
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
2 * purple - Jabber Protocol Plugin
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
3 *
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
4 * Purple is the legal property of its developers, whose names are too numerous
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
6 * source distribution.
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
7 *
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
11 * (at your option) any later version.
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
12 *
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
16 * GNU General Public License for more details.
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
17 *
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
28321
c8d617c408ab Update various header copyrights thanks to licensecheck.
Paul Aurich <darkrain42@pidgin.im>
parents: 28048
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
21 *
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
22 */
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
23
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
24 #include "internal.h"
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
25
34227
6d016a081401 HTTP: migrate purple_util_fetch_url to new API for prpls
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33774
diff changeset
26 #include "http.h"
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
27 #include "useravatar.h"
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
28 #include "pep.h"
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
29 #include "debug.h"
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
30
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
31 #define MAX_HTTP_BUDDYICON_BYTES (200 * 1024)
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
32
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
33 static void update_buddy_metadata(JabberStream *js, const char *from, PurpleXmlNode *items);
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
34
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
35 void jabber_avatar_init(void)
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
36 {
26959
8482365bb2ec Fix merging.
Paul Aurich <darkrain42@pidgin.im>
parents: 26950
diff changeset
37 jabber_add_feature(NS_AVATAR_1_1_METADATA,
25479
416673fd83b4 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents: 25477
diff changeset
38 jabber_pep_namespace_only_when_pep_enabled_cb);
26959
8482365bb2ec Fix merging.
Paul Aurich <darkrain42@pidgin.im>
parents: 26950
diff changeset
39 jabber_add_feature(NS_AVATAR_1_1_DATA,
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
40 jabber_pep_namespace_only_when_pep_enabled_cb);
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
41
26959
8482365bb2ec Fix merging.
Paul Aurich <darkrain42@pidgin.im>
parents: 26950
diff changeset
42 jabber_pep_register_handler(NS_AVATAR_1_1_METADATA,
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
43 update_buddy_metadata);
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
44 }
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
45
26950
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26949
diff changeset
46 static void
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26949
diff changeset
47 remove_avatar_0_12_nodes(JabberStream *js)
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26949
diff changeset
48 {
27025
cda390e09aaf Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <darkrain42@pidgin.im>
parents: 27017
diff changeset
49 #if 0
27035
2246f8a9d680 The correct fix here is to place non-code in a comment (yes, even if it's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 27034
diff changeset
50 /* See note below for why this is #if 0'd */
27025
cda390e09aaf Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <darkrain42@pidgin.im>
parents: 27017
diff changeset
51
27017
02ddb8e8c3d2 Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <darkrain42@pidgin.im>
parents: 26959
diff changeset
52 /* Publish an empty avatar according to the XEP-0084 v0.12 semantics */
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
53 PurpleXmlNode *publish, *item, *metadata;
27017
02ddb8e8c3d2 Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <darkrain42@pidgin.im>
parents: 26959
diff changeset
54 /* publish the metadata */
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
55 publish = purple_xmlnode_new("publish");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
56 purple_xmlnode_set_attrib(publish, "node", NS_AVATAR_0_12_METADATA);
27017
02ddb8e8c3d2 Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <darkrain42@pidgin.im>
parents: 26959
diff changeset
57
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
58 item = purple_xmlnode_new_child(publish, "item");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
59 purple_xmlnode_set_attrib(item, "id", "stop");
27017
02ddb8e8c3d2 Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <darkrain42@pidgin.im>
parents: 26959
diff changeset
60
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
61 metadata = purple_xmlnode_new_child(item, "metadata");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
62 purple_xmlnode_set_namespace(metadata, NS_AVATAR_0_12_METADATA);
27017
02ddb8e8c3d2 Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <darkrain42@pidgin.im>
parents: 26959
diff changeset
63
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
64 purple_xmlnode_new_child(metadata, "stop");
27017
02ddb8e8c3d2 Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <darkrain42@pidgin.im>
parents: 26959
diff changeset
65
02ddb8e8c3d2 Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <darkrain42@pidgin.im>
parents: 26959
diff changeset
66 /* publish */
02ddb8e8c3d2 Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <darkrain42@pidgin.im>
parents: 26959
diff changeset
67 jabber_pep_publish(js, publish);
27025
cda390e09aaf Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <darkrain42@pidgin.im>
parents: 27017
diff changeset
68 #endif
27017
02ddb8e8c3d2 Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <darkrain42@pidgin.im>
parents: 26959
diff changeset
69
02ddb8e8c3d2 Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <darkrain42@pidgin.im>
parents: 26959
diff changeset
70 /*
27025
cda390e09aaf Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <darkrain42@pidgin.im>
parents: 27017
diff changeset
71 * This causes ejabberd 2.0.0 to kill the connection unceremoniously.
cda390e09aaf Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <darkrain42@pidgin.im>
parents: 27017
diff changeset
72 * See https://support.process-one.net/browse/EJAB-623. When adiumx.com
cda390e09aaf Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <darkrain42@pidgin.im>
parents: 27017
diff changeset
73 * was upgraded, the issue went away.
cda390e09aaf Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <darkrain42@pidgin.im>
parents: 27017
diff changeset
74 *
cda390e09aaf Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <darkrain42@pidgin.im>
parents: 27017
diff changeset
75 * I think it makes a lot of sense to not have an avatar at the old
cda390e09aaf Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <darkrain42@pidgin.im>
parents: 27017
diff changeset
76 * node instead of having something interpreted as "no avatar". When
cda390e09aaf Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <darkrain42@pidgin.im>
parents: 27017
diff changeset
77 * a contact with an older client logs in, in the latter situation,
cda390e09aaf Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <darkrain42@pidgin.im>
parents: 27017
diff changeset
78 * there's a race between interpreting the <presence/> vcard-temp:x:update
cda390e09aaf Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <darkrain42@pidgin.im>
parents: 27017
diff changeset
79 * avatar (non-empty) and the XEP-0084 v0.12 avatar (empty, so show no
cda390e09aaf Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <darkrain42@pidgin.im>
parents: 27017
diff changeset
80 * avatar for the buddy) which leads to unhappy and confused users.
cda390e09aaf Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <darkrain42@pidgin.im>
parents: 27017
diff changeset
81 *
cda390e09aaf Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <darkrain42@pidgin.im>
parents: 27017
diff changeset
82 * A deluge of frustrating "Read error" bug reports may change my mind
cda390e09aaf Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <darkrain42@pidgin.im>
parents: 27017
diff changeset
83 * about this.
cda390e09aaf Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <darkrain42@pidgin.im>
parents: 27017
diff changeset
84 * --darkrain42
27017
02ddb8e8c3d2 Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <darkrain42@pidgin.im>
parents: 26959
diff changeset
85 */
26950
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26949
diff changeset
86 jabber_pep_delete_node(js, NS_AVATAR_0_12_METADATA);
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26949
diff changeset
87 jabber_pep_delete_node(js, NS_AVATAR_0_12_DATA);
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26949
diff changeset
88 }
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26949
diff changeset
89
35823
268a9d3b3fd7 imgstore: unref xmpp
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34935
diff changeset
90 void jabber_avatar_set(JabberStream *js, PurpleImage *img)
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
91 {
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
92 PurpleXmlNode *publish, *metadata, *item;
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
93
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
94 if (!js->pep)
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
95 return;
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
96
27017
02ddb8e8c3d2 Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <darkrain42@pidgin.im>
parents: 26959
diff changeset
97 /* Hmmm, not sure if this is worth the traffic, but meh */
26950
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26949
diff changeset
98 remove_avatar_0_12_nodes(js);
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26949
diff changeset
99
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
100 if (!img) {
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
101 publish = purple_xmlnode_new("publish");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
102 purple_xmlnode_set_attrib(publish, "node", NS_AVATAR_1_1_METADATA);
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
103
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
104 item = purple_xmlnode_new_child(publish, "item");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
105 metadata = purple_xmlnode_new_child(item, "metadata");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
106 purple_xmlnode_set_namespace(metadata, NS_AVATAR_1_1_METADATA);
25479
416673fd83b4 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents: 25477
diff changeset
107
26950
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26949
diff changeset
108 /* publish */
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26949
diff changeset
109 jabber_pep_publish(js, publish);
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
110 } else {
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
111 /*
36637
9b0109ae118d Renamed some prpl stuff to protocol stuff.
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
112 * TODO: This is pretty gross. The Jabber protocol really shouldn't
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
113 * do voodoo to try to determine the image type, height
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
114 * and width.
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
115 */
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
116 /* A PNG header, including the IHDR, but nothing else */
33766
49eb0136f2ec jabber: avoid possible heap overflow when a very small file has been chosen for
Daniel Atallah <datallah@pidgin.im>
parents: 29910
diff changeset
117 /* ATTN: this is in network byte order! */
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
118 const struct {
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
119 guchar signature[8]; /* must be hex 89 50 4E 47 0D 0A 1A 0A */
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
120 struct {
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
121 guint32 length; /* must be 0x0d */
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
122 guchar type[4]; /* must be 'I' 'H' 'D' 'R' */
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
123 guint32 width;
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
124 guint32 height;
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
125 guchar bitdepth;
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
126 guchar colortype;
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
127 guchar compression;
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
128 guchar filter;
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
129 guchar interlace;
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
130 } ihdr;
33766
49eb0136f2ec jabber: avoid possible heap overflow when a very small file has been chosen for
Daniel Atallah <datallah@pidgin.im>
parents: 29910
diff changeset
131 } *png = NULL;
49eb0136f2ec jabber: avoid possible heap overflow when a very small file has been chosen for
Daniel Atallah <datallah@pidgin.im>
parents: 29910
diff changeset
132
38298
f0a8f63f9312 rename purple_image_get_size to purple_image_get_data_size and deal with the fallout
Gary Kramlich <grim@reaperworld.com>
parents: 37134
diff changeset
133 if (purple_image_get_data_size(img) > sizeof(*png))
35823
268a9d3b3fd7 imgstore: unref xmpp
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34935
diff changeset
134 png = purple_image_get_data(img);
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
135
26947
176ef2bfef9f Use purple_strequal and g_str_equal
Paul Aurich <darkrain42@pidgin.im>
parents: 25811
diff changeset
136 /* check if the data is a valid png file (well, at least to some extent) */
33766
49eb0136f2ec jabber: avoid possible heap overflow when a very small file has been chosen for
Daniel Atallah <datallah@pidgin.im>
parents: 29910
diff changeset
137 if(png && png->signature[0] == 0x89 &&
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
138 png->signature[1] == 0x50 &&
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
139 png->signature[2] == 0x4e &&
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
140 png->signature[3] == 0x47 &&
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
141 png->signature[4] == 0x0d &&
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
142 png->signature[5] == 0x0a &&
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
143 png->signature[6] == 0x1a &&
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
144 png->signature[7] == 0x0a &&
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
145 ntohl(png->ihdr.length) == 0x0d &&
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
146 png->ihdr.type[0] == 'I' &&
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
147 png->ihdr.type[1] == 'H' &&
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
148 png->ihdr.type[2] == 'D' &&
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
149 png->ihdr.type[3] == 'R') {
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
150 /* parse PNG header to get the size of the image (yes, this is required) */
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
151 guint32 width = ntohl(png->ihdr.width);
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
152 guint32 height = ntohl(png->ihdr.height);
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
153 PurpleXmlNode *data, *info;
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
154 char *lengthstring, *widthstring, *heightstring;
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
155
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
156 /* compute the sha1 hash */
35823
268a9d3b3fd7 imgstore: unref xmpp
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34935
diff changeset
157 char *hash = jabber_calculate_data_hash(
268a9d3b3fd7 imgstore: unref xmpp
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34935
diff changeset
158 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: 37134
diff changeset
159 purple_image_get_data_size(img), "sha1");
35823
268a9d3b3fd7 imgstore: unref xmpp
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34935
diff changeset
160 char *base64avatar = purple_base64_encode(
268a9d3b3fd7 imgstore: unref xmpp
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34935
diff changeset
161 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: 37134
diff changeset
162 purple_image_get_data_size(img));
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
163
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
164 publish = purple_xmlnode_new("publish");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
165 purple_xmlnode_set_attrib(publish, "node", NS_AVATAR_1_1_DATA);
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
166
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
167 item = purple_xmlnode_new_child(publish, "item");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
168 purple_xmlnode_set_attrib(item, "id", hash);
25479
416673fd83b4 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents: 25477
diff changeset
169
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
170 data = purple_xmlnode_new_child(item, "data");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
171 purple_xmlnode_set_namespace(data, NS_AVATAR_1_1_DATA);
25480
6e01ab2bc943 Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents: 25479
diff changeset
172
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
173 purple_xmlnode_insert_data(data, base64avatar, -1);
26950
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26949
diff changeset
174 /* publish the avatar itself */
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26949
diff changeset
175 jabber_pep_publish(js, publish);
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
176
25480
6e01ab2bc943 Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents: 25479
diff changeset
177 g_free(base64avatar);
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
178
25479
416673fd83b4 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents: 25477
diff changeset
179 lengthstring = g_strdup_printf("%" G_GSIZE_FORMAT,
38298
f0a8f63f9312 rename purple_image_get_size to purple_image_get_data_size and deal with the fallout
Gary Kramlich <grim@reaperworld.com>
parents: 37134
diff changeset
180 purple_image_get_data_size(img));
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
181 widthstring = g_strdup_printf("%u", width);
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
182 heightstring = g_strdup_printf("%u", height);
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
183
26950
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26949
diff changeset
184 /* publish the metadata */
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
185 publish = purple_xmlnode_new("publish");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
186 purple_xmlnode_set_attrib(publish, "node", NS_AVATAR_1_1_METADATA);
25480
6e01ab2bc943 Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents: 25479
diff changeset
187
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
188 item = purple_xmlnode_new_child(publish, "item");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
189 purple_xmlnode_set_attrib(item, "id", hash);
25480
6e01ab2bc943 Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents: 25479
diff changeset
190
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
191 metadata = purple_xmlnode_new_child(item, "metadata");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
192 purple_xmlnode_set_namespace(metadata, NS_AVATAR_1_1_METADATA);
25480
6e01ab2bc943 Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents: 25479
diff changeset
193
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
194 info = purple_xmlnode_new_child(metadata, "info");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
195 purple_xmlnode_set_attrib(info, "id", hash);
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
196 purple_xmlnode_set_attrib(info, "type", "image/png");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
197 purple_xmlnode_set_attrib(info, "bytes", lengthstring);
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
198 purple_xmlnode_set_attrib(info, "width", widthstring);
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
199 purple_xmlnode_set_attrib(info, "height", heightstring);
25480
6e01ab2bc943 Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents: 25479
diff changeset
200
26950
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26949
diff changeset
201 jabber_pep_publish(js, publish);
25480
6e01ab2bc943 Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents: 25479
diff changeset
202
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
203 g_free(lengthstring);
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
204 g_free(widthstring);
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
205 g_free(heightstring);
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
206 g_free(hash);
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
207 } else {
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
208 purple_debug_error("jabber", "Cannot set PEP avatar to non-PNG data\n");
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
209 }
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
210 }
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
211 }
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
212
25477
ada9e5c4a10a Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents: 25476
diff changeset
213 static void
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
214 do_got_own_avatar_0_12_cb(JabberStream *js, const char *from, PurpleXmlNode *items)
27017
02ddb8e8c3d2 Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <darkrain42@pidgin.im>
parents: 26959
diff changeset
215 {
02ddb8e8c3d2 Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <darkrain42@pidgin.im>
parents: 26959
diff changeset
216 if (items)
02ddb8e8c3d2 Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <darkrain42@pidgin.im>
parents: 26959
diff changeset
217 /* It wasn't an error (i.e. 'item-not-found') */
02ddb8e8c3d2 Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <darkrain42@pidgin.im>
parents: 26959
diff changeset
218 remove_avatar_0_12_nodes(js);
02ddb8e8c3d2 Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <darkrain42@pidgin.im>
parents: 26959
diff changeset
219 }
02ddb8e8c3d2 Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <darkrain42@pidgin.im>
parents: 26959
diff changeset
220
02ddb8e8c3d2 Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <darkrain42@pidgin.im>
parents: 26959
diff changeset
221 static void
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
222 do_got_own_avatar_cb(JabberStream *js, const char *from, PurpleXmlNode *items)
25477
ada9e5c4a10a Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents: 25476
diff changeset
223 {
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
224 PurpleXmlNode *item = NULL, *metadata = NULL, *info = NULL;
25477
ada9e5c4a10a Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents: 25476
diff changeset
225 PurpleAccount *account = purple_connection_get_account(js->gc);
ada9e5c4a10a Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents: 25476
diff changeset
226 const char *server_hash = NULL;
ada9e5c4a10a Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents: 25476
diff changeset
227
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
228 if (items && (item = purple_xmlnode_get_child(items, "item")) &&
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
229 (metadata = purple_xmlnode_get_child(item, "metadata")) &&
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
230 (info = purple_xmlnode_get_child(metadata, "info"))) {
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
231 server_hash = purple_xmlnode_get_attrib(info, "id");
25477
ada9e5c4a10a Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents: 25476
diff changeset
232 }
ada9e5c4a10a Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents: 25476
diff changeset
233
28048
cdc92f9d634a jabber: Fix setting the PEP node the first time.
Paul Aurich <darkrain42@pidgin.im>
parents: 27358
diff changeset
234 /*
cdc92f9d634a jabber: Fix setting the PEP node the first time.
Paul Aurich <darkrain42@pidgin.im>
parents: 27358
diff changeset
235 * If we have an avatar and the server returned an error/malformed data,
cdc92f9d634a jabber: Fix setting the PEP node the first time.
Paul Aurich <darkrain42@pidgin.im>
parents: 27358
diff changeset
236 * push our avatar. If the server avatar doesn't match the local one, push
cdc92f9d634a jabber: Fix setting the PEP node the first time.
Paul Aurich <darkrain42@pidgin.im>
parents: 27358
diff changeset
237 * our avatar.
cdc92f9d634a jabber: Fix setting the PEP node the first time.
Paul Aurich <darkrain42@pidgin.im>
parents: 27358
diff changeset
238 */
28881
244fb329e5df jabber: Go back to not overwriting avatars if there is not one locally set.
Paul Aurich <darkrain42@pidgin.im>
parents: 28828
diff changeset
239 if ((!items || !metadata) ||
28048
cdc92f9d634a jabber: Fix setting the PEP node the first time.
Paul Aurich <darkrain42@pidgin.im>
parents: 27358
diff changeset
240 !purple_strequal(server_hash, js->initial_avatar_hash)) {
35823
268a9d3b3fd7 imgstore: unref xmpp
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34935
diff changeset
241 PurpleImage *img = purple_buddy_icons_find_account_icon(account);
26950
842628304397 Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents: 26949
diff changeset
242 jabber_avatar_set(js, img);
35823
268a9d3b3fd7 imgstore: unref xmpp
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34935
diff changeset
243 if (img)
268a9d3b3fd7 imgstore: unref xmpp
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 34935
diff changeset
244 g_object_unref(img);
25477
ada9e5c4a10a Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents: 25476
diff changeset
245 }
ada9e5c4a10a Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents: 25476
diff changeset
246 }
ada9e5c4a10a Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents: 25476
diff changeset
247
ada9e5c4a10a Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents: 25476
diff changeset
248 void jabber_avatar_fetch_mine(JabberStream *js)
ada9e5c4a10a Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents: 25476
diff changeset
249 {
28881
244fb329e5df jabber: Go back to not overwriting avatars if there is not one locally set.
Paul Aurich <darkrain42@pidgin.im>
parents: 28828
diff changeset
250 if (js->initial_avatar_hash) {
29782
ca4fedd9e890 jabber: Allow jabber_pep_request_item() to take NULL for JID; server's routing takes care of the rest
Paul Aurich <darkrain42@pidgin.im>
parents: 28881
diff changeset
251 jabber_pep_request_item(js, NULL, NS_AVATAR_0_12_METADATA, NULL,
28881
244fb329e5df jabber: Go back to not overwriting avatars if there is not one locally set.
Paul Aurich <darkrain42@pidgin.im>
parents: 28828
diff changeset
252 do_got_own_avatar_0_12_cb);
29782
ca4fedd9e890 jabber: Allow jabber_pep_request_item() to take NULL for JID; server's routing takes care of the rest
Paul Aurich <darkrain42@pidgin.im>
parents: 28881
diff changeset
253 jabber_pep_request_item(js, NULL, NS_AVATAR_1_1_METADATA, NULL,
28881
244fb329e5df jabber: Go back to not overwriting avatars if there is not one locally set.
Paul Aurich <darkrain42@pidgin.im>
parents: 28828
diff changeset
254 do_got_own_avatar_cb);
244fb329e5df jabber: Go back to not overwriting avatars if there is not one locally set.
Paul Aurich <darkrain42@pidgin.im>
parents: 28828
diff changeset
255 }
25477
ada9e5c4a10a Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents: 25476
diff changeset
256 }
ada9e5c4a10a Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents: 25476
diff changeset
257
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
258 typedef struct _JabberBuddyAvatarUpdateURLInfo {
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
259 JabberStream *js;
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
260 char *from;
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
261 char *id;
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
262 } JabberBuddyAvatarUpdateURLInfo;
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
263
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
264 static void
34227
6d016a081401 HTTP: migrate purple_util_fetch_url to new API for prpls
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33774
diff changeset
265 do_buddy_avatar_update_fromurl(PurpleHttpConnection *http_conn,
6d016a081401 HTTP: migrate purple_util_fetch_url to new API for prpls
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33774
diff changeset
266 PurpleHttpResponse *response, gpointer _info)
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
267 {
34227
6d016a081401 HTTP: migrate purple_util_fetch_url to new API for prpls
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33774
diff changeset
268 JabberBuddyAvatarUpdateURLInfo *info = _info;
27358
a1e3486558a0 Need to make a copy of this because purple_util_fetch_url frees its.
Paul Aurich <darkrain42@pidgin.im>
parents: 27035
diff changeset
269 gpointer icon_data;
34227
6d016a081401 HTTP: migrate purple_util_fetch_url to new API for prpls
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33774
diff changeset
270 const gchar *got_data;
6d016a081401 HTTP: migrate purple_util_fetch_url to new API for prpls
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33774
diff changeset
271 size_t got_len;
27358
a1e3486558a0 Need to make a copy of this because purple_util_fetch_url frees its.
Paul Aurich <darkrain42@pidgin.im>
parents: 27035
diff changeset
272
34287
6cd0c77b1f6a HTTP: successful is spelled with one l
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34269
diff changeset
273 if (!purple_http_response_is_successful(response)) {
34227
6d016a081401 HTTP: migrate purple_util_fetch_url to new API for prpls
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33774
diff changeset
274 purple_debug_error("jabber", "do_buddy_avatar_update_fromurl "
6d016a081401 HTTP: migrate purple_util_fetch_url to new API for prpls
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33774
diff changeset
275 "got error \"%s\"",
6d016a081401 HTTP: migrate purple_util_fetch_url to new API for prpls
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33774
diff changeset
276 purple_http_response_get_error(response));
25476
d31fcddd65a4 Don't leak a JabberBuddyAvatarUpdateURLInfo struct in the error case
Paul Aurich <darkrain42@pidgin.im>
parents: 25475
diff changeset
277 goto out;
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
278 }
25481
46c34a4f99df Whitespace changes
Paul Aurich <darkrain42@pidgin.im>
parents: 25480
diff changeset
279
34227
6d016a081401 HTTP: migrate purple_util_fetch_url to new API for prpls
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33774
diff changeset
280 got_data = purple_http_response_get_data(response, &got_len);
6d016a081401 HTTP: migrate purple_util_fetch_url to new API for prpls
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33774
diff changeset
281 icon_data = g_memdup(got_data, got_len);
6d016a081401 HTTP: migrate purple_util_fetch_url to new API for prpls
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33774
diff changeset
282 purple_buddy_icons_set_for_user(purple_connection_get_account(info->js->gc), info->from, icon_data, got_len, info->id);
25476
d31fcddd65a4 Don't leak a JabberBuddyAvatarUpdateURLInfo struct in the error case
Paul Aurich <darkrain42@pidgin.im>
parents: 25475
diff changeset
283
d31fcddd65a4 Don't leak a JabberBuddyAvatarUpdateURLInfo struct in the error case
Paul Aurich <darkrain42@pidgin.im>
parents: 25475
diff changeset
284 out:
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
285 g_free(info->from);
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
286 g_free(info->id);
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
287 g_free(info);
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
288 }
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
289
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
290 static void
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
291 do_buddy_avatar_update_data(JabberStream *js, const char *from, PurpleXmlNode *items)
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
292 {
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
293 PurpleXmlNode *item, *data;
27017
02ddb8e8c3d2 Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <darkrain42@pidgin.im>
parents: 26959
diff changeset
294 const char *checksum;
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
295 char *b64data;
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
296 void *img;
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
297 size_t size;
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
298 if(!items)
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
299 return;
25481
46c34a4f99df Whitespace changes
Paul Aurich <darkrain42@pidgin.im>
parents: 25480
diff changeset
300
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
301 item = purple_xmlnode_get_child(items, "item");
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
302 if(!item)
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
303 return;
25479
416673fd83b4 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents: 25477
diff changeset
304
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
305 data = purple_xmlnode_get_child(item, "data");
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
306 if(!data)
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
307 return;
25479
416673fd83b4 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents: 25477
diff changeset
308
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
309 checksum = purple_xmlnode_get_attrib(item,"id");
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
310 if(!checksum)
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
311 return;
25481
46c34a4f99df Whitespace changes
Paul Aurich <darkrain42@pidgin.im>
parents: 25480
diff changeset
312
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
313 b64data = purple_xmlnode_get_data(data);
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
314 if(!b64data)
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
315 return;
25481
46c34a4f99df Whitespace changes
Paul Aurich <darkrain42@pidgin.im>
parents: 25480
diff changeset
316
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
317 img = purple_base64_decode(b64data, &size);
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
318 if(!img) {
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
319 g_free(b64data);
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
320 return;
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
321 }
25481
46c34a4f99df Whitespace changes
Paul Aurich <darkrain42@pidgin.im>
parents: 25480
diff changeset
322
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
323 purple_buddy_icons_set_for_user(purple_connection_get_account(js->gc), from, img, size, checksum);
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
324 g_free(b64data);
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
325 }
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
326
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
327 static void
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
328 update_buddy_metadata(JabberStream *js, const char *from, PurpleXmlNode *items)
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
329 {
34728
8efd73063ecf Renamed buddy list functions to more appropriate/simler names.
Ankit Vani <a@nevitus.org>
parents: 34227
diff changeset
330 PurpleBuddy *buddy = purple_blist_find_buddy(purple_connection_get_account(js->gc), from);
27017
02ddb8e8c3d2 Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <darkrain42@pidgin.im>
parents: 26959
diff changeset
331 const char *checksum;
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
332 PurpleXmlNode *item, *metadata;
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
333 if(!buddy)
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
334 return;
25481
46c34a4f99df Whitespace changes
Paul Aurich <darkrain42@pidgin.im>
parents: 25480
diff changeset
335
25809
f0d37a73663a I had the distinct pleasure of throwing invalid garbage at this code; it
Paul Aurich <darkrain42@pidgin.im>
parents: 25543
diff changeset
336 if (!items)
f0d37a73663a I had the distinct pleasure of throwing invalid garbage at this code; it
Paul Aurich <darkrain42@pidgin.im>
parents: 25543
diff changeset
337 return;
f0d37a73663a I had the distinct pleasure of throwing invalid garbage at this code; it
Paul Aurich <darkrain42@pidgin.im>
parents: 25543
diff changeset
338
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
339 item = purple_xmlnode_get_child(items,"item");
25809
f0d37a73663a I had the distinct pleasure of throwing invalid garbage at this code; it
Paul Aurich <darkrain42@pidgin.im>
parents: 25543
diff changeset
340 if (!item)
f0d37a73663a I had the distinct pleasure of throwing invalid garbage at this code; it
Paul Aurich <darkrain42@pidgin.im>
parents: 25543
diff changeset
341 return;
f0d37a73663a I had the distinct pleasure of throwing invalid garbage at this code; it
Paul Aurich <darkrain42@pidgin.im>
parents: 25543
diff changeset
342
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
343 metadata = purple_xmlnode_get_child(item, "metadata");
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
344 if(!metadata)
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
345 return;
25479
416673fd83b4 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents: 25477
diff changeset
346
25809
f0d37a73663a I had the distinct pleasure of throwing invalid garbage at this code; it
Paul Aurich <darkrain42@pidgin.im>
parents: 25543
diff changeset
347 checksum = purple_buddy_icons_get_checksum_for_user(buddy);
f0d37a73663a I had the distinct pleasure of throwing invalid garbage at this code; it
Paul Aurich <darkrain42@pidgin.im>
parents: 25543
diff changeset
348
27017
02ddb8e8c3d2 Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <darkrain42@pidgin.im>
parents: 26959
diff changeset
349 /* <stop/> was the pre-v1.1 method of publishing an empty avatar */
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
350 if(purple_xmlnode_get_child(metadata, "stop")) {
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
351 purple_buddy_icons_set_for_user(purple_connection_get_account(js->gc), from, NULL, 0, NULL);
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
352 } else {
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
353 PurpleXmlNode *info, *goodinfo = NULL;
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
354 gboolean has_children = FALSE;
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
355
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
356 /* iterate over all info nodes to get one we can use */
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
357 for(info = metadata->child; info; info = info->next) {
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
358 if(info->type == PURPLE_XMLNODE_TYPE_TAG)
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
359 has_children = TRUE;
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
360 if(info->type == PURPLE_XMLNODE_TYPE_TAG && !strcmp(info->name,"info")) {
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
361 const char *type = purple_xmlnode_get_attrib(info,"type");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
362 const char *id = purple_xmlnode_get_attrib(info,"id");
25481
46c34a4f99df Whitespace changes
Paul Aurich <darkrain42@pidgin.im>
parents: 25480
diff changeset
363
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
364 if(checksum && id && !strcmp(id, checksum)) {
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
365 /* we already have that avatar, so we don't have to do anything */
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
366 goodinfo = NULL;
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
367 break;
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
368 }
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
369 /* We'll only pick the png one for now. It's a very nice image format anyways. */
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
370 if(type && id && !goodinfo && !strcmp(type, "image/png"))
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
371 goodinfo = info;
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
372 }
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
373 }
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
374 if(has_children == FALSE) {
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
375 purple_buddy_icons_set_for_user(purple_connection_get_account(js->gc), from, NULL, 0, NULL);
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
376 } else if(goodinfo) {
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
377 const char *url = purple_xmlnode_get_attrib(goodinfo, "url");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34878
diff changeset
378 const char *id = purple_xmlnode_get_attrib(goodinfo,"id");
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
379
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
380 /* the avatar might either be stored in a pep node, or on a HTTP(S) URL */
25479
416673fd83b4 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents: 25477
diff changeset
381 if(!url) {
27017
02ddb8e8c3d2 Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <darkrain42@pidgin.im>
parents: 26959
diff changeset
382 jabber_pep_request_item(js, from, NS_AVATAR_1_1_DATA, id,
25479
416673fd83b4 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents: 25477
diff changeset
383 do_buddy_avatar_update_data);
416673fd83b4 Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents: 25477
diff changeset
384 } else {
34227
6d016a081401 HTTP: migrate purple_util_fetch_url to new API for prpls
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33774
diff changeset
385 PurpleHttpRequest *req;
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
386 JabberBuddyAvatarUpdateURLInfo *info = g_new0(JabberBuddyAvatarUpdateURLInfo, 1);
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
387 info->js = js;
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
388
34227
6d016a081401 HTTP: migrate purple_util_fetch_url to new API for prpls
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33774
diff changeset
389 req = purple_http_request_new(url);
6d016a081401 HTTP: migrate purple_util_fetch_url to new API for prpls
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33774
diff changeset
390 purple_http_request_set_max_len(req, MAX_HTTP_BUDDYICON_BYTES);
34269
26b4c9a54166 HTTP: Use PurpleHttpConnectionSet instead of GSLists of PurpleHttpConnection structs
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34227
diff changeset
391 purple_http_connection_set_add(js->http_conns,
26b4c9a54166 HTTP: Use PurpleHttpConnectionSet instead of GSLists of PurpleHttpConnection structs
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34227
diff changeset
392 purple_http_request(js->gc, req,
26b4c9a54166 HTTP: Use PurpleHttpConnectionSet instead of GSLists of PurpleHttpConnection structs
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 34227
diff changeset
393 do_buddy_avatar_update_fromurl, info));
34227
6d016a081401 HTTP: migrate purple_util_fetch_url to new API for prpls
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33774
diff changeset
394 purple_http_request_unref(req);
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
395
34227
6d016a081401 HTTP: migrate purple_util_fetch_url to new API for prpls
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33774
diff changeset
396 info->from = g_strdup(from);
6d016a081401 HTTP: migrate purple_util_fetch_url to new API for prpls
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 33774
diff changeset
397 info->id = g_strdup(id);
25475
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
398 }
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
399 }
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
400 }
ad7612a5d678 Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff changeset
401 }

mercurial