diff options
| -rw-r--r-- | protocols/jabber/jabber_util.c | 33 | ||||
| -rw-r--r-- | tests/check_jabber_util.c | 42 | 
2 files changed, 46 insertions, 29 deletions
| diff --git a/protocols/jabber/jabber_util.c b/protocols/jabber/jabber_util.c index 78d1009c..44dc5984 100644 --- a/protocols/jabber/jabber_util.c +++ b/protocols/jabber/jabber_util.c @@ -289,8 +289,13 @@ char *jabber_normalize( const char *orig )  	len = strlen( orig );  	new = g_new( char, len + 1 ); -	for( i = 0; i < len; i ++ ) +	 +	/* So it turns out the /resource part is case sensitive. Yeah, and +	   it's Unicode but feck Unicode. :-P So stop once we see a slash. */ +	for( i = 0; i < len && orig[i] != '/' ; i ++ )  		new[i] = tolower( orig[i] ); +	for( ; orig[i]; i ++ ) +		new[i] = orig[i];  	new[i] = 0;  	return new; @@ -333,7 +338,7 @@ struct jabber_buddy *jabber_buddy_add( struct im_connection *ic, char *full_jid_  		for( bi = bud; bi; bi = bi->next )  		{  			/* Check for dupes. */ -			if( g_strcasecmp( bi->resource, s + 1 ) == 0 ) +			if( strcmp( bi->resource, s + 1 ) == 0 )  			{  				*s = '/';  				g_free( new ); @@ -386,7 +391,7 @@ struct jabber_buddy *jabber_buddy_by_jid( struct im_connection *ic, char *jid_,  	if( ( s = strchr( jid, '/' ) ) )  	{ -		int none_found = 0; +		int bare_exists = 0;  		*s = 0;  		if( ( bud = g_hash_table_lookup( jd->buddies, jid ) ) ) @@ -409,21 +414,19 @@ struct jabber_buddy *jabber_buddy_by_jid( struct im_connection *ic, char *jid_,  			/* See if there's an exact match. */  			for( ; bud; bud = bud->next ) -				if( g_strcasecmp( bud->resource, s + 1 ) == 0 ) +				if( strcmp( bud->resource, s + 1 ) == 0 )  					break;  		}  		else  		{ -			/* This hack is there to make sure that O_CREAT will -			   work if there's already another resouce present -			   for this JID, even if it's an unknown buddy. This -			   is done to handle conferences properly. */ -			none_found = 1; -			/* TODO(wilmer): Find out what I was thinking when I -			   wrote this??? And then fix it. This makes me sad... */ +			/* This variable tells the if down here that the bare +			   JID already exists and we should feel free to add +			   more resources, if the caller asked for that. */ +			bare_exists = 1;  		} -		if( bud == NULL && ( flags & GET_BUDDY_CREAT ) && ( imcb_find_buddy( ic, jid ) || !none_found ) ) +		if( bud == NULL && ( flags & GET_BUDDY_CREAT ) && +		    ( !bare_exists || imcb_find_buddy( ic, jid ) ) )  		{  			*s = '/';  			bud = jabber_buddy_add( ic, jid ); @@ -448,7 +451,7 @@ struct jabber_buddy *jabber_buddy_by_jid( struct im_connection *ic, char *jid_,  		else if( bud->resource && ( flags & GET_BUDDY_EXACT ) )  			/* We want an exact match, so in thise case there shouldn't be a /resource. */  			return NULL; -		else if( ( bud->resource == NULL || bud->next == NULL ) ) +		else if( bud->resource == NULL || bud->next == NULL )  			/* No need for selection if there's only one option. */  			return bud;  		else if( flags & GET_BUDDY_FIRST ) @@ -526,7 +529,7 @@ int jabber_buddy_remove( struct im_connection *ic, char *full_jid_ )  		   should be removed too!) */  		if( bud->next == NULL &&  		    ( ( s == NULL && bud->resource == NULL ) || -		      ( bud->resource && s && g_strcasecmp( bud->resource, s + 1 ) == 0 ) ) ) +		      ( bud->resource && s && strcmp( bud->resource, s + 1 ) == 0 ) ) )  		{  			g_hash_table_remove( jd->buddies, bud->bare_jid );  			g_free( bud->bare_jid ); @@ -549,7 +552,7 @@ int jabber_buddy_remove( struct im_connection *ic, char *full_jid_ )  		else  		{  			for( bi = bud, prev = NULL; bi; bi = (prev=bi)->next ) -				if( g_strcasecmp( bi->resource, s + 1 ) == 0 ) +				if( strcmp( bi->resource, s + 1 ) == 0 )  					break;  			g_free( full_jid ); diff --git a/tests/check_jabber_util.c b/tests/check_jabber_util.c index 2d54ed23..4728c5ee 100644 --- a/tests/check_jabber_util.c +++ b/tests/check_jabber_util.c @@ -10,47 +10,61 @@ static struct im_connection *ic;  static void check_buddy_add(int l)  { -	struct jabber_buddy *budw1, *budw2, *budw3, *budw4, *budn; -	int i; +	struct jabber_buddy *budw1, *budw2, *budw3, *budn, *bud;  	budw1 = jabber_buddy_add( ic, "wilmer@gaast.net/BitlBee" );  	budw1->last_act = time( NULL ) - 100; -	budw2 = jabber_buddy_add( ic, "wilmer@gaast.net/Telepathy" ); +	budw2 = jabber_buddy_add( ic, "WILMER@gaast.net/Telepathy" );  	budw2->priority = 2;  	budw2->last_act = time( NULL ); -	budw3 = jabber_buddy_add( ic, "wilmer@gaast.net/Druif" ); +	budw3 = jabber_buddy_add( ic, "wilmer@GAAST.NET/bitlbee" );  	budw3->last_act = time( NULL ) - 200;  	budw3->priority = 4;  	/* TODO(wilmer): Shouldn't this just return budw3? */ -	fail_if( jabber_buddy_add( ic, "wilmer@gaast.net/druif" ) != NULL ); +	fail_if( jabber_buddy_add( ic, "wilmer@gaast.net/Telepathy" ) != NULL );  	budn = jabber_buddy_add( ic, "nekkid@lamejab.net" );  	/* Shouldn't be allowed if there's already a bare JID. */  	fail_if( jabber_buddy_add( ic, "nekkid@lamejab.net/Illegal" ) ); +	/* Case sensitivity: Case only matters after the / */ +	fail_if( jabber_buddy_by_jid( ic, "wilmer@gaast.net/BitlBee", 0 ) == +	         jabber_buddy_by_jid( ic, "wilmer@gaast.net/bitlbee", 0 ) ); +	fail_if( jabber_buddy_by_jid( ic, "wilmer@gaast.net/telepathy", 0 ) ); +	  	fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net/BitlBee", 0 ) == budw1 ); -	fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net/bitlbee", GET_BUDDY_EXACT ) == budw1 ); -	fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net/BitlBee", GET_BUDDY_CREAT ) == budw1 ); +	fail_unless( jabber_buddy_by_jid( ic, "WILMER@GAAST.NET/BitlBee", GET_BUDDY_EXACT ) == budw1 ); +	fail_unless( jabber_buddy_by_jid( ic, "wilmer@GAAST.NET/BitlBee", GET_BUDDY_CREAT ) == budw1 );  	fail_if( jabber_buddy_by_jid( ic, "wilmer@gaast.net", GET_BUDDY_EXACT ) ); -	fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", GET_BUDDY_FIRST ) == budw1 ); -	fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) == budw3 ); +	fail_unless( jabber_buddy_by_jid( ic, "WILMER@gaast.net", 0 ) == budw3 ); + +	/* Check O_FIRST and see if it's indeed the first item from the list. */ +	fail_unless( ( bud = jabber_buddy_by_jid( ic, "wilmer@gaast.net", GET_BUDDY_FIRST ) ) == budw1 ); +	fail_unless( bud->next == budw2 && bud->next->next == budw3 && bud->next->next->next == NULL ); +	/* Change the resource_select setting, now we should get a different resource. */  	set_setstr( &ic->acc->set, "resource_select", "activity" ); -	fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) == budw2 ); +	fail_unless( jabber_buddy_by_jid( ic, "wilmer@GAAST.NET", 0 ) == budw2 ); +	/* Some testing of bare JID handling (which is horrible). */  	fail_if( jabber_buddy_by_jid( ic, "nekkid@lamejab.net/Illegal", 0 ) ); -	fail_if( jabber_buddy_by_jid( ic, "nekkid@lamejab.net/Illegal", GET_BUDDY_CREAT ) ); +	fail_if( jabber_buddy_by_jid( ic, "NEKKID@LAMEJAB.NET/Illegal", GET_BUDDY_CREAT ) );  	fail_unless( jabber_buddy_by_jid( ic, "nekkid@lamejab.net", 0 ) == budn ); -	fail_unless( jabber_buddy_by_jid( ic, "nekkid@lamejab.net", GET_BUDDY_EXACT ) == budn ); -	fail_unless( jabber_buddy_by_jid( ic, "nekkid@lamejab.net", GET_BUDDY_CREAT ) == budn ); +	fail_unless( jabber_buddy_by_jid( ic, "NEKKID@lamejab.net", GET_BUDDY_EXACT ) == budn ); +	fail_unless( jabber_buddy_by_jid( ic, "nekkid@LAMEJAB.NET", GET_BUDDY_CREAT ) == budn ); -	jabber_buddy_remove( ic, "wilmer@gaast.net/telepathy" ); +	/* More case sensitivity testing, and see if remove works properly. */ +	fail_if( jabber_buddy_remove( ic, "wilmer@gaast.net/telepathy" ) ); +	fail_if( jabber_buddy_by_jid( ic, "wilmer@GAAST.NET/telepathy", GET_BUDDY_CREAT ) == budw2 ); +	fail_unless( jabber_buddy_remove( ic, "wilmer@gaast.net/Telepathy" ) ); +	fail_unless( jabber_buddy_remove( ic, "wilmer@gaast.net/telepathy" ) );  	fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) == budw1 );  	fail_if( jabber_buddy_remove( ic, "wilmer@gaast.net" ) );  	fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) == budw1 ); +	/* Check if remove_bare() indeed gets rid of all. */  	fail_unless( jabber_buddy_remove_bare( ic, "wilmer@gaast.net" ) );  	fail_if( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) ); | 
