--- v2: - fix manager.ProvisionService dbus signature - handle malformed configurations properly - remove -EINPROGRESS special case in __connman_service_provision() error handling
v1: - initial revision src/connman.h | 1 + src/manager.c | 15 ++++++++++++++ src/service.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 0 deletions(-) diff --git a/src/connman.h b/src/connman.h index 2ea3071..558530b 100644 --- a/src/connman.h +++ b/src/connman.h @@ -513,6 +513,7 @@ int __connman_service_lookup(const char *pattern, const char **path); int __connman_service_connect(struct connman_service *service); int __connman_service_disconnect(struct connman_service *service); int __connman_service_create_and_connect(DBusMessage *msg); +int __connman_service_provision(DBusMessage *msg); void __connman_service_auto_connect(void); struct connman_service *__connman_service_connect_type(enum connman_service_type type); diff --git a/src/manager.c b/src/manager.c index 0a11f5d..fe715df 100644 --- a/src/manager.c +++ b/src/manager.c @@ -455,6 +455,19 @@ static DBusMessage *connect_service(DBusConnection *conn, return NULL; } +static DBusMessage *provision_service(DBusConnection *conn, DBusMessage *msg, + void *data) +{ + int err; + + DBG("conn %p", conn); + + err = __connman_service_provision(msg); + if (err < 0) + return __connman_error_failed(msg, -err); + + return NULL; +} static DBusMessage *connect_provider(DBusConnection *conn, DBusMessage *msg, void *data) @@ -617,6 +630,8 @@ static GDBusMethodTable manager_methods[] = { { "LookupService", "s", "o", lookup_service, }, { "ConnectService", "a{sv}", "o", connect_service, G_DBUS_METHOD_FLAG_ASYNC }, + { "ProvisionService", "s", "", provision_service, + G_DBUS_METHOD_FLAG_ASYNC }, { "ConnectProvider", "a{sv}", "o", connect_provider, G_DBUS_METHOD_FLAG_ASYNC }, { "RegisterAgent", "o", "", register_agent }, diff --git a/src/service.c b/src/service.c index d3b1de8..3d3f7fb 100644 --- a/src/service.c +++ b/src/service.c @@ -4137,6 +4137,64 @@ failed: return err; } +int __connman_service_provision(DBusMessage *msg) +{ + GKeyFile *keyfile = NULL; + const char *config_str = NULL; + char *group = NULL, *ident = NULL; + int err = 0; + + DBG(""); + + dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &config_str, + DBUS_TYPE_INVALID); + + if (config_str == NULL || strlen(config_str) == 0) + return -EINVAL; + + keyfile = g_key_file_new(); + + /* populate GKeyFile with config_str */ + if (g_key_file_load_from_data(keyfile, config_str, + strlen(config_str), 0, NULL) == FALSE) { + err = -EINVAL; + goto done; + } + + /* + * read only one group of settings (only one service supported, no + * global settings) + */ + group = g_key_file_get_start_group(keyfile); + + if (group == NULL || g_str_has_prefix(group, "service_") == FALSE) { + err = -EINVAL; + goto done; + } + + err = __connman_config_load_service(keyfile, group); + if (err < 0) + goto done; + + ident = group + strlen("service_"); + + /* trigger service provisioning if service exists */ + service = lookup_by_identifier(ident); + if (service != NULL) + __connman_config_provision_service(service); + + g_dbus_send_reply(connection, msg, DBUS_TYPE_INVALID); + +done: + if (group != NULL) + g_free(group); + + if (keyfile != NULL) + g_key_file_free(keyfile); + + return err; +} + /** * __connman_service_get: * @identifier: service identifier -- 1.7.0.4 _______________________________________________ connman mailing list connman@connman.net http://lists.connman.net/listinfo/connman