comparison libpurple/protocols/bonjour/bonjour.c @ 21654:32629dbb0bb9

Don't allow buddies to be manually added to Bonjour (remove the added buddy in the prpl add_buddy callback). Also, fix a crash when rendering the tooltip for one of these previously added buddies. Fixes #4045.
author Daniel Atallah <daniel.atallah@gmail.com>
date Mon, 26 Nov 2007 19:03:39 +0000
parents d3ac933fae46
children cc0809ec0c85
comparison
equal deleted inserted replaced
21653:28c63fdcda73 21654:32629dbb0bb9
41 #include "mdns_common.h" 41 #include "mdns_common.h"
42 #include "jabber.h" 42 #include "jabber.h"
43 #include "buddy.h" 43 #include "buddy.h"
44 #include "bonjour_ft.h" 44 #include "bonjour_ft.h"
45 45
46 /*
47 * TODO: Should implement an add_buddy callback that removes the buddy
48 * from the local list. Bonjour manages buddies for you, and
49 * adding someone locally by hand is stupid. Or, maybe even better,
50 * if a PRPL does not have an add_buddy callback then do not allow
51 * users to add buddies.
52 */
53
54 static char *default_firstname; 46 static char *default_firstname;
55 static char *default_lastname; 47 static char *default_lastname;
56 static char *default_hostname; 48 static char *default_hostname;
57 49
58 static void 50 static void
258 250
259 bonjour_dns_sd_send_status(bd->dns_sd_data, bonjour_status, stripped); 251 bonjour_dns_sd_send_status(bd->dns_sd_data, bonjour_status, stripped);
260 g_free(stripped); 252 g_free(stripped);
261 } 253 }
262 254
255 /*
256 * The add_buddy callback removes the buddy from the local list.
257 * Bonjour manages buddies for you, and adding someone locally by
258 * hand is stupid. Perhaps we should change libpurple not to allow adding
259 * if there is no add_buddy callback.
260 */
261 static void
262 bonjour_fake_add_buddy(PurpleConnection *pc, PurpleBuddy *buddy, PurpleGroup *group) {
263 purple_debug_error("bonjour", "Buddy '%s' manually added; removing. "
264 "Bonjour buddies must be discovered and not manually added.\n",
265 purple_buddy_get_name(buddy));
266
267 /* I suppose we could alert the user here, but it seems unnecessary. */
268
269 /* If this causes problems, it can be moved to an idle callback */
270 purple_blist_remove_buddy(buddy);
271 }
272
273
263 static void bonjour_remove_buddy(PurpleConnection *pc, PurpleBuddy *buddy, PurpleGroup *group) { 274 static void bonjour_remove_buddy(PurpleConnection *pc, PurpleBuddy *buddy, PurpleGroup *group) {
264 if (buddy->proto_data) { 275 if (buddy->proto_data) {
265 bonjour_buddy_delete(buddy->proto_data); 276 bonjour_buddy_delete(buddy->proto_data);
266 buddy->proto_data = NULL; 277 buddy->proto_data = NULL;
267 } 278 }
301 bonjour_convo_closed(PurpleConnection *connection, const char *who) 312 bonjour_convo_closed(PurpleConnection *connection, const char *who)
302 { 313 {
303 PurpleBuddy *buddy = purple_find_buddy(connection->account, who); 314 PurpleBuddy *buddy = purple_find_buddy(connection->account, who);
304 BonjourBuddy *bb; 315 BonjourBuddy *bb;
305 316
306 if (buddy == NULL) 317 if (buddy == NULL || buddy->proto_data == NULL)
307 { 318 {
308 /* 319 /*
309 * This buddy is not in our buddy list, and therefore does not really 320 * This buddy is not in our buddy list, and therefore does not really
310 * exist, so we won't have any data about them. 321 * exist, so we won't have any data about them.
311 */ 322 */
367 status_description = purple_status_get_name(status); 378 status_description = purple_status_get_name(status);
368 379
369 purple_notify_user_info_add_pair(user_info, _("Status"), status_description); 380 purple_notify_user_info_add_pair(user_info, _("Status"), status_description);
370 if (message != NULL) 381 if (message != NULL)
371 purple_notify_user_info_add_pair(user_info, _("Message"), message); 382 purple_notify_user_info_add_pair(user_info, _("Message"), message);
383
384 if (bb == NULL) {
385 purple_debug_error("bonjour", "Got tooltip request for a buddy without protocol data.\n");
386 return;
387 }
372 388
373 /* Only show first/last name if there is a nickname set (to avoid duplication) */ 389 /* Only show first/last name if there is a nickname set (to avoid duplication) */
374 if (bb->nick != NULL) { 390 if (bb->nick != NULL) {
375 if (bb->first != NULL) 391 if (bb->first != NULL)
376 purple_notify_user_info_add_pair(user_info, _("First name"), bb->first); 392 purple_notify_user_info_add_pair(user_info, _("First name"), bb->first);
423 NULL, /* send_typing */ 439 NULL, /* send_typing */
424 NULL, /* get_info */ 440 NULL, /* get_info */
425 bonjour_set_status, /* set_status */ 441 bonjour_set_status, /* set_status */
426 NULL, /* set_idle */ 442 NULL, /* set_idle */
427 NULL, /* change_passwd */ 443 NULL, /* change_passwd */
428 NULL, /* add_buddy */ 444 bonjour_fake_add_buddy, /* add_buddy */
429 NULL, /* add_buddies */ 445 NULL, /* add_buddies */
430 bonjour_remove_buddy, /* remove_buddy */ 446 bonjour_remove_buddy, /* remove_buddy */
431 NULL, /* remove_buddies */ 447 NULL, /* remove_buddies */
432 NULL, /* add_permit */ 448 NULL, /* add_permit */
433 NULL, /* add_deny */ 449 NULL, /* add_deny */