Ignore:
Timestamp:
2008-08-04T14:45:24Z (12 years ago)
Author:
ulim <a.sporto+bee@…>
Branches:
master
Children:
87f525e
Parents:
4ac647d (diff), 718e05f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merged in upstream r410.

Only conflict was the correction of jabber normalization which I had already done.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/jabber_util.c

    r4ac647d r8661caa  
    2323
    2424#include "jabber.h"
     25#include "md5.h"
     26#include "base64.h"
    2527
    2628static unsigned int next_id = 1;
     
    138140        struct jabber_data *jd = ic->proto_data;
    139141        struct jabber_cache_entry *entry = g_new0( struct jabber_cache_entry, 1 );
    140         char *id;
    141        
    142         id = g_strdup_printf( "%s%05x", jd->cached_id_prefix, ( next_id++ ) & 0xfffff );
     142        md5_state_t id_hash;
     143        md5_byte_t id_sum[16];
     144        char *id, *asc_hash;
     145       
     146        next_id ++;
     147       
     148        id_hash = jd->cached_id_prefix;
     149        md5_append( &id_hash, (md5_byte_t*) &next_id, sizeof( next_id ) );
     150        md5_finish( &id_hash, id_sum );
     151        asc_hash = base64_encode( id_sum, 12 );
     152       
     153        id = g_strdup_printf( "%s%s", JABBER_CACHED_ID, asc_hash );
    143154        xt_add_attr( node, "id", id );
    144155        g_free( id );
     156        g_free( asc_hash );
    145157       
    146158        entry->node = node;
     
    188200       
    189201        if( ( s = xt_find_attr( node, "id" ) ) == NULL ||
    190             strncmp( s, jd->cached_id_prefix, strlen( jd->cached_id_prefix ) ) != 0 )
     202            strncmp( s, JABBER_CACHED_ID, strlen( JABBER_CACHED_ID ) ) != 0 )
    191203        {
    192204                /* Silently ignore it, without an ID (or a non-cache
     
    200212        if( entry == NULL )
    201213        {
     214                /*
     215                There's no longer an easy way to see if we generated this
     216                one or someone else, and there's a ten-minute timeout anyway,
     217                so meh.
     218               
    202219                imcb_log( ic, "Warning: Received %s-%s packet with unknown/expired ID %s!",
    203220                              node->name, xt_find_attr( node, "type" ) ? : "(no type)", s );
     221                */
    204222        }
    205223        else if( entry->func )
     
    294312        len = strlen( orig );
    295313        new = g_new( char, len + 1 );
    296         for( i = 0; i < len; i ++ )
    297         {
    298                 /* don't normalize the resource */
    299                 if( orig[i] == '/' )
    300                         break;
     314       
     315        /* So it turns out the /resource part is case sensitive. Yeah, and
     316           it's Unicode but feck Unicode. :-P So stop once we see a slash. */
     317        for( i = 0; i < len && orig[i] != '/' ; i ++ )
    301318                new[i] = tolower( orig[i] );
    302         }
    303         for( ; i < len; i ++ )
     319        for( ; orig[i]; i ++ )
    304320                new[i] = orig[i];
    305321       
     
    345361                {
    346362                        /* Check for dupes. */
    347                         if( g_strcasecmp( bi->resource, s + 1 ) == 0 )
     363                        if( strcmp( bi->resource, s + 1 ) == 0 )
    348364                        {
    349365                                *s = '/';
     
    398414        if( ( s = strchr( jid, '/' ) ) )
    399415        {
    400                 int none_found = 0;
     416                int bare_exists = 0;
    401417               
    402418                *s = 0;
     
    421437                        /* See if there's an exact match. */
    422438                        for( ; bud; bud = bud->next )
    423                                 if( g_strcasecmp( bud->resource, s + 1 ) == 0 )
     439                                if( strcmp( bud->resource, s + 1 ) == 0 )
    424440                                        break;
    425441                }
    426442                else
    427443                {
    428                         /* This hack is there to make sure that O_CREAT will
    429                            work if there's already another resouce present
    430                            for this JID, even if it's an unknown buddy. This
    431                            is done to handle conferences properly. */
    432                         none_found = 1;
    433                         /* TODO(wilmer): Find out what I was thinking when I
    434                            wrote this??? And then fix it. This makes me sad... */
    435                 }
    436                
    437                 if( bud == NULL && ( flags & GET_BUDDY_CREAT ) && ( imcb_find_buddy( ic, jid ) || !none_found ) )
     444                        /* This variable tells the if down here that the bare
     445                           JID already exists and we should feel free to add
     446                           more resources, if the caller asked for that. */
     447                        bare_exists = 1;
     448                }
     449               
     450                if( bud == NULL && ( flags & GET_BUDDY_CREAT ) &&
     451                    ( !bare_exists || imcb_find_buddy( ic, jid ) ) )
    438452                {
    439453                        *s = '/';
     
    460474                        /* We want an exact match, so in thise case there shouldn't be a /resource. */
    461475                        return NULL;
    462                 else if( ( bud->resource == NULL || bud->next == NULL ) )
     476                else if( bud->resource == NULL || bud->next == NULL )
    463477                        /* No need for selection if there's only one option. */
    464478                        return bud;
     
    536550                   matches), removing it is simple. (And the hash reference
    537551                   should be removed too!) */
    538                 if( bud->next == NULL && ( ( s == NULL || bud->resource == NULL ) || g_strcasecmp( bud->resource, s + 1 ) == 0 ) )
     552                if( bud->next == NULL &&
     553                    ( ( s == NULL && bud->resource == NULL ) ||
     554                      ( bud->resource && s && strcmp( bud->resource, s + 1 ) == 0 ) ) )
    539555                {
    540556                        g_hash_table_remove( jd->buddies, bud->bare_jid );
     
    559575                {
    560576                        for( bi = bud, prev = NULL; bi; bi = (prev=bi)->next )
    561                                 if( g_strcasecmp( bi->resource, s + 1 ) == 0 )
     577                                if( strcmp( bi->resource, s + 1 ) == 0 )
    562578                                        break;
    563579                       
Note: See TracChangeset for help on using the changeset viewer.