Changes in protocols/jabber/jabber_util.c [f0cb961:9da0bbf]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/jabber_util.c
rf0cb961 r9da0bbf 48 48 call p_s_u() now to send the new prio setting, it would 49 49 send the old setting because the set->value gets changed 50 when theeval returns a non-NULL value.50 after the (this) eval returns a non-NULL value. 51 51 52 52 So now I can choose between implementing post-set … … 129 129 /* Cache a node/packet for later use. Mainly useful for IQ packets if you need 130 130 them when you receive the response. Use this BEFORE sending the packet so 131 it'll get a new id= tag, and do NOT free() the packet after writing it! */131 it'll get a new id= tag, and do NOT free() the packet after sending it! */ 132 132 void jabber_cache_add( struct im_connection *ic, struct xt_node *node, jabber_cache_event func ) 133 133 { … … 252 252 253 253 /* Returns a new string. Don't leak it! */ 254 char *jabber_normalize( c har *orig )254 char *jabber_normalize( const char *orig ) 255 255 { 256 256 int len, i; … … 320 320 else 321 321 { 322 /* Keep in mind that full_jid currently isn't really 323 a full JID... */ 322 324 new->bare_jid = g_strdup( full_jid ); 323 325 g_hash_table_insert( jd->buddies, new->bare_jid, new ); … … 333 335 { 334 336 /* Let's waste some more bytes of RAM instead of to make 335 memory management a total disaster here.. */ 337 memory management a total disaster here. And it saves 338 me one g_free() call in this function. :-P */ 336 339 new->full_jid = full_jid; 337 340 } … … 353 356 if( ( s = strchr( jid, '/' ) ) ) 354 357 { 358 int none_found = 0; 359 355 360 *s = 0; 356 361 if( ( bud = g_hash_table_lookup( jd->buddies, jid ) ) ) … … 370 375 } 371 376 } 372 373 if( bud == NULL && ( flags & GET_BUDDY_CREAT ) && imcb_find_buddy( ic, jid ) ) 377 else 378 { 379 /* This hack is there to make sure that O_CREAT will 380 work if there's already another resouce present 381 for this JID, even if it's an unknown buddy. This 382 is done to handle conferences properly. */ 383 none_found = 1; 384 } 385 386 if( bud == NULL && ( flags & GET_BUDDY_CREAT ) && ( imcb_find_buddy( ic, jid ) || !none_found ) ) 374 387 { 375 388 *s = '/'; … … 418 431 } 419 432 433 /* I'm keeping a separate ext_jid attribute to save a JID that makes sense 434 to export to BitlBee. This is mainly for groupchats right now. It's 435 a bit of a hack, but I just think having the user nickname in the hostname 436 part of the hostmask doesn't look nice on IRC. Normally you can convert 437 a normal JID to ext_jid by swapping the part before and after the / and 438 replacing the / with a =. But there should be some stripping (@s are 439 allowed in Jabber nicks...). */ 440 struct jabber_buddy *jabber_buddy_by_ext_jid( struct im_connection *ic, char *jid_, get_buddy_flags_t flags ) 441 { 442 struct jabber_buddy *bud; 443 char *s, *jid; 444 445 jid = jabber_normalize( jid_ ); 446 447 if( ( s = strchr( jid, '=' ) ) == NULL ) 448 return NULL; 449 450 for( bud = jabber_buddy_by_jid( ic, s + 1, GET_BUDDY_FIRST ); bud; bud = bud->next ) 451 { 452 /* Hmmm, could happen if not all people in the chat are anonymized? */ 453 if( bud->ext_jid == NULL ) 454 continue; 455 456 if( strcmp( bud->ext_jid, jid ) == 0 ) 457 break; 458 } 459 460 g_free( jid ); 461 462 return bud; 463 } 464 420 465 /* Remove one specific full JID from our list. Use this when a buddy goes 421 466 off-line (because (s)he can still be online from a different location. … … 441 486 g_hash_table_remove( jd->buddies, bud->bare_jid ); 442 487 g_free( bud->bare_jid ); 488 g_free( bud->ext_jid ); 443 489 g_free( bud->full_jid ); 444 490 g_free( bud->away_message ); … … 473 519 g_hash_table_replace( jd->buddies, bi->bare_jid, bi->next ); 474 520 521 g_free( bi->ext_jid ); 475 522 g_free( bi->full_jid ); 476 523 g_free( bi->away_message ); … … 495 542 specified bare JID. Use this when removing someone from the contact 496 543 list, for example. */ 497 int jabber_buddy_remove_bare( struct im_connection *ic, char *bare_jid _)544 int jabber_buddy_remove_bare( struct im_connection *ic, char *bare_jid ) 498 545 { 499 546 struct jabber_data *jd = ic->proto_data; 500 547 struct jabber_buddy *bud, *next; 501 char *bare_jid; 502 503 if( strchr( bare_jid_, '/' ) ) 548 549 if( strchr( bare_jid, '/' ) ) 504 550 return 0; 505 551 506 bare_jid = jabber_normalize( bare_jid_ ); 507 508 if( ( bud = g_hash_table_lookup( jd->buddies, bare_jid ) ) ) 552 if( ( bud = jabber_buddy_by_jid( ic, bare_jid, GET_BUDDY_FIRST ) ) ) 509 553 { 510 554 /* Most important: Remove the hash reference. We don't know 511 555 this buddy anymore. */ 512 556 g_hash_table_remove( jd->buddies, bud->bare_jid ); 557 g_free( bud->bare_jid ); 513 558 514 559 /* Deallocate the linked list of resources. */ 515 560 while( bud ) 516 561 { 562 /* ext_jid && anonymous means that this buddy is 563 specific to one groupchat (the one we're 564 currently cleaning up) so it can be deleted 565 completely. */ 566 if( bud->ext_jid && bud->flags & JBFLAG_IS_ANONYMOUS ) 567 imcb_remove_buddy( ic, bud->ext_jid, NULL ); 568 517 569 next = bud->next; 570 g_free( bud->ext_jid ); 518 571 g_free( bud->full_jid ); 519 572 g_free( bud->away_message ); … … 522 575 } 523 576 524 g_free( bare_jid );525 577 return 1; 526 578 } 527 579 else 528 580 { 529 g_free( bare_jid );530 581 return 0; 531 582 } 532 583 } 584 585 struct groupchat *jabber_chat_by_name( struct im_connection *ic, const char *name ) 586 { 587 char *normalized = jabber_normalize( name ); 588 struct groupchat *ret; 589 struct jabber_chat *jc; 590 591 for( ret = ic->groupchats; ret; ret = ret->next ) 592 { 593 jc = ret->data; 594 if( strcmp( normalized, jc->name ) == 0 ) 595 break; 596 } 597 g_free( normalized ); 598 599 return ret; 600 } 601 602 time_t jabber_get_timestamp( struct xt_node *xt ) 603 { 604 struct tm tp, utc; 605 struct xt_node *c; 606 time_t res, tres; 607 char *s = NULL; 608 609 for( c = xt->children; ( c = xt_find_node( c, "x" ) ); c = c->next ) 610 { 611 if( ( s = xt_find_attr( c, "xmlns" ) ) && strcmp( s, XMLNS_DELAY ) == 0 ) 612 break; 613 } 614 615 if( !c || !( s = xt_find_attr( c, "stamp" ) ) ) 616 return 0; 617 618 memset( &tp, 0, sizeof( tp ) ); 619 if( sscanf( s, "%4d%2d%2dT%2d:%2d:%2d", &tp.tm_year, &tp.tm_mon, &tp.tm_mday, 620 &tp.tm_hour, &tp.tm_min, &tp.tm_sec ) != 6 ) 621 return 0; 622 623 tp.tm_year -= 1900; 624 tp.tm_mon --; 625 tp.tm_isdst = -1; /* GRRRRRRRRRRR */ 626 627 res = mktime( &tp ); 628 /* Problem is, mktime() just gave us the GMT timestamp for the 629 given local time... While the given time WAS NOT local. So 630 we should fix this now. 631 632 Now I could choose between messing with environment variables 633 (kludgy) or using timegm() (not portable)... Or doing the 634 following, which I actually prefer... */ 635 gmtime_r( &res, &utc ); 636 utc.tm_isdst = -1; /* Once more: GRRRRRRRRRRRRRRRRRR!!! */ 637 if( utc.tm_hour == tp.tm_hour && utc.tm_min == tp.tm_min ) 638 /* Sweet! We're in UTC right now... */ 639 return res; 640 641 tres = mktime( &utc ); 642 res += res - tres; 643 644 /* Yes, this is a hack. And it will go wrong around DST changes. 645 BUT this is more likely to be threadsafe than messing with 646 environment variables, and possibly more portable... */ 647 648 return res; 649 }
Note: See TracChangeset
for help on using the changeset viewer.