summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Becker <chemobejk@gmail.com>2013-04-09 19:30:34 +0300
committerWill Thompson <will.thompson@collabora.co.uk>2013-04-11 19:42:00 +0100
commit66b7fff2f65b65a5d298bf868bb8e21a32492a58 (patch)
tree2ac20ade50ac8e8963eb3ee6509e90cca88bf026
parent1fe98b1bede98c4935f76a514a3943546a869c02 (diff)
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. The flagging for --enable-leaky-request-stubs was refactored so that this new code is always compiled in. https://bugs.freedesktop.org/show_bug.cgi?id=63326
-rw-r--r--src/connection.c45
-rw-r--r--src/connection.h3
-rw-r--r--src/main.c2
-rw-r--r--src/request.c66
-rw-r--r--src/request.h3
5 files changed, 105 insertions, 14 deletions
diff --git a/src/connection.c b/src/connection.c
index 0b272a9..6e9121d 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"
@@ -138,6 +139,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.
*/
@@ -446,6 +450,11 @@ _haze_connection_password_manager_prompt_cb (GObject *source,
{
DEBUG ("Simple password manager failed: %s", error->message);
+ if (priv->password_request)
+ {
+ 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,
@@ -454,7 +463,13 @@ _haze_connection_password_manager_prompt_cb (GObject *source,
}
/* no need to call purple_account_disconnect because _connect
- * was never called */
+ * was never called ...
+ * ... unless we had a dynamic password request */
+ if (priv->password_request)
+ {
+ priv->disconnecting = TRUE;
+ purple_account_disconnect (self->account);
+ }
g_error_free (error);
return;
@@ -463,11 +478,17 @@ _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
@@ -516,6 +537,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 c69a7c1..2e68935 100644
--- a/src/connection.h
+++ b/src/connection.h
@@ -111,6 +111,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/main.c b/src/main.c
index afa0a02..4cd171c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -141,9 +141,7 @@ haze_ui_init (void)
purple_accounts_set_ui_ops (haze_get_account_ui_ops ());
purple_conversations_set_ui_ops (haze_get_conv_ui_ops ());
purple_connections_set_ui_ops (haze_get_connection_ui_ops ());
-#ifdef ENABLE_LEAKY_REQUEST_STUBS
purple_request_set_ui_ops (haze_request_get_ui_ops ());
-#endif
purple_notify_set_ui_ops (haze_notify_get_ui_ops ());
purple_privacy_set_ui_ops (haze_get_privacy_ui_ops ());
}
diff --git a/src/request.c b/src/request.c
index 408678b..dae859d 100644
--- a/src/request.c
+++ b/src/request.c
@@ -18,6 +18,8 @@
*
*/
+#include "config.h"
+
#include <glib-object.h>
#include <libpurple/account.h>
@@ -25,7 +27,9 @@
#include "debug.h"
#include "request.h"
+#include "connection.h"
+#ifdef ENABLE_LEAKY_REQUEST_STUBS
static gpointer
haze_request_input (const char *title,
const char *primary,
@@ -95,6 +99,30 @@ haze_request_action (const char *title,
return NULL;
}
+#endif
+
+struct password_data {
+ 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);
+ ((PurpleRequestFieldsCb)pd->ok_cb)(pd->user_data, pd->fields);
+ } else {
+ ((PurpleRequestFieldsCb)pd->cancel_cb)(pd->user_data, pd->fields);
+ }
+
+ g_free(pd);
+}
static gpointer
haze_request_fields (const char *title,
@@ -110,14 +138,36 @@ 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->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;
}
+#ifdef ENABLE_LEAKY_REQUEST_STUBS
static gpointer
haze_request_file (const char *title,
const char *filename,
@@ -152,7 +202,7 @@ haze_request_folder (const char *title,
return NULL;
}
-
+#endif
/*
void (*close_request)(PurpleRequestType type, void *ui_handle);
@@ -160,12 +210,14 @@ haze_request_folder (const char *title,
static PurpleRequestUiOps request_uiops =
{
+#ifdef ENABLE_LEAKY_REQUEST_STUBS
.request_input = haze_request_input,
.request_choice = haze_request_choice,
.request_action = haze_request_action,
- .request_fields = haze_request_fields,
.request_file = haze_request_file,
- .request_folder = haze_request_folder
+ .request_folder = haze_request_folder,
+#endif
+ .request_fields = haze_request_fields
};
PurpleRequestUiOps *
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 <libpurple/request.h>
+void haze_request_password_cb (gpointer user_data,
+ const gchar *password);
+
PurpleRequestUiOps *haze_request_get_ui_ops (void);