soc.2009.transport: b0490de9: Fixed memory leak and purpleBuddyChanged...

hanzz at soc.pidgin.im hanzz at soc.pidgin.im
Sat Apr 25 06:55:43 EDT 2009


-----------------------------------------------------------------
Revision: b0490de955a0c884c5b3ad0fbb2f1f4fc587af51
Ancestor: 553e69c3dd3b766d79d4519f283c59f06a85f43a
Author: hanzz at soc.pidgin.im
Date: 2009-04-25T09:53:22
Branch: im.pidgin.soc.2009.transport
URL: http://d.pidgin.im/viewmtn/revision/info/b0490de955a0c884c5b3ad0fbb2f1f4fc587af51

Modified files:
        user.cpp user.h

ChangeLog: 

Fixed memory leak and purpleBuddyChanged optimization.

-------------- next part --------------
============================================================
--- user.cpp	d8cb9c175da4cc6ac88e188ed5d6f95c8ccfe17c
+++ user.cpp	87d0b8e31e2438c58787ba6ea891870ffdf1f2c5
@@ -193,7 +193,7 @@ void User::syncContacts()
 	for(std::map<std::string, RosterRow>::iterator u = m_roster.begin(); u != m_roster.end() ; u++){
 		buddy = purple_find_buddy(m_account, (*u).second.uin.c_str());
 		// buddy is not in blist, so it's not on server
-		if(!buddy) {
+		if (!buddy) {
 			// add buddy to server
 			buddy = purple_buddy_new(m_account,(*u).second.uin.c_str(),(*u).second.uin.c_str());
 			purple_blist_add_buddy(buddy, NULL, NULL ,NULL);
@@ -217,7 +217,7 @@ Tag *User::generatePresenceStanza(Purple
 	PurpleStatus *stat = purple_presence_get_active_status(pres);
 	if (stat==NULL)
 		return NULL;
-	int s=purple_status_type_get_primitive(purple_status_get_type(stat));
+	int s = purple_status_type_get_primitive(purple_status_get_type(stat));
 	const char *statusMessage = purple_status_get_attr_string(stat, "message");
 
 	Log().Get(m_jid) << "Generating presence stanza for user " << name;
@@ -304,18 +304,19 @@ void User::purpleReauthorizeBuddy(Purple
 		PurplePluginProtocolInfo *prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_account_get_connection(m_account)->prpl);
 		if(prpl_info && prpl_info->blist_node_menu){
 			for(l = ll = prpl_info->blist_node_menu((PurpleBlistNode*)buddy); l; l = l->next) {
-				if (l->data){
+				if (l->data) {
 					PurpleMenuAction *act = (PurpleMenuAction *) l->data;
 					if (act->label) {
 						Log().Get(m_jid) << (std::string)act->label;
 						if ((std::string)act->label == "Re-request Authorization"){
-							Log().Get(m_jid) << "rerequestin authorization for " << name;
+							Log().Get(m_jid) << "rerequesting authorization for " << name;
 							((GSourceFunc) act->callback)(act->data);
 							break;
 						}
 					}
 				}
 			}
+			g_list_free(ll);
 		}
 	}
 }
@@ -334,7 +335,8 @@ void User::purpleBuddyChanged(PurpleBudd
 	PurpleStatus *stat = purple_presence_get_active_status(pres);
 	if (stat==NULL)
 		return;
-	int s=purple_status_type_get_primitive(purple_status_get_type(stat));
+	int s = purple_status_type_get_primitive(purple_status_get_type(stat));
+	// TODO: rewrite me to use prpl_info->status_text(buddy)
 	const char *statusMessage = purple_status_get_attr_string(stat, "message");
 
 	Log().Get(m_jid) << "purpleBuddyChanged: " << name << " ("<< alias <<") (" << s << ")";
@@ -343,7 +345,13 @@ void User::purpleBuddyChanged(PurpleBudd
 		m_syncTimer = purple_timeout_add_seconds(4, sync_cb, this);
 	}
 
-	if (!isInRoster(name,"")){
+	bool inRoster = purple_blist_node_get_bool(&buddy->node, "inRoster");
+	if (!inRoster) {
+		inRoster = isInRoster(name,"");
+		purple_blist_node_set_bool(&buddy->node, "inRoster", true);
+	}
+
+	if (!inRoster) {
 		if (!m_rosterXCalled && hasFeature(GLOOX_FEATURE_ROSTERX)){
 			subscribeContact c;
 			c.uin=name;
============================================================
--- user.h	fd7434d5d35b75272a00cfebf0b5b8f65579d42e
+++ user.h	a641c455417dbe359743d2fc3e051c67442d1203
@@ -63,11 +63,16 @@ class User {
 		bool hasTransportFeature(int feature); // TODO: move me to p->hasTransportFeature and rewrite my API
 
 		// Utils
-		Tag *generatePresenceStanza(PurpleBuddy *buddy);
 		bool syncCallback();
 		bool isInRoster(const std::string &name,const std::string &subscription);
 		bool isOpenedConversation(const std::string &name);
 		bool hasFeature(int feature);
+		
+		// XMPP stuff
+		Tag *generatePresenceStanza(PurpleBuddy *buddy);
+		
+		// Libpurple stuff
+		void purpleReauthorizeBuddy(PurpleBuddy *buddy);
 
 		// Gloox callbacks
 		void receivedPresence(Stanza *stanza);
@@ -80,7 +85,6 @@ class User {
 		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 purpleBuddyTypingStopped(const std::string &uin);
 		void purpleBuddyTyping(const std::string &uin);
-		void purpleReauthorizeBuddy(PurpleBuddy *buddy);
 		void connected();
 		void disconnected();
 


More information about the Commits mailing list