/cpw/tomkiewicz/masterpassword: c47b85d03439: keyring.c refactor...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Sat Apr 27 20:26:46 EDT 2013


Changeset: c47b85d034395ecbf59b4aca0695ebdd08e21ffe
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2013-04-28 02:26 +0200
Branch:	 soc.2008.masterpassword
URL: https://hg.pidgin.im/cpw/tomkiewicz/masterpassword/rev/c47b85d03439

Description:

keyring.c refactoring - order up function implementations

diffstat:

 libpurple/keyring.c |  815 +++++++++++++++++++++++++--------------------------
 libpurple/keyring.h |    6 +-
 2 files changed, 410 insertions(+), 411 deletions(-)

diffs (truncated from 950 to 300 lines):

diff --git a/libpurple/keyring.c b/libpurple/keyring.c
--- a/libpurple/keyring.c
+++ b/libpurple/keyring.c
@@ -34,11 +34,6 @@
 #include "internal.h"
 #include "dbus-maybe.h"
 
-/**************************************************************************/
-/** @name PurpleKeyring                                                   */
-/**************************************************************************/
-/*@{*/
-
 struct _PurpleKeyring
 {
 	char *name;
@@ -88,8 +83,12 @@ typedef struct
 	gpointer cb_data;
 } PurpleKeyringSetPasswordData;
 
-static void
-purple_keyring_close(PurpleKeyring *keyring);
+typedef struct
+{
+	gchar *keyring_id;
+	gchar *mode;
+	gchar *data;
+} PurpleKeyringFailedImport;
 
 static void
 purple_keyring_change_tracker_free(PurpleKeyringChangeTracker *tracker)
@@ -99,177 +98,19 @@ purple_keyring_change_tracker_free(Purpl
 	g_free(tracker);
 }
 
-PurpleKeyring *
-purple_keyring_new(void)
+static void
+purple_keyring_failed_import_free(PurpleKeyringFailedImport *import)
 {
-	return g_new0(PurpleKeyring, 1);
+	g_return_if_fail(import != NULL);
+
+	g_free(import->keyring_id);
+	g_free(import->mode);
+	g_free(import->data);
+	g_free(import);
 }
 
