Add generic suffix handling to storage helpers
authorMarcel Holtmann <marcel@holtmann.org>
Mon, 14 Dec 2009 08:51:31 +0000 (09:51 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Mon, 14 Dec 2009 08:51:31 +0000 (09:51 +0100)
src/connman.h
src/device.c
src/profile.c
src/storage.c

index dcb0aef..451b02e 100644 (file)
@@ -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);
index fde5fd6..cc9bd23 100644 (file)
@@ -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;
 }
index c9c8981..35a2f16 100644 (file)
@@ -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;
 }
index 0472169..e7959aa 100644 (file)
@@ -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;