/cpw/tomkiewicz/masterpassword: 51c1bce7f52f: Tidying debug mess...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Thu Mar 21 19:05:18 EDT 2013


Changeset: 51c1bce7f52fbb0b2fc14655a9fb0bd8bacf2bfa
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2013-03-22 00:05 +0100
Branch:	 soc.2008.masterpassword
URL: https://hg.pidgin.im/cpw/tomkiewicz/masterpassword/rev/51c1bce7f52f

Description:

Tidying debug messages, signals

diffstat:

 libpurple/account.c                          |    9 +-
 libpurple/core.c                             |   12 +-
 libpurple/keyring.c                          |  194 ++++++++++++++------------
 libpurple/keyring.h                          |   12 +-
 libpurple/plugins/keyrings/internalkeyring.c |   54 +++---
 libpurple/plugins/keyrings/kwallet.cpp       |   29 +++-
 6 files changed, 169 insertions(+), 141 deletions(-)

diffs (truncated from 667 to 300 lines):

diff --git a/libpurple/account.c b/libpurple/account.c
--- a/libpurple/account.c
+++ b/libpurple/account.c
@@ -380,16 +380,12 @@ account_to_xmlnode(PurpleAccount *accoun
 
 	if (purple_account_get_remember_password(account))
 	{
-		purple_debug_info("account", "Exporting password for account %s (%s).\n",
-			purple_account_get_username(account),
-			purple_account_get_protocol_id(account));
-
 		purple_keyring_export_password(account, &keyring_id, 
 			&mode, &data, &error, &destroy);
 
 		if (error != NULL) {
 
-			purple_debug_info("account",
+			purple_debug_error("account",
 				"Failed to export password for account %s : %s.\n",
 				purple_account_get_username(account),
 				error->message);
@@ -980,8 +976,7 @@ parse_account(xmlnode *node)
 		result = purple_keyring_import_password(ret, keyring_id, mode, data, NULL);
 
 		if (result == TRUE) {
-			purple_debug_info("account", "Password imported successfully.\n");
-			purple_account_set_remember_password(ret, TRUE);		
+			purple_account_set_remember_password(ret, TRUE);
 		} else {
 			purple_debug_info("account", "Failed to import password.\n");
 		} 
diff --git a/libpurple/core.c b/libpurple/core.c
--- a/libpurple/core.c
+++ b/libpurple/core.c
@@ -114,6 +114,7 @@ purple_core_init(const char *ui)
 		purple_value_new(PURPLE_TYPE_BOXED, "GHashTable *")); /* Parameters */
 
 	purple_signal_register(core, "quitting", purple_marshal_VOID, NULL, 0);
+	purple_signal_register(core, "core-initialized", purple_marshal_VOID, NULL, 0);
 
 	/* The prefs subsystem needs to be initialized before static protocols
 	 * for protocol prefs to work. */
@@ -136,7 +137,6 @@ purple_core_init(const char *ui)
 
 	purple_ciphers_init();
 	purple_cmds_init();
-	purple_keyring_init();
 
 	/* Since plugins get probed so early we should probably initialize their
 	 * subsystem right away too.
@@ -148,6 +148,7 @@ purple_core_init(const char *ui)
 
 	purple_plugins_probe(G_MODULE_SUFFIX);
 
+	purple_keyring_init();
 	purple_theme_manager_init();
 
 	/* The buddy icon code uses the imgstore, so init it early. */
@@ -188,15 +189,14 @@ purple_core_init(const char *ui)
 	if (ops != NULL && ops->ui_init != NULL)
 		ops->ui_init();
 
-	/* Selected keyring may have failed to load, so UI should be notified */
-	purple_keyring_load_plugins();
-
 	/* The UI may have registered some theme types, so refresh them */
 	purple_theme_manager_refresh();
 
 	/* Load the buddy list after UI init */
 	purple_blist_boot();
 
+	purple_signal_emit(purple_get_core(), "core-initialized");
+
 	return TRUE;
 }
 
@@ -222,9 +222,8 @@ purple_core_quit(void)
 	 */
 	purple_certificate_uninit();
 
-	/* The SSL and keyring plugins must be uninit before they're unloaded */
+	/* The SSL plugins must be uninit before they're unloaded */
 	purple_ssl_uninit();
-	purple_keyring_uninit();
 
 	/* Unload all non-loader, non-prpl plugins before shutting down
 	 * subsystems. */
@@ -245,6 +244,7 @@ purple_core_quit(void)
 	purple_savedstatuses_uninit();
 	purple_status_uninit();
 	purple_accounts_uninit();
+	purple_keyring_uninit(); /* after accounts */
 	purple_sound_uninit();
 	purple_theme_manager_uninit();
 	purple_xfers_uninit();
diff --git a/libpurple/keyring.c b/libpurple/keyring.c
--- a/libpurple/keyring.c
+++ b/libpurple/keyring.c
@@ -254,10 +254,53 @@ purple_keyring_pref_cb(const char *pref,
 	purple_keyring_set_inuse(new, FALSE, NULL, data);
 }
 
-void purple_keyring_load_plugins(void)
+static void purple_keyring_core_initialized_cb()
 {
+	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."));
+	}
+}
+
+void
+purple_keyring_init(void)
+{
+	const char *touse;
 	GList *it;
 
+	purple_keyring_keyrings = NULL;
+	purple_keyring_inuse = NULL;
+
+	purple_signal_register(purple_keyring_get_handle(),
+		"keyring-register",
+		purple_marshal_VOID__POINTER_POINTER,
+		NULL, 2,
+		purple_value_new(PURPLE_TYPE_STRING),                    /* keyring ID */
+		purple_value_new(PURPLE_TYPE_BOXED, "PurpleKeyring *")); /* a pointer to the keyring */
+
+	purple_signal_register(purple_keyring_get_handle(),
+		"keyring-unregister",
+		purple_marshal_VOID__POINTER_POINTER,
+		NULL, 2,
+		purple_value_new(PURPLE_TYPE_STRING),                    /* keyring ID */
+		purple_value_new(PURPLE_TYPE_BOXED, "PurpleKeyring *")); /* a pointer to the keyring */
+
+	/* see what keyring we want to use */
+	touse = purple_prefs_get_string("/purple/keyring/active");
+
+	if (touse == NULL) {
+		purple_prefs_add_none("/purple/keyring");
+		purple_prefs_add_string("/purple/keyring/active", PURPLE_DEFAULT_KEYRING);
+		purple_keyring_to_use = g_strdup(PURPLE_DEFAULT_KEYRING);
+	} else {
+		purple_keyring_to_use = g_strdup(touse);
+	}
+
+	purple_keyring_pref_cb_id = purple_prefs_connect_callback(NULL,
+		"/purple/keyring/active", purple_keyring_pref_cb, NULL);
+
 	for (it = purple_plugins_get_all(); it != NULL; it = it->next)
 	{
 		PurplePlugin *plugin = (PurplePlugin *)it->data;
@@ -277,63 +320,18 @@ void purple_keyring_load_plugins(void)
 		}
 	}
 
-	if (purple_keyring_inuse == NULL) {
+	if (purple_keyring_inuse == NULL)
 		purple_debug_error("keyring", "selected keyring failed to load\n");
-		purple_notify_error(NULL, _("Keyrings"),
-			_("Failed to load selected keyring."),
-			_("Check your system configuration or select another "
-			"one in Preferences dialog."));
-	}
-}
 
