Mercurial > hg
annotate mcabber/mcabber/caps.c @ 2019:33483d3324cf
s/Copyrigth/Copyright/ and so on
author | Myhailo Danylenko <isbear@ukrpost.net> |
---|---|
date | Sat, 28 Jul 2012 22:10:10 +0300 |
parents | 76d7c5721210 |
children | 01485f807811 |
rev | line source |
---|---|
1600 | 1 /* |
2 * caps.c -- Entity Capabilities Cache for mcabber | |
3 * | |
1872 | 4 * Copyright (C) 2008-2010 Frank Zschockelt <mcabber@freakysoft.de> |
1600 | 5 * |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or (at | |
9 * your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, but | |
12 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
19 * USA | |
20 */ | |
21 | |
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 | 30 |
31 typedef struct { | |
32 char *category; | |
1999
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
33 char *type; |
1600 | 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 | 43 GHashTable *features; |
1999
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
44 GHashTable *forms; |
1600 | 45 } caps; |
46 | |
47 static GHashTable *caps_cache = NULL; | |
48 | |
49 void caps_destroy(gpointer data) | |
50 { | |
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 | 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 | 55 g_free(c); |
56 } | |
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 | 81 void caps_init(void) |
82 { | |
83 if (!caps_cache) | |
84 caps_cache = g_hash_table_new_full(g_str_hash, g_str_equal, | |
85 g_free, caps_destroy); | |
86 } | |
87 | |
88 void caps_free(void) | |
89 { | |
90 if (caps_cache) { | |
91 g_hash_table_destroy(caps_cache); | |
92 caps_cache = NULL; | |
93 } | |
94 } | |
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 | 97 { |
98 if (!hash) | |
99 return; | |
100 caps *c = g_new0(caps, 1); | |
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); |
1600 | 104 g_hash_table_insert(caps_cache, g_strdup(hash), c); |
105 } | |
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 | 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 | 168 } |
169 | |
170 void caps_set_identity(char *hash, | |
171 const char *category, | |
172 const char *name, | |
173 const char *type) | |
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 | 180 caps *c; |
1999
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
181 if (!formtype) |
1600 | 182 return; |
183 c = g_hash_table_lookup(caps_cache, hash); | |
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 | 190 } |
191 } | |
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 | 225 { |
226 caps *c; | |
1872 | 227 if (!hash || !feature) |
1600 | 228 return; |
229 c = g_hash_table_lookup(caps_cache, hash); | |
230 if (c) { | |
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 | 233 } |
234 } | |
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 | 240 { |
1999
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
241 caps *c = NULL; |
1872 | 242 if (!hash || !feature) |
1600 | 243 return 0; |
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 | 250 if (c) |
251 return (g_hash_table_lookup(c->features, feature) != NULL); | |
252 return 0; | |
253 } | |
254 | |
255 static GFunc _foreach_function; | |
256 | |
257 void _caps_foreach_helper(gpointer key, gpointer value, gpointer user_data) | |
258 { | |
259 // GFunc func = (GFunc)user_data; | |
260 _foreach_function(value, user_data); | |
261 } | |
262 | |
263 void caps_foreach_feature(const char *hash, GFunc func, gpointer user_data) | |
264 { | |
265 caps *c; | |
266 if (!hash) | |
267 return; | |
268 c = g_hash_table_lookup(caps_cache, hash); | |
269 if (!c) | |
270 return; | |
271 _foreach_function = func; | |
272 g_hash_table_foreach(c->features, _caps_foreach_helper, user_data); | |
273 } | |
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 | 276 const char *caps_generate(void) |
277 { | |
1999
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
278 GList *features, *langs; |
1600 | 279 GChecksum *sha1; |
280 guint8 digest[20]; | |
281 gsize digest_size = 20; | |
282 gchar *hash, *old_hash = NULL; | |
283 caps *old_caps; | |
284 caps *c = g_hash_table_lookup(caps_cache, ""); | |
285 | |
286 g_hash_table_steal(caps_cache, ""); | |
287 sha1 = g_checksum_new(G_CHECKSUM_SHA1); | |
1999
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
288 |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
289 langs = g_hash_table_get_keys(c->identities); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
290 langs = g_list_sort(langs, _strcmp_sort); |
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 identity *i; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
293 GList *lang; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
294 char *identity_S; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
295 for (lang=langs; lang; lang=lang->next) { |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
296 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
|
297 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
|
298 (char *)lang->data, i->name ? i->name : ""); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
299 g_checksum_update(sha1, (guchar *)identity_S, -1); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
300 g_free(identity_S); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
301 } |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
302 } |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
303 g_list_free(langs); |
1600 | 304 |
1662
63ebb1d32c7d
Fix for entity capabilities hash generation.
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1645
diff
changeset
|
305 features = g_hash_table_get_values(c->features); |
1600 | 306 features = g_list_sort(features, _strcmp_sort); |
1662
63ebb1d32c7d
Fix for entity capabilities hash generation.
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1645
diff
changeset
|
307 { |
63ebb1d32c7d
Fix for entity capabilities hash generation.
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1645
diff
changeset
|
308 GList *feature; |
63ebb1d32c7d
Fix for entity capabilities hash generation.
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1645
diff
changeset
|
309 for (feature=features; feature; feature=feature->next) { |
63ebb1d32c7d
Fix for entity capabilities hash generation.
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1645
diff
changeset
|
310 g_checksum_update(sha1, feature->data, -1); |
63ebb1d32c7d
Fix for entity capabilities hash generation.
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1645
diff
changeset
|
311 g_checksum_update(sha1, (guchar *)"<", -1); |
63ebb1d32c7d
Fix for entity capabilities hash generation.
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1645
diff
changeset
|
312 } |
1600 | 313 } |
314 g_list_free(features); | |
315 | |
316 g_checksum_get_digest(sha1, digest, &digest_size); | |
317 hash = g_base64_encode(digest, digest_size); | |
318 g_checksum_free(sha1); | |
319 g_hash_table_lookup_extended(caps_cache, hash, | |
320 (gpointer *)&old_hash, (gpointer *)&old_caps); | |
321 g_hash_table_insert(caps_cache, hash, c); | |
322 if (old_hash) | |
323 return old_hash; | |
324 else | |
325 return hash; | |
326 } | |
327 | |
1999
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
328 gboolean caps_verify(const char *hash, char *function) |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
329 { |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
330 GList *features, *langs, *forms; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
331 GChecksum *checksum; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
332 guint8 digest[20]; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
333 gsize digest_size = 20; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
334 gchar *local_hash; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
335 gboolean match = FALSE; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
336 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
|
337 |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
338 if (!g_strcmp0(function, "sha-1")) { |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
339 checksum = g_checksum_new(G_CHECKSUM_SHA1); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
340 } else if (!g_strcmp0(function, "md5")) { |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
341 checksum = g_checksum_new(G_CHECKSUM_MD5); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
342 digest_size = 16; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
343 } else |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
344 return FALSE; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
345 |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
346 langs = g_hash_table_get_keys(c->identities); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
347 langs = g_list_sort(langs, _strcmp_sort); |
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 identity *i; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
350 GList *lang; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
351 char *identity_S; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
352 for (lang=langs; lang; lang=lang->next) { |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
353 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
|
354 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
|
355 (char *)lang->data, i->name ? i->name : ""); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
356 g_checksum_update(checksum, (guchar *)identity_S, -1); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
357 g_free(identity_S); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
358 } |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
359 } |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
360 g_list_free(langs); |
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 features = g_hash_table_get_values(c->features); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
363 features = g_list_sort(features, _strcmp_sort); |
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 GList *feature; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
366 for (feature=features; feature; feature=feature->next) { |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
367 g_checksum_update(checksum, feature->data, -1); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
368 g_checksum_update(checksum, (guchar *)"<", -1); |
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 } |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
371 g_list_free(features); |
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 forms = g_hash_table_get_keys(c->forms); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
374 forms = g_list_sort(forms, _strcmp_sort); |
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 dataform *d; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
377 GList *form, *fields; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
378 for (form=forms; form; form=form->next) { |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
379 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
|
380 g_checksum_update(checksum, form->data, -1); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
381 g_checksum_update(checksum, (guchar *)"<", -1); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
382 fields = g_hash_table_get_keys(d->fields); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
383 fields = g_list_sort(fields, _strcmp_sort); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
384 { |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
385 GList *field; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
386 GList *values; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
387 for (field=fields; field; field=field->next) { |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
388 g_checksum_update(checksum, field->data, -1); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
389 g_checksum_update(checksum, (guchar *)"<", -1); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
390 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
|
391 { |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
392 GList *value; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
393 for (value=values; value; value=value->next) { |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
394 g_checksum_update(checksum, value->data, -1); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
395 g_checksum_update(checksum, (guchar *)"<", -1); |
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 } |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
398 } |
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 g_list_free(fields); |
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(forms); |
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_checksum_get_digest(checksum, digest, &digest_size); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
406 local_hash = g_base64_encode(digest, digest_size); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
407 g_checksum_free(checksum); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
408 |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
409 match = !g_strcmp0(hash, local_hash); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
410 |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
411 g_free(local_hash); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
412 return match; |
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 |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
415 static gchar* caps_get_filename(const char* hash) |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
416 { |
2001
76d7c5721210
Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents:
1999
diff
changeset
|
417 gchar *hash_fs; |
1999
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
418 gchar *dir = (gchar *) settings_opt_get ("caps_directory"); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
419 gchar *file = NULL; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
420 |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
421 if (!dir) |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
422 goto caps_filename_return; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
423 |
2001
76d7c5721210
Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents:
1999
diff
changeset
|
424 hash_fs = g_strdup (hash); |
1999
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 const gchar *valid_fs = |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
427 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+="; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
428 g_strcanon(hash_fs, valid_fs, '-'); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
429 } |
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 dir = expand_filename (dir); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
432 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
|
433 g_free(dir); |
2001
76d7c5721210
Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents:
1999
diff
changeset
|
434 g_free(hash_fs); |
1999
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 caps_filename_return: |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
437 return file; |
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 |
2001
76d7c5721210
Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents:
1999
diff
changeset
|
440 /* 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
|
441 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
|
442 { |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
443 gchar *file; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
444 GList *features, *langs, *forms; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
445 GKeyFile *key_file; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
446 caps *c; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
447 int fd; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
448 |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
449 g_free (xml); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
450 |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
451 c = g_hash_table_lookup (caps_cache, hash); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
452 if (!c) |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
453 goto caps_copy_return; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
454 |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
455 file = caps_get_filename (hash); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
456 if (!file) |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
457 goto caps_copy_return; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
458 |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
459 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
|
460 if (fd == -1) |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
461 goto caps_copy_exists; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
462 |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
463 key_file = g_key_file_new (); |
2001
76d7c5721210
Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents:
1999
diff
changeset
|
464 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
|
465 "This is autogenerated file. Please do not modify.", |
76d7c5721210
Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents:
1999
diff
changeset
|
466 NULL); |
1999
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 langs = g_hash_table_get_keys (c->identities); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
469 { |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
470 identity *i; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
471 GList *lang; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
472 gchar *group; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
473 for (lang=langs; lang; lang=lang->next) { |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
474 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
|
475 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
|
476 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
|
477 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
|
478 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
|
479 g_free (group); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
480 } |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
481 } |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
482 g_list_free (langs); |
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 features = g_hash_table_get_values (c->features); |
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 GList *feature; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
487 gchar **string_list; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
488 gint i; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
489 |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
490 i = g_list_length (features); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
491 string_list = g_new (gchar*, i + 1); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
492 i = 0; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
493 for (feature=features; feature; feature=feature->next) { |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
494 string_list[i] = g_strdup(feature->data); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
495 ++i; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
496 } |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
497 string_list[i] = NULL; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
498 |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
499 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
|
500 (const gchar**)string_list, i); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
501 g_strfreev (string_list); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
502 } |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
503 g_list_free (features); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
504 |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
505 forms = g_hash_table_get_keys(c->forms); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
506 { |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
507 dataform *d; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
508 GList *form, *fields; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
509 gchar *group; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
510 for (form=forms; form; form=form->next) { |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
511 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
|
512 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
|
513 fields = g_hash_table_get_keys(d->fields); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
514 { |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
515 GList *field; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
516 GList *values; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
517 for (field=fields; field; field=field->next) { |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
518 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
|
519 { |
76d7c5721210
Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents:
1999
diff
changeset
|
520 GList *value; |
76d7c5721210
Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents:
1999
diff
changeset
|
521 gchar **string_list; |
76d7c5721210
Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents:
1999
diff
changeset
|
522 gint i; |
76d7c5721210
Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents:
1999
diff
changeset
|
523 i = g_list_length (values); |
76d7c5721210
Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents:
1999
diff
changeset
|
524 string_list = g_new (gchar*, i + 1); |
76d7c5721210
Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents:
1999
diff
changeset
|
525 i = 0; |
76d7c5721210
Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents:
1999
diff
changeset
|
526 for (value=values; value; value=value->next) { |
76d7c5721210
Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents:
1999
diff
changeset
|
527 string_list[i] = g_strdup(value->data); |
76d7c5721210
Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents:
1999
diff
changeset
|
528 ++i; |
76d7c5721210
Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents:
1999
diff
changeset
|
529 } |
76d7c5721210
Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents:
1999
diff
changeset
|
530 string_list[i] = NULL; |
1999
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
531 |
2001
76d7c5721210
Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents:
1999
diff
changeset
|
532 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
|
533 (const gchar**)string_list, 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 g_strfreev (string_list); |
76d7c5721210
Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents:
1999
diff
changeset
|
536 } |
1999
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
537 } |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
538 } |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
539 g_list_free(fields); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
540 g_free (group); |
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 } |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
543 g_list_free (forms); |
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 gchar *data; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
547 gsize length; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
548 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
|
549 write (fd, data, length); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
550 g_free(data); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
551 close (fd); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
552 } |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
553 |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
554 g_key_file_free(key_file); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
555 caps_copy_exists: |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
556 g_free(file); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
557 caps_copy_return: |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
558 return; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
559 } |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
560 |
2001
76d7c5721210
Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents:
1999
diff
changeset
|
561 /* 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
|
562 gboolean caps_restore_from_persistent (const char* hash) |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
563 { |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
564 gchar *file; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
565 GKeyFile *key_file; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
566 gchar **groups, **group; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
567 gboolean restored = FALSE; |
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 file = caps_get_filename (hash); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
570 if (!file) |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
571 goto caps_restore_no_file; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
572 |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
573 key_file = g_key_file_new (); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
574 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
|
575 goto caps_restore_bad_file; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
576 |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
577 caps_add(hash); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
578 |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
579 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
|
580 for (group = groups; *group; ++group) { |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
581 if (!g_strcmp0(*group, "features")) { |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
582 gchar **features, **feature; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
583 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
|
584 NULL, NULL); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
585 for (feature = features; *feature; ++feature) { |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
586 caps_add_feature(hash, *feature); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
587 } |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
588 |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
589 g_strfreev (features); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
590 } else if (g_str_has_prefix (*group, "identity_")) { |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
591 gchar *category, *type, *name, *lang; |
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 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
|
594 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
|
595 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
|
596 lang = *group + 9; /* "identity_" */ |
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 caps_add_identity(hash, category, name, type, lang); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
599 g_free(category); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
600 g_free(type); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
601 g_free(name); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
602 } else if (g_str_has_prefix (*group, "form_")) { |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
603 gchar *formtype; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
604 gchar **fields, **field; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
605 formtype = *group + 5; /* "form_" */ |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
606 caps_add_dataform (hash, formtype); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
607 |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
608 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
|
609 for (field = fields; *field; ++field) { |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
610 gchar **values, **value; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
611 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
|
612 NULL, NULL); |
76d7c5721210
Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents:
1999
diff
changeset
|
613 for (value = values; *value; ++value) { |
76d7c5721210
Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents:
1999
diff
changeset
|
614 caps_add_dataform_field (hash, formtype, *field, *value); |
76d7c5721210
Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents:
1999
diff
changeset
|
615 } |
76d7c5721210
Remove dependency on newer glib. Caps.c comments, whitespace cleanup.
Hermitifier
parents:
1999
diff
changeset
|
616 g_strfreev (values); |
1999
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
617 } |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
618 g_strfreev (fields); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
619 } |
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(groups); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
622 restored = TRUE; |
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 caps_restore_bad_file: |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
625 g_key_file_free (key_file); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
626 g_free (file); |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
627 caps_restore_no_file: |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
628 return restored; |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
629 } |
51f032d5ca22
Add support for XEP-0115 Entity Capabilities, with offline cache
Hermitifier
parents:
1877
diff
changeset
|
630 |
1811 | 631 /* vim: set expandtab cindent cinoptions=>2\:2(0 sw=2 ts=2: For Vim users... */ |