- Timestamp:
- 2006-10-08T16:11:16Z (18 years ago)
- Branches:
- master
- Children:
- 861c199
- Parents:
- 36e9f62
- Location:
- protocols/jabber
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/io.c
r36e9f62 r038d17f 360 360 xt_add_attr( reply, "xmlns", "urn:ietf:params:xml:ns:xmpp-bind" ); 361 361 reply = jabber_make_packet( "iq", "set", NULL, reply ); 362 jabber_cache_ packet( gc, reply );362 jabber_cache_add( gc, reply ); 363 363 364 364 if( !jabber_write_packet( gc, reply ) ) … … 373 373 xt_add_attr( reply, "xmlns", "urn:ietf:params:xml:ns:xmpp-session" ); 374 374 reply = jabber_make_packet( "iq", "set", NULL, reply ); 375 jabber_cache_ packet( gc, reply );375 jabber_cache_add( gc, reply ); 376 376 377 377 if( !jabber_write_packet( gc, reply ) ) -
protocols/jabber/iq.c
r36e9f62 r038d17f 41 41 42 42 if( ( s = xt_find_attr( node, "id" ) ) ) 43 orig = jabber_ packet_from_cache( gc, s );43 orig = jabber_cache_get( gc, s ); 44 44 45 45 if( strcmp( type, "result" ) == 0 && xmlns && strcmp( xmlns, "jabber:iq:auth" ) == 0 ) … … 85 85 86 86 reply = jabber_make_packet( "iq", "set", NULL, reply ); 87 jabber_cache_ packet( gc, reply );87 jabber_cache_add( gc, reply ); 88 88 st = jabber_write_packet( gc, reply ); 89 89 -
protocols/jabber/jabber.c
r36e9f62 r038d17f 79 79 jd->server ++; 80 80 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 ); 82 82 83 83 /* Figure out the hostname to connect to. */ … … 125 125 g_free( jd->txq ); 126 126 127 xt_free_node( jd->node_cache ); 127 g_hash_table_destroy( jd->node_cache ); 128 128 129 xt_free( jd->xt ); 129 130 … … 164 165 165 166 return l; 167 } 168 169 static 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 ); 166 179 } 167 180 … … 194 207 static void jabber_keepalive( struct gaim_connection *gc ) 195 208 { 196 struct jabber_data *jd = gc->proto_data;197 struct xt_node *c, *tmp;198 199 209 /* Just any whitespace character is enough as a keepalive for XMPP sessions. */ 200 210 jabber_write( gc, "\n", 1 ); 201 211 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 ); 240 215 } 241 216 … … 253 228 ret->set_away = jabber_set_away; 254 229 // ret->set_info = jabber_set_info; 255 //ret->get_info = jabber_get_info;230 ret->get_info = jabber_get_info; 256 231 ret->add_buddy = jabber_add_buddy; 257 232 ret->remove_buddy = jabber_remove_buddy; -
protocols/jabber/jabber.h
r36e9f62 r038d17f 60 60 char *away_message; 61 61 62 struct xt_node *node_cache;62 GHashTable *node_cache; 63 63 }; 64 64 … … 67 67 char code[5]; 68 68 char *full_name; 69 }; 70 71 typedef xt_status (*jabber_cache_event) ( struct gaim_connection *gc, struct xt_node *packet ); 72 73 struct jabber_cache_entry 74 { 75 struct xt_node *node; 76 jabber_cache_event func; 69 77 }; 70 78 … … 88 96 char *set_eval_tls( set_t *set, char *value ); 89 97 struct xt_node *jabber_make_packet( char *name, char *type, char *to, struct xt_node *children ); 90 void jabber_cache_packet( struct gaim_connection *gc, struct xt_node *node ); 91 struct xt_node *jabber_packet_from_cache( struct gaim_connection *gc, char *id ); 98 void jabber_cache_add( struct gaim_connection *gc, struct xt_node *node ); 99 struct xt_node *jabber_cache_get( struct gaim_connection *gc, char *id ); 100 void jabber_cache_entry_free( gpointer entry ); 101 void jabber_cache_clean( struct gaim_connection *gc ); 92 102 const struct jabber_away_state *jabber_away_state_by_code( char *code ); 93 103 const struct jabber_away_state *jabber_away_state_by_name( char *name ); -
protocols/jabber/jabber_util.c
r36e9f62 r038d17f 82 82 them when you receive the response. Use this BEFORE sending the packet so 83 83 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 )84 void jabber_cache_add( struct gaim_connection *gc, struct xt_node *node ) 85 85 { 86 86 struct jabber_data *jd = gc->proto_data; 87 87 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 ); 90 89 91 90 xt_add_attr( node, "id", id ); 92 xt_add_child( jd->node_cache, node );93 91 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 97 struct xt_node *jabber_cache_get( struct gaim_connection *gc, char *id ) 98 98 { 99 99 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 105 void 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 113 gboolean jabber_cache_clean_entry( gpointer key, gpointer entry, gpointer nullpointer ); 114 115 void 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 122 gboolean 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 } 108 134 } 109 135
Note: See TracChangeset
for help on using the changeset viewer.