annotate libpurple/protocols/jabber/data.c @ 28420:7921a53b94b3

Oops, Elliott correctly pointed out this was wrong...
author Paul Aurich <paul@darkrain42.org>
date Sat, 22 Aug 2009 23:32:38 +0000
parents 8c991e09efcb
children 7f447db0e03b 191bb5bf2fc5 7763697a85c8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23448
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
1 /*
28397
8c991e09efcb Update various header copyrights thanks to licensecheck.
Paul Aurich <paul@darkrain42.org>
parents: 27014
diff changeset
2 * Purple is the legal property of its developers, whose names are too numerous
8c991e09efcb Update various header copyrights thanks to licensecheck.
Paul Aurich <paul@darkrain42.org>
parents: 27014
diff changeset
3 * to list here. Please refer to the COPYRIGHT file distributed with this
8c991e09efcb Update various header copyrights thanks to licensecheck.
Paul Aurich <paul@darkrain42.org>
parents: 27014
diff changeset
4 * source distribution.
8c991e09efcb Update various header copyrights thanks to licensecheck.
Paul Aurich <paul@darkrain42.org>
parents: 27014
diff changeset
5 *
23448
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
9 * (at your option) any later version.
25443
5f9a24d1c25e Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 24110
diff changeset
10 *
23448
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
14 * GNU Library General Public License for more details.
25443
5f9a24d1c25e Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 24110
diff changeset
15 *
23448
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
28420
7921a53b94b3 Oops, Elliott correctly pointed out this was wrong...
Paul Aurich <paul@darkrain42.org>
parents: 28397
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
23448
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
19 */
25443
5f9a24d1c25e Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 24110
diff changeset
20
23448
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
21 #include <stdlib.h>
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
22 #include <glib.h>
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
23 #include <string.h>
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
24
23990
0952f73a452c Patch from Phil Hannent fixing build on Windows
Marcus Lundblad <ml@update.uu.se>
parents: 23989
diff changeset
25 #include "internal.h"
23448
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
26 #include "data.h"
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
27 #include "debug.h"
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
28 #include "xmlnode.h"
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
29 #include "util.h"
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
30 #include "iq.h"
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
31
23988
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
32 static GHashTable *local_data_by_alt = NULL;
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
33 static GHashTable *local_data_by_cid = NULL;
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
34 static GHashTable *remote_data_by_cid = NULL;
23448
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
35
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
36 JabberData *
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
37 jabber_data_create_from_data(gconstpointer rawdata, gsize size, const char *type,
23988
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
38 JabberStream *js)
23448
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
39 {
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
40 JabberData *data = g_new0(JabberData, 1);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
41 gchar *checksum = purple_util_get_image_checksum(rawdata, size);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
42 gchar cid[256];
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
43
23988
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
44 g_snprintf(cid, sizeof(cid), "sha1+%s@bob.xmpp.org", checksum);
23448
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
45 g_free(checksum);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
46
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
47 data->cid = g_strdup(cid);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
48 data->type = g_strdup(type);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
49 data->size = size;
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
50
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
51 data->data = g_memdup(rawdata, size);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
52
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
53 return data;
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
54 }
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
55
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
56 JabberData *
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
57 jabber_data_create_from_xml(xmlnode *tag)
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
58 {
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
59 JabberData *data = g_new0(JabberData, 1);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
60 gsize size;
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
61 gpointer raw_data = NULL;
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
62
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
63 if (data == NULL) {
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
64 purple_debug_error("jabber", "Could not allocate data object\n");
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
65 g_free(data);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
66 return NULL;
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
67 }
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
68
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
69 /* check if this is a "data" tag */
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
70 if (strcmp(tag->name, "data") != 0) {
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
71 purple_debug_error("jabber", "Invalid data element");
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
72 g_free(data);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
73 return NULL;
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
74 }
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
75
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
76 data->cid = g_strdup(xmlnode_get_attrib(tag, "cid"));
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
77 data->type = g_strdup(xmlnode_get_attrib(tag, "type"));
25443
5f9a24d1c25e Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 24110
diff changeset
78
23448
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
79 raw_data = xmlnode_get_data(tag);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
80 data->data = purple_base64_decode(raw_data, &size);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
81 data->size = size;
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
82
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
83 g_free(raw_data);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
84
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
85 return data;
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
86 }
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
87
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
88
24110
2c6c9d72f54f A couple of compile warning fixes, a couple of memory leak plugs.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23991
diff changeset
89 static void
2c6c9d72f54f A couple of compile warning fixes, a couple of memory leak plugs.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23991
diff changeset
90 jabber_data_delete(gpointer cbdata)
23448
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
91 {
24110
2c6c9d72f54f A couple of compile warning fixes, a couple of memory leak plugs.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23991
diff changeset
92 JabberData *data = cbdata;
23448
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
93 g_free(data->cid);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
94 g_free(data->type);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
95 g_free(data->data);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
96 g_free(data);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
97 }
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
98
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
99 const char *
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
100 jabber_data_get_cid(const JabberData *data)
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
101 {
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
102 return data->cid;
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
103 }
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
104
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
105
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
106 const char *
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
107 jabber_data_get_type(const JabberData *data)
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
108 {
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
109 return data->type;
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
110 }
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
111
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
112 gsize
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
113 jabber_data_get_size(const JabberData *data)
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
114 {
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
115 return data->size;
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
116 }
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
117
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
118 gpointer
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
119 jabber_data_get_data(const JabberData *data)
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
120 {
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
121 return data->data;
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
122 }
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
123
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
124 xmlnode *
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
125 jabber_data_get_xml_definition(const JabberData *data)
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
126 {
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
127 xmlnode *tag = xmlnode_new("data");
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
128 char *base64data = purple_base64_encode(data->data, data->size);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
129
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
130 xmlnode_set_namespace(tag, XEP_0231_NAMESPACE);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
131 xmlnode_set_attrib(tag, "cid", data->cid);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
132 xmlnode_set_attrib(tag, "type", data->type);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
133
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
134 xmlnode_insert_data(tag, base64data, -1);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
135
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
136 g_free(base64data);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
137
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
138 return tag;
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
139 }
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
140
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
141 xmlnode *
23988
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
142 jabber_data_get_xhtml_im(const JabberData *data, const gchar *alt)
23448
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
143 {
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
144 xmlnode *img = xmlnode_new("img");
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
145 char src[128];
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
146
23988
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
147 xmlnode_set_attrib(img, "alt", alt);
23448
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
148 g_snprintf(src, sizeof(src), "cid:%s", data->cid);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
149 xmlnode_set_attrib(img, "src", src);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
150
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
151 return img;
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
152 }
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
153
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
154 xmlnode *
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
155 jabber_data_get_xml_request(const gchar *cid)
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
156 {
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
157 xmlnode *tag = xmlnode_new("data");
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
158
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
159 xmlnode_set_namespace(tag, XEP_0231_NAMESPACE);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
160 xmlnode_set_attrib(tag, "cid", cid);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
161
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
162 return tag;
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
163 }
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
164
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
165 const JabberData *
23988
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
166 jabber_data_find_local_by_alt(const gchar *alt)
23448
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
167 {
23991
fba7c73c8f02 Fixed a memory error, which was due to me destroying some hashtables in the
Marcus Lundblad <ml@update.uu.se>
parents: 23990
diff changeset
168 purple_debug_info("jabber", "looking up local smiley with alt = %s\n", alt);
23988
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
169 return g_hash_table_lookup(local_data_by_alt, alt);
23448
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
170 }
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
171
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
172 const JabberData *
23988
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
173 jabber_data_find_local_by_cid(const gchar *cid)
23448
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
174 {
23991
fba7c73c8f02 Fixed a memory error, which was due to me destroying some hashtables in the
Marcus Lundblad <ml@update.uu.se>
parents: 23990
diff changeset
175 purple_debug_info("jabber", "lookup local smiley with cid = %s\n", cid);
23988
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
176 return g_hash_table_lookup(local_data_by_cid, cid);
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
177 }
23448
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
178
23988
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
179 const JabberData *
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
180 jabber_data_find_remote_by_cid(const gchar *cid)
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
181 {
23991
fba7c73c8f02 Fixed a memory error, which was due to me destroying some hashtables in the
Marcus Lundblad <ml@update.uu.se>
parents: 23990
diff changeset
182 purple_debug_info("jabber", "lookup remote smiley with cid = %s\n", cid);
25443
5f9a24d1c25e Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 24110
diff changeset
183
23988
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
184 return g_hash_table_lookup(remote_data_by_cid, cid);
23448
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
185 }
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
186
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
187 void
23988
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
188 jabber_data_associate_local(JabberData *data, const gchar *alt)
23448
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
189 {
23991
fba7c73c8f02 Fixed a memory error, which was due to me destroying some hashtables in the
Marcus Lundblad <ml@update.uu.se>
parents: 23990
diff changeset
190 purple_debug_info("jabber", "associating local smiley\n alt = %s, cid = %s\n",
fba7c73c8f02 Fixed a memory error, which was due to me destroying some hashtables in the
Marcus Lundblad <ml@update.uu.se>
parents: 23990
diff changeset
191 alt, jabber_data_get_cid(data));
23988
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
192 g_hash_table_insert(local_data_by_alt, g_strdup(alt), data);
25443
5f9a24d1c25e Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 24110
diff changeset
193 g_hash_table_insert(local_data_by_cid, g_strdup(jabber_data_get_cid(data)),
23988
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
194 data);
23448
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
195 }
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
196
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
197 void
23988
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
198 jabber_data_associate_remote(JabberData *data)
23448
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
199 {
23991
fba7c73c8f02 Fixed a memory error, which was due to me destroying some hashtables in the
Marcus Lundblad <ml@update.uu.se>
parents: 23990
diff changeset
200 purple_debug_info("jabber", "associating remote smiley, cid = %s\n",
fba7c73c8f02 Fixed a memory error, which was due to me destroying some hashtables in the
Marcus Lundblad <ml@update.uu.se>
parents: 23990
diff changeset
201 jabber_data_get_cid(data));
25443
5f9a24d1c25e Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 24110
diff changeset
202 g_hash_table_insert(remote_data_by_cid, g_strdup(jabber_data_get_cid(data)),
23988
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
203 data);
23448
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
204 }
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
205
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
206 void
25933
050052891c55 Pass IQ handlers type, from, id, and the child node
Paul Aurich <paul@darkrain42.org>
parents: 25067
diff changeset
207 jabber_data_parse(JabberStream *js, const char *who, JabberIqType type,
050052891c55 Pass IQ handlers type, from, id, and the child node
Paul Aurich <paul@darkrain42.org>
parents: 25067
diff changeset
208 const char *id, xmlnode *data_node)
23448
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
209 {
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
210 JabberIq *result = NULL;
25933
050052891c55 Pass IQ handlers type, from, id, and the child node
Paul Aurich <paul@darkrain42.org>
parents: 25067
diff changeset
211 const char *cid = xmlnode_get_attrib(data_node, "cid");
050052891c55 Pass IQ handlers type, from, id, and the child node
Paul Aurich <paul@darkrain42.org>
parents: 25067
diff changeset
212 const JabberData *data = cid ? jabber_data_find_local_by_cid(cid) : NULL;
23448
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
213
23988
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
214 if (!data) {
23448
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
215 xmlnode *item_not_found = xmlnode_new("item-not-found");
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
216
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
217 result = jabber_iq_new(js, JABBER_IQ_ERROR);
25933
050052891c55 Pass IQ handlers type, from, id, and the child node
Paul Aurich <paul@darkrain42.org>
parents: 25067
diff changeset
218 if (who)
050052891c55 Pass IQ handlers type, from, id, and the child node
Paul Aurich <paul@darkrain42.org>
parents: 25067
diff changeset
219 xmlnode_set_attrib(result->node, "to", who);
050052891c55 Pass IQ handlers type, from, id, and the child node
Paul Aurich <paul@darkrain42.org>
parents: 25067
diff changeset
220 xmlnode_set_attrib(result->node, "id", id);
23448
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
221 xmlnode_insert_child(result->node, item_not_found);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
222 } else {
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
223 result = jabber_iq_new(js, JABBER_IQ_RESULT);
25933
050052891c55 Pass IQ handlers type, from, id, and the child node
Paul Aurich <paul@darkrain42.org>
parents: 25067
diff changeset
224 if (who)
050052891c55 Pass IQ handlers type, from, id, and the child node
Paul Aurich <paul@darkrain42.org>
parents: 25067
diff changeset
225 xmlnode_set_attrib(result->node, "to", who);
050052891c55 Pass IQ handlers type, from, id, and the child node
Paul Aurich <paul@darkrain42.org>
parents: 25067
diff changeset
226 xmlnode_set_attrib(result->node, "id", id);
23448
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
227 xmlnode_insert_child(result->node,
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
228 jabber_data_get_xml_definition(data));
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
229 }
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
230 jabber_iq_send(result);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
231 }
23988
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
232
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
233 void
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
234 jabber_data_init(void)
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
235 {
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
236 purple_debug_info("jabber", "creating hash tables for data objects\n");
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
237 local_data_by_alt = g_hash_table_new_full(g_str_hash, g_str_equal,
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
238 g_free, NULL);
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
239 local_data_by_cid = g_hash_table_new_full(g_str_hash, g_str_equal,
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
240 g_free, jabber_data_delete);
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
241 remote_data_by_cid = g_hash_table_new_full(g_str_hash, g_str_equal,
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
242 g_free, jabber_data_delete);
26564
457dca546b23 Gratuitous alphabetization of the IQ handlers (again!) and move the data handler to jabber_data_init
Paul Aurich <paul@darkrain42.org>
parents: 25983
diff changeset
243
27014
a8537bbcfb79 Remove trailing whitespace that has snuck in.
Paul Aurich <paul@darkrain42.org>
parents: 26569
diff changeset
244 jabber_iq_register_handler("data", XEP_0231_NAMESPACE, jabber_data_parse);
23988
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
245 }
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
246
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
247 void
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
248 jabber_data_uninit(void)
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
249 {
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
250 purple_debug_info("jabber", "destroying hash tables for data objects\n");
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
251 g_hash_table_destroy(local_data_by_alt);
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
252 g_hash_table_destroy(local_data_by_cid);
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
253 g_hash_table_destroy(remote_data_by_cid);
25763
860ebaf275ae Add more jabber plugin unloading functions to clean up more data structures
Paul Aurich <paul@darkrain42.org>
parents: 24110
diff changeset
254 local_data_by_alt = local_data_by_cid = remote_data_by_cid = NULL;
23988
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23448
diff changeset
255 }