5 * Copyright (C) 2007-2008 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
28 int __connman_storage_init(void)
35 void __connman_storage_cleanup(void)
40 static int do_load(GKeyFile *keyfile, struct connman_element *element)
44 DBG("element %p name %s", element, element->name);
46 value = g_key_file_get_string(keyfile, element->path,
47 "WiFi.Security", NULL);
49 connman_element_set_property(element,
50 CONNMAN_PROPERTY_ID_WIFI_SECURITY, &value);
52 value = g_key_file_get_string(keyfile, element->path,
53 "WiFi.Passphrase", NULL);
55 connman_element_set_property(element,
56 CONNMAN_PROPERTY_ID_WIFI_PASSPHRASE, &value);
61 int __connman_element_load(struct connman_element *element)
64 gchar *pathname, *data = NULL;
67 DBG("element %p name %s", element, element->name);
69 pathname = g_strdup_printf("%s/elements.conf", STORAGEDIR);
73 keyfile = g_key_file_new();
75 if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE) {
82 if (g_key_file_load_from_data(keyfile, data, length,
90 do_load(keyfile, element);
92 g_key_file_free(keyfile);
97 static void do_update(GKeyFile *keyfile, struct connman_element *element)
102 DBG("element %p name %s", element, element->name);
104 g_key_file_set_string(keyfile, element->path, "Name", element->name);
106 g_key_file_set_boolean(keyfile, element->path, "Enabled",
109 connman_element_lock(element);
111 for (list = element->properties; list; list = list->next) {
112 struct connman_property *property = list->data;
114 if (property->flags & CONNMAN_PROPERTY_FLAG_STATIC)
117 if (property->flags & CONNMAN_PROPERTY_FLAG_REFERENCE)
120 if (property->type == DBUS_TYPE_STRING)
121 g_key_file_set_string(keyfile, element->path,
122 property->name, property->value);
125 connman_element_unlock(element);
127 if (connman_element_get_value(element,
128 CONNMAN_PROPERTY_ID_WIFI_SECURITY, &value) == 0)
129 g_key_file_set_string(keyfile, element->path,
130 "WiFi.Security", value);
132 if (connman_element_get_value(element,
133 CONNMAN_PROPERTY_ID_WIFI_PASSPHRASE, &value) == 0)
134 g_key_file_set_string(keyfile, element->path,
135 "WiFi.Passphrase", value);
138 int __connman_element_store(struct connman_element *element)
141 gchar *pathname, *data = NULL;
144 DBG("element %p name %s", element, element->name);
146 if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE &&
147 element->type != CONNMAN_ELEMENT_TYPE_NETWORK)
150 pathname = g_strdup_printf("%s/elements.conf", STORAGEDIR);
151 if (pathname == NULL)
154 keyfile = g_key_file_new();
156 if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE)
160 if (g_key_file_load_from_data(keyfile, data, length,
161 G_KEY_FILE_KEEP_COMMENTS, NULL) == FALSE)
168 do_update(keyfile, element);
170 data = g_key_file_to_data(keyfile, &length, NULL);
172 g_file_set_contents(pathname, data, length, NULL);
177 g_key_file_free(keyfile);