aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.co.uk>2012-08-22 19:28:32 +0800
committerXavier Claessens <xavier.claessens@collabora.co.uk>2012-08-27 21:47:21 +0800
commit51507f03677306f35097e10c1e81d57961d05388 (patch)
treec72a24412806f81658aa23201c8889196234e241 /libempathy
parentd183765f18a915d889f4b6c6fc6a7f1692522809 (diff)
downloadgsoc2013-empathy-51507f03677306f35097e10c1e81d57961d05388.tar
gsoc2013-empathy-51507f03677306f35097e10c1e81d57961d05388.tar.gz
gsoc2013-empathy-51507f03677306f35097e10c1e81d57961d05388.tar.bz2
gsoc2013-empathy-51507f03677306f35097e10c1e81d57961d05388.tar.lz
gsoc2013-empathy-51507f03677306f35097e10c1e81d57961d05388.tar.xz
gsoc2013-empathy-51507f03677306f35097e10c1e81d57961d05388.tar.zst
gsoc2013-empathy-51507f03677306f35097e10c1e81d57961d05388.zip
Move X-TELEPATHY-PASSWORD mechanism code into empathy-sasl-mechanisms.c
https://bugzilla.gnome.org/show_bug.cgi?id=680776
Diffstat (limited to 'libempathy')
-rw-r--r--libempathy/empathy-sasl-mechanisms.c35
-rw-r--r--libempathy/empathy-sasl-mechanisms.h6
-rw-r--r--libempathy/empathy-server-sasl-handler.c106
3 files changed, 67 insertions, 80 deletions
diff --git a/libempathy/empathy-sasl-mechanisms.c b/libempathy/empathy-sasl-mechanisms.c
index 2857c8b6a..b900fa5da 100644
--- a/libempathy/empathy-sasl-mechanisms.c
+++ b/libempathy/empathy-sasl-mechanisms.c
@@ -31,6 +31,7 @@
#define MECH_FACEBOOK "X-FACEBOOK-PLATFORM"
#define MECH_WLM "X-MESSENGER-OAUTH2"
#define MECH_GOOGLE "X-OAUTH2"
+#define MECH_PASSWORD "X-TELEPATHY-PASSWORD"
typedef struct
{
@@ -42,6 +43,10 @@ static SupportedMech supported_mechanisms[] = {
{ EMPATHY_SASL_MECHANISM_FACEBOOK, MECH_FACEBOOK },
{ EMPATHY_SASL_MECHANISM_WLM, MECH_WLM },
{ EMPATHY_SASL_MECHANISM_GOOGLE, MECH_GOOGLE },
+
+ /* Must be the last one, otherwise empathy_sasl_channel_select_mechanism()
+ * will prefer password over web auth for servers supporting both. */
+ { EMPATHY_SASL_MECHANISM_PASSWORD, MECH_PASSWORD }
};
static void
@@ -297,6 +302,36 @@ empathy_sasl_auth_google_async (TpChannel *channel,
g_object_unref (result);
}
+void
+empathy_sasl_auth_password_async (TpChannel *channel,
+ const gchar *password,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+ GArray *password_array;
+
+ result = empathy_sasl_auth_common_async (channel, callback, user_data);
+
+ g_return_if_fail (result != NULL);
+ g_return_if_fail (empathy_sasl_channel_supports_mechanism (channel,
+ MECH_PASSWORD));
+ g_return_if_fail (!tp_str_empty (password));
+
+ DEBUG ("Start %s mechanism", MECH_PASSWORD);
+
+ password_array = g_array_sized_new (FALSE, FALSE, sizeof (gchar),
+ strlen (password));
+ g_array_append_vals (password_array, password, strlen (password));
+
+ tp_cli_channel_interface_sasl_authentication_call_start_mechanism_with_data (
+ channel, -1, MECH_PASSWORD, password_array,
+ generic_cb, g_object_ref (result), g_object_unref, NULL);
+
+ g_array_unref (password_array);
+ g_object_unref (result);
+}
+
gboolean
empathy_sasl_auth_finish (TpChannel *channel,
GAsyncResult *result,
diff --git a/libempathy/empathy-sasl-mechanisms.h b/libempathy/empathy-sasl-mechanisms.h
index f0ac12343..ef7ccd6db 100644
--- a/libempathy/empathy-sasl-mechanisms.h
+++ b/libempathy/empathy-sasl-mechanisms.h
@@ -31,6 +31,7 @@ typedef enum
EMPATHY_SASL_MECHANISM_FACEBOOK,
EMPATHY_SASL_MECHANISM_WLM,
EMPATHY_SASL_MECHANISM_GOOGLE,
+ EMPATHY_SASL_MECHANISM_PASSWORD,
} EmpathySaslMechanism;
void empathy_sasl_auth_facebook_async (TpChannel *channel,
@@ -50,6 +51,11 @@ void empathy_sasl_auth_google_async (TpChannel *channel,
GAsyncReadyCallback callback,
gpointer user_data);
+void empathy_sasl_auth_password_async (TpChannel *channel,
+ const gchar *password,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
gboolean empathy_sasl_auth_finish (TpChannel *channel,
GAsyncResult *result,
GError **error);
diff --git a/libempathy/empathy-server-sasl-handler.c b/libempathy/empathy-server-sasl-handler.c
index db7ba1be8..bc139df30 100644
--- a/libempathy/empathy-server-sasl-handler.c
+++ b/libempathy/empathy-server-sasl-handler.c
@@ -30,6 +30,7 @@
#define DEBUG_FLAG EMPATHY_DEBUG_SASL
#include "empathy-debug.h"
#include "empathy-keyring.h"
+#include "empathy-sasl-mechanisms.h"
enum {
PROP_CHANNEL = 1,
@@ -64,16 +65,6 @@ G_DEFINE_TYPE_WITH_CODE (EmpathyServerSASLHandler, empathy_server_sasl_handler,
G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, async_initable_iface_init));
-static const gchar *sasl_statuses[] = {
- "not started",
- "in progress",
- "server succeeded",
- "client accepted",
- "succeeded",
- "server failed",
- "client failed",
-};
-
static void
empathy_server_sasl_handler_set_password_cb (GObject *source,
GAsyncResult *result,
@@ -93,52 +84,6 @@ empathy_server_sasl_handler_set_password_cb (GObject *source,
}
}
-static void
-sasl_status_changed_cb (TpChannel *channel,
- TpSASLStatus status,
- const gchar *error,
- GHashTable *details,
- gpointer user_data,
- GObject *weak_object)
-{
- EmpathyServerSASLHandler *self = EMPATHY_SERVER_SASL_HANDLER (weak_object);
- EmpathyServerSASLHandlerPriv *priv = EMPATHY_SERVER_SASL_HANDLER (weak_object)->priv;
-
- /* buh boh */
- if (status >= G_N_ELEMENTS (sasl_statuses))
- {
- DEBUG ("SASL status changed to unknown status");
- return;
- }
-
- DEBUG ("SASL status changed to '%s'", sasl_statuses[status]);
-
- if (status == TP_SASL_STATUS_SERVER_SUCCEEDED)
- {
- empathy_keyring_set_account_password_async (priv->account,
- priv->password, priv->save_password,
- empathy_server_sasl_handler_set_password_cb,
- NULL);
-
- DEBUG ("Calling AcceptSASL");
- tp_cli_channel_interface_sasl_authentication_call_accept_sasl (
- priv->channel, -1, NULL, NULL, NULL, NULL);
- }
- else if (status == TP_SASL_STATUS_SUCCEEDED)
- {
- DEBUG ("SASL succeeded, calling Close");
- tp_cli_channel_call_close (priv->channel, -1,
- NULL, NULL, NULL, NULL);
- }
- else if (status == TP_SASL_STATUS_SERVER_FAILED)
- {
- if (!tp_strdiff (error, TP_ERROR_STR_AUTHENTICATION_FAILED))
- {
- g_signal_emit (self, signals[AUTH_PASSWORD_FAILED], 0, priv->password);
- }
- }
-}
-
static gboolean
empathy_server_sasl_handler_give_password (gpointer data)
{
@@ -232,9 +177,6 @@ empathy_server_sasl_handler_constructed (GObject *object)
EmpathyServerSASLHandlerPriv *priv = EMPATHY_SERVER_SASL_HANDLER (object)->priv;
GError *error = NULL;
- tp_cli_channel_interface_sasl_authentication_connect_to_sasl_status_changed (
- priv->channel, sasl_status_changed_cb, NULL, NULL, object, &error);
-
if (error != NULL)
{
DEBUG ("Failed to connect to SASLStatusChanged: %s", error->message);
@@ -398,18 +340,33 @@ empathy_server_sasl_handler_new_async (TpAccount *account,
}
static void
-start_mechanism_with_data_cb (TpChannel *proxy,
- const GError *error,
- gpointer user_data,
- GObject *weak_object)
+auth_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
{
- if (error != NULL)
+ EmpathyServerSASLHandler *self = user_data;
+ EmpathyServerSASLHandlerPriv *priv = self->priv;
+ GError *error = NULL;
+
+ if (!empathy_sasl_auth_finish (priv->channel, result, &error))
+ {
+ if (g_error_matches (error, TP_ERROR, TP_ERROR_AUTHENTICATION_FAILED))
+ {
+ g_signal_emit (self, signals[AUTH_PASSWORD_FAILED], 0, priv->password);
+ }
+ g_clear_error (&error);
+ }
+ else
{
- DEBUG ("Failed to start mechanism: %s", error->message);
- return;
+ DEBUG ("Saving password in keyring");
+ empathy_keyring_set_account_password_async (priv->account,
+ priv->password, priv->save_password,
+ empathy_server_sasl_handler_set_password_cb,
+ NULL);
}
- DEBUG ("Started mechanism successfully");
+ tp_channel_close_async (priv->channel, NULL, NULL);
+ g_object_unref (self);
}
void
@@ -419,25 +376,14 @@ empathy_server_sasl_handler_provide_password (
gboolean remember)
{
EmpathyServerSASLHandlerPriv *priv;
- GArray *array;
gboolean may_save_response, may_save_response_valid;
g_return_if_fail (EMPATHY_IS_SERVER_SASL_HANDLER (handler));
priv = handler->priv;
- array = g_array_sized_new (TRUE, FALSE,
- sizeof (gchar), strlen (password));
-
- g_array_append_vals (array, password, strlen (password));
-
- DEBUG ("Calling StartMechanismWithData with our password");
-
- tp_cli_channel_interface_sasl_authentication_call_start_mechanism_with_data (
- priv->channel, -1, "X-TELEPATHY-PASSWORD", array,
- start_mechanism_with_data_cb, NULL, NULL, G_OBJECT (handler));
-
- g_array_unref (array);
+ empathy_sasl_auth_password_async (priv->channel, password,
+ auth_cb, g_object_ref (handler));
DEBUG ("%sremembering the password", remember ? "" : "not ");