Mercurial > pidgin.yaz
comparison gtk/plugins/cap/cap.c @ 14821:5e5b34ac509a
[gaim-migrate @ 17588]
Don't rely on the sender or receiver of messages being a buddy,
and add some other safeguards to prevent crashes like bug #1585017
I'm pretty sure this is good, but don't have the necessary sqlite
installed to test this at the moment.
committer: Tailor Script <tailor@pidgin.im>
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Thu, 26 Oct 2006 15:55:31 +0000 |
parents | 1444d83ff10a |
children | 2db21e0292b8 |
comparison
equal
deleted
inserted
replaced
14820:77c68f898389 | 14821:5e5b34ac509a |
---|---|
107 } | 107 } |
108 | 108 |
109 static CapStatistics * get_stats_for(GaimBuddy *buddy) { | 109 static CapStatistics * get_stats_for(GaimBuddy *buddy) { |
110 gchar *buddy_name; | 110 gchar *buddy_name; |
111 CapStatistics *stats; | 111 CapStatistics *stats; |
112 | |
113 g_return_val_if_fail(buddy != NULL, NULL); | |
114 | |
112 buddy_name = g_strdup(buddy->name); | 115 buddy_name = g_strdup(buddy->name); |
113 stats = g_hash_table_lookup(_buddy_stats, buddy_name); | 116 stats = g_hash_table_lookup(_buddy_stats, buddy_name); |
114 if(!stats) { | 117 if(!stats) { |
115 stats = g_malloc(sizeof(CapStatistics)); | 118 stats = g_malloc(sizeof(CapStatistics)); |
116 stats->last_message = -1; | 119 stats->last_message = -1; |
338 | 341 |
339 /* Gaim Signal Handlers */ | 342 /* Gaim Signal Handlers */ |
340 | 343 |
341 /* sent-im-msg */ | 344 /* sent-im-msg */ |
342 static void sent_im_msg(GaimAccount *account, const char *receiver, const char *message) { | 345 static void sent_im_msg(GaimAccount *account, const char *receiver, const char *message) { |
343 GaimBuddy *buddy = gaim_find_buddy(account, receiver); | 346 GaimBuddy *buddy; |
344 guint interval = gaim_prefs_get_int("/plugins/gtk/cap/max_msg_difference") * 1000 * 60; | 347 guint interval, words; |
345 guint words = word_count(message); | 348 |
349 buddy = gaim_find_buddy(account, receiver); | |
350 | |
351 if (buddy == NULL) | |
352 return; | |
353 | |
354 interval = gaim_prefs_get_int("/plugins/gtk/cap/max_msg_difference") * 1000 * 60; | |
355 words = word_count(message); | |
356 | |
346 CapStatistics *stats = get_stats_for(buddy); | 357 CapStatistics *stats = get_stats_for(buddy); |
347 | 358 |
348 insert_word_count(gaim_account_get_username(account), receiver, words); | 359 insert_word_count(gaim_account_get_username(account), receiver, words); |
349 stats->last_message = time(NULL); | 360 stats->last_message = time(NULL); |
350 stats->last_message_status_id = gaim_status_get_id(get_status_for(buddy)); | 361 stats->last_message_status_id = gaim_status_get_id(get_status_for(buddy)); |
355 } | 366 } |
356 | 367 |
357 /* received-im-msg */ | 368 /* received-im-msg */ |
358 static void | 369 static void |
359 received_im_msg(GaimAccount *account, char *sender, char *message, GaimConversation *conv, GaimMessageFlags flags) { | 370 received_im_msg(GaimAccount *account, char *sender, char *message, GaimConversation *conv, GaimMessageFlags flags) { |
360 GaimBuddy *buddy = gaim_find_buddy(account, sender); | 371 GaimBuddy *buddy; |
372 CapStatistics *stats; | |
361 /* guint words = word_count(message); */ | 373 /* guint words = word_count(message); */ |
362 CapStatistics *stats = get_stats_for(buddy); | 374 |
375 buddy = gaim_find_buddy(account, sender); | |
376 | |
377 if (buddy == NULL) | |
378 return; | |
379 | |
380 stats = get_stats_for(buddy); | |
363 | 381 |
364 /* insert_word_count(sender, buddy_name, words); */ | 382 /* insert_word_count(sender, buddy_name, words); */ |
365 | 383 |
366 /* If we are waiting for a response from a prior message | 384 /* If we are waiting for a response from a prior message |
367 * then cancel the timeout callback. */ | 385 * then cancel the timeout callback. */ |