diff options
| -rw-r--r-- | protocols/jabber/jabber_util.c | 11 | ||||
| -rw-r--r-- | tests/check_jabber_util.c | 9 | 
2 files changed, 14 insertions, 6 deletions
| diff --git a/protocols/jabber/jabber_util.c b/protocols/jabber/jabber_util.c index a0266d3e..db5944bc 100644 --- a/protocols/jabber/jabber_util.c +++ b/protocols/jabber/jabber_util.c @@ -3,7 +3,7 @@  *  BitlBee - An IRC to IM gateway                                           *  *  Jabber module - Misc. stuff                                              *  *                                                                           * -*  Copyright 2006 Wilmer van der Gaast <wilmer@gaast.net>                   * +*  Copyright 2006-2010 Wilmer van der Gaast <wilmer@gaast.net>                *                                                                           *  *  This program is free software; you can redistribute it and/or modify     *  *  it under the terms of the GNU General Public License as published by     * @@ -555,7 +555,7 @@ struct jabber_buddy *jabber_buddy_by_ext_jid( struct im_connection *ic, char *ji  int jabber_buddy_remove( struct im_connection *ic, char *full_jid_ )  {  	struct jabber_data *jd = ic->proto_data; -	struct jabber_buddy *bud, *prev, *bi; +	struct jabber_buddy *bud, *prev = NULL, *bi;  	char *s, *full_jid;  	full_jid = jabber_normalize( full_jid_ ); @@ -566,7 +566,7 @@ int jabber_buddy_remove( struct im_connection *ic, char *full_jid_ )  	if( ( bud = g_hash_table_lookup( jd->buddies, full_jid ) ) )  	{  		if( bud->next ) -			bud = bud->next; +			bud = (prev=bud)->next;  		/* If there's only one item in the list (and if the resource  		   matches), removing it is simple. (And the hash reference @@ -586,7 +586,7 @@ int jabber_buddy_remove( struct im_connection *ic, char *full_jid_ )  		}  		else  		{ -			for( bi = bud, prev = NULL; bi; bi = (prev=bi)->next ) +			for( bi = bud; bi; bi = (prev=bi)->next )  				if( strcmp( bi->resource, s + 1 ) == 0 )  					break; @@ -597,8 +597,7 @@ int jabber_buddy_remove( struct im_connection *ic, char *full_jid_ )  				if( prev )  					prev->next = bi->next;  				else -					/* The hash table should point at the second -					   item, because we're removing the first. */ +					/* Don't think this should ever happen anymore. */  					g_hash_table_replace( jd->buddies, bi->bare_jid, bi->next );  				g_free( bi->ext_jid ); diff --git a/tests/check_jabber_util.c b/tests/check_jabber_util.c index 47e1e1a0..bf6d3e60 100644 --- a/tests/check_jabber_util.c +++ b/tests/check_jabber_util.c @@ -83,6 +83,15 @@ static void check_buddy_add(int l)  	fail_if( jabber_buddy_remove( ic, "nekkid@lamejab.net/Illegal" ) );  	fail_unless( jabber_buddy_remove( ic, "nekkid@lamejab.net" ) );  	fail_if( jabber_buddy_by_jid( ic, "nekkid@lamejab.net", 0 ) ); +	 +	/* Fixing a bug in this branch that caused information to get lost when +	   removing the first full JID from a list. */ +	jabber_buddy_add( ic, "bugtest@google.com/A" ); +	jabber_buddy_add( ic, "bugtest@google.com/B" ); +	jabber_buddy_add( ic, "bugtest@google.com/C" ); +	fail_unless( jabber_buddy_remove( ic, "bugtest@google.com/A" ) ); +	fail_unless( jabber_buddy_remove( ic, "bugtest@google.com/B" ) ); +	fail_unless( jabber_buddy_remove( ic, "bugtest@google.com/C" ) );  }  Suite *jabber_util_suite (void) | 
