From f9f7f6e271e20d054f846e7f1c41bc06edc33fc4 Mon Sep 17 00:00:00 2001 From: George Kiagiadakis <george.kiagiadakis@collabora.com> Date: Thu, 27 Jun 2019 18:10:21 +0300 Subject: [PATCH] config: implement reading properties for modules from the config file Properties are expected to be a GVariant a{sv} dictionary, specified in the GVariant text format: https://developer.gnome.org/glib/stable/gvariant-text.html --- src/main.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 33d40d56..968233b1 100644 --- a/src/main.c +++ b/src/main.c @@ -99,9 +99,10 @@ parse_commands_file (struct WpDaemonData *d, GInputStream * stream, gchar buffer[4096]; gssize bytes_read; gchar *cur, *linestart, *saveptr; - gchar *cmd, *abi, *module; + gchar *cmd, *abi, *module, *props; gint lineno = 1; gboolean eof = FALSE; + GVariant *properties; linestart = cur = buffer; @@ -142,7 +143,26 @@ parse_commands_file (struct WpDaemonData *d, GInputStream * stream, return FALSE; } - if (!wp_module_load (d->core, abi, module, NULL, error)) { + /* if there are remaining characters after the module name, + treat it as a serialized GVariant for the properties */ + props = module + strlen(module) + 1; + if (cur - props > 0) { + g_autoptr (GError) tmperr = NULL; + g_autofree gchar *context = NULL; + + properties = g_variant_parse (G_VARIANT_TYPE_VARDICT, props, cur, + NULL, &tmperr); + if (!properties) { + context = g_variant_parse_error_print_context (tmperr, props); + g_set_error (error, WP_DOMAIN_DAEMON, WP_CODE_INVALID_ARGUMENT, + "GVariant parse error:\n%s", context); + return FALSE; + } + } else { + properties = g_variant_new_parsed ("@a{sv} {}"); + } + + if (!wp_module_load (d->core, abi, module, properties, error)) { return FALSE; } } else { -- GitLab