soc.2009.transport: 05b69c63: Fixed crash when PurpleBuddy had been re...

hanzz at soc.pidgin.im hanzz at soc.pidgin.im
Mon May 25 20:45:46 EDT 2009


-----------------------------------------------------------------
Revision: 05b69c63bdaff5b60f78753244dde5f5c8e16631
Ancestor: befb45413139c04b53e54759941b8b57df5ca962
Author: hanzz at soc.pidgin.im
Date: 2009-05-26T00:19:46
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/05b69c63bdaff5b60f78753244dde5f5c8e16631

Modified files:
        main.cpp main.h user.cpp user.h

ChangeLog: 

Fixed crash when PurpleBuddy had been removed, but pointer to it was still used

-------------- next part --------------
============================================================
--- main.cpp	3be25b60bb61ff986b54ba45817845d1188c30fd
+++ main.cpp	6fc8e8b73d3fcb67dbaed026814f913bfc46f4dd
@@ -125,6 +125,13 @@ static void buddyTypingStopped(PurpleAcc
 }
 
 /*
+ * Called when PurpleBuddy is removed
+ */
+static void buddyRemoved(PurpleBuddy *buddy, gpointer null) {
+	GlooxMessageHandler::instance()->purpleBuddyRemoved(buddy);
+}
+
+/*
  * Called when purple disconnects from legacy network.
  */
 void connection_report_disconnect(PurpleConnection *gc,PurpleConnectionError reason,const char *text){
@@ -560,6 +567,15 @@ void GlooxMessageHandler::purpleBuddyTyp
 	}
 }
 
+void GlooxMessageHandler::purpleBuddyRemoved(PurpleBuddy *buddy) {
+	if (buddy != NULL){
+		PurpleAccount *a = purple_buddy_get_account(buddy);
+		User *user = userManager()->getUserByAccount(a);
+		if (user!=NULL)
+			user->purpleBuddyRemoved(buddy);
+	}
+}
+
 void GlooxMessageHandler::purpleBuddyTypingStopped(PurpleAccount *account, const char *who){
 	User *user = userManager()->getUserByAccount(account);
 	if (user!=NULL){
@@ -1063,6 +1079,7 @@ bool GlooxMessageHandler::initPurple(){
 		static int conversation_handle;
 		static int conn_handle;
 		static int xfer_handle;
+		static int blist_handle;
 		iter = purple_plugins_get_protocols();
 		for (i = 0; iter; iter = iter->next) {
 			PurplePlugin *plugin = (PurplePlugin *)iter->data;
@@ -1082,6 +1099,7 @@ bool GlooxMessageHandler::initPurple(){
 		purple_signal_connect(purple_xfers_get_handle(), "file-recv-request", &xfer_handle, PURPLE_CALLBACK(newXfer), NULL);
 		purple_signal_connect(purple_xfers_get_handle(), "file-recv-complete", &xfer_handle, PURPLE_CALLBACK(XferComplete), NULL);
 		purple_signal_connect(purple_connections_get_handle(), "signed-on", &conn_handle,PURPLE_CALLBACK(signed_on), NULL);
+		purple_signal_connect(purple_blist_get_handle(), "buddy-removed", &blist_handle,PURPLE_CALLBACK(buddyRemoved), NULL);
 // 		purple_signal_connect(purple_connections_get_handle(), "connection-error", &conn_handle,PURPLE_CALLBACK(connection_error_cb), NULL);
 // 		base64Dir = std::string(g_build_filename(userDir.c_str(), "base64", NULL));
 // 		if (!g_file_test(base64Dir.c_str(), G_FILE_TEST_IS_DIR))
============================================================
--- main.h	150338a243569e9b1f3b92f448349cc40ea281d2
+++ main.h	eaa8de36fbccbdd2acf5943611cc6b6061547ee6
@@ -142,6 +142,7 @@ public:
 	void * purpleAuthorizeReceived(PurpleAccount *account,const char *remote_user,const char *id,const char *alias,const char *message,gboolean on_list,PurpleAccountRequestAuthorizationCb authorize_cb,PurpleAccountRequestAuthorizationCb deny_cb,void *user_data);
 	void purpleBuddyTyping(PurpleAccount *account, const char *who);
 	void purpleBuddyTypingStopped(PurpleAccount *account, const char *who);
+	void purpleBuddyRemoved(PurpleBuddy *buddy);
 	void purpleAuthorizeClose(void *data);
 	void purpleFileReceiveRequest(PurpleXfer *xfer);
 	void purpleFileReceiveComplete(PurpleXfer *xfer);
============================================================
--- user.cpp	9f29f4949be9280d84ddd30435523fbf3977d6e2
+++ user.cpp	ab26ce5358c92fa6bd8f88ce91cd85d9763142e2
@@ -442,6 +442,15 @@ void User::purpleBuddyChanged(PurpleBudd
 }
 
 /*
+ * Called when PurpleBuddy is removed.
+ */
+void User::purpleBuddyRemoved(PurpleBuddy *buddy) {
+	// we should remove pointer to buddy from subscribCache
+	std::string name(purple_buddy_get_name(buddy));
+	m_subscribeCache.erase(name);
+}
+
+/*
  * Called when new message has been received.
  */
 void User::purpleMessageReceived(PurpleAccount* account,char * name,char *msg,PurpleConversation *conv,PurpleMessageFlags flags){
============================================================
--- user.h	11ce62f3078fecb587aa9cc63b7f821ae544105a
+++ user.h	6dfedcc9a6d51a07e10976f6a58bf4905082980c
@@ -81,6 +81,7 @@ class User {
 
 		// Libpurple callbacks
 		void purpleBuddyChanged(PurpleBuddy *buddy);
+		void purpleBuddyRemoved(PurpleBuddy *buddy);
 		void purpleMessageReceived(PurpleAccount* account,char * name,char *msg,PurpleConversation *conv,PurpleMessageFlags flags);
 		void purpleConversationWriteIM(PurpleConversation *conv, const char *who, const char *msg, PurpleMessageFlags flags, time_t mtime);
 		void purpleAuthorizeReceived(PurpleAccount *account,const char *remote_user,const char *id,const char *alias,const char *message,gboolean on_list,PurpleAccountRequestAuthorizationCb authorize_cb,PurpleAccountRequestAuthorizationCb deny_cb,void *user_data);


More information about the Commits mailing list