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 if (element->type == CONNMAN_ELEMENT_TYPE_NETWORK)
52 element->remember = g_key_file_get_boolean(keyfile,
53 element->path, "Remember", NULL);
55 value = g_key_file_get_string(keyfile, element->path,
56 "WiFi.Security", NULL);
58 connman_element_set_property(element,
59 CONNMAN_PROPERTY_ID_WIFI_SECURITY, &value);
61 value = g_key_file_get_string(keyfile, element->path,
62 "WiFi.Passphrase", NULL);
64 connman_element_set_property(element,
65 CONNMAN_PROPERTY_ID_WIFI_PASSPHRASE, &value);
70 int __connman_element_load(struct connman_element *element)
73 gchar *pathname, *data = NULL;
76 DBG("element %p name %s", element, element->name);
78 pathname = g_strdup_printf("%s/elements.conf", STORAGEDIR);
82 keyfile = g_key_file_new();
84 if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE) {
91 if (g_key_file_load_from_data(keyfile, data, length,
99 do_load(keyfile, element);
101 g_key_file_free(keyfile);
106 static void do_update(GKeyFile *keyfile, struct connman_element *element)
112 DBG("element %p name %s", element, element->name);
114 g_key_file_set_string(keyfile, element->path, "Name", element->name);
116 str = __connman_element_policy2string(element->policy);
118 g_key_file_set_string(keyfile, element->path, "Policy", str);
120 //g_key_file_set_boolean(keyfile, element->path, "Enabled",
121 // element->enabled);
123 if (element->type == CONNMAN_ELEMENT_TYPE_NETWORK)
124 g_key_file_set_boolean(keyfile, element->path, "Remember",
127 __connman_element_lock(element);
129 for (list = element->properties; list; list = list->next) {
130 struct connman_property *property = list->data;
132 if (property->flags & CONNMAN_PROPERTY_FLAG_STATIC)
135 if (property->flags & CONNMAN_PROPERTY_FLAG_REFERENCE)
138 if (property->type == DBUS_TYPE_STRING)
139 g_key_file_set_string(keyfile, element->path,
140 property->name, property->value);
143 __connman_element_unlock(element);
145 if (connman_element_get_value(element,
146 CONNMAN_PROPERTY_ID_WIFI_SECURITY, &value) == 0)
147 g_key_file_set_string(keyfile, element->path,
148 "WiFi.Security", value);
150 if (connman_element_get_value(element,
151 CONNMAN_PROPERTY_ID_WIFI_PASSPHRASE, &value) == 0)
152 g_key_file_set_string(keyfile, element->path,
153 "WiFi.Passphrase", value);
156 int __connman_element_store(struct connman_element *element)
159 gchar *pathname, *data = NULL;
162 DBG("element %p name %s", element, element->name);
164 if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE &&
165 element->type != CONNMAN_ELEMENT_TYPE_NETWORK)
168 if (element->subtype == CONNMAN_ELEMENT_SUBTYPE_FAKE)
171 pathname = g_strdup_printf("%s/elements.conf", STORAGEDIR);
172 if (pathname == NULL)
175 keyfile = g_key_file_new();
177 if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE)
181 if (g_key_file_load_from_data(keyfile, data, length,
189 do_update(keyfile, element);
191 data = g_key_file_to_data(keyfile, &length, NULL);
193 g_file_set_contents(pathname, data, length, NULL);
198 g_key_file_free(keyfile);