Mercurial > pidgin
changeset 29651:84ec9e3cbb6d
jabber: Plug some leaks and make the success case quieter.
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Wed, 31 Mar 2010 03:42:21 +0000 |
parents | 0646207f360f |
children | 7b4c881ebe64 |
files | libpurple/protocols/jabber/data.c |
diffstat | 1 files changed, 24 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/jabber/data.c Mon Mar 29 23:35:35 2010 +0000 +++ b/libpurple/protocols/jabber/data.c Wed Mar 31 03:42:21 2010 +0000 @@ -181,50 +181,48 @@ { const gchar *cid = jabber_data_get_cid(data); gchar **cid_parts = g_strsplit(cid, "@", -1); - gchar **iter; - int num_parts = 0; + guint num_cid_parts = 0; + gboolean ret = FALSE; - purple_debug_info("jabber", "validating BoB hash %s\n", cid); - - for (iter = cid_parts; *iter != NULL ; iter++) { - num_parts++; - } + if (cid_parts) + num_cid_parts = g_strv_length(cid_parts); - if (num_parts == 2 && purple_strequal(cid_parts[1], "bob.xmpp.org")) { + if (num_cid_parts == 2 && purple_strequal(cid_parts[1], "bob.xmpp.org")) { gchar **sub_parts = g_strsplit(cid_parts[0], "+", -1); + guint num_sub_parts = 0; - num_parts = 0; - for (iter = sub_parts ; *iter != NULL ; iter++) { - num_parts++; - } + if (sub_parts) + num_sub_parts = g_strv_length(sub_parts); - if (num_parts == 2) { + if (num_sub_parts == 2) { const gchar *hash_algo = sub_parts[0]; const gchar *hash_value = sub_parts[1]; gchar *digest = jabber_calculate_data_hash(jabber_data_get_data(data), jabber_data_get_size(data), hash_algo); - + if (digest) { - gboolean result = purple_strequal(digest, hash_value); - - purple_debug_info("jabber", "BoB expecting hash: %s\n", digest); + ret = purple_strequal(digest, hash_value); - if (!result) { - purple_debug_error("jabber", "invalid BoB hash\n"); - } + if (!ret) + purple_debug_warning("jabber", "Unable to validate BoB " + "hash; expecting %s, got %s\n", + cid, digest); + g_free(digest); - return result; } else { - purple_debug_info("jabber", "unknown BoB hash algo\n"); - return FALSE; + purple_debug_warning("jabber", "Unable to validate BoB hash; " + "unknown hash algorithm %s\n", hash_algo); } } else { - return FALSE; + purple_debug_warning("jabber", "Malformed BoB CID\n"); } - } else { - return FALSE; + + g_strfreev(sub_parts); } + + g_strfreev(cid_parts); + return ret; }