Changeset 81ee561 for protocols/jabber


Ignore:
Timestamp:
2010-03-20T18:03:18Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
85693e6
Parents:
3330468 (diff), 0baed0d (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:

Merging head. Most changes are not so relevant because they're to IM
modules.

Location:
protocols/jabber
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/io.c

    r3330468 r81ee561  
    380380                jd->flags |= JFLAG_WANT_SESSION;
    381381       
    382         /* This flag is already set if we authenticated via SASL, so now
    383            we can resume the session in the new stream, if we don't have
    384            to bind/initialize the session. */
    385         if( jd->flags & JFLAG_AUTHENTICATED && ( jd->flags & ( JFLAG_WANT_BIND | JFLAG_WANT_SESSION ) ) == 0 )
    386         {
    387                 if( !jabber_get_roster( ic ) )
    388                         return XT_ABORT;
    389         }
    390         else if( jd->flags & JFLAG_AUTHENTICATED )
    391         {
     382        if( jd->flags & JFLAG_AUTHENTICATED )
    392383                return jabber_pkt_bind_sess( ic, NULL, NULL );
    393         }
    394384       
    395385        return XT_HANDLED;
  • protocols/jabber/iq.c

    r3330468 r81ee561  
    307307                    strcmp( s + 1, set_getstr( &ic->acc->set, "resource" ) ) != 0 )
    308308                        imcb_log( ic, "Server changed session resource string to `%s'", s + 1 );
    309                
    310                 jd->flags &= ~JFLAG_WANT_BIND;
    311         }
    312         else if( node && ( c = xt_find_node( node->children, "session" ) ) )
    313         {
    314                 jd->flags &= ~JFLAG_WANT_SESSION;
    315309        }
    316310       
     
    319313                reply = xt_new_node( "bind", NULL, xt_new_node( "resource", set_getstr( &ic->acc->set, "resource" ), NULL ) );
    320314                xt_add_attr( reply, "xmlns", XMLNS_BIND );
     315                jd->flags &= ~JFLAG_WANT_BIND;
    321316        }
    322317        else if( jd->flags & JFLAG_WANT_SESSION )
     
    324319                reply = xt_new_node( "session", NULL, NULL );
    325320                xt_add_attr( reply, "xmlns", XMLNS_SESSION );
     321                jd->flags &= ~JFLAG_WANT_SESSION;
    326322        }
    327323       
  • protocols/jabber/jabber.c

    r3330468 r81ee561  
    5858        char str[16];
    5959       
     60        s = set_add( &acc->set, "activity_timeout", "600", set_eval_int, acc );
     61       
    6062        g_snprintf( str, sizeof( str ), "%d", jabber_port_list[0] );
    6163        s = set_add( &acc->set, "port", str, set_eval_int, acc );
     
    6769        s->flags |= ACC_SET_OFFLINE_ONLY;
    6870       
    69         s = set_add( &acc->set, "resource_select", "priority", NULL, acc );
     71        s = set_add( &acc->set, "resource_select", "activity", NULL, acc );
    7072       
    7173        s = set_add( &acc->set, "server", NULL, set_eval_account, acc );
     
    307309                bud = jabber_buddy_by_ext_jid( ic, who, 0 );
    308310        else
    309                 bud = jabber_buddy_by_jid( ic, who, 0 );
     311                bud = jabber_buddy_by_jid( ic, who, GET_BUDDY_BARE_OK );
    310312       
    311313        node = xt_new_node( "body", message, NULL );
     
    352354static void jabber_get_info( struct im_connection *ic, char *who )
    353355{
    354         struct jabber_data *jd = ic->proto_data;
    355356        struct jabber_buddy *bud;
    356357       
    357         if( strchr( who, '/' ) )
    358                 bud = jabber_buddy_by_jid( ic, who, 0 );
    359         else
    360         {
    361                 char *s = jabber_normalize( who );
    362                 bud = g_hash_table_lookup( jd->buddies, s );
    363                 g_free( s );
    364         }
     358        bud = jabber_buddy_by_jid( ic, who, GET_BUDDY_FIRST );
    365359       
    366360        while( bud )
  • protocols/jabber/jabber.h

    r3330468 r81ee561  
    108108};
    109109
     110/* Somewhat messy data structure: We have a hash table with the bare JID as
     111   the key and the head of a struct jabber_buddy list as the value. The head
     112   is always a bare JID. If the JID has other resources (often the case,
     113   except for some transports that don't support multiple resources), those
     114   follow. In that case, the bare JID at the beginning doesn't actually
     115   refer to a real session and should only be used for operations that
     116   support incomplete JIDs. */
    110117struct jabber_buddy
    111118{
     
    121128        char *away_message;
    122129       
    123         time_t last_act;
     130        time_t last_msg;
    124131        jabber_buddy_flags_t flags;
    125132       
     
    209216        GET_BUDDY_EXACT = 2,    /* Get an exact match (only makes sense with bare JIDs). */
    210217        GET_BUDDY_FIRST = 4,    /* No selection, simply get the first resource for this JID. */
     218        GET_BUDDY_BARE = 8,     /* Get the bare version of the JID (possibly inexistent). */
     219        GET_BUDDY_BARE_OK = 16, /* Allow returning a bare JID if that seems better. */
    211220} get_buddy_flags_t;
    212221
  • protocols/jabber/jabber_util.c

    r3330468 r81ee561  
    44*  Jabber module - Misc. stuff                                              *
    55*                                                                           *
    6 *  Copyright 2006 Wilmer van der Gaast <wilmer@gaast.net>                   *
     6*  Copyright 2006-2010 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               
    347352                /* If this is a transport buddy or whatever, it can't have more
    348353                   than one instance, so this is always wrong: */
     
    379384        else
    380385        {
    381                 /* Keep in mind that full_jid currently isn't really
    382                    a full JID... */
    383                 new->bare_jid = g_strdup( full_jid );
     386                new->full_jid = new->bare_jid = g_strdup( full_jid );
    384387                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                }
    385395        }
    386396       
     
    408418{
    409419        struct jabber_data *jd = ic->proto_data;
    410         struct jabber_buddy *bud;
     420        struct jabber_buddy *bud, *head;
    411421        char *s, *jid;
    412422       
     
    420430                if( ( bud = g_hash_table_lookup( jd->buddies, jid ) ) )
    421431                {
     432                        bare_exists = 1;
     433                       
     434                        if( bud->next )
     435                                bud = bud->next;
     436                       
    422437                        /* Just return the first one for this bare JID. */
    423438                        if( flags & GET_BUDDY_FIRST )
     
    441456                                        break;
    442457                }
    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                 }
    450458               
    451459                if( bud == NULL && ( flags & GET_BUDDY_CREAT ) &&
    452                     ( !bare_exists || imcb_find_buddy( ic, jid ) ) )
     460                    ( bare_exists || imcb_find_buddy( ic, jid ) ) )
    453461                {
    454462                        *s = '/';
     
    464472                char *set;
    465473               
    466                 bud = g_hash_table_lookup( jd->buddies, jid );
     474                head = g_hash_table_lookup( jd->buddies, jid );
     475                bud = ( head && head->next ) ? head->next : head;
    467476               
    468477                g_free( jid );
     
    481490                        /* Looks like the caller doesn't care about details. */
    482491                        return bud;
     492                else if( flags & GET_BUDDY_BARE )
     493                        return head;
    483494               
    484495                best_prio = best_time = bud;
     
    487498                        if( bud->priority > best_prio->priority )
    488499                                best_prio = bud;
    489                         if( bud->last_act > best_time->last_act )
     500                        if( bud->last_msg > best_time->last_msg )
    490501                                best_time = bud;
    491502                }
     
    493504                if( ( set = set_getstr( &ic->acc->set, "resource_select" ) ) == NULL )
    494505                        return NULL;
    495                 else if( strcmp( set, "activity" ) == 0 )
     506                else if( strcmp( set, "priority" ) == 0 )
     507                        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
    496516                        return best_time;
    497                 else /* if( strcmp( set, "priority" ) == 0 ) */
    498                         return best_prio;
    499517        }
    500518}
     
    538556{
    539557        struct jabber_data *jd = ic->proto_data;
    540         struct jabber_buddy *bud, *prev, *bi;
     558        struct jabber_buddy *bud, *prev = NULL, *bi;
    541559        char *s, *full_jid;
    542560       
     
    548566        if( ( bud = g_hash_table_lookup( jd->buddies, full_jid ) ) )
    549567        {
     568                if( bud->next )
     569                        bud = (prev=bud)->next;
     570               
    550571                /* If there's only one item in the list (and if the resource
    551572                   matches), removing it is simple. (And the hash reference
     
    555576                      ( bud->resource && s && strcmp( bud->resource, s + 1 ) == 0 ) ) )
    556577                {
    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;
     578                        return jabber_buddy_remove_bare( ic, full_jid );
    567579                }
    568580                else if( s == NULL || bud->resource == NULL )
     
    575587                else
    576588                {
    577                         for( bi = bud, prev = NULL; bi; bi = (prev=bi)->next )
     589                        for( bi = bud; bi; bi = (prev=bi)->next )
    578590                                if( strcmp( bi->resource, s + 1 ) == 0 )
    579591                                        break;
     
    586598                                        prev->next = bi->next;
    587599                                else
    588                                         /* The hash table should point at the second
    589                                            item, because we're removing the first. */
     600                                        /* Don't think this should ever happen anymore. */
    590601                                        g_hash_table_replace( jd->buddies, bi->bare_jid, bi->next );
    591602                               
  • protocols/jabber/message.c

    r3330468 r81ee561  
    7171                        if( bud )
    7272                        {
    73                                 bud->last_act = time( NULL );
     73                                bud->last_msg = time( NULL );
    7474                                from = bud->ext_jid ? : bud->bare_jid;
    7575                        }
  • protocols/jabber/presence.c

    r3330468 r81ee561  
    6868                {
    6969                        bud->away_state = NULL;
    70                         /* Let's only set last_act if there's *no* away state,
    71                            since it could be some auto-away thingy. */
    72                         bud->last_act = time( NULL );
    7370                }
    7471               
Note: See TracChangeset for help on using the changeset viewer.