Changeset 76c85b4c
- Timestamp:
- 2009-11-19T13:11:38Z (15 years ago)
- Branches:
- master
- Children:
- 20e830b
- Parents:
- 36cf9fd
- Location:
- protocols/jabber
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/jabber.c
r36cf9fd r76c85b4c 58 58 char str[16]; 59 59 60 s = set_add( &acc->set, "activity_timeout", "600", set_eval_int, acc ); 61 60 62 g_snprintf( str, sizeof( str ), "%d", jabber_port_list[0] ); 61 63 s = set_add( &acc->set, "port", str, set_eval_int, acc ); … … 67 69 s->flags |= ACC_SET_OFFLINE_ONLY; 68 70 69 s = set_add( &acc->set, "resource_select", " priority", NULL, acc );71 s = set_add( &acc->set, "resource_select", "activity", NULL, acc ); 70 72 71 73 s = set_add( &acc->set, "server", NULL, set_eval_account, acc ); … … 305 307 bud = jabber_buddy_by_ext_jid( ic, who, 0 ); 306 308 else 307 bud = jabber_buddy_by_jid( ic, who, 0);309 bud = jabber_buddy_by_jid( ic, who, GET_BUDDY_BARE_OK ); 308 310 309 311 node = xt_new_node( "body", message, NULL ); … … 350 352 static void jabber_get_info( struct im_connection *ic, char *who ) 351 353 { 352 struct jabber_data *jd = ic->proto_data;353 354 struct jabber_buddy *bud; 354 355 355 if( strchr( who, '/' ) ) 356 bud = jabber_buddy_by_jid( ic, who, 0 ); 357 else 358 { 359 char *s = jabber_normalize( who ); 360 bud = g_hash_table_lookup( jd->buddies, s ); 361 g_free( s ); 362 } 356 bud = jabber_buddy_by_jid( ic, who, GET_BUDDY_FIRST ); 363 357 364 358 while( bud ) -
protocols/jabber/jabber.h
r36cf9fd r76c85b4c 107 107 }; 108 108 109 /* Somewhat messy data structure: We have a hash table with the bare JID as 110 the key and the head of a struct jabber_buddy list as the value. The head 111 is always a bare JID. If the JID has other resources (often the case, 112 except for some transports that don't support multiple resources), those 113 follow. In that case, the bare JID at the beginning doesn't actually 114 refer to a real session and should only be used for operations that 115 support incomplete JIDs. */ 109 116 struct jabber_buddy 110 117 { … … 120 127 char *away_message; 121 128 122 time_t last_ act;129 time_t last_msg; 123 130 jabber_buddy_flags_t flags; 124 131 … … 208 215 GET_BUDDY_EXACT = 2, /* Get an exact match (only makes sense with bare JIDs). */ 209 216 GET_BUDDY_FIRST = 4, /* No selection, simply get the first resource for this JID. */ 217 GET_BUDDY_BARE = 8, /* Get the bare version of the JID (possibly inexistent). */ 218 GET_BUDDY_BARE_OK = 16, /* Allow returning a bare JID if that seems better. */ 210 219 } get_buddy_flags_t; 211 220 -
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 ) -
protocols/jabber/message.c
r36cf9fd r76c85b4c 71 71 if( bud ) 72 72 { 73 bud->last_ act= time( NULL );73 bud->last_msg = time( NULL ); 74 74 from = bud->ext_jid ? : bud->bare_jid; 75 75 } -
protocols/jabber/presence.c
r36cf9fd r76c85b4c 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 );73 70 } 74 71
Note: See TracChangeset
for help on using the changeset viewer.