Changeset 43671b9 for protocols/jabber/jabber_util.c
- Timestamp:
- 2007-04-22T23:39:37Z (17 years ago)
- Branches:
- master
- Children:
- 0e7ab64
- Parents:
- e35d1a1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/jabber_util.c
re35d1a1 r43671b9 558 558 return ret; 559 559 } 560 561 time_t jabber_get_timestamp( struct xt_node *xt ) 562 { 563 struct tm tp, utc; 564 struct xt_node *c; 565 time_t res, tres; 566 char *s = NULL; 567 568 for( c = xt->children; ( c = xt_find_node( c, "x" ) ); c = c->next ) 569 { 570 if( ( s = xt_find_attr( c, "xmlns" ) ) && strcmp( s, XMLNS_DELAY ) == 0 ) 571 break; 572 } 573 574 if( !c || !( s = xt_find_attr( c, "stamp" ) ) ) 575 return 0; 576 577 memset( &tp, 0, sizeof( tp ) ); 578 if( sscanf( s, "%4d%2d%2dT%2d:%2d:%2d", &tp.tm_year, &tp.tm_mon, &tp.tm_mday, 579 &tp.tm_hour, &tp.tm_min, &tp.tm_sec ) != 6 ) 580 return 0; 581 582 tp.tm_year -= 1900; 583 tp.tm_mon --; 584 tp.tm_isdst = -1; /* GRRRRRRRRRRR */ 585 586 res = mktime( &tp ); 587 /* Problem is, mktime() just gave us the GMT timestamp for the 588 given local time... While the given time WAS NOT local. So 589 we should fix this now. 590 591 Now I could choose between messing with environment variables 592 (kludgy) or using timegm() (not portable)... Or doing the 593 following, which I actually prefer... */ 594 gmtime_r( &res, &utc ); 595 utc.tm_isdst = -1; /* Once more: GRRRRRRRRRRRRRRRRRR!!! */ 596 if( utc.tm_hour == tp.tm_hour && utc.tm_min == tp.tm_min ) 597 /* Sweet! We're in UTC right now... */ 598 return res; 599 600 tres = mktime( &utc ); 601 res += res - tres; 602 603 /* Yes, this is a hack. And it will go wrong around DST changes. 604 BUT this is more likely to be threadsafe than messing with 605 environment variables, and possibly more portable... */ 606 607 return res; 608 }
Note: See TracChangeset
for help on using the changeset viewer.