Changeset 76c85b4c for protocols/jabber/jabber_util.c
- Timestamp:
- 2009-11-19T13:11:38Z (14 years ago)
- Branches:
- master
- Children:
- 20e830b
- Parents:
- 36cf9fd
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/jabber_util.c
r36cf9fd r76c85b4c 340 340 if( ( bud = g_hash_table_lookup( jd->buddies, full_jid ) ) ) 341 341 { 342 /* The first entry is always a bare JID. If there are more, we 343 should ignore the first one here. */ 344 if( bud->next ) 345 bud = bud->next; 346 342 347 /* If this is a transport buddy or whatever, it can't have more 343 348 than one instance, so this is always wrong: */ … … 374 379 else 375 380 { 376 /* Keep in mind that full_jid currently isn't really 377 a full JID... */ 378 new->bare_jid = g_strdup( full_jid ); 381 new->full_jid = new->bare_jid = g_strdup( full_jid ); 379 382 g_hash_table_insert( jd->buddies, new->bare_jid, new ); 383 384 if( s ) 385 { 386 new->next = g_new0( struct jabber_buddy, 1 ); 387 new->next->bare_jid = new->bare_jid; 388 new = new->next; 389 } 380 390 } 381 391 … … 403 413 { 404 414 struct jabber_data *jd = ic->proto_data; 405 struct jabber_buddy *bud ;415 struct jabber_buddy *bud, *head; 406 416 char *s, *jid; 407 417 … … 410 420 if( ( s = strchr( jid, '/' ) ) ) 411 421 { 412 int bare_exists = 0;413 414 422 *s = 0; 415 423 if( ( bud = g_hash_table_lookup( jd->buddies, jid ) ) ) 416 424 { 425 if( bud->next ) 426 bud = bud->next; 427 417 428 /* Just return the first one for this bare JID. */ 418 429 if( flags & GET_BUDDY_FIRST ) … … 436 447 break; 437 448 } 438 else 439 { 440 /* This variable tells the if down here that the bare 441 JID already exists and we should feel free to add 442 more resources, if the caller asked for that. */ 443 bare_exists = 1; 444 } 445 446 if( bud == NULL && ( flags & GET_BUDDY_CREAT ) && 447 ( !bare_exists || imcb_find_buddy( ic, jid ) ) ) 449 450 if( bud == NULL && ( flags & GET_BUDDY_CREAT ) && imcb_find_buddy( ic, jid ) ) 448 451 { 449 452 *s = '/'; … … 459 462 char *set; 460 463 461 bud = g_hash_table_lookup( jd->buddies, jid ); 464 head = g_hash_table_lookup( jd->buddies, jid ); 465 bud = head->next ? head->next : head; 462 466 463 467 g_free( jid ); … … 476 480 /* Looks like the caller doesn't care about details. */ 477 481 return bud; 482 else if( flags & GET_BUDDY_BARE ) 483 return head; 478 484 479 485 best_prio = best_time = bud; … … 482 488 if( bud->priority > best_prio->priority ) 483 489 best_prio = bud; 484 if( bud->last_ act > best_time->last_act)490 if( bud->last_msg > best_time->last_msg ) 485 491 best_time = bud; 486 492 } … … 488 494 if( ( set = set_getstr( &ic->acc->set, "resource_select" ) ) == NULL ) 489 495 return NULL; 490 else if( strcmp( set, "activity" ) == 0 ) 496 else if( strcmp( set, "priority" ) == 0 ) 497 return best_prio; 498 else if( flags & GET_BUDDY_BARE_OK ) /* && strcmp( set, "activity" ) == 0 */ 499 { 500 if( best_time->last_msg + set_getint( &ic->acc->set, "activity_timeout" ) >= time( NULL ) ) 501 return best_time; 502 else 503 return head; 504 } 505 else 491 506 return best_time; 492 else /* if( strcmp( set, "priority" ) == 0 ) */493 return best_prio;494 507 } 495 508 } … … 533 546 { 534 547 struct jabber_data *jd = ic->proto_data; 535 struct jabber_buddy * bud, *prev, *bi;548 struct jabber_buddy *head, *bud, *prev, *bi; 536 549 char *s, *full_jid; 537 550 … … 541 554 *s = 0; 542 555 543 if( ( bud = g_hash_table_lookup( jd->buddies, full_jid ) ) ) 544 { 556 if( ( head = g_hash_table_lookup( jd->buddies, full_jid ) ) ) 557 { 558 bud = head->next ? head->next : head; 559 545 560 /* If there's only one item in the list (and if the resource 546 561 matches), removing it is simple. (And the hash reference … … 550 565 ( bud->resource && s && strcmp( bud->resource, s + 1 ) == 0 ) ) ) 551 566 { 552 g_hash_table_remove( jd->buddies, bud->bare_jid ); 553 g_free( bud->bare_jid ); 554 g_free( bud->ext_jid ); 555 g_free( bud->full_jid ); 556 g_free( bud->away_message ); 557 g_free( bud ); 558 559 g_free( full_jid ); 560 561 return 1; 567 return jabber_buddy_remove_bare( ic, full_jid ); 562 568 } 563 569 else if( s == NULL || bud->resource == NULL )
Note: See TracChangeset
for help on using the changeset viewer.