Mercurial > pidgin.yaz
changeset 21391:4b1088076c50
Extract setting an account's current error to a static function. In the
process, g_strdup the description passed to connection_error_cb since it's not
guaranteed (and isn't, at least on MSN) to be a valid pointer for ever.
author | Will Thompson <will.thompson@collabora.co.uk> |
---|---|
date | Fri, 02 Nov 2007 19:36:34 +0000 |
parents | aa52a0a224be |
children | 2daec6b5bbca |
files | libpurple/account.c |
diffstat | 1 files changed, 31 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/account.c Fri Nov 02 15:00:24 2007 +0000 +++ b/libpurple/account.c Fri Nov 02 19:36:34 2007 +0000 @@ -2239,23 +2239,40 @@ } static void +set_current_error(PurpleAccount *account, + PurpleConnectionErrorInfo *new_err) +{ + PurpleAccountPrivate *priv = PURPLE_ACCOUNT_GET_PRIVATE(account); + PurpleConnectionErrorInfo *old_err = priv->current_error; + + if(new_err == old_err) + return; + + priv->current_error = new_err; + + purple_signal_emit(purple_accounts_get_handle(), + "account-error-changed", + account, old_err, new_err); + + if(old_err) + g_free(old_err->description); + + g_free(old_err); +} + +static void connection_error_cb(PurpleConnection *gc, - PurpleConnectionError err, - const gchar *desc, + PurpleConnectionError type, + const gchar *description, gpointer unused) { PurpleAccount *account = purple_connection_get_account(gc); - PurpleAccountPrivate *priv = PURPLE_ACCOUNT_GET_PRIVATE(account); - PurpleConnectionErrorInfo *old = priv->current_error; - - priv->current_error = g_new0(PurpleConnectionErrorInfo, 1); - priv->current_error->type = err; - priv->current_error->description = desc; - - purple_signal_emit(purple_accounts_get_handle(), - "account-error-changed", - account, old, priv->current_error); - g_free(old); + PurpleConnectionErrorInfo *err = g_new0(PurpleConnectionErrorInfo, 1); + + err->type = type; + err->description = g_strdup(description); + + set_current_error(account, err); } const PurpleConnectionErrorInfo * @@ -2268,18 +2285,7 @@ static void purple_account_clear_current_error(PurpleAccount *account) { - PurpleAccountPrivate *priv = PURPLE_ACCOUNT_GET_PRIVATE(account); - PurpleConnectionErrorInfo *old; - - if (priv->current_error) - { - old = priv->current_error; - priv->current_error = NULL; - purple_signal_emit(purple_accounts_get_handle(), - "account-error-changed", - account, old, priv->current_error); - g_free (old); - } + set_current_error(account, NULL); }