aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonny Lamb <jonnylamb@gnome.org>2011-02-01 16:50:22 +0800
committerJonny Lamb <jonnylamb@gnome.org>2011-02-01 16:50:22 +0800
commit38a7c551fb07d72dd7b6744a8d1a345466b011d2 (patch)
tree3eca2564dbb6240421e1d7b43e8cb1898f73bd0c
parent7f5c02a63be19988ab199e497e22cd93880ae0bd (diff)
parentb03dfefd8103ea41f61407df122021a6d14d5a19 (diff)
downloadgsoc2013-empathy-38a7c551fb07d72dd7b6744a8d1a345466b011d2.tar
gsoc2013-empathy-38a7c551fb07d72dd7b6744a8d1a345466b011d2.tar.gz
gsoc2013-empathy-38a7c551fb07d72dd7b6744a8d1a345466b011d2.tar.bz2
gsoc2013-empathy-38a7c551fb07d72dd7b6744a8d1a345466b011d2.tar.lz
gsoc2013-empathy-38a7c551fb07d72dd7b6744a8d1a345466b011d2.tar.xz
gsoc2013-empathy-38a7c551fb07d72dd7b6744a8d1a345466b011d2.tar.zst
gsoc2013-empathy-38a7c551fb07d72dd7b6744a8d1a345466b011d2.zip
Merge branch 'muc-password'
-rw-r--r--libempathy-gtk/empathy-chat.c177
-rw-r--r--libempathy/empathy-account-settings.c16
-rw-r--r--libempathy/empathy-auth-factory.c4
-rw-r--r--libempathy/empathy-keyring.c162
-rw-r--r--libempathy/empathy-keyring.h28
-rw-r--r--libempathy/empathy-server-sasl-handler.c8
-rw-r--r--libempathy/empathy-utils.h45
7 files changed, 365 insertions, 75 deletions
diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c
index 489a0a69a..eb7325339 100644
--- a/libempathy-gtk/empathy-chat.c
+++ b/libempathy-gtk/empathy-chat.c
@@ -40,6 +40,7 @@
#include <telepathy-logger/log-manager.h>
#include <libempathy/empathy-contact-list.h>
#include <libempathy/empathy-gsettings.h>
+#include <libempathy/empathy-keyring.h>
#include <libempathy/empathy-utils.h>
#include <libempathy/empathy-dispatcher.h>
#include <libempathy/empathy-marshal.h>
@@ -2967,13 +2968,115 @@ typedef struct
{
EmpathyChat *self;
GtkWidget *info_bar;
+ gulong response_id;
GtkWidget *button;
GtkWidget *label;
GtkWidget *entry;
GtkWidget *spinner;
+ gchar *password;
} PasswordData;
static void
+passwd_remember_button_cb (GtkButton *button,
+ PasswordData *data)
+{
+ gtk_info_bar_response (GTK_INFO_BAR (data->info_bar), GTK_RESPONSE_OK);
+}
+
+static void
+passwd_not_now_button_cb (GtkButton *button,
+ PasswordData *data)
+{
+ gtk_info_bar_response (GTK_INFO_BAR (data->info_bar), GTK_RESPONSE_NO);
+}
+
+static void
+remember_password_infobar_response_cb (GtkWidget *info_bar,
+ gint response_id,
+ PasswordData *data)
+{
+ EmpathyChatPriv *priv = GET_PRIV (data->self);
+
+ if (response_id == GTK_RESPONSE_OK) {
+ DEBUG ("Saving room password");
+ empathy_keyring_set_room_password_async (priv->account,
+ empathy_tp_chat_get_id (priv->tp_chat),
+ data->password,
+ NULL, NULL);
+ }
+
+ gtk_widget_destroy (info_bar);
+ g_free (data->password);
+ g_slice_free (PasswordData, data);
+}
+
+static void
+chat_prompt_to_save_password (EmpathyChat *self,
+ PasswordData *data)
+{
+ GtkWidget *content_area;
+ GtkWidget *hbox;
+ GtkWidget *image;
+ GtkWidget *label;
+ GtkWidget *alig;
+ GtkWidget *button;
+
+ /* save the password in case it needs to be saved */
+ data->password = g_strdup (gtk_entry_get_text (GTK_ENTRY (data->entry)));
+
+ /* Remove all previous widgets */
+ content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (data->info_bar));
+ gtk_container_forall (GTK_CONTAINER (content_area),
+ (GtkCallback) gtk_widget_destroy, NULL);
+ data->button = NULL;
+ data->label = NULL;
+ data->entry = NULL;
+ data->spinner = NULL;
+
+ gtk_info_bar_set_message_type (GTK_INFO_BAR (data->info_bar),
+ GTK_MESSAGE_QUESTION);
+
+ hbox = gtk_hbox_new (FALSE, 5);
+ gtk_box_pack_start (GTK_BOX (content_area), hbox, TRUE, TRUE, 0);
+
+ /* Add image */
+ image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_AUTHENTICATION,
+ GTK_ICON_SIZE_DIALOG);
+ gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
+
+ /* Add message */
+ label = gtk_label_new (_("Would you like to store this password?"));
+ gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
+
+ /* Add 'Remember' button */
+ alig = gtk_alignment_new (0, 0.5, 1, 0);
+
+ button = gtk_button_new_with_label (_("Remember"));
+ gtk_container_add (GTK_CONTAINER (alig), button);
+ gtk_box_pack_start (GTK_BOX (hbox), alig, FALSE, FALSE, 0);
+
+ g_signal_connect (button, "clicked", G_CALLBACK (passwd_remember_button_cb),
+ data);
+
+ /* Add 'Not now' button */
+ alig = gtk_alignment_new (0, 0.5, 1, 0);
+
+ button = gtk_button_new_with_label (_("Not now"));
+ gtk_container_add (GTK_CONTAINER (alig), button);
+ gtk_box_pack_start (GTK_BOX (hbox), alig, FALSE, FALSE, 0);
+
+ g_signal_connect (button, "clicked", G_CALLBACK (passwd_not_now_button_cb),
+ data);
+
+ /* go! */
+ g_signal_handler_disconnect (data->info_bar, data->response_id);
+ g_signal_connect (data->info_bar, "response",
+ G_CALLBACK (remember_password_infobar_response_cb), data);
+
+ gtk_widget_show_all (data->info_bar);
+}
+
+static void
provide_password_cb (GObject *tp_chat,
GAsyncResult *res,
gpointer user_data)
@@ -3016,10 +3119,14 @@ provide_password_cb (GObject *tp_chat,
return;
}
- /* Get rid of the password info bar finally */
- gtk_widget_destroy (data->info_bar);
-
- g_slice_free (PasswordData, data);
+ if (empathy_keyring_is_available ()) {
+ /* ask whether they want to save the password */
+ chat_prompt_to_save_password (self, data);
+ } else {
+ /* Get rid of the password info bar finally */
+ gtk_widget_destroy (data->info_bar);
+ g_slice_free (PasswordData, data);
+ }
/* Room joined */
gtk_widget_set_sensitive (priv->hpaned, TRUE);
@@ -3169,8 +3276,8 @@ display_password_info_bar (EmpathyChat *self)
TRUE, TRUE, 3);
gtk_widget_show_all (hbox);
- g_signal_connect (info_bar, "response",
- G_CALLBACK (password_infobar_response_cb), data);
+ data->response_id = g_signal_connect (info_bar, "response",
+ G_CALLBACK (password_infobar_response_cb), data);
gtk_widget_show_all (info_bar);
/* ... but hide the spinner */
@@ -3178,13 +3285,67 @@ display_password_info_bar (EmpathyChat *self)
}
static void
-chat_password_needed_changed_cb (EmpathyChat *self)
+provide_saved_password_cb (GObject *tp_chat,
+ GAsyncResult *res,
+ gpointer user_data)
{
+ EmpathyChat *self = user_data;
EmpathyChatPriv *priv = GET_PRIV (self);
+ GError *error = NULL;
+
+ if (!empathy_tp_chat_provide_password_finish (EMPATHY_TP_CHAT (tp_chat), res,
+ &error)) {
+ DEBUG ("error: %s", error->message);
+ /* FIXME: what should we do if that's another error? Close the channel?
+ * Display the raw D-Bus error to the user isn't very useful */
+ if (g_error_matches (error, TP_ERRORS, TP_ERROR_AUTHENTICATION_FAILED)) {
+ display_password_info_bar (self);
+ gtk_widget_set_sensitive (priv->hpaned, FALSE);
+ }
+ g_error_free (error);
+ return;
+ }
+
+ /* Room joined */
+ gtk_widget_set_sensitive (priv->hpaned, TRUE);
+ gtk_widget_grab_focus (self->input_text_view);
+}
+
+static void
+chat_room_got_password_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ EmpathyChat *self = user_data;
+ EmpathyChatPriv *priv = GET_PRIV (self);
+ const gchar *password;
+ GError *error = NULL;
+
+ password = empathy_keyring_get_room_password_finish (priv->account,
+ result, &error);
+
+ if (error != NULL) {
+ DEBUG ("Couldn't get room password: %s\n", error->message);
+ g_clear_error (&error);
- if (empathy_tp_chat_password_needed (priv->tp_chat)) {
display_password_info_bar (self);
gtk_widget_set_sensitive (priv->hpaned, FALSE);
+ return;
+ }
+
+ empathy_tp_chat_provide_password_async (priv->tp_chat, password,
+ provide_saved_password_cb, self);
+}
+
+static void
+chat_password_needed_changed_cb (EmpathyChat *self)
+{
+ EmpathyChatPriv *priv = GET_PRIV (self);
+
+ if (empathy_tp_chat_password_needed (priv->tp_chat)) {
+ empathy_keyring_get_room_password_async (priv->account,
+ empathy_tp_chat_get_id (priv->tp_chat),
+ chat_room_got_password_cb, self);
}
}
diff --git a/libempathy/empathy-account-settings.c b/libempathy/empathy-account-settings.c
index 8c673dfcf..1d2379fe5 100644
--- a/libempathy/empathy-account-settings.c
+++ b/libempathy/empathy-account-settings.c
@@ -434,7 +434,7 @@ empathy_account_settings_get_password_cb (GObject *source,
const gchar *password;
GError *error = NULL;
- password = empathy_keyring_get_password_finish (TP_ACCOUNT (source),
+ password = empathy_keyring_get_account_password_finish (TP_ACCOUNT (source),
result, &error);
if (error != NULL)
@@ -467,7 +467,7 @@ empathy_account_settings_migrate_password_cb (GObject *source,
GHashTable *empty;
const gchar *unset[] = { "password", NULL };
- if (!empathy_keyring_set_password_finish (account, result, &error))
+ if (!empathy_keyring_set_account_password_finish (account, result, &error))
{
DEBUG ("Failed to set password: %s", error->message);
g_clear_error (&error);
@@ -513,7 +513,7 @@ empathy_account_settings_try_migrating_password (EmpathyAccountSettings *self)
if (EMP_STR_EMPTY (password))
return;
- empathy_keyring_set_password_async (priv->account, password,
+ empathy_keyring_set_account_password_async (priv->account, password,
empathy_account_settings_migrate_password_cb, self);
/* We don't want to request the password again, we
@@ -624,7 +624,7 @@ empathy_account_settings_check_readyness (EmpathyAccountSettings *self)
/* Make this call but don't block on its readiness. We'll signal
* if it's updated later with ::password-retrieved. */
- empathy_keyring_get_password_async (priv->account,
+ empathy_keyring_get_account_password_async (priv->account,
empathy_account_settings_get_password_cb, self);
}
@@ -1401,7 +1401,7 @@ empathy_account_settings_set_password_cb (GObject *source,
gpointer user_data)
{
empathy_account_settings_processed_password (source, result, user_data,
- empathy_keyring_set_password_finish);
+ empathy_keyring_set_account_password_finish);
}
static void
@@ -1410,7 +1410,7 @@ empathy_account_settings_delete_password_cb (GObject *source,
gpointer user_data)
{
empathy_account_settings_processed_password (source, result, user_data,
- empathy_keyring_delete_password_finish);
+ empathy_keyring_delete_account_password_finish);
}
static void
@@ -1437,12 +1437,12 @@ empathy_account_settings_account_updated (GObject *source,
{
if (priv->password != NULL)
{
- empathy_keyring_set_password_async (priv->account, priv->password,
+ empathy_keyring_set_account_password_async (priv->account, priv->password,
empathy_account_settings_set_password_cb, settings);
}
else
{
- empathy_keyring_delete_password_async (priv->account,
+ empathy_keyring_delete_account_password_async (priv->account,
empathy_account_settings_delete_password_cb, settings);
}
diff --git a/libempathy/empathy-auth-factory.c b/libempathy/empathy-auth-factory.c
index 443962a7c..8cbb90a14 100644
--- a/libempathy/empathy-auth-factory.c
+++ b/libempathy/empathy-auth-factory.c
@@ -345,7 +345,7 @@ get_password_cb (GObject *source,
{
ObserveChannelsData *data = user_data;
- if (empathy_keyring_get_password_finish (TP_ACCOUNT (source), result, NULL) == NULL)
+ if (empathy_keyring_get_account_password_finish (TP_ACCOUNT (source), result, NULL) == NULL)
{
/* We don't actually mind if this fails, just let the approver
* go ahead and take the channel. */
@@ -404,7 +404,7 @@ observe_channels (TpBaseClient *client,
data->account = g_object_ref (account);
data->channel = g_object_ref (channel);
- empathy_keyring_get_password_async (account, get_password_cb, data);
+ empathy_keyring_get_account_password_async (account, get_password_cb, data);
tp_observe_channels_context_delay (context);
}
diff --git a/libempathy/empathy-keyring.c b/libempathy/empathy-keyring.c
index 4923a9463..f8422c151 100644
--- a/libempathy/empathy-keyring.c
+++ b/libempathy/empathy-keyring.c
@@ -24,15 +24,31 @@
#include <gnome-keyring.h>
+#include "empathy-utils.h"
+
#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
#include "empathy-debug.h"
-static GnomeKeyringPasswordSchema keyring_schema =
+static GnomeKeyringPasswordSchema account_keyring_schema =
{ GNOME_KEYRING_ITEM_GENERIC_SECRET,
{ { "account-id", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
{ "param-name", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
{ NULL } } };
+static GnomeKeyringPasswordSchema room_keyring_schema =
+ { GNOME_KEYRING_ITEM_GENERIC_SECRET,
+ { { "account-id", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
+ { "room-id", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
+ { NULL } } };
+
+gboolean
+empathy_keyring_is_available (void)
+{
+ return gnome_keyring_is_available ();
+}
+
+/* get */
+
static void
find_items_cb (GnomeKeyringResult result,
GList *list,
@@ -63,7 +79,7 @@ find_items_cb (GnomeKeyringResult result,
}
void
-empathy_keyring_get_password_async (TpAccount *account,
+empathy_keyring_get_account_password_async (TpAccount *account,
GAsyncReadyCallback callback,
gpointer user_data)
{
@@ -75,7 +91,7 @@ empathy_keyring_get_password_async (TpAccount *account,
g_return_if_fail (callback != NULL);
simple = g_simple_async_result_new (G_OBJECT (account), callback,
- user_data, empathy_keyring_get_password_async);
+ user_data, empathy_keyring_get_account_password_async);
account_id = tp_proxy_get_object_path (account) +
strlen (TP_ACCOUNT_OBJECT_PATH_BASE);
@@ -93,27 +109,60 @@ empathy_keyring_get_password_async (TpAccount *account,
gnome_keyring_attribute_list_free (match);
}
-const gchar *
-empathy_keyring_get_password_finish (TpAccount *account,
- GAsyncResult *result,
- GError **error)
+void
+empathy_keyring_get_room_password_async (TpAccount *account,
+ const gchar *id,
+ 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 (id != NULL);
+ g_return_if_fail (callback != NULL);
- g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL);
- g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL);
+ simple = g_simple_async_result_new (G_OBJECT (account), callback,
+ user_data, empathy_keyring_get_room_password_async);
- simple = G_SIMPLE_ASYNC_RESULT (result);
+ account_id = tp_proxy_get_object_path (account) +
+ strlen (TP_ACCOUNT_OBJECT_PATH_BASE);
- if (g_simple_async_result_propagate_error (simple, error))
- return NULL;
+ DEBUG ("Trying to get password for room '%s' on account '%s'",
+ id, account_id);
- g_return_val_if_fail (g_simple_async_result_is_valid (result,
- G_OBJECT (account), empathy_keyring_get_password_async), NULL);
+ match = gnome_keyring_attribute_list_new ();
+ gnome_keyring_attribute_list_append_string (match, "account-id",
+ account_id);
+ gnome_keyring_attribute_list_append_string (match, "room-id", id);
- return g_simple_async_result_get_op_res_gpointer (simple);
+ gnome_keyring_find_items (GNOME_KEYRING_ITEM_GENERIC_SECRET,
+ match, find_items_cb, simple, NULL);
+
+ gnome_keyring_attribute_list_free (match);
}
+const gchar *
+empathy_keyring_get_account_password_finish (TpAccount *account,
+ GAsyncResult *result,
+ GError **error)
+{
+ empathy_implement_finish_return_pointer (account,
+ empathy_keyring_get_account_password_async);
+}
+
+const gchar *
+empathy_keyring_get_room_password_finish (TpAccount *account,
+ GAsyncResult *result,
+ GError **error)
+{
+ empathy_implement_finish_return_pointer (account,
+ empathy_keyring_get_room_password_async);
+}
+
+/* set */
+
static void
store_password_cb (GnomeKeyringResult result,
gpointer user_data)
@@ -134,7 +183,7 @@ store_password_cb (GnomeKeyringResult result,
}
void
-empathy_keyring_set_password_async (TpAccount *account,
+empathy_keyring_set_account_password_async (TpAccount *account,
const gchar *password,
GAsyncReadyCallback callback,
gpointer user_data)
@@ -147,7 +196,7 @@ empathy_keyring_set_password_async (TpAccount *account,
g_return_if_fail (password != NULL);
simple = g_simple_async_result_new (G_OBJECT (account), callback,
- user_data, empathy_keyring_set_password_async);
+ user_data, empathy_keyring_set_account_password_async);
account_id = tp_proxy_get_object_path (account) +
strlen (TP_ACCOUNT_OBJECT_PATH_BASE);
@@ -157,7 +206,7 @@ empathy_keyring_set_password_async (TpAccount *account,
name = g_strdup_printf ("IM account password for %s (%s)",
tp_account_get_display_name (account), account_id);
- gnome_keyring_store_password (&keyring_schema, NULL, name, password,
+ gnome_keyring_store_password (&account_keyring_schema, NULL, name, password,
store_password_cb, simple, NULL,
"account-id", account_id,
"param-name", "password",
@@ -166,27 +215,59 @@ empathy_keyring_set_password_async (TpAccount *account,
g_free (name);
}
-gboolean
-empathy_keyring_set_password_finish (TpAccount *account,
- GAsyncResult *result,
- GError **error)
+void
+empathy_keyring_set_room_password_async (TpAccount *account,
+ const gchar *id,
+ const gchar *password,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
GSimpleAsyncResult *simple;
+ const gchar *account_id;
+ gchar *name;
- g_return_val_if_fail (TP_IS_ACCOUNT (account), FALSE);
- g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE);
+ g_return_if_fail (TP_IS_ACCOUNT (account));
+ g_return_if_fail (id != NULL);
+ g_return_if_fail (password != NULL);
+
+ simple = g_simple_async_result_new (G_OBJECT (account), callback,
+ user_data, empathy_keyring_set_room_password_async);
+
+ account_id = tp_proxy_get_object_path (account) +
+ strlen (TP_ACCOUNT_OBJECT_PATH_BASE);
- simple = G_SIMPLE_ASYNC_RESULT (result);
+ DEBUG ("Remembering password for room '%s' on account '%s'", id, account_id);
- if (g_simple_async_result_propagate_error (simple, error))
- return FALSE;
+ name = g_strdup_printf ("Password for chatroom '%s' on account %s (%s)",
+ id, tp_account_get_display_name (account), account_id);
- g_return_val_if_fail (g_simple_async_result_is_valid (result,
- G_OBJECT (account), empathy_keyring_set_password_async), FALSE);
+ gnome_keyring_store_password (&room_keyring_schema, NULL, name, password,
+ store_password_cb, simple, NULL,
+ "account-id", account_id,
+ "room-id", id,
+ NULL);
- return TRUE;
+ g_free (name);
+}
+
+gboolean
+empathy_keyring_set_account_password_finish (TpAccount *account,
+ GAsyncResult *result,
+ GError **error)
+{
+ empathy_implement_finish_void (account, empathy_keyring_set_account_password_async);
+}
+
+gboolean
+empathy_keyring_set_room_password_finish (TpAccount *account,
+ GAsyncResult *result,
+ GError **error)
+{
+ empathy_implement_finish_void (account, empathy_keyring_set_room_password_async);
}
+/* delete */
+
static void
item_delete_cb (GnomeKeyringResult result,
gpointer user_data)
@@ -234,7 +315,7 @@ find_item_to_delete_cb (GnomeKeyringResult result,
}
void
-empathy_keyring_delete_password_async (TpAccount *account,
+empathy_keyring_delete_account_password_async (TpAccount *account,
GAsyncReadyCallback callback,
gpointer user_data)
{
@@ -245,7 +326,7 @@ empathy_keyring_delete_password_async (TpAccount *account,
g_return_if_fail (TP_IS_ACCOUNT (account));
simple = g_simple_async_result_new (G_OBJECT (account), callback,
- user_data, empathy_keyring_delete_password_async);
+ user_data, empathy_keyring_delete_account_password_async);
account_id = tp_proxy_get_object_path (account) +
strlen (TP_ACCOUNT_OBJECT_PATH_BASE);
@@ -262,23 +343,10 @@ empathy_keyring_delete_password_async (TpAccount *account,
}
gboolean
-empathy_keyring_delete_password_finish (TpAccount *account,
+empathy_keyring_delete_account_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;
+ empathy_implement_finish_void (account, empathy_keyring_delete_account_password_async);
}
diff --git a/libempathy/empathy-keyring.h b/libempathy/empathy-keyring.h
index 000f987f7..92c8a6e9f 100644
--- a/libempathy/empathy-keyring.h
+++ b/libempathy/empathy-keyring.h
@@ -25,23 +25,39 @@
G_BEGIN_DECLS
-void empathy_keyring_get_password_async (TpAccount *account,
+gboolean empathy_keyring_is_available (void);
+
+void empathy_keyring_get_account_password_async (TpAccount *account,
+ GAsyncReadyCallback callback, gpointer user_data);
+
+const gchar * empathy_keyring_get_account_password_finish (TpAccount *account,
+ GAsyncResult *result, GError **error);
+
+void empathy_keyring_get_room_password_async (TpAccount *account,
+ const gchar *id,
GAsyncReadyCallback callback, gpointer user_data);
-const gchar * empathy_keyring_get_password_finish (TpAccount *account,
+const gchar * empathy_keyring_get_room_password_finish (TpAccount *account,
GAsyncResult *result, GError **error);
-void empathy_keyring_set_password_async (TpAccount *account,
+void empathy_keyring_set_account_password_async (TpAccount *account,
const gchar *password, GAsyncReadyCallback callback,
gpointer user_data);
-gboolean empathy_keyring_set_password_finish (TpAccount *account,
+gboolean empathy_keyring_set_account_password_finish (TpAccount *account,
+ GAsyncResult *result, GError **error);
+
+void empathy_keyring_set_room_password_async (TpAccount *account,
+ const gchar *id, const gchar *password, GAsyncReadyCallback callback,
+ gpointer user_data);
+
+gboolean empathy_keyring_set_room_password_finish (TpAccount *account,
GAsyncResult *result, GError **error);
-void empathy_keyring_delete_password_async (TpAccount *account,
+void empathy_keyring_delete_account_password_async (TpAccount *account,
GAsyncReadyCallback callback, gpointer user_data);
-gboolean empathy_keyring_delete_password_finish (TpAccount *account,
+gboolean empathy_keyring_delete_account_password_finish (TpAccount *account,
GAsyncResult *result, GError **error);
G_END_DECLS
diff --git a/libempathy/empathy-server-sasl-handler.c b/libempathy/empathy-server-sasl-handler.c
index 3cfc86fa8..4b5683881 100644
--- a/libempathy/empathy-server-sasl-handler.c
+++ b/libempathy/empathy-server-sasl-handler.c
@@ -124,7 +124,7 @@ empathy_server_sasl_handler_get_password_async_cb (GObject *source,
priv = EMPATHY_SERVER_SASL_HANDLER (user_data)->priv;
- password = empathy_keyring_get_password_finish (TP_ACCOUNT (source),
+ password = empathy_keyring_get_account_password_finish (TP_ACCOUNT (source),
result, &error);
if (password != NULL)
@@ -155,7 +155,7 @@ empathy_server_sasl_handler_init_async (GAsyncInitable *initable,
priv->async_init_res = g_simple_async_result_new (G_OBJECT (self),
callback, user_data, empathy_server_sasl_handler_new_async);
- empathy_keyring_get_password_async (priv->account,
+ empathy_keyring_get_account_password_async (priv->account,
empathy_server_sasl_handler_get_password_async_cb, self);
}
@@ -374,7 +374,7 @@ empathy_server_sasl_handler_set_password_cb (GObject *source,
{
GError *error = NULL;
- if (!empathy_keyring_set_password_finish (TP_ACCOUNT (source), result,
+ if (!empathy_keyring_set_account_password_finish (TP_ACCOUNT (source), result,
&error))
{
DEBUG ("Failed to set password: %s", error->message);
@@ -416,7 +416,7 @@ empathy_server_sasl_handler_provide_password (
if (remember)
{
- empathy_keyring_set_password_async (priv->account, password,
+ empathy_keyring_set_account_password_async (priv->account, password,
empathy_server_sasl_handler_set_password_cb, NULL);
}
}
diff --git a/libempathy/empathy-utils.h b/libempathy/empathy-utils.h
index 3c89962c1..f0ac666ed 100644
--- a/libempathy/empathy-utils.h
+++ b/libempathy/empathy-utils.h
@@ -107,6 +107,51 @@ gboolean empathy_connection_can_group_personas (TpConnection *connection);
gchar * empathy_get_x509_certificate_hostname (gnutls_x509_crt_t cert);
+/* Copied from wocky/wocky-utils.h */
+
+#define empathy_implement_finish_void(source, tag) \
+ if (g_simple_async_result_propagate_error (\
+ G_SIMPLE_ASYNC_RESULT (result), error)) \
+ return FALSE; \
+ g_return_val_if_fail (g_simple_async_result_is_valid (result, \
+ G_OBJECT(source), tag), \
+ FALSE); \
+ return TRUE;
+
+#define empathy_implement_finish_copy_pointer(source, tag, copy_func, \
+ out_param) \
+ GSimpleAsyncResult *_simple; \
+ _simple = (GSimpleAsyncResult *) 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 (source), tag), \
+ FALSE); \
+ if (out_param != NULL) \
+ *out_param = copy_func ( \
+ g_simple_async_result_get_op_res_gpointer (_simple)); \
+ return TRUE;
+
+#define empathy_implement_finish_return_copy_pointer(source, tag, copy_func) \
+ GSimpleAsyncResult *_simple; \
+ _simple = (GSimpleAsyncResult *) result; \
+ if (g_simple_async_result_propagate_error (_simple, error)) \
+ return NULL; \
+ g_return_val_if_fail (g_simple_async_result_is_valid (result, \
+ G_OBJECT (source), tag), \
+ NULL); \
+ return copy_func (g_simple_async_result_get_op_res_gpointer (_simple));
+
+#define empathy_implement_finish_return_pointer(source, tag) \
+ GSimpleAsyncResult *_simple; \
+ _simple = (GSimpleAsyncResult *) result; \
+ if (g_simple_async_result_propagate_error (_simple, error)) \
+ return NULL; \
+ g_return_val_if_fail (g_simple_async_result_is_valid (result, \
+ G_OBJECT (source), tag), \
+ NULL); \
+ return g_simple_async_result_get_op_res_gpointer (_simple);
+
G_END_DECLS
#endif /* __EMPATHY_UTILS_H__ */