diff options
author | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2010-12-06 10:05:56 +0000 |
---|---|---|
committer | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2010-12-06 10:05:56 +0000 |
commit | 085edd72db61d923a639d874f44c9ed2805e75a8 (patch) | |
tree | 2689215fe9505c5e39644fd6d7175e91e4b3bc43 /libempathy | |
parent | bc099434f22a78d09d0dad3d5006ad836ab11d02 (diff) |
keyring: add set_password_{async,finish} functions
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
Diffstat (limited to 'libempathy')
-rw-r--r-- | libempathy/empathy-keyring.c | 86 | ||||
-rw-r--r-- | libempathy/empathy-keyring.h | 7 |
2 files changed, 87 insertions, 6 deletions
diff --git a/libempathy/empathy-keyring.c b/libempathy/empathy-keyring.c index 7f49acc6d..b27df710f 100644 --- a/libempathy/empathy-keyring.c +++ b/libempathy/empathy-keyring.c @@ -27,13 +27,11 @@ #define DEBUG_FLAG EMPATHY_DEBUG_OTHER #include "empathy-debug.h" -/* -GnomeKeyringPasswordSchema keyring_schema = +static GnomeKeyringPasswordSchema keyring_schema = { GNOME_KEYRING_ITEM_GENERIC_SECRET, { { "account", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, { "param", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, { NULL } } }; -*/ static void find_items_cb (GnomeKeyringResult result, @@ -44,9 +42,11 @@ find_items_cb (GnomeKeyringResult result, if (result != GNOME_KEYRING_RESULT_OK) { - GError error = { TP_ERROR, TP_ERROR_DOES_NOT_EXIST, - (gchar *) gnome_keyring_result_to_message (result) }; - g_simple_async_result_set_from_error (simple, &error); + 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); } if (g_list_length (list) == 1) @@ -113,3 +113,77 @@ empathy_keyring_get_password_finish (TpAccount *account, return g_simple_async_result_get_op_res_gpointer (simple); } + +static void +store_password_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); +} + +void +empathy_keyring_set_password_async (TpAccount *account, + const gchar *password, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GSimpleAsyncResult *simple; + const gchar *account_id; + gchar *name; + + g_return_if_fail (TP_IS_ACCOUNT (account)); + g_return_if_fail (password != NULL); + g_return_if_fail (callback != NULL); + + simple = g_simple_async_result_new (G_OBJECT (account), callback, + user_data, empathy_keyring_set_password_async); + + account_id = tp_proxy_get_object_path (account) + + strlen (TP_ACCOUNT_OBJECT_PATH_BASE); + + DEBUG ("Remembering password for %s", account_id); + + name = g_strdup_printf ("account: %s; param: param-password", account_id); + + gnome_keyring_store_password (&keyring_schema, NULL, name, password, + store_password_cb, simple, NULL, + "account", account_id, + "param", "password", + NULL); + + g_free (name); +} + +gboolean +empathy_keyring_set_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_set_password_async), FALSE); + + return TRUE; +} + diff --git a/libempathy/empathy-keyring.h b/libempathy/empathy-keyring.h index 2c062e1cd..015b7ae86 100644 --- a/libempathy/empathy-keyring.h +++ b/libempathy/empathy-keyring.h @@ -31,6 +31,13 @@ void empathy_keyring_get_password_async (TpAccount *account, const gchar * empathy_keyring_get_password_finish (TpAccount *account, GAsyncResult *result, GError **error); +void empathy_keyring_set_password_async (TpAccount *account, + const gchar *password, GAsyncReadyCallback callback, + gpointer user_data); + +gboolean empathy_keyring_set_password_finish (TpAccount *account, + GAsyncResult *result, GError **error); + G_END_DECLS #endif /* __EMPATHY_KEYRING_H__ */ |