summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2009-12-14 09:51:31 +0100
committerMarcel Holtmann <marcel@holtmann.org>2009-12-14 09:51:31 +0100
commita4d04d8c7bce8ada5ca7fd8a431de5d29e264fb0 (patch)
treec018d96741caa46049e3d340c217f78b88949baa /src
parent549cf017b031985f2f2966637fbfaac16a3e9a83 (diff)
downloadconnman-a4d04d8c7bce8ada5ca7fd8a431de5d29e264fb0.tar.gz
connman-a4d04d8c7bce8ada5ca7fd8a431de5d29e264fb0.tar.bz2
connman-a4d04d8c7bce8ada5ca7fd8a431de5d29e264fb0.zip
Add generic suffix handling to storage helpers
Diffstat (limited to 'src')
-rw-r--r--src/connman.h11
-rw-r--r--src/device.c8
-rw-r--r--src/profile.c10
-rw-r--r--src/storage.c37
4 files changed, 45 insertions, 21 deletions
diff --git a/src/connman.h b/src/connman.h
index dcb0aef0..451b02ec 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -160,10 +160,15 @@ int __connman_resolver_selftest(void);
int __connman_storage_init(void);
void __connman_storage_cleanup(void);
-GKeyFile *__connman_storage_open(const char *ident);
-void __connman_storage_close(const char *ident,
+GKeyFile *__connman_storage_open(const char *ident, const char *suffix);
+void __connman_storage_close(const char *ident, const char *suffix,
GKeyFile *keyfile, gboolean save);
-void __connman_storage_delete(const char *ident);
+void __connman_storage_delete(const char *ident, const char *suffix);
+
+GKeyFile *__connman_storage_open_profile(const char *ident);
+void __connman_storage_close_profile(const char *ident,
+ GKeyFile *keyfile, gboolean save);
+void __connman_storage_delete_profile(const char *ident);
int __connman_storage_init_profile(void);
int __connman_storage_load_profile(struct connman_profile *profile);
diff --git a/src/device.c b/src/device.c
index fde5fd6d..cc9bd236 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1732,7 +1732,7 @@ static int device_load(struct connman_device *device)
DBG("device %p", device);
- keyfile = __connman_storage_open(ident);
+ keyfile = __connman_storage_open_profile(ident);
if (keyfile == NULL)
return 0;
@@ -1762,7 +1762,7 @@ static int device_load(struct connman_device *device)
done:
g_free(identifier);
- __connman_storage_close(ident, keyfile, FALSE);
+ __connman_storage_close_profile(ident, keyfile, FALSE);
return 0;
}
@@ -1775,7 +1775,7 @@ static int device_save(struct connman_device *device)
DBG("device %p", device);
- keyfile = __connman_storage_open(ident);
+ keyfile = __connman_storage_open_profile(ident);
if (keyfile == NULL)
return 0;
@@ -1800,7 +1800,7 @@ static int device_save(struct connman_device *device)
done:
g_free(identifier);
- __connman_storage_close(ident, keyfile, TRUE);
+ __connman_storage_close_profile(ident, keyfile, TRUE);
return 0;
}
diff --git a/src/profile.c b/src/profile.c
index c9c89815..35a2f16c 100644
--- a/src/profile.c
+++ b/src/profile.c
@@ -535,7 +535,7 @@ int __connman_profile_remove(const char *path)
if (profile == NULL)
return -ENXIO;
- __connman_storage_delete(profile->ident);
+ __connman_storage_delete_profile(profile->ident);
g_hash_table_remove(profile_hash, path);
@@ -596,7 +596,7 @@ static int profile_load(struct connman_profile *profile)
DBG("profile %p", profile);
- keyfile = __connman_storage_open(profile->ident);
+ keyfile = __connman_storage_open_profile(profile->ident);
if (keyfile == NULL)
return -EIO;
@@ -612,7 +612,7 @@ static int profile_load(struct connman_profile *profile)
profile->offlinemode = offlinemode;
g_clear_error(&error);
- __connman_storage_close(profile->ident, keyfile, FALSE);
+ __connman_storage_close_profile(profile->ident, keyfile, FALSE);
return 0;
}
@@ -623,7 +623,7 @@ static int profile_save(struct connman_profile *profile)
DBG("profile %p", profile);
- keyfile = __connman_storage_open(profile->ident);
+ keyfile = __connman_storage_open_profile(profile->ident);
if (keyfile == NULL)
return -EIO;
@@ -634,7 +634,7 @@ static int profile_save(struct connman_profile *profile)
g_key_file_set_boolean(keyfile, "global",
"OfflineMode", profile->offlinemode);
- __connman_storage_close(profile->ident, keyfile, TRUE);
+ __connman_storage_close_profile(profile->ident, keyfile, TRUE);
return 0;
}
diff --git a/src/storage.c b/src/storage.c
index 04721692..e7959aae 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -27,6 +27,8 @@
#include "connman.h"
+#define PROFILE_SUFFIX "profile"
+
static GSList *storage_list = NULL;
static gint compare_priority(gconstpointer a, gconstpointer b)
@@ -68,16 +70,16 @@ void connman_storage_unregister(struct connman_storage *storage)
storage_list = g_slist_remove(storage_list, storage);
}
-GKeyFile *__connman_storage_open(const char *ident)
+GKeyFile *__connman_storage_open(const char *ident, const char *suffix)
{
GKeyFile *keyfile;
gchar *pathname, *data = NULL;
gboolean result;
gsize length;
- DBG("ident %s", ident);
+ DBG("ident %s suffix %s", ident, suffix);
- pathname = g_strdup_printf("%s/%s.profile", STORAGEDIR, ident);
+ pathname = g_strdup_printf("%s/%s.%s", STORAGEDIR, ident, suffix);
if (pathname == NULL)
return NULL;
@@ -101,20 +103,21 @@ done:
return keyfile;
}
-void __connman_storage_close(const char *ident,
+void __connman_storage_close(const char *ident, const char *suffix,
GKeyFile *keyfile, gboolean save)
{
gchar *pathname, *data = NULL;
gsize length = 0;
- DBG("ident %s keyfile %p save %d", ident, keyfile, save);
+ DBG("ident %s suffix %s keyfile %p save %d",
+ ident, suffix, keyfile, save);
if (save == FALSE) {
g_key_file_free(keyfile);
return;
}
- pathname = g_strdup_printf("%s/%s.profile", STORAGEDIR, ident);
+ pathname = g_strdup_printf("%s/%s.%s", STORAGEDIR, ident, suffix);
if (pathname == NULL)
return;
@@ -130,13 +133,13 @@ void __connman_storage_close(const char *ident,
g_key_file_free(keyfile);
}
-void __connman_storage_delete(const char *ident)
+void __connman_storage_delete(const char *ident, const char *suffix)
{
gchar *pathname;
- DBG("ident %s", ident);
+ DBG("ident %s suffix %s", ident, suffix);
- pathname = g_strdup_printf("%s/%s.profile", STORAGEDIR, ident);
+ pathname = g_strdup_printf("%s/%s.%s", STORAGEDIR, ident, suffix);
if (pathname == NULL)
return;
@@ -144,6 +147,22 @@ void __connman_storage_delete(const char *ident)
connman_error("Failed to remove %s", pathname);
}
+GKeyFile *__connman_storage_open_profile(const char *ident)
+{
+ return __connman_storage_open(ident, PROFILE_SUFFIX);
+}
+
+void __connman_storage_close_profile(const char *ident,
+ GKeyFile *keyfile, gboolean save)
+{
+ __connman_storage_close(ident, PROFILE_SUFFIX, keyfile, save);
+}
+
+void __connman_storage_delete_profile(const char *ident)
+{
+ __connman_storage_delete(ident, PROFILE_SUFFIX);
+}
+
int __connman_storage_init_profile(void)
{
GSList *list;