Diff between 10bb8c3e504afb0113fdede1ff27b04dbe166b35 and 975449945e83ffa5365401cc48fffe9722c1a4d5

Changed Files

File Additions Deletions Status
obexd/src/obex.c +51 -0 modified
obexd/src/obex.h +1 -0 modified

Full Patch

diff --git a/obexd/src/obex.c b/obexd/src/obex.c
index 897aba9..f831337 100644
--- a/obexd/src/obex.c
+++ b/obexd/src/obex.c
@@ -31,6 +31,7 @@
 #include <errno.h>
 #include <stdlib.h>
 #include <signal.h>
+#include <time.h>
 #include <string.h>
 #include <unistd.h>
 #include <sys/types.h>
@@ -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 bd8868f..c7dc93f 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;