storage: Load and save functions for providers
[platform/upstream/connman.git] / src / storage.c
index 1755650..1d14e13 100644 (file)
@@ -204,7 +204,8 @@ gchar **connman_storage_get_services()
 
        while ((d = readdir(dir))) {
                if (strcmp(d->d_name, ".") == 0 ||
-                               strcmp(d->d_name, "..") == 0)
+                               strcmp(d->d_name, "..") == 0 ||
+                               strncmp(d->d_name, "provider_", 9) == 0)
                        continue;
 
                switch (d->d_type) {
@@ -237,7 +238,7 @@ gchar **connman_storage_get_services()
        return services;
 }
 
-GKeyFile *__connman_storage_load_service(const char *service_id)
+GKeyFile *connman_storage_load_service(const char *service_id)
 {
        gchar *pathname;
        GKeyFile *keyfile = NULL;
@@ -247,12 +248,9 @@ GKeyFile *__connman_storage_load_service(const char *service_id)
                return NULL;
 
        keyfile =  storage_load(pathname);
-       if (keyfile) {
-               g_free(pathname);
-               return keyfile;
-       }
-
        g_free(pathname);
+       if (keyfile)
+               return keyfile;
 
        pathname = g_strdup_printf("%s/%s", STORAGEDIR, DEFAULT);
        if(pathname == NULL)
@@ -292,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.