5 * Copyright (C) 2007-2009 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 struct connman_config {
36 static GHashTable *config_hash = NULL;
38 static int load_config(struct connman_config *config)
43 DBG("config %p", config);
45 keyfile = __connman_storage_open_config(config->ident);
49 str = g_key_file_get_string(keyfile, "global", "Name", NULL);
55 str = g_key_file_get_string(keyfile, "global", "Description", NULL);
57 g_free(config->description);
58 config->description = str;
61 __connman_storage_close_config(config->ident, keyfile, FALSE);
66 static void free_config(struct connman_config *config)
68 g_free(config->description);
70 g_free(config->ident);
74 static void unregister_config(gpointer data)
76 struct connman_config *config = data;
78 connman_info("Removing configuration %s", config->ident);
83 static int create_config(const char *ident)
85 struct connman_config *config;
87 DBG("ident %s", ident);
89 config = g_try_new0(struct connman_config, 1);
93 config->ident = g_strdup(ident);
95 if (config->ident == NULL) {
100 if (g_hash_table_lookup(config_hash, config->ident) != NULL) {
105 g_hash_table_insert(config_hash, g_strdup(config->ident), config);
107 connman_info("Adding configuration %s", config->ident);
114 static int config_init(void)
121 dir = g_dir_open(STORAGEDIR, 0, NULL);
123 while ((file = g_dir_read_name(dir)) != NULL) {
127 if (g_str_has_suffix(file, ".config") == FALSE)
130 ident = g_strrstr(file, ".config");
134 str = g_string_new_len(file, ident - file);
138 ident = g_string_free(str, FALSE);
140 if (connman_dbus_validate_ident(ident) == TRUE)
141 create_config(ident);
152 int __connman_config_init(void)
156 config_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
157 g_free, unregister_config);
159 return config_init();
162 void __connman_config_cleanup(void)
166 g_hash_table_destroy(config_hash);
170 int __connman_config_provision_service(struct connman_service *service)
172 DBG("service %p", service);