]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-server-sasl-handler.c
Updated Spanish Translation
[empathy.git] / libempathy / empathy-server-sasl-handler.c
index bc139df303bfa58a3e39de6dfa83f87f5040dead..c29e0ba927ffb5aabcc1007a146f9229697be878 100644 (file)
  */
 
 #include "config.h"
-
 #include "empathy-server-sasl-handler.h"
 
-#include <telepathy-glib/telepathy-glib.h>
-
-#include <extensions/extensions.h>
+#include <tp-account-widgets/tpaw-keyring.h>
+#include <telepathy-glib/telepathy-glib-dbus.h>
 
-#include <string.h>
+#include "empathy-sasl-mechanisms.h"
+#include "extensions.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_SASL
 #include "empathy-debug.h"
-#include "empathy-keyring.h"
-#include "empathy-sasl-mechanisms.h"
 
 enum {
   PROP_CHANNEL = 1,
@@ -72,7 +69,7 @@ empathy_server_sasl_handler_set_password_cb (GObject *source,
 {
   GError *error = NULL;
 
-  if (!empathy_keyring_set_account_password_finish (TP_ACCOUNT (source), result,
+  if (!tpaw_keyring_set_account_password_finish (TP_ACCOUNT (source), result,
           &error))
     {
       DEBUG ("Failed to set password: %s", error->message);
@@ -107,7 +104,7 @@ empathy_server_sasl_handler_get_password_async_cb (GObject *source,
 
   priv = EMPATHY_SERVER_SASL_HANDLER (user_data)->priv;
 
-  password = empathy_keyring_get_account_password_finish (TP_ACCOUNT (source),
+  password = tpaw_keyring_get_account_password_finish (TP_ACCOUNT (source),
       result, &error);
 
   if (password != NULL)
@@ -138,7 +135,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_account_password_async (priv->account,
+  tpaw_keyring_get_account_password_async (priv->account,
       empathy_server_sasl_handler_get_password_async_cb, self);
 }
 
@@ -359,7 +356,7 @@ auth_cb (GObject *source,
   else
     {
       DEBUG ("Saving password in keyring");
-      empathy_keyring_set_account_password_async (priv->account,
+      tpaw_keyring_set_account_password_async (priv->account,
           priv->password, priv->save_password,
           empathy_server_sasl_handler_set_password_cb,
           NULL);
@@ -369,6 +366,27 @@ auth_cb (GObject *source,
   g_object_unref (self);
 }
 
+static gboolean
+channel_has_may_save_response (TpChannel *channel)
+{
+  /* determine if we are permitted to save the password locally */
+  GVariant *props;
+  gboolean may_save_response;
+
+  props = tp_channel_dup_immutable_properties (channel);
+
+  if (!g_variant_lookup (props,
+        TP_PROP_CHANNEL_INTERFACE_SASL_AUTHENTICATION_MAY_SAVE_RESPONSE,
+        "b", &may_save_response))
+    {
+      DEBUG ("MaySaveResponse unknown, assuming TRUE");
+      may_save_response = TRUE;
+    }
+
+  g_variant_unref (props);
+  return may_save_response;
+}
+
 void
 empathy_server_sasl_handler_provide_password (
     EmpathyServerSASLHandler *handler,
@@ -376,7 +394,7 @@ empathy_server_sasl_handler_provide_password (
     gboolean remember)
 {
   EmpathyServerSASLHandlerPriv *priv;
-  gboolean may_save_response, may_save_response_valid;
+  gboolean may_save_response;
 
   g_return_if_fail (EMPATHY_IS_SERVER_SASL_HANDLER (handler));
 
@@ -387,17 +405,7 @@ empathy_server_sasl_handler_provide_password (
 
   DEBUG ("%sremembering the password", remember ? "" : "not ");
 
-  /* determine if we are permitted to save the password locally */
-  may_save_response = tp_asv_get_boolean (
-      tp_channel_borrow_immutable_properties (priv->channel),
-      TP_PROP_CHANNEL_INTERFACE_SASL_AUTHENTICATION_MAY_SAVE_RESPONSE,
-      &may_save_response_valid);
-
-  if (!may_save_response_valid)
-    {
-      DEBUG ("MaySaveResponse unknown, assuming TRUE");
-      may_save_response = TRUE;
-    }
+  may_save_response = channel_has_may_save_response (priv->channel);
 
   if (remember)
     {
@@ -423,7 +431,7 @@ empathy_server_sasl_handler_provide_password (
   if (!may_save_response)
     {
       /* delete any password present, it shouldn't be there */
-      empathy_keyring_delete_account_password_async (priv->account, NULL, NULL);
+      tpaw_keyring_delete_account_password_async (priv->account, NULL, NULL);
     }
 
   /* Additionally, if we implement Ch.I.CredentialsStorage, inform that
@@ -501,24 +509,14 @@ empathy_server_sasl_handler_can_save_response_somewhere (
     EmpathyServerSASLHandler *self)
 {
   EmpathyServerSASLHandlerPriv *priv;
-  gboolean may_save_response, may_save_response_valid;
+  gboolean may_save_response;
   gboolean has_storage_iface;
 
   g_return_val_if_fail (EMPATHY_IS_SERVER_SASL_HANDLER (self), FALSE);
 
   priv = self->priv;
 
-  /* determine if we are permitted to save the password locally */
-  may_save_response = tp_asv_get_boolean (
-      tp_channel_borrow_immutable_properties (priv->channel),
-      TP_PROP_CHANNEL_INTERFACE_SASL_AUTHENTICATION_MAY_SAVE_RESPONSE,
-      &may_save_response_valid);
-
-  if (!may_save_response_valid)
-    {
-      DEBUG ("MaySaveResponse unknown, assuming TRUE");
-      may_save_response = TRUE;
-    }
+  may_save_response = channel_has_may_save_response (priv->channel);
 
   has_storage_iface = tp_proxy_has_interface_by_id (priv->channel,
       EMP_IFACE_QUARK_CHANNEL_INTERFACE_CREDENTIALS_STORAGE);