From 5ddf9069f0c5f487b65ef5b64dbd19a56066b350 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Fri, 12 Apr 2013 10:26:57 +0200 Subject: [PATCH] Set UTC time in received chat messages. --- coreapi/sal_eXosip2.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/coreapi/sal_eXosip2.c b/coreapi/sal_eXosip2.c index 1bbbe36e..75ee4629 100644 --- a/coreapi/sal_eXosip2.c +++ b/coreapi/sal_eXosip2.c @@ -1771,6 +1771,26 @@ static bool_t comes_from_local_if(osip_message_t *msg){ 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"}; +static int utc_offset() { + time_t ref = 24 * 60 * 60L; + struct tm * timeptr; + int gmtime_hours; + + /* get the local reference time for Jan 2, 1900 00:00 UTC */ + timeptr = localtime(&ref); + gmtime_hours = timeptr->tm_hour; + + /* if the local time is the "day before" the UTC, subtract 24 hours + from the hours to get the UTC offset */ + if (timeptr->tm_mday < 2) gmtime_hours -= 24; + + return gmtime_hours; +} + +time_t mktime_utc(struct tm *timeptr) { + return mktime(timeptr) + utc_offset() * 3600; +} + static void text_received(Sal *sal, eXosip_event_t *ev){ osip_body_t *body=NULL; char *from=NULL,*msg=NULL; @@ -1842,7 +1862,7 @@ static void text_received(Sal *sal, eXosip_event_t *ev){ salmsg.text=msg; salmsg.url=external_body_size>0 ? unquoted_external_body_url : NULL; salmsg.message_id=message_id; - salmsg.time=date!=NULL ? mktime(&ret) : time(NULL); + salmsg.time=date!=NULL ? mktime_utc(&ret) : time(NULL); sal->callbacks.text_received(op,&salmsg); sal_op_release(op); osip_free(from); -- 2.39.2