-void
-purple_keyring_init(void)
-{
-	PurpleCore *core;
-	const char *touse;
-
-	/* Make sure we don't have junk */
-	purple_keyring_keyrings = NULL;
-	purple_keyring_inuse = NULL;
-
-	/* register signals */
-	core = purple_get_core();
-
-	purple_signal_register(core, "keyring-register",
-		purple_marshal_VOID__POINTER_POINTER,
-		NULL, 2,
-		purple_value_new(PURPLE_TYPE_STRING),                    /* keyring ID */
-		purple_value_new(PURPLE_TYPE_BOXED, "PurpleKeyring *")); /* a pointer to the keyring */
-
-	purple_signal_register(core, "keyring-unregister",
-		purple_marshal_VOID__POINTER_POINTER,
-		NULL, 2,
-		purple_value_new(PURPLE_TYPE_STRING),                    /* keyring ID */
-		purple_value_new(PURPLE_TYPE_BOXED, "PurpleKeyring *")); /* a pointer to the keyring */
-
-	/* see what keyring we want to use */
-	touse = purple_prefs_get_string("/purple/keyring/active");
-
-	if (touse == NULL) {
-		purple_prefs_add_none("/purple/keyring");
-		purple_prefs_add_string("/purple/keyring/active", PURPLE_DEFAULT_KEYRING);
-		purple_keyring_to_use = g_strdup(PURPLE_DEFAULT_KEYRING);
-	} else {
-		purple_keyring_to_use = g_strdup(touse);
-	}
-
-	purple_keyring_pref_cb_id = purple_prefs_connect_callback(NULL,
-		"/purple/keyring/active", purple_keyring_pref_cb, NULL);
-
-	purple_debug_info("keyring", "purple_keyring_init() done, selected keyring is : %s.\n",
-		purple_keyring_to_use);
+	purple_signal_connect(purple_get_core(), "core-initialized",
+		purple_keyring_get_handle(),
+		PURPLE_CALLBACK(purple_keyring_core_initialized_cb), NULL);
 }
 
 void
 purple_keyring_uninit(void)
 {
 	GList *it;
-	PurpleCore *core = purple_get_core();
 
 	g_free(purple_keyring_to_use);
 	purple_keyring_inuse = NULL;
@@ -349,12 +347,19 @@ purple_keyring_uninit(void)
 	g_list_free(purple_keyring_loaded_plugins);
 	purple_keyring_loaded_plugins = NULL;
 
-	purple_signal_unregister(core, "keyring-register");
-	purple_signal_unregister(core, "keyring-unregister");
+	purple_signals_unregister_by_instance(purple_keyring_get_handle());
 	purple_prefs_disconnect_callback(purple_keyring_pref_cb_id);
 	purple_keyring_pref_cb_id = 0;
 }
 
