]> sjero.net Git - linphone/commitdiff
Set UTC time in received chat messages.
authorGhislain MARY <ghislain.mary@belledonne-communications.com>
Fri, 12 Apr 2013 08:26:57 +0000 (10:26 +0200)
committerGhislain MARY <ghislain.mary@belledonne-communications.com>
Fri, 12 Apr 2013 08:26:57 +0000 (10:26 +0200)
coreapi/sal_eXosip2.c

index 1bbbe36e6ed3e67307eb248395ecb8d42555fe61..75ee46298c5ced1d3c102d5cb0121de670f690b0 100644 (file)
@@ -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"};\r
 static const char *months[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};\r
 \r
+static int utc_offset() {\r
+       time_t ref = 24 * 60 * 60L;\r
+       struct tm * timeptr;\r
+       int gmtime_hours;\r
+\r
+       /* get the local reference time for Jan 2, 1900 00:00 UTC */\r
+       timeptr = localtime(&ref);\r
+       gmtime_hours = timeptr->tm_hour;\r
+\r
+       /* if the local time is the "day before" the UTC, subtract 24 hours\r
+       from the hours to get the UTC offset */\r
+       if (timeptr->tm_mday < 2) gmtime_hours -= 24;\r
+\r
+       return gmtime_hours;\r
+}\r
+\r
+time_t mktime_utc(struct tm *timeptr) {\r
+       return mktime(timeptr) + utc_offset() * 3600;\r
+}\r
+\r
 static void text_received(Sal *sal, eXosip_event_t *ev){\r
        osip_body_t *body=NULL;\r
        char *from=NULL,*msg=NULL;\r
@@ -1842,7 +1862,7 @@ static void text_received(Sal *sal, eXosip_event_t *ev){
        salmsg.text=msg;\r
        salmsg.url=external_body_size>0 ? unquoted_external_body_url : NULL;\r
        salmsg.message_id=message_id;\r
-       salmsg.time=date!=NULL ? mktime(&ret) : time(NULL);\r
+       salmsg.time=date!=NULL ? mktime_utc(&ret) : time(NULL);\r
        sal->callbacks.text_received(op,&salmsg);\r
        sal_op_release(op);\r
        osip_free(from);\r