void __connman_storage_save_config(GKeyFile *keyfile, const char *ident);
void __connman_storage_delete_config(const char *ident);
+GKeyFile *__connman_storage_open_service(const char *ident);
+GKeyFile *__connman_storage_load_service(const char *ident);
+void __connman_storage_save_service(GKeyFile *keyfile, const char *ident);
+
int __connman_detect_init(void);
void __connman_detect_cleanup(void);
static int service_load(struct connman_service *service)
{
- const char *ident = "default";
GKeyFile *keyfile;
GError *error = NULL;
- gchar *pathname, *data = NULL;
gsize length;
gchar *str;
connman_bool_t autoconnect;
DBG("service %p", service);
- if (ident == NULL)
- return -EINVAL;
-
- pathname = g_strdup_printf("%s/%s.profile", STORAGEDIR, ident);
- if (pathname == NULL)
- return -ENOMEM;
-
- keyfile = g_key_file_new();
-
- if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE) {
- g_free(pathname);
- return -ENOENT;
- }
-
- g_free(pathname);
-
- if (g_key_file_load_from_data(keyfile, data, length,
- 0, NULL) == FALSE) {
- g_free(data);
- return -EILSEQ;
- }
-
- g_free(data);
+ keyfile = __connman_storage_load_service(service->identifier);
+ if (keyfile == NULL)
+ return -EIO;
switch (service->type) {
case CONNMAN_SERVICE_TYPE_UNKNOWN:
static int service_save(struct connman_service *service)
{
- const char *ident = "default";
GKeyFile *keyfile;
- gchar *pathname, *data = NULL;
- gsize length;
gchar *str;
const char *cst_str = NULL;
int err = 0;
DBG("service %p", service);
- if (ident == NULL)
- return -EINVAL;
-
- pathname = g_strdup_printf("%s/%s.profile", STORAGEDIR, ident);
- if (pathname == NULL)
- return -ENOMEM;
-
- keyfile = g_key_file_new();
-
- if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE)
- goto update;
-
- if (length > 0) {
- if (g_key_file_load_from_data(keyfile, data, length,
- 0, NULL) == FALSE)
- goto done;
- }
-
- g_free(data);
+ keyfile = __connman_storage_open_service(service->identifier);
+ if (keyfile == NULL)
+ return -EIO;
-update:
if (service->name != NULL)
g_key_file_set_string(keyfile, service->identifier,
"Name", service->name);
g_key_file_remove_key(keyfile, service->identifier,
"Proxy.URL", NULL);
- data = g_key_file_to_data(keyfile, &length, NULL);
-
- if (g_file_set_contents(pathname, data, length, NULL) == FALSE)
- connman_error("Failed to store service information");
-
done:
- g_free(data);
+ __connman_storage_save_service(keyfile, service->identifier);
g_key_file_free(keyfile);
- g_free(pathname);
-
return err;
}
__connman_notifier_service_remove(service);
stats_stop(service);
- service_save(service);
service->path = NULL;
if (service->ipconfig_ipv6 == NULL)
return;
- keyfile = __connman_storage_load_global();
+ keyfile = __connman_storage_load_service(service->identifier);
if (keyfile == NULL)
return;
#include <errno.h>
#include <unistd.h>
+#include <sys/stat.h>
#include "connman.h"
#define SETTINGS "settings"
#define DEFAULT "default.profile"
+#define MODE (S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | \
+ S_IXGRP | S_IROTH | S_IXOTH)
+
static GKeyFile *storage_load(const char *pathname)
{
GKeyFile *keyfile = NULL;
g_free(pathname);
}
+GKeyFile *__connman_storage_open_service(const char *service_id)
+{
+ gchar *pathname;
+ GKeyFile *keyfile = NULL;
+
+ pathname = g_strdup_printf("%s/%s/%s", STORAGEDIR, service_id, SETTINGS);
+ if(pathname == NULL)
+ return NULL;
+
+ keyfile = storage_load(pathname);
+ if (keyfile) {
+ g_free(pathname);
+ return keyfile;
+ }
+
+ g_free(pathname);
+
+ keyfile = g_key_file_new();
+
+ return keyfile;
+}
+
+GKeyFile *__connman_storage_load_service(const char *service_id)
+{
+ gchar *pathname;
+ GKeyFile *keyfile = NULL;
+
+ pathname = g_strdup_printf("%s/%s/%s", STORAGEDIR, service_id, SETTINGS);
+ if(pathname == NULL)
+ return NULL;
+
+ keyfile = storage_load(pathname);
+ if (keyfile) {
+ g_free(pathname);
+ return keyfile;
+ }
+
+ g_free(pathname);
+
+ pathname = g_strdup_printf("%s/%s", STORAGEDIR, DEFAULT);
+ if(pathname == NULL)
+ return NULL;
+
+ keyfile = storage_load(pathname);
+
+ g_free(pathname);
+
+ return keyfile;
+}
+
+void __connman_storage_save_service(GKeyFile *keyfile, const char *service_id)
+{
+ gchar *pathname, *dirname;
+
+ dirname = g_strdup_printf("%s/%s", STORAGEDIR, service_id);
+ if(dirname == NULL)
+ return;
+
+ /* If the dir doesn't exist, create it */
+ if (!g_file_test(dirname, G_FILE_TEST_IS_DIR)) {
+ if(mkdir(dirname, MODE) < 0) {
+ if (errno != EEXIST) {
+ 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.