/cpw/tomkiewicz/masterpassword: 567c48f9658c: Refactor the keyri...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Sat Apr 27 11:46:44 EDT 2013


Changeset: 567c48f9658c467f579f2467d3ecfd0d4d3f16e2
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2013-04-27 17:46 +0200
Branch:	 soc.2008.masterpassword
URL: https://hg.pidgin.im/cpw/tomkiewicz/masterpassword/rev/567c48f9658c

Description:

Refactor the keyring API

diffstat:

 libpurple/keyring.c                          |   60 +--
 libpurple/keyring.h                          |  375 ++++++++++++++------------
 libpurple/plugins/keyrings/gnomekeyring.c    |    4 +-
 libpurple/plugins/keyrings/internalkeyring.c |    4 +-
 libpurple/plugins/keyrings/kwallet.cpp       |   14 +-
 libpurple/plugins/keyrings/secretservice.c   |    4 +-
 pidgin/gtkprefs.c                            |    4 +-
 7 files changed, 238 insertions(+), 227 deletions(-)

diffs (truncated from 927 to 300 lines):

diff --git a/libpurple/keyring.c b/libpurple/keyring.c
--- a/libpurple/keyring.c
+++ b/libpurple/keyring.c
@@ -1,5 +1,5 @@
 /**
- * @file keyring.c Keyring plugin API
+ * @file keyring.c Keyring API
  * @ingroup core
  */
 
@@ -60,8 +60,8 @@ struct _PurpleKeyringChangeTracker
 	GError *error;
 	PurpleKeyringSetInUseCallback cb;
 	gpointer data;
-	const PurpleKeyring *new;
-	const PurpleKeyring *old;   /* we are done when: finished == TRUE && read_outstanding == 0 */
+	PurpleKeyring *new;
+	PurpleKeyring *old; /* we are done when: finished == TRUE && read_outstanding == 0 */
 	int read_outstanding;
 	gboolean finished;
 	gboolean abort;
@@ -86,6 +86,9 @@ typedef struct
 } PurpleKeyringDropTracker;
 
 static void