+void *
+purple_keyring_get_handle(void)
+{
+	static int handle;
+
+	return &handle;
+}
+
 PurpleKeyring *
 purple_keyring_find_keyring_by_id(const char *id)
 {
@@ -426,26 +431,26 @@ purple_keyring_set_inuse_check_error_cb(
 		switch(error->code) {
 			case PURPLE_KEYRING_ERROR_NOCAP:
 				purple_debug_info("keyring",
-					"Keyring could not save password for account %s : %s.\n",
+					"Keyring could not save password for account %s: %s.\n",
 					name, error->message);
 				break;
 
 			case PURPLE_KEYRING_ERROR_NOPASSWD:
 				purple_debug_info("keyring",
-					"No password found while changing keyring for account %s : %s.\n",
+					"No password found while changing keyring for account %s: %s.\n",
 					name, error->message);
 				break;
 
 			case PURPLE_KEYRING_ERROR_NOCHANNEL:
 				purple_debug_info("keyring",
-					"Failed to communicate with backend while changing keyring for account %s : %s. Aborting changes.\n",
+					"Failed to communicate with backend while changing keyring for account %s: %s. Aborting changes.\n",
 					name, error->message);
 				tracker->abort = TRUE;
 				break;
 
 			default:
 				purple_debug_info("keyring",
-					"Unknown error while changing keyring for account %s : %s.\n",
+					"Unknown error while changing keyring for account %s: %s.\n",
 					name, error->message);
 				break;
 		}
@@ -561,11 +566,8 @@ purple_keyring_set_inuse(const PurpleKey
 	PurpleKeyringClose close;
 	PurpleKeyringChangeTracker *tracker;
 
-	if (newkeyring != NULL)
-		purple_debug_info("keyring", "Attempting to set new keyring : %s.\n",
-			newkeyring->id);
-	else
-		purple_debug_info("keyring", "Attempting to set new keyring : NULL.\n");
+	purple_debug_info("keyring", "Attempting to set new keyring: %s.\n",
+		(newkeyring != NULL) ? newkeyring->id : "(null)");
 
 	oldkeyring = purple_keyring_get_inuse();
 
@@ -625,10 +627,12 @@ purple_keyring_set_inuse(const PurpleKey
 		}
 
 	} else { /* no keyring was set before. */
-		purple_debug_info("keyring", "Setting keyring for the first time : %s.\n",
-			newkeyring->id);
+		if (purple_debug_is_verbose()) {
+			purple_debug_misc("keyring", "Setting keyring for the "
+				"first time: %s.\n", newkeyring->id);
+		}
+
 		purple_keyring_inuse = newkeyring;



More information about the Commits mailing list