Changes in protocols/jabber/jabber_util.c [842cd8d:840bba8]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/jabber_util.c
r842cd8d r840bba8 4 4 * Jabber module - Misc. stuff * 5 5 * * 6 * Copyright 2006 -2010 Wilmer van der Gaast <wilmer@gaast.net>6 * Copyright 2006 Wilmer van der Gaast <wilmer@gaast.net> * 7 7 * * 8 8 * This program is free software; you can redistribute it and/or modify * … … 345 345 if( ( bud = g_hash_table_lookup( jd->buddies, full_jid ) ) ) 346 346 { 347 /* The first entry is always a bare JID. If there are more, we348 should ignore the first one here. */349 if( bud->next )350 bud = bud->next;351 352 347 /* If this is a transport buddy or whatever, it can't have more 353 348 than one instance, so this is always wrong: */ … … 384 379 else 385 380 { 386 new->full_jid = new->bare_jid = g_strdup( full_jid ); 381 /* Keep in mind that full_jid currently isn't really 382 a full JID... */ 383 new->bare_jid = g_strdup( full_jid ); 387 384 g_hash_table_insert( jd->buddies, new->bare_jid, new ); 388 389 if( s )390 {391 new->next = g_new0( struct jabber_buddy, 1 );392 new->next->bare_jid = new->bare_jid;393 new = new->next;394 }395 385 } 396 386 … … 418 408 { 419 409 struct jabber_data *jd = ic->proto_data; 420 struct jabber_buddy *bud , *head;410 struct jabber_buddy *bud; 421 411 char *s, *jid; 422 412 … … 430 420 if( ( bud = g_hash_table_lookup( jd->buddies, jid ) ) ) 431 421 { 432 bare_exists = 1;433 434 if( bud->next )435 bud = bud->next;436 437 422 /* Just return the first one for this bare JID. */ 438 423 if( flags & GET_BUDDY_FIRST ) … … 456 441 break; 457 442 } 443 else 444 { 445 /* This variable tells the if down here that the bare 446 JID already exists and we should feel free to add 447 more resources, if the caller asked for that. */ 448 bare_exists = 1; 449 } 458 450 459 451 if( bud == NULL && ( flags & GET_BUDDY_CREAT ) && 460 ( bare_exists || imcb_find_buddy( ic, jid ) ) )452 ( !bare_exists || imcb_find_buddy( ic, jid ) ) ) 461 453 { 462 454 *s = '/'; … … 472 464 char *set; 473 465 474 head = g_hash_table_lookup( jd->buddies, jid ); 475 bud = ( head && head->next ) ? head->next : head; 466 bud = g_hash_table_lookup( jd->buddies, jid ); 476 467 477 468 g_free( jid ); … … 490 481 /* Looks like the caller doesn't care about details. */ 491 482 return bud; 492 else if( flags & GET_BUDDY_BARE )493 return head;494 483 495 484 best_prio = best_time = bud; … … 498 487 if( bud->priority > best_prio->priority ) 499 488 best_prio = bud; 500 if( bud->last_ msg > best_time->last_msg)489 if( bud->last_act > best_time->last_act ) 501 490 best_time = bud; 502 491 } … … 504 493 if( ( set = set_getstr( &ic->acc->set, "resource_select" ) ) == NULL ) 505 494 return NULL; 506 else if( strcmp( set, "priority" ) == 0 ) 495 else if( strcmp( set, "activity" ) == 0 ) 496 return best_time; 497 else /* if( strcmp( set, "priority" ) == 0 ) */ 507 498 return best_prio; 508 else if( flags & GET_BUDDY_BARE_OK ) /* && strcmp( set, "activity" ) == 0 */509 {510 if( best_time->last_msg + set_getint( &ic->acc->set, "activity_timeout" ) >= time( NULL ) )511 return best_time;512 else513 return head;514 }515 else516 return best_time;517 499 } 518 500 } … … 556 538 { 557 539 struct jabber_data *jd = ic->proto_data; 558 struct jabber_buddy *bud, *prev = NULL, *bi;540 struct jabber_buddy *bud, *prev, *bi; 559 541 char *s, *full_jid; 560 542 … … 566 548 if( ( bud = g_hash_table_lookup( jd->buddies, full_jid ) ) ) 567 549 { 568 if( bud->next )569 bud = (prev=bud)->next;570 571 550 /* If there's only one item in the list (and if the resource 572 551 matches), removing it is simple. (And the hash reference … … 576 555 ( bud->resource && s && strcmp( bud->resource, s + 1 ) == 0 ) ) ) 577 556 { 578 return jabber_buddy_remove_bare( ic, full_jid ); 557 g_hash_table_remove( jd->buddies, bud->bare_jid ); 558 g_free( bud->bare_jid ); 559 g_free( bud->ext_jid ); 560 g_free( bud->full_jid ); 561 g_free( bud->away_message ); 562 g_free( bud ); 563 564 g_free( full_jid ); 565 566 return 1; 579 567 } 580 568 else if( s == NULL || bud->resource == NULL ) … … 587 575 else 588 576 { 589 for( bi = bud ; bi; bi = (prev=bi)->next )577 for( bi = bud, prev = NULL; bi; bi = (prev=bi)->next ) 590 578 if( strcmp( bi->resource, s + 1 ) == 0 ) 591 579 break; … … 598 586 prev->next = bi->next; 599 587 else 600 /* Don't think this should ever happen anymore. */ 588 /* The hash table should point at the second 589 item, because we're removing the first. */ 601 590 g_hash_table_replace( jd->buddies, bi->bare_jid, bi->next ); 602 591
Note: See TracChangeset
for help on using the changeset viewer.