From: Patrik Flykt <[email protected]>
Save 'Type', 'Name', 'Host' and 'VPN.Domain' provider settings.
On load, fetch all saved keys and their values from storage
and add the key/value pairs to the provider struct.
---
src/provider.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 91 insertions(+), 0 deletions(-)
diff --git a/src/provider.c b/src/provider.c
index fc0c9e1..a627fff 100644
--- a/src/provider.c
+++ b/src/provider.c
@@ -943,9 +943,100 @@ static struct connman_notifier provider_notifier = {
.offline_mode = provider_offline_mode,
};
+static int provider_load(struct connman_provider *provider)
+{
+ const char *profile = provider->profile;
+ const char *group = provider->identifier;
+ gsize idx = 0;
+ GKeyFile *keyfile;
+ gchar *pathname, *key, *value;
+ gchar **settings;
+ gsize length;
+
+ DBG("provider %p", provider);
+
+ if (profile == NULL || group == NULL)
+ return -EINVAL;
+
+ pathname = g_strdup_printf("%s/%s.profile", STORAGEDIR, profile);
+ if (pathname == NULL)
+ return -ENOMEM;
+ keyfile = g_key_file_new();
+ if (g_key_file_load_from_file(keyfile, pathname, 0, NULL) == FALSE) {
+ g_free(pathname);
+ g_key_file_free(keyfile);
+ return -ENOENT;
+ }
+ g_free(pathname);
+
+ settings = g_key_file_get_keys(keyfile, group, &length, NULL);
+ if (settings == NULL) {
+ g_key_file_free(keyfile);
+ return -ENOENT;
+ }
+
+ while (idx < length) {
+ key = settings[idx];
+ DBG("found key %s", key);
+ if (key != NULL) {
+ value = g_key_file_get_string(keyfile, group, key,
+ NULL);
+ connman_provider_set_string(provider, key, value);
+ g_free(value);
+ }
+ idx += 1;
+ }
+ g_strfreev(settings);
+
+ g_key_file_free(keyfile);
+ return 0;
+}
+
+static int provider_save(struct connman_provider *provider)
+{
+ const char *profile = provider->profile;
+ const char *group = provider->identifier;
+ gchar *pathname, *data;
+ GKeyFile *keyfile;
+ gsize length;
+
+ DBG("provider %p", provider);
+
+ if (profile == NULL || group == NULL)
+ return -EINVAL;
+
+ pathname = g_strdup_printf("%s/%s.profile", STORAGEDIR, profile);
+ if (pathname == NULL)
+ return -ENOMEM;
+ keyfile = g_key_file_new();
+ if (g_key_file_load_from_file(keyfile, pathname,
+ G_KEY_FILE_KEEP_COMMENTS|
+ G_KEY_FILE_KEEP_TRANSLATIONS
+ , NULL) == FALSE) {
+ g_free(pathname);
+ g_key_file_free(keyfile);
+ return -ENOENT;
+ }
+
+ g_key_file_set_string(keyfile, group, "Name", provider->name);
+ g_key_file_set_string(keyfile, group, "Type", provider->type);
+ g_key_file_set_string(keyfile, group, "Host", provider->host);
+ g_key_file_set_string(keyfile, group, "VPN.Domain", provider->domain);
+
+ data = g_key_file_to_data(keyfile, &length, NULL);
+ if (g_file_set_contents(pathname, data, length, NULL) == FALSE)
+ connman_error("Failed to store provider information");
+ g_free(pathname);
+
+ g_key_file_free(keyfile);
+ return 0;
+}
+
static struct connman_storage provider_storage = {
.name = "provider",
.priority = CONNMAN_STORAGE_PRIORITY_LOW,
+ .provider_save = provider_save,
+ .provider_load = provider_load,
};
int __connman_provider_init(void)
--
1.7.2.5
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman