Changeset 76c85b4c


Ignore:
Timestamp:
2009-11-19T13:11:38Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
20e830b
Parents:
36cf9fd
Message:

resource_select now defaults to activity instead of priority. Also, adding
a activity_timeout setting. Now, messages to someone who hasn't spoken for
a while will be sent to his/her bare JID, usually resulting in a broadcast.
This should fix issues with messages sometimes arriving on someone's
Crackberry/Android/etc instead of some place s/he's paying attention to.
Last, the activity timer is only reset on incoming messages.

Location:
protocols/jabber
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/jabber.c

    r36cf9fd r76c85b4c  
    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 );
     
    305307                bud = jabber_buddy_by_ext_jid( ic, who, 0 );
    306308        else
    307                 bud = jabber_buddy_by_jid( ic, who, 0 );
     309                bud = jabber_buddy_by_jid( ic, who, GET_BUDDY_BARE_OK );
    308310       
    309311        node = xt_new_node( "body", message, NULL );
     
    350352static void jabber_get_info( struct im_connection *ic, char *who )
    351353{
    352         struct jabber_data *jd = ic->proto_data;
    353354        struct jabber_buddy *bud;
    354355       
    355         if( strchr( who, '/' ) )
    356                 bud = jabber_buddy_by_jid( ic, who, 0 );
    357         else
    358         {
    359                 char *s = jabber_normalize( who );
    360                 bud = g_hash_table_lookup( jd->buddies, s );
    361                 g_free( s );
    362         }
     356        bud = jabber_buddy_by_jid( ic, who, GET_BUDDY_FIRST );
    363357       
    364358        while( bud )
  • protocols/jabber/jabber.h

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

    r36cf9fd r76c85b4c  
    340340        if( ( bud = g_hash_table_lookup( jd->buddies, full_jid ) ) )
    341341        {
     342                /* The first entry is always a bare JID. If there are more, we
     343                   should ignore the first one here. */
     344                if( bud->next )
     345                        bud = bud->next;
     346               
    342347                /* If this is a transport buddy or whatever, it can't have more
    343348                   than one instance, so this is always wrong: */
     
    374379        else
    375380        {
    376                 /* Keep in mind that full_jid currently isn't really
    377                    a full JID... */
    378                 new->bare_jid = g_strdup( full_jid );
     381                new->full_jid = new->bare_jid = g_strdup( full_jid );
    379382                g_hash_table_insert( jd->buddies, new->bare_jid, new );
     383               
     384                if( s )
     385                {
     386                        new->next = g_new0( struct jabber_buddy, 1 );
     387                        new->next->bare_jid = new->bare_jid;
     388                        new = new->next;
     389                }
    380390        }
    381391       
     
    403413{
    404414        struct jabber_data *jd = ic->proto_data;
    405         struct jabber_buddy *bud;
     415        struct jabber_buddy *bud, *head;
    406416        char *s, *jid;
    407417       
     
    410420        if( ( s = strchr( jid, '/' ) ) )
    411421        {
    412                 int bare_exists = 0;
    413                
    414422                *s = 0;
    415423                if( ( bud = g_hash_table_lookup( jd->buddies, jid ) ) )
    416424                {
     425                        if( bud->next )
     426                                bud = bud->next;
     427                       
    417428                        /* Just return the first one for this bare JID. */
    418429                        if( flags & GET_BUDDY_FIRST )
     
    436447                                        break;
    437448                }
    438                 else
    439                 {
    440                         /* This variable tells the if down here that the bare
    441                            JID already exists and we should feel free to add
    442                            more resources, if the caller asked for that. */
    443                         bare_exists = 1;
    444                 }
    445                
    446                 if( bud == NULL && ( flags & GET_BUDDY_CREAT ) &&
    447                     ( !bare_exists || imcb_find_buddy( ic, jid ) ) )
     449               
     450                if( bud == NULL && ( flags & GET_BUDDY_CREAT ) && imcb_find_buddy( ic, jid ) )
    448451                {
    449452                        *s = '/';
     
    459462                char *set;
    460463               
    461                 bud = g_hash_table_lookup( jd->buddies, jid );
     464                head = g_hash_table_lookup( jd->buddies, jid );
     465                bud = head->next ? head->next : head;
    462466               
    463467                g_free( jid );
     
    476480                        /* Looks like the caller doesn't care about details. */
    477481                        return bud;
     482                else if( flags & GET_BUDDY_BARE )
     483                        return head;
    478484               
    479485                best_prio = best_time = bud;
     
    482488                        if( bud->priority > best_prio->priority )
    483489                                best_prio = bud;
    484                         if( bud->last_act > best_time->last_act )
     490                        if( bud->last_msg > best_time->last_msg )
    485491                                best_time = bud;
    486492                }
     
    488494                if( ( set = set_getstr( &ic->acc->set, "resource_select" ) ) == NULL )
    489495                        return NULL;
    490                 else if( strcmp( set, "activity" ) == 0 )
     496                else if( strcmp( set, "priority" ) == 0 )
     497                        return best_prio;
     498                else if( flags & GET_BUDDY_BARE_OK ) /* && strcmp( set, "activity" ) == 0 */
     499                {
     500                        if( best_time->last_msg + set_getint( &ic->acc->set, "activity_timeout" ) >= time( NULL ) )
     501                                return best_time;
     502                        else
     503                                return head;
     504                }
     505                else
    491506                        return best_time;
    492                 else /* if( strcmp( set, "priority" ) == 0 ) */
    493                         return best_prio;
    494507        }
    495508}
     
    533546{
    534547        struct jabber_data *jd = ic->proto_data;
    535         struct jabber_buddy *bud, *prev, *bi;
     548        struct jabber_buddy *head, *bud, *prev, *bi;
    536549        char *s, *full_jid;
    537550       
     
    541554                *s = 0;
    542555       
    543         if( ( bud = g_hash_table_lookup( jd->buddies, full_jid ) ) )
    544         {
     556        if( ( head = g_hash_table_lookup( jd->buddies, full_jid ) ) )
     557        {
     558                bud = head->next ? head->next : head;
     559               
    545560                /* If there's only one item in the list (and if the resource
    546561                   matches), removing it is simple. (And the hash reference
     
    550565                      ( bud->resource && s && strcmp( bud->resource, s + 1 ) == 0 ) ) )
    551566                {
    552                         g_hash_table_remove( jd->buddies, bud->bare_jid );
    553                         g_free( bud->bare_jid );
    554                         g_free( bud->ext_jid );
    555                         g_free( bud->full_jid );
    556                         g_free( bud->away_message );
    557                         g_free( bud );
    558                        
    559                         g_free( full_jid );
    560                        
    561                         return 1;
     567                        return jabber_buddy_remove_bare( ic, full_jid );
    562568                }
    563569                else if( s == NULL || bud->resource == NULL )
  • protocols/jabber/message.c

    r36cf9fd r76c85b4c  
    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

    r36cf9fd r76c85b4c  
    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.