summaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
authorHenri Bragge <henri.bragge@ixonos.com>2011-04-01 11:41:40 +0300
committerSamuel Ortiz <sameo@linux.intel.com>2011-04-11 12:02:42 +0200
commitcda0efeb01e196c80c9202aba48c401daacb75a5 (patch)
tree041b545c10ae1ae16d45c830112f3c9a3193bd1a /src/config.c
parent3092bccc020d84001dd23f76fdcb449069c8f657 (diff)
downloadconnman-cda0efeb01e196c80c9202aba48c401daacb75a5.tar.gz
connman-cda0efeb01e196c80c9202aba48c401daacb75a5.tar.bz2
connman-cda0efeb01e196c80c9202aba48c401daacb75a5.zip
config: Export a function to load service configs
__connman_config_load_service() function can be used by other parts of ConnMan core to load service configurations, which can later be used for service provisioning. Within config.c, a special field (from_fs) will be used to mark which configurations originate from the filesystem and which do not. This information is needed to manage service immutability. Also a special name "internal" will be used to label the "file" used for non-fs configurations. A real file will not be created by ConnMan, and it will be silently ignored if created by someone else. Filesystem storage can be implemented later if necessary.
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/src/config.c b/src/config.c
index dcef4e53..17ed7d14 100644
--- a/src/config.c
+++ b/src/config.c
@@ -47,6 +47,7 @@ struct connman_config_service {
char *private_key_passphrase_type;
char *phase2;
char *passphrase;
+ gboolean from_fs;
};
struct connman_config {
@@ -63,6 +64,8 @@ static int inotify_wd = -1;
static GIOChannel *inotify_channel = NULL;
static uint inotify_watch = 0;
+#define NONFS_CONFIG_NAME "internal"
+
/* Definition of possible strings in the .config files */
#define CONFIG_KEY_NAME "Name"
#define CONFIG_KEY_DESC "Description"
@@ -300,6 +303,11 @@ static int load_service(GKeyFile *keyfile, const char *group,
service->passphrase = str;
}
+ if (g_strcmp0(config->ident, NONFS_CONFIG_NAME) != 0)
+ service->from_fs = TRUE;
+ else
+ service->from_fs = FALSE;
+
if (service_created)
g_hash_table_insert(config->service_table, service->ident,
service);
@@ -309,6 +317,22 @@ static int load_service(GKeyFile *keyfile, const char *group,
return 0;
}
+static struct connman_config *create_config(const char *ident);
+
+int __connman_config_load_service(GKeyFile *keyfile, const char *group)
+{
+ struct connman_config *config = g_hash_table_lookup(config_table,
+ NONFS_CONFIG_NAME);
+
+ if (config == NULL) {
+ config = create_config(NONFS_CONFIG_NAME);
+ if (config == NULL)
+ return -ENOMEM;
+ }
+
+ return load_service(keyfile, group, config);
+}
+
static int load_config(struct connman_config *config)
{
GKeyFile *keyfile;
@@ -398,6 +422,9 @@ static int read_configs(void)
if (ident == NULL)
continue;
+ if (g_str_equal(ident, NONFS_CONFIG_NAME) == TRUE)
+ continue;
+
str = g_string_new_len(file, ident - file);
if (str == NULL)
continue;
@@ -482,6 +509,9 @@ static gboolean inotify_data(GIOChannel *channel, GIOCondition cond,
*ext = '\0';
+ if (g_str_equal(ident, NONFS_CONFIG_NAME) == TRUE)
+ continue;
+
if (connman_dbus_validate_ident(ident) == FALSE)
continue;
@@ -636,7 +666,15 @@ static void provision_service(gpointer key, gpointer value, gpointer user_data)
if (memcmp(config->ssid, ssid, ssid_len) != 0)
return;
- __connman_service_set_immutable(service, TRUE);
+ /* do not provision immutable services with non-fs originated configs */
+ if (config->from_fs == FALSE &&
+ __connman_service_get_immutable(service) == TRUE)
+ return;
+
+ /* only lock services with a config originated from the filesystem */
+ if (config->from_fs == TRUE)
+ __connman_service_set_immutable(service, TRUE);
+
__connman_service_set_favorite(service, TRUE);
if (config->eap != NULL)