Mercurial > ~mikael > mcabber > hg
comparison mcabber/mcabber/settings.c @ 1768:d80a9e32ab1a
Refuse to replace existing guards
* Settings_set_guard returns success status
* API v3
* Min API v3
author | Myhailo Danylenko <isbear@ukrpost.net> |
---|---|
date | Sat, 13 Mar 2010 20:09:14 +0200 |
parents | 15e1f3957786 |
children | 58d1390f28ca |
comparison
equal
deleted
inserted
replaced
1767:0e7fe154ab76 | 1768:d80a9e32ab1a |
---|---|
49 guint pgp_disabled; /* If TRUE, PGP is disabled for outgoing messages */ | 49 guint pgp_disabled; /* If TRUE, PGP is disabled for outgoing messages */ |
50 guint pgp_force; /* If TRUE, PGP is used w/o negotiation */ | 50 guint pgp_force; /* If TRUE, PGP is used w/o negotiation */ |
51 } T_pgpopt; | 51 } T_pgpopt; |
52 #endif | 52 #endif |
53 | 53 |
54 typedef struct { | |
55 settings_guard_t guard; | |
56 } installed_guard_t; | |
57 | |
54 #ifdef HAVE_LIBOTR | 58 #ifdef HAVE_LIBOTR |
55 static GHashTable *otrpolicy; | 59 static GHashTable *otrpolicy; |
56 static enum otr_policy default_policy; | 60 static enum otr_policy default_policy; |
57 #endif | 61 #endif |
58 | 62 |
72 void settings_init(void) | 76 void settings_init(void) |
73 { | 77 { |
74 option = g_hash_table_new_full(&g_str_hash, &g_str_equal, &g_free, &g_free); | 78 option = g_hash_table_new_full(&g_str_hash, &g_str_equal, &g_free, &g_free); |
75 alias = g_hash_table_new_full(&g_str_hash, &g_str_equal, &g_free, &g_free); | 79 alias = g_hash_table_new_full(&g_str_hash, &g_str_equal, &g_free, &g_free); |
76 binding = g_hash_table_new_full(&g_str_hash, &g_str_equal, &g_free, &g_free); | 80 binding = g_hash_table_new_full(&g_str_hash, &g_str_equal, &g_free, &g_free); |
77 guards = g_hash_table_new_full(&g_str_hash, &g_str_equal, &g_free, NULL); | 81 guards = g_hash_table_new_full(&g_str_hash, &g_str_equal, &g_free, &g_free); |
78 #ifdef HAVE_GPGME | 82 #ifdef HAVE_GPGME |
79 pgpopt = g_hash_table_new(&g_str_hash, &g_str_equal); | 83 pgpopt = g_hash_table_new(&g_str_hash, &g_str_equal); |
80 #endif | 84 #endif |
81 #ifdef HAVE_LIBOTR | 85 #ifdef HAVE_LIBOTR |
82 otrpolicy = g_hash_table_new(&g_str_hash, &g_str_equal); | 86 otrpolicy = g_hash_table_new(&g_str_hash, &g_str_equal); |
297 } | 301 } |
298 *pval = g_strndup(val, t+1-val); | 302 *pval = g_strndup(val, t+1-val); |
299 return TRUE; | 303 return TRUE; |
300 } | 304 } |
301 | 305 |
302 void settings_set_guard(const gchar *key, settings_guard_t guard) | 306 gboolean settings_set_guard(const gchar *key, settings_guard_t guard) |
303 { | 307 { |
304 if (!guard) | 308 if (!guard) |
305 g_hash_table_remove(guards, key); | 309 g_hash_table_remove(guards, key); |
306 else | 310 else { |
307 g_hash_table_insert(guards, g_strdup(key), (gpointer)guard); | 311 installed_guard_t *iguard = g_hash_table_lookup(guards, key); |
312 if (iguard) | |
313 return FALSE; | |
314 iguard = g_new(installed_guard_t, 1); | |
315 iguard->guard = guard; | |
316 g_hash_table_insert(guards, g_strdup(key), iguard); | |
317 } | |
318 return TRUE; | |
308 } | 319 } |
309 | 320 |
310 void settings_del_guard(const gchar *key) | 321 void settings_del_guard(const gchar *key) |
311 { | 322 { |
312 settings_set_guard(key, NULL); | 323 settings_set_guard(key, NULL); |
325 GHashTable *hash; | 336 GHashTable *hash; |
326 gchar *dup_value = NULL; | 337 gchar *dup_value = NULL; |
327 settings_guard_t guard = NULL; | 338 settings_guard_t guard = NULL; |
328 | 339 |
329 if (type == SETTINGS_TYPE_OPTION) { | 340 if (type == SETTINGS_TYPE_OPTION) { |
330 guard = (settings_guard_t)g_hash_table_lookup(guards, key); | 341 installed_guard_t *guard = g_hash_table_lookup(guards, key); |
331 if (guard) | 342 if (guard) |
332 dup_value = guard(key, value); | 343 dup_value = guard->guard(key, value); |
333 } | 344 } |
334 | 345 |
335 hash = get_hash(type); | 346 hash = get_hash(type); |
336 if (!hash) | 347 if (!hash) |
337 return; | 348 return; |