From 975449945e83ffa5365401cc48fffe9722c1a4d5 Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Wed, 2 Jul 2008 10:11:07 -0300 Subject: [PATCH] obexd: Extract time from header --- obexd/src/obex.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ obexd/src/obex.h | 1 + 2 files changed, 52 insertions(+) diff --git a/obexd/src/obex.c b/obexd/src/obex.c index 897aba90e..f83133798 100644 --- a/obexd/src/obex.c +++ b/obexd/src/obex.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -116,6 +117,53 @@ static void obex_session_free(struct obex_session *os) g_free(os); } +/* From Imendio's GnomeVFS OBEX module (om-utils.c) */ +static time_t parse_iso8610(const gchar *val, int size) +{ + time_t time, tz_offset = 0; + struct tm tm; + gchar *date; + gchar tz; + int nr; + + memset(&tm, 0, sizeof(tm)); + /* According to spec the time doesn't have to be null terminated */ + date = g_strndup(val, size); + nr = sscanf(date, "%04u%02u%02uT%02u%02u%02u%c", + &tm.tm_year, &tm.tm_mon, &tm.tm_mday, + &tm.tm_hour, &tm.tm_min, &tm.tm_sec, + &tz); + g_free(date); + if (nr < 6) { + /* Invalid time format */ + return -1; + } + + tm.tm_year -= 1900; /* Year since 1900 */ + tm.tm_mon--; /* Months since January, values 0-11 */ + tm.tm_isdst = -1; /* Daylight savings information not avail */ + +#if defined(HAVE_TM_GMTOFF) + tz_offset = tm.tm_gmtoff; +#elif defined(HAVE_TIMEZONE) + tz_offset = -timezone; + if (tm.tm_isdst > 0) + tz_offset += 3600; +#endif + + time = mktime(&tm); + if (nr == 7) { + /* + * Date/Time was in localtime (to remote device) + * already. Since we don't know anything about the + * timezone on that one we won't try to apply UTC offset + */ + time += tz_offset; + } + + return time; +} + static void cmd_connect(struct obex_session *os, obex_t *obex, obex_object_t *obj) { @@ -524,6 +572,9 @@ static gboolean check_put(obex_t *obex, obex_object_t *obj) os->size = hd.bq4; debug("OBEX_HDR_LENGTH: %d", os->size); break; + case OBEX_HDR_TIME: + os->time = parse_iso8610((const gchar *) hd.bs, hlen); + break; } } diff --git a/obexd/src/obex.h b/obexd/src/obex.h index bd8868ff2..c7dc93f70 100644 --- a/obexd/src/obex.h +++ b/obexd/src/obex.h @@ -51,6 +51,7 @@ struct obex_session { guint16 rx_mtu; gchar *name; gchar *type; + time_t time; gchar *current_folder; guint8 *buf; gint32 offset; -- 2.47.3