Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/jabber_util.c

    r2ff2076 r979cfb4  
    9797}
    9898
    99 struct xt_node *jabber_make_error_packet( struct xt_node *orig, char *err_cond, char *err_type, char *err_code )
     99struct xt_node *jabber_make_error_packet( struct xt_node *orig, char *err_cond, char *err_type )
    100100{
    101101        struct xt_node *node, *c;
     
    109109        c = xt_new_node( "error", NULL, c );
    110110        xt_add_attr( c, "type", err_type );
    111        
    112         /* Add the error code, if present */
    113         if (err_code)
    114                 xt_add_attr( c, "code", err_code );
    115111       
    116112        /* To make the actual error packet, we copy the original packet and
     
    146142        entry->node = node;
    147143        entry->func = func;
     144        entry->saved_at = time( NULL );
    148145        g_hash_table_insert( jd->node_cache, xt_find_attr( node, "id" ), entry );
    149146}
     
    167164{
    168165        struct jabber_data *jd = ic->proto_data;
    169        
    170         g_hash_table_foreach_remove( jd->node_cache, jabber_cache_clean_entry, NULL );
    171 }
    172 
    173 gboolean jabber_cache_clean_entry( gpointer key, gpointer entry_, gpointer nullpointer )
     166        time_t threshold = time( NULL ) - JABBER_CACHE_MAX_AGE;
     167       
     168        g_hash_table_foreach_remove( jd->node_cache, jabber_cache_clean_entry, &threshold );
     169}
     170
     171gboolean jabber_cache_clean_entry( gpointer key, gpointer entry_, gpointer threshold_ )
    174172{
    175173        struct jabber_cache_entry *entry = entry_;
    176         struct xt_node *node = entry->node;
    177        
    178         if( node->flags & XT_SEEN )
    179                 return TRUE;
    180         else
    181         {
    182                 node->flags |= XT_SEEN;
    183                 return FALSE;
    184         }
     174        time_t *threshold = threshold_;
     175       
     176        return entry->saved_at < *threshold;
     177}
     178
     179xt_status jabber_cache_handle_packet( struct im_connection *ic, struct xt_node *node )
     180{
     181        struct jabber_data *jd = ic->proto_data;
     182        struct jabber_cache_entry *entry;
     183        char *s;
     184       
     185        if( ( s = xt_find_attr( node, "id" ) ) == NULL ||
     186            strncmp( s, jd->cached_id_prefix, strlen( jd->cached_id_prefix ) ) != 0 )
     187        {
     188                /* Silently ignore it, without an ID (or a non-cache
     189                   ID) we don't know how to handle the packet and we
     190                   probably don't have to. */
     191                return XT_HANDLED;
     192        }
     193       
     194        entry = g_hash_table_lookup( jd->node_cache, s );
     195       
     196        if( entry == NULL )
     197        {
     198                imcb_log( ic, "Warning: Received %s-%s packet with unknown/expired ID %s!",
     199                              node->name, xt_find_attr( node, "type" ) ? : "(no type)", s );
     200        }
     201        else if( entry->func )
     202        {
     203                return entry->func( ic, node, entry->node );
     204        }
     205       
     206        return XT_HANDLED;
    185207}
    186208
     
    265287        new = g_new( char, len + 1 );
    266288        for( i = 0; i < len; i ++ )
    267         {
    268                 /* don't normalize the resource */
    269                 if( orig[i] == '/' )
    270                         break;
    271289                new[i] = tolower( orig[i] );
    272         }
    273         for( ; i < len; i ++ )
    274                 new[i] = orig[i];
    275290       
    276291        new[i] = 0;
     
    373388                if( ( bud = g_hash_table_lookup( jd->buddies, jid ) ) )
    374389                {
     390                        /* Just return the first one for this bare JID. */
     391                        if( flags & GET_BUDDY_FIRST )
     392                        {
     393                                *s = '/';
     394                                g_free( jid );
     395                                return bud;
     396                        }
     397                       
    375398                        /* Is this one of those no-resource buddies? */
    376399                        if( bud->resource == NULL )
    377400                        {
     401                                *s = '/';
    378402                                g_free( jid );
    379403                                return NULL;
    380404                        }
    381                         else
    382                         {
    383                                 /* See if there's an exact match. */
    384                                 for( ; bud; bud = bud->next )
    385                                         if( g_strcasecmp( bud->resource, s + 1 ) == 0 )
    386                                                 break;
    387                         }
     405                       
     406                        /* See if there's an exact match. */
     407                        for( ; bud; bud = bud->next )
     408                                if( g_strcasecmp( bud->resource, s + 1 ) == 0 )
     409                                        break;
    388410                }
    389411                else
     
    394416                           is done to handle conferences properly. */
    395417                        none_found = 1;
     418                        /* TODO(wilmer): Find out what I was thinking when I
     419                           wrote this??? And then fix it. This makes me sad... */
    396420                }
    397421               
     
    423447                else if( ( bud->resource == NULL || bud->next == NULL ) )
    424448                        /* No need for selection if there's only one option. */
     449                        return bud;
     450                else if( flags & GET_BUDDY_FIRST )
     451                        /* Looks like the caller doesn't care about details. */
    425452                        return bud;
    426453               
     
    595622}
    596623
    597 struct groupchat *jabber_chat_by_name( struct im_connection *ic, const char *name )
    598 {
    599         char *normalized = jabber_normalize( name );
    600         struct groupchat *ret;
    601         struct jabber_chat *jc;
    602        
    603         for( ret = ic->groupchats; ret; ret = ret->next )
    604         {
    605                 jc = ret->data;
    606                 if( strcmp( normalized, jc->name ) == 0 )
    607                         break;
    608         }
    609         g_free( normalized );
    610        
    611         return ret;
    612 }
    613 
    614624time_t jabber_get_timestamp( struct xt_node *xt )
    615625{
     
    663673struct jabber_error *jabber_error_parse( struct xt_node *node, char *xmlns )
    664674{
    665         struct jabber_error *err = g_new0( struct jabber_error, 1 );
     675        struct jabber_error *err;
    666676        struct xt_node *c;
    667677        char *s;
    668678       
     679        if( node == NULL )
     680                return NULL;
     681       
     682        err = g_new0( struct jabber_error, 1 );
    669683        err->type = xt_find_attr( node, "type" );
    670684       
Note: See TracChangeset for help on using the changeset viewer.