Changes in / [638feab:6ce01be]
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/jabber.c
r638feab r6ce01be 57 57 set_t *s; 58 58 char str[16]; 59 60 s = set_add( &acc->set, "activity_timeout", "600", set_eval_int, acc );61 59 62 60 g_snprintf( str, sizeof( str ), "%d", jabber_port_list[0] ); … … 309 307 bud = jabber_buddy_by_ext_jid( ic, who, 0 ); 310 308 else 311 bud = jabber_buddy_by_jid( ic, who, GET_BUDDY_BARE_OK);309 bud = jabber_buddy_by_jid( ic, who, 0 ); 312 310 313 311 node = xt_new_node( "body", message, NULL ); … … 354 352 static void jabber_get_info( struct im_connection *ic, char *who ) 355 353 { 354 struct jabber_data *jd = ic->proto_data; 356 355 struct jabber_buddy *bud; 357 356 358 bud = jabber_buddy_by_jid( ic, who, GET_BUDDY_FIRST ); 357 if( strchr( who, '/' ) ) 358 bud = jabber_buddy_by_jid( ic, who, 0 ); 359 else 360 { 361 char *s = jabber_normalize( who ); 362 bud = g_hash_table_lookup( jd->buddies, s ); 363 g_free( s ); 364 } 359 365 360 366 while( bud ) -
protocols/jabber/jabber.h
r638feab r6ce01be 108 108 }; 109 109 110 /* Somewhat messy data structure: We have a hash table with the bare JID as111 the key and the head of a struct jabber_buddy list as the value. The head112 is always a bare JID. If the JID has other resources (often the case,113 except for some transports that don't support multiple resources), those114 follow. In that case, the bare JID at the beginning doesn't actually115 refer to a real session and should only be used for operations that116 support incomplete JIDs. */117 110 struct jabber_buddy 118 111 { … … 128 121 char *away_message; 129 122 130 time_t last_ msg;123 time_t last_act; 131 124 jabber_buddy_flags_t flags; 132 125 … … 216 209 GET_BUDDY_EXACT = 2, /* Get an exact match (only makes sense with bare JIDs). */ 217 210 GET_BUDDY_FIRST = 4, /* No selection, simply get the first resource for this JID. */ 218 GET_BUDDY_BARE = 8, /* Get the bare version of the JID (possibly inexistent). */219 GET_BUDDY_BARE_OK = 16, /* Allow returning a bare JID if that seems better. */220 211 } get_buddy_flags_t; 221 212 -
protocols/jabber/jabber_util.c
r638feab r6ce01be 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 -
protocols/jabber/message.c
r638feab r6ce01be 71 71 if( bud ) 72 72 { 73 bud->last_ msg= time( NULL );73 bud->last_act = time( NULL ); 74 74 from = bud->ext_jid ? : bud->bare_jid; 75 75 } -
protocols/jabber/presence.c
r638feab r6ce01be 68 68 { 69 69 bud->away_state = NULL; 70 /* Let's only set last_act if there's *no* away state, 71 since it could be some auto-away thingy. */ 72 bud->last_act = time( NULL ); 70 73 } 71 74 -
tests/check_jabber_util.c
r638feab r6ce01be 14 14 15 15 budw1 = jabber_buddy_add( ic, "wilmer@gaast.net/BitlBee" ); 16 budw1->last_ msg= time( NULL ) - 100;16 budw1->last_act = time( NULL ) - 100; 17 17 budw2 = jabber_buddy_add( ic, "WILMER@gaast.net/Telepathy" ); 18 18 budw2->priority = 2; 19 budw2->last_ msg= time( NULL );19 budw2->last_act = time( NULL ); 20 20 budw3 = jabber_buddy_add( ic, "wilmer@GAAST.NET/bitlbee" ); 21 budw3->last_ msg= time( NULL ) - 200;21 budw3->last_act = time( NULL ) - 200; 22 22 budw3->priority = 4; 23 23 /* TODO(wilmer): Shouldn't this just return budw3? */ … … 60 60 fail_unless( jabber_buddy_remove( ic, "wilmer@gaast.net/Telepathy" ) ); 61 61 fail_unless( jabber_buddy_remove( ic, "wilmer@gaast.net/telepathy" ) ); 62 63 /* Test activity_timeout and GET_BUDDY_BARE_OK. */ 64 fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", GET_BUDDY_BARE_OK ) == budw1 ); 65 budw1->last_msg -= 50; 66 fail_unless( ( bud = jabber_buddy_by_jid( ic, "wilmer@gaast.net", GET_BUDDY_BARE_OK ) ) != NULL ); 67 fail_unless( strcmp( bud->full_jid, "wilmer@gaast.net" ) == 0 ); 62 fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) == budw1 ); 68 63 69 64 fail_if( jabber_buddy_remove( ic, "wilmer@gaast.net" ) ); 70 65 fail_unless( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) == budw1 ); 71 66 72 fail_if( jabber_buddy_remove( ic, "wilmer@gaast.net" ) );73 fail_unless( jabber_buddy_remove( ic, "wilmer@gaast.net/bitlbee" ) );74 fail_unless( jabber_buddy_remove( ic, "wilmer@gaast.net/BitlBee" ) );75 fail_if( jabber_buddy_by_jid( ic, "wilmer@gaast.net", GET_BUDDY_BARE_OK ) );76 77 67 /* Check if remove_bare() indeed gets rid of all. */ 78 /* disable this one for now.79 68 fail_unless( jabber_buddy_remove_bare( ic, "wilmer@gaast.net" ) ); 80 69 fail_if( jabber_buddy_by_jid( ic, "wilmer@gaast.net", 0 ) ); 81 */82 70 83 71 fail_if( jabber_buddy_remove( ic, "nekkid@lamejab.net/Illegal" ) ); 84 72 fail_unless( jabber_buddy_remove( ic, "nekkid@lamejab.net" ) ); 85 73 fail_if( jabber_buddy_by_jid( ic, "nekkid@lamejab.net", 0 ) ); 86 87 /* Fixing a bug in this branch that caused information to get lost when88 removing the first full JID from a list. */89 jabber_buddy_add( ic, "bugtest@google.com/A" );90 jabber_buddy_add( ic, "bugtest@google.com/B" );91 jabber_buddy_add( ic, "bugtest@google.com/C" );92 fail_unless( jabber_buddy_remove( ic, "bugtest@google.com/A" ) );93 fail_unless( jabber_buddy_remove( ic, "bugtest@google.com/B" ) );94 fail_unless( jabber_buddy_remove( ic, "bugtest@google.com/C" ) );95 74 } 96 75 … … 106 85 jd->buddies = g_hash_table_new( g_str_hash, g_str_equal ); 107 86 set_add( &ic->acc->set, "resource_select", "priority", NULL, ic->acc ); 108 set_add( &ic->acc->set, "activity_timeout", "120", NULL, ic->acc );109 87 110 88 suite_add_tcase (s, tc_core);
Note: See TracChangeset
for help on using the changeset viewer.