diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2014-02-03 20:22:32 +0000 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2014-02-04 13:57:33 +0000 |
commit | 7290f4e00a5eb3cd155998d7a0a81a14028ced7c (patch) | |
tree | 8bcbae78d666ba50b1edaae210a7123fab9336b4 /tests/twisted | |
parent | ea63753dbccb7fa617496c3c0d3d0d2bc0351bc3 (diff) |
Require account plugins to provide the ability to list parameters
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=71093
Reviewed-by: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Diffstat (limited to 'tests/twisted')
-rw-r--r-- | tests/twisted/dbus-account-plugin.c | 59 | ||||
-rw-r--r-- | tests/twisted/mcp-account-diversion.c | 44 |
2 files changed, 102 insertions, 1 deletions
diff --git a/tests/twisted/dbus-account-plugin.c b/tests/twisted/dbus-account-plugin.c index 446a2ad7..36f78914 100644 --- a/tests/twisted/dbus-account-plugin.c +++ b/tests/twisted/dbus-account-plugin.c @@ -1017,7 +1017,7 @@ test_dbus_account_plugin_get_parameter (McpAccountStorage *storage, { return g_variant_ref (v); } - else if (s != NULL) + else if (s != NULL && type != NULL) { return mcp_account_manager_unescape_variant_from_keyfile (am, s, type, NULL); @@ -1028,6 +1028,59 @@ test_dbus_account_plugin_get_parameter (McpAccountStorage *storage, } } +static gchar ** +test_dbus_account_plugin_list_typed_parameters (McpAccountStorage *storage, + McpAccountManager *am, + const gchar *account_name) +{ + TestDBusAccountPlugin *self = TEST_DBUS_ACCOUNT_PLUGIN (storage); + Account *account = lookup_account (self, account_name); + GPtrArray *arr; + GHashTableIter iter; + gpointer k; + + g_return_val_if_fail (self->active, NULL); + g_return_val_if_fail (account != NULL, NULL); + + arr = g_ptr_array_sized_new (g_hash_table_size (account->parameters) + 1); + + g_hash_table_iter_init (&iter, account->parameters); + + while (g_hash_table_iter_next (&iter, &k, NULL)) + g_ptr_array_add (arr, g_strdup (k)); + + g_ptr_array_add (arr, NULL); + + return (gchar **) g_ptr_array_free (arr, FALSE); +} + +static gchar ** +test_dbus_account_plugin_list_untyped_parameters (McpAccountStorage *storage, + McpAccountManager *am, + const gchar *account_name) +{ + TestDBusAccountPlugin *self = TEST_DBUS_ACCOUNT_PLUGIN (storage); + Account *account = lookup_account (self, account_name); + GPtrArray *arr; + GHashTableIter iter; + gpointer k; + + g_return_val_if_fail (self->active, NULL); + g_return_val_if_fail (account != NULL, NULL); + + arr = g_ptr_array_sized_new ( + g_hash_table_size (account->untyped_parameters) + 1); + + g_hash_table_iter_init (&iter, account->untyped_parameters); + + while (g_hash_table_iter_next (&iter, &k, NULL)) + g_ptr_array_add (arr, g_strdup (k)); + + g_ptr_array_add (arr, NULL); + + return (gchar **) g_ptr_array_free (arr, FALSE); +} + static McpAccountStorageSetResult test_dbus_account_plugin_set_attribute (McpAccountStorage *storage, McpAccountManager *am, @@ -1500,6 +1553,10 @@ account_storage_iface_init (McpAccountStorageIface *iface) iface->get_attribute = test_dbus_account_plugin_get_attribute; iface->get_parameter = test_dbus_account_plugin_get_parameter; + iface->list_typed_parameters = + test_dbus_account_plugin_list_typed_parameters; + iface->list_untyped_parameters = + test_dbus_account_plugin_list_untyped_parameters; iface->set_attribute = test_dbus_account_plugin_set_attribute; iface->set_parameter = test_dbus_account_plugin_set_parameter; iface->list = test_dbus_account_plugin_list; diff --git a/tests/twisted/mcp-account-diversion.c b/tests/twisted/mcp-account-diversion.c index 466d3ee3..0e8bfbc8 100644 --- a/tests/twisted/mcp-account-diversion.c +++ b/tests/twisted/mcp-account-diversion.c @@ -238,6 +238,11 @@ _get_parameter (McpAccountStorage *self, if (flags != NULL) *flags = 0; + /* this plugin does not store parameters' types, so we can't invent + * a sensible type from nowhere */ + if (type == NULL) + return NULL; + key = g_strdup_printf ("param-%s", parameter); v = g_key_file_get_value (adp->keyfile, account, key, NULL); g_free (key); @@ -250,6 +255,43 @@ _get_parameter (McpAccountStorage *self, return ret; } +static gchar ** +list_typed_parameters (McpAccountStorage *storage, + McpAccountManager *am, + const gchar *account_name) +{ + /* this plugin can't store parameters' types */ + return NULL; +} + +static gchar ** +list_untyped_parameters (McpAccountStorage *storage, + McpAccountManager *am, + const gchar *account_name) +{ + AccountDiversionPlugin *adp = ACCOUNT_DIVERSION_PLUGIN (storage); + gchar **keys; + gsize i; + GPtrArray *arr; + + keys = g_key_file_get_keys (adp->keyfile, account_name, &i, NULL); + + if (keys == NULL) + return NULL; + + arr = g_ptr_array_sized_new (i); + + for (i = 0; keys[i] != NULL; i++) + { + if (g_str_has_prefix (keys[i], "param-")) + g_ptr_array_add (arr, g_strdup (keys[i] + 6)); + } + + g_strfreev (keys); + g_ptr_array_add (arr, NULL); + return (gchar **) g_ptr_array_free (arr, FALSE); +} + static gboolean _commit (McpAccountStorage *self, McpAccountManager *am, const gchar *account_name); @@ -386,6 +428,8 @@ account_storage_iface_init (McpAccountStorageIface *iface, iface->get_attribute = _get_attribute; iface->get_parameter = _get_parameter; + iface->list_typed_parameters = list_typed_parameters; + iface->list_untyped_parameters = list_untyped_parameters; iface->set_attribute = _set_attribute; iface->set_parameter = _set_parameter; iface->delete_async = delete_async; |