Ignore:
Timestamp:
2006-10-08T16:11:16Z (18 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_util.c

    r36e9f62 r038d17f  
    8282   them when you receive the response. Use this BEFORE sending the packet so
    8383   it'll get an id= tag, and do NOT free() the packet after writing it! */
    84 void jabber_cache_packet( struct gaim_connection *gc, struct xt_node *node )
     84void jabber_cache_add( struct gaim_connection *gc, struct xt_node *node )
    8585{
    8686        struct jabber_data *jd = gc->proto_data;
    8787        char *id = g_strdup_printf( "BeeX%04x", next_id++ );
    88        
    89         /* FIXME: Maybe start using g_error() here if nodes still have a parent, for example? */
     88        struct jabber_cache_entry *entry = g_new0( struct jabber_cache_entry, 1 );
    9089       
    9190        xt_add_attr( node, "id", id );
    92         xt_add_child( jd->node_cache, node );
    9391        g_free( id );
    94 }
    95 
    96 /* Emptying this cache is a BIG TODO! */
    97 struct xt_node *jabber_packet_from_cache( struct gaim_connection *gc, char *id )
     92       
     93        entry->node = node;
     94        g_hash_table_insert( jd->node_cache, xt_find_attr( node, "id" ), entry );
     95}
     96
     97struct xt_node *jabber_cache_get( struct gaim_connection *gc, char *id )
    9898{
    9999        struct jabber_data *jd = gc->proto_data;
    100         struct xt_node *node;
    101         char *s;
    102        
    103         for( node = jd->node_cache->children; node; node = node->next )
    104                 if( ( s = xt_find_attr( node, "id" ) ) && strcmp( id, s ) == 0 )
    105                         break;
    106        
    107         return node;
     100        struct jabber_cache_entry *entry = g_hash_table_lookup( jd->node_cache, id );
     101       
     102        return entry ? entry->node : NULL;
     103}
     104
     105void jabber_cache_entry_free( gpointer data )
     106{
     107        struct jabber_cache_entry *entry = data;
     108       
     109        xt_free_node( entry->node );
     110        g_free( entry );
     111}
     112
     113gboolean jabber_cache_clean_entry( gpointer key, gpointer entry, gpointer nullpointer );
     114
     115void jabber_cache_clean( struct gaim_connection *gc )
     116{
     117        struct jabber_data *jd = gc->proto_data;
     118       
     119        g_hash_table_foreach_remove( jd->node_cache, jabber_cache_clean_entry, NULL );
     120}
     121
     122gboolean jabber_cache_clean_entry( gpointer key, gpointer entry_, gpointer nullpointer )
     123{
     124        struct jabber_cache_entry *entry = entry_;
     125        struct xt_node *node = entry->node;
     126       
     127        if( node->flags & XT_SEEN )
     128                return TRUE;
     129        else
     130        {
     131                node->flags |= XT_SEEN;
     132                return FALSE;
     133        }
    108134}
    109135
Note: See TracChangeset for help on using the changeset viewer.