diff options
| -rw-r--r-- | protocols/jabber/iq.c | 2 | ||||
| -rw-r--r-- | protocols/jabber/jabber.h | 1 | ||||
| -rw-r--r-- | protocols/jabber/jabber_util.c | 22 | ||||
| -rw-r--r-- | tests/check_jabber_util.c | 11 | 
4 files changed, 35 insertions, 1 deletions
| diff --git a/protocols/jabber/iq.c b/protocols/jabber/iq.c index 31b92049..61417bcc 100644 --- a/protocols/jabber/iq.c +++ b/protocols/jabber/iq.c @@ -351,7 +351,7 @@ xt_status jabber_pkt_bind_sess( struct im_connection *ic, struct xt_node *node,  		{  			/* Server is crap, but this is no disaster. */  		} -		else if( strncmp( jd->me, c->text, strlen( jd->me ) ) != 0 ) +		else if( jabber_compare_jid( jd->me, c->text ) == 0 )  		{  			s = strchr( c->text, '/' );  			if( s ) diff --git a/protocols/jabber/jabber.h b/protocols/jabber/jabber.h index 006da9a3..21769a3b 100644 --- a/protocols/jabber/jabber.h +++ b/protocols/jabber/jabber.h @@ -288,6 +288,7 @@ xt_status jabber_cache_handle_packet( struct im_connection *ic, struct xt_node *  const struct jabber_away_state *jabber_away_state_by_code( char *code );  const struct jabber_away_state *jabber_away_state_by_name( char *name );  void jabber_buddy_ask( struct im_connection *ic, char *handle ); +int jabber_compare_jid( const char *jid1, const char *jid2 );  char *jabber_normalize( const char *orig );  typedef enum diff --git a/protocols/jabber/jabber_util.c b/protocols/jabber/jabber_util.c index 67aa378a..f850e9d6 100644 --- a/protocols/jabber/jabber_util.c +++ b/protocols/jabber/jabber_util.c @@ -307,6 +307,28 @@ void jabber_buddy_ask( struct im_connection *ic, char *handle )  	g_free( buf );  } +/* Compares two Jabber IDs to check for match. */ +int jabber_compare_jid( const char *jid1, const char *jid2 ) +{ +	int i; +	 +	for( i = 0; ; i ++ ) +	{ +		if( jid1[i] == '\0' || jid1[i] == '/' || jid2[i] == '\0' || jid2[i] == '/' ) +		{ +			if( ( jid1[i] == '\0' || jid1[i] == '/' ) && ( jid2[i] == '\0' || jid2[i] == '/' ) ) +				break; +			return FALSE; +		} +		if( tolower( jid1[i] ) != tolower( jid2[i] ) ) +		{ +			return FALSE; +		} +	} +	 +	return TRUE; +} +  /* Returns a new string. Don't leak it! */  char *jabber_normalize( const char *orig )  { diff --git a/tests/check_jabber_util.c b/tests/check_jabber_util.c index bf6d3e60..966b5230 100644 --- a/tests/check_jabber_util.c +++ b/tests/check_jabber_util.c @@ -94,6 +94,16 @@ static void check_buddy_add(int l)  	fail_unless( jabber_buddy_remove( ic, "bugtest@google.com/C" ) );  } +static void check_compareJID(int l) +{ +	fail_unless( jabber_compare_jid( "bugtest@google.com/B", "bugtest@google.com/A" ) ); +	fail_if( jabber_compare_jid( "bugtest1@google.com/B", "bugtest@google.com/A" ) ); +	fail_if( jabber_compare_jid( "bugtest@google.com/B", "bugtest1@google.com/A" ) ); +	fail_if( jabber_compare_jid( "bugtest1@google.com/B", "bugtest2@google.com/A" ) ); +	fail_unless( jabber_compare_jid( "bugtest@google.com/A", "bugtest@google.com/A" ) ); +	fail_if( jabber_compare_jid( "", "bugtest@google.com/A" ) ); +} +  Suite *jabber_util_suite (void)  {  	Suite *s = suite_create("jabber/util"); @@ -109,5 +119,6 @@ Suite *jabber_util_suite (void)  	suite_add_tcase (s, tc_core);  	tcase_add_test (tc_core, check_buddy_add); +	tcase_add_test (tc_core, check_compareJID);  	return s;  } | 