+purple_keyring_close(PurpleKeyring *keyring);
+
+static void
 purple_keyring_change_tracker_free(PurpleKeyringChangeTracker *tracker)
 {
 	if (tracker->error)
@@ -269,7 +272,7 @@ purple_keyring_set_export_password(Purpl
 /*@{*/
 
 static GList *purple_keyring_keyrings;              /* list of available keyrings */
-static const PurpleKeyring *purple_keyring_inuse;   /* keyring being used         */
+static PurpleKeyring *purple_keyring_inuse; /* keyring being used */
 static char *purple_keyring_to_use;
 static guint purple_keyring_pref_cb_id;
 static GList *purple_keyring_loaded_plugins = NULL;
@@ -453,13 +456,7 @@ purple_keyring_find_keyring_by_id(const 
 	return NULL;
 }
 
-const GList *
-purple_keyring_get_keyrings(void)
-{
-	return purple_keyring_keyrings;
-}
-
-const PurpleKeyring *
+PurpleKeyring *
 purple_keyring_get_inuse(void)
 {
 	return purple_keyring_inuse;
@@ -483,7 +480,7 @@ purple_keyring_drop_passwords_cb(PurpleA
 }
 
 static void
-purple_keyring_drop_passwords(const PurpleKeyring *keyring,
+purple_keyring_drop_passwords(PurpleKeyring *keyring,
 	PurpleKeyringDropCallback cb, gpointer data)
 {
 	GList *cur;
@@ -517,10 +514,7 @@ purple_keyring_set_inuse_drop_cb(gpointe
 	g_return_if_fail(tracker != NULL);
 
 	if (tracker->succeeded) {
-		PurpleKeyringClose close_cb =
-			purple_keyring_get_close_keyring(tracker->old);
-		if (close_cb != NULL)
-			close_cb(NULL);
+		purple_keyring_close(tracker->old);
 
 		purple_debug_info("keyring", "Successfully changed keyring.\n");
 
@@ -530,14 +524,11 @@ purple_keyring_set_inuse_drop_cb(gpointe
 		if (tracker->cb != NULL)
 			tracker->cb(tracker->new, NULL, tracker->data);
 	} else {
-		PurpleKeyringClose close_cb =
-			purple_keyring_get_close_keyring(tracker->new);
-		if (close_cb != NULL)
-			close_cb(NULL);
-
 		purple_debug_error("keyring",
 			"Failed to change keyring, aborting.\n");
 
+		purple_keyring_close(tracker->new);
+
 		purple_prefs_disconnect_callback(purple_keyring_pref_cb_id);
 		purple_prefs_set_string("/purple/keyring/active",
 			purple_keyring_get_id(tracker->old));
@@ -641,7 +632,7 @@ purple_keyring_set_inuse_got_pw_cb(Purpl
                                    GError *error,
                                    gpointer data)
 {
-	const PurpleKeyring *new;
+	PurpleKeyring *new;
 	PurpleKeyringSave save_cb;
 	PurpleKeyringChangeTracker *tracker;
 
@@ -673,13 +664,13 @@ purple_keyring_set_inuse_got_pw_cb(Purpl
 }
 
 void
-purple_keyring_set_inuse(const PurpleKeyring *newkeyring,
+purple_keyring_set_inuse(PurpleKeyring *newkeyring,
                          gboolean force,
                          PurpleKeyringSetInUseCallback cb,
                          gpointer data)
 {
 	GList *cur;
-	const PurpleKeyring *oldkeyring;
+	PurpleKeyring *oldkeyring;
 	PurpleKeyringRead read_cb = NULL;
 	PurpleKeyringChangeTracker *tracker;
 
@@ -777,7 +768,7 @@ purple_keyring_get_options(void)
 		list = g_list_append(list, purple_keyring_to_use);
 	}
 
-	for (keyrings = purple_keyring_get_keyrings(); keyrings != NULL;
+	for (keyrings = purple_keyring_keyrings; keyrings != NULL;
 		keyrings = keyrings->next) {
 
 		keyring = keyrings->data;
@@ -835,7 +826,7 @@ purple_keyring_register(PurpleKeyring *k
 void
 purple_keyring_unregister(PurpleKeyring *keyring)
 {
-	const PurpleKeyring *inuse;
+	PurpleKeyring *inuse;
 	PurpleKeyring *fallback;
 	const char *keyring_id;
 
@@ -881,7 +872,7 @@ purple_keyring_import_password(PurpleAcc
                                const char *data,
                                GError **error)
 {
-	const PurpleKeyring *inuse;
+	PurpleKeyring *inuse;
 	PurpleKeyringImportPassword import;
 	const char *realid;
 
@@ -946,7 +937,7 @@ purple_keyring_export_password(PurpleAcc
                                GError **error,
                                GDestroyNotify *destroy)
 {
-	const PurpleKeyring *inuse;
+	PurpleKeyring *inuse;
 	PurpleKeyringExportPassword export;
 
 	inuse = purple_keyring_get_inuse();
@@ -1000,7 +991,7 @@ purple_keyring_get_password(PurpleAccoun
                             gpointer data)
 {
 	GError *error = NULL;
-	const PurpleKeyring *inuse;
+	PurpleKeyring *inuse;
 	PurpleKeyringRead read_cb;
 
 	if (purple_keyring_is_quitting) {
@@ -1092,7 +1083,7 @@ purple_keyring_set_password(PurpleAccoun
                             gpointer data)
 {
 	GError *error = NULL;
-	const PurpleKeyring *inuse;
+	PurpleKeyring *inuse;
 	PurpleKeyringSave save_cb;
 	PurpleKeyringCbInfo *cbinfo;
 
@@ -1141,9 +1132,8 @@ purple_keyring_set_password(PurpleAccoun
 	}
 }
 
-/* TODO: get rid of GError */
-void
-purple_keyring_close(PurpleKeyring *keyring, GError **error)
+static void
+purple_keyring_close(PurpleKeyring *keyring)
 {
 	PurpleKeyringClose close_cb;
 
@@ -1152,7 +1142,7 @@ purple_keyring_close(PurpleKeyring *keyr
 	close_cb = purple_keyring_get_close_keyring(keyring);
 
 	if (close_cb != NULL)
-		close_cb(error);
+		close_cb();
 }
 
 
@@ -1162,7 +1152,7 @@ purple_keyring_change_master(PurpleKeyri
 {
 	GError *error = NULL;
 	PurpleKeyringChangeMaster change;
-	const PurpleKeyring *inuse;
+	PurpleKeyring *inuse;
 
 	inuse = purple_keyring_get_inuse();
 
diff --git a/libpurple/keyring.h b/libpurple/keyring.h
--- a/libpurple/keyring.h
+++ b/libpurple/keyring.h
@@ -1,9 +1,6 @@
 /**
- * @file keyring.h Keyring plugin API
+ * @file keyring.h Keyring API
  * @ingroup core
- *
- * @todo
- *  - Offer a way to prompt the user for a password or for a password change.
  */
 
 /* purple
@@ -24,38 +21,36 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
  */
 
 #ifndef _PURPLE_KEYRING_H_
 #define _PURPLE_KEYRING_H_
 
-#include <glib.h>
 #include "account.h"
 
 /**
- * Default keyring
+ * Default keyring ID.
  */
 #define PURPLE_DEFAULT_KEYRING "keyring-internal"
 
-/*******************************************************/
-/** @name data structures and types                    */
-/*******************************************************/
+/**
+ * Keyring subsystem error domain.
+ */
+#define PURPLE_KEYRING_ERROR purple_keyring_error_domain()
+
+/**************************************************************************/
+/** @name Data structures and types                                       */
+/**************************************************************************/
 /*@{*/
+
 typedef struct _PurpleKeyring PurpleKeyring;
 
 /*@}*/
 
-/**
- * XXX maybe strip a couple GError* if they're not used,
- * since they should only be interresting for the callback
- *  --> ability to forward errors ?
- *
- */
-
-/********************************************************/
-/** @name Callbacks for basic keyring operation         */
-/********************************************************/
+/**************************************************************************/
+/** @name Callbacks for keyrings access functions                        */
+/**************************************************************************/
 /*@{*/
 
 /**
@@ -69,9 +64,7 @@ typedef struct _PurpleKeyring PurpleKeyr
  * @param data     Data passed to the callback.
  */
 typedef void (*PurpleKeyringReadCallback)(PurpleAccount *account,
-                                          const gchar *password,
-                                          GError *error,
-                                          gpointer data);
+	const gchar *password, GError *error, gpointer data);
 
 /**
  * Callback for once a password has been stored.
@@ -82,9 +75,8 @@ typedef void (*PurpleKeyringReadCallback
  * @param error   Error that may have occurred.
  * @param data    Data passed to the callback.
  */
-typedef void (*PurpleKeyringSaveCallback)(PurpleAccount *account,
-                                          GError *error,
-                                          gpointer data);
+typedef void (*PurpleKeyringSaveCallback)(PurpleAccount *account, GError *error,
+	gpointer data);
 
 /**
  * Callback for once the master password for a keyring has been changed.
@@ -92,8 +84,7 @@ typedef void (*PurpleKeyringSaveCallback
  * @param error  Error that has occurred.
  * @param data   Data passed to the callback.
  */
-typedef void (*PurpleKeyringChangeMasterCallback)(GError *error,
-                                                  gpointer data);
+typedef void (*PurpleKeyringChangeMasterCallback)(GError *error, gpointer data);
 



More information about the Commits mailing list