Ignore:
Timestamp:
2006-10-08T16:11:16Z (15 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
861c199
Parents:
36e9f62
Message:

Implemented a better node cache using a GLib hash, and preparing to add
event handlers that can be set when sending a packet to handle the reply
to this specific packet. This should allow me to make the iq handler a
lot cleaner.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/jabber.c

    r36e9f62 r038d17f  
    7979        jd->server ++;
    8080       
    81         jd->node_cache = xt_new_node( "cache", NULL, NULL );
     81        jd->node_cache = g_hash_table_new_full( g_str_hash, g_str_equal, NULL, jabber_cache_entry_free );
    8282       
    8383        /* Figure out the hostname to connect to. */
     
    125125                g_free( jd->txq );
    126126       
    127         xt_free_node( jd->node_cache );
     127        g_hash_table_destroy( jd->node_cache );
     128       
    128129        xt_free( jd->xt );
    129130       
     
    164165       
    165166        return l;
     167}
     168
     169static void jabber_get_info( struct gaim_connection *gc, char *who )
     170{
     171        struct xt_node *node;
     172       
     173        node = xt_new_node( "query", NULL, NULL );
     174        xt_add_attr( node, "xmlns", "http://jabber.org/protocol/disco#info" );
     175        node = jabber_make_packet( "iq", "get", who, node );
     176        jabber_cache_add( gc, node );
     177       
     178        jabber_write_packet( gc, node );
    166179}
    167180
     
    194207static void jabber_keepalive( struct gaim_connection *gc )
    195208{
    196         struct jabber_data *jd = gc->proto_data;
    197         struct xt_node *c, *tmp;
    198        
    199209        /* Just any whitespace character is enough as a keepalive for XMPP sessions. */
    200210        jabber_write( gc, "\n", 1 );
    201211       
    202         /* Let's abuse this keepalive for garbage collection of the node cache too.
    203            It runs every minute, so let's mark every node with a special flag the
    204            first time we see it, and clean it up the second time (clean up all
    205            packets with the flag set).
    206            
    207            node->flags is normally only used by xmltree itself for parsing/handling,
    208            so it should be safe to use the variable for gc. */
    209        
    210         /* This horrible loop is explained in xmltree.c. Makes me wonder if maybe I
    211            didn't choose the perfect data structure... */
    212         for( c = jd->node_cache->children; c; c =  c->next )
    213                 if( !( c->flags & XT_SEEN ) )
    214                         break;
    215        
    216         /* Now c points at the first unflagged node (or at NULL). Clean up
    217            everything until that point. */
    218         while( jd->node_cache->children != c )
    219         {
    220                 /*
    221                 printf( "Cleaning up:\n" );
    222                 xt_print( jd->node_cache->children );
    223                 */
    224                
    225                 tmp = jd->node_cache->children->next;
    226                 xt_free_node( jd->node_cache->children );
    227                 jd->node_cache->children = tmp;
    228         }
    229        
    230         /* Now flag the ones that were still unflagged. */
    231         for( c = jd->node_cache->children; c; c = c->next )
    232         {
    233                 /*
    234                 printf( "Flagged:\n" );
    235                 xt_print( c );
    236                 */
    237                
    238                 c->flags |= XT_SEEN;
    239         }
     212        /* This runs the garbage collection every minute, which means every packet
     213           is in the cache for about a minute (which should be enough AFAIK). */
     214        jabber_cache_clean( gc );
    240215}
    241216
     
    253228        ret->set_away = jabber_set_away;
    254229//      ret->set_info = jabber_set_info;
    255 //      ret->get_info = jabber_get_info;
     230        ret->get_info = jabber_get_info;
    256231        ret->add_buddy = jabber_add_buddy;
    257232        ret->remove_buddy = jabber_remove_buddy;
Note: See TracChangeset for help on using the changeset viewer.