Mon, 26 Jan 2009 06:04:01 +0000
Whitespace changes
|
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 | { |
|
25479
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
36 | jabber_add_feature("avatarmeta", NS_AVATAR_0_12_METADATA, |
|
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); |
|
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
38 | jabber_add_feature("avatardata", NS_AVATAR_0_12_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); |
|
25479
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
40 | jabber_pep_register_handler("avatar", NS_AVATAR_0_12_METADATA, |
|
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
41 | update_buddy_metadata); |
|
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
42 | |
|
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
43 | jabber_add_feature("urn_avatarmeta", NS_AVATAR_1_1_METADATA, |
|
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
44 | jabber_pep_namespace_only_when_pep_enabled_cb); |
|
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
45 | jabber_add_feature("urn_avatardata", 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
|
46 | 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
|
47 | |
|
25479
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
48 | jabber_pep_register_handler("urn_avatar", 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
|
49 | update_buddy_metadata); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
50 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
51 | |
|
25480
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
52 | void jabber_avatar_set(JabberStream *js, PurpleStoredImage *img, const char *ns) |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
53 | { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
54 | 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
|
55 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
56 | if (!js->pep) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
57 | return; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
58 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
59 | if (!img) { |
|
25480
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
60 | if (ns == NULL || !strcmp(ns, NS_AVATAR_0_12_METADATA)) { |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
61 | /* remove the metadata */ |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
62 | publish = xmlnode_new("publish"); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
63 | xmlnode_set_attrib(publish, "node", NS_AVATAR_0_12_METADATA); |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
64 | |
|
25480
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
65 | item = xmlnode_new_child(publish, "item"); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
66 | metadata = xmlnode_new_child(item, "metadata"); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
67 | xmlnode_set_namespace(metadata, NS_AVATAR_0_12_METADATA); |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
68 | |
|
25480
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
69 | xmlnode_new_child(metadata, "stop"); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
70 | /* publish */ |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
71 | jabber_pep_publish(js, publish); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
72 | } |
|
25479
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
73 | |
|
25480
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
74 | if (ns == NULL || !strcmp(ns, NS_AVATAR_1_1_METADATA)) { |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
75 | /* Now for the XEP-0084 v1.1 namespace, where we publish an empty |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
76 | * metadata node instead of a <stop/> element */ |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
77 | publish = xmlnode_new("publish"); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
78 | xmlnode_set_attrib(publish, "node", 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
|
79 | |
|
25480
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
80 | item = xmlnode_new_child(publish, "item"); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
81 | metadata = xmlnode_new_child(item, "metadata"); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
82 | 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
|
83 | |
|
25480
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
84 | /* publish */ |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
85 | jabber_pep_publish(js, publish); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
86 | } |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
87 | } else { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
88 | /* |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
89 | * 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
|
90 | * 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
|
91 | * and width. |
|
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 | /* 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
|
94 | const struct { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
95 | 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
|
96 | struct { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
97 | 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
|
98 | 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
|
99 | guint32 width; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
100 | guint32 height; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
101 | guchar bitdepth; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
102 | guchar colortype; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
103 | guchar compression; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
104 | guchar filter; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
105 | guchar interlace; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
106 | } ihdr; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
107 | } *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
|
108 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
109 | /* check if the data is a valid png file (well, at least to some extend) */ |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
110 | 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
|
111 | 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
|
112 | 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
|
113 | 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
|
114 | 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
|
115 | 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
|
116 | 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
|
117 | 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
|
118 | 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
|
119 | 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
|
120 | 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
|
121 | 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
|
122 | 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
|
123 | /* 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
|
124 | 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
|
125 | 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
|
126 | 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
|
127 | 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
|
128 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
129 | /* 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
|
130 | 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
|
131 | 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
|
132 | 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
|
133 | 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
|
134 | |
|
25480
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
135 | if (ns == NULL || !strcmp(ns, NS_AVATAR_0_12_METADATA)) { |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
136 | publish = xmlnode_new("publish"); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
137 | xmlnode_set_attrib(publish, "node", NS_AVATAR_0_12_DATA); |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
138 | |
|
25480
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
139 | item = xmlnode_new_child(publish, "item"); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
140 | xmlnode_set_attrib(item, "id", hash); |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
141 | |
|
25480
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
142 | data = xmlnode_new_child(item, "data"); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
143 | xmlnode_set_namespace(data, NS_AVATAR_0_12_DATA); |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
144 | |
|
25480
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
145 | xmlnode_insert_data(data, base64avatar, -1); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
146 | /* publish the avatar itself */ |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
147 | jabber_pep_publish(js, publish); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
148 | } |
|
25479
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
149 | |
|
25480
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
150 | if (ns == NULL || !strcmp(ns, NS_AVATAR_1_1_METADATA)) { |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
151 | publish = xmlnode_new("publish"); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
152 | xmlnode_set_attrib(publish, "node", NS_AVATAR_1_1_DATA); |
|
25479
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
153 | |
|
25480
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
154 | item = xmlnode_new_child(publish, "item"); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
155 | xmlnode_set_attrib(item, "id", "hash"); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
156 | |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
157 | data = xmlnode_new_child(item, "data"); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
158 | xmlnode_set_namespace(data, NS_AVATAR_1_1_DATA); |
|
25479
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
159 | |
|
25480
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
160 | xmlnode_insert_data(data, base64avatar, -1); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
161 | /* publish the avatar itself */ |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
162 | jabber_pep_publish(js, publish); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
163 | } |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
164 | |
|
25480
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
165 | 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
|
166 | |
|
25479
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
167 | 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
|
168 | 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
|
169 | 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
|
170 | 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
|
171 | |
|
25480
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
172 | /* next step: publish the metadata to the old namespace */ |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
173 | if (ns == NULL || !strcmp(ns, NS_AVATAR_0_12_METADATA)) { |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
174 | publish = xmlnode_new("publish"); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
175 | xmlnode_set_attrib(publish, "node", NS_AVATAR_0_12_METADATA); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
176 | |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
177 | item = xmlnode_new_child(publish, "item"); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
178 | xmlnode_set_attrib(item, "id", hash); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
179 | |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
180 | metadata = xmlnode_new_child(item, "metadata"); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
181 | xmlnode_set_namespace(metadata, NS_AVATAR_0_12_METADATA); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
182 | |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
183 | info = xmlnode_new_child(metadata, "info"); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
184 | xmlnode_set_attrib(info, "id", hash); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
185 | xmlnode_set_attrib(info, "type", "image/png"); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
186 | xmlnode_set_attrib(info, "bytes", lengthstring); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
187 | xmlnode_set_attrib(info, "width", widthstring); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
188 | xmlnode_set_attrib(info, "height", heightstring); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
189 | /* publish the metadata */ |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
190 | jabber_pep_publish(js, publish); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
191 | } |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
192 | |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
193 | if (ns == NULL || !strcmp(ns, NS_AVATAR_1_1_METADATA)) { |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
194 | /* publish the metadata to the new namespace */ |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
195 | publish = xmlnode_new("publish"); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
196 | xmlnode_set_attrib(publish, "node", NS_AVATAR_1_1_METADATA); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
197 | |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
198 | item = xmlnode_new_child(publish, "item"); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
199 | xmlnode_set_attrib(item, "id", hash); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
200 | |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
201 | metadata = xmlnode_new_child(item, "metdata"); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
202 | xmlnode_set_namespace(metadata, NS_AVATAR_1_1_METADATA); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
203 | |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
204 | info = xmlnode_new_child(metadata, "info"); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
205 | xmlnode_set_attrib(info, "id", hash); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
206 | xmlnode_set_attrib(info, "type", "image/png"); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
207 | xmlnode_set_attrib(info, "bytes", lengthstring); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
208 | xmlnode_set_attrib(info, "width", widthstring); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
209 | xmlnode_set_attrib(info, "height", heightstring); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
210 | |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
211 | jabber_pep_publish(js, publish); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
212 | } |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
213 | |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
214 | g_free(lengthstring); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
215 | g_free(widthstring); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
216 | g_free(heightstring); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
217 | g_free(hash); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
218 | } else { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
219 | 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
|
220 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
221 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
222 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
223 | |
|
25477
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
224 | static void |
|
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
225 | 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
|
226 | { |
|
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
227 | 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
|
228 | 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
|
229 | const char *current_hash = purple_account_get_string(account, "prpl-jabber_icon_checksum", ""); |
|
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
230 | const char *server_hash = NULL; |
|
25480
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
231 | const char *ns; |
|
25477
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
232 | |
|
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
233 | if ((item = xmlnode_get_child(items, "item")) && |
|
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
234 | (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
|
235 | (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
|
236 | 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
|
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 | |
|
25480
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
239 | ns = xmlnode_get_namespace(metadata); |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
240 | if (!ns) |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
241 | return; |
|
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
242 | |
|
25477
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
243 | /* Publish ours if it's different than the server's */ |
|
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
244 | if ((!server_hash && current_hash[0] != '\0') || |
|
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
245 | (server_hash && strcmp(server_hash, current_hash))) { |
|
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
246 | PurpleStoredImage *img = purple_buddy_icons_find_account_icon(account); |
|
25480
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
247 | jabber_avatar_set(js, img, ns); |
|
25477
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
248 | 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
|
249 | } |
|
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
250 | } |
|
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
251 | |
|
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
252 | 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
|
253 | { |
|
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
254 | 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
|
255 | jabber_pep_request_item(js, jid, NS_AVATAR_0_12_METADATA, NULL, |
|
25477
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
256 | do_got_own_avatar_cb); |
|
25480
6e01ab2bc943
Support both XEP-0084 namespaces for fetching our own avatars at login
Paul Aurich <darkrain42@pidgin.im>
parents:
25479
diff
changeset
|
257 | 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
|
258 | 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
|
259 | 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
|
260 | } |
|
ada9e5c4a10a
Only (re)publish XMPP avatars at login if the server's avatar differs
Paul Aurich <darkrain42@pidgin.im>
parents:
25476
diff
changeset
|
261 | |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
262 | typedef struct _JabberBuddyAvatarUpdateURLInfo { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
263 | JabberStream *js; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
264 | char *from; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
265 | char *id; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
266 | } JabberBuddyAvatarUpdateURLInfo; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
267 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
268 | static void |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
269 | 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
|
270 | 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
|
271 | 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
|
272 | { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
273 | 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
|
274 | if(!url_text) { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
275 | 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
|
276 | "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
|
277 | error_message); |
|
25476
d31fcddd65a4
Don't leak a JabberBuddyAvatarUpdateURLInfo struct in the error case
Paul Aurich <darkrain42@pidgin.im>
parents:
25475
diff
changeset
|
278 | goto out; |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
279 | } |
| 25481 | 280 | |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
281 | 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
|
282 | |
|
d31fcddd65a4
Don't leak a JabberBuddyAvatarUpdateURLInfo struct in the error case
Paul Aurich <darkrain42@pidgin.im>
parents:
25475
diff
changeset
|
283 | out: |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
284 | 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
|
285 | 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
|
286 | g_free(info); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
287 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
288 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
289 | static void |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
290 | 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
|
291 | { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
292 | xmlnode *item, *data; |
|
25479
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
293 | const char *checksum, *ns; |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
294 | char *b64data; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
295 | void *img; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
296 | size_t size; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
297 | if(!items) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
298 | return; |
| 25481 | 299 | |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
300 | 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
|
301 | if(!item) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
302 | return; |
|
25479
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
303 | |
|
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
304 | 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
|
305 | if(!data) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
306 | return; |
|
25479
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
307 | |
|
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
308 | ns = xmlnode_get_namespace(data); |
|
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
309 | /* Make sure the namespace is one of the two valid possibilities */ |
|
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
310 | if (!ns || (strcmp(ns, NS_AVATAR_0_12_DATA) && |
|
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
311 | strcmp(ns, NS_AVATAR_1_1_DATA))) |
|
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
312 | return; |
|
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
313 | |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
314 | 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
|
315 | if(!checksum) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
316 | return; |
| 25481 | 317 | |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
318 | 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
|
319 | if(!b64data) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
320 | return; |
| 25481 | 321 | |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
322 | 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
|
323 | if(!img) { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
324 | g_free(b64data); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
325 | return; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
326 | } |
| 25481 | 327 | |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
328 | 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
|
329 | g_free(b64data); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
330 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
331 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
332 | static void |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
333 | 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
|
334 | { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
335 | PurpleBuddy *buddy = purple_find_buddy(purple_connection_get_account(js->gc), from); |
|
25479
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
336 | const char *checksum, *ns; |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
337 | xmlnode *item, *metadata; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
338 | if(!buddy) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
339 | return; |
| 25481 | 340 | |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
341 | checksum = purple_buddy_icons_get_checksum_for_user(buddy); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
342 | item = xmlnode_get_child(items,"item"); |
|
25479
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
343 | 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
|
344 | if(!metadata) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
345 | return; |
|
25479
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
346 | |
|
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
347 | ns = xmlnode_get_namespace(metadata); |
|
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
348 | /* Make sure the namespace is one of the two valid possibilities */ |
|
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
349 | if (!ns || (strcmp(ns, NS_AVATAR_0_12_METADATA) && |
|
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
350 | strcmp(ns, NS_AVATAR_1_1_METADATA))) |
|
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
351 | return; |
|
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
352 | |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
353 | /* check if we have received a stop */ |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
354 | 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
|
355 | 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
|
356 | } else { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
357 | 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
|
358 | 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
|
359 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
360 | /* 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
|
361 | 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
|
362 | 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
|
363 | has_children = TRUE; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
364 | 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
|
365 | 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
|
366 | const char *id = xmlnode_get_attrib(info,"id"); |
| 25481 | 367 | |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
368 | 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
|
369 | /* 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
|
370 | goodinfo = NULL; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
371 | break; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
372 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
373 | /* 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
|
374 | 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
|
375 | goodinfo = info; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
376 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
377 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
378 | 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
|
379 | 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
|
380 | } else if(goodinfo) { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
381 | 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
|
382 | 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
|
383 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
384 | /* 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
|
385 | if(!url) { |
|
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
386 | const char *data_ns; |
|
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
387 | data_ns = (strcmp(ns, NS_AVATAR_0_12_METADATA) == 0 ? |
|
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
388 | NS_AVATAR_0_12_DATA : NS_AVATAR_1_1_DATA); |
|
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
389 | jabber_pep_request_item(js, from, data_ns, id, |
|
416673fd83b4
Support XEP-0084 (User Avatar) v1.1 alongside v0.12
Paul Aurich <darkrain42@pidgin.im>
parents:
25477
diff
changeset
|
390 | 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
|
391 | } else { |
|
25475
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
392 | PurpleUtilFetchUrlData *url_data; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
393 | 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
|
394 | info->js = js; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
395 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
396 | 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
|
397 | 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
|
398 | 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
|
399 | if (url_data) { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
400 | 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
|
401 | 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
|
402 | 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
|
403 | } else |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
404 | g_free(info); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
405 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
406 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
407 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
408 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
409 | } |