aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonny Lamb <jonny.lamb@collabora.co.uk>2010-12-06 19:35:26 +0800
committerJonny Lamb <jonny.lamb@collabora.co.uk>2010-12-06 19:35:38 +0800
commit2c201cf276aa11b3ae1d1bedcf92eb29abf7f04d (patch)
treed8432b1bdddbf6e9d2a1cc9cac160782bc9a7bd7
parentb66750b8540761c03b935ff93d50c642c9d1f07c (diff)
downloadgsoc2013-empathy-2c201cf276aa11b3ae1d1bedcf92eb29abf7f04d.tar
gsoc2013-empathy-2c201cf276aa11b3ae1d1bedcf92eb29abf7f04d.tar.gz
gsoc2013-empathy-2c201cf276aa11b3ae1d1bedcf92eb29abf7f04d.tar.bz2
gsoc2013-empathy-2c201cf276aa11b3ae1d1bedcf92eb29abf7f04d.tar.lz
gsoc2013-empathy-2c201cf276aa11b3ae1d1bedcf92eb29abf7f04d.tar.xz
gsoc2013-empathy-2c201cf276aa11b3ae1d1bedcf92eb29abf7f04d.tar.zst
gsoc2013-empathy-2c201cf276aa11b3ae1d1bedcf92eb29abf7f04d.zip
keyring: add a delete_password function
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
-rw-r--r--libempathy/empathy-keyring.c96
-rw-r--r--libempathy/empathy-keyring.h6
2 files changed, 102 insertions, 0 deletions
diff --git a/libempathy/empathy-keyring.c b/libempathy/empathy-keyring.c
index b27df710f..55ddd1f69 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 015b7ae86..000f987f7 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__ */