config: Save D-Bus provisioned files
authorSamuel Ortiz <sameo@linux.intel.com>
Mon, 11 Apr 2011 09:07:37 +0000 (11:07 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Mon, 11 Apr 2011 10:02:45 +0000 (12:02 +0200)
They will not be able to overwrite protected configs though.

src/config.c
src/connman.h
src/service.c

index 932a108..974643f 100644 (file)
@@ -67,6 +67,7 @@ static GIOChannel *inotify_channel = NULL;
 static uint inotify_watch = 0;
 
 #define NONFS_CONFIG_NAME                "internal"
+#define INTERNAL_CONFIG_PREFIX           "__internal"
 
 /* Definition of possible strings in the .config files */
 #define CONFIG_KEY_NAME                "Name"
@@ -446,18 +447,70 @@ static struct connman_config *create_config(const char *ident)
        return config;
 }
 
-int __connman_config_load_service(GKeyFile *keyfile, const char *group)
+int __connman_config_load_service(GKeyFile *keyfile, const char *group,
+                                       connman_bool_t persistent)
 {
-       struct connman_config *config = g_hash_table_lookup(config_table,
-                                                       NONFS_CONFIG_NAME);
+       struct connman_config *config;
+       const char *service_name;
+       char *ident, *filename = NULL, *content = NULL;
+       gsize content_length;
+       int err;
+
+       service_name = group + strlen("service_");
+       ident = g_strdup_printf("%s_%s", INTERNAL_CONFIG_PREFIX, service_name);
+       if (ident == NULL)
+               return -ENOMEM;
 
+       DBG("ident %s", ident);
+
+       config = g_hash_table_lookup(config_table, ident);
        if (config == NULL) {
-               config = create_config(NONFS_CONFIG_NAME);
-               if (config == NULL)
-                       return -ENOMEM;
+               config = create_config(ident);
+               if (config == NULL) {
+                       err = -ENOMEM;
+                       goto out;
+               }
+
+               config->protected = FALSE;
+       }
+
+       err = load_service(keyfile, group, config);
+       if (persistent == FALSE || err < 0)
+               goto out;
+
+       g_key_file_set_string(keyfile, "global", CONFIG_KEY_NAME,
+                                                       service_name);
+       g_key_file_set_string(keyfile, "global", CONFIG_KEY_DESC,
+                                               "Internal Config File");
+
+       content = g_key_file_to_data(keyfile, &content_length, NULL);
+       if (content == NULL) {
+               err = -EIO;
+               goto out;
+       }
+
+       filename = g_strdup_printf("%s/%s.config", STORAGEDIR, ident);
+       if (filename == NULL) {
+               err = -ENOMEM;
+               goto out;
        }
 
-       return load_service(keyfile, group, config);
+       DBG("Saving %d bytes to %s", content_length, filename);
+
+       if (g_file_set_contents(filename, content,
+                               content_length, NULL) == FALSE) {
+               err = -EIO;
+               goto out;
+       }
+
+       return 0;
+
+out:
+       g_free(ident);
+       g_free(content);
+       g_free(filename);
+
+       return err;
 }
 
 static int read_configs(void)
index f912026..ac56ef2 100644 (file)
@@ -416,7 +416,7 @@ connman_bool_t __connman_network_get_weakness(struct connman_network *network);
 int __connman_config_init();
 void __connman_config_cleanup(void);
 
-int __connman_config_load_service(GKeyFile *keyfile, const char *group);
+int __connman_config_load_service(GKeyFile *keyfile, const char *group, connman_bool_t persistent);
 int __connman_config_provision_service(struct connman_service *service);
 
 #include <connman/profile.h>
index 46f7ade..f18cd33 100644 (file)
@@ -4272,7 +4272,7 @@ int __connman_service_provision(DBusMessage *msg)
                goto done;
        }
 
-       err = __connman_config_load_service(keyfile, group);
+       err = __connman_config_load_service(keyfile, group, TRUE);
        if (err < 0)
                goto done;