From 2c201cf276aa11b3ae1d1bedcf92eb29abf7f04d Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Mon, 6 Dec 2010 11:35:26 +0000 Subject: [PATCH] keyring: add a delete_password function Signed-off-by: Jonny Lamb --- libempathy/empathy-keyring.c | 96 ++++++++++++++++++++++++++++++++++++ libempathy/empathy-keyring.h | 6 +++ 2 files changed, 102 insertions(+) diff --git a/libempathy/empathy-keyring.c b/libempathy/empathy-keyring.c index b27df710..55ddd1f6 100644 --- a/libempathy/empathy-keyring.c +++ b/libempathy/empathy-keyring.c @@ -187,3 +187,99 @@ empathy_keyring_set_password_finish (TpAccount *account, return TRUE; } +static void +item_delete_cb (GnomeKeyringResult result, + gpointer user_data) +{ + GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data); + + if (result != GNOME_KEYRING_RESULT_OK) + { + GError *error = g_error_new_literal (TP_ERROR, + TP_ERROR_DOES_NOT_EXIST, + gnome_keyring_result_to_message (result)); + g_simple_async_result_set_from_error (simple, error); + g_clear_error (&error); + } + + g_simple_async_result_complete (simple); + g_object_unref (simple); +} + +static void +find_item_to_delete_cb (GnomeKeyringResult result, + GList *list, + gpointer user_data) +{ + GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data); + GnomeKeyringFound *found; + + if (result != GNOME_KEYRING_RESULT_OK || g_list_length (list) != 1) + { + GError *error = g_error_new_literal (TP_ERROR, + TP_ERROR_DOES_NOT_EXIST, + gnome_keyring_result_to_message (result)); + g_simple_async_result_set_from_error (simple, error); + g_clear_error (&error); + + g_simple_async_result_complete (simple); + g_object_unref (simple); + return; + } + + found = list->data; + + gnome_keyring_item_delete (NULL, found->item_id, item_delete_cb, + simple, NULL); +} + +void +empathy_keyring_delete_password_async (TpAccount *account, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GSimpleAsyncResult *simple; + GnomeKeyringAttributeList *match; + const gchar *account_id; + + g_return_if_fail (TP_IS_ACCOUNT (account)); + g_return_if_fail (callback != NULL); + + simple = g_simple_async_result_new (G_OBJECT (account), callback, + user_data, empathy_keyring_delete_password_async); + + account_id = tp_proxy_get_object_path (account) + + strlen (TP_ACCOUNT_OBJECT_PATH_BASE); + + match = gnome_keyring_attribute_list_new (); + gnome_keyring_attribute_list_append_string (match, "account", + account_id); + gnome_keyring_attribute_list_append_string (match, "param", "password"); + + gnome_keyring_find_items (GNOME_KEYRING_ITEM_GENERIC_SECRET, + match, find_item_to_delete_cb, simple, NULL); + + gnome_keyring_attribute_list_free (match); +} + +gboolean +empathy_keyring_delete_password_finish (TpAccount *account, + GAsyncResult *result, + GError **error) +{ + GSimpleAsyncResult *simple; + + g_return_val_if_fail (TP_IS_ACCOUNT (account), FALSE); + g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE); + + simple = G_SIMPLE_ASYNC_RESULT (result); + + if (g_simple_async_result_propagate_error (simple, error)) + return FALSE; + + g_return_val_if_fail (g_simple_async_result_is_valid (result, + G_OBJECT (account), empathy_keyring_delete_password_async), FALSE); + + return TRUE; +} + diff --git a/libempathy/empathy-keyring.h b/libempathy/empathy-keyring.h index 015b7ae8..000f987f 100644 --- a/libempathy/empathy-keyring.h +++ b/libempathy/empathy-keyring.h @@ -38,6 +38,12 @@ void empathy_keyring_set_password_async (TpAccount *account, gboolean empathy_keyring_set_password_finish (TpAccount *account, GAsyncResult *result, GError **error); +void empathy_keyring_delete_password_async (TpAccount *account, + GAsyncReadyCallback callback, gpointer user_data); + +gboolean empathy_keyring_delete_password_finish (TpAccount *account, + GAsyncResult *result, GError **error); + G_END_DECLS #endif /* __EMPATHY_KEYRING_H__ */ -- 2.39.2