im.pidgin.pidgin: a00ff8e1a342a8326627d51728ad97699740c945

datallah at pidgin.im datallah at pidgin.im
Mon Nov 26 14:10:38 EST 2007


-----------------------------------------------------------------
Revision: a00ff8e1a342a8326627d51728ad97699740c945
Ancestor: 88390766d9b581d7a7e2e3b6156437c5bef76e93
Author: datallah at pidgin.im
Date: 2007-11-26T19:03:39
Branch: im.pidgin.pidgin

Modified files:
        libpurple/protocols/bonjour/bonjour.c

ChangeLog: 

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.

-------------- next part --------------
============================================================
--- libpurple/protocols/bonjour/bonjour.c	eda33f3853fc4c25c2067eadf365f6ce0cb161da
+++ libpurple/protocols/bonjour/bonjour.c	961e8c5acba0264e7e2a9e9ecf0d1b0225bae9fe
@@ -43,14 +43,6 @@
 #include "buddy.h"
 #include "bonjour_ft.h"
 
-/*
- * TODO: Should implement an add_buddy callback that removes the buddy
- *       from the local list.  Bonjour manages buddies for you, and
- *       adding someone locally by hand is stupid.  Or, maybe even better,
- *       if a PRPL does not have an add_buddy callback then do not allow
- *       users to add buddies.
- */
-
 static char *default_firstname;
 static char *default_lastname;
 static char *default_hostname;
@@ -260,6 +252,25 @@ bonjour_set_status(PurpleAccount *accoun
 	g_free(stripped);
 }
 
+/*
+ * The add_buddy callback removes the buddy from the local list.
+ * Bonjour manages buddies for you, and adding someone locally by
+ * hand is stupid.  Perhaps we should change libpurple not to allow adding
+ * if there is no add_buddy callback.
+ */
+static void
+bonjour_fake_add_buddy(PurpleConnection *pc, PurpleBuddy *buddy, PurpleGroup *group) {
+	purple_debug_error("bonjour", "Buddy '%s' manually added; removing.  "
+				      "Bonjour buddies must be discovered and not manually added.\n",
+			   purple_buddy_get_name(buddy));
+
+	/* I suppose we could alert the user here, but it seems unnecessary. */
+
+	/* If this causes problems, it can be moved to an idle callback */
+	purple_blist_remove_buddy(buddy);
+}
+
+
 static void bonjour_remove_buddy(PurpleConnection *pc, PurpleBuddy *buddy, PurpleGroup *group) {
 	if (buddy->proto_data) {
 		bonjour_buddy_delete(buddy->proto_data);
@@ -303,7 +314,7 @@ bonjour_convo_closed(PurpleConnection *c
 	PurpleBuddy *buddy = purple_find_buddy(connection->account, who);
 	BonjourBuddy *bb;
 
-	if (buddy == NULL)
+	if (buddy == NULL || buddy->proto_data == NULL)
 	{
 		/*
 		 * This buddy is not in our buddy list, and therefore does not really
@@ -370,6 +381,11 @@ bonjour_tooltip_text(PurpleBuddy *buddy,
 	if (message != NULL)
 		purple_notify_user_info_add_pair(user_info, _("Message"), message);
 
+	if (bb == NULL) {
+		purple_debug_error("bonjour", "Got tooltip request for a buddy without protocol data.\n");
+		return;
+	}
+
 	/* Only show first/last name if there is a nickname set (to avoid duplication) */
 	if (bb->nick != NULL) {
 		if (bb->first != NULL)
@@ -425,7 +441,7 @@ static PurplePluginProtocolInfo prpl_inf
 	bonjour_set_status,                                      /* set_status */
 	NULL,                                                    /* set_idle */
 	NULL,                                                    /* change_passwd */
-	NULL,                                                    /* add_buddy */
+	bonjour_fake_add_buddy,                                  /* add_buddy */
 	NULL,                                                    /* add_buddies */
 	bonjour_remove_buddy,                                    /* remove_buddy */
 	NULL,                                                    /* remove_buddies */


More information about the Commits mailing list