From f7adeabe6fb2fff210ba309eecc8d2500b0b6223 Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Tue, 9 Apr 2013 19:30:34 +0300 Subject: [PATCH] request: handle purple_account_request_password() This is needed for libpurple plugins with optional password, e.g. SIPE since 1.14.1. That libpurple API call boils down to a purple_request_fields() call. NOTE: this requires ./configure --enable-leaky-request-stubs --- src/connection.c | 35 +++++++++++++++++++++++++++++++---- src/connection.h | 3 +++ src/request.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++---- src/request.h | 3 +++ 4 files changed, 88 insertions(+), 8 deletions(-) diff --git a/src/connection.c b/src/connection.c index 3ec4c8e..9305c05 100644 --- a/src/connection.c +++ b/src/connection.c @@ -42,6 +42,7 @@ #include "connection-avatars.h" #include "connection-mail.h" #include "extensions/extensions.h" +#include "request.h" #include "connection-capabilities.h" @@ -135,6 +136,9 @@ struct _HazeConnectionPrivate gchar *prpl_id; PurplePluginProtocolInfo *prpl_info; + /* Set if purple_account_request_password() was called */ + gpointer password_request; + /* Set if purple_account_disconnect has been called or is scheduled to be * called, so should not be called again. */ @@ -443,6 +447,11 @@ _haze_connection_password_manager_prompt_cb (GObject *source, { DEBUG ("Simple password manager failed: %s", error->message); + if (priv->password_request) { + priv->disconnecting = TRUE; + haze_request_password_cb(priv->password_request, NULL); + } + if (base_conn->status != TP_CONNECTION_STATUS_DISCONNECTED) { tp_base_connection_disconnect_with_dbus_error (base_conn, @@ -460,11 +469,15 @@ _haze_connection_password_manager_prompt_cb (GObject *source, g_free (priv->password); priv->password = g_strdup (password->str); - purple_account_set_password (self->account, priv->password); + if (priv->password_request) { + haze_request_password_cb(priv->password_request, priv->password); + } else { + purple_account_set_password (self->account, priv->password); - purple_account_set_enabled(self->account, UI_ID, TRUE); - purple_account_connect (self->account); - priv->connect_called = TRUE; + purple_account_set_enabled(self->account, UI_ID, TRUE); + purple_account_connect (self->account); + priv->connect_called = TRUE; + } } static gboolean @@ -513,6 +526,20 @@ _haze_connection_start_connecting (TpBaseConnection *base, return TRUE; } +void haze_connection_request_password (PurpleAccount *account, + void *user_data) +{ + HazeConnection *self = ACCOUNT_GET_HAZE_CONNECTION (account); + HazeConnectionPrivate *priv = self->priv; + + priv->password_request = user_data; + + /* pop up auth channel */ + tp_simple_password_manager_prompt_async (self->password_manager, + _haze_connection_password_manager_prompt_cb, + self); +} + static void _haze_connection_shut_down (TpBaseConnection *base) { diff --git a/src/connection.h b/src/connection.h index a75732a..ae587ab 100644 --- a/src/connection.h +++ b/src/connection.h @@ -109,6 +109,9 @@ const gchar *haze_get_fallback_group (void); const gchar **haze_connection_get_implemented_interfaces (void); const gchar **haze_connection_get_guaranteed_interfaces (void); +void haze_connection_request_password (PurpleAccount *account, + gpointer user_data); + G_END_DECLS #endif /* #ifndef __HAZE_CONNECTION_H__*/ diff --git a/src/request.c b/src/request.c index 408678b..fcc1f68 100644 --- a/src/request.c +++ b/src/request.c @@ -96,6 +96,31 @@ haze_request_action (const char *title, return NULL; } +struct password_data { + PurpleAccount *account; + PurpleRequestFields *fields; + PurpleRequestField *password; + GCallback ok_cb; + GCallback cancel_cb; + void *user_data; +}; + +void haze_request_password_cb (gpointer user_data, + const gchar *password) +{ + struct password_data *pd = user_data; + + if (password) { + purple_request_field_string_set_value(pd->password, password); + ((PurpleRequestInputCb)pd->ok_cb)(pd->user_data, pd->fields); + } else { + ((PurpleRequestInputCb)pd->cancel_cb)(pd->user_data, pd->fields); + purple_account_disconnect(pd->account); + } + + g_free(pd); +} + static gpointer haze_request_fields (const char *title, const char *primary, @@ -110,10 +135,32 @@ haze_request_fields (const char *title, PurpleConversation *conv, void *user_data) { - DEBUG ("ignoring request:"); - DEBUG (" title: %s", (title ? title : "(null)")); - DEBUG (" primary: %s", (primary ? primary : "(null)")); - DEBUG (" secondary: %s", (secondary ? secondary : "(null)")); + /* + * We must support purple_account_request_password() which boils down + * to purple_request_fields() with certain parameters. I'm not sure + * if this the best way of doing this, but it works. + */ + if (purple_request_fields_exists(fields, "password") && + purple_request_fields_exists(fields, "remember")) { + struct password_data *pd = g_new0(struct password_data, 1); + + DEBUG ("triggering password request"); + + pd->account = account; + pd->fields = fields; + pd->password = purple_request_fields_get_field(fields, "password"); + pd->ok_cb = ok_cb; + pd->cancel_cb = cancel_cb; + pd->user_data = user_data; + + haze_connection_request_password(account, pd); + + } else { + DEBUG ("ignoring request:"); + DEBUG (" title: %s", (title ? title : "(null)")); + DEBUG (" primary: %s", (primary ? primary : "(null)")); + DEBUG (" secondary: %s", (secondary ? secondary : "(null)")); + } return NULL; } diff --git a/src/request.h b/src/request.h index d896cc6..cc572d6 100644 --- a/src/request.h +++ b/src/request.h @@ -20,4 +20,7 @@ #include +void haze_request_password_cb (gpointer user_data, + const gchar *password); + PurpleRequestUiOps *haze_request_get_ui_ops (void); -- 1.8.1.4