From f4daef01c5d68523e9a58ab489b085714e877bc8 Mon Sep 17 00:00:00 2001 From: Patrik Flykt Date: Mon, 31 Oct 2011 15:31:36 +0200 Subject: [PATCH] storage: Load and save functions for providers --- src/connman.h | 2 ++ src/storage.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/connman.h b/src/connman.h index 3871a4b..a3f9285 100644 --- a/src/connman.h +++ b/src/connman.h @@ -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); diff --git a/src/storage.c b/src/storage.c index 0854ed4..1d14e13 100644 --- a/src/storage.c +++ b/src/storage.c @@ -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. -- 2.7.4