soc.2008.masterpassword: 2a854c62: Made more calls asynch, enhanced error c...
scrouaf at soc.pidgin.im
scrouaf at soc.pidgin.im
Thu Aug 14 23:46:20 EDT 2008
-----------------------------------------------------------------
Revision: 2a854c62dce5b27dc247b6d3964050068533b629
Ancestor: 374e706ed07438c1140bd5cabe48958c47829868
Author: scrouaf at soc.pidgin.im
Date: 2008-08-14T19:47:00
Branch: im.pidgin.soc.2008.masterpassword
URL: http://d.pidgin.im/viewmtn/revision/info/2a854c62dce5b27dc247b6d3964050068533b629
Modified files:
finch/gntaccount.c finch/gntprefs.c libpurple/keyring.c
libpurple/keyring.h pidgin/gtkaccount.c
ChangeLog:
Made more calls asynch, enhanced error checking and reporting.
-------------- next part --------------
============================================================
--- finch/gntaccount.c ca651f89af911d02c06bdce4ca60a749bea40954
+++ finch/gntaccount.c a3bb24a41e42468c1655425adb19bcde974c182d
@@ -58,6 +58,9 @@ static FinchAccountList accounts;
static FinchAccountList accounts;
+static void edit_account_continue(PurpleAccount * account,
+ const gchar * password, GError * error, gpointer user_data);
+
typedef struct
{
PurpleAccount *account; /* NULL for a new account */
@@ -173,9 +176,9 @@ save_account_cb(AccountEditDialog *dialo
gnt_check_box_get_checked(GNT_CHECK_BOX(dialog->remember)));
value = gnt_entry_get_text(GNT_ENTRY(dialog->password));
if (value && *value)
- purple_account_set_password(account, value);
+ purple_account_set_password_async(account, g_strdup(value), g_free, NULL, NULL);
else
- purple_account_set_password(account, NULL);
+ purple_account_set_password_async(account, NULL, NULL, NULL, NULL);
/* Mail notification */
purple_account_set_check_mail(account,
@@ -484,11 +487,21 @@ edit_account(PurpleAccount *account)
static void
edit_account(PurpleAccount *account)
{
+ purple_account_get_password_async(account, edit_account_continue, account);
+}
+
+static void
+edit_account_continue(PurpleAccount * account,
+ const gchar * password, GError * error, gpointer user_data)
+{
GntWidget *window, *hbox;
GntWidget *combo, *button, *entry;
GList *list, *iter;
AccountEditDialog *dialog;
+ if (error)
+ g_error_free(error);
+
if (account)
{
GList *iter;
@@ -563,7 +576,7 @@ edit_account(PurpleAccount *account)
gnt_box_add_widget(GNT_BOX(hbox), gnt_label_new(_("Password:")));
gnt_box_add_widget(GNT_BOX(hbox), entry);
if (account)
- gnt_entry_set_text(GNT_ENTRY(entry), purple_account_get_password(account));
+ gnt_entry_set_text(GNT_ENTRY(entry), password);
hbox = gnt_hbox_new(TRUE);
gnt_box_set_pad(GNT_BOX(hbox), 0);
============================================================
--- finch/gntprefs.c f99767052ae453a6a10ecb1ce7a5b2030e6fa25f
+++ finch/gntprefs.c ca8575e5fb76efaa0ede3eae9708de37ff599c26
@@ -1,6 +1,7 @@
/**
* @file gntprefs.c GNT Preferences API
* @ingroup finch
+ * @todo : add support for master password changing.
*/
/* finch
@@ -80,6 +81,13 @@ static GList *
} Prefs;
static GList *
+get_keyring_options(void)
+{
+ return purple_keyring_get_options();
+}
+
+
+static GList *
get_log_options(void)
{
return purple_log_logger_get_options();
@@ -202,6 +210,11 @@ static Prefs logging[] =
{PURPLE_PREF_NONE, NULL, NULL, NULL},
};
+static Prefs keyring[] =
+{
+ {PURPLE_PREF_STRING, "/purple/keyring/active", N_("Active keyring"), purple_keyring_get_options}
+};
+
static Prefs idle[] =
{
{PURPLE_PREF_STRING, "/purple/away/idle_reporting", N_("Report Idle time"), get_idle_options},
@@ -257,6 +270,7 @@ void finch_prefs_show_all()
add_pref_group(fields, _("Buddy List"), blist);
add_pref_group(fields, _("Conversations"), convs);
+ add_pref_group(fields, _("Keyring"), keyring);
add_pref_group(fields, _("Logging"), logging);
add_pref_group(fields, _("Idle"), idle);
============================================================
--- libpurple/keyring.c 1b687ba433c6da254a9d3890ceb016fef6f75907
+++ libpurple/keyring.c db768cd667bccb5076353c9a519fa7159c3f6323
@@ -1,6 +1,8 @@
/**
* @file keyring.c Keyring plugin API
* @ingroup core
+ * @todo ? : add dummy callback to all calls to prevent poorly written
+ * plugins from segfaulting on NULL callback ?
*/
/* purple
@@ -32,6 +34,7 @@
#include "core.h"
#include "debug.h"
+typedef struct _PurpleKeyringCbInfo PurpleKeyringCbInfo;
typedef struct _PurpleKeyringChangeTracker PurpleKeyringChangeTracker;
static void purple_keyring_pref_cb(const char *, PurplePrefType, gconstpointer, gpointer);
@@ -76,6 +79,12 @@ struct _PurpleKeyringChangeTracker
gboolean force;
};
+struct _PurpleKeyringCbInfo
+{
+ gpointer cb;
+ gpointer data;
+};
+
/* Constructor */
PurpleKeyring *
purple_keyring_new()
@@ -279,8 +288,6 @@ purple_keyring_set_export_password(Purpl
/***************************************/
/** @name Keyring API */
-/** @todo (maybe) */
-/** - rename as purple_keyrings */
/***************************************/
/*@{*/
@@ -375,7 +382,6 @@ purple_keyring_get_inuse()
/* fire and forget */
-/** @todo ? : add dummy callback ? */
static void
purple_keyring_drop_passwords(const PurpleKeyring * keyring)
{
@@ -451,10 +457,7 @@ purple_keyring_set_inuse_check_error_cb(
if (tracker->finished == TRUE && tracker->read_outstanding == 0) {
if (tracker->abort == TRUE && tracker->force == FALSE) {
- /**
- * TODO :
- * - create faulty keyring to test this code.
- */
+
if (tracker->cb != NULL)
tracker->cb(tracker->old, FALSE, tracker->error, tracker->data);
@@ -467,8 +470,8 @@ purple_keyring_set_inuse_check_error_cb(
purple_debug_info("keyring",
"Failed to change keyring, aborting");
- /* FIXME : this should maybe be in a callback
- * cancel the prefs change
+ /**
+ * FIXME : call purple_notify()
*/
purple_prefs_disconnect_callback(purple_keyring_pref_cb_id);
purple_prefs_set_string("/purple/keyring/active",
@@ -664,7 +667,7 @@ purple_keyring_pref_cb(const char *pref,
new = purple_keyring_get_keyring_by_id(id);
g_return_if_fail(new != NULL);
- purple_keyring_set_inuse(new, FALSE, NULL, data); /* FIXME Maybe this should have a callback that can cancel the action */
+ purple_keyring_set_inuse(new, FALSE, NULL, data);
return;
}
@@ -733,7 +736,6 @@ purple_keyring_register(PurpleKeyring *
purple_debug_info("keyring", "Keyring %s matches keyring to use, using it.\n",
keyring->id);
- /** @todo add callback to make sure all is ok */
purple_keyring_set_inuse(keyring, TRUE, NULL, NULL);
}
@@ -771,7 +773,6 @@ purple_keyring_unregister(PurpleKeyring
if (inuse == keyring) {
if (inuse != fallback) {
- /* TODO : check result ? */
purple_keyring_set_inuse(fallback, TRUE, NULL, NULL);
} else {
@@ -783,7 +784,7 @@ purple_keyring_unregister(PurpleKeyring
purple_keyring_keyrings = g_list_remove(purple_keyring_keyrings,
keyring);
- //purple_debug_info("keyring", "Keyring %s unregistered", keyring->id);
+ purple_debug_info("keyring", "Keyring %s unregistered", keyring->id);
}
@@ -971,6 +972,7 @@ purple_keyring_set_password_async(const
GError * error = NULL;
const PurpleKeyring * inuse;
PurpleKeyringSave save;
+ PurpleKeyringCbInfo * cbinfo;
if (account == NULL) {
error = g_error_new(ERR_PIDGINKEYRING, ERR_INVALID,
@@ -1006,7 +1008,10 @@ purple_keyring_set_password_async(const
g_error_free(error);
} else {
- save(account, password, destroypassword, cb, data);
+ cbinfo->cb = cb;
+ cbinfo->data = data;
+ save(account, password, destroypassword,
+ purple_keyring_set_password_async, data);
}
}
}
@@ -1014,7 +1019,22 @@ purple_keyring_set_password_async(const
return;
}
+void
+purple_keyring_set_password_async_cb(PurpleAccount * account,
+ GError * error,
+ gpointer data)
+{
+ PurpleKeyringCbInfo * cbinfo = data;
+ PurpleKeyringSaveCallback cb = cbinfo->cb;
+ if (error != NULL) {
+ /* FIXME : purple_notify_warning() */
+ }
+
+ if (cb != NULL)
+ cb(account, error, cbinfo->data);
+ g_free(data);
+}
/**
* This should be dropped at 3.0 (it's here for compatibility)
*/
============================================================
--- libpurple/keyring.h 2a60b386ea7e439a55a4543bf9ca533d2bbc09a2
+++ libpurple/keyring.h b9f80e1f1dbac927b2cbef61e5b595b0a185cbdf
@@ -67,8 +67,8 @@ typedef struct _PurpleKeyring PurpleKeyr
* @param error Error that could have occured. Must be freed by the calling function.
* @param data Data passed to the callback.
*/
-typedef void (*PurpleKeyringReadCallback)(const PurpleAccount * account,
- const gchar * password,
+typedef void (*PurpleKeyringReadCallback)(PurpleAccount * account,
+ gchar * password,
GError * error,
gpointer data);
============================================================
--- pidgin/gtkaccount.c 6d89a8287020c65fde0164a38fc76d0390215c37
+++ pidgin/gtkaccount.c d6a43d89af6d06476933f00155266ac0c495ab8b
@@ -144,6 +144,8 @@ static void set_account(GtkListStore *st
static void add_account_to_liststore(PurpleAccount *account, gpointer user_data);
static void set_account(GtkListStore *store, GtkTreeIter *iter,
PurpleAccount *account, GdkPixbuf *global_buddyicon);
+static void add_login_options_continue(PurpleAccount * account,
+ const gchar * password, GError * error, gpointer user_data);
/**************************************************************************
* Add/Modify Account dialog
@@ -390,9 +392,33 @@ update_editable(PurpleConnection *gc, Ac
gtk_widget_set_sensitive((GtkWidget *)l->data, set);
}
+typedef struct _AddLoginOptionsCalbackData {
+ AccountPrefsDialog *dialog;
+ GtkWidget *parent;
+} AddLoginOptionsCallbackData;
+
static void
add_login_options(AccountPrefsDialog *dialog, GtkWidget *parent)
{
+
+ AddLoginOptionsCallbackData *data;
+ data = g_new(AddLoginOptionsCallbackData, 1);
+
+ data->dialog = dialog;
+ data->parent = parent;
+
+ purple_account_get_password_async(dialog->account, add_login_options_continue, data);
+}
+
+static void
+add_login_options_continue(PurpleAccount * account,
+ const gchar * password,
+ GError * error,
+ gpointer user_data)
+{
+ AddLoginOptionsCallbackData * data = user_data;
+ AccountPrefsDialog *dialog = data->dialog;
+ GtkWidget *parent = data->parent;
GtkWidget *frame;
GtkWidget *hbox;
GtkWidget *vbox;
@@ -402,8 +428,11 @@ add_login_options(AccountPrefsDialog *di
GList *user_splits;
GList *l, *l2;
char *username = NULL;
- char *password = NULL;
+ /* XXX : report error ? */
+ if (error)
+ g_error_free(error);
+
if (dialog->protocol_menu != NULL)
{
gtk_widget_ref(dialog->protocol_menu);
@@ -562,7 +591,6 @@ add_login_options(AccountPrefsDialog *di
/* Set the fields. */
if (dialog->account != NULL) {
- password = purple_account_get_password(dialog->account);
if (password)
gtk_entry_set_text(GTK_ENTRY(dialog->password_entry), password);
More information about the Commits
mailing list