Mercurial > pidgin
annotate libpurple/protocols/jabber/useravatar.c @ 30762:e03f912141dd
Start moving p2p specific code to its own module.
author | masca@cpw.pidgin.im |
---|---|
date | Thu, 03 Jun 2010 21:07:08 +0000 |
parents | 9f59abd49def |
children | 904686722499 |
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 |
28047
8c991e09efcb
Update various header copyrights thanks to licensecheck.
Paul Aurich <paul@darkrain42.org>
parents:
27777
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
25351
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 { |
26736 | 36 jabber_add_feature(NS_AVATAR_1_1_METADATA, |
25355
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); |
26736 | 38 jabber_add_feature(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
|
39 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
|
40 |
26736 | 41 jabber_pep_register_handler(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
|
42 update_buddy_metadata); |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
43 } |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
44 |
26709
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
45 static void |
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
46 remove_avatar_0_12_nodes(JabberStream *js) |
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
47 { |
26798
afc3ec89e83b
Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <paul@darkrain42.org>
parents:
26792
diff
changeset
|
48 #if 0 |
26801
df7505e0d64a
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:
26800
diff
changeset
|
49 /* See note below for why this is #if 0'd */ |
26798
afc3ec89e83b
Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <paul@darkrain42.org>
parents:
26792
diff
changeset
|
50 |
26792
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
51 /* Publish an empty avatar according to the XEP-0084 v0.12 semantics */ |
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
52 xmlnode *publish, *item, *metadata; |
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
53 /* publish the metadata */ |
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
54 publish = xmlnode_new("publish"); |
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
55 xmlnode_set_attrib(publish, "node", NS_AVATAR_0_12_METADATA); |
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
56 |
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
57 item = xmlnode_new_child(publish, "item"); |
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
58 xmlnode_set_attrib(item, "id", "stop"); |
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
59 |
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
60 metadata = xmlnode_new_child(item, "metadata"); |
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
61 xmlnode_set_namespace(metadata, NS_AVATAR_0_12_METADATA); |
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
62 |
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
63 xmlnode_new_child(metadata, "stop"); |
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
64 |
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
65 /* publish */ |
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
66 jabber_pep_publish(js, publish); |
26798
afc3ec89e83b
Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <paul@darkrain42.org>
parents:
26792
diff
changeset
|
67 #endif |
26792
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
68 |
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
69 /* |
26798
afc3ec89e83b
Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <paul@darkrain42.org>
parents:
26792
diff
changeset
|
70 * This causes ejabberd 2.0.0 to kill the connection unceremoniously. |
afc3ec89e83b
Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <paul@darkrain42.org>
parents:
26792
diff
changeset
|
71 * See https://support.process-one.net/browse/EJAB-623. When adiumx.com |
afc3ec89e83b
Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <paul@darkrain42.org>
parents:
26792
diff
changeset
|
72 * was upgraded, the issue went away. |
afc3ec89e83b
Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <paul@darkrain42.org>
parents:
26792
diff
changeset
|
73 * |
afc3ec89e83b
Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <paul@darkrain42.org>
parents:
26792
diff
changeset
|
74 * I think it makes a lot of sense to not have an avatar at the old |
afc3ec89e83b
Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <paul@darkrain42.org>
parents:
26792
diff
changeset
|
75 * node instead of having something interpreted as "no avatar". When |
afc3ec89e83b
Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <paul@darkrain42.org>
parents:
26792
diff
changeset
|
76 * a contact with an older client logs in, in the latter situation, |
afc3ec89e83b
Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <paul@darkrain42.org>
parents:
26792
diff
changeset
|
77 * there's a race between interpreting the <presence/> vcard-temp:x:update |
afc3ec89e83b
Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <paul@darkrain42.org>
parents:
26792
diff
changeset
|
78 * avatar (non-empty) and the XEP-0084 v0.12 avatar (empty, so show no |
afc3ec89e83b
Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <paul@darkrain42.org>
parents:
26792
diff
changeset
|
79 * avatar for the buddy) which leads to unhappy and confused users. |
afc3ec89e83b
Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <paul@darkrain42.org>
parents:
26792
diff
changeset
|
80 * |
afc3ec89e83b
Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <paul@darkrain42.org>
parents:
26792
diff
changeset
|
81 * A deluge of frustrating "Read error" bug reports may change my mind |
afc3ec89e83b
Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <paul@darkrain42.org>
parents:
26792
diff
changeset
|
82 * about this. |
afc3ec89e83b
Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <paul@darkrain42.org>
parents:
26792
diff
changeset
|
83 * --darkrain42 |
26792
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
84 */ |
26709
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
85 jabber_pep_delete_node(js, NS_AVATAR_0_12_METADATA); |
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
86 jabber_pep_delete_node(js, NS_AVATAR_0_12_DATA); |
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
87 } |
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
88 |
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
89 void jabber_avatar_set(JabberStream *js, PurpleStoredImage *img) |
25351
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
90 { |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
91 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
|
92 |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
93 if (!js->pep) |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
94 return; |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
95 |
26792
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
96 /* Hmmm, not sure if this is worth the traffic, but meh */ |
26709
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
97 remove_avatar_0_12_nodes(js); |
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
98 |
25351
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
99 if (!img) { |
26709
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
100 publish = xmlnode_new("publish"); |
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
101 xmlnode_set_attrib(publish, "node", 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
|
102 |
26709
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
103 item = xmlnode_new_child(publish, "item"); |
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
104 metadata = xmlnode_new_child(item, "metadata"); |
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
105 xmlnode_set_namespace(metadata, NS_AVATAR_1_1_METADATA); |
25355
ba8f51cb3691
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents:
25353
diff
changeset
|
106 |
26709
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
107 /* publish */ |
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
108 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
|
109 } else { |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
110 /* |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
111 * 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
|
112 * 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
|
113 * and width. |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
114 */ |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
115 /* 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
|
116 const struct { |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
117 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
|
118 struct { |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
119 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
|
120 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
|
121 guint32 width; |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
122 guint32 height; |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
123 guchar bitdepth; |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
124 guchar colortype; |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
125 guchar compression; |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
126 guchar filter; |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
127 guchar interlace; |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
128 } ihdr; |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
129 } *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
|
130 |
26706
fbb2b8e2d91e
Use purple_strequal and g_str_equal
Paul Aurich <paul@darkrain42.org>
parents:
25426
diff
changeset
|
131 /* check if the data is a valid png file (well, at least to some extent) */ |
25351
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
132 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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 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
|
138 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
|
139 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
|
140 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 /* 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
|
146 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
|
147 guint32 height = ntohl(png->ihdr.height); |
25356
c0a27a44ebd6
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <paul@darkrain42.org>
parents:
25355
diff
changeset
|
148 xmlnode *data, *info; |
25351
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
149 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
|
150 |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
151 /* compute the sha1 hash */ |
29630
9f59abd49def
jabber: Validate the hash on incoming BoB objects (in case the CID is on the
Marcus Lundblad <ml@update.uu.se>
parents:
29498
diff
changeset
|
152 char *hash = jabber_calculate_data_hash(purple_imgstore_get_data(img), |
9f59abd49def
jabber: Validate the hash on incoming BoB objects (in case the CID is on the
Marcus Lundblad <ml@update.uu.se>
parents:
29498
diff
changeset
|
153 purple_imgstore_get_size(img), |
9f59abd49def
jabber: Validate the hash on incoming BoB objects (in case the CID is on the
Marcus Lundblad <ml@update.uu.se>
parents:
29498
diff
changeset
|
154 "sha1"); |
25356
c0a27a44ebd6
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <paul@darkrain42.org>
parents:
25355
diff
changeset
|
155 char *base64avatar = purple_base64_encode(purple_imgstore_get_data(img), |
c0a27a44ebd6
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <paul@darkrain42.org>
parents:
25355
diff
changeset
|
156 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
|
157 |
26709
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
158 publish = xmlnode_new("publish"); |
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
159 xmlnode_set_attrib(publish, "node", 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
|
160 |
26709
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
161 item = xmlnode_new_child(publish, "item"); |
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
162 xmlnode_set_attrib(item, "id", hash); |
25355
ba8f51cb3691
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents:
25353
diff
changeset
|
163 |
26709
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
164 data = xmlnode_new_child(item, "data"); |
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
165 xmlnode_set_namespace(data, NS_AVATAR_1_1_DATA); |
25356
c0a27a44ebd6
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <paul@darkrain42.org>
parents:
25355
diff
changeset
|
166 |
26709
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
167 xmlnode_insert_data(data, base64avatar, -1); |
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
168 /* publish the avatar itself */ |
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
169 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
|
170 |
25356
c0a27a44ebd6
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <paul@darkrain42.org>
parents:
25355
diff
changeset
|
171 g_free(base64avatar); |
25351
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
172 |
25355
ba8f51cb3691
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents:
25353
diff
changeset
|
173 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
|
174 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
|
175 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
|
176 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
|
177 |
26709
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
178 /* publish the metadata */ |
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
179 publish = xmlnode_new("publish"); |
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
180 xmlnode_set_attrib(publish, "node", NS_AVATAR_1_1_METADATA); |
25356
c0a27a44ebd6
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <paul@darkrain42.org>
parents:
25355
diff
changeset
|
181 |
26709
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
182 item = xmlnode_new_child(publish, "item"); |
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
183 xmlnode_set_attrib(item, "id", hash); |
25356
c0a27a44ebd6
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <paul@darkrain42.org>
parents:
25355
diff
changeset
|
184 |
26709
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
185 metadata = xmlnode_new_child(item, "metadata"); |
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
186 xmlnode_set_namespace(metadata, NS_AVATAR_1_1_METADATA); |
25356
c0a27a44ebd6
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <paul@darkrain42.org>
parents:
25355
diff
changeset
|
187 |
26709
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
188 info = xmlnode_new_child(metadata, "info"); |
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
189 xmlnode_set_attrib(info, "id", hash); |
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
190 xmlnode_set_attrib(info, "type", "image/png"); |
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
191 xmlnode_set_attrib(info, "bytes", lengthstring); |
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
192 xmlnode_set_attrib(info, "width", widthstring); |
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
193 xmlnode_set_attrib(info, "height", heightstring); |
25356
c0a27a44ebd6
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <paul@darkrain42.org>
parents:
25355
diff
changeset
|
194 |
26709
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
195 jabber_pep_publish(js, publish); |
25356
c0a27a44ebd6
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <paul@darkrain42.org>
parents:
25355
diff
changeset
|
196 |
25351
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
197 g_free(lengthstring); |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
198 g_free(widthstring); |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
199 g_free(heightstring); |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
200 g_free(hash); |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
201 } else { |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
202 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
|
203 } |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
204 } |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
205 } |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
206 |
25353
9195955395b6
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents:
25352
diff
changeset
|
207 static void |
26792
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
208 do_got_own_avatar_0_12_cb(JabberStream *js, const char *from, xmlnode *items) |
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
209 { |
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
210 if (items) |
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
211 /* It wasn't an error (i.e. 'item-not-found') */ |
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
212 remove_avatar_0_12_nodes(js); |
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
213 } |
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
214 |
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
215 static void |
25353
9195955395b6
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents:
25352
diff
changeset
|
216 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
|
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 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
|
219 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
|
220 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
|
221 |
26792
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
222 if (items && (item = xmlnode_get_child(items, "item")) && |
27777
93d9cf1151a4
jabber: Fix setting the PEP node the first time.
Paul Aurich <paul@darkrain42.org>
parents:
27134
diff
changeset
|
223 (metadata = xmlnode_get_child(item, "metadata")) && |
93d9cf1151a4
jabber: Fix setting the PEP node the first time.
Paul Aurich <paul@darkrain42.org>
parents:
27134
diff
changeset
|
224 (info = xmlnode_get_child(metadata, "info"))) { |
25353
9195955395b6
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents:
25352
diff
changeset
|
225 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
|
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 |
27777
93d9cf1151a4
jabber: Fix setting the PEP node the first time.
Paul Aurich <paul@darkrain42.org>
parents:
27134
diff
changeset
|
228 /* |
93d9cf1151a4
jabber: Fix setting the PEP node the first time.
Paul Aurich <paul@darkrain42.org>
parents:
27134
diff
changeset
|
229 * If we have an avatar and the server returned an error/malformed data, |
93d9cf1151a4
jabber: Fix setting the PEP node the first time.
Paul Aurich <paul@darkrain42.org>
parents:
27134
diff
changeset
|
230 * push our avatar. If the server avatar doesn't match the local one, push |
93d9cf1151a4
jabber: Fix setting the PEP node the first time.
Paul Aurich <paul@darkrain42.org>
parents:
27134
diff
changeset
|
231 * our avatar. |
93d9cf1151a4
jabber: Fix setting the PEP node the first time.
Paul Aurich <paul@darkrain42.org>
parents:
27134
diff
changeset
|
232 */ |
28536
e14402d6c5e0
jabber: Go back to not overwriting avatars if there is not one locally set.
Paul Aurich <paul@darkrain42.org>
parents:
28513
diff
changeset
|
233 if ((!items || !metadata) || |
27777
93d9cf1151a4
jabber: Fix setting the PEP node the first time.
Paul Aurich <paul@darkrain42.org>
parents:
27134
diff
changeset
|
234 !purple_strequal(server_hash, js->initial_avatar_hash)) { |
25353
9195955395b6
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents:
25352
diff
changeset
|
235 PurpleStoredImage *img = purple_buddy_icons_find_account_icon(account); |
26709
80437c891f92
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <paul@darkrain42.org>
parents:
26708
diff
changeset
|
236 jabber_avatar_set(js, img); |
25353
9195955395b6
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents:
25352
diff
changeset
|
237 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
|
238 } |
9195955395b6
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents:
25352
diff
changeset
|
239 } |
9195955395b6
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents:
25352
diff
changeset
|
240 |
9195955395b6
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents:
25352
diff
changeset
|
241 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
|
242 { |
28536
e14402d6c5e0
jabber: Go back to not overwriting avatars if there is not one locally set.
Paul Aurich <paul@darkrain42.org>
parents:
28513
diff
changeset
|
243 if (js->initial_avatar_hash) { |
29498
93e8e6331d44
jabber: Allow jabber_pep_request_item() to take NULL for JID; server's routing takes care of the rest
Paul Aurich <paul@darkrain42.org>
parents:
28536
diff
changeset
|
244 jabber_pep_request_item(js, NULL, NS_AVATAR_0_12_METADATA, NULL, |
28536
e14402d6c5e0
jabber: Go back to not overwriting avatars if there is not one locally set.
Paul Aurich <paul@darkrain42.org>
parents:
28513
diff
changeset
|
245 do_got_own_avatar_0_12_cb); |
29498
93e8e6331d44
jabber: Allow jabber_pep_request_item() to take NULL for JID; server's routing takes care of the rest
Paul Aurich <paul@darkrain42.org>
parents:
28536
diff
changeset
|
246 jabber_pep_request_item(js, NULL, NS_AVATAR_1_1_METADATA, NULL, |
28536
e14402d6c5e0
jabber: Go back to not overwriting avatars if there is not one locally set.
Paul Aurich <paul@darkrain42.org>
parents:
28513
diff
changeset
|
247 do_got_own_avatar_cb); |
e14402d6c5e0
jabber: Go back to not overwriting avatars if there is not one locally set.
Paul Aurich <paul@darkrain42.org>
parents:
28513
diff
changeset
|
248 } |
25353
9195955395b6
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents:
25352
diff
changeset
|
249 } |
9195955395b6
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <paul@darkrain42.org>
parents:
25352
diff
changeset
|
250 |
25351
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
251 typedef struct _JabberBuddyAvatarUpdateURLInfo { |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
252 JabberStream *js; |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
253 char *from; |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
254 char *id; |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
255 } JabberBuddyAvatarUpdateURLInfo; |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
256 |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
257 static void |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
258 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
|
259 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
|
260 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
|
261 { |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
262 JabberBuddyAvatarUpdateURLInfo *info = user_data; |
27134
77cfaae36918
Need to make a copy of this because purple_util_fetch_url frees its.
Paul Aurich <paul@darkrain42.org>
parents:
26801
diff
changeset
|
263 gpointer icon_data; |
77cfaae36918
Need to make a copy of this because purple_util_fetch_url frees its.
Paul Aurich <paul@darkrain42.org>
parents:
26801
diff
changeset
|
264 |
25351
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
265 if(!url_text) { |
28513
fa7f3426ed13
jabber: Convert to purple_debug_* convenience functions.
Paul Aurich <paul@darkrain42.org>
parents:
28047
diff
changeset
|
266 purple_debug_error("jabber", |
25351
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
267 "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
|
268 error_message); |
25352
b68ac693ae2d
Don't leak a JabberBuddyAvatarUpdateURLInfo struct in the error case
Paul Aurich <paul@darkrain42.org>
parents:
25351
diff
changeset
|
269 goto out; |
25351
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
270 } |
25357 | 271 |
27134
77cfaae36918
Need to make a copy of this because purple_util_fetch_url frees its.
Paul Aurich <paul@darkrain42.org>
parents:
26801
diff
changeset
|
272 icon_data = g_memdup(url_text, len); |
77cfaae36918
Need to make a copy of this because purple_util_fetch_url frees its.
Paul Aurich <paul@darkrain42.org>
parents:
26801
diff
changeset
|
273 purple_buddy_icons_set_for_user(purple_connection_get_account(info->js->gc), info->from, icon_data, len, info->id); |
25352
b68ac693ae2d
Don't leak a JabberBuddyAvatarUpdateURLInfo struct in the error case
Paul Aurich <paul@darkrain42.org>
parents:
25351
diff
changeset
|
274 |
b68ac693ae2d
Don't leak a JabberBuddyAvatarUpdateURLInfo struct in the error case
Paul Aurich <paul@darkrain42.org>
parents:
25351
diff
changeset
|
275 out: |
25351
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
276 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
|
277 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
|
278 g_free(info); |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
279 } |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
280 |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
281 static void |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
282 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
|
283 { |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
284 xmlnode *item, *data; |
26792
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
285 const char *checksum; |
25351
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
286 char *b64data; |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
287 void *img; |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
288 size_t size; |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
289 if(!items) |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
290 return; |
25357 | 291 |
25351
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
292 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
|
293 if(!item) |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
294 return; |
25355
ba8f51cb3691
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents:
25353
diff
changeset
|
295 |
ba8f51cb3691
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents:
25353
diff
changeset
|
296 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
|
297 if(!data) |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
298 return; |
25355
ba8f51cb3691
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents:
25353
diff
changeset
|
299 |
25351
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
300 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
|
301 if(!checksum) |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
302 return; |
25357 | 303 |
25351
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
304 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
|
305 if(!b64data) |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
306 return; |
25357 | 307 |
25351
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
308 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
|
309 if(!img) { |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
310 g_free(b64data); |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
311 return; |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
312 } |
25357 | 313 |
25351
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
314 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
|
315 g_free(b64data); |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
316 } |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
317 |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
318 static void |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
319 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
|
320 { |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
321 PurpleBuddy *buddy = purple_find_buddy(purple_connection_get_account(js->gc), from); |
26792
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
322 const char *checksum; |
25351
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
323 xmlnode *item, *metadata; |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
324 if(!buddy) |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
325 return; |
25357 | 326 |
25424
b3dbc9e8b6ef
I had the distinct pleasure of throwing invalid garbage at this code; it
Paul Aurich <paul@darkrain42.org>
parents:
25403
diff
changeset
|
327 if (!items) |
b3dbc9e8b6ef
I had the distinct pleasure of throwing invalid garbage at this code; it
Paul Aurich <paul@darkrain42.org>
parents:
25403
diff
changeset
|
328 return; |
b3dbc9e8b6ef
I had the distinct pleasure of throwing invalid garbage at this code; it
Paul Aurich <paul@darkrain42.org>
parents:
25403
diff
changeset
|
329 |
25351
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
330 item = xmlnode_get_child(items,"item"); |
25424
b3dbc9e8b6ef
I had the distinct pleasure of throwing invalid garbage at this code; it
Paul Aurich <paul@darkrain42.org>
parents:
25403
diff
changeset
|
331 if (!item) |
b3dbc9e8b6ef
I had the distinct pleasure of throwing invalid garbage at this code; it
Paul Aurich <paul@darkrain42.org>
parents:
25403
diff
changeset
|
332 return; |
b3dbc9e8b6ef
I had the distinct pleasure of throwing invalid garbage at this code; it
Paul Aurich <paul@darkrain42.org>
parents:
25403
diff
changeset
|
333 |
25355
ba8f51cb3691
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents:
25353
diff
changeset
|
334 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
|
335 if(!metadata) |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
336 return; |
25355
ba8f51cb3691
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents:
25353
diff
changeset
|
337 |
25424
b3dbc9e8b6ef
I had the distinct pleasure of throwing invalid garbage at this code; it
Paul Aurich <paul@darkrain42.org>
parents:
25403
diff
changeset
|
338 checksum = purple_buddy_icons_get_checksum_for_user(buddy); |
b3dbc9e8b6ef
I had the distinct pleasure of throwing invalid garbage at this code; it
Paul Aurich <paul@darkrain42.org>
parents:
25403
diff
changeset
|
339 |
26792
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
340 /* <stop/> was the pre-v1.1 method of publishing an empty avatar */ |
25351
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
341 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
|
342 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
|
343 } else { |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
344 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
|
345 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
|
346 |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
347 /* 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
|
348 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
|
349 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
|
350 has_children = TRUE; |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
351 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
|
352 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
|
353 const char *id = xmlnode_get_attrib(info,"id"); |
25357 | 354 |
25351
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
355 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
|
356 /* 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
|
357 goodinfo = NULL; |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
358 break; |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
359 } |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
360 /* 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
|
361 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
|
362 goodinfo = info; |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
363 } |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
364 } |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
365 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
|
366 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
|
367 } else if(goodinfo) { |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
368 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
|
369 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
|
370 |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
371 /* 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
|
372 if(!url) { |
26792
76de9455154c
Drop support for XEP-0084 v0.12 and publish a <stop/> instead of deleting the node.
Paul Aurich <paul@darkrain42.org>
parents:
26736
diff
changeset
|
373 jabber_pep_request_item(js, from, NS_AVATAR_1_1_DATA, id, |
25355
ba8f51cb3691
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <paul@darkrain42.org>
parents:
25353
diff
changeset
|
374 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
|
375 } else { |
25351
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
376 PurpleUtilFetchUrlData *url_data; |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
377 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
|
378 info->js = js; |
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 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
|
381 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
|
382 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
|
383 if (url_data) { |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
384 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
|
385 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
|
386 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
|
387 } else |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
388 g_free(info); |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
389 |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
390 } |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
391 } |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
392 } |
5dd25c58b65e
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <paul@darkrain42.org>
parents:
diff
changeset
|
393 } |