Changeset 98de2cc


Ignore:
Timestamp:
2008-06-21T23:51:18Z (16 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
424e663
Parents:
3e6764a
Message:

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.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/jabber_util.c

    r3e6764a r98de2cc  
    290290        len = strlen( orig );
    291291        new = g_new( char, len + 1 );
    292         for( i = 0; i < len; i ++ )
     292       
     293        /* So it turns out the /resource part is case sensitive. Yeah, and
     294           it's Unicode but feck Unicode. :-P So stop once we see a slash. */
     295        for( i = 0; i < len && orig[i] != '/' ; i ++ )
    293296                new[i] = tolower( orig[i] );
     297        for( ; orig[i]; i ++ )
     298                new[i] = orig[i];
    294299       
    295300        new[i] = 0;
     
    334339                {
    335340                        /* Check for dupes. */
    336                         if( g_strcasecmp( bi->resource, s + 1 ) == 0 )
     341                        if( strcmp( bi->resource, s + 1 ) == 0 )
    337342                        {
    338343                                *s = '/';
     
    387392        if( ( s = strchr( jid, '/' ) ) )
    388393        {
    389                 int none_found = 0;
     394                int bare_exists = 0;
    390395               
    391396                *s = 0;
     
    410415                        /* See if there's an exact match. */
    411416                        for( ; bud; bud = bud->next )
    412                                 if( g_strcasecmp( bud->resource, s + 1 ) == 0 )
     417                                if( strcmp( bud->resource, s + 1 ) == 0 )
    413418                                        break;
    414419                }
    415420                else
    416421                {
    417                         /* This hack is there to make sure that O_CREAT will
    418                            work if there's already another resouce present
    419                            for this JID, even if it's an unknown buddy. This
    420                            is done to handle conferences properly. */
    421                         none_found = 1;
    422                         /* TODO(wilmer): Find out what I was thinking when I
    423                            wrote this??? And then fix it. This makes me sad... */
    424                 }
    425                
    426                 if( bud == NULL && ( flags & GET_BUDDY_CREAT ) && ( imcb_find_buddy( ic, jid ) || !none_found ) )
     422                        /* This variable tells the if down here that the bare
     423                           JID already exists and we should feel free to add
     424                           more resources, if the caller asked for that. */
     425                        bare_exists = 1;
     426                }
     427               
     428                if( bud == NULL && ( flags & GET_BUDDY_CREAT ) &&
     429                    ( !bare_exists || imcb_find_buddy( ic, jid ) ) )
    427430                {
    428431                        *s = '/';
     
    449452                        /* We want an exact match, so in thise case there shouldn't be a /resource. */
    450453                        return NULL;
    451                 else if( ( bud->resource == NULL || bud->next == NULL ) )
     454                else if( bud->resource == NULL || bud->next == NULL )
    452455                        /* No need for selection if there's only one option. */
    453456                        return bud;
     
    527530                if( bud->next == NULL &&
    528531                    ( ( s == NULL && bud->resource == NULL ) ||
    529                       ( bud->resource && s && g_strcasecmp( bud->resource, s + 1 ) == 0 ) ) )
     532                      ( bud->resource && s && strcmp( bud->resource, s + 1 ) == 0 ) ) )
    530533                {
    531534                        g_hash_table_remove( jd->buddies, bud->bare_jid );
     
    550553                {
    551554                        for( bi = bud, prev = NULL; bi; bi = (prev=bi)->next )
    552                                 if( g_strcasecmp( bi->resource, s + 1 ) == 0 )
     555                                if( strcmp( bi->resource, s + 1 ) == 0 )
    553556                                        break;
    554557                       
  • tests/check_jabber_util.c

    r3e6764a r98de2cc  
    1111static void check_buddy_add(int l)
    1212{
    13         struct jabber_buddy *budw1, *budw2, *budw3, *budw4, *budn;
    14         int i;
     13        struct jabber_buddy *budw1, *budw2, *budw3, *budn, *bud;
    1514       
    1615        budw1 = jabber_buddy_add( ic, "wilmer@gaast.net/BitlBee" );
    1716        budw1->last_act = time( NULL ) - 100;
    18         budw2 = jabber_buddy_add( ic, "wilmer@gaast.net/Telepathy" );
     17        budw2 = jabber_buddy_add( ic, "WILMER@gaast.net/Telepathy" );
    1918        budw2->priority = 2;
    2019        budw2->last_act = time( NULL );
    21         budw3 = jabber_buddy_add( ic, "wilmer@gaast.net/Druif" );
     20        budw3 = jabber_buddy_add( ic, "wilmer@GAAST.NET/bitlbee" );
    2221        budw3->last_act = time( NULL ) - 200;
    2322        budw3->priority = 4;
    2423        /* TODO(wilmer): Shouldn't this just return budw3? */
    25         fail_if( jabber_buddy_add( ic, "wilmer@gaast.net/druif" ) != NULL );
     24        fail_if( jabber_buddy_add( ic, "wilmer@gaast.net/Telepathy" ) != NULL );
    2625       
    2726        budn = jabber_buddy_add( ic, "nekkid@lamejab.net" );
     
    2928        fail_if( jabber_buddy_add( ic, "nekkid@lamejab.net/Illegal" ) );
    3029       
     30        /* Case sensitivity: Case only matters after the / */
     31        fail_if( jabber_buddy_by_jid( ic, "wilmer@gaast.net/BitlBee", 0 ) ==
     32                 jabber_buddy_by_jid( ic, "wilmer@gaast.net/bitlbee", 0 ) );
     33        fail_if( jabber_buddy_by_jid( ic, "wilmer@gaast.net/telepathy", 0 ) );
     34       
    3135        fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net/BitlBee", 0 ) == budw1 );
    32         fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net/bitlbee", GET_BUDDY_EXACT ) == budw1 );
    33         fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net/BitlBee", GET_BUDDY_CREAT ) == budw1 );
     36        fail_unless( jabber_buddy_by_jid( ic, "WILMER@GAAST.NET/BitlBee", GET_BUDDY_EXACT ) == budw1 );
     37        fail_unless( jabber_buddy_by_jid( ic, "wilmer@GAAST.NET/BitlBee", GET_BUDDY_CREAT ) == budw1 );
    3438
    3539        fail_if( jabber_buddy_by_jid( ic, "wilmer@gaast.net", GET_BUDDY_EXACT ) );
    36         fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", GET_BUDDY_FIRST ) == budw1 );
    37         fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) == budw3 );
     40        fail_unless( jabber_buddy_by_jid( ic, "WILMER@gaast.net", 0 ) == budw3 );
     41
     42        /* Check O_FIRST and see if it's indeed the first item from the list. */
     43        fail_unless( ( bud = jabber_buddy_by_jid( ic, "wilmer@gaast.net", GET_BUDDY_FIRST ) ) == budw1 );
     44        fail_unless( bud->next == budw2 && bud->next->next == budw3 && bud->next->next->next == NULL );
    3845       
     46        /* Change the resource_select setting, now we should get a different resource. */
    3947        set_setstr( &ic->acc->set, "resource_select", "activity" );
    40         fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) == budw2 );
     48        fail_unless( jabber_buddy_by_jid( ic, "wilmer@GAAST.NET", 0 ) == budw2 );
    4149       
     50        /* Some testing of bare JID handling (which is horrible). */
    4251        fail_if( jabber_buddy_by_jid( ic, "nekkid@lamejab.net/Illegal", 0 ) );
    43         fail_if( jabber_buddy_by_jid( ic, "nekkid@lamejab.net/Illegal", GET_BUDDY_CREAT ) );
     52        fail_if( jabber_buddy_by_jid( ic, "NEKKID@LAMEJAB.NET/Illegal", GET_BUDDY_CREAT ) );
    4453        fail_unless( jabber_buddy_by_jid( ic, "nekkid@lamejab.net", 0 ) == budn );
    45         fail_unless( jabber_buddy_by_jid( ic, "nekkid@lamejab.net", GET_BUDDY_EXACT ) == budn );
    46         fail_unless( jabber_buddy_by_jid( ic, "nekkid@lamejab.net", GET_BUDDY_CREAT ) == budn );
     54        fail_unless( jabber_buddy_by_jid( ic, "NEKKID@lamejab.net", GET_BUDDY_EXACT ) == budn );
     55        fail_unless( jabber_buddy_by_jid( ic, "nekkid@LAMEJAB.NET", GET_BUDDY_CREAT ) == budn );
    4756       
    48         jabber_buddy_remove( ic, "wilmer@gaast.net/telepathy" );
     57        /* More case sensitivity testing, and see if remove works properly. */
     58        fail_if( jabber_buddy_remove( ic, "wilmer@gaast.net/telepathy" ) );
     59        fail_if( jabber_buddy_by_jid( ic, "wilmer@GAAST.NET/telepathy", GET_BUDDY_CREAT ) == budw2 );
     60        fail_unless( jabber_buddy_remove( ic, "wilmer@gaast.net/Telepathy" ) );
     61        fail_unless( jabber_buddy_remove( ic, "wilmer@gaast.net/telepathy" ) );
    4962        fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) == budw1 );
    5063       
     
    5265        fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) == budw1 );
    5366       
     67        /* Check if remove_bare() indeed gets rid of all. */
    5468        fail_unless( jabber_buddy_remove_bare( ic, "wilmer@gaast.net" ) );
    5569        fail_if( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) );
Note: See TracChangeset for help on using the changeset viewer.