Wed, 13 May 2009 20:29:03 +0000
Support custom smileys in MUCs (when all participants support BoB and a maximum
of 10 participants are in the chat).
Always announce support for BoB, since disable custom smileys will still turn
off fetching them, and BoB can be used for other purposes further on.
|
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 |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
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 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
26 | #include "useravatar.h" |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
27 | #include "pep.h" |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
28 | #include "debug.h" |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
29 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
30 | #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
|
31 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
32 | static void update_buddy_metadata(JabberStream *js, const char *from, xmlnode *items); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
33 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
34 | 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
|
35 | { |
| 26959 | 36 | 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
|
37 | jabber_pep_namespace_only_when_pep_enabled_cb); |
| 26959 | 38 | 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
|
39 | 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
|
40 | |
| 26959 | 41 | 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
|
42 | update_buddy_metadata); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
43 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
44 | |
|
26950
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
45 | static void |
|
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
46 | 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
|
47 | { |
|
27025
cda390e09aaf
Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <darkrain42@pidgin.im>
parents:
27017
diff
changeset
|
48 | #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
|
49 | /* 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
|
50 | |
|
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
|
51 | /* Publish an empty avatar according to the XEP-0084 v0.12 semantics */ |
|
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 | xmlnode *publish, *item, *metadata; |
|
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
|
53 | /* publish the metadata */ |
|
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 = xmlnode_new("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
|
55 | xmlnode_set_attrib(publish, "node", NS_AVATAR_0_12_METADATA); |
|
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
|
56 | |
|
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 | item = xmlnode_new_child(publish, "item"); |
|
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
|
58 | xmlnode_set_attrib(item, "id", "stop"); |
|
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
|
59 | |
|
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 | metadata = xmlnode_new_child(item, "metadata"); |
|
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
|
61 | xmlnode_set_namespace(metadata, NS_AVATAR_0_12_METADATA); |
|
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
|
62 | |
|
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 | xmlnode_new_child(metadata, "stop"); |
|
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
|
64 | |
|
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 | /* 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
|
66 | 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
|
67 | #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
|
68 | |
|
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 | /* |
|
27025
cda390e09aaf
Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <darkrain42@pidgin.im>
parents:
27017
diff
changeset
|
70 | * 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
|
71 | * 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
|
72 | * 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
|
73 | * |
|
cda390e09aaf
Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <darkrain42@pidgin.im>
parents:
27017
diff
changeset
|
74 | * 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
|
75 | * 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
|
76 | * 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
|
77 | * 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
|
78 | * 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
|
79 | * 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
|
80 | * |
|
cda390e09aaf
Revert the partial hack for ejabberd 2.0.0. See comment in code.
Paul Aurich <darkrain42@pidgin.im>
parents:
27017
diff
changeset
|
81 | * 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
|
82 | * 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
|
83 | * --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
|
84 | */ |
|
26950
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
85 | 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
|
86 | 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
|
87 | } |
|
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 | void jabber_avatar_set(JabberStream *js, PurpleStoredImage *img) |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
90 | { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
91 | xmlnode *publish, *metadata, *item; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
92 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
93 | if (!js->pep) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
94 | return; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
95 | |
|
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
|
96 | /* 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
|
97 | 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
|
98 | |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
99 | if (!img) { |
|
26950
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
100 | publish = xmlnode_new("publish"); |
|
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
101 | 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
|
102 | |
|
26950
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
103 | item = xmlnode_new_child(publish, "item"); |
|
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
104 | metadata = xmlnode_new_child(item, "metadata"); |
|
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
105 | 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
|
106 | |
|
26950
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
107 | /* publish */ |
|
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
108 | 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
|
109 | } else { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
110 | /* |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
111 | * TODO: This is pretty gross. The Jabber PRPL really shouldn't |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
112 | * 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
|
113 | * and width. |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
114 | */ |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
115 | /* A PNG header, including the IHDR, but nothing else */ |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
116 | const struct { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
117 | 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
|
118 | struct { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
119 | 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
|
120 | 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
|
121 | guint32 width; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
122 | guint32 height; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
123 | guchar bitdepth; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
124 | guchar colortype; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
125 | guchar compression; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
126 | guchar filter; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
127 | guchar interlace; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
128 | } ihdr; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
129 | } *png = purple_imgstore_get_data(img); /* ATTN: this is in network byte order! */ |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
130 | |
|
26947
176ef2bfef9f
Use purple_strequal and g_str_equal
Paul Aurich <darkrain42@pidgin.im>
parents:
25811
diff
changeset
|
131 | /* check if the data is a valid png file (well, at least to some extent) */ |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
132 | if(png->signature[0] == 0x89 && |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
133 | 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
|
134 | 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
|
135 | 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
|
136 | 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
|
137 | 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
|
138 | 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
|
139 | 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
|
140 | 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
|
141 | 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
|
142 | 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
|
143 | 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
|
144 | 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
|
145 | /* 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
|
146 | 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
|
147 | guint32 height = ntohl(png->ihdr.height); |
|
25480
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
148 | xmlnode *data, *info; |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
149 | 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
|
150 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
151 | /* compute the sha1 hash */ |
|
25480
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
152 | char *hash = jabber_calculate_data_sha1sum(purple_imgstore_get_data(img), |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
153 | purple_imgstore_get_size(img)); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
154 | char *base64avatar = purple_base64_encode(purple_imgstore_get_data(img), |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
155 | purple_imgstore_get_size(img)); |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
156 | |
|
26950
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
157 | publish = xmlnode_new("publish"); |
|
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
158 | 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
|
159 | |
|
26950
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
160 | item = xmlnode_new_child(publish, "item"); |
|
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
161 | 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
|
162 | |
|
26950
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
163 | data = xmlnode_new_child(item, "data"); |
|
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
164 | 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
|
165 | |
|
26950
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
166 | xmlnode_insert_data(data, base64avatar, -1); |
|
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
167 | /* publish the avatar itself */ |
|
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
168 | 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
|
169 | |
|
25480
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
170 | 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
|
171 | |
|
25479
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
172 | lengthstring = g_strdup_printf("%" G_GSIZE_FORMAT, |
|
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
173 | purple_imgstore_get_size(img)); |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
174 | 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
|
175 | 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
|
176 | |
|
26950
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
177 | /* publish the metadata */ |
|
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
178 | publish = xmlnode_new("publish"); |
|
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
179 | 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
|
180 | |
|
26950
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
181 | item = xmlnode_new_child(publish, "item"); |
|
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
182 | 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
|
183 | |
|
26950
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
184 | metadata = xmlnode_new_child(item, "metadata"); |
|
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
185 | 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
|
186 | |
|
26950
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
187 | info = xmlnode_new_child(metadata, "info"); |
|
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
188 | xmlnode_set_attrib(info, "id", hash); |
|
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
189 | xmlnode_set_attrib(info, "type", "image/png"); |
|
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
190 | xmlnode_set_attrib(info, "bytes", lengthstring); |
|
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
191 | xmlnode_set_attrib(info, "width", widthstring); |
|
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
192 | 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
|
193 | |
|
26950
842628304397
Publish only 'new' xmlns of avatars and delete old.
Paul Aurich <darkrain42@pidgin.im>
parents:
26949
diff
changeset
|
194 | 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
|
195 | |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
196 | g_free(lengthstring); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
197 | g_free(widthstring); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
198 | g_free(heightstring); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
199 | g_free(hash); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
200 | } else { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
201 | 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
|
202 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
203 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
204 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
205 | |
|
25477
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
206 | static void |
|
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
|
207 | do_got_own_avatar_0_12_cb(JabberStream *js, const char *from, xmlnode *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
|
208 | { |
|
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
|
209 | 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
|
210 | /* 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
|
211 | 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
|
212 | } |
|
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
|
213 | |
|
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
|
214 | static void |
|
25477
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
215 | do_got_own_avatar_cb(JabberStream *js, const char *from, xmlnode *items) |
|
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
216 | { |
|
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
217 | xmlnode *item = NULL, *metadata = NULL, *info = NULL; |
|
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
218 | 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
|
219 | 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
|
220 | |
|
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
|
221 | if (items && (item = xmlnode_get_child(items, "item")) && |
|
25477
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
222 | (metadata = xmlnode_get_child(item, "metadata")) && |
|
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
223 | (info = xmlnode_get_child(metadata, "info"))) { |
|
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
224 | server_hash = xmlnode_get_attrib(info, "id"); |
|
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
225 | } |
|
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
226 | |
|
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
|
227 | if (items && !metadata) |
|
25480
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
228 | return; |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
229 | |
|
25477
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
230 | /* Publish ours if it's different than the server's */ |
|
26947
176ef2bfef9f
Use purple_strequal and g_str_equal
Paul Aurich <darkrain42@pidgin.im>
parents:
25811
diff
changeset
|
231 | if (!purple_strequal(server_hash, js->initial_avatar_hash)) { |
|
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 | PurpleStoredImage *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
|
233 | jabber_avatar_set(js, 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
|
234 | purple_imgstore_unref(img); |
|
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
235 | } |
|
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
236 | } |
|
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
237 | |
|
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
238 | 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
|
239 | { |
|
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
240 | char *jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain); |
|
25479
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
241 | jabber_pep_request_item(js, jid, NS_AVATAR_0_12_METADATA, NULL, |
|
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
|
242 | do_got_own_avatar_0_12_cb); |
|
25480
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
243 | jabber_pep_request_item(js, jid, NS_AVATAR_1_1_METADATA, NULL, |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
244 | do_got_own_avatar_cb); |
|
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 | g_free(jid); |
|
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 | |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
248 | typedef struct _JabberBuddyAvatarUpdateURLInfo { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
249 | JabberStream *js; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
250 | char *from; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
251 | char *id; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
252 | } JabberBuddyAvatarUpdateURLInfo; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
253 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
254 | static void |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
255 | do_buddy_avatar_update_fromurl(PurpleUtilFetchUrlData *url_data, |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
256 | gpointer user_data, const gchar *url_text, |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
257 | gsize len, const gchar *error_message) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
258 | { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
259 | JabberBuddyAvatarUpdateURLInfo *info = user_data; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
260 | if(!url_text) { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
261 | purple_debug(PURPLE_DEBUG_ERROR, "jabber", |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
262 | "do_buddy_avatar_update_fromurl got error \"%s\"", |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
263 | error_message); |
|
25476
d31fcddd65a4
Don't leak a JabberBuddyAvatarUpdateURLInfo struct in the error case
Paul Aurich <darkrain42@pidgin.im>
parents:
25475
diff
changeset
|
264 | goto out; |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
265 | } |
| 25481 | 266 | |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
267 | purple_buddy_icons_set_for_user(purple_connection_get_account(info->js->gc), info->from, (void*)url_text, len, info->id); |
|
25476
d31fcddd65a4
Don't leak a JabberBuddyAvatarUpdateURLInfo struct in the error case
Paul Aurich <darkrain42@pidgin.im>
parents:
25475
diff
changeset
|
268 | |
|
d31fcddd65a4
Don't leak a JabberBuddyAvatarUpdateURLInfo struct in the error case
Paul Aurich <darkrain42@pidgin.im>
parents:
25475
diff
changeset
|
269 | out: |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
270 | 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
|
271 | 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
|
272 | g_free(info); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
273 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
274 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
275 | static void |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
276 | do_buddy_avatar_update_data(JabberStream *js, const char *from, xmlnode *items) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
277 | { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
278 | xmlnode *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
|
279 | 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
|
280 | char *b64data; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
281 | void *img; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
282 | size_t size; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
283 | if(!items) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
284 | return; |
| 25481 | 285 | |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
286 | item = xmlnode_get_child(items, "item"); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
287 | if(!item) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
288 | return; |
|
25479
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
289 | |
|
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
290 | data = 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
|
291 | if(!data) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
292 | return; |
|
25479
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
293 | |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
294 | checksum = xmlnode_get_attrib(item,"id"); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
295 | if(!checksum) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
296 | return; |
| 25481 | 297 | |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
298 | b64data = xmlnode_get_data(data); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
299 | if(!b64data) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
300 | return; |
| 25481 | 301 | |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
302 | 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
|
303 | if(!img) { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
304 | g_free(b64data); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
305 | return; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
306 | } |
| 25481 | 307 | |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
308 | 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
|
309 | g_free(b64data); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
310 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
311 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
312 | static void |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
313 | update_buddy_metadata(JabberStream *js, const char *from, xmlnode *items) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
314 | { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
315 | PurpleBuddy *buddy = purple_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
|
316 | 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
|
317 | xmlnode *item, *metadata; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
318 | if(!buddy) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
319 | return; |
| 25481 | 320 | |
|
25809
f0d37a73663a
I had the distinct pleasure of throwing invalid garbage at this code; it
Paul Aurich <darkrain42@pidgin.im>
parents:
25543
diff
changeset
|
321 | 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
|
322 | return; |
|
f0d37a73663a
I had the distinct pleasure of throwing invalid garbage at this code; it
Paul Aurich <darkrain42@pidgin.im>
parents:
25543
diff
changeset
|
323 | |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
324 | item = 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
|
325 | 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
|
326 | return; |
|
f0d37a73663a
I had the distinct pleasure of throwing invalid garbage at this code; it
Paul Aurich <darkrain42@pidgin.im>
parents:
25543
diff
changeset
|
327 | |
|
25479
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
328 | metadata = 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
|
329 | if(!metadata) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
330 | return; |
|
25479
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
331 | |
|
25809
f0d37a73663a
I had the distinct pleasure of throwing invalid garbage at this code; it
Paul Aurich <darkrain42@pidgin.im>
parents:
25543
diff
changeset
|
332 | 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
|
333 | |
|
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
|
334 | /* <stop/> was the pre-v1.1 method of publishing an empty avatar */ |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
335 | if(xmlnode_get_child(metadata, "stop")) { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
336 | 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
|
337 | } else { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
338 | xmlnode *info, *goodinfo = NULL; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
339 | 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
|
340 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
341 | /* 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
|
342 | for(info = metadata->child; info; info = info->next) { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
343 | if(info->type == XMLNODE_TYPE_TAG) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
344 | has_children = TRUE; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
345 | if(info->type == XMLNODE_TYPE_TAG && !strcmp(info->name,"info")) { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
346 | const char *type = xmlnode_get_attrib(info,"type"); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
347 | const char *id = xmlnode_get_attrib(info,"id"); |
| 25481 | 348 | |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
349 | 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
|
350 | /* 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
|
351 | goodinfo = NULL; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
352 | break; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
353 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
354 | /* 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
|
355 | 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
|
356 | goodinfo = info; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
357 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
358 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
359 | 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
|
360 | 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
|
361 | } else if(goodinfo) { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
362 | const char *url = xmlnode_get_attrib(goodinfo, "url"); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
363 | const char *id = xmlnode_get_attrib(goodinfo,"id"); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
364 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
365 | /* 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
|
366 | 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
|
367 | 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
|
368 | 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
|
369 | } else { |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
370 | PurpleUtilFetchUrlData *url_data; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
371 | 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
|
372 | info->js = js; |
|
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 | url_data = purple_util_fetch_url_len(url, TRUE, NULL, TRUE, |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
375 | MAX_HTTP_BUDDYICON_BYTES, |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
376 | do_buddy_avatar_update_fromurl, info); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
377 | if (url_data) { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
378 | info->from = g_strdup(from); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
379 | info->id = g_strdup(id); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
380 | js->url_datas = g_slist_prepend(js->url_datas, url_data); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
381 | } else |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
382 | g_free(info); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
383 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
384 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
385 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
386 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
387 | } |