summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonny Lamb <jonny.lamb@collabora.co.uk>2010-11-24 16:26:08 +0000
committerDavid Laban <david.laban@collabora.co.uk>2010-12-15 14:34:32 +0000
commit7fd45d95dc7909585976670a77243a175d977734 (patch)
tree3039b8af5966731a96fade4016d10b9af436a0cf
parentd8e180b6f802cccea36fee81714d82203cba1f5b (diff)
connection: use TpSimplePasswordManager to get a password if one was not given
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
-rw-r--r--src/sip-connection-private.h3
-rw-r--r--src/sip-connection.c46
2 files changed, 48 insertions, 1 deletions
diff --git a/src/sip-connection-private.h b/src/sip-connection-private.h
index 6a7efcf..2250694 100644
--- a/src/sip-connection-private.h
+++ b/src/sip-connection-private.h
@@ -27,6 +27,8 @@
#include <tpsip/sofia-decls.h>
#include <sofia-sip/sresolv.h>
+#include <telepathy-glib/simple-password-manager.h>
+
#ifdef HAVE_LIBIPHB
#include <libiphb.h>
#endif
@@ -51,6 +53,7 @@ struct _TpsipConnectionPrivate
gchar *registrar_realm;
TpsipMediaFactory *media_factory;
+ TpSimplePasswordManager *password_manager;
gchar *address;
gchar *auth_user;
diff --git a/src/sip-connection.c b/src/sip-connection.c
index d383dfb..da73e63 100644
--- a/src/sip-connection.c
+++ b/src/sip-connection.c
@@ -160,6 +160,10 @@ tpsip_connection_create_channel_managers (TpBaseConnection *conn)
"connection", self, NULL);
g_ptr_array_add (channel_managers, priv->media_factory);
+ priv->password_manager = tp_simple_password_manager_new (
+ conn);
+ g_ptr_array_add (channel_managers, priv->password_manager);
+
return channel_managers;
}
@@ -881,6 +885,38 @@ tpsip_connection_finalize (GObject *obj)
G_OBJECT_CLASS (tpsip_connection_parent_class)->finalize (obj);
}
+static void
+_password_manager_prompt_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ TpsipConnection *self = user_data;
+ TpsipConnectionPrivate *priv = TPSIP_CONNECTION_GET_PRIVATE (self);
+ TpBaseConnection *base_conn = (TpBaseConnection *) self;
+ GError *error = NULL;
+ const GString *password;
+
+ password = tp_simple_password_manager_prompt_finish (
+ TP_SIMPLE_PASSWORD_MANAGER (source_object), result, &error);
+
+ if (error != NULL)
+ {
+ DEBUG ("Auth channel failed: %s", error->message);
+
+ tp_base_connection_change_status (base_conn,
+ TP_CONNECTION_STATUS_DISCONNECTED,
+ TP_CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED);
+
+ g_error_free (error);
+ return;
+ }
+
+ g_free (priv->password);
+ priv->password = g_strdup (password->str);
+
+ nua_register (priv->register_op, TAG_NULL());
+}
+
static gboolean
tpsip_connection_start_connecting (TpBaseConnection *base,
GError **error)
@@ -977,7 +1013,15 @@ tpsip_connection_start_connecting (TpBaseConnection *base,
tpsip_event_target_attach (priv->register_op, (GObject *) self);
- nua_register (priv->register_op, TAG_NULL());
+ if (priv->password != NULL)
+ {
+ nua_register (priv->register_op, TAG_NULL());
+ }
+ else
+ {
+ tp_simple_password_manager_prompt_async (priv->password_manager,
+ _password_manager_prompt_cb, self);
+ }
return TRUE;
}