Changes in protocols/jabber/jabber_util.c [2ff2076:979cfb4]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/jabber_util.c
r2ff2076 r979cfb4 97 97 } 98 98 99 struct xt_node *jabber_make_error_packet( struct xt_node *orig, char *err_cond, char *err_type , char *err_code)99 struct xt_node *jabber_make_error_packet( struct xt_node *orig, char *err_cond, char *err_type ) 100 100 { 101 101 struct xt_node *node, *c; … … 109 109 c = xt_new_node( "error", NULL, c ); 110 110 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 );115 111 116 112 /* To make the actual error packet, we copy the original packet and … … 146 142 entry->node = node; 147 143 entry->func = func; 144 entry->saved_at = time( NULL ); 148 145 g_hash_table_insert( jd->node_cache, xt_find_attr( node, "id" ), entry ); 149 146 } … … 167 164 { 168 165 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 171 gboolean jabber_cache_clean_entry( gpointer key, gpointer entry_, gpointer threshold_ ) 174 172 { 175 173 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 179 xt_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; 185 207 } 186 208 … … 265 287 new = g_new( char, len + 1 ); 266 288 for( i = 0; i < len; i ++ ) 267 {268 /* don't normalize the resource */269 if( orig[i] == '/' )270 break;271 289 new[i] = tolower( orig[i] ); 272 }273 for( ; i < len; i ++ )274 new[i] = orig[i];275 290 276 291 new[i] = 0; … … 373 388 if( ( bud = g_hash_table_lookup( jd->buddies, jid ) ) ) 374 389 { 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 375 398 /* Is this one of those no-resource buddies? */ 376 399 if( bud->resource == NULL ) 377 400 { 401 *s = '/'; 378 402 g_free( jid ); 379 403 return NULL; 380 404 } 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; 388 410 } 389 411 else … … 394 416 is done to handle conferences properly. */ 395 417 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... */ 396 420 } 397 421 … … 423 447 else if( ( bud->resource == NULL || bud->next == NULL ) ) 424 448 /* 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. */ 425 452 return bud; 426 453 … … 595 622 } 596 623 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 614 624 time_t jabber_get_timestamp( struct xt_node *xt ) 615 625 { … … 663 673 struct jabber_error *jabber_error_parse( struct xt_node *node, char *xmlns ) 664 674 { 665 struct jabber_error *err = g_new0( struct jabber_error, 1 );675 struct jabber_error *err; 666 676 struct xt_node *c; 667 677 char *s; 668 678 679 if( node == NULL ) 680 return NULL; 681 682 err = g_new0( struct jabber_error, 1 ); 669 683 err->type = xt_find_attr( node, "type" ); 670 684
Note: See TracChangeset
for help on using the changeset viewer.