]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-auth-factory.c
libempathy-gtk: fix uninitialized variable
[empathy.git] / libempathy / empathy-auth-factory.c
index fb178216d5412c2a77c90020b5346a1d968e6c79..04e619bd03cf20942c6c1f98c2a5edaa5c2c2acb 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include <config.h>
-
+#include "config.h"
 #include "empathy-auth-factory.h"
 
-#include <telepathy-glib/telepathy-glib.h>
+#include <telepathy-glib/telepathy-glib-dbus.h>
+#include <tp-account-widgets/tpaw-keyring.h>
 
-#define DEBUG_FLAG EMPATHY_DEBUG_TLS
-#include "empathy-debug.h"
-#include "empathy-keyring.h"
+#include "empathy-sasl-mechanisms.h"
 #include "empathy-server-sasl-handler.h"
 #include "empathy-server-tls-handler.h"
 #include "empathy-utils.h"
 #include "empathy-goa-auth-handler.h"
 #endif /* HAVE_GOA */
 
-#include "extensions/extensions.h"
+#ifdef HAVE_UOA
+#include "empathy-uoa-auth-handler.h"
+#endif /* HAVE_UOA */
+
+#define DEBUG_FLAG EMPATHY_DEBUG_TLS
+#include "empathy-debug.h"
 
 G_DEFINE_TYPE (EmpathyAuthFactory, empathy_auth_factory, TP_TYPE_BASE_CLIENT);
 
@@ -53,6 +56,10 @@ struct _EmpathyAuthFactoryPriv {
   EmpathyGoaAuthHandler *goa_handler;
 #endif /* HAVE_GOA */
 
+#ifdef HAVE_UOA
+  EmpathyUoaAuthHandler *uoa_handler;
+#endif /* HAVE_UOA */
+
   /* If an account failed to connect and user enters a new password to try, we
    * store it in this hash table and will try to use it next time the account
    * attemps to connect.
@@ -274,7 +281,7 @@ common_checks (EmpathyAuthFactory *self,
        * ServerTLSConnection channels. */
       if (observe
           || tp_channel_get_channel_type_id (channel) !=
-          EMP_IFACE_QUARK_CHANNEL_TYPE_SERVER_TLS_CONNECTION)
+          TP_IFACE_QUARK_CHANNEL_TYPE_SERVER_TLS_CONNECTION)
         {
           g_set_error (error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
               "Can only %s ServerTLSConnection or ServerAuthentication channels, "
@@ -356,7 +363,7 @@ handle_channels (TpBaseClient *handler,
 
   /* create a handler */
   if (tp_channel_get_channel_type_id (channel) ==
-      EMP_IFACE_QUARK_CHANNEL_TYPE_SERVER_TLS_CONNECTION)
+      TP_IFACE_QUARK_CHANNEL_TYPE_SERVER_TLS_CONNECTION)
     {
       empathy_server_tls_handler_new_async (channel, server_tls_handler_ready_cb,
           data);
@@ -424,7 +431,7 @@ get_password_cb (GObject *source,
 {
   ObserveChannelsData *data = user_data;
 
-  if (empathy_keyring_get_account_password_finish (TP_ACCOUNT (source), result, NULL) == NULL)
+  if (tpaw_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. */
@@ -473,6 +480,32 @@ goa_claim_cb (GObject *source,
 }
 #endif /* HAVE_GOA */
 
+#ifdef HAVE_UOA
+static void
+uoa_claim_cb (GObject *source,
+    GAsyncResult *result,
+    gpointer user_data)
+{
+  ObserveChannelsData *data = user_data;
+  EmpathyAuthFactory *self = data->self;
+  GError *error = NULL;
+
+  if (!tp_channel_dispatch_operation_claim_with_finish (data->dispatch_operation,
+          result, &error))
+    {
+      DEBUG ("Failed to claim: %s", error->message);
+      g_clear_error (&error);
+    }
+  else
+    {
+      empathy_uoa_auth_handler_start (self->priv->uoa_handler,
+          data->channel, data->account);
+    }
+
+  observe_channels_data_free (data);
+}
+#endif /* HAVE_UOA */
+
 static void
 observe_channels (TpBaseClient *client,
     TpAccount *account,
@@ -521,6 +554,20 @@ observe_channels (TpBaseClient *client,
     }
 #endif /* HAVE_GOA */
 
+#ifdef HAVE_UOA
+  /* UOA auth? */
+  if (empathy_uoa_auth_handler_supports (self->priv->uoa_handler, channel, account))
+    {
+      DEBUG ("Supported UOA account (%s), claim SASL channel",
+          tp_proxy_get_object_path (account));
+
+      tp_channel_dispatch_operation_claim_with_async (dispatch_operation,
+          client, uoa_claim_cb, data);
+      tp_observe_channels_context_accept (context);
+      return;
+    }
+#endif /* HAVE_UOA */
+
   /* Password auth? */
   if (empathy_sasl_channel_supports_mechanism (data->channel,
           "X-TELEPATHY-PASSWORD"))
@@ -537,7 +584,7 @@ observe_channels (TpBaseClient *client,
           return;
         }
 
-      empathy_keyring_get_account_password_async (data->account,
+      tpaw_keyring_get_account_password_async (data->account,
           get_password_cb, data);
       tp_observe_channels_context_delay (context);
       return;
@@ -588,6 +635,10 @@ empathy_auth_factory_init (EmpathyAuthFactory *self)
   self->priv->goa_handler = empathy_goa_auth_handler_new ();
 #endif /* HAVE_GOA */
 
+#ifdef HAVE_UOA
+  self->priv->uoa_handler = empathy_uoa_auth_handler_new ();
+#endif /* HAVE_UOA */
+
   self->priv->retry_passwords = g_hash_table_new_full (NULL, NULL,
       g_object_unref, g_free);
 }
@@ -607,7 +658,7 @@ empathy_auth_factory_constructed (GObject *obj)
   tp_base_client_take_handler_filter (client, tp_asv_new (
           /* ChannelType */
           TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
-          EMP_IFACE_CHANNEL_TYPE_SERVER_TLS_CONNECTION,
+          TP_IFACE_CHANNEL_TYPE_SERVER_TLS_CONNECTION,
           /* AuthenticationMethod */
           TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT,
           TP_HANDLE_TYPE_NONE, NULL));
@@ -656,6 +707,10 @@ empathy_auth_factory_dispose (GObject *object)
   g_object_unref (priv->goa_handler);
 #endif /* HAVE_GOA */
 
+#ifdef HAVE_UOA
+  g_object_unref (priv->uoa_handler);
+#endif /* HAVE_UOA */
+
   g_hash_table_unref (priv->retry_passwords);
 
   G_OBJECT_CLASS (empathy_auth_factory_parent_class)->dispose (object);