aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy
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 /libempathy
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'
Diffstat (limited to 'libempathy')
-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
6 files changed, 196 insertions, 67 deletions
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__ */