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,
49 element->policy = __connman_element_string2policy(value);
51 value = g_key_file_get_string(keyfile, element->path,
52 "WiFi.Security", NULL);
54 connman_element_set_property(element,
55 CONNMAN_PROPERTY_ID_WIFI_SECURITY, &value);
57 value = g_key_file_get_string(keyfile, element->path,
58 "WiFi.Passphrase", NULL);
60 connman_element_set_property(element,
61 CONNMAN_PROPERTY_ID_WIFI_PASSPHRASE, &value);
66 int __connman_element_load(struct connman_element *element)
69 gchar *pathname, *data = NULL;
72 DBG("element %p name %s", element, element->name);
74 pathname = g_strdup_printf("%s/elements.conf", STORAGEDIR);
78 keyfile = g_key_file_new();
80 if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE) {
87 if (g_key_file_load_from_data(keyfile, data, length,
95 do_load(keyfile, element);
97 g_key_file_free(keyfile);
102 static void do_update(GKeyFile *keyfile, struct connman_element *element)
108 DBG("element %p name %s", element, element->name);
110 g_key_file_set_string(keyfile, element->path, "Name", element->name);
112 str = __connman_element_policy2string(element->policy);
114 g_key_file_set_string(keyfile, element->path, "Policy", str);
116 //g_key_file_set_boolean(keyfile, element->path, "Enabled",
117 // element->enabled);
119 __connman_element_lock(element);
121 for (list = element->properties; list; list = list->next) {
122 struct connman_property *property = list->data;
124 if (property->flags & CONNMAN_PROPERTY_FLAG_STATIC)
127 if (property->flags & CONNMAN_PROPERTY_FLAG_REFERENCE)
130 if (property->type == DBUS_TYPE_STRING)
131 g_key_file_set_string(keyfile, element->path,
132 property->name, property->value);
135 __connman_element_unlock(element);
137 if (connman_element_get_value(element,
138 CONNMAN_PROPERTY_ID_WIFI_SECURITY, &value) == 0)
139 g_key_file_set_string(keyfile, element->path,
140 "WiFi.Security", value);
142 if (connman_element_get_value(element,
143 CONNMAN_PROPERTY_ID_WIFI_PASSPHRASE, &value) == 0)
144 g_key_file_set_string(keyfile, element->path,
145 "WiFi.Passphrase", value);
148 int __connman_element_store(struct connman_element *element)
151 gchar *pathname, *data = NULL;
154 DBG("element %p name %s", element, element->name);
156 if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE &&
157 element->type != CONNMAN_ELEMENT_TYPE_NETWORK)
160 if (element->subtype == CONNMAN_ELEMENT_SUBTYPE_FAKE ||
161 element->subtype == CONNMAN_ELEMENT_SUBTYPE_NETWORK)
164 pathname = g_strdup_printf("%s/elements.conf", STORAGEDIR);
165 if (pathname == NULL)
168 keyfile = g_key_file_new();
170 if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE)
174 if (g_key_file_load_from_data(keyfile, data, length,
175 G_KEY_FILE_KEEP_COMMENTS, NULL) == FALSE)
182 do_update(keyfile, element);
184 data = g_key_file_to_data(keyfile, &length, NULL);
186 g_file_set_contents(pathname, data, length, NULL);
191 g_key_file_free(keyfile);