5 * Copyright (C) 2007-2010 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
31 #define PROFILE_SUFFIX "profile"
32 #define CONFIG_SUFFIX "config"
34 GKeyFile *__connman_storage_open(const char *ident, const char *suffix)
37 gchar *pathname, *data = NULL;
41 DBG("ident %s suffix %s", ident, suffix);
43 pathname = g_strdup_printf("%s/%s.%s", STORAGEDIR, ident, suffix);
47 result = g_file_get_contents(pathname, &data, &length, NULL);
51 keyfile = g_key_file_new();
57 g_key_file_load_from_data(keyfile, data, length, 0, NULL);
62 DBG("keyfile %p", keyfile);
67 void __connman_storage_close(const char *ident, const char *suffix,
68 GKeyFile *keyfile, gboolean save)
70 gchar *pathname, *data = NULL;
73 DBG("ident %s suffix %s keyfile %p save %d",
74 ident, suffix, keyfile, save);
77 g_key_file_free(keyfile);
81 pathname = g_strdup_printf("%s/%s.%s", STORAGEDIR, ident, suffix);
85 data = g_key_file_to_data(keyfile, &length, NULL);
87 if (g_file_set_contents(pathname, data, length, NULL) == FALSE)
88 connman_error("Failed to store information");
94 g_key_file_free(keyfile);
97 void __connman_storage_delete(const char *ident, const char *suffix)
101 DBG("ident %s suffix %s", ident, suffix);
103 pathname = g_strdup_printf("%s/%s.%s", STORAGEDIR, ident, suffix);
104 if (pathname == NULL)
107 if (unlink(pathname) < 0)
108 connman_error("Failed to remove %s", pathname);
111 GKeyFile *__connman_storage_open_profile(const char *ident)
113 return __connman_storage_open(ident, PROFILE_SUFFIX);
116 void __connman_storage_close_profile(const char *ident,
117 GKeyFile *keyfile, gboolean save)
119 __connman_storage_close(ident, PROFILE_SUFFIX, keyfile, save);
122 void __connman_storage_delete_profile(const char *ident)
124 __connman_storage_delete(ident, PROFILE_SUFFIX);
127 GKeyFile *__connman_storage_open_config(const char *ident)
129 return __connman_storage_open(ident, CONFIG_SUFFIX);
132 void __connman_storage_close_config(const char *ident,
133 GKeyFile *keyfile, gboolean save)
135 __connman_storage_close(ident, CONFIG_SUFFIX, keyfile, save);
138 void __connman_storage_delete_config(const char *ident)
140 __connman_storage_delete(ident, CONFIG_SUFFIX);