Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/jabber_util.c

    r842cd8d r840bba8  
    44*  Jabber module - Misc. stuff                                              *
    55*                                                                           *
    6 *  Copyright 2006-2010 Wilmer van der Gaast <wilmer@gaast.net>             
     6*  Copyright 2006 Wilmer van der Gaast <wilmer@gaast.net>                   *
    77*                                                                           *
    88*  This program is free software; you can redistribute it and/or modify     *
     
    345345        if( ( bud = g_hash_table_lookup( jd->buddies, full_jid ) ) )
    346346        {
    347                 /* The first entry is always a bare JID. If there are more, we
    348                    should ignore the first one here. */
    349                 if( bud->next )
    350                         bud = bud->next;
    351                
    352347                /* If this is a transport buddy or whatever, it can't have more
    353348                   than one instance, so this is always wrong: */
     
    384379        else
    385380        {
    386                 new->full_jid = new->bare_jid = g_strdup( full_jid );
     381                /* Keep in mind that full_jid currently isn't really
     382                   a full JID... */
     383                new->bare_jid = g_strdup( full_jid );
    387384                g_hash_table_insert( jd->buddies, new->bare_jid, new );
    388                
    389                 if( s )
    390                 {
    391                         new->next = g_new0( struct jabber_buddy, 1 );
    392                         new->next->bare_jid = new->bare_jid;
    393                         new = new->next;
    394                 }
    395385        }
    396386       
     
    418408{
    419409        struct jabber_data *jd = ic->proto_data;
    420         struct jabber_buddy *bud, *head;
     410        struct jabber_buddy *bud;
    421411        char *s, *jid;
    422412       
     
    430420                if( ( bud = g_hash_table_lookup( jd->buddies, jid ) ) )
    431421                {
    432                         bare_exists = 1;
    433                        
    434                         if( bud->next )
    435                                 bud = bud->next;
    436                        
    437422                        /* Just return the first one for this bare JID. */
    438423                        if( flags & GET_BUDDY_FIRST )
     
    456441                                        break;
    457442                }
     443                else
     444                {
     445                        /* This variable tells the if down here that the bare
     446                           JID already exists and we should feel free to add
     447                           more resources, if the caller asked for that. */
     448                        bare_exists = 1;
     449                }
    458450               
    459451                if( bud == NULL && ( flags & GET_BUDDY_CREAT ) &&
    460                     ( bare_exists || imcb_find_buddy( ic, jid ) ) )
     452                    ( !bare_exists || imcb_find_buddy( ic, jid ) ) )
    461453                {
    462454                        *s = '/';
     
    472464                char *set;
    473465               
    474                 head = g_hash_table_lookup( jd->buddies, jid );
    475                 bud = ( head && head->next ) ? head->next : head;
     466                bud = g_hash_table_lookup( jd->buddies, jid );
    476467               
    477468                g_free( jid );
     
    490481                        /* Looks like the caller doesn't care about details. */
    491482                        return bud;
    492                 else if( flags & GET_BUDDY_BARE )
    493                         return head;
    494483               
    495484                best_prio = best_time = bud;
     
    498487                        if( bud->priority > best_prio->priority )
    499488                                best_prio = bud;
    500                         if( bud->last_msg > best_time->last_msg )
     489                        if( bud->last_act > best_time->last_act )
    501490                                best_time = bud;
    502491                }
     
    504493                if( ( set = set_getstr( &ic->acc->set, "resource_select" ) ) == NULL )
    505494                        return NULL;
    506                 else if( strcmp( set, "priority" ) == 0 )
     495                else if( strcmp( set, "activity" ) == 0 )
     496                        return best_time;
     497                else /* if( strcmp( set, "priority" ) == 0 ) */
    507498                        return best_prio;
    508                 else if( flags & GET_BUDDY_BARE_OK ) /* && strcmp( set, "activity" ) == 0 */
    509                 {
    510                         if( best_time->last_msg + set_getint( &ic->acc->set, "activity_timeout" ) >= time( NULL ) )
    511                                 return best_time;
    512                         else
    513                                 return head;
    514                 }
    515                 else
    516                         return best_time;
    517499        }
    518500}
     
    556538{
    557539        struct jabber_data *jd = ic->proto_data;
    558         struct jabber_buddy *bud, *prev = NULL, *bi;
     540        struct jabber_buddy *bud, *prev, *bi;
    559541        char *s, *full_jid;
    560542       
     
    566548        if( ( bud = g_hash_table_lookup( jd->buddies, full_jid ) ) )
    567549        {
    568                 if( bud->next )
    569                         bud = (prev=bud)->next;
    570                
    571550                /* If there's only one item in the list (and if the resource
    572551                   matches), removing it is simple. (And the hash reference
     
    576555                      ( bud->resource && s && strcmp( bud->resource, s + 1 ) == 0 ) ) )
    577556                {
    578                         return jabber_buddy_remove_bare( ic, full_jid );
     557                        g_hash_table_remove( jd->buddies, bud->bare_jid );
     558                        g_free( bud->bare_jid );
     559                        g_free( bud->ext_jid );
     560                        g_free( bud->full_jid );
     561                        g_free( bud->away_message );
     562                        g_free( bud );
     563                       
     564                        g_free( full_jid );
     565                       
     566                        return 1;
    579567                }
    580568                else if( s == NULL || bud->resource == NULL )
     
    587575                else
    588576                {
    589                         for( bi = bud; bi; bi = (prev=bi)->next )
     577                        for( bi = bud, prev = NULL; bi; bi = (prev=bi)->next )
    590578                                if( strcmp( bi->resource, s + 1 ) == 0 )
    591579                                        break;
     
    598586                                        prev->next = bi->next;
    599587                                else
    600                                         /* Don't think this should ever happen anymore. */
     588                                        /* The hash table should point at the second
     589                                           item, because we're removing the first. */
    601590                                        g_hash_table_replace( jd->buddies, bi->bare_jid, bi->next );
    602591                               
Note: See TracChangeset for help on using the changeset viewer.