Changeset 6a1128d


Ignore:
Timestamp:
2006-10-09T18:19:05Z (17 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
a21a8ac
Parents:
861c199
Message:

The module now keeps track of all resources available for a buddy. This
means the buddy won't show up offline when one resource goes down (while
there are still others available). It also remembers away state
information for every separate resource. Later this system will be used
to keep track of client capability information (Typing notices, yay...)
and who knows what else.

Location:
protocols/jabber
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/jabber.c

    r861c199 r6a1128d  
    8080       
    8181        jd->node_cache = g_hash_table_new_full( g_str_hash, g_str_equal, NULL, jabber_cache_entry_free );
     82        jd->buddies = g_hash_table_new( g_str_hash, g_str_equal );
    8283       
    8384        /* Figure out the hostname to connect to. */
     
    169170static void jabber_get_info( struct gaim_connection *gc, char *who )
    170171{
     172        struct jabber_buddy *bud;
    171173        struct xt_node *node;
    172174       
     175        bud = jabber_buddy_by_jid( gc, who );
     176        while( bud )
     177        {
     178                serv_got_crap( gc, "Buddy %s/%s (%d) information:\nAway state: %s\nAway message: %s",
     179                                   bud->handle, bud->resource, bud->priority,
     180                                   bud->away_state ? bud->away_state->full_name : "(none)",
     181                                   bud->away_message ? : "(none)" );
     182                bud = bud->next;
     183        }
     184       
     185//      node = xt_new_node( "vCard", NULL, NULL );
     186//      xt_add_attr( node, "xmlns", "vcard-temp" );
    173187        node = xt_new_node( "query", NULL, NULL );
    174         xt_add_attr( node, "xmlns", "http://jabber.org/protocol/disco#info" );
     188        xt_add_attr( node, "xmlns", "jabber:iq:version" );
    175189        node = jabber_make_packet( "iq", "get", who, node );
    176190        // jabber_cache_add( gc, node,  );
  • protocols/jabber/jabber.h

    r861c199 r6a1128d  
    6161       
    6262        GHashTable *node_cache;
     63        GHashTable *buddies;
    6364};
    6465
     
    7576        struct xt_node *node;
    7677        jabber_cache_event func;
     78};
     79
     80struct jabber_buddy
     81{
     82        char *handle;
     83        char *resource;
     84       
     85        int priority;
     86        struct jabber_away_state *away_state;
     87        char *away_message;
     88       
     89        time_t last_act;
     90        int flags;
     91       
     92        struct jabber_buddy *next;
    7793};
    7894
     
    104120const struct jabber_away_state *jabber_away_state_by_name( char *name );
    105121void jabber_buddy_ask( struct gaim_connection *gc, char *handle );
     122struct jabber_buddy *jabber_buddy_add( struct gaim_connection *gc, char *full_jid );
     123struct jabber_buddy *jabber_buddy_by_jid( struct gaim_connection *gc, char *jid );
     124int jabber_buddy_remove( struct gaim_connection *gc, char *full_jid );
    106125
    107126extern const struct jabber_away_state jabber_away_state_list[];
  • protocols/jabber/jabber_util.c

    r861c199 r6a1128d  
    202202        g_free( buf );
    203203}
     204
     205/* Adds a buddy/resource to our list. Returns NULL if full_jid is not really a
     206   FULL jid or if we already have this buddy/resource. */
     207struct jabber_buddy *jabber_buddy_add( struct gaim_connection *gc, char *full_jid )
     208{
     209        struct jabber_data *jd = gc->proto_data;
     210        struct jabber_buddy *bud, *new, *bi;
     211        char *s;
     212       
     213        if( !( s = strchr( full_jid, '/' ) ) )
     214                return NULL;
     215       
     216        new = g_new0( struct jabber_buddy, 1 );
     217       
     218        *s = 0;
     219        if( ( bud = g_hash_table_lookup( jd->buddies, full_jid ) ) )
     220        {
     221                new->handle = bud->handle;
     222               
     223                /* We already have another resource for this buddy, add the
     224                   new one to the list. */
     225                for( bi = bud; bi; bi = bi->next )
     226                {
     227                        /* Check for dupes. Resource seem to be case sensitive. */
     228                        if( strcmp( bi->resource, s + 1 ) == 0 )
     229                        {
     230                                *s = '/';
     231                                g_free( new );
     232                                return NULL;
     233                        }
     234                        /* Append the new item to the list. */
     235                        else if( bi->next == NULL )
     236                        {
     237                                bi->next = new;
     238                                break;
     239                        }
     240                }
     241        }
     242        else
     243        {
     244                new->handle = g_strdup( full_jid );
     245                g_hash_table_insert( jd->buddies, new->handle, new );
     246        }
     247       
     248        *s = '/';
     249        new->resource = g_strdup( s + 1 );
     250       
     251        return new;
     252}
     253
     254struct jabber_buddy *jabber_buddy_by_jid( struct gaim_connection *gc, char *jid )
     255{
     256        struct jabber_data *jd = gc->proto_data;
     257        struct jabber_buddy *bud;
     258        char *s;
     259       
     260        if( ( s = strchr( jid, '/' ) ) )
     261        {
     262                *s = 0;
     263                if( ( bud = g_hash_table_lookup( jd->buddies, jid ) ) )
     264                        for( ; bud; bud = bud->next )
     265                                if( strcmp( bud->resource, s + 1 ) == 0 )
     266                                        break;
     267        }
     268        else
     269        {
     270                /* TODO: Add selection. */
     271                return g_hash_table_lookup( jd->buddies, jid );
     272        }
     273       
     274        *s = '/';
     275        return bud;
     276}
     277
     278int jabber_buddy_remove( struct gaim_connection *gc, char *full_jid )
     279{
     280        struct jabber_data *jd = gc->proto_data;
     281        struct jabber_buddy *bud, *prev, *bi;
     282        char *s;
     283       
     284        if( !( s = strchr( full_jid, '/' ) ) )
     285                return 0;
     286       
     287        *s = 0;
     288        if( ( bud = g_hash_table_lookup( jd->buddies, full_jid ) ) )
     289        {
     290                /* If there's only one item in the list (and if the resource
     291                   matches), removing it is simple. (And the hash reference
     292                   should be removed too!) */
     293                if( bud->next == NULL && strcmp( bud->resource, s + 1 ) == 0 )
     294                {
     295                        g_hash_table_remove( jd->buddies, bud->handle );
     296                        g_free( bud->handle );
     297                        g_free( bud->resource );
     298                        g_free( bud->away_message );
     299                        g_free( bud );
     300                }
     301                else
     302                {
     303                        for( bi = bud, prev = NULL; bi; bi = (prev=bi)->next )
     304                                if( strcmp( bi->resource, s + 1 ) == 0 )
     305                                        break;
     306                       
     307                        if( bi )
     308                        {
     309                                if( prev )
     310                                        prev->next = bi->next;
     311                                else
     312                                        /* The hash table should point at the second
     313                                           item, because we're removing the first. */
     314                                        g_hash_table_replace( jd->buddies, bi->handle, bi->next );
     315                               
     316                                g_free( bi->resource );
     317                                g_free( bi->away_message );
     318                                g_free( bi );
     319                        }
     320                        else
     321                        {
     322                                *s = '/';
     323                                return 0;
     324                        }
     325                }
     326               
     327                *s = '/';
     328                return 1;
     329        }
     330        else
     331        {
     332                *s = '/';
     333                return 0;
     334        }
     335}
  • protocols/jabber/presence.c

    r861c199 r6a1128d  
    2929        char *from = xt_find_attr( node, "from" );
    3030        char *type = xt_find_attr( node, "type" );      /* NULL should mean the person is online. */
    31         char *s;
     31        struct xt_node *c;
    3232       
    3333        if( !from )
    3434                return XT_HANDLED;
    3535       
    36         s = strchr( from, '/' );
    37         if( s )
    38                 *s = 0;
    39        
    40         /* Will implement better parsing of away states/msgs when we
    41            finally do those API changes. Which will probably be after
    42            merging this module into the main tree. */
    4336        if( type == NULL )
    44                 serv_got_update( gc, from, 1, 0, 0, 0, 0, 0 );
     37        {
     38                struct jabber_buddy *bud;
     39               
     40                if( !( bud = jabber_buddy_by_jid( gc, from ) ) )
     41                {
     42                        bud = jabber_buddy_add( gc, from );
     43                }
     44               
     45                g_free( bud->away_message );
     46                if( ( c = xt_find_node( node->children, "status" ) ) && c->text_len > 0 )
     47                        bud->away_message = g_strdup( c->text );
     48                else
     49                        bud->away_message = NULL;
     50               
     51                if( ( c = xt_find_node( node->children, "show" ) ) && c->text_len > 0 )
     52                        bud->away_state = (void*) jabber_away_state_by_code( c->text );
     53                else
     54                        bud->away_state = NULL;
     55               
     56                if( ( c = xt_find_node( node->children, "priority" ) ) && c->text_len > 0 )
     57                        bud->priority = atoi( c->text );
     58                else
     59                        bud->priority = 0;
     60               
     61                serv_got_update( gc, bud->handle, 1, 0, 0, 0, 0, 0 );
     62        }
    4563        else if( strcmp( type, "unavailable" ) == 0 )
    46                 serv_got_update( gc, from, 0, 0, 0, 0, 0, 0 );
     64        {
     65                char *s;
     66               
     67                jabber_buddy_remove( gc, from );
     68               
     69                if( ( s = strchr( from, '/' ) ) )
     70                        *s = 0;
     71               
     72                /* Only count this as offline if there's no other resource
     73                   available anymore. */
     74                if( jabber_buddy_by_jid( gc, from ) == NULL )
     75                        serv_got_update( gc, from, 0, 0, 0, 0, 0, 0 );
     76               
     77                *s = '/';
     78        }
    4779        else if( strcmp( type, "subscribe" ) == 0 )
     80        {
    4881                jabber_buddy_ask( gc, from );
     82        }
    4983        else if( strcmp( type, "subscribed" ) == 0 )
     84        {
    5085                serv_got_crap( gc, "%s just accepted your authorization request", from );
     86        }
    5187        else if( strcmp( type, "unsubscribe" ) == 0 || strcmp( type, "unsubscribed" ) == 0 )
    5288        {
     
    69105                xt_print( node );
    70106        }
    71        
    72         if( s )
    73                 *s = '/';
    74107       
    75108        return XT_HANDLED;
Note: See TracChangeset for help on using the changeset viewer.