From: Henri Bragge Date: Fri, 1 Apr 2011 08:41:40 +0000 (+0300) Subject: config: Export a function to load service configs X-Git-Tag: 0.73~43 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cda0efeb01e196c80c9202aba48c401daacb75a5;p=platform%2Fupstream%2Fconnman.git 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. --- diff --git a/src/config.c b/src/config.c index dcef4e5..17ed7d1 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) diff --git a/src/connman.h b/src/connman.h index f32c2eb..5a9e927 100644 --- a/src/connman.h +++ b/src/connman.h @@ -416,6 +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_provision_service(struct connman_service *service); #include