changeset 29725:ecc6217baa1e

struct hiding updates for mxit
author Gary Kramlich <grim@reaperworld.com>
date Fri, 11 Dec 2009 00:44:42 +0000
parents ca106d1e3d6d
children dba5d0f7bb39
files libpurple/protocols/mxit/mxit.c libpurple/protocols/mxit/profile.c libpurple/protocols/mxit/roster.c
diffstat 3 files changed, 42 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/mxit/mxit.c	Fri Dec 11 00:21:45 2009 +0000
+++ b/libpurple/protocols/mxit/mxit.c	Fri Dec 11 00:44:42 2009 +0000
@@ -188,7 +188,11 @@
 
 	/* find the buddy object */
 	buddy = purple_find_buddy( session->acc, who );
-	if ( ( !buddy ) || ( !buddy->proto_data ) )
+	if ( !buddy )
+		return;
+
+	contact = purple_buddy_get_protocol_data(buddy);
+	if ( !contact )
 		return;
 
 	/* we ignore all conversations with which we have chatted with in this session */
@@ -196,7 +200,6 @@
 		return;
 
 	/* determite if this buddy is a MXit service */
-	contact = buddy->proto_data;
 	switch ( contact->type ) {
 		case MXIT_TYPE_BOT :
 		case MXIT_TYPE_CHATROOM :
@@ -258,7 +261,7 @@
  */
 static const char* mxit_list_emblem( PurpleBuddy* buddy )
 {
-	struct contact*	contact = buddy->proto_data;
+	struct contact*	contact = purple_buddy_get_protocol_data(buddy);
 
 	if ( !contact )
 		return NULL;
@@ -295,7 +298,7 @@
  */
 char* mxit_status_text( PurpleBuddy* buddy )
 {
-	struct contact*	contact = buddy->proto_data;
+	struct contact*	contact = purple_buddy_get_protocol_data(buddy);
 
 	if ( !contact )
 		return NULL;
@@ -320,7 +323,7 @@
  */
 static void mxit_tooltip( PurpleBuddy* buddy, PurpleNotifyUserInfo* info, gboolean full )
 {
-	struct contact*	contact = buddy->proto_data;
+	struct contact*	contact = purple_buddy_get_protocol_data(buddy);
 
 	if ( !contact )
 		return;
@@ -455,7 +458,7 @@
 
 	purple_debug_info( MXIT_PLUGIN_ID, "mxit_free_buddy\n" );
 
-	contact = buddy->proto_data;
+	contact = purple_buddy_get_protocol_data(buddy);
 	if ( contact ) {
 		if ( contact->statusMsg )
 			g_free( contact->statusMsg );
@@ -463,7 +466,8 @@
 			g_free( contact->avatarId );
 		g_free( contact );
 	}
-	buddy->proto_data = NULL;
+
+	purple_buddy_set_protocol_data(buddy, NULL);
 }
 
 
--- a/libpurple/protocols/mxit/profile.c	Fri Dec 11 00:21:45 2009 +0000
+++ b/libpurple/protocols/mxit/profile.c	Fri Dec 11 00:44:42 2009 +0000
@@ -115,9 +115,9 @@
 
 	buddy = purple_find_buddy( session->acc, username );
 	if ( buddy ) {
-		purple_notify_user_info_add_pair( info, _( "Alias" ), buddy->alias );
+		purple_notify_user_info_add_pair( info, _( "Alias" ), purple_buddy_get_alias( buddy ) );
 		purple_notify_user_info_add_section_break( info );
-		contact = buddy->proto_data;
+		contact = purple_buddy_get_protocol_data(buddy);
 	}
 
 	purple_notify_user_info_add_pair( info, _( "Nick Name" ), profile->nickname );
--- a/libpurple/protocols/mxit/roster.c	Fri Dec 11 00:21:45 2009 +0000
+++ b/libpurple/protocols/mxit/roster.c	Fri Dec 11 00:44:42 2009 +0000
@@ -318,7 +318,7 @@
 
 		/* create new buddy */
 		buddy = purple_buddy_new( session->acc, contact->username, contact->alias );
-		buddy->proto_data = contact;
+		purple_buddy_set_protocol_data(buddy, contact);
 
 		/* add new buddy to list */
 		purple_blist_add_buddy( buddy, NULL, group, NULL );
@@ -326,13 +326,15 @@
 	else {
 		/* buddy was found in the group */
 
+		gpointer data = NULL;
+
 		/* now update the buddy's alias */
 		purple_blist_alias_buddy( buddy, contact->alias );
 
 		/* replace the buddy's contact struct */
-		if ( buddy->proto_data )
-			free( buddy->proto_data );
-		buddy->proto_data = contact;
+		if ( ( data = purple_buddy_get_protocol_data( buddy ) ) )
+			free( data );
+		purple_buddy_set_protocol_data( buddy, contact );
 	}
 
 	/* load buddy's avatar id */
@@ -379,7 +381,7 @@
 		return;
 	}
 
-	contact = buddy->proto_data;
+	contact = purple_buddy_get_protocol_data( buddy );
 	if ( !contact )
 		return;
 
@@ -439,9 +441,12 @@
 	for ( i = 0; i < g_slist_length( list ); i++ ) {
 		buddy = g_slist_nth_data( list, i );
 
-		if ( !buddy->proto_data ) {
+		if ( !purple_buddy_get_protocol_data( buddy ) ) {
+			const gchar *alias = purple_buddy_get_alias( buddy );
+			const gchar *name = purple_buddy_get_name( buddy );
+
 			/* this buddy should be removed, because we did not receive him in our roster update from MXit */
-			purple_debug_info( MXIT_PLUGIN_ID, "Removed 'old' buddy from the blist '%s' (%s)\n", buddy->alias, buddy->name );
+			purple_debug_info( MXIT_PLUGIN_ID, "Removed 'old' buddy from the blist '%s' (%s)\n", alias, name );
 			purple_blist_remove_buddy( buddy );
 		}
 	}
@@ -535,7 +540,7 @@
 		return FALSE;
 	}
 
-	contact = buddy->proto_data;
+	contact = purple_buddy_get_protocol_data( buddy );
 	if ( !contact )
 		return FALSE;
 
@@ -560,10 +565,13 @@
 	GSList*				list	= NULL;
 	PurpleBuddy*		mxbuddy	= NULL;
 	unsigned int		i;
+	const gchar *		buddy_name = purple_buddy_get_name( buddy );
+	const gchar *		buddy_alias = purple_buddy_get_alias( buddy );
+	const gchar *		group_name = purple_group_get_name( group );
 
-	purple_debug_info( MXIT_PLUGIN_ID, "mxit_add_buddy '%s' (group='%s')\n", buddy->name, group->name );
+	purple_debug_info( MXIT_PLUGIN_ID, "mxit_add_buddy '%s' (group='%s')\n", buddy_name, group_name );
 
-	list = purple_find_buddies( session->acc, buddy->name );
+	list = purple_find_buddies( session->acc, buddy_name );
 	if ( g_slist_length( list ) == 1 ) {
 		purple_debug_info( MXIT_PLUGIN_ID, "mxit_add_buddy (scenario 1) (list:%i)\n", g_slist_length( list ) );
 		/*
@@ -572,7 +580,7 @@
 		 * you accept an invite.  so in that case the user is already
 		 * in our blist and ready to be chatted to.
 		 */
-		mxit_send_invite( session, buddy->name, buddy->alias, group->name );
+		mxit_send_invite( session, buddy_name, buddy_alias, group_name );
 	}
 	else {
 		purple_debug_info( MXIT_PLUGIN_ID, "mxit_add_buddy (scenario 2) (list:%i)\n", g_slist_length( list ) );
@@ -585,17 +593,17 @@
 		for ( i = 0; i < g_slist_length( list ); i++ ) {
 			mxbuddy = g_slist_nth_data( list, i );
 
-			if ( mxbuddy->proto_data != NULL ) {
+			if ( purple_buddy_get_protocol_data( mxbuddy ) != NULL ) {
 				/* this is our REAL MXit buddy! */
 
 				/* now update the buddy's alias */
-				purple_blist_alias_buddy( mxbuddy, buddy->alias );
+				purple_blist_alias_buddy( mxbuddy, buddy_alias );
 
 				/* now update the buddy's group */
 //				mxbuddy = mxit_update_buddy_group( session, mxbuddy, group );
 
 				/* send the update to the MXit server */
-				mxit_send_update_contact( session, mxbuddy->name, mxbuddy->alias, group->name );
+				mxit_send_update_contact( session, purple_buddy_get_name( mxbuddy ), purple_buddy_get_alias( mxbuddy ), group_name );
 			}
 		}
 	}
@@ -623,10 +631,11 @@
 void mxit_remove_buddy( PurpleConnection* gc, PurpleBuddy* buddy, PurpleGroup* group )
 {
 	struct MXitSession*	session	= (struct MXitSession*) gc->proto_data;
+	const gchar *		buddy_name = purple_buddy_get_name( buddy );
 
-	purple_debug_info( MXIT_PLUGIN_ID, "mxit_remove_buddy '%s'\n", buddy->name );
+	purple_debug_info( MXIT_PLUGIN_ID, "mxit_remove_buddy '%s'\n", buddy_name );
 
-	mxit_send_remove( session, buddy->name );
+	mxit_send_remove( session, buddy_name );
 }
 
 
@@ -659,7 +668,7 @@
 		return;
 	}
 
-	mxit_send_update_contact( session, who, alias, group->name );
+	mxit_send_update_contact( session, who, alias, purple_group_get_name( group ) );
 }
 
 
@@ -685,7 +694,7 @@
 		return;
 	}
 
-	mxit_send_update_contact( session, who, buddy->alias, new_group );
+	mxit_send_update_contact( session, who, purple_buddy_get_alias( buddy ), new_group );
 }
 
 
@@ -704,7 +713,7 @@
 	PurpleBuddy*		buddy	= NULL;
 	GList*				item	= NULL;
 
-	purple_debug_info( MXIT_PLUGIN_ID, "mxit_rename_group from '%s' to '%s\n", old_name, group->name );
+	purple_debug_info( MXIT_PLUGIN_ID, "mxit_rename_group from '%s' to '%s\n", old_name, purple_group_get_name( group ) );
 
 	//  TODO: Might be more efficient to use the "rename group" command (cmd=29).
 
@@ -712,7 +721,7 @@
 	item = moved_buddies;
 	while ( item ) {
 		buddy = item->data;
-		mxit_send_update_contact( session, buddy->name, buddy->alias, group->name );
+		mxit_send_update_contact( session, purple_buddy_get_name( buddy ), purple_buddy_get_alias( buddy ), purple_group_get_name( group ) );
 		item = g_list_next( item );
 	}
 }