annotate libpurple/protocols/jabber/data.c @ 29651:84ec9e3cbb6d

jabber: Plug some leaks and make the success case quieter.
author Paul Aurich <paul@darkrain42.org>
date Wed, 31 Mar 2010 03:42:21 +0000
parents 1bde873d1b94
children 2ab17571bf42
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
1 /*
28047
8c991e09efcb Update various header copyrights thanks to licensecheck.
Paul Aurich <paul@darkrain42.org>
parents: 26932
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: 26932
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: 26932
diff changeset
4 * source distribution.
8c991e09efcb Update various header copyrights thanks to licensecheck.
Paul Aurich <paul@darkrain42.org>
parents: 26932
diff changeset
5 *
23780
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.
25952
5f9a24d1c25e Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 24179
diff changeset
10 *
23780
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.
25952
5f9a24d1c25e Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 24179
diff changeset
15 *
23780
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
28070
7921a53b94b3 Oops, Elliott correctly pointed out this was wrong...
Paul Aurich <paul@darkrain42.org>
parents: 28047
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
19 */
25952
5f9a24d1c25e Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 24179
diff changeset
20
28647
f1437342cc0e Include 'internal.h' before all other headers to make some non-gcc compilers happy.
Paul Aurich <paul@darkrain42.org>
parents: 28645
diff changeset
21 #include "internal.h"
f1437342cc0e Include 'internal.h' before all other headers to make some non-gcc compilers happy.
Paul Aurich <paul@darkrain42.org>
parents: 28645
diff changeset
22
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
23 #include <stdlib.h>
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
24 #include <glib.h>
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
25 #include <string.h>
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
26
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
27 #include "data.h"
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
28 #include "debug.h"
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
29 #include "xmlnode.h"
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
30 #include "util.h"
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
31 #include "iq.h"
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
32
24058
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
33 static GHashTable *local_data_by_alt = NULL;
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
34 static GHashTable *local_data_by_cid = NULL;
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
35 static GHashTable *remote_data_by_cid = NULL;
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
36
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
37 JabberData *
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
38 jabber_data_create_from_data(gconstpointer rawdata, gsize size, const char *type,
24058
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
39 JabberStream *js)
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
40 {
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
41 JabberData *data = g_new0(JabberData, 1);
29630
9f59abd49def jabber: Validate the hash on incoming BoB objects (in case the CID is on the
Marcus Lundblad <ml@update.uu.se>
parents: 29627
diff changeset
42 gchar *checksum = jabber_calculate_data_hash(rawdata, size, "sha1");
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
43 gchar cid[256];
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
44
24058
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
45 g_snprintf(cid, sizeof(cid), "sha1+%s@bob.xmpp.org", checksum);
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
46 g_free(checksum);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
47
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
48 data->cid = g_strdup(cid);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
49 data->type = g_strdup(type);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
50 data->size = size;
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
51
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
52 data->data = g_memdup(rawdata, size);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
53
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
54 return data;
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
29630
9f59abd49def jabber: Validate the hash on incoming BoB objects (in case the CID is on the
Marcus Lundblad <ml@update.uu.se>
parents: 29627
diff changeset
57 static void
9f59abd49def jabber: Validate the hash on incoming BoB objects (in case the CID is on the
Marcus Lundblad <ml@update.uu.se>
parents: 29627
diff changeset
58 jabber_data_delete(gpointer cbdata)
9f59abd49def jabber: Validate the hash on incoming BoB objects (in case the CID is on the
Marcus Lundblad <ml@update.uu.se>
parents: 29627
diff changeset
59 {
9f59abd49def jabber: Validate the hash on incoming BoB objects (in case the CID is on the
Marcus Lundblad <ml@update.uu.se>
parents: 29627
diff changeset
60 JabberData *data = cbdata;
9f59abd49def jabber: Validate the hash on incoming BoB objects (in case the CID is on the
Marcus Lundblad <ml@update.uu.se>
parents: 29627
diff changeset
61 g_free(data->cid);
9f59abd49def jabber: Validate the hash on incoming BoB objects (in case the CID is on the
Marcus Lundblad <ml@update.uu.se>
parents: 29627
diff changeset
62 g_free(data->type);
9f59abd49def jabber: Validate the hash on incoming BoB objects (in case the CID is on the
Marcus Lundblad <ml@update.uu.se>
parents: 29627
diff changeset
63 g_free(data->data);
9f59abd49def jabber: Validate the hash on incoming BoB objects (in case the CID is on the
Marcus Lundblad <ml@update.uu.se>
parents: 29627
diff changeset
64 g_free(data);
9f59abd49def jabber: Validate the hash on incoming BoB objects (in case the CID is on the
Marcus Lundblad <ml@update.uu.se>
parents: 29627
diff changeset
65 }
9f59abd49def jabber: Validate the hash on incoming BoB objects (in case the CID is on the
Marcus Lundblad <ml@update.uu.se>
parents: 29627
diff changeset
66
9f59abd49def jabber: Validate the hash on incoming BoB objects (in case the CID is on the
Marcus Lundblad <ml@update.uu.se>
parents: 29627
diff changeset
67
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
68 JabberData *
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
69 jabber_data_create_from_xml(xmlnode *tag)
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
70 {
28157
7f447db0e03b jabber: Stricter parsing of a BoB data stanza
Paul Aurich <paul@darkrain42.org>
parents: 28070
diff changeset
71 JabberData *data;
7f447db0e03b jabber: Stricter parsing of a BoB data stanza
Paul Aurich <paul@darkrain42.org>
parents: 28070
diff changeset
72 gchar *raw_data = NULL;
7f447db0e03b jabber: Stricter parsing of a BoB data stanza
Paul Aurich <paul@darkrain42.org>
parents: 28070
diff changeset
73 const gchar *cid, *type;
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
74
28157
7f447db0e03b jabber: Stricter parsing of a BoB data stanza
Paul Aurich <paul@darkrain42.org>
parents: 28070
diff changeset
75 /* check if this is a "data" tag */
7f447db0e03b jabber: Stricter parsing of a BoB data stanza
Paul Aurich <paul@darkrain42.org>
parents: 28070
diff changeset
76 if (strcmp(tag->name, "data") != 0) {
7f447db0e03b jabber: Stricter parsing of a BoB data stanza
Paul Aurich <paul@darkrain42.org>
parents: 28070
diff changeset
77 purple_debug_error("jabber", "Invalid data element\n");
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
78 return NULL;
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
79 }
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
80
28157
7f447db0e03b jabber: Stricter parsing of a BoB data stanza
Paul Aurich <paul@darkrain42.org>
parents: 28070
diff changeset
81 cid = xmlnode_get_attrib(tag, "cid");
7f447db0e03b jabber: Stricter parsing of a BoB data stanza
Paul Aurich <paul@darkrain42.org>
parents: 28070
diff changeset
82 type = xmlnode_get_attrib(tag, "type");
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
83
28157
7f447db0e03b jabber: Stricter parsing of a BoB data stanza
Paul Aurich <paul@darkrain42.org>
parents: 28070
diff changeset
84 if (!cid || !type) {
7f447db0e03b jabber: Stricter parsing of a BoB data stanza
Paul Aurich <paul@darkrain42.org>
parents: 28070
diff changeset
85 purple_debug_error("jabber", "cid or type missing\n");
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
86 return NULL;
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
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
89 raw_data = xmlnode_get_data(tag);
28156
191bb5bf2fc5 Don't crash when receiving an error iq response when trying fetch a custom
Marcus Lundblad <ml@update.uu.se>
parents: 28070
diff changeset
90
28160
40d8427d1813 Minor merge duplication.
Paul Aurich <paul@darkrain42.org>
parents: 28159
diff changeset
91 if (raw_data == NULL || *raw_data == '\0') {
28156
191bb5bf2fc5 Don't crash when receiving an error iq response when trying fetch a custom
Marcus Lundblad <ml@update.uu.se>
parents: 28070
diff changeset
92 purple_debug_error("jabber", "data element was empty");
28161
8aa7df246e13 Eighth^WNinth time's the charm...
Paul Aurich <paul@darkrain42.org>
parents: 28160
diff changeset
93 g_free(raw_data);
28156
191bb5bf2fc5 Don't crash when receiving an error iq response when trying fetch a custom
Marcus Lundblad <ml@update.uu.se>
parents: 28070
diff changeset
94 return NULL;
191bb5bf2fc5 Don't crash when receiving an error iq response when trying fetch a custom
Marcus Lundblad <ml@update.uu.se>
parents: 28070
diff changeset
95 }
191bb5bf2fc5 Don't crash when receiving an error iq response when trying fetch a custom
Marcus Lundblad <ml@update.uu.se>
parents: 28070
diff changeset
96
28157
7f447db0e03b jabber: Stricter parsing of a BoB data stanza
Paul Aurich <paul@darkrain42.org>
parents: 28070
diff changeset
97 data = g_new0(JabberData, 1);
7f447db0e03b jabber: Stricter parsing of a BoB data stanza
Paul Aurich <paul@darkrain42.org>
parents: 28070
diff changeset
98 data->data = purple_base64_decode(raw_data, &data->size);
7f447db0e03b jabber: Stricter parsing of a BoB data stanza
Paul Aurich <paul@darkrain42.org>
parents: 28070
diff changeset
99 g_free(raw_data);
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
100
28157
7f447db0e03b jabber: Stricter parsing of a BoB data stanza
Paul Aurich <paul@darkrain42.org>
parents: 28070
diff changeset
101 if (data->data == NULL) {
7f447db0e03b jabber: Stricter parsing of a BoB data stanza
Paul Aurich <paul@darkrain42.org>
parents: 28070
diff changeset
102 purple_debug_error("jabber", "Malformed base64 data\n");
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
103 g_free(data);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
104 return NULL;
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
28157
7f447db0e03b jabber: Stricter parsing of a BoB data stanza
Paul Aurich <paul@darkrain42.org>
parents: 28070
diff changeset
107 data->cid = g_strdup(cid);
7f447db0e03b jabber: Stricter parsing of a BoB data stanza
Paul Aurich <paul@darkrain42.org>
parents: 28070
diff changeset
108 data->type = g_strdup(type);
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
109
29630
9f59abd49def jabber: Validate the hash on incoming BoB objects (in case the CID is on the
Marcus Lundblad <ml@update.uu.se>
parents: 29627
diff changeset
110 return data;
23780
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
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
113 const char *
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
114 jabber_data_get_cid(const JabberData *data)
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
115 {
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
116 return data->cid;
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
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
119
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
120 const char *
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
121 jabber_data_get_type(const JabberData *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 return data->type;
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
124 }
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
125
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
126 gsize
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
127 jabber_data_get_size(const JabberData *data)
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
128 {
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
129 return data->size;
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
130 }
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
131
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
132 gpointer
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
133 jabber_data_get_data(const JabberData *data)
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
134 {
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
135 return data->data;
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
136 }
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 xmlnode *
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
139 jabber_data_get_xml_definition(const JabberData *data)
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 *tag = xmlnode_new("data");
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
142 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
143
28645
7b4ade7c6d8a jabber: Start putting all the namespaces in one location with consistent naming.
Paul Aurich <paul@darkrain42.org>
parents: 28161
diff changeset
144 xmlnode_set_namespace(tag, NS_BOB);
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
145 xmlnode_set_attrib(tag, "cid", data->cid);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
146 xmlnode_set_attrib(tag, "type", data->type);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
147
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
148 xmlnode_insert_data(tag, base64data, -1);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
149
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
150 g_free(base64data);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
151
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
152 return tag;
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
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
155 xmlnode *
24058
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
156 jabber_data_get_xhtml_im(const JabberData *data, const gchar *alt)
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
157 {
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
158 xmlnode *img = xmlnode_new("img");
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
159 char src[128];
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
160
24058
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
161 xmlnode_set_attrib(img, "alt", alt);
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
162 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
163 xmlnode_set_attrib(img, "src", src);
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 return img;
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
166 }
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
167
29626
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
168 static xmlnode *
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
169 jabber_data_get_xml_request(const gchar *cid)
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 xmlnode *tag = xmlnode_new("data");
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
172
28645
7b4ade7c6d8a jabber: Start putting all the namespaces in one location with consistent naming.
Paul Aurich <paul@darkrain42.org>
parents: 28161
diff changeset
173 xmlnode_set_namespace(tag, NS_BOB);
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
174 xmlnode_set_attrib(tag, "cid", cid);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
175
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
176 return tag;
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
177 }
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
178
29633
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
179 static gboolean
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
180 jabber_data_has_valid_hash(const JabberData *data)
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
181 {
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
182 const gchar *cid = jabber_data_get_cid(data);
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
183 gchar **cid_parts = g_strsplit(cid, "@", -1);
29651
84ec9e3cbb6d jabber: Plug some leaks and make the success case quieter.
Paul Aurich <paul@darkrain42.org>
parents: 29633
diff changeset
184 guint num_cid_parts = 0;
84ec9e3cbb6d jabber: Plug some leaks and make the success case quieter.
Paul Aurich <paul@darkrain42.org>
parents: 29633
diff changeset
185 gboolean ret = FALSE;
29633
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
186
29651
84ec9e3cbb6d jabber: Plug some leaks and make the success case quieter.
Paul Aurich <paul@darkrain42.org>
parents: 29633
diff changeset
187 if (cid_parts)
84ec9e3cbb6d jabber: Plug some leaks and make the success case quieter.
Paul Aurich <paul@darkrain42.org>
parents: 29633
diff changeset
188 num_cid_parts = g_strv_length(cid_parts);
29633
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
189
29651
84ec9e3cbb6d jabber: Plug some leaks and make the success case quieter.
Paul Aurich <paul@darkrain42.org>
parents: 29633
diff changeset
190 if (num_cid_parts == 2 && purple_strequal(cid_parts[1], "bob.xmpp.org")) {
29633
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
191 gchar **sub_parts = g_strsplit(cid_parts[0], "+", -1);
29651
84ec9e3cbb6d jabber: Plug some leaks and make the success case quieter.
Paul Aurich <paul@darkrain42.org>
parents: 29633
diff changeset
192 guint num_sub_parts = 0;
29633
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
193
29651
84ec9e3cbb6d jabber: Plug some leaks and make the success case quieter.
Paul Aurich <paul@darkrain42.org>
parents: 29633
diff changeset
194 if (sub_parts)
84ec9e3cbb6d jabber: Plug some leaks and make the success case quieter.
Paul Aurich <paul@darkrain42.org>
parents: 29633
diff changeset
195 num_sub_parts = g_strv_length(sub_parts);
29633
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
196
29651
84ec9e3cbb6d jabber: Plug some leaks and make the success case quieter.
Paul Aurich <paul@darkrain42.org>
parents: 29633
diff changeset
197 if (num_sub_parts == 2) {
29633
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
198 const gchar *hash_algo = sub_parts[0];
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
199 const gchar *hash_value = sub_parts[1];
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
200 gchar *digest =
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
201 jabber_calculate_data_hash(jabber_data_get_data(data),
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
202 jabber_data_get_size(data), hash_algo);
29651
84ec9e3cbb6d jabber: Plug some leaks and make the success case quieter.
Paul Aurich <paul@darkrain42.org>
parents: 29633
diff changeset
203
29633
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
204 if (digest) {
29651
84ec9e3cbb6d jabber: Plug some leaks and make the success case quieter.
Paul Aurich <paul@darkrain42.org>
parents: 29633
diff changeset
205 ret = purple_strequal(digest, hash_value);
29633
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
206
29651
84ec9e3cbb6d jabber: Plug some leaks and make the success case quieter.
Paul Aurich <paul@darkrain42.org>
parents: 29633
diff changeset
207 if (!ret)
84ec9e3cbb6d jabber: Plug some leaks and make the success case quieter.
Paul Aurich <paul@darkrain42.org>
parents: 29633
diff changeset
208 purple_debug_warning("jabber", "Unable to validate BoB "
84ec9e3cbb6d jabber: Plug some leaks and make the success case quieter.
Paul Aurich <paul@darkrain42.org>
parents: 29633
diff changeset
209 "hash; expecting %s, got %s\n",
84ec9e3cbb6d jabber: Plug some leaks and make the success case quieter.
Paul Aurich <paul@darkrain42.org>
parents: 29633
diff changeset
210 cid, digest);
84ec9e3cbb6d jabber: Plug some leaks and make the success case quieter.
Paul Aurich <paul@darkrain42.org>
parents: 29633
diff changeset
211
29633
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
212 g_free(digest);
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
213 } else {
29651
84ec9e3cbb6d jabber: Plug some leaks and make the success case quieter.
Paul Aurich <paul@darkrain42.org>
parents: 29633
diff changeset
214 purple_debug_warning("jabber", "Unable to validate BoB hash; "
84ec9e3cbb6d jabber: Plug some leaks and make the success case quieter.
Paul Aurich <paul@darkrain42.org>
parents: 29633
diff changeset
215 "unknown hash algorithm %s\n", hash_algo);
29633
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
216 }
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
217 } else {
29651
84ec9e3cbb6d jabber: Plug some leaks and make the success case quieter.
Paul Aurich <paul@darkrain42.org>
parents: 29633
diff changeset
218 purple_debug_warning("jabber", "Malformed BoB CID\n");
29633
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
219 }
29651
84ec9e3cbb6d jabber: Plug some leaks and make the success case quieter.
Paul Aurich <paul@darkrain42.org>
parents: 29633
diff changeset
220
84ec9e3cbb6d jabber: Plug some leaks and make the success case quieter.
Paul Aurich <paul@darkrain42.org>
parents: 29633
diff changeset
221 g_strfreev(sub_parts);
29633
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
222 }
29651
84ec9e3cbb6d jabber: Plug some leaks and make the success case quieter.
Paul Aurich <paul@darkrain42.org>
parents: 29633
diff changeset
223
84ec9e3cbb6d jabber: Plug some leaks and make the success case quieter.
Paul Aurich <paul@darkrain42.org>
parents: 29633
diff changeset
224 g_strfreev(cid_parts);
84ec9e3cbb6d jabber: Plug some leaks and make the success case quieter.
Paul Aurich <paul@darkrain42.org>
parents: 29633
diff changeset
225 return ret;
29633
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
226 }
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
227
29626
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
228
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
229 typedef struct {
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
230 gpointer userdata;
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
231 gchar *alt;
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
232 gboolean ephemeral;
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
233 JabberDataRequestCallback *cb;
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
234 } JabberDataRequestData;
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
235
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
236 static void
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
237 jabber_data_request_cb(JabberStream *js, const char *from,
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
238 JabberIqType type, const char *id, xmlnode *packet, gpointer data)
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
239 {
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
240 JabberDataRequestData *request_data = (JabberDataRequestData *) data;
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
241 gpointer userdata = request_data->userdata;
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
242 gchar *alt = request_data->alt;
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
243 gboolean ephemeral = request_data->ephemeral;
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
244 JabberDataRequestCallback *cb = request_data->cb;
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
245
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
246 xmlnode *data_element = xmlnode_get_child(packet, "data");
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
247 xmlnode *item_not_found = xmlnode_get_child(packet, "item-not-found");
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
248
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
249 /* did we get a data element as result? */
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
250 if (data_element && type == JABBER_IQ_RESULT) {
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
251 JabberData *data = jabber_data_create_from_xml(data_element);
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
252
29633
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
253 if (!ephemeral) {
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
254 jabber_data_associate_remote(js, from, data);
29626
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
255 }
29633
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
256 cb(data, alt, userdata);
29626
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
257 } else if (item_not_found) {
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
258 purple_debug_info("jabber",
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
259 "Responder didn't recognize requested data\n");
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
260 cb(NULL, alt, userdata);
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
261 } else {
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
262 purple_debug_error("jabber", "Unknown response to data request\n");
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
263 cb(NULL, alt, userdata);
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
264 }
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
265
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
266 g_free(request_data);
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
267 }
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
268
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
269 void
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
270 jabber_data_request(JabberStream *js, const gchar *cid, const gchar *who,
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
271 gchar *alt, gboolean ephemeral, JabberDataRequestCallback cb,
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
272 gpointer userdata)
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
273 {
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
274 JabberIq *request = jabber_iq_new(js, JABBER_IQ_GET);
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
275 xmlnode *data_request = jabber_data_get_xml_request(cid);
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
276 JabberDataRequestData *data = g_new0(JabberDataRequestData, 1);
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
277
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
278 data->userdata = userdata;
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
279 data->alt = alt;
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
280 data->ephemeral = ephemeral;
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
281 data->cb = cb;
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
282
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
283 xmlnode_set_attrib(request->node, "to", who);
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
284 jabber_iq_set_callback(request, jabber_data_request_cb, data);
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
285 xmlnode_insert_child(request->node, data_request);
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
286 jabber_iq_send(request);
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
287 }
fce17268c9ec jabber: Refactor BoB request code to reside inside data.c
Marcus Lundblad <ml@update.uu.se>
parents: 29554
diff changeset
288
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
289 const JabberData *
24058
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
290 jabber_data_find_local_by_alt(const gchar *alt)
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
291 {
24061
fba7c73c8f02 Fixed a memory error, which was due to me destroying some hashtables in the
Marcus Lundblad <ml@update.uu.se>
parents: 24060
diff changeset
292 purple_debug_info("jabber", "looking up local smiley with alt = %s\n", alt);
24058
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
293 return g_hash_table_lookup(local_data_by_alt, alt);
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
294 }
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
295
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
296 const JabberData *
24058
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
297 jabber_data_find_local_by_cid(const gchar *cid)
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
298 {
24061
fba7c73c8f02 Fixed a memory error, which was due to me destroying some hashtables in the
Marcus Lundblad <ml@update.uu.se>
parents: 24060
diff changeset
299 purple_debug_info("jabber", "lookup local smiley with cid = %s\n", cid);
24058
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
300 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: 23780
diff changeset
301 }
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
302
24058
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
303 const JabberData *
29633
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
304 jabber_data_find_remote_by_cid(JabberStream *js, const gchar *who,
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
305 const gchar *cid)
24058
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
306 {
29633
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
307 const JabberData *data = g_hash_table_lookup(remote_data_by_cid, cid);
24061
fba7c73c8f02 Fixed a memory error, which was due to me destroying some hashtables in the
Marcus Lundblad <ml@update.uu.se>
parents: 24060
diff changeset
308 purple_debug_info("jabber", "lookup remote smiley with cid = %s\n", cid);
25952
5f9a24d1c25e Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 24179
diff changeset
309
29633
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
310 if (data == NULL) {
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
311 gchar *jid_cid =
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
312 g_strdup_printf("%s@%s/%s%s%s", js->user->node, js->user->domain,
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
313 js->user->resource, who, cid);
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
314 purple_debug_info("jabber",
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
315 "didn't find BoB object by pure CID, try including JIDs: %s\n",
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
316 jid_cid);
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
317 data = g_hash_table_lookup(remote_data_by_cid, jid_cid);
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
318 g_free(jid_cid);
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
319 }
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
320 return data;
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
321 }
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
322
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
323 void
24058
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
324 jabber_data_associate_local(JabberData *data, const gchar *alt)
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
325 {
24061
fba7c73c8f02 Fixed a memory error, which was due to me destroying some hashtables in the
Marcus Lundblad <ml@update.uu.se>
parents: 24060
diff changeset
326 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: 24060
diff changeset
327 alt, jabber_data_get_cid(data));
24058
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
328 g_hash_table_insert(local_data_by_alt, g_strdup(alt), data);
25952
5f9a24d1c25e Remove some extra trailing whitespace I noticed after merging mlundblad's
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 24179
diff changeset
329 g_hash_table_insert(local_data_by_cid, g_strdup(jabber_data_get_cid(data)),
24058
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
330 data);
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
331 }
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
332
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
333 void
29633
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
334 jabber_data_associate_remote(JabberStream *js, const gchar *who, JabberData *data)
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
335 {
29633
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
336 gchar *cid;
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
337
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
338 if (jabber_data_has_valid_hash(data)) {
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
339 cid = g_strdup(jabber_data_get_cid(data));
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
340 } else {
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
341 cid = g_strdup_printf("%s@%s/%s%s%s", js->user->node, js->user->domain,
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
342 js->user->resource, who, jabber_data_get_cid(data));
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
343 }
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
344
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
345 purple_debug_info("jabber", "associating remote BoB object with cid = %s\n",
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
346 cid);
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
347
1bde873d1b94 jabber: Cache incoming BoB object per JID (and local JID) instead of discarding
Marcus Lundblad <ml@update.uu.se>
parents: 29630
diff changeset
348 g_hash_table_insert(remote_data_by_cid, cid, data);
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
349 }
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
350
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
351 void
25648
050052891c55 Pass IQ handlers type, from, id, and the child node
Paul Aurich <paul@darkrain42.org>
parents: 25433
diff changeset
352 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: 25433
diff changeset
353 const char *id, xmlnode *data_node)
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
354 {
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
355 JabberIq *result = NULL;
25648
050052891c55 Pass IQ handlers type, from, id, and the child node
Paul Aurich <paul@darkrain42.org>
parents: 25433
diff changeset
356 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: 25433
diff changeset
357 const JabberData *data = cid ? jabber_data_find_local_by_cid(cid) : NULL;
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
358
24058
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
359 if (!data) {
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
360 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
361
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
362 result = jabber_iq_new(js, JABBER_IQ_ERROR);
25648
050052891c55 Pass IQ handlers type, from, id, and the child node
Paul Aurich <paul@darkrain42.org>
parents: 25433
diff changeset
363 if (who)
050052891c55 Pass IQ handlers type, from, id, and the child node
Paul Aurich <paul@darkrain42.org>
parents: 25433
diff changeset
364 xmlnode_set_attrib(result->node, "to", who);
050052891c55 Pass IQ handlers type, from, id, and the child node
Paul Aurich <paul@darkrain42.org>
parents: 25433
diff changeset
365 xmlnode_set_attrib(result->node, "id", id);
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
366 xmlnode_insert_child(result->node, item_not_found);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
367 } else {
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
368 result = jabber_iq_new(js, JABBER_IQ_RESULT);
25648
050052891c55 Pass IQ handlers type, from, id, and the child node
Paul Aurich <paul@darkrain42.org>
parents: 25433
diff changeset
369 if (who)
050052891c55 Pass IQ handlers type, from, id, and the child node
Paul Aurich <paul@darkrain42.org>
parents: 25433
diff changeset
370 xmlnode_set_attrib(result->node, "to", who);
050052891c55 Pass IQ handlers type, from, id, and the child node
Paul Aurich <paul@darkrain42.org>
parents: 25433
diff changeset
371 xmlnode_set_attrib(result->node, "id", id);
23780
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
372 xmlnode_insert_child(result->node,
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
373 jabber_data_get_xml_definition(data));
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
374 }
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
375 jabber_iq_send(result);
9d83ae2c1a4f New files used for custom smileys.
Marcus Lundblad <ml@update.uu.se>
parents:
diff changeset
376 }
24058
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
377
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
378 void
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
379 jabber_data_init(void)
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
380 {
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
381 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: 23780
diff changeset
382 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: 23780
diff changeset
383 g_free, NULL);
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
384 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: 23780
diff changeset
385 g_free, jabber_data_delete);
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
386 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: 23780
diff changeset
387 g_free, jabber_data_delete);
26482
457dca546b23 Gratuitous alphabetization of the IQ handlers (again!) and move the data handler to jabber_data_init
Paul Aurich <paul@darkrain42.org>
parents: 25979
diff changeset
388
28645
7b4ade7c6d8a jabber: Start putting all the namespaces in one location with consistent naming.
Paul Aurich <paul@darkrain42.org>
parents: 28161
diff changeset
389 jabber_iq_register_handler("data", NS_BOB, jabber_data_parse);
24058
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
390 }
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
391
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
392 void
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
393 jabber_data_uninit(void)
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
394 {
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
395 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: 23780
diff changeset
396 g_hash_table_destroy(local_data_by_alt);
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
397 g_hash_table_destroy(local_data_by_cid);
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
398 g_hash_table_destroy(remote_data_by_cid);
25167
860ebaf275ae Add more jabber plugin unloading functions to clean up more data structures
Paul Aurich <paul@darkrain42.org>
parents: 24179
diff changeset
399 local_data_by_alt = local_data_by_cid = remote_data_by_cid = NULL;
24058
305fac6af8f9 Updated to use latest spec. in XEP-0231
Marcus Lundblad <ml@update.uu.se>
parents: 23780
diff changeset
400 }