storage: Load and save functions for providers
authorPatrik Flykt <patrik.flykt@linux.intel.com>
Mon, 31 Oct 2011 13:31:36 +0000 (15:31 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Mon, 7 Nov 2011 16:40:08 +0000 (17:40 +0100)
src/connman.h
src/storage.c

index 3871a4b..a3f9285 100644 (file)
@@ -157,6 +157,8 @@ void __connman_storage_delete_config(const char *ident);
 
 GKeyFile *__connman_storage_open_service(const char *ident);
 void __connman_storage_save_service(GKeyFile *keyfile, const char *ident);
+GKeyFile *__connman_storage_load_provider(const char *identifier);
+void __connman_storage_save_provider(GKeyFile *keyfile, const char *identifier);
 
 int __connman_detect_init(void);
 void __connman_detect_cleanup(void);
index 0854ed4..1d14e13 100644 (file)
@@ -290,6 +290,44 @@ void __connman_storage_save_service(GKeyFile *keyfile, const char *service_id)
        g_free(pathname);
 }
 
+GKeyFile *__connman_storage_load_provider(const char *identifier)
+{
+       gchar *pathname;
+       GKeyFile *keyfile;
+
+       pathname = g_strdup_printf("%s/%s_%s/%s", STORAGEDIR, "provider",
+                       identifier, SETTINGS);
+       if (pathname == NULL)
+               return NULL;
+
+       keyfile = storage_load(pathname);
+       g_free(pathname);
+
+       return keyfile;
+}
+
+void __connman_storage_save_provider(GKeyFile *keyfile, const char *identifier)
+{
+       gchar *pathname, *dirname;
+
+       dirname = g_strdup_printf("%s/%s_%s", STORAGEDIR,
+                       "provider", identifier);
+       if (dirname == NULL)
+               return;
+
+       if (g_file_test(dirname, G_FILE_TEST_IS_DIR) == FALSE &&
+                       mkdir(dirname, MODE) < 0) {
+               g_free(dirname);
+               return;
+       }
+
+       pathname = g_strdup_printf("%s/%s", dirname, SETTINGS);
+       g_free(dirname);
+
+       storage_save(keyfile, pathname);
+       g_free(pathname);
+}
+
 /*
  * This function migrates keys from default.profile to settings file.
  * This can be removed once the migration is over.