-void
-purple_keyring_free(PurpleKeyring *keyring)
-{
-	g_free(keyring->name);
-	g_free(keyring->id);
-	g_free(keyring);
-}
-
-const char *
-purple_keyring_get_name(const PurpleKeyring *keyring)
-{
-	g_return_val_if_fail(keyring != NULL, NULL);
-
-	return keyring->name;
-}
-
-const char *
-purple_keyring_get_id(const PurpleKeyring *keyring)
-{
-	g_return_val_if_fail(keyring != NULL, NULL);
-
-	return keyring->id;
-}
-
-PurpleKeyringRead
-purple_keyring_get_read_password(const PurpleKeyring *keyring)
-{
-	g_return_val_if_fail(keyring != NULL, NULL);
-
-	return keyring->read_password;
-}
-
-PurpleKeyringSave
-purple_keyring_get_save_password(const PurpleKeyring *keyring)
-{
-	g_return_val_if_fail(keyring != NULL, NULL);
-
-	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)
-{
-	g_return_val_if_fail(keyring != NULL, NULL);
-
-	return keyring->close_keyring;
-}
-
-PurpleKeyringChangeMaster
-purple_keyring_get_change_master(const PurpleKeyring *keyring)
-{
-	g_return_val_if_fail(keyring != NULL, NULL);
-
-	return keyring->change_master;
-}
-
-PurpleKeyringImportPassword
-purple_keyring_get_import_password(const PurpleKeyring *keyring)
-{
-	g_return_val_if_fail(keyring != NULL, NULL);
-
-	return keyring->import_password;
-}
-
-PurpleKeyringExportPassword
-purple_keyring_get_export_password(const PurpleKeyring *keyring)
-{
-	g_return_val_if_fail(keyring != NULL, NULL);
-
-	return keyring->export_password;
-}
-
-void
-purple_keyring_set_name(PurpleKeyring *keyring, const char *name)
-{
-	g_return_if_fail(keyring != NULL);
-	g_return_if_fail(name != NULL);
-
-	g_free(keyring->name);
-	keyring->name = g_strdup(name);
-}
-
-void
-purple_keyring_set_id(PurpleKeyring *keyring, const char *id)
-{
-	g_return_if_fail(keyring != NULL);
-	g_return_if_fail(id != NULL);
-
-	g_free(keyring->id);
-	keyring->id = g_strdup(id);
-}
-
-void
-purple_keyring_set_read_password(PurpleKeyring *keyring, PurpleKeyringRead read_cb)
-{
-	g_return_if_fail(keyring != NULL);
-	g_return_if_fail(read_cb != NULL);
-
-	keyring->read_password = read_cb;
-}
-
-void
-purple_keyring_set_save_password(PurpleKeyring *keyring, PurpleKeyringSave save_cb)
-{
-	g_return_if_fail(keyring != NULL);
-	g_return_if_fail(save_cb != NULL);
-
-	keyring->save_password = save_cb;
-}
-
-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_cb)
-{
-	g_return_if_fail(keyring != NULL);
-
-	keyring->close_keyring = close_cb;
-}
-
-void
-purple_keyring_set_change_master(PurpleKeyring *keyring, PurpleKeyringChangeMaster change)
-{
-	g_return_if_fail(keyring != NULL);
-
-	keyring->change_master = change;
-}
-
-void
-purple_keyring_set_import_password(PurpleKeyring *keyring, PurpleKeyringImportPassword import)
-{
-	g_return_if_fail(keyring != NULL);
-
-	keyring->import_password = import;
-}
-
-void
-purple_keyring_set_export_password(PurpleKeyring *keyring, PurpleKeyringExportPassword export)
-{
-	g_return_if_fail(keyring != NULL);
-
-	keyring->export_password = export;
-}
-
-/*@}*/
-
-
-/***************************************/
-/** @name Keyring API                  */
-/***************************************/
-/*@{*/
+static void
+purple_keyring_close(PurpleKeyring *keyring);
 
 static GList *purple_keyring_keyrings;              /* list of available keyrings */
 static PurpleKeyring *purple_keyring_inuse; /* keyring being used */
@@ -280,22 +121,27 @@ static PurpleKeyringChangeTracker *curre
 static gboolean purple_keyring_is_quitting = FALSE;
 static GHashTable *purple_keyring_failed_imports = NULL;
 
-typedef struct
+
+/**************************************************************************/
+/* Setting used keyrings                                                  */
+/**************************************************************************/
+
+PurpleKeyring *
+purple_keyring_find_keyring_by_id(const char *id)
 {
-	gchar *keyring_id;
-	gchar *mode;
-	gchar *data;
-} purple_keyring_failed_import;
+	GList *l;
+	PurpleKeyring *keyring;
+	const char *curr_id;
 
-static void
-purple_keyring_failed_import_free(purple_keyring_failed_import *import)
-{
-	g_return_if_fail(import != NULL);
+	for (l = purple_keyring_keyrings; l != NULL; l = l->next) {
+		keyring = l->data;
+		curr_id = purple_keyring_get_id(keyring);
 
-	g_free(import->keyring_id);
-	g_free(import->mode);
-	g_free(import->data);
-	g_free(import);
+		if (g_strcmp0(id, curr_id) == 0)
+			return keyring;
+	}
+
+	return NULL;
 }
 
 static void
@@ -316,179 +162,12 @@ purple_keyring_pref_cb(const char *pref,
 	purple_keyring_set_inuse(new, FALSE, NULL, data);
 }
 
-static void purple_keyring_core_initialized_cb(void)
-{
-	if (purple_keyring_inuse == NULL) {
-		purple_notify_error(NULL, _("Keyrings"),
-			_("Failed to load selected keyring."),
-			_("Check your system configuration or select another "
-			"one in Preferences dialog."));
-	}
-}
-
-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();
-		}
-	}
-	purple_keyring_is_quitting = TRUE;
-	if (purple_keyring_inuse != NULL) {
-		PurpleKeyringCancelRequests cancel;
-		cancel = purple_keyring_get_cancel_requests(
-			purple_keyring_inuse);
-		if (cancel)



More information about the Commits mailing list