From 0f92e6c9d9176e4934786ee77b57e1c5149e2ada Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 14 Nov 2013 16:14:35 +0000 Subject: [PATCH 21/26] mcp_account_manager_unescape_variant_from_keyfile: add I want to push responsibility for unescaping into storage plugins. --- mission-control-plugins/account.c | 29 +++++++++++++++++++++++++++++ mission-control-plugins/account.h | 6 ++++++ mission-control-plugins/implementation.h | 4 ++++ src/mcd-storage.c | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+) diff --git a/mission-control-plugins/account.c b/mission-control-plugins/account.c index fecd3d8..a6ca95a 100644 --- a/mission-control-plugins/account.c +++ b/mission-control-plugins/account.c @@ -272,3 +272,32 @@ mcp_account_manager_escape_variant_for_keyfile (const McpAccountManager *mcpa, return iface->escape_variant_for_keyfile (mcpa, variant); } + +/** + * mcp_account_manager_unescape_variant_from_keyfile: + * @mcpa: a #McpAccountManager + * @escaped: a string that could have come from g_key_file_get_value() + * @type: the type of the variant to which to unescape + * + * Unescape @escaped as if it had appeared in a #GKeyFile, with syntax + * appropriate for @type. + * + * It is a programming error to use an unsupported type. + * + * Returns: (transfer full): the unescaped form of @escaped + * (*not* a floating reference) + */ +GVariant * +mcp_account_manager_unescape_variant_from_keyfile ( + const McpAccountManager *mcpa, + const gchar *escaped, + const GVariantType *type, + GError **error) +{ + McpAccountManagerIface *iface = MCP_ACCOUNT_MANAGER_GET_IFACE (mcpa); + + g_return_val_if_fail (iface != NULL, NULL); + g_return_val_if_fail (iface->unescape_variant_from_keyfile != NULL, NULL); + + return iface->unescape_variant_from_keyfile (mcpa, escaped, type, error); +} diff --git a/mission-control-plugins/account.h b/mission-control-plugins/account.h index 788813f..78e58d0 100644 --- a/mission-control-plugins/account.h +++ b/mission-control-plugins/account.h @@ -71,6 +71,12 @@ gchar *mcp_account_manager_escape_variant_for_keyfile ( const McpAccountManager *mcpa, GVariant *variant); +GVariant *mcp_account_manager_unescape_variant_from_keyfile ( + const McpAccountManager *mcpa, + const gchar *escaped, + const GVariantType *type, + GError **error); + void mcp_account_manager_identify_account_async (McpAccountManager *mcpa, const gchar *manager, const gchar *protocol, diff --git a/mission-control-plugins/implementation.h b/mission-control-plugins/implementation.h index 7d95146..7db25f5 100644 --- a/mission-control-plugins/implementation.h +++ b/mission-control-plugins/implementation.h @@ -89,6 +89,10 @@ struct _McpAccountManagerIface { gchar * (* escape_variant_for_keyfile) (const McpAccountManager *mcpa, GVariant *variant); + GVariant *(* unescape_variant_from_keyfile) (const McpAccountManager *mcpa, + const gchar *escaped, + const GVariantType *type, + GError **error); void (* set_attribute) (const McpAccountManager *mcpa, const gchar *account, diff --git a/src/mcd-storage.c b/src/mcd-storage.c index b09473d..af63dfb 100644 --- a/src/mcd-storage.c +++ b/src/mcd-storage.c @@ -2081,6 +2081,37 @@ mcd_storage_ready (McdStorage *self) } } +static GVariant * +mcd_keyfile_unescape_variant (const gchar *escaped, + const GVariantType *type, + GError **error) +{ + GKeyFile *keyfile; + GVariant *ret; + + g_return_val_if_fail (escaped != NULL, NULL); + g_return_val_if_fail (type != NULL, NULL); + + keyfile = g_key_file_new (); + g_key_file_set_value (keyfile, "g", "k", escaped); + ret = mcd_keyfile_get_variant (keyfile, "g", "k", type, error); + g_key_file_free (keyfile); + + if (ret != NULL) + g_variant_ref_sink (ret); + + return ret; +} + +static GVariant * +mcpa_unescape_variant_from_keyfile (const McpAccountManager *mcpa, + const gchar *escaped, + const GVariantType *type, + GError **error) +{ + return mcd_keyfile_unescape_variant (escaped, type, error); +} + static void plugin_iface_init (McpAccountManagerIface *iface, gpointer unused G_GNUC_UNUSED) @@ -2094,6 +2125,7 @@ plugin_iface_init (McpAccountManagerIface *iface, iface->identify_account_async = identify_account_async; iface->identify_account_finish = identify_account_finish; iface->escape_variant_for_keyfile = mcpa_escape_variant_for_keyfile; + iface->unescape_variant_from_keyfile = mcpa_unescape_variant_from_keyfile; } gboolean -- 1.8.4.3