aboutsummaryrefslogtreecommitdiffstats
path: root/protocols/jabber/jabber_util.c
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2008-06-22 00:51:18 +0100
committerWilmer van der Gaast <wilmer@gaast.net>2008-06-22 00:51:18 +0100
commit98de2cca016d458ad2980c59f334fae10164b3bb (patch)
tree09ba75f3fd231a9256a234c66bf896b84f01e6fe /protocols/jabber/jabber_util.c
parent3e6764ab9c8ebd99683fd3c153161d96b32e05de (diff)
Now preserving case in JID resources, and handling them with case sensitivity
since apparently that's how the RFC wants it. (While the rest of the JID should be case IN-sensitive. Consistency is hard to find these days...) Also extended the unittests a little bit. Closes #422.
Diffstat (limited to 'protocols/jabber/jabber_util.c')
-rw-r--r--protocols/jabber/jabber_util.c33
1 files changed, 18 insertions, 15 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 );