/cpw/tomkiewicz/masterpassword: 37d7d0e22484: Revert existing pa...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Tue Mar 26 09:19:20 EDT 2013


Changeset: 37d7d0e22484f822b322645743f145fb67a37929
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2013-03-26 14:19 +0100
Branch:	 soc.2008.masterpassword
URL: https://hg.pidgin.im/cpw/tomkiewicz/masterpassword/rev/37d7d0e22484

Description:

Revert existing password migration at exit, allow cancelling kwallet requests

diffstat:

 libpurple/keyring.c                       |  32 ++++++++++++++++++++-----
 libpurple/plugins/keyrings/gnomekeyring.c |   5 +++-
 libpurple/plugins/keyrings/kwallet.cpp    |  37 ++++++++++++++++++++++--------
 3 files changed, 56 insertions(+), 18 deletions(-)

diffs (209 lines):

diff --git a/libpurple/keyring.c b/libpurple/keyring.c
--- a/libpurple/keyring.c
+++ b/libpurple/keyring.c
@@ -260,7 +260,7 @@ static const PurpleKeyring *purple_keyri
 static char *purple_keyring_to_use;
 static guint purple_keyring_pref_cb_id;
 static GList *purple_keyring_loaded_plugins = NULL;
-static gboolean purple_keyring_inuse_under_change = FALSE;
+static PurpleKeyringChangeTracker *current_change_tracker = NULL;
 
 static void
 purple_keyring_pref_cb(const char *pref,
@@ -292,6 +292,25 @@ static void purple_keyring_core_initiali
 
 static void purple_keyring_core_quitting_cb()
 {
+	if (current_change_tracker != NULL) {
+		PurpleKeyringChangeTracker *tracker;
+		PurpleKeyringCancelRequests cancel = NULL;
+
+		tracker = current_change_tracker;
+		tracker->abort = TRUE;
+		if (tracker->old) {
+			cancel = purple_keyring_get_cancel_requests(
+				tracker->old);
+			if (cancel)
+				cancel();
+		}
+		if (current_change_tracker == tracker && tracker->new) {
+			cancel = purple_keyring_get_cancel_requests(
+				tracker->new);
+			if (cancel)
+				cancel();
+		}
+	}
 	if (purple_keyring_inuse != NULL) {
 		PurpleKeyringCancelRequests cancel;
 		cancel = purple_keyring_get_cancel_requests(
@@ -518,7 +537,7 @@ purple_keyring_set_inuse_check_error_cb(
 			purple_keyring_pref_cb_id = purple_prefs_connect_callback(NULL,
 				"/purple/keyring/active", purple_keyring_pref_cb, NULL);
 
-			purple_keyring_inuse_under_change = FALSE;
+			current_change_tracker = NULL;
 
 			if (tracker->cb != NULL)
 				tracker->cb(tracker->old, FALSE, tracker->error, tracker->data);
@@ -532,7 +551,7 @@ purple_keyring_set_inuse_check_error_cb(
 			purple_debug_info("keyring", "Successfully changed keyring.\n");
 
 			purple_keyring_inuse = tracker->new;
-			purple_keyring_inuse_under_change = FALSE;
+			current_change_tracker = NULL;
 
 			if (tracker->cb != NULL)
 				tracker->cb(tracker->new, TRUE, NULL, tracker->data);
@@ -615,7 +634,7 @@ purple_keyring_set_inuse(const PurpleKey
 
 	oldkeyring = purple_keyring_get_inuse();
 
-	if (purple_keyring_inuse_under_change) {
+	if (current_change_tracker != NULL) {
 		GError *error;
 		purple_debug_error("keyring", "There is password migration "
 			"session already running.\n");
@@ -628,13 +647,11 @@ purple_keyring_set_inuse(const PurpleKey
 		g_error_free(error);
 		return;
 	}
-	purple_keyring_inuse_under_change = TRUE;
 
 	if (oldkeyring == newkeyring) {
 		purple_debug_misc("keyring",
 			"Old and new keyring are the same: %s.\n",
 			(newkeyring != NULL) ? newkeyring->id : "(null)");
-		purple_keyring_inuse_under_change = FALSE;
 		if (cb != NULL)
 			cb(newkeyring, TRUE, NULL, data);
 		return;
@@ -672,6 +689,7 @@ purple_keyring_set_inuse(const PurpleKey
 				oldkeyring->id);
 
 			tracker = g_new(PurpleKeyringChangeTracker, 1);
+			current_change_tracker = tracker;
 
 			tracker->cb = cb;
 			tracker->data = data;
@@ -707,7 +725,7 @@ purple_keyring_set_inuse(const PurpleKey
 		}
 
 		purple_keyring_inuse = newkeyring;
-		purple_keyring_inuse_under_change = FALSE;
+		g_assert(current_change_tracker == NULL);
 		if (cb != NULL)
 			cb(newkeyring, TRUE, NULL, data);
 	}
diff --git a/libpurple/plugins/keyrings/gnomekeyring.c b/libpurple/plugins/keyrings/gnomekeyring.c
--- a/libpurple/plugins/keyrings/gnomekeyring.c
+++ b/libpurple/plugins/keyrings/gnomekeyring.c
@@ -240,6 +240,9 @@ gnomekeyring_cancel_queue(void)
 {
 	GList *cancel_list = request_queue;
 
+	if (request_queue == NULL)
+		return;
+
 	purple_debug_info("gnome-keyring", "cancelling all pending requests\n");
 	request_queue = NULL;
 
@@ -343,7 +346,7 @@ gnomekeyring_save(PurpleAccount *account
 }
 
 static void
-gnomekeyring_cancel()
+gnomekeyring_cancel(void)
 {
 	gnomekeyring_cancel_queue();
 	if (current_request) {
diff --git a/libpurple/plugins/keyrings/kwallet.cpp b/libpurple/plugins/keyrings/kwallet.cpp
--- a/libpurple/plugins/keyrings/kwallet.cpp
+++ b/libpurple/plugins/keyrings/kwallet.cpp
@@ -72,7 +72,8 @@ class engine : private QObject, private 
 		engine();
 		~engine();
 		void queue(request *req);
-		static engine *instance();
+		void abortAll();
+		static engine *instance(bool create);
 		static void closeInstance();
 
 	private slots:
@@ -188,6 +189,18 @@ KWalletPlugin::engine::reopenWallet()
 KWalletPlugin::engine::~engine()
 {
 	closing = true;
+
+	abortAll();
+
+	delete wallet;
+
+	if (pinstance == this)
+		pinstance = NULL;
+}
+
+void
+KWalletPlugin::engine::abortAll()
+{
 	int abortedCount = 0;
 
 	while (!isEmpty()) {
@@ -201,17 +214,12 @@ KWalletPlugin::engine::~engine()
 		purple_debug_info("keyring-kwallet", "aborted requests: %d\n",
 			abortedCount);
 	}
-
-	delete wallet;
-
-	if (pinstance == this)
-		pinstance = NULL;
 }
 
 KWalletPlugin::engine *
-KWalletPlugin::engine::instance()
+KWalletPlugin::engine::instance(bool create)
 {
-	if (pinstance == NULL)
+	if (pinstance == NULL && create)
 		pinstance = new engine;
 	return pinstance;
 }
@@ -429,7 +437,7 @@ kwallet_read(PurpleAccount *account, Pur
 		delete req;
 	}
 	else
-		KWalletPlugin::engine::instance()->queue(req);
+		KWalletPlugin::engine::instance(true)->queue(req);
 }
 
 static void
@@ -443,12 +451,20 @@ kwallet_save(PurpleAccount *account, con
 			cb(account, NULL, data);
 	}
 	else
-		KWalletPlugin::engine::instance()->queue(
+		KWalletPlugin::engine::instance(true)->queue(
 			new KWalletPlugin::save_request(account, password, cb,
 			data));
 }
 
 static void
+kwallet_cancel(void)
+{
+	KWalletPlugin::engine *instance = KWalletPlugin::engine::instance(false);
+	if (instance)
+		instance->abortAll();
+}
+
+static void
 kwallet_close(GError **error)
 {
 	KWalletPlugin::engine::closeInstance();
@@ -475,6 +491,7 @@ kwallet_load(PurplePlugin *plugin)
 	purple_keyring_set_id(keyring_handler, KWALLET_ID);
 	purple_keyring_set_read_password(keyring_handler, kwallet_read);
 	purple_keyring_set_save_password(keyring_handler, kwallet_save);
+	purple_keyring_set_cancel_requests(keyring_handler, kwallet_cancel);
 	purple_keyring_set_close_keyring(keyring_handler, kwallet_close);
 
 	purple_keyring_register(keyring_handler);



More information about the Commits mailing list