From: Marcel Holtmann Date: Sun, 4 Jan 2009 18:58:06 +0000 (+0100) Subject: Add support for device default storage X-Git-Tag: 0.7~88 X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;h=44ed8df3ee8197d0cb06a4250cf51484b88e5b5b;p=connman Add support for device default storage --- diff --git a/src/device.c b/src/device.c index 5ff4b5a..e63b8d2 100644 --- a/src/device.c +++ b/src/device.c @@ -1162,15 +1162,87 @@ static struct connman_driver device_driver = { static int device_load(struct connman_device *device) { + GKeyFile *keyfile; + gchar *pathname, *data = NULL; + gsize length; + const char *str; + DBG("device %p", device); + pathname = g_strdup_printf("%s/%s.conf", STORAGEDIR, + device->element.name); + if (pathname == NULL) + return -ENOMEM; + + keyfile = g_key_file_new(); + + if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE) { + g_free(pathname); + return -ENOENT; + } + + g_free(pathname); + + if (g_key_file_load_from_data(keyfile, data, length, + 0, NULL) == FALSE) { + g_free(data); + return -EILSEQ; + } + + g_free(data); + + str = g_key_file_get_string(keyfile, "Configuration", "Policy", NULL); + if (str != NULL) + device->policy = string2policy(str); + + g_key_file_free(keyfile); + return 0; } static int device_save(struct connman_device *device) { + GKeyFile *keyfile; + gchar *pathname, *data = NULL; + gsize length; + const char *str; + DBG("device %p", device); + pathname = g_strdup_printf("%s/%s.conf", STORAGEDIR, + device->element.name); + if (pathname == NULL) + return -ENOMEM; + + keyfile = g_key_file_new(); + + if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE) + goto update; + + if (length > 0) { + if (g_key_file_load_from_data(keyfile, data, length, + 0, NULL) == FALSE) + goto done; + } + + g_free(data); + +update: + str = policy2string(device->policy); + if (str != NULL) + g_key_file_set_string(keyfile, "Configuration", "Policy", str); + + data = g_key_file_to_data(keyfile, &length, NULL); + + g_file_set_contents(pathname, data, length, NULL); + +done: + g_free(data); + + g_key_file_free(keyfile); + + g_free(pathname); + return 0; }