diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2013-11-15 15:24:16 +0000 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2014-01-29 19:28:33 +0000 |
commit | 9e890f2ee20791dc87093bb72b1a6a5148d28766 (patch) | |
tree | 9598ea43eb2b67ca0da5d1c5c37392591c8104c3 | |
parent | ff00f3cfcf3b50ad8fea903434b13f4dac33b793 (diff) |
McdAccountManagerDefault: get/set/commit on a missing account is an error
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=27727
-rw-r--r-- | src/mcd-account-manager-default.c | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/src/mcd-account-manager-default.c b/src/mcd-account-manager-default.c index 9becfd3b..49f04079 100644 --- a/src/mcd-account-manager-default.c +++ b/src/mcd-account-manager-default.c @@ -181,15 +181,14 @@ set_parameter (McpAccountStorage *self, McdAccountManagerDefault *amd = MCD_ACCOUNT_MANAGER_DEFAULT (self); McdDefaultStoredAccount *sa; + sa = lookup_stored_account (amd, account); + g_return_val_if_fail (sa != NULL, MCP_ACCOUNT_STORAGE_SET_RESULT_FAILED); + g_return_val_if_fail (!sa->absent, MCP_ACCOUNT_STORAGE_SET_RESULT_FAILED); + if (val == NULL) { gboolean changed = FALSE; - sa = lookup_stored_account (amd, account); - - if (sa == NULL) - return MCP_ACCOUNT_STORAGE_SET_RESULT_UNCHANGED; - changed = g_hash_table_remove (sa->parameters, parameter); /* deliberately not ||= - if we removed it from parameters, we * still want to remove it from untyped_parameters if it was there */ @@ -202,7 +201,6 @@ set_parameter (McpAccountStorage *self, { GVariant *old; - sa = ensure_stored_account (amd, account); old = g_hash_table_lookup (sa->parameters, parameter); if (old == NULL) @@ -246,13 +244,12 @@ set_attribute (McpAccountStorage *self, McdAccountManagerDefault *amd = MCD_ACCOUNT_MANAGER_DEFAULT (self); McdDefaultStoredAccount *sa; + sa = lookup_stored_account (amd, account); + g_return_val_if_fail (sa != NULL, MCP_ACCOUNT_STORAGE_SET_RESULT_FAILED); + g_return_val_if_fail (!sa->absent, MCP_ACCOUNT_STORAGE_SET_RESULT_FAILED); + if (val == NULL) { - sa = lookup_stored_account (amd, account); - - if (sa == NULL) - return MCP_ACCOUNT_STORAGE_SET_RESULT_UNCHANGED; - if (!g_hash_table_remove (sa->attributes, attribute)) return MCP_ACCOUNT_STORAGE_SET_RESULT_UNCHANGED; } @@ -260,7 +257,6 @@ set_attribute (McpAccountStorage *self, { GVariant *old; - sa = ensure_stored_account (amd, account); old = g_hash_table_lookup (sa->attributes, attribute); if (old != NULL && g_variant_equal (old, val)) @@ -288,8 +284,8 @@ get_attribute (McpAccountStorage *self, if (flags != NULL) *flags = 0; - if (sa == NULL || sa->absent) - return FALSE; + g_return_val_if_fail (sa != NULL, NULL); + g_return_val_if_fail (!sa->absent, NULL); /* ignore @type, we store every attribute with its type anyway; MC will * coerce values to an appropriate type if needed */ @@ -312,8 +308,8 @@ get_parameter (McpAccountStorage *self, if (flags != NULL) *flags = 0; - if (sa == NULL || sa->absent) - return FALSE; + g_return_val_if_fail (sa != NULL, NULL); + g_return_val_if_fail (!sa->absent, NULL); variant = g_hash_table_lookup (sa->parameters, parameter); @@ -457,6 +453,9 @@ am_default_commit_one (McdAccountManagerDefault *self, gboolean ret; GError *error = NULL; + g_return_val_if_fail (sa != NULL, FALSE); + g_return_val_if_fail (!sa->absent, FALSE); + if (!sa->dirty) return TRUE; @@ -539,6 +538,16 @@ _commit (const McpAccountStorage *self, * give us a chance to commit to the keyring too */ } + if (account != NULL) + { + McdDefaultStoredAccount *sa = lookup_stored_account (amd, account); + + g_return_val_if_fail (sa != NULL, FALSE); + g_return_val_if_fail (!sa->absent, FALSE); + + return am_default_commit_one (amd, account, sa); + } + g_hash_table_iter_init (&outer, amd->accounts); while (g_hash_table_iter_next (&outer, &account_p, &sa_p)) |