Changes in protocols/jabber/jabber_util.c [7125cb3:842cd8d]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/jabber_util.c
r7125cb3 r842cd8d 4 4 * Jabber module - Misc. stuff * 5 5 * * 6 * Copyright 2006 Wilmer van der Gaast <wilmer@gaast.net> *6 * Copyright 2006-2010 Wilmer van der Gaast <wilmer@gaast.net> 7 7 * * 8 8 * This program is free software; you can redistribute it and/or modify * … … 228 228 { 229 229 { "away", "Away" }, 230 { "chat", "Free for Chat" }, 230 { "chat", "Free for Chat" }, /* WTF actually uses this? */ 231 231 { "dnd", "Do not Disturb" }, 232 232 { "xa", "Extended Away" }, 233 { "", "Online" },234 233 { "", NULL } 235 234 }; … … 238 237 { 239 238 int i; 239 240 if( code == NULL ) 241 return NULL; 240 242 241 243 for( i = 0; jabber_away_state_list[i].full_name; i ++ ) … … 249 251 { 250 252 int i; 253 254 if( name == NULL ) 255 return NULL; 251 256 252 257 for( i = 0; jabber_away_state_list[i].full_name; i ++ ) … … 340 345 if( ( bud = g_hash_table_lookup( jd->buddies, full_jid ) ) ) 341 346 { 347 /* The first entry is always a bare JID. If there are more, we 348 should ignore the first one here. */ 349 if( bud->next ) 350 bud = bud->next; 351 342 352 /* If this is a transport buddy or whatever, it can't have more 343 353 than one instance, so this is always wrong: */ … … 374 384 else 375 385 { 376 /* Keep in mind that full_jid currently isn't really 377 a full JID... */ 378 new->bare_jid = g_strdup( full_jid ); 386 new->full_jid = new->bare_jid = g_strdup( full_jid ); 379 387 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 } 380 395 } 381 396 … … 403 418 { 404 419 struct jabber_data *jd = ic->proto_data; 405 struct jabber_buddy *bud ;420 struct jabber_buddy *bud, *head; 406 421 char *s, *jid; 407 422 … … 415 430 if( ( bud = g_hash_table_lookup( jd->buddies, jid ) ) ) 416 431 { 432 bare_exists = 1; 433 434 if( bud->next ) 435 bud = bud->next; 436 417 437 /* Just return the first one for this bare JID. */ 418 438 if( flags & GET_BUDDY_FIRST ) … … 436 456 break; 437 457 } 438 else439 {440 /* This variable tells the if down here that the bare441 JID already exists and we should feel free to add442 more resources, if the caller asked for that. */443 bare_exists = 1;444 }445 458 446 459 if( bud == NULL && ( flags & GET_BUDDY_CREAT ) && 447 ( !bare_exists || imcb_find_buddy( ic, jid ) ) )460 ( bare_exists || imcb_find_buddy( ic, jid ) ) ) 448 461 { 449 462 *s = '/'; … … 459 472 char *set; 460 473 461 bud = g_hash_table_lookup( jd->buddies, jid ); 474 head = g_hash_table_lookup( jd->buddies, jid ); 475 bud = ( head && head->next ) ? head->next : head; 462 476 463 477 g_free( jid ); … … 476 490 /* Looks like the caller doesn't care about details. */ 477 491 return bud; 492 else if( flags & GET_BUDDY_BARE ) 493 return head; 478 494 479 495 best_prio = best_time = bud; … … 482 498 if( bud->priority > best_prio->priority ) 483 499 best_prio = bud; 484 if( bud->last_ act > best_time->last_act)500 if( bud->last_msg > best_time->last_msg ) 485 501 best_time = bud; 486 502 } … … 488 504 if( ( set = set_getstr( &ic->acc->set, "resource_select" ) ) == NULL ) 489 505 return NULL; 490 else if( strcmp( set, "activity" ) == 0 ) 506 else if( strcmp( set, "priority" ) == 0 ) 507 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 else 513 return head; 514 } 515 else 491 516 return best_time; 492 else /* if( strcmp( set, "priority" ) == 0 ) */493 return best_prio;494 517 } 495 518 } … … 533 556 { 534 557 struct jabber_data *jd = ic->proto_data; 535 struct jabber_buddy *bud, *prev , *bi;558 struct jabber_buddy *bud, *prev = NULL, *bi; 536 559 char *s, *full_jid; 537 560 … … 543 566 if( ( bud = g_hash_table_lookup( jd->buddies, full_jid ) ) ) 544 567 { 568 if( bud->next ) 569 bud = (prev=bud)->next; 570 545 571 /* If there's only one item in the list (and if the resource 546 572 matches), removing it is simple. (And the hash reference … … 550 576 ( bud->resource && s && strcmp( bud->resource, s + 1 ) == 0 ) ) ) 551 577 { 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; 578 return jabber_buddy_remove_bare( ic, full_jid ); 562 579 } 563 580 else if( s == NULL || bud->resource == NULL ) … … 570 587 else 571 588 { 572 for( bi = bud , prev = NULL; bi; bi = (prev=bi)->next )589 for( bi = bud; bi; bi = (prev=bi)->next ) 573 590 if( strcmp( bi->resource, s + 1 ) == 0 ) 574 591 break; … … 581 598 prev->next = bi->next; 582 599 else 583 /* The hash table should point at the second 584 item, because we're removing the first. */ 600 /* Don't think this should ever happen anymore. */ 585 601 g_hash_table_replace( jd->buddies, bi->bare_jid, bi->next ); 586 602
Note: See TracChangeset
for help on using the changeset viewer.