Changeset 4cff28f for protocols


Ignore:
Timestamp:
2015-01-16T19:50:24Z (10 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
fed4f76
Parents:
840394e
Message:

Add jabber_normalize_ext() to fix case sensitivity issues with ext jids

Also refactor jabber_normalize() to be UTF8 aware.

See trac ticket 1106 for more details

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/jabber_util.c

    r840394e r4cff28f  
    330330}
    331331
    332 /* Returns a new string. Don't leak it! */
     332/* The /resource part is case sensitive. This stops once we see a slash.
     333   Returns a new string. Don't leak it! */
    333334char *jabber_normalize( const char *orig )
    334335{
    335         int len, i;
    336         char *new;
    337        
    338         len = strlen( orig );
    339         new = g_new( char, len + 1 );
    340        
    341         /* So it turns out the /resource part is case sensitive. Yeah, and
    342            it's Unicode but feck Unicode. :-P So stop once we see a slash. */
    343         for( i = 0; i < len && orig[i] != '/' ; i ++ )
    344                 new[i] = g_ascii_tolower( orig[i] );
    345         for( ; orig[i]; i ++ )
    346                 new[i] = orig[i];
    347        
    348         new[i] = 0;
     336        char *lower, *new, *s;
     337
     338        if ( ! ( s = strchr( orig, '/' ) ) )
     339                return g_utf8_strdown( orig, -1 );
     340
     341        lower = g_utf8_strdown( orig, (s - orig) );  /* stop in s */
     342        new = g_strconcat( lower, s, NULL );
     343        g_free( lower );
     344        return new;
     345}
     346
     347/* Similar to jabber_normalize, but works with addresses in the form
     348 * resource=chatroom@example.com */
     349char *jabber_normalize_ext( const char *orig )
     350{
     351        char *lower, *new, *s;
     352
     353        if ( ! ( s = strchr( orig, '=' ) ) )
     354                return g_utf8_strdown( orig, -1 );
     355
     356        lower = g_utf8_strdown( s, -1 ); /* start in s */
     357
     358        *s = 0;
     359        new = g_strconcat( orig, lower, NULL );
     360        *s = '=';
     361
     362        g_free( lower );
    349363        return new;
    350364}
     
    556570        char *s, *jid;
    557571       
    558         jid = jabber_normalize( jid_ );
     572        jid = jabber_normalize_ext( jid_ );
    559573       
    560574        if( ( s = strchr( jid, '=' ) ) == NULL )
Note: See TracChangeset for help on using the changeset viewer.