/cpw/tomkiewicz/masterpassword: 2bda8642afa3: Early cancelling p...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Mon Mar 25 14:22:40 EDT 2013


Changeset: 2bda8642afa3b50e3132ed68f71e5b3cf9a762b8
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2013-03-25 19:22 +0100
Branch:	 soc.2008.masterpassword
URL: https://hg.pidgin.im/cpw/tomkiewicz/masterpassword/rev/2bda8642afa3

Description:

Early cancelling password requests before quitting

diffstat:

 libpurple/keyring.c                       |  31 +++++++++++++++++++++++++++++++
 libpurple/keyring.h                       |  10 ++++++++++
 libpurple/plugins/keyrings/gnomekeyring.c |  14 ++++++++++++--
 3 files changed, 53 insertions(+), 2 deletions(-)

diffs (143 lines):

diff --git a/libpurple/keyring.c b/libpurple/keyring.c
--- a/libpurple/keyring.c
+++ b/libpurple/keyring.c
@@ -50,6 +50,7 @@ struct _PurpleKeyring
 	char *id;   /* same as plugin id    */
 	PurpleKeyringRead read_password;
 	PurpleKeyringSave save_password;
+	PurpleKeyringCancelRequests cancel_requests;
 	PurpleKeyringClose close_keyring;
 	PurpleKeyringChangeMaster change_master;
 	PurpleKeyringImportPassword import_password;
@@ -132,6 +133,14 @@ purple_keyring_get_save_password(const P
 	return keyring->save_password;
 }
 
+PurpleKeyringCancelRequests
+purple_keyring_get_cancel_requests(const PurpleKeyring *keyring)
+{
+	g_return_val_if_fail(keyring != NULL, NULL);
+
+	return keyring->cancel_requests;
+}
+
 PurpleKeyringClose
 purple_keyring_get_close_keyring(const PurpleKeyring *keyring)
 {
@@ -199,6 +208,14 @@ purple_keyring_set_save_password(PurpleK
 }
 
 void
+purple_keyring_set_cancel_requests(PurpleKeyring *keyring, PurpleKeyringCancelRequests cancel_requests)
+{
+	g_return_if_fail(keyring != NULL);
+
+	keyring->cancel_requests = cancel_requests;
+}
+
+void
 purple_keyring_set_close_keyring(PurpleKeyring *keyring, PurpleKeyringClose close)
 {
 	g_return_if_fail(keyring != NULL);
@@ -273,6 +290,17 @@ static void purple_keyring_core_initiali
 	}
 }
 
+static void purple_keyring_core_quitting_cb()
+{
+	if (purple_keyring_inuse != NULL) {
+		PurpleKeyringCancelRequests cancel;
+		cancel = purple_keyring_get_cancel_requests(
+			purple_keyring_inuse);
+		if (cancel)
+			cancel();
+	}
+}
+
 void
 purple_keyring_init(void)
 {
@@ -335,6 +363,9 @@ purple_keyring_init(void)
 	purple_signal_connect(purple_get_core(), "core-initialized",
 		purple_keyring_get_handle(),
 		PURPLE_CALLBACK(purple_keyring_core_initialized_cb), NULL);
+	purple_signal_connect(purple_get_core(), "quitting",
+		purple_keyring_get_handle(),
+		PURPLE_CALLBACK(purple_keyring_core_quitting_cb), NULL);
 }
 
 void
diff --git a/libpurple/keyring.h b/libpurple/keyring.h
--- a/libpurple/keyring.h
+++ b/libpurple/keyring.h
@@ -143,6 +143,14 @@ typedef void (*PurpleKeyringSave)(Purple
                                   gpointer data);
 
 /**
+ * Cancel all running requests.
+ *
+ * After calling that, all queued requests should run their callbacks (most
+ * probably, with failure result).
+ */
+typedef void (*PurpleKeyringCancelRequests)(void);
+
+/**
  * Close the keyring.
  *
  * This will be called so the keyring can do any cleanup it wants.
@@ -398,6 +406,7 @@ const char *purple_keyring_get_name(cons
 const char *purple_keyring_get_id(const PurpleKeyring *info);
 PurpleKeyringRead purple_keyring_get_read_password(const PurpleKeyring *info);
 PurpleKeyringSave purple_keyring_get_save_password(const PurpleKeyring *info);
+PurpleKeyringCancelRequests purple_keyring_get_cancel_requests(const PurpleKeyring *info);
 PurpleKeyringClose purple_keyring_get_close_keyring(const PurpleKeyring *info);
 PurpleKeyringChangeMaster purple_keyring_get_change_master(const PurpleKeyring *info);
 PurpleKeyringImportPassword purple_keyring_get_import_password(const PurpleKeyring *info);
@@ -407,6 +416,7 @@ void purple_keyring_set_name(PurpleKeyri
 void purple_keyring_set_id(PurpleKeyring *info, const char *id);
 void purple_keyring_set_read_password(PurpleKeyring *info, PurpleKeyringRead read);
 void purple_keyring_set_save_password(PurpleKeyring *info, PurpleKeyringSave save);
+void purple_keyring_set_cancel_requests(PurpleKeyring *info, PurpleKeyringCancelRequests cancel_requests);
 void purple_keyring_set_close_keyring(PurpleKeyring *info, PurpleKeyringClose close);
 void purple_keyring_set_change_master(PurpleKeyring *info, PurpleKeyringChangeMaster change_master);
 void purple_keyring_set_import_password(PurpleKeyring *info, PurpleKeyringImportPassword import_password);
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
@@ -43,7 +43,6 @@
 static PurpleKeyring *keyring_handler = NULL;
 static GList *request_queue = NULL;
 static gpointer current_request = NULL;
-static gboolean is_closing = FALSE; /* TODO */
 
 typedef struct
 {
@@ -344,9 +343,19 @@ gnomekeyring_save(PurpleAccount *account
 }
 
 static void
+gnomekeyring_cancel()
+{
+	gnomekeyring_cancel_queue();
+	if (current_request) {
+		gnome_keyring_cancel_request(current_request);
+		while (g_main_iteration(FALSE));
+	}
+}
+
+static void
 gnomekeyring_close(GError **error)
 {
-	is_closing = TRUE;
+	gnomekeyring_cancel();
 }
 
 static gboolean
@@ -364,6 +373,7 @@ gnomekeyring_load(PurplePlugin *plugin)
 	purple_keyring_set_id(keyring_handler, GNOMEKEYRING_ID);
 	purple_keyring_set_read_password(keyring_handler, gnomekeyring_read);
 	purple_keyring_set_save_password(keyring_handler, gnomekeyring_save);
+	purple_keyring_set_cancel_requests(keyring_handler, gnomekeyring_cancel);
 	purple_keyring_set_close_keyring(keyring_handler, gnomekeyring_close);
 
 	purple_keyring_register(keyring_handler);



More information about the Commits mailing list