Commit c3d73667 authored by Guillaume BIENKOWSKI's avatar Guillaume BIENKOWSKI
Browse files

Use timegm() function in iPhone Simulator to convert UTC struct tm to time_t...

Use timegm() function in iPhone Simulator to convert UTC struct tm to time_t in belle_sip chat messages parsing.
parent 04d50c98
......@@ -1612,19 +1612,21 @@ static const char *days[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
static const char *months[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
BELLESIP_EXPORT time_t belle_sip_header_date_get_time(belle_sip_header_date_t *obj){
struct tm ret={0};
char tmp1[16]={0};
char tmp2[16]={0};
struct tm ret ={0};
char tmp1[16] ={0};
char tmp2[16] ={0};
int i,j;
time_t seconds;
time_t adjust_timezone = timezone;
/* time headers are in GMT as spec says */
sscanf(obj->date,"%3c,%d %16s %d %d:%d:%d",tmp1,&ret.tm_mday,tmp2,
&ret.tm_year,&ret.tm_hour,&ret.tm_min,&ret.tm_sec);
ret.tm_year-=1900;
for(i=0;i<7;i++) {
for(i=0;i<7;i++) {
if(strcmp(tmp1,days[i])==0) {
ret.tm_wday=i;
for(j=0;j<12;j++) {
for(j=0;j<12;j++) {
if(strcmp(tmp2,months[j])==0) {
ret.tm_mon=j;
goto success;
......@@ -1635,18 +1637,25 @@ BELLESIP_EXPORT time_t belle_sip_header_date_get_time(belle_sip_header_date_t *o
belle_sip_warning("Failed to parse date %s",obj->date);
return (time_t)-1;
success:
ret.tm_isdst=0;
#if TARGET_IPHONE_SIMULATOR
/* 'timezone' is buggy on iOS simulator, use the timegm() function to convert to UTC timestamp
and discard the adjust timezone value */
seconds = timegm(&ret);
adjust_timezone = 0;
#else
seconds=mktime(&ret);
#endif
if (seconds==(time_t)-1){
belle_sip_error("mktime() failed: %s",strerror(errno));
return (time_t)-1;
}
return seconds-timezone;
return seconds-adjust_timezone;
}
BELLESIP_EXPORT void belle_sip_header_date_set_time(belle_sip_header_date_t *obj, const time_t *utc_time){
struct tm *ret;
#ifndef WIN32
struct tm gmt;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment