diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2009-01-04 19:58:06 +0100 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2009-01-04 19:58:06 +0100 |
commit | 44ed8df3ee8197d0cb06a4250cf51484b88e5b5b (patch) | |
tree | affacccda3932bdc49ae2a04823e8a617e090dc0 | |
parent | 625f2806e7d80e99709ef3b1441e8bc1db9dae4e (diff) | |
download | connman-44ed8df3ee8197d0cb06a4250cf51484b88e5b5b.tar.gz connman-44ed8df3ee8197d0cb06a4250cf51484b88e5b5b.tar.bz2 connman-44ed8df3ee8197d0cb06a4250cf51484b88e5b5b.zip |
Add support for device default storage
-rw-r--r-- | src/device.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/device.c b/src/device.c index 5ff4b5a5..e63b8d24 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; } |