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