/cpw/tomkiewicz/masterpassword: 8be287b0d6be: keyring.c refactor...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Sun Apr 28 05:32:39 EDT 2013


Changeset: 8be287b0d6be03e7715b4e5882a2a27df3838935
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2013-04-28 11:32 +0200
Branch:	 soc.2008.masterpassword
URL: https://hg.pidgin.im/cpw/tomkiewicz/masterpassword/rev/8be287b0d6be

Description:

keyring.c refactoring: registering, unregistering

diffstat:

 libpurple/keyring.c |  45 ++++++++++++++++++++++-----------------------
 libpurple/keyring.h |  32 ++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 23 deletions(-)

diffs (153 lines):

diff --git a/libpurple/keyring.c b/libpurple/keyring.c
--- a/libpurple/keyring.c
+++ b/libpurple/keyring.c
@@ -436,27 +436,25 @@ purple_keyring_register(PurpleKeyring *k
 
 	keyring_id = purple_keyring_get_id(keyring);
 
-	purple_debug_info("keyring", "Registering keyring: %s.\n",
-		keyring->id ? keyring->id : "(null)");
+	purple_debug_info("keyring", "Registering keyring: %s\n",
+		keyring_id ? keyring_id : "(null)");
 
 	if (purple_keyring_get_id(keyring) == NULL ||
 		purple_keyring_get_name(keyring) == NULL ||
 		purple_keyring_get_read_password(keyring) == NULL ||
 		purple_keyring_get_save_password(keyring) == NULL) {
-		purple_debug_error("keyring", "Invalid keyring %s, some "
+		purple_debug_error("keyring", "Cannot register %s, some "
 			"required fields are missing.\n",
-			keyring->id ? keyring->id : "(null)");
+			keyring_id ? keyring_id : "(null)");
 		return;
 	}
 
 	/* If this is the configured keyring, use it. */
 	if (purple_keyring_inuse == NULL &&
-	    g_strcmp0(keyring_id, purple_keyring_to_use) == 0) {
-
-		purple_debug_info("keyring", "Keyring %s matches keyring to use, using it.\n",
-			keyring->id);
+		g_strcmp0(keyring_id, purple_keyring_to_use) == 0) {
+		purple_debug_info("keyring", "Keyring %s matches keyring to "
+			"use, using it.\n", keyring_id);
 		purple_keyring_set_inuse(keyring, TRUE, NULL, NULL);
-
 	}
 
 	PURPLE_DBUS_REGISTER_POINTER(keyring, PurpleKeyring);
@@ -480,10 +478,11 @@ purple_keyring_unregister(PurpleKeyring 
 
 	g_return_if_fail(keyring != NULL);
 
+	keyring_id = purple_keyring_get_id(keyring);
+
 	purple_debug_info("keyring", "Unregistering keyring: %s.\n",
-		purple_keyring_get_id(keyring));
+		keyring_id);
 
-	keyring_id = purple_keyring_get_id(keyring);
 	purple_signal_emit(purple_keyring_get_handle(), "keyring-unregister",
 		keyring_id, keyring);
 	PURPLE_DBUS_UNREGISTER_POINTER(keyring);
@@ -494,7 +493,6 @@ purple_keyring_unregister(PurpleKeyring 
 	if (inuse == keyring) {
 		if (inuse != fallback) {
 			purple_keyring_set_inuse(fallback, TRUE, NULL, NULL);
-
 		} else {
 			fallback = NULL;
 			purple_keyring_set_inuse(NULL, TRUE, NULL, NULL);
@@ -508,28 +506,29 @@ purple_keyring_unregister(PurpleKeyring 
 GList *
 purple_keyring_get_options(void)
 {
-	const GList *keyrings;
-	PurpleKeyring *keyring;
-	GList *list = NULL;
+	GList *options = NULL;
+	GList *it;
 	static gchar currentDisabledName[40];
 
 	if (purple_keyring_get_inuse() == NULL && purple_keyring_to_use != NULL
 		&& purple_keyring_to_use[0] != '\0') {
 		g_snprintf(currentDisabledName, sizeof(currentDisabledName),
 			_("%s (disabled)"), purple_keyring_to_use);
-		list = g_list_append(list, currentDisabledName);
-		list = g_list_append(list, purple_keyring_to_use);
+
+		options = g_list_append(options, currentDisabledName);
+		options = g_list_append(options, purple_keyring_to_use);
 	}
 
-	for (keyrings = purple_keyring_keyrings; keyrings != NULL;
-		keyrings = keyrings->next) {
+	for (it = purple_keyring_keyrings; it != NULL; it = it->next) {
+		PurpleKeyring *keyring = it->data;
 
-		keyring = keyrings->data;
-		list = g_list_append(list, keyring->name);
-		list = g_list_append(list, keyring->id);
+		options = g_list_append(options,
+			(gpointer)purple_keyring_get_name(keyring));
+		options = g_list_append(options,
+			(gpointer)purple_keyring_get_id(keyring));
 	}
 
-	return list;
+	return options;
 }
 
 
diff --git a/libpurple/keyring.h b/libpurple/keyring.h
--- a/libpurple/keyring.h
+++ b/libpurple/keyring.h
@@ -391,16 +391,48 @@ purple_keyring_get_import_password(const
 PurpleKeyringExportPassword
 purple_keyring_get_export_password(const PurpleKeyring *keyring);
 
+/**
+ * Sets friendly user name.
+ *
+ * This field is required.
+ *
+ * @param keyring The keyring.
+ * @param name    Friendly user name.
+ */
 void
 purple_keyring_set_name(PurpleKeyring *keyring, const gchar *name);
 
+/**
+ * Sets keyring ID.
+ *
+ * This field is required.
+ *
+ * @param keyring The keyring.
+ * @param name    Keyring ID.
+ */
 void
 purple_keyring_set_id(PurpleKeyring *keyring, const gchar *id);
 
+/**
+ * Sets read password method.
+ *
+ * This field is required.
+ *
+ * @param keyring The keyring.
+ * @param read_cb Read password method.
+ */
 void
 purple_keyring_set_read_password(PurpleKeyring *keyring,
 	PurpleKeyringRead read_cb);
 
+/**
+ * Sets save password method.
+ *
+ * This field is required.
+ *
+ * @param keyring The keyring.
+ * @param save_cb Save password method.
+ */
 void
 purple_keyring_set_save_password(PurpleKeyring *keyring,
 	PurpleKeyringSave save_cb);



More information about the Commits mailing list