comparison libpurple/protocols/jabber/data.c @ 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 1bde873d1b94
children 2ab17571bf42
comparison
equal deleted inserted replaced
29650:0646207f360f 29651:84ec9e3cbb6d
179 static gboolean 179 static gboolean
180 jabber_data_has_valid_hash(const JabberData *data) 180 jabber_data_has_valid_hash(const JabberData *data)
181 { 181 {
182 const gchar *cid = jabber_data_get_cid(data); 182 const gchar *cid = jabber_data_get_cid(data);
183 gchar **cid_parts = g_strsplit(cid, "@", -1); 183 gchar **cid_parts = g_strsplit(cid, "@", -1);
184 gchar **iter; 184 guint num_cid_parts = 0;
185 int num_parts = 0; 185 gboolean ret = FALSE;
186 186
187 purple_debug_info("jabber", "validating BoB hash %s\n", cid); 187 if (cid_parts)
188 188 num_cid_parts = g_strv_length(cid_parts);
189 for (iter = cid_parts; *iter != NULL ; iter++) { 189
190 num_parts++; 190 if (num_cid_parts == 2 && purple_strequal(cid_parts[1], "bob.xmpp.org")) {
191 }
192
193 if (num_parts == 2 && purple_strequal(cid_parts[1], "bob.xmpp.org")) {
194 gchar **sub_parts = g_strsplit(cid_parts[0], "+", -1); 191 gchar **sub_parts = g_strsplit(cid_parts[0], "+", -1);
195 192 guint num_sub_parts = 0;
196 num_parts = 0; 193
197 for (iter = sub_parts ; *iter != NULL ; iter++) { 194 if (sub_parts)
198 num_parts++; 195 num_sub_parts = g_strv_length(sub_parts);
199 } 196
200 197 if (num_sub_parts == 2) {
201 if (num_parts == 2) {
202 const gchar *hash_algo = sub_parts[0]; 198 const gchar *hash_algo = sub_parts[0];
203 const gchar *hash_value = sub_parts[1]; 199 const gchar *hash_value = sub_parts[1];
204 gchar *digest = 200 gchar *digest =
205 jabber_calculate_data_hash(jabber_data_get_data(data), 201 jabber_calculate_data_hash(jabber_data_get_data(data),
206 jabber_data_get_size(data), hash_algo); 202 jabber_data_get_size(data), hash_algo);
207 203
208 if (digest) { 204 if (digest) {
209 gboolean result = purple_strequal(digest, hash_value); 205 ret = purple_strequal(digest, hash_value);
210 206
211 purple_debug_info("jabber", "BoB expecting hash: %s\n", digest); 207 if (!ret)
212 208 purple_debug_warning("jabber", "Unable to validate BoB "
213 if (!result) { 209 "hash; expecting %s, got %s\n",
214 purple_debug_error("jabber", "invalid BoB hash\n"); 210 cid, digest);
215 } 211
216 g_free(digest); 212 g_free(digest);
217 return result;
218 } else { 213 } else {
219 purple_debug_info("jabber", "unknown BoB hash algo\n"); 214 purple_debug_warning("jabber", "Unable to validate BoB hash; "
220 return FALSE; 215 "unknown hash algorithm %s\n", hash_algo);
221 } 216 }
222 } else { 217 } else {
223 return FALSE; 218 purple_debug_warning("jabber", "Malformed BoB CID\n");
224 } 219 }
225 } else { 220
226 return FALSE; 221 g_strfreev(sub_parts);
227 } 222 }
223
224 g_strfreev(cid_parts);
225 return ret;
228 } 226 }
229 227
230 228
231 typedef struct { 229 typedef struct {
232 gpointer userdata; 230 gpointer userdata;