2 * Copyright (C) 2007-2009 Thadeu Lima de Souza Cascardo
3 * <cascardo@holoscopio.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <atompub/atom.h>
25 ghashtable_atom_config_set (AtomCtx *ctx, char *group, char *key,
29 GHashTable *grouptable;
31 table = atom_config_data (atom_config (ctx));
32 if (!g_hash_table_lookup_extended (table, group, NULL,
33 (gpointer *) &grouptable))
35 grouptable = g_hash_table_new_full (g_str_hash, g_str_equal,
37 g_hash_table_replace (table, g_strdup (group), grouptable);
39 g_hash_table_replace (grouptable, g_strdup (key), val);
43 ghashtable_atom_config_set_str (AtomCtx *ctx, char *group, char *key,
46 ghashtable_atom_config_set (ctx, group, key, val);
50 ghashtable_atom_config_get (AtomCtx *ctx, char *group, char *key)
53 GHashTable *grouptable;
55 table = atom_config_data (atom_config (ctx));
56 if (!g_hash_table_lookup_extended (table, group, NULL,
57 (gpointer *) &grouptable))
59 if (!g_hash_table_lookup_extended (grouptable, key, NULL, &value))
65 ghashtable_atom_config_get_str (AtomCtx *ctx, gchar *group, gchar * key)
68 GHashTable *grouptable;
70 value = ghashtable_atom_config_get (ctx, group, key);
73 AtomError *aerr = atom_error_new ();
74 atom_error_code_set (aerr, 500);
75 atom_error_message_set (aerr, "Could not find configuration value");
76 atom_error_set (ctx, aerr);
78 return g_strdup (value);
82 ghashtable_atom_config_init (AtomCtx *ctx)
87 table = g_hash_table_new_full (g_str_hash, g_str_equal,
88 g_free, g_hash_table_destroy);
89 config = atom_config_new ();
90 atom_config_get_str_set (config, ghashtable_atom_config_get_str);
91 atom_config_data_set (config, table);