annotate mcabber/mcabber/caps.c @ 2223:965e0282c128

Backed out changeset fa516ef22145 Turns out that in this hash the value pointer is the same as the key pointer, so there's no need to free both the key and the value.
author Mikael Berthe <mikael@lilotux.net>
date Fri, 06 Nov 2015 22:31:40 +0100
parents 3f9988ec21e0
children f5402d705f67
rev   line source
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
1 /*
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
2 * caps.c -- Entity Capabilities Cache for mcabber
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
3 *
1872
c1d0187f0959 Check for NULL parameters in caps functions
franky
parents: 1811
diff changeset
4 * Copyright (C) 2008-2010 Frank Zschockelt <mcabber@freakysoft.de>
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
5 *
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or (at
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
9 * your option) any later version.
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
10 *
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful, but
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
14 * General Public License for more details.
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
15 *
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
19 * USA
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
20 */
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
21
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
22 #include <glib.h>
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
23 #include <string.h>
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
24 #include <sys/stat.h>
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
25 #include <unistd.h>
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
26 #include <fcntl.h>
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
27
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
28 #include "settings.h"
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
29 #include "utils.h"
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
30
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
31 typedef struct {
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
32 char *category;
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
33 char *type;
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
34 char *name;
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
35 } identity;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
36
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
37 typedef struct {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
38 GHashTable *fields;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
39 } dataform;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
40
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
41 typedef struct {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
42 GHashTable *identities;
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
43 GHashTable *features;
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
44 GHashTable *forms;
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
45 } caps;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
46
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
47 static GHashTable *caps_cache = NULL;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
48
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
49 void caps_destroy(gpointer data)
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
50 {
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
51 caps *c = data;
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
52 g_hash_table_destroy(c->identities);
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
53 g_hash_table_destroy(c->features);
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
54 g_hash_table_destroy(c->forms);
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
55 g_free(c);
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
56 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
57
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
58 void identity_destroy(gpointer data)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
59 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
60 identity *i = data;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
61 g_free(i->category);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
62 g_free(i->type);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
63 g_free(i->name);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
64 g_free(i);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
65 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
66
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
67 void form_destroy(gpointer data)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
68 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
69 dataform *f = data;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
70 g_hash_table_destroy(f->fields);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
71 g_free(f);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
72 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
73
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
74 void field_destroy(gpointer data)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
75 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
76 GList *v = data;
2001
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
77 g_list_foreach (v, (GFunc) g_free, NULL);
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
78 g_list_free (v);
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
79 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
80
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
81 void caps_init(void)
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
82 {
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
83 if (!caps_cache)
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
84 caps_cache = g_hash_table_new_full(g_str_hash, g_str_equal,
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
85 g_free, caps_destroy);
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
86 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
87
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
88 void caps_free(void)
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
89 {
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
90 if (caps_cache) {
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
91 g_hash_table_destroy(caps_cache);
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
92 caps_cache = NULL;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
93 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
94 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
95
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
96 void caps_add(const char *hash)
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
97 {
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
98 if (!hash)
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
99 return;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
100 caps *c = g_new0(caps, 1);
2223
965e0282c128 Backed out changeset fa516ef22145
Mikael Berthe <mikael@lilotux.net>
parents: 2221
diff changeset
101 c->features = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
102 c->identities = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, identity_destroy);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
103 c->forms = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, form_destroy);
2212
778280b01bcb Fix a few memory leaks
Mikael Berthe <mikael@lilotux.net>
parents: 2064
diff changeset
104 g_hash_table_replace(caps_cache, g_strdup(hash), c);
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
105 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
106
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
107 void caps_remove(const char *hash)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
108 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
109 if (!hash)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
110 return;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
111 g_hash_table_remove(caps_cache, hash);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
112 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
113
2001
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
114 /* if hash is not verified, this will bind capabilities set only with bare jid */
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
115 void caps_move_to_local(char *hash, char *bjid)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
116 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
117 char *orig_hash;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
118 caps *c = NULL;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
119 if (!hash || !bjid)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
120 return;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
121 g_hash_table_lookup_extended(caps_cache, hash, (gpointer*)&orig_hash, (gpointer*)&c);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
122 if (c) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
123 g_hash_table_steal(caps_cache, hash);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
124 g_free(orig_hash);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
125 g_hash_table_replace(caps_cache, g_strdup_printf("%s/#%s", bjid, hash), c);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
126 // solidus is guaranteed to never appear in bare jid
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
127 // hash will not appear in base64 encoded hash
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
128 // sequence "/#" is deterministic separator, and allows to identify local cache entry
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
129 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
130 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
131
2001
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
132 /*if bjid is NULL, it will check only verified hashes */
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
133 int caps_has_hash(const char *hash, const char *bjid)
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
134 {
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
135 caps *c = NULL;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
136 if (!hash)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
137 return 0;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
138 c = g_hash_table_lookup(caps_cache, hash);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
139 if (!c && bjid) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
140 char *key = g_strdup_printf("%s/#%s", bjid, hash);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
141 c = g_hash_table_lookup(caps_cache, key);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
142 g_free(key);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
143 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
144 return (c != NULL);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
145 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
146
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
147 void caps_add_identity(const char *hash,
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
148 const char *category,
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
149 const char *name,
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
150 const char *type,
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
151 const char *lang)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
152 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
153 caps *c;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
154 if (!hash || !category || !type)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
155 return;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
156 if (!lang)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
157 lang = "";
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
158
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
159 c = g_hash_table_lookup(caps_cache, hash);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
160 if (c) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
161 identity *i = g_new0(identity, 1);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
162
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
163 i->category = g_strdup(category);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
164 i->name = g_strdup(name);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
165 i->type = g_strdup(type);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
166 g_hash_table_replace(c->identities, g_strdup(lang), i);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
167 }
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
168 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
169
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
170 void caps_set_identity(char *hash,
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
171 const char *category,
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
172 const char *name,
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
173 const char *type)
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
174 {
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
175 caps_add_identity(hash, category, name, type, NULL);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
176 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
177
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
178 void caps_add_dataform(const char *hash, const char *formtype)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
179 {
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
180 caps *c;
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
181 if (!formtype)
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
182 return;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
183 c = g_hash_table_lookup(caps_cache, hash);
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
184 if (c) {
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
185 dataform *d = g_new0(dataform, 1);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
186 char *f = g_strdup(formtype);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
187
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
188 d->fields = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, field_destroy);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
189 g_hash_table_replace(c->forms, f, d);
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
190 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
191 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
192
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
193 gint _strcmp_sort(gconstpointer a, gconstpointer b)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
194 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
195 return g_strcmp0(a, b);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
196 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
197
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
198 void caps_add_dataform_field(const char *hash, const char *formtype,
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
199 const char *field, const char *value)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
200 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
201 caps *c;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
202 if (!formtype || !field || !value)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
203 return;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
204 c = g_hash_table_lookup(caps_cache, hash);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
205 if (c) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
206 dataform *d;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
207 d = g_hash_table_lookup(c->forms, formtype);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
208 if (d) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
209 gpointer key, val;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
210 char *f;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
211 GList *v = NULL;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
212 if (g_hash_table_lookup_extended(d->fields, field, &key, &val)) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
213 g_hash_table_steal(d->fields, field);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
214 g_free(key);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
215 v = val;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
216 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
217 f = g_strdup(field);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
218 v = g_list_insert_sorted(v, g_strdup(value), _strcmp_sort);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
219 g_hash_table_replace(d->fields, f, v);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
220 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
221 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
222 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
223
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
224 void caps_add_feature(const char *hash, const char *feature)
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
225 {
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
226 caps *c;
1872
c1d0187f0959 Check for NULL parameters in caps functions
franky
parents: 1811
diff changeset
227 if (!hash || !feature)
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
228 return;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
229 c = g_hash_table_lookup(caps_cache, hash);
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
230 if (c) {
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
231 char *f = g_strdup(feature);
1645
d3cd4db23f55 Fix for double-inserted features
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1600
diff changeset
232 g_hash_table_replace(c->features, f, f);
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
233 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
234 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
235
2001
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
236 /* If hash is verified, then bare jid is ignored.
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
237 * If there is no globally verified hash, and bare jid is not null,
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
238 * then local storage for that jid will be checked */
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
239 int caps_has_feature(const char *hash, char *feature, char *bjid)
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
240 {
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
241 caps *c = NULL;
1872
c1d0187f0959 Check for NULL parameters in caps functions
franky
parents: 1811
diff changeset
242 if (!hash || !feature)
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
243 return 0;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
244 c = g_hash_table_lookup(caps_cache, hash);
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
245 if (!c && bjid) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
246 char *key = g_strdup_printf("%s/#%s", bjid, hash);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
247 c = g_hash_table_lookup(caps_cache, key);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
248 g_free(key);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
249 }
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
250 if (c)
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
251 return (g_hash_table_lookup(c->features, feature) != NULL);
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
252 return 0;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
253 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
254
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
255 static GFunc _foreach_function;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
256
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
257 void _caps_foreach_helper(gpointer key, gpointer value, gpointer user_data)
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
258 {
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
259 // GFunc func = (GFunc)user_data;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
260 _foreach_function(value, user_data);
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
261 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
262
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
263 void caps_foreach_feature(const char *hash, GFunc func, gpointer user_data)
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
264 {
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
265 caps *c;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
266 if (!hash)
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
267 return;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
268 c = g_hash_table_lookup(caps_cache, hash);
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
269 if (!c)
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
270 return;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
271 _foreach_function = func;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
272 g_hash_table_foreach(c->features, _caps_foreach_helper, user_data);
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
273 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
274
1729
e6e89b1d7831 Minor style and header updates
Mikael Berthe <mikael@lilotux.net>
parents: 1668
diff changeset
275 // Generates the sha1 hash for the special capability "" and returns it
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
276 const char *caps_generate(void)
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
277 {
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
278 GList *features, *langs;
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
279 GChecksum *sha1;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
280 guint8 digest[20];
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
281 gsize digest_size = 20;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
282 gchar *hash, *old_hash = NULL;
2220
79e12dacbccd Fix a 1-byte memory leak in caps_generate()
Mikael Berthe <mikael@lilotux.net>
parents: 2216
diff changeset
283 caps *old_caps, *c;
79e12dacbccd Fix a 1-byte memory leak in caps_generate()
Mikael Berthe <mikael@lilotux.net>
parents: 2216
diff changeset
284 gpointer key;
79e12dacbccd Fix a 1-byte memory leak in caps_generate()
Mikael Berthe <mikael@lilotux.net>
parents: 2216
diff changeset
285
2221
3f9988ec21e0 caps: Add a cast to remove a compilation warning
Mikael Berthe <mikael@lilotux.net>
parents: 2220
diff changeset
286 if (!g_hash_table_lookup_extended(caps_cache, "", &key, (gpointer *)&c))
2220
79e12dacbccd Fix a 1-byte memory leak in caps_generate()
Mikael Berthe <mikael@lilotux.net>
parents: 2216
diff changeset
287 return NULL;
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
288
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
289 g_hash_table_steal(caps_cache, "");
2220
79e12dacbccd Fix a 1-byte memory leak in caps_generate()
Mikael Berthe <mikael@lilotux.net>
parents: 2216
diff changeset
290 g_free(key);
79e12dacbccd Fix a 1-byte memory leak in caps_generate()
Mikael Berthe <mikael@lilotux.net>
parents: 2216
diff changeset
291
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
292 sha1 = g_checksum_new(G_CHECKSUM_SHA1);
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
293
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
294 langs = g_hash_table_get_keys(c->identities);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
295 langs = g_list_sort(langs, _strcmp_sort);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
296 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
297 identity *i;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
298 GList *lang;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
299 char *identity_S;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
300 for (lang=langs; lang; lang=lang->next) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
301 i = g_hash_table_lookup(c->identities, lang->data);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
302 identity_S = g_strdup_printf("%s/%s/%s/%s<", i->category, i->type,
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
303 (char *)lang->data, i->name ? i->name : "");
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
304 g_checksum_update(sha1, (guchar *)identity_S, -1);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
305 g_free(identity_S);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
306 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
307 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
308 g_list_free(langs);
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
309
1662
63ebb1d32c7d Fix for entity capabilities hash generation.
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1645
diff changeset
310 features = g_hash_table_get_values(c->features);
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
311 features = g_list_sort(features, _strcmp_sort);
1662
63ebb1d32c7d Fix for entity capabilities hash generation.
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1645
diff changeset
312 {
63ebb1d32c7d Fix for entity capabilities hash generation.
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1645
diff changeset
313 GList *feature;
63ebb1d32c7d Fix for entity capabilities hash generation.
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1645
diff changeset
314 for (feature=features; feature; feature=feature->next) {
63ebb1d32c7d Fix for entity capabilities hash generation.
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1645
diff changeset
315 g_checksum_update(sha1, feature->data, -1);
63ebb1d32c7d Fix for entity capabilities hash generation.
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1645
diff changeset
316 g_checksum_update(sha1, (guchar *)"<", -1);
63ebb1d32c7d Fix for entity capabilities hash generation.
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1645
diff changeset
317 }
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
318 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
319 g_list_free(features);
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
320
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
321 g_checksum_get_digest(sha1, digest, &digest_size);
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
322 hash = g_base64_encode(digest, digest_size);
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
323 g_checksum_free(sha1);
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
324 g_hash_table_lookup_extended(caps_cache, hash,
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
325 (gpointer *)&old_hash, (gpointer *)&old_caps);
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
326 g_hash_table_insert(caps_cache, hash, c);
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
327 if (old_hash)
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
328 return old_hash;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
329 else
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
330 return hash;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
331 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
332
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
333 gboolean caps_verify(const char *hash, char *function)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
334 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
335 GList *features, *langs, *forms;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
336 GChecksum *checksum;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
337 guint8 digest[20];
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
338 gsize digest_size = 20;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
339 gchar *local_hash;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
340 gboolean match = FALSE;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
341 caps *c = g_hash_table_lookup(caps_cache, hash);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
342
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
343 if (!g_strcmp0(function, "sha-1")) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
344 checksum = g_checksum_new(G_CHECKSUM_SHA1);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
345 } else if (!g_strcmp0(function, "md5")) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
346 checksum = g_checksum_new(G_CHECKSUM_MD5);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
347 digest_size = 16;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
348 } else
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
349 return FALSE;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
350
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
351 langs = g_hash_table_get_keys(c->identities);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
352 langs = g_list_sort(langs, _strcmp_sort);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
353 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
354 identity *i;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
355 GList *lang;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
356 char *identity_S;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
357 for (lang=langs; lang; lang=lang->next) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
358 i = g_hash_table_lookup(c->identities, lang->data);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
359 identity_S = g_strdup_printf("%s/%s/%s/%s<", i->category, i->type,
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
360 (char *)lang->data, i->name ? i->name : "");
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
361 g_checksum_update(checksum, (guchar *)identity_S, -1);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
362 g_free(identity_S);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
363 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
364 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
365 g_list_free(langs);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
366
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
367 features = g_hash_table_get_values(c->features);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
368 features = g_list_sort(features, _strcmp_sort);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
369 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
370 GList *feature;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
371 for (feature=features; feature; feature=feature->next) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
372 g_checksum_update(checksum, feature->data, -1);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
373 g_checksum_update(checksum, (guchar *)"<", -1);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
374 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
375 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
376 g_list_free(features);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
377
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
378 forms = g_hash_table_get_keys(c->forms);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
379 forms = g_list_sort(forms, _strcmp_sort);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
380 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
381 dataform *d;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
382 GList *form, *fields;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
383 for (form=forms; form; form=form->next) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
384 d = g_hash_table_lookup(c->forms, form->data);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
385 g_checksum_update(checksum, form->data, -1);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
386 g_checksum_update(checksum, (guchar *)"<", -1);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
387 fields = g_hash_table_get_keys(d->fields);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
388 fields = g_list_sort(fields, _strcmp_sort);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
389 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
390 GList *field;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
391 GList *values;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
392 for (field=fields; field; field=field->next) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
393 g_checksum_update(checksum, field->data, -1);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
394 g_checksum_update(checksum, (guchar *)"<", -1);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
395 values = g_hash_table_lookup(d->fields, field->data);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
396 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
397 GList *value;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
398 for (value=values; value; value=value->next) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
399 g_checksum_update(checksum, value->data, -1);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
400 g_checksum_update(checksum, (guchar *)"<", -1);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
401 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
402 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
403 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
404 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
405 g_list_free(fields);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
406 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
407 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
408 g_list_free(forms);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
409
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
410 g_checksum_get_digest(checksum, digest, &digest_size);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
411 local_hash = g_base64_encode(digest, digest_size);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
412 g_checksum_free(checksum);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
413
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
414 match = !g_strcmp0(hash, local_hash);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
415
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
416 g_free(local_hash);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
417 return match;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
418 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
419
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
420 static gchar* caps_get_filename(const char* hash)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
421 {
2001
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
422 gchar *hash_fs;
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
423 gchar *dir = (gchar *) settings_opt_get ("caps_directory");
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
424 gchar *file = NULL;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
425
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
426 if (!dir)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
427 goto caps_filename_return;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
428
2001
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
429 hash_fs = g_strdup (hash);
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
430 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
431 const gchar *valid_fs =
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
432 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+=";
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
433 g_strcanon(hash_fs, valid_fs, '-');
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
434 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
435
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
436 dir = expand_filename (dir);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
437 file = g_strdup_printf ("%s/%s.ini", dir, hash_fs);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
438 g_free(dir);
2001
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
439 g_free(hash_fs);
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
440
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
441 caps_filename_return:
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
442 return file;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
443 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
444
2001
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
445 /* Store capabilities set in GKeyFile. To be used with verified hashes only */
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
446 void caps_copy_to_persistent(const char* hash, char* xml)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
447 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
448 gchar *file;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
449 GList *features, *langs, *forms;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
450 GKeyFile *key_file;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
451 caps *c;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
452 int fd;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
453
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
454 g_free (xml);
2064
01485f807811 Remove trailing space
Mikael Berthe <mikael@lilotux.net>
parents: 2001
diff changeset
455
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
456 c = g_hash_table_lookup (caps_cache, hash);
2064
01485f807811 Remove trailing space
Mikael Berthe <mikael@lilotux.net>
parents: 2001
diff changeset
457 if (!c)
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
458 goto caps_copy_return;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
459
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
460 file = caps_get_filename (hash);
2064
01485f807811 Remove trailing space
Mikael Berthe <mikael@lilotux.net>
parents: 2001
diff changeset
461 if (!file)
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
462 goto caps_copy_return;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
463
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
464 fd = open (file, O_WRONLY|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
465 if (fd == -1)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
466 goto caps_copy_exists;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
467
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
468 key_file = g_key_file_new ();
2001
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
469 g_key_file_set_comment (key_file, NULL, NULL,
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
470 "This is autogenerated file. Please do not modify.",
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
471 NULL);
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
472
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
473 langs = g_hash_table_get_keys (c->identities);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
474 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
475 identity *i;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
476 GList *lang;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
477 gchar *group;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
478 for (lang=langs; lang; lang=lang->next) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
479 i = g_hash_table_lookup (c->identities, lang->data);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
480 group = g_strdup_printf("identity_%s", (gchar *)lang->data);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
481 g_key_file_set_string (key_file, group, "category", i->category);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
482 g_key_file_set_string (key_file, group, "type", i->type);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
483 g_key_file_set_string (key_file, group, "name", i->name);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
484 g_free (group);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
485 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
486 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
487 g_list_free (langs);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
488
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
489 features = g_hash_table_get_values (c->features);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
490 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
491 GList *feature;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
492 gchar **string_list;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
493 gint i;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
494
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
495 i = g_list_length (features);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
496 string_list = g_new (gchar*, i + 1);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
497 i = 0;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
498 for (feature=features; feature; feature=feature->next) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
499 string_list[i] = g_strdup(feature->data);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
500 ++i;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
501 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
502 string_list[i] = NULL;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
503
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
504 g_key_file_set_string_list (key_file, "features", "features",
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
505 (const gchar**)string_list, i);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
506 g_strfreev (string_list);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
507 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
508 g_list_free (features);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
509
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
510 forms = g_hash_table_get_keys(c->forms);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
511 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
512 dataform *d;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
513 GList *form, *fields;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
514 gchar *group;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
515 for (form=forms; form; form=form->next) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
516 d = g_hash_table_lookup (c->forms, form->data);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
517 group = g_strdup_printf ("form_%s", (gchar *)form->data);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
518 fields = g_hash_table_get_keys(d->fields);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
519 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
520 GList *field;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
521 GList *values;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
522 for (field=fields; field; field=field->next) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
523 values = g_hash_table_lookup (d->fields, field->data);
2001
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
524 {
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
525 GList *value;
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
526 gchar **string_list;
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
527 gint i;
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
528 i = g_list_length (values);
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
529 string_list = g_new (gchar*, i + 1);
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
530 i = 0;
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
531 for (value=values; value; value=value->next) {
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
532 string_list[i] = g_strdup(value->data);
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
533 ++i;
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
534 }
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
535 string_list[i] = NULL;
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
536
2001
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
537 g_key_file_set_string_list (key_file, group, field->data,
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
538 (const gchar**)string_list, i);
2064
01485f807811 Remove trailing space
Mikael Berthe <mikael@lilotux.net>
parents: 2001
diff changeset
539
2001
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
540 g_strfreev (string_list);
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
541 }
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
542 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
543 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
544 g_list_free(fields);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
545 g_free (group);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
546 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
547 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
548 g_list_free (forms);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
549
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
550 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
551 gchar *data;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
552 gsize length;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
553 data = g_key_file_to_data (key_file, &length, NULL);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
554 write (fd, data, length);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
555 g_free(data);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
556 close (fd);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
557 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
558
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
559 g_key_file_free(key_file);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
560 caps_copy_exists:
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
561 g_free(file);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
562 caps_copy_return:
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
563 return;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
564 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
565
2001
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
566 /* Restore capabilities from GKeyFile. Hash is not verified afterwards */
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
567 gboolean caps_restore_from_persistent (const char* hash)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
568 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
569 gchar *file;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
570 GKeyFile *key_file;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
571 gchar **groups, **group;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
572 gboolean restored = FALSE;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
573
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
574 file = caps_get_filename (hash);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
575 if (!file)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
576 goto caps_restore_no_file;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
577
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
578 key_file = g_key_file_new ();
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
579 if (!g_key_file_load_from_file (key_file, file, G_KEY_FILE_NONE, NULL))
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
580 goto caps_restore_bad_file;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
581
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
582 caps_add(hash);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
583
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
584 groups = g_key_file_get_groups (key_file, NULL);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
585 for (group = groups; *group; ++group) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
586 if (!g_strcmp0(*group, "features")) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
587 gchar **features, **feature;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
588 features = g_key_file_get_string_list (key_file, *group, "features",
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
589 NULL, NULL);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
590 for (feature = features; *feature; ++feature) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
591 caps_add_feature(hash, *feature);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
592 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
593
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
594 g_strfreev (features);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
595 } else if (g_str_has_prefix (*group, "identity_")) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
596 gchar *category, *type, *name, *lang;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
597
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
598 category = g_key_file_get_string(key_file, *group, "category", NULL);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
599 type = g_key_file_get_string(key_file, *group, "type", NULL);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
600 name = g_key_file_get_string(key_file, *group, "name", NULL);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
601 lang = *group + 9; /* "identity_" */
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
602
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
603 caps_add_identity(hash, category, name, type, lang);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
604 g_free(category);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
605 g_free(type);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
606 g_free(name);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
607 } else if (g_str_has_prefix (*group, "form_")) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
608 gchar *formtype;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
609 gchar **fields, **field;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
610 formtype = *group + 5; /* "form_" */
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
611 caps_add_dataform (hash, formtype);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
612
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
613 fields = g_key_file_get_keys(key_file, *group, NULL, NULL);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
614 for (field = fields; *field; ++field) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
615 gchar **values, **value;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
616 values = g_key_file_get_string_list (key_file, *group, *field,
2001
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
617 NULL, NULL);
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
618 for (value = values; *value; ++value) {
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
619 caps_add_dataform_field (hash, formtype, *field, *value);
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
620 }
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
621 g_strfreev (values);
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
622 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
623 g_strfreev (fields);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
624 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
625 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
626 g_strfreev(groups);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
627 restored = TRUE;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
628
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
629 caps_restore_bad_file:
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
630 g_key_file_free (key_file);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
631 g_free (file);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
632 caps_restore_no_file:
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
633 return restored;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
634 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
635
1811
e6d355e50d7a Update Vim modelines
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
636 /* vim: set expandtab cindent cinoptions=>2\:2(0 sw=2 ts=2: For Vim users... */