annotate mcabber/mcabber/caps.c @ 2334:6ad3cada768c default tip

Fix multiple declarations issue with vi_mode This fails compilation with GCC 10 or -fno-common in CFLAGS. Link: https://bugs.gentoo.org/707418
author Andrey Utkin <andrey_utkin@gentoo.org>
date Mon, 17 Feb 2020 23:44:03 +0000
parents f5402d705f67
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
2268
f5402d705f67 Fix FSF addresses in all files
Mikael Berthe <mikael@lilotux.net>
parents: 2223
diff changeset
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
18 */
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
19
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
20 #include <glib.h>
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
21 #include <string.h>
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
22 #include <sys/stat.h>
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
23 #include <unistd.h>
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
24 #include <fcntl.h>
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
25
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
26 #include "settings.h"
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
27 #include "utils.h"
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
28
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
29 typedef struct {
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
30 char *category;
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
31 char *type;
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
32 char *name;
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
33 } identity;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
34
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
35 typedef struct {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
36 GHashTable *fields;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
37 } dataform;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
38
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
39 typedef struct {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
40 GHashTable *identities;
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
41 GHashTable *features;
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
42 GHashTable *forms;
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
43 } caps;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
44
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
45 static GHashTable *caps_cache = NULL;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
46
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
47 void caps_destroy(gpointer data)
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
48 {
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
49 caps *c = data;
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
50 g_hash_table_destroy(c->identities);
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
51 g_hash_table_destroy(c->features);
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
52 g_hash_table_destroy(c->forms);
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
53 g_free(c);
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
54 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
55
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
56 void identity_destroy(gpointer data)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
57 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
58 identity *i = data;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
59 g_free(i->category);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
60 g_free(i->type);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
61 g_free(i->name);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
62 g_free(i);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
63 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
64
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
65 void form_destroy(gpointer data)
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 dataform *f = data;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
68 g_hash_table_destroy(f->fields);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
69 g_free(f);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
70 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
71
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
72 void field_destroy(gpointer data)
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 GList *v = data;
2001
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
75 g_list_foreach (v, (GFunc) g_free, NULL);
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
76 g_list_free (v);
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
77 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
78
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
79 void caps_init(void)
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
80 {
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
81 if (!caps_cache)
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
82 caps_cache = g_hash_table_new_full(g_str_hash, g_str_equal,
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
83 g_free, caps_destroy);
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
84 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
85
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
86 void caps_free(void)
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
87 {
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
88 if (caps_cache) {
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
89 g_hash_table_destroy(caps_cache);
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
90 caps_cache = NULL;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
91 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
92 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
93
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
94 void caps_add(const char *hash)
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
95 {
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
96 if (!hash)
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
97 return;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
98 caps *c = g_new0(caps, 1);
2223
965e0282c128 Backed out changeset fa516ef22145
Mikael Berthe <mikael@lilotux.net>
parents: 2221
diff changeset
99 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
100 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
101 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
102 g_hash_table_replace(caps_cache, g_strdup(hash), c);
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
103 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
104
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
105 void caps_remove(const char *hash)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
106 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
107 if (!hash)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
108 return;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
109 g_hash_table_remove(caps_cache, hash);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
110 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
111
2001
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
112 /* 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
113 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
114 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
115 char *orig_hash;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
116 caps *c = NULL;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
117 if (!hash || !bjid)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
118 return;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
119 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
120 if (c) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
121 g_hash_table_steal(caps_cache, hash);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
122 g_free(orig_hash);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
123 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
124 // 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
125 // hash will not appear in base64 encoded hash
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
126 // 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
127 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
128 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
129
2001
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
130 /*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
131 int caps_has_hash(const char *hash, const char *bjid)
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
132 {
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
133 caps *c = NULL;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
134 if (!hash)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
135 return 0;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
136 c = g_hash_table_lookup(caps_cache, hash);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
137 if (!c && bjid) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
138 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
139 c = g_hash_table_lookup(caps_cache, key);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
140 g_free(key);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
141 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
142 return (c != NULL);
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
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
145 void caps_add_identity(const char *hash,
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
146 const char *category,
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
147 const char *name,
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
148 const char *type,
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
149 const char *lang)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
150 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
151 caps *c;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
152 if (!hash || !category || !type)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
153 return;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
154 if (!lang)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
155 lang = "";
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
156
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
157 c = g_hash_table_lookup(caps_cache, hash);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
158 if (c) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
159 identity *i = g_new0(identity, 1);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
160
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
161 i->category = g_strdup(category);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
162 i->name = g_strdup(name);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
163 i->type = g_strdup(type);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
164 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
165 }
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
166 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
167
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
168 void caps_set_identity(char *hash,
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
169 const char *category,
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
170 const char *name,
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
171 const char *type)
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
172 {
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
173 caps_add_identity(hash, category, name, type, NULL);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
174 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
175
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
176 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
177 {
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
178 caps *c;
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
179 if (!formtype)
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
180 return;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
181 c = g_hash_table_lookup(caps_cache, hash);
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
182 if (c) {
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
183 dataform *d = g_new0(dataform, 1);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
184 char *f = g_strdup(formtype);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
185
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
186 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
187 g_hash_table_replace(c->forms, f, d);
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
188 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
189 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
190
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
191 gint _strcmp_sort(gconstpointer a, gconstpointer b)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
192 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
193 return g_strcmp0(a, 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
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
196 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
197 const char *field, const char *value)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
198 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
199 caps *c;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
200 if (!formtype || !field || !value)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
201 return;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
202 c = g_hash_table_lookup(caps_cache, hash);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
203 if (c) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
204 dataform *d;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
205 d = g_hash_table_lookup(c->forms, formtype);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
206 if (d) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
207 gpointer key, val;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
208 char *f;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
209 GList *v = NULL;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
210 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
211 g_hash_table_steal(d->fields, field);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
212 g_free(key);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
213 v = val;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
214 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
215 f = g_strdup(field);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
216 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
217 g_hash_table_replace(d->fields, f, v);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
218 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
219 }
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 void caps_add_feature(const char *hash, const char *feature)
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
223 {
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
224 caps *c;
1872
c1d0187f0959 Check for NULL parameters in caps functions
franky
parents: 1811
diff changeset
225 if (!hash || !feature)
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
226 return;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
227 c = g_hash_table_lookup(caps_cache, hash);
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
228 if (c) {
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
229 char *f = g_strdup(feature);
1645
d3cd4db23f55 Fix for double-inserted features
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1600
diff changeset
230 g_hash_table_replace(c->features, f, f);
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
231 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
232 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
233
2001
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
234 /* 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
235 * 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
236 * 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
237 int caps_has_feature(const char *hash, char *feature, char *bjid)
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
238 {
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
239 caps *c = NULL;
1872
c1d0187f0959 Check for NULL parameters in caps functions
franky
parents: 1811
diff changeset
240 if (!hash || !feature)
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
241 return 0;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
242 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
243 if (!c && bjid) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
244 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
245 c = g_hash_table_lookup(caps_cache, key);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
246 g_free(key);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
247 }
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
248 if (c)
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
249 return (g_hash_table_lookup(c->features, feature) != NULL);
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
250 return 0;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
251 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
252
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
253 static GFunc _foreach_function;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
254
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
255 void _caps_foreach_helper(gpointer key, gpointer value, gpointer user_data)
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
256 {
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
257 // GFunc func = (GFunc)user_data;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
258 _foreach_function(value, user_data);
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
259 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
260
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
261 void caps_foreach_feature(const char *hash, GFunc func, gpointer user_data)
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
262 {
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
263 caps *c;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
264 if (!hash)
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
265 return;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
266 c = g_hash_table_lookup(caps_cache, hash);
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
267 if (!c)
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
268 return;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
269 _foreach_function = func;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
270 g_hash_table_foreach(c->features, _caps_foreach_helper, user_data);
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
271 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
272
1729
e6e89b1d7831 Minor style and header updates
Mikael Berthe <mikael@lilotux.net>
parents: 1668
diff changeset
273 // Generates the sha1 hash for the special capability "" and returns it
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
274 const char *caps_generate(void)
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
275 {
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
276 GList *features, *langs;
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
277 GChecksum *sha1;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
278 guint8 digest[20];
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
279 gsize digest_size = 20;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
280 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
281 caps *old_caps, *c;
79e12dacbccd Fix a 1-byte memory leak in caps_generate()
Mikael Berthe <mikael@lilotux.net>
parents: 2216
diff changeset
282 gpointer key;
79e12dacbccd Fix a 1-byte memory leak in caps_generate()
Mikael Berthe <mikael@lilotux.net>
parents: 2216
diff changeset
283
2221
3f9988ec21e0 caps: Add a cast to remove a compilation warning
Mikael Berthe <mikael@lilotux.net>
parents: 2220
diff changeset
284 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
285 return NULL;
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
286
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
287 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
288 g_free(key);
79e12dacbccd Fix a 1-byte memory leak in caps_generate()
Mikael Berthe <mikael@lilotux.net>
parents: 2216
diff changeset
289
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
290 sha1 = g_checksum_new(G_CHECKSUM_SHA1);
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
291
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
292 langs = g_hash_table_get_keys(c->identities);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
293 langs = g_list_sort(langs, _strcmp_sort);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
294 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
295 identity *i;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
296 GList *lang;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
297 char *identity_S;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
298 for (lang=langs; lang; lang=lang->next) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
299 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
300 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
301 (char *)lang->data, i->name ? i->name : "");
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
302 g_checksum_update(sha1, (guchar *)identity_S, -1);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
303 g_free(identity_S);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
304 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
305 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
306 g_list_free(langs);
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
307
1662
63ebb1d32c7d Fix for entity capabilities hash generation.
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1645
diff changeset
308 features = g_hash_table_get_values(c->features);
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
309 features = g_list_sort(features, _strcmp_sort);
1662
63ebb1d32c7d Fix for entity capabilities hash generation.
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1645
diff changeset
310 {
63ebb1d32c7d Fix for entity capabilities hash generation.
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1645
diff changeset
311 GList *feature;
63ebb1d32c7d Fix for entity capabilities hash generation.
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1645
diff changeset
312 for (feature=features; feature; feature=feature->next) {
63ebb1d32c7d Fix for entity capabilities hash generation.
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1645
diff changeset
313 g_checksum_update(sha1, feature->data, -1);
63ebb1d32c7d Fix for entity capabilities hash generation.
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1645
diff changeset
314 g_checksum_update(sha1, (guchar *)"<", -1);
63ebb1d32c7d Fix for entity capabilities hash generation.
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1645
diff changeset
315 }
1600
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
316 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
317 g_list_free(features);
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_checksum_get_digest(sha1, digest, &digest_size);
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
320 hash = g_base64_encode(digest, digest_size);
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
321 g_checksum_free(sha1);
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
322 g_hash_table_lookup_extended(caps_cache, hash,
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
323 (gpointer *)&old_hash, (gpointer *)&old_caps);
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
324 g_hash_table_insert(caps_cache, hash, c);
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
325 if (old_hash)
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
326 return old_hash;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
327 else
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
328 return hash;
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
329 }
c5ee395fbc8c Updated Entity Capabilities support (XEP-0115)
franky
parents:
diff changeset
330
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
331 gboolean caps_verify(const char *hash, char *function)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
332 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
333 GList *features, *langs, *forms;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
334 GChecksum *checksum;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
335 guint8 digest[20];
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
336 gsize digest_size = 20;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
337 gchar *local_hash;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
338 gboolean match = FALSE;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
339 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
340
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
341 if (!g_strcmp0(function, "sha-1")) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
342 checksum = g_checksum_new(G_CHECKSUM_SHA1);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
343 } else if (!g_strcmp0(function, "md5")) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
344 checksum = g_checksum_new(G_CHECKSUM_MD5);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
345 digest_size = 16;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
346 } else
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
347 return FALSE;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
348
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
349 langs = g_hash_table_get_keys(c->identities);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
350 langs = g_list_sort(langs, _strcmp_sort);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
351 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
352 identity *i;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
353 GList *lang;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
354 char *identity_S;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
355 for (lang=langs; lang; lang=lang->next) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
356 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
357 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
358 (char *)lang->data, i->name ? i->name : "");
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
359 g_checksum_update(checksum, (guchar *)identity_S, -1);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
360 g_free(identity_S);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
361 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
362 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
363 g_list_free(langs);
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 features = g_hash_table_get_values(c->features);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
366 features = g_list_sort(features, _strcmp_sort);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
367 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
368 GList *feature;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
369 for (feature=features; feature; feature=feature->next) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
370 g_checksum_update(checksum, feature->data, -1);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
371 g_checksum_update(checksum, (guchar *)"<", -1);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
372 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
373 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
374 g_list_free(features);
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 forms = g_hash_table_get_keys(c->forms);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
377 forms = g_list_sort(forms, _strcmp_sort);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
378 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
379 dataform *d;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
380 GList *form, *fields;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
381 for (form=forms; form; form=form->next) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
382 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
383 g_checksum_update(checksum, form->data, -1);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
384 g_checksum_update(checksum, (guchar *)"<", -1);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
385 fields = g_hash_table_get_keys(d->fields);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
386 fields = g_list_sort(fields, _strcmp_sort);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
387 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
388 GList *field;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
389 GList *values;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
390 for (field=fields; field; field=field->next) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
391 g_checksum_update(checksum, field->data, -1);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
392 g_checksum_update(checksum, (guchar *)"<", -1);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
393 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
394 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
395 GList *value;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
396 for (value=values; value; value=value->next) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
397 g_checksum_update(checksum, value->data, -1);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
398 g_checksum_update(checksum, (guchar *)"<", -1);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
399 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
400 }
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 g_list_free(fields);
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 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
406 g_list_free(forms);
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_checksum_get_digest(checksum, digest, &digest_size);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
409 local_hash = g_base64_encode(digest, digest_size);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
410 g_checksum_free(checksum);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
411
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
412 match = !g_strcmp0(hash, local_hash);
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 g_free(local_hash);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
415 return match;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
416 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
417
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
418 static gchar* caps_get_filename(const char* hash)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
419 {
2001
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
420 gchar *hash_fs;
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
421 gchar *dir = (gchar *) settings_opt_get ("caps_directory");
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
422 gchar *file = NULL;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
423
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
424 if (!dir)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
425 goto caps_filename_return;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
426
2001
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
427 hash_fs = g_strdup (hash);
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
428 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
429 const gchar *valid_fs =
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
430 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+=";
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
431 g_strcanon(hash_fs, valid_fs, '-');
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
432 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
433
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
434 dir = expand_filename (dir);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
435 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
436 g_free(dir);
2001
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
437 g_free(hash_fs);
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
438
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
439 caps_filename_return:
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
440 return file;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
441 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
442
2001
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
443 /* 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
444 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
445 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
446 gchar *file;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
447 GList *features, *langs, *forms;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
448 GKeyFile *key_file;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
449 caps *c;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
450 int fd;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
451
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
452 g_free (xml);
2064
01485f807811 Remove trailing space
Mikael Berthe <mikael@lilotux.net>
parents: 2001
diff changeset
453
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
454 c = g_hash_table_lookup (caps_cache, hash);
2064
01485f807811 Remove trailing space
Mikael Berthe <mikael@lilotux.net>
parents: 2001
diff changeset
455 if (!c)
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
456 goto caps_copy_return;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
457
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
458 file = caps_get_filename (hash);
2064
01485f807811 Remove trailing space
Mikael Berthe <mikael@lilotux.net>
parents: 2001
diff changeset
459 if (!file)
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
460 goto caps_copy_return;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
461
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
462 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
463 if (fd == -1)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
464 goto caps_copy_exists;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
465
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
466 key_file = g_key_file_new ();
2001
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
467 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
468 "This is autogenerated file. Please do not modify.",
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
469 NULL);
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
470
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
471 langs = g_hash_table_get_keys (c->identities);
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 identity *i;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
474 GList *lang;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
475 gchar *group;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
476 for (lang=langs; lang; lang=lang->next) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
477 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
478 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
479 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
480 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
481 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
482 g_free (group);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
483 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
484 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
485 g_list_free (langs);
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 features = g_hash_table_get_values (c->features);
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 GList *feature;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
490 gchar **string_list;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
491 gint i;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
492
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
493 i = g_list_length (features);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
494 string_list = g_new (gchar*, i + 1);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
495 i = 0;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
496 for (feature=features; feature; feature=feature->next) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
497 string_list[i] = g_strdup(feature->data);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
498 ++i;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
499 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
500 string_list[i] = NULL;
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 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
503 (const gchar**)string_list, i);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
504 g_strfreev (string_list);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
505 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
506 g_list_free (features);
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 forms = g_hash_table_get_keys(c->forms);
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 dataform *d;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
511 GList *form, *fields;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
512 gchar *group;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
513 for (form=forms; form; form=form->next) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
514 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
515 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
516 fields = g_hash_table_get_keys(d->fields);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
517 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
518 GList *field;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
519 GList *values;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
520 for (field=fields; field; field=field->next) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
521 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
522 {
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
523 GList *value;
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
524 gchar **string_list;
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
525 gint i;
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
526 i = g_list_length (values);
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
527 string_list = g_new (gchar*, i + 1);
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
528 i = 0;
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
529 for (value=values; value; value=value->next) {
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
530 string_list[i] = g_strdup(value->data);
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
531 ++i;
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
532 }
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
533 string_list[i] = NULL;
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
534
2001
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
535 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
536 (const gchar**)string_list, i);
2064
01485f807811 Remove trailing space
Mikael Berthe <mikael@lilotux.net>
parents: 2001
diff changeset
537
2001
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
538 g_strfreev (string_list);
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
539 }
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
540 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
541 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
542 g_list_free(fields);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
543 g_free (group);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
544 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
545 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
546 g_list_free (forms);
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 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
549 gchar *data;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
550 gsize length;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
551 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
552 write (fd, data, length);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
553 g_free(data);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
554 close (fd);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
555 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
556
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
557 g_key_file_free(key_file);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
558 caps_copy_exists:
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
559 g_free(file);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
560 caps_copy_return:
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
561 return;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
562 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
563
2001
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
564 /* 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
565 gboolean caps_restore_from_persistent (const char* hash)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
566 {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
567 gchar *file;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
568 GKeyFile *key_file;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
569 gchar **groups, **group;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
570 gboolean restored = FALSE;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
571
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
572 file = caps_get_filename (hash);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
573 if (!file)
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
574 goto caps_restore_no_file;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
575
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
576 key_file = g_key_file_new ();
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
577 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
578 goto caps_restore_bad_file;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
579
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
580 caps_add(hash);
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 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
583 for (group = groups; *group; ++group) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
584 if (!g_strcmp0(*group, "features")) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
585 gchar **features, **feature;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
586 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
587 NULL, NULL);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
588 for (feature = features; *feature; ++feature) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
589 caps_add_feature(hash, *feature);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
590 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
591
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
592 g_strfreev (features);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
593 } else if (g_str_has_prefix (*group, "identity_")) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
594 gchar *category, *type, *name, *lang;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
595
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
596 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
597 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
598 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
599 lang = *group + 9; /* "identity_" */
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
600
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
601 caps_add_identity(hash, category, name, type, lang);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
602 g_free(category);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
603 g_free(type);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
604 g_free(name);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
605 } else if (g_str_has_prefix (*group, "form_")) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
606 gchar *formtype;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
607 gchar **fields, **field;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
608 formtype = *group + 5; /* "form_" */
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
609 caps_add_dataform (hash, formtype);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
610
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
611 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
612 for (field = fields; *field; ++field) {
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
613 gchar **values, **value;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
614 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
615 NULL, NULL);
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
616 for (value = values; *value; ++value) {
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
617 caps_add_dataform_field (hash, formtype, *field, *value);
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
618 }
76d7c5721210 Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents: 1999
diff changeset
619 g_strfreev (values);
1999
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
620 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
621 g_strfreev (fields);
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 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
624 g_strfreev(groups);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
625 restored = TRUE;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
626
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
627 caps_restore_bad_file:
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
628 g_key_file_free (key_file);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
629 g_free (file);
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
630 caps_restore_no_file:
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
631 return restored;
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
632 }
51f032d5ca22 Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents: 1877
diff changeset
633
1811
e6d355e50d7a Update Vim modelines
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
634 /* vim: set expandtab cindent cinoptions=>2\:2(0 sw=2 ts=2: For Vim users... */