/cpw/tomkiewicz/masterpassword: bda1c52322fe: Keyring: more verb...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Mon Mar 18 06:53:45 EDT 2013


Changeset: bda1c52322fe3a9412b2ce8bc9892380d33a15f3
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2013-03-18 11:53 +0100
Branch:	 soc.2008.masterpassword
URL: https://hg.pidgin.im/cpw/tomkiewicz/masterpassword/rev/bda1c52322fe

Description:

Keyring: more verbosity, handle kwallet connection errors

diffstat:

 .hgignore                                    |   1 +
 libpurple/account.c                          |   8 +++---
 libpurple/keyring.c                          |   9 +++++++
 libpurple/plugins/keyrings/internalkeyring.c |   2 +-
 libpurple/plugins/keyrings/kwallet.cpp       |  33 +++++++++++++++++++++++++--
 5 files changed, 45 insertions(+), 8 deletions(-)

diffs (181 lines):

diff --git a/.hgignore b/.hgignore
--- a/.hgignore
+++ b/.hgignore
@@ -28,6 +28,7 @@ syntax: regexp
 .*\.pyo$
 .*\.rej$
 .*\.so$
+.*\.moc$
 Doxyfile(\.mingw)?$
 VERSION$
 aclocal.m4
diff --git a/libpurple/account.c b/libpurple/account.c
--- a/libpurple/account.c
+++ b/libpurple/account.c
@@ -361,13 +361,13 @@ account_to_xmlnode(PurpleAccount *accoun
 {
 	xmlnode *node, *child;
 	const char *tmp;
-	const char *keyring_id;
-	const char *mode;
-	char *data;
+	const char *keyring_id = NULL;
+	const char *mode = NULL;
+	char *data = NULL;
 	PurplePresence *presence;
 	PurpleProxyInfo *proxy_info;
 	GError *error = NULL;
-	GDestroyNotify destroy;
+	GDestroyNotify destroy = NULL;
 
 	node = xmlnode_new("account");
 
diff --git a/libpurple/keyring.c b/libpurple/keyring.c
--- a/libpurple/keyring.c
+++ b/libpurple/keyring.c
@@ -34,6 +34,7 @@
 #include "core.h"
 #include "debug.h"
 #include "internal.h"
+#include "dbus-maybe.h"
 
 typedef struct _PurpleKeyringCbInfo PurpleKeyringCbInfo;
 typedef struct _PurpleKeyringChangeTracker PurpleKeyringChangeTracker;
@@ -622,6 +623,7 @@ purple_keyring_register(PurpleKeyring *k
 
 	core = purple_get_core();
 
+	PURPLE_DBUS_REGISTER_POINTER(keyring, PurpleKeyring);
 	purple_signal_emit(core, "keyring-register", keyring_id, keyring);
 	purple_debug_info("keyring", "Registered keyring : %s.\n", keyring_id);
 
@@ -645,6 +647,7 @@ purple_keyring_unregister(PurpleKeyring 
 	core = purple_get_core();
 	keyring_id = purple_keyring_get_id(keyring);
 	purple_signal_emit(core, "keyring-unregister", keyring_id, keyring);
+	PURPLE_DBUS_UNREGISTER_POINTER(keyring);
 
 	inuse = purple_keyring_get_inuse();
 	fallback = purple_keyring_find_keyring_by_id(PURPLE_DEFAULT_KEYRING);
@@ -788,6 +791,7 @@ purple_keyring_get_password(PurpleAccoun
 	PurpleKeyringRead read;
 
 	if (account == NULL) {
+		purple_debug_error("keyring", "No account passed to the function.");
 		error = g_error_new(PURPLE_KEYRING_ERROR, PURPLE_KEYRING_ERROR_INVALID,
 			"No account passed to the function.");
 
@@ -800,6 +804,7 @@ purple_keyring_get_password(PurpleAccoun
 		inuse = purple_keyring_get_inuse();
 
 		if (inuse == NULL) {
+			purple_debug_error("keyring", "No keyring configured.");
 			error = g_error_new(PURPLE_KEYRING_ERROR, PURPLE_KEYRING_ERROR_NOKEYRING,
 				"No keyring configured.");
 
@@ -812,6 +817,7 @@ purple_keyring_get_password(PurpleAccoun
 			read = purple_keyring_get_read_password(inuse);
 
 			if (read == NULL) {
+				purple_debug_warning("keyring", "Keyring cannot read password.");
 				error = g_error_new(PURPLE_KEYRING_ERROR, PURPLE_KEYRING_ERROR_NOCAP,
 					"Keyring cannot read password.");
 
@@ -821,6 +827,9 @@ purple_keyring_get_password(PurpleAccoun
 				g_error_free(error);
 
 			} else {
+				purple_debug_info("keyring", "Reading password for account %s (%s).\n",
+					purple_account_get_username(account),
+					purple_account_get_protocol_id(account));
 				read(account, cb, data);
 			}
 		}
diff --git a/libpurple/plugins/keyrings/internalkeyring.c b/libpurple/plugins/keyrings/internalkeyring.c
--- a/libpurple/plugins/keyrings/internalkeyring.c
+++ b/libpurple/plugins/keyrings/internalkeyring.c
@@ -66,7 +66,7 @@ internal_keyring_read(PurpleAccount *acc
 
 	ACTIVATE();
 
-	purple_debug_info("keyring-internal",
+	purple_debug_misc("keyring-internal",
 		"Reading password for account %s (%s).\n",
 		purple_account_get_username(account),
 		purple_account_get_protocol_id(account));
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
@@ -78,6 +78,7 @@ class engine : private QObject, private 
 	private:
 		QCoreApplication *app;
 		bool connected;
+		bool failed;
 		KWallet::Wallet *wallet;
 		static engine *pinstance;
 		gint idle_handle;
@@ -124,8 +125,12 @@ KWalletPlugin::engine::engine()
 	app = new QCoreApplication(argc, NULL);
 
 	connected = FALSE;
+	failed = FALSE;
 	wallet = KWallet::Wallet::openWallet(KWallet::Wallet::NetworkWallet(), 0, KWallet::Wallet::Asynchronous);
-	connect(wallet, SIGNAL(walletOpened(bool)), SLOT(walletOpened(bool)));
+	if (wallet == NULL || !connect(wallet, SIGNAL(walletOpened(bool)), SLOT(walletOpened(bool)))) {
+		failed = TRUE;
+		purple_debug_error("keyring-kwallet", "failed connecting to wallet %p\n", wallet);
+	}
 }
 
 KWalletPlugin::engine::~engine()
@@ -192,12 +197,14 @@ KWalletPlugin::engine::ExecuteRequests()
 	if (idle_handle == 0)
 		idle_handle = g_idle_add((GSourceFunc)idle_cb, this);
 
-	if (connected) {
+	if (connected || failed) {
 		while (!isEmpty()) {
 			request *req = dequeue();
-			req->execute(wallet);
+			req->execute(connected ? wallet : NULL);
 			delete req;
 		}
+	} else {
+		purple_debug_misc("keyring-kwallet", "not yet connected\n");
 	}
 }
 
@@ -249,6 +256,16 @@ KWalletPlugin::read_request::execute(KWa
 	int result;
 	QString key;
 
+	if (wallet == NULL) {
+		GError *error;
+		error = g_error_new(ERR_KWALLETPLUGIN,
+			PURPLE_KEYRING_ERROR_UNKNOWN,
+			"No wallet opened");
+		callback(account, NULL, error, data);
+		g_error_free(error);
+		return;
+	}
+
 	key = QString("purple-") + purple_account_get_username(account) + " " + purple_account_get_protocol_id(account);
 	result = wallet->readPassword(key, password);
 
@@ -264,6 +281,16 @@ KWalletPlugin::save_request::execute(KWa
 	int result;
 	QString key;
 
+	if (wallet == NULL) {
+		GError *error;
+		error = g_error_new(ERR_KWALLETPLUGIN,
+			PURPLE_KEYRING_ERROR_UNKNOWN,
+			"No wallet opened");
+		callback(account, error, data);
+		g_error_free(error);
+		return;
+	}
+
 	key = QString("purple-") + purple_account_get_username(account) + " " + purple_account_get_protocol_id(account);
 	result = wallet->writePassword(key, password);
 



More information about the Commits mailing list