/cpw/tomkiewicz/masterpassword: 857c361d3791: Refine keyring err...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Sat Apr 27 09:47:53 EDT 2013


Changeset: 857c361d379162985db1930f3cd12f0278886491
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2013-04-27 15:47 +0200
Branch:	 soc.2008.masterpassword
URL: https://hg.pidgin.im/cpw/tomkiewicz/masterpassword/rev/857c361d3791

Description:

Refine keyring error coded

diffstat:

 libpurple/keyring.c                          |  64 ++++++++++++---------------
 libpurple/keyring.h                          |  19 +++----
 libpurple/plugins/keyrings/gnomekeyring.c    |  18 +++---
 libpurple/plugins/keyrings/internalkeyring.c |   6 +-
 libpurple/plugins/keyrings/kwallet.cpp       |   4 +-
 libpurple/plugins/keyrings/secretservice.c   |  10 ++--
 6 files changed, 57 insertions(+), 64 deletions(-)

diffs (truncated from 353 to 300 lines):

diff --git a/libpurple/keyring.c b/libpurple/keyring.c
--- a/libpurple/keyring.c
+++ b/libpurple/keyring.c
@@ -574,13 +574,7 @@ purple_keyring_set_inuse_check_error_cb(
 
 	if ((error != NULL) && (error->domain == PURPLE_KEYRING_ERROR)) {
 		switch(error->code) {
-			case PURPLE_KEYRING_ERROR_NOCAP:
-				purple_debug_info("keyring",
-					"Keyring does not support saving a password for account %s: %s.\n",
-					name, error->message);
-				break;
-
-			case PURPLE_KEYRING_ERROR_NOPASSWD:
+			case PURPLE_KEYRING_ERROR_NOPASSWORD:
 				if (purple_debug_is_verbose()) {
 					purple_debug_misc("keyring",
 						"No password found while changing keyring for account %s: %s.\n",
@@ -588,7 +582,17 @@ purple_keyring_set_inuse_check_error_cb(
 				}
 				break;
 
-			case PURPLE_KEYRING_ERROR_NOCHANNEL:
+			case PURPLE_KEYRING_ERROR_CANCELLED:
+				purple_debug_info("keyring",
+					"Operation cancelled while changing keyring for account %s: %s.\n",
+					name, error->message);
+				tracker->abort = TRUE;
+				if (tracker->error != NULL)
+					g_error_free(tracker->error);
+				tracker->error = g_error_copy(error);
+				break;
+
+			case PURPLE_KEYRING_ERROR_BACKENDFAIL:
 				purple_debug_error("keyring",
 					"Failed to communicate with backend while changing keyring for account %s: %s. Aborting changes.\n",
 					name, error->message);
@@ -651,9 +655,8 @@ purple_keyring_set_inuse_got_pw_cb(Purpl
 	}
 
 	if (error != NULL) {
-		if (error->code == PURPLE_KEYRING_ERROR_NOPASSWD ||
-		    error->code == PURPLE_KEYRING_ERROR_NOACCOUNT ||
-		    tracker->force == TRUE) {
+		if (error->code == PURPLE_KEYRING_ERROR_NOPASSWORD ||
+			tracker->force == TRUE) {
 			/* don't save password, and ignore it */
 		} else {
 			/* fatal error, abort all */
@@ -689,8 +692,8 @@ purple_keyring_set_inuse(const PurpleKey
 		if (cb == NULL)
 			return;
 		error = g_error_new(PURPLE_KEYRING_ERROR,
-			PURPLE_KEYRING_ERROR_UNKNOWN,
-			"There is password migration session already running");
+			PURPLE_KEYRING_ERROR_INTERNAL,
+			"There is a password migration session already running");
 		cb(oldkeyring, error, data);
 		g_error_free(error);
 		return;
@@ -912,7 +915,7 @@ purple_keyring_import_password(PurpleAcc
 	    (keyringid == NULL && g_strcmp0(PURPLE_DEFAULT_KEYRING, realid))) {
 		if (error != NULL) {
 			*error = g_error_new(PURPLE_KEYRING_ERROR,
-				PURPLE_KEYRING_ERROR_INVALID,
+				PURPLE_KEYRING_ERROR_INTERNAL,
 				"Specified keyring id does not match the "
 				"configured one.");
 		}
@@ -967,7 +970,7 @@ purple_keyring_export_password(PurpleAcc
 	}
 
 	if (*keyringid == NULL) {
-		*error = g_error_new(PURPLE_KEYRING_ERROR, PURPLE_KEYRING_ERROR_INVALID,
+		*error = g_error_new(PURPLE_KEYRING_ERROR, PURPLE_KEYRING_ERROR_INTERNAL,
 			"Plugin does not have a keyring id");
 		purple_debug_info("keyring",
 			"Configured keyring does not have a keyring id, cannot export password.\n");
@@ -1002,7 +1005,7 @@ purple_keyring_get_password(PurpleAccoun
 
 	if (purple_keyring_is_quitting) {
 		purple_debug_error("keyring", "Cannot request a password while quitting.\n");
-		error = g_error_new(PURPLE_KEYRING_ERROR, PURPLE_KEYRING_ERROR_NOCHANNEL,
+		error = g_error_new(PURPLE_KEYRING_ERROR, PURPLE_KEYRING_ERROR_INTERNAL,
 			"Cannot request a password while quitting.");
 		if (cb != NULL)
 			cb(account, NULL, error, data);
@@ -1012,7 +1015,7 @@ purple_keyring_get_password(PurpleAccoun
 
 	if (account == NULL) {
 		purple_debug_error("keyring", "No account passed to the function.\n");
-		error = g_error_new(PURPLE_KEYRING_ERROR, PURPLE_KEYRING_ERROR_INVALID,
+		error = g_error_new(PURPLE_KEYRING_ERROR, PURPLE_KEYRING_ERROR_INTERNAL,
 			"No account passed to the function.");
 
 		if (cb != NULL)
@@ -1097,7 +1100,7 @@ purple_keyring_set_password(PurpleAccoun
 
 	if (purple_keyring_is_quitting) {
 		purple_debug_error("keyring", "Cannot save a password while quitting.\n");
-		error = g_error_new(PURPLE_KEYRING_ERROR, PURPLE_KEYRING_ERROR_NOCHANNEL,
+		error = g_error_new(PURPLE_KEYRING_ERROR, PURPLE_KEYRING_ERROR_INTERNAL,
 			"Cannot save a password while quitting.");
 		if (cb != NULL)
 			cb(account, error, data);
@@ -1107,7 +1110,7 @@ purple_keyring_set_password(PurpleAccoun
 
 	if (current_change_tracker != NULL) {
 		purple_debug_error("keyring", "Cannot save a password during password migration.\n");
-		error = g_error_new(PURPLE_KEYRING_ERROR, PURPLE_KEYRING_ERROR_NOCHANNEL,
+		error = g_error_new(PURPLE_KEYRING_ERROR, PURPLE_KEYRING_ERROR_INTERNAL,
 			"Cannot save a password during password migration.");
 		if (cb != NULL)
 			cb(account, error, data);
@@ -1138,27 +1141,18 @@ purple_keyring_set_password(PurpleAccoun
 	}
 }
 
+/* TODO: get rid of GError */
 void
 purple_keyring_close(PurpleKeyring *keyring, GError **error)
 {
 	PurpleKeyringClose close_cb;
 
-	if (keyring == NULL) {
-		*error = g_error_new(PURPLE_KEYRING_ERROR, PURPLE_KEYRING_ERROR_INVALID,
-			"No keyring passed to the function.");
+	g_return_if_fail(keyring != NULL);
 
-	} else {
-		close_cb = purple_keyring_get_close_keyring(keyring);
+	close_cb = purple_keyring_get_close_keyring(keyring);
 
-		if (close_cb == NULL) {
-			*error = g_error_new(PURPLE_KEYRING_ERROR, PURPLE_KEYRING_ERROR_NOCAP,
-				"Keyring doesn't support being closed.");
-
-		} else {
-			close_cb(error);
-
-		}
-	}
+	if (close_cb != NULL)
+		close_cb(error);
 }
 
 
@@ -1174,7 +1168,7 @@ purple_keyring_change_master(PurpleKeyri
 
 	if (purple_keyring_is_quitting || current_change_tracker != NULL) {
 		purple_debug_error("keyring", "Cannot change a master password at the moment.\n");
-		error = g_error_new(PURPLE_KEYRING_ERROR, PURPLE_KEYRING_ERROR_NOCHANNEL,
+		error = g_error_new(PURPLE_KEYRING_ERROR, PURPLE_KEYRING_ERROR_INTERNAL,
 			"Cannot change a master password at the moment.");
 		if (cb != NULL)
 			cb(error, data);
@@ -1194,7 +1188,7 @@ purple_keyring_change_master(PurpleKeyri
 		change = purple_keyring_get_change_master(inuse);
 
 		if (change == NULL) {
-			error = g_error_new(PURPLE_KEYRING_ERROR, PURPLE_KEYRING_ERROR_NOCAP,
+			error = g_error_new(PURPLE_KEYRING_ERROR, PURPLE_KEYRING_ERROR_BACKENDFAIL,
 				"Keyring doesn't support master passwords.");
 			if (cb)
 				cb(error, data);
diff --git a/libpurple/keyring.h b/libpurple/keyring.h
--- a/libpurple/keyring.h
+++ b/libpurple/keyring.h
@@ -436,16 +436,15 @@ GQuark purple_keyring_error_domain(void)
 /** error codes for keyrings. */
 enum PurpleKeyringError
 {
-	PURPLE_KEYRING_ERROR_OK = 0,         /**< No error. */
-	PURPLE_KEYRING_ERROR_NOPASSWD = 1,   /**< No stored password. */
-	PURPLE_KEYRING_ERROR_NOACCOUNT,      /**< Account not found. */
-	PURPLE_KEYRING_ERROR_WRONGPASS,      /**< User submitted wrong password when prompted. */
-	PURPLE_KEYRING_ERROR_WRONGFORMAT,    /**< Data passed is not in suitable format. */
-	PURPLE_KEYRING_ERROR_NOKEYRING,      /**< No keyring configured. */
-	PURPLE_KEYRING_ERROR_NOCHANNEL,      /**< Failed to communicate with the backend */
-	PURPLE_KEYRING_ERROR_INVALID,        /**< Invalid input */
-	PURPLE_KEYRING_ERROR_NOCAP,          /**< Keyring doesn't support this */
-	PURPLE_KEYRING_ERROR_UNKNOWN         /**< Unknown error */
+	PURPLE_KEYRING_ERROR_UNKNOWN = 0,     /**< Unknown error. */
+
+	PURPLE_KEYRING_ERROR_NOKEYRING = 10,  /**< No keyring configured. */
+	PURPLE_KEYRING_ERROR_INTERNAL,        /**< Internal keyring system error. */
+	PURPLE_KEYRING_ERROR_BACKENDFAIL,     /**< Failed to communicate with the backend or internal backend error. */
+
+	PURPLE_KEYRING_ERROR_NOPASSWORD = 20, /**< No password stored for the specified account. */
+	PURPLE_KEYRING_ERROR_ACCESSDENIED,    /**< Access denied for the specified keyring or entry. */
+	PURPLE_KEYRING_ERROR_CANCELLED        /**< Operation was cancelled. */
 };
 
 /*}@*/
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
@@ -98,28 +98,28 @@ gnomekeyring_read_cb(GnomeKeyringResult 
 		error = NULL;
 	} else if (result == GNOME_KEYRING_RESULT_NO_MATCH) {
 		error = g_error_new(PURPLE_KEYRING_ERROR,
-			PURPLE_KEYRING_ERROR_NOPASSWD,
+			PURPLE_KEYRING_ERROR_NOPASSWORD,
 			"No password found for account");
 	} else if (result == GNOME_KEYRING_RESULT_DENIED ||
 		result == GNOME_KEYRING_RESULT_CANCELLED) {
 		error = g_error_new(PURPLE_KEYRING_ERROR,
-			PURPLE_KEYRING_ERROR_WRONGPASS,
+			PURPLE_KEYRING_ERROR_ACCESSDENIED,
 			"Access denied");
 		gnomekeyring_cancel_queue();
 	} else if (result == GNOME_KEYRING_RESULT_NO_KEYRING_DAEMON ||
 		GNOME_KEYRING_RESULT_IO_ERROR) {
 		error = g_error_new(PURPLE_KEYRING_ERROR,
-			PURPLE_KEYRING_ERROR_NOCHANNEL,
+			PURPLE_KEYRING_ERROR_BACKENDFAIL,
 			"Communication with GNOME Keyring failed");
 	} else {
 		error = g_error_new(PURPLE_KEYRING_ERROR,
-			PURPLE_KEYRING_ERROR_NOCHANNEL,
+			PURPLE_KEYRING_ERROR_BACKENDFAIL,
 			"Unknown error (code: %d)", result);
 	}
 
 	if (error == NULL && password == NULL) {
 		error = g_error_new(PURPLE_KEYRING_ERROR,
-			PURPLE_KEYRING_ERROR_NOCHANNEL,
+			PURPLE_KEYRING_ERROR_BACKENDFAIL,
 			"Unknown error (password empty)");
 	}
 
@@ -176,17 +176,17 @@ gnomekeyring_save_cb(GnomeKeyringResult 
 	} else if (result == GNOME_KEYRING_RESULT_DENIED ||
 		result == GNOME_KEYRING_RESULT_CANCELLED) {
 		error = g_error_new(PURPLE_KEYRING_ERROR,
-			PURPLE_KEYRING_ERROR_WRONGPASS,
+			PURPLE_KEYRING_ERROR_ACCESSDENIED,
 			"Access denied");
 		gnomekeyring_cancel_queue();
 	} else if (result == GNOME_KEYRING_RESULT_NO_KEYRING_DAEMON ||
 		GNOME_KEYRING_RESULT_IO_ERROR) {
 		error = g_error_new(PURPLE_KEYRING_ERROR,
-			PURPLE_KEYRING_ERROR_NOCHANNEL,
+			PURPLE_KEYRING_ERROR_BACKENDFAIL,
 			"Communication with GNOME Keyring failed");
 	} else {
 		error = g_error_new(PURPLE_KEYRING_ERROR,
-			PURPLE_KEYRING_ERROR_NOCHANNEL,
+			PURPLE_KEYRING_ERROR_BACKENDFAIL,
 			"Unknown error (code: %d)", result);
 	}
 
@@ -237,7 +237,7 @@ gnomekeyring_request_cancel(gpointer _re
 
 	account = req->account;
 	error = g_error_new(PURPLE_KEYRING_ERROR,
-		PURPLE_KEYRING_ERROR_NOCHANNEL,
+		PURPLE_KEYRING_ERROR_CANCELLED,
 		"Operation cancelled");
 	if (req->type == GNOMEKEYRING_REQUEST_READ && req->cb.read)
 		req->cb.read(account, NULL, error, req->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
@@ -83,7 +83,7 @@ internal_keyring_read(PurpleAccount *acc
 				purple_account_get_protocol_id(account));
 		}
 		error = g_error_new(PURPLE_KEYRING_ERROR,
-			PURPLE_KEYRING_ERROR_NOPASSWD, "Password not found.");
+			PURPLE_KEYRING_ERROR_NOPASSWORD, "Password not found.");
 		if (cb != NULL)
 			cb(account, NULL, error, data);
 		g_error_free(error);
@@ -153,8 +153,8 @@ internal_keyring_import_password(PurpleA
 	} else {
 		if (error != NULL) {
 			*error = g_error_new(PURPLE_KEYRING_ERROR,
-				PURPLE_KEYRING_ERROR_WRONGFORMAT,
-				"invalid mode");
+				PURPLE_KEYRING_ERROR_BACKENDFAIL,
+				"Invalid password storage mode");
 		}
 		return FALSE;
 	}
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
@@ -138,7 +138,7 @@ KWalletPlugin::request::~request()
 void
 KWalletPlugin::request::abort()
 {
-	detailedAbort(PURPLE_KEYRING_ERROR_NOCHANNEL);
+	detailedAbort(PURPLE_KEYRING_ERROR_CANCELLED);
 }
 
 KWalletPlugin::engine::engine()
@@ -434,7 +434,7 @@ kwallet_read(PurpleAccount *account, Pur
 
 	if (KWallet::Wallet::keyDoesNotExist(KWALLET_WALLET_NAME,
 		KWALLET_FOLDER_NAME, kwallet_account_key(account))) {



More information about the Commits mailing list