+
+ return ret;
+}
+
+static gboolean remove_file(const char *service_id, const char *file)
+{
+ gchar *pathname;
+ gboolean ret = FALSE;
+
+ pathname = g_strdup_printf("%s/%s/%s", STORAGEDIR, service_id, file);
+ if(pathname == NULL)
+ return FALSE;
+
+ if (g_file_test(pathname, G_FILE_TEST_EXISTS) == FALSE) {
+ ret = TRUE;
+ } else if (g_file_test(pathname, G_FILE_TEST_IS_REGULAR) == TRUE) {
+ unlink(pathname);
+ ret = TRUE;
+ }
+
+ g_free(pathname);
+ return ret;
+}
+
+static gboolean remove_dir(const char *service_id)
+{
+ gchar *pathname;
+ gboolean ret = FALSE;
+
+ pathname = g_strdup_printf("%s/%s", STORAGEDIR, service_id);
+ if(pathname == NULL)
+ return FALSE;
+
+ if (g_file_test(pathname, G_FILE_TEST_EXISTS) == FALSE) {
+ ret = TRUE;
+ } else if (g_file_test(pathname, G_FILE_TEST_IS_DIR) == TRUE) {
+ rmdir(pathname);
+ ret = TRUE;
+ }
+
+ g_free(pathname);
+ return ret;
+}
+
+gboolean __connman_storage_remove_service(const char *service_id)
+{
+ gboolean removed;
+
+ /* Remove service configuration file */
+ removed = remove_file(service_id, SETTINGS);
+ if (removed == FALSE)
+ return FALSE;
+
+ /* Remove the statistics file also */
+ removed = remove_file(service_id, "data");
+ if (removed == FALSE)
+ return FALSE;
+
+ removed = remove_dir(service_id);
+ if (removed == FALSE)
+ return FALSE;
+
+ DBG("Removed service dir %s/%s", STORAGEDIR, service_id);
+
+ return TRUE;
+}
+
+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);
+}
+
+gchar **__connman_storage_get_providers(void)
+{
+ GSList *list = NULL;
+ int num = 0, i = 0;
+ struct dirent *d;
+ gchar *str;
+ DIR *dir;
+ struct stat buf;
+ int ret;
+ char **providers;
+ GSList *iter;
+
+ dir = opendir(STORAGEDIR);
+ if (dir == NULL)
+ return NULL;
+
+ while ((d = readdir(dir))) {
+ if (strcmp(d->d_name, ".") == 0 ||
+ strcmp(d->d_name, "..") == 0 ||
+ strncmp(d->d_name, "provider_", 9) != 0)
+ continue;
+
+ if (d->d_type == DT_DIR) {
+ str = g_strdup_printf("%s/%s/settings", STORAGEDIR,
+ d->d_name);
+ ret = stat(str, &buf);
+ g_free(str);
+ if (ret < 0)
+ continue;
+ list = g_slist_prepend(list, g_strdup(d->d_name));
+ num += 1;
+ }
+ }
+
+ closedir(dir);
+
+ providers = g_try_new0(char *, num + 1);
+ for (iter = list; iter != NULL; iter = g_slist_next(iter)) {
+ if (providers != NULL)
+ providers[i] = iter->data;
+ else
+ g_free(iter->data);
+ i += 1;
+ }
+ g_slist_free(list);
+
+ return providers;