Wed, 21 Jan 2009 17:55:09 +0000
Migrate the XMPP User Avatar (XEP-0084) code to its own file
I also slightly rearranged the ordering of jabber_avatar_set to make the
error cases slightly more apparent.
|
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 | { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
36 | jabber_add_feature("avatarmeta", AVATARNAMESPACEMETA, |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
37 | 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
|
38 | jabber_add_feature("avatardata", AVATARNAMESPACEMETA, |
|
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 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
41 | jabber_pep_register_handler("avatar", AVATARNAMESPACEMETA, |
|
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 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
45 | void jabber_avatar_set(JabberStream *js, PurpleStoredImage *img) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
46 | { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
47 | 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
|
48 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
49 | if (!js->pep) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
50 | return; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
51 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
52 | if (!img) { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
53 | /* remove the metadata */ |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
54 | publish = xmlnode_new("publish"); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
55 | xmlnode_set_attrib(publish, "node", AVATARNAMESPACEMETA); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
56 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
57 | item = xmlnode_new_child(publish, "item"); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
58 | metadata = xmlnode_new_child(item, "metadata"); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
59 | xmlnode_set_namespace(metadata, AVATARNAMESPACEMETA); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
60 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
61 | xmlnode_new_child(metadata, "stop"); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
62 | /* publish */ |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
63 | jabber_pep_publish(js, publish); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
64 | } else { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
65 | /* |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
66 | * 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
|
67 | * 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
|
68 | * and width. |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
69 | */ |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
70 | /* 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
|
71 | const struct { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
72 | 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
|
73 | struct { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
74 | 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
|
75 | 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
|
76 | guint32 width; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
77 | guint32 height; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
78 | guchar bitdepth; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
79 | guchar colortype; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
80 | guchar compression; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
81 | guchar filter; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
82 | guchar interlace; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
83 | } ihdr; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
84 | } *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
|
85 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
86 | /* 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
|
87 | 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
|
88 | 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
|
89 | 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
|
90 | 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
|
91 | 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
|
92 | 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
|
93 | 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
|
94 | 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
|
95 | 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
|
96 | 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
|
97 | 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
|
98 | 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
|
99 | 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
|
100 | /* 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
|
101 | 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
|
102 | guint32 height = ntohl(png->ihdr.height); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
103 | xmlnode *data, *info; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
104 | 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
|
105 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
106 | /* compute the sha1 hash */ |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
107 | char *hash = jabber_calculate_data_sha1sum(purple_imgstore_get_data(img), purple_imgstore_get_size(img)); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
108 | char *base64avatar; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
109 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
110 | publish = xmlnode_new("publish"); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
111 | xmlnode_set_attrib(publish, "node", AVATARNAMESPACEDATA); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
112 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
113 | item = xmlnode_new_child(publish, "item"); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
114 | xmlnode_set_attrib(item, "id", hash); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
115 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
116 | data = xmlnode_new_child(item, "data"); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
117 | xmlnode_set_namespace(data, AVATARNAMESPACEDATA); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
118 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
119 | base64avatar = purple_base64_encode(purple_imgstore_get_data(img), |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
120 | purple_imgstore_get_size(img)); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
121 | xmlnode_insert_data(data,base64avatar,-1); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
122 | g_free(base64avatar); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
123 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
124 | /* publish the avatar itself */ |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
125 | jabber_pep_publish(js, publish); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
126 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
127 | /* next step: publish the metadata */ |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
128 | publish = xmlnode_new("publish"); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
129 | xmlnode_set_attrib(publish,"node", AVATARNAMESPACEMETA); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
130 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
131 | item = xmlnode_new_child(publish, "item"); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
132 | xmlnode_set_attrib(item, "id", hash); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
133 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
134 | metadata = xmlnode_new_child(item, "metadata"); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
135 | xmlnode_set_namespace(metadata, AVATARNAMESPACEMETA); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
136 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
137 | lengthstring = g_strdup_printf("%u", (unsigned)purple_imgstore_get_size(img)); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
138 | 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
|
139 | 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
|
140 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
141 | info = xmlnode_new_child(metadata, "info"); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
142 | xmlnode_set_attrib(info, "id", hash); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
143 | xmlnode_set_attrib(info, "type", "image/png"); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
144 | xmlnode_set_attrib(info, "bytes", lengthstring); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
145 | xmlnode_set_attrib(info, "width", widthstring); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
146 | xmlnode_set_attrib(info, "height", heightstring); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
147 | g_free(lengthstring); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
148 | g_free(widthstring); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
149 | g_free(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 | /* publish the metadata */ |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
152 | jabber_pep_publish(js, publish); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
153 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
154 | g_free(hash); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
155 | } else { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
156 | 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
|
157 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
158 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
159 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
160 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
161 | typedef struct _JabberBuddyAvatarUpdateURLInfo { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
162 | JabberStream *js; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
163 | char *from; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
164 | char *id; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
165 | } JabberBuddyAvatarUpdateURLInfo; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
166 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
167 | static void |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
168 | 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
|
169 | 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
|
170 | 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
|
171 | { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
172 | 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
|
173 | if(!url_text) { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
174 | 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
|
175 | "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
|
176 | error_message); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
177 | return; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
178 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
179 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
180 | purple_buddy_icons_set_for_user(purple_connection_get_account(info->js->gc), info->from, (void*)url_text, len, info->id); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
181 | 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
|
182 | 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
|
183 | g_free(info); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
184 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
185 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
186 | static void |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
187 | 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
|
188 | { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
189 | xmlnode *item, *data; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
190 | const char *checksum; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
191 | char *b64data; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
192 | void *img; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
193 | size_t size; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
194 | if(!items) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
195 | return; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
196 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
197 | 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
|
198 | if(!item) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
199 | return; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
200 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
201 | data = xmlnode_get_child_with_namespace(item,"data",AVATARNAMESPACEDATA); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
202 | if(!data) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
203 | return; |
|
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 | 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
|
206 | if(!checksum) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
207 | return; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
208 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
209 | 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
|
210 | if(!b64data) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
211 | return; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
212 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
213 | 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
|
214 | if(!img) { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
215 | g_free(b64data); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
216 | return; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
217 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
218 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
219 | 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
|
220 | g_free(b64data); |
|
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 | static void |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
224 | 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
|
225 | { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
226 | PurpleBuddy *buddy = purple_find_buddy(purple_connection_get_account(js->gc), from); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
227 | const char *checksum; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
228 | xmlnode *item, *metadata; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
229 | if(!buddy) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
230 | return; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
231 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
232 | 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
|
233 | 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
|
234 | metadata = xmlnode_get_child_with_namespace(item, "metadata", AVATARNAMESPACEMETA); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
235 | if(!metadata) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
236 | return; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
237 | /* 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
|
238 | 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
|
239 | 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
|
240 | } else { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
241 | 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
|
242 | 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
|
243 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
244 | /* 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
|
245 | 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
|
246 | 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
|
247 | has_children = TRUE; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
248 | 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
|
249 | 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
|
250 | const char *id = xmlnode_get_attrib(info,"id"); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
251 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
252 | 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
|
253 | /* 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
|
254 | goodinfo = NULL; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
255 | break; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
256 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
257 | /* 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
|
258 | 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
|
259 | goodinfo = info; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
260 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
261 | } |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
262 | 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
|
263 | 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
|
264 | } else if(goodinfo) { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
265 | 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
|
266 | 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
|
267 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
268 | /* the avatar might either be stored in a pep node, or on a HTTP(S) URL */ |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
269 | if(!url) |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
270 | jabber_pep_request_item(js, from, AVATARNAMESPACEDATA, id, do_buddy_avatar_update_data); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
271 | else { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
272 | PurpleUtilFetchUrlData *url_data; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
273 | 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
|
274 | info->js = js; |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
275 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
276 | 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
|
277 | 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
|
278 | 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
|
279 | if (url_data) { |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
280 | 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
|
281 | 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
|
282 | 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
|
283 | } else |
|
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); |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
285 | |
|
ad7612a5d678
Migrate the XMPP User Avatar (XEP-0084) code to its own file
Paul Aurich <darkrain42@pidgin.im>
parents:
diff
changeset
|
286 | } |
|
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 | } |