summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Dufresne <nicolas.dufresne@collabora.co.uk>2011-03-07 21:42:54 -0500
committerNicolas Dufresne <nicolas.dufresne@collabora.co.uk>2011-03-07 21:43:01 -0500
commit1c8dc3eaab53acc935f965aed51d4a4f4f0c991c (patch)
tree11f220969b92580aed7f24352b9f2c365124c506
parent7f725d638c36dc9e77ee7d81f03025968d848a8a (diff)
parent7dbbb62b3b748ce84033630549a50fe8c01b5e17 (diff)
Merge branch 'date-time'
Reviewed-by: Danielle Madeley <danielle.madeley@collabora.co.uk>
-rw-r--r--doc/reference/libtelepathy-logger/Makefile.am1
-rw-r--r--telepathy-logger/Makefile.am2
-rw-r--r--telepathy-logger/datetime-internal.h42
-rw-r--r--telepathy-logger/datetime.c127
-rw-r--r--telepathy-logger/log-manager.c1
-rw-r--r--telepathy-logger/log-store-pidgin.c1
-rw-r--r--telepathy-logger/log-store-sqlite-internal.h2
-rw-r--r--telepathy-logger/log-store-sqlite.c52
-rw-r--r--telepathy-logger/log-store-xml.c19
-rw-r--r--telepathy-logger/text-channel.c8
-rw-r--r--telepathy-logger/util-internal.h6
-rw-r--r--telepathy-logger/util.c48
12 files changed, 100 insertions, 209 deletions
diff --git a/doc/reference/libtelepathy-logger/Makefile.am b/doc/reference/libtelepathy-logger/Makefile.am
index c235d1f48..8a0062345 100644
--- a/doc/reference/libtelepathy-logger/Makefile.am
+++ b/doc/reference/libtelepathy-logger/Makefile.am
@@ -61,7 +61,6 @@ IGNORE_HFILES=\
channel-internal.h \
conf-internal.h \
contact-internal.h \
- datetime-internal.h \
dbus-service-internal.h \
debug-internal.h \
event-internal.h \
diff --git a/telepathy-logger/Makefile.am b/telepathy-logger/Makefile.am
index 7431e9213..9941f7bbe 100644
--- a/telepathy-logger/Makefile.am
+++ b/telepathy-logger/Makefile.am
@@ -52,8 +52,6 @@ libtelepathy_logger_la_SOURCES = \
conf-internal.h \
entity.c \
entity-internal.h \
- datetime.c \
- datetime-internal.h \
dbus-service.c \
dbus-service-internal.h \
debug-internal.h \
diff --git a/telepathy-logger/datetime-internal.h b/telepathy-logger/datetime-internal.h
deleted file mode 100644
index 34d292812..000000000
--- a/telepathy-logger/datetime-internal.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * Copyright (C) 2004 Imendio AB
- * Copyright (C) 2007-2010 Collabora Ltd.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Authors: Richard Hult <richard@imendio.com>
- */
-
-#ifndef __TPL_TIME_H__
-#define __TPL_TIME_H__
-
-#ifndef __USE_XOPEN
-#define __USE_XOPEN
-#endif
-#include <time.h>
-
-#include <glib.h>
-
-G_BEGIN_DECLS
-#define _TPL_TIME_FORMAT_DISPLAY_SHORT "%H:%M"
-#define _TPL_TIME_FORMAT_DISPLAY_LONG "%a %d %b %Y"
-time_t _tpl_time_get_current (void);
-time_t _tpl_time_parse (const gchar * str);
-gchar *_tpl_time_to_string_utc (time_t t, const gchar * format);
-gchar *_tpl_time_to_string_local (time_t t, const gchar * format);
-
-G_END_DECLS
-#endif /* __TPL_TIME_H__ */
diff --git a/telepathy-logger/datetime.c b/telepathy-logger/datetime.c
deleted file mode 100644
index dde31e15d..000000000
--- a/telepathy-logger/datetime.c
+++ /dev/null
@@ -1,127 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/*
- * Copyright (C) 2003-2007 Imendio AB
- * Copyright (C) 2007-2010 Collabora Ltd.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Authors: Richard Hult <richard@imendio.com>
- */
-
-#include "config.h"
-#include "datetime-internal.h"
-
-#include <glib/gi18n.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-
-
-/* Note: time is always in UTC. */
-
-time_t
-_tpl_time_get_current (void)
-{
- return time (NULL);
-}
-
-static time_t
-_tpl_time_get_local_time (struct tm *tm)
-{
- const gchar *tz;
- time_t t;
-
- tz = g_getenv ("TZ");
- g_setenv ("TZ", "", TRUE);
-
- tzset ();
-
- t = mktime (tm);
-
- if (tz != NULL)
- g_setenv ("TZ", tz, TRUE);
- else
- g_unsetenv ("TZ");
-
- tzset ();
-
- return t;
-}
-
-/* The format is: "20021209T23:51:30" and is in UTC. 0 is returned on
- * failure. The alternative format "20021209" is also accepted.
- */
-time_t
-_tpl_time_parse (const gchar *str)
-{
- struct tm tm;
- gint year, month;
- gint n_parsed;
-
- memset (&tm, 0, sizeof (struct tm));
-
- n_parsed = sscanf (str, "%4d%2d%2dT%2d:%2d:%2d",
- &year, &month, &tm.tm_mday, &tm.tm_hour,
- &tm.tm_min, &tm.tm_sec);
- if (n_parsed != 3 && n_parsed != 6)
- {
- return 0;
- }
-
- tm.tm_year = year - 1900;
- tm.tm_mon = month - 1;
- tm.tm_isdst = -1;
-
- return _tpl_time_get_local_time (&tm);
-}
-
-/* Converts the UTC timestamp to a string, also in UTC. Returns NULL on failure. */
-gchar *
-_tpl_time_to_string_utc (time_t t,
- const gchar * format)
-{
- gchar stamp[128];
- struct tm *tm;
-
- g_return_val_if_fail (format != NULL, NULL);
-
- tm = gmtime (&t);
- if (strftime (stamp, sizeof (stamp), format, tm) == 0)
- {
- return NULL;
- }
-
- return g_strdup (stamp);
-}
-
-/* Converts the UTC timestamp to a string, in local time. Returns NULL on failure. */
-gchar *
-_tpl_time_to_string_local (time_t t,
- const gchar *format)
-{
- gchar stamp[128];
- struct tm *tm;
-
- g_return_val_if_fail (format != NULL, NULL);
-
- tm = localtime (&t);
- if (strftime (stamp, sizeof (stamp), format, tm) == 0)
- {
- return NULL;
- }
-
- return g_strdup (stamp);
-}
diff --git a/telepathy-logger/log-manager.c b/telepathy-logger/log-manager.c
index a69a4f900..00229c420 100644
--- a/telepathy-logger/log-manager.c
+++ b/telepathy-logger/log-manager.c
@@ -43,7 +43,6 @@
#include <telepathy-logger/log-store-sqlite-internal.h>
#define DEBUG_FLAG TPL_DEBUG_LOG_MANAGER
-#include <telepathy-logger/datetime-internal.h>
#include <telepathy-logger/debug-internal.h>
#include <telepathy-logger/util-internal.h>
diff --git a/telepathy-logger/log-store-pidgin.c b/telepathy-logger/log-store-pidgin.c
index 766f724dc..b40a21415 100644
--- a/telepathy-logger/log-store-pidgin.c
+++ b/telepathy-logger/log-store-pidgin.c
@@ -35,7 +35,6 @@
#include "log-manager-internal.h"
#include "text-event-internal.h"
#include "entity-internal.h"
-#include "datetime-internal.h"
#include "util-internal.h"
#define DEBUG_FLAG TPL_DEBUG_LOG_STORE
diff --git a/telepathy-logger/log-store-sqlite-internal.h b/telepathy-logger/log-store-sqlite-internal.h
index d44d9712b..aa978fa2c 100644
--- a/telepathy-logger/log-store-sqlite-internal.h
+++ b/telepathy-logger/log-store-sqlite-internal.h
@@ -79,7 +79,7 @@ TplLogStore * _tpl_log_store_sqlite_dup (void);
GList * _tpl_log_store_sqlite_get_pending_messages (TplLogStore *self,
TpChannel *channel, GError **error);
GList * _tpl_log_store_sqlite_get_log_ids (TplLogStore *self,
- TpChannel *channel, time_t timestamp, GError **error);
+ TpChannel *channel, gint64 timestamp, GError **error);
gboolean _tpl_log_store_sqlite_log_id_is_present (TplLogStore *self,
const gchar* log_id);
diff --git a/telepathy-logger/log-store-sqlite.c b/telepathy-logger/log-store-sqlite.c
index 90668ea48..7c17effcc 100644
--- a/telepathy-logger/log-store-sqlite.c
+++ b/telepathy-logger/log-store-sqlite.c
@@ -34,7 +34,6 @@
#include "log-manager-internal.h"
#define DEBUG_FLAG TPL_DEBUG_LOG_STORE
-#include "datetime-internal.h"
#include "debug-internal.h"
#include "util-internal.h"
@@ -47,7 +46,7 @@
static void log_store_iface_init (TplLogStoreInterface *iface);
static gboolean _insert_to_cache_table (TplLogStore *self,
TplEvent *message, GError **error);
-static void tpl_log_store_sqlite_purge (TplLogStoreSqlite *self, time_t delta,
+static void tpl_log_store_sqlite_purge (TplLogStoreSqlite *self, GTimeSpan delta,
GError **error);
static gboolean purge_event_timeout (gpointer logstore);
@@ -298,21 +297,30 @@ get_channel_name_from_event (TplEvent *event)
static char *
get_date (TplEvent *event)
{
- time_t t;
+ GDateTime *ts;
+ gchar *date;
+
+ ts = g_date_time_new_from_unix_utc (tpl_event_get_timestamp (event));
+ date = g_date_time_format (ts, "%Y-%m-%d");
- t = tpl_event_get_timestamp (event);
+ g_date_time_unref (ts);
- return _tpl_time_to_string_utc (t, "%Y-%m-%d");
+
+ return date;
}
static char *
get_datetime (TplEvent *event)
{
- time_t t;
+ GDateTime *ts;
+ gchar *date;
+
+ ts = g_date_time_new_from_unix_utc (tpl_event_get_timestamp (event));
+ date = g_date_time_format (ts, TPL_LOG_STORE_SQLITE_TIMESTAMP_FORMAT);
- t = tpl_event_get_timestamp (event);
+ g_date_time_unref (ts);
- return _tpl_time_to_string_utc (t, TPL_LOG_STORE_SQLITE_TIMESTAMP_FORMAT);
+ return date;
}
static const char *
@@ -799,10 +807,10 @@ out:
* If @channel is %NULL, it will get all the existing log-ids.
*
* All the entries will be filtered against @timestamp, returning only log-ids
- * older than this value (time_t). Set it to %G_MAXUINT or any other value in
+ * older than this value (gint64). Set it to %G_MAXINT64 or any other value in
* the future to obtain all the entries.
* For example, to obtain entries older than one day ago, use
- * @timestamp = (#_tpl_time_get_current()-86400)
+ * @timestamp = (now - 86400)
*
* Note that (in case @channel is not %NULL) this method might return log-ids
* which are not currently related to @channel but just share the object-path,
@@ -819,13 +827,14 @@ out:
GList *
_tpl_log_store_sqlite_get_log_ids (TplLogStore *self,
TpChannel *channel,
- time_t timestamp,
+ gint64 unix_timestamp,
GError **error)
{
TplLogStoreSqlitePrivate *priv = GET_PRIV (self);
sqlite3_stmt *sql = NULL;
GList *retval = NULL;
- gchar *date = NULL;
+ GDateTime *timestamp;
+ gchar *date;
int e;
g_return_val_if_fail (TPL_IS_LOG_STORE_SQLITE (self), NULL);
@@ -849,10 +858,14 @@ _tpl_log_store_sqlite_get_log_ids (TplLogStore *self,
goto out;
}
- date = _tpl_time_to_string_utc (timestamp,
+ timestamp = g_date_time_new_from_unix_utc (unix_timestamp);
+ date = g_date_time_format (timestamp,
TPL_LOG_STORE_SQLITE_TIMESTAMP_FORMAT);
sqlite3_bind_text (sql, 1, date, -1, SQLITE_TRANSIENT);
+ g_date_time_unref (timestamp);
+ g_free (date);
+
if (channel != NULL)
sqlite3_bind_text (sql, 2, get_channel_name (channel), -1,
SQLITE_TRANSIENT);
@@ -877,7 +890,6 @@ _tpl_log_store_sqlite_get_log_ids (TplLogStore *self,
out:
if (sql != NULL)
sqlite3_finalize (sql);
- g_free (date);
/* check that we set an error if appropriate
* NOTE: retval == NULL && *error !=
@@ -1059,20 +1071,28 @@ out:
static void
tpl_log_store_sqlite_purge (TplLogStoreSqlite *self,
- time_t delta,
+ GTimeSpan delta,
GError **error)
{
TplLogStoreSqlitePrivate *priv = GET_PRIV (self);
sqlite3_stmt *sql = NULL;
+ GDateTime *now;
+ GDateTime *timestamp;
gchar *date;
int e;
g_return_if_fail (error == NULL || *error == NULL);
g_return_if_fail (TPL_IS_LOG_STORE_SQLITE (self));
- date = _tpl_time_to_string_utc ((_tpl_time_get_current () - delta),
+ now = g_date_time_new_now_utc ();
+ timestamp = g_date_time_add (now, -delta);
+
+ date = g_date_time_format (timestamp,
TPL_LOG_STORE_SQLITE_TIMESTAMP_FORMAT);
+ g_date_time_unref (now);
+ g_date_time_unref (timestamp);
+
DEBUG ("Purging entries older than %s (%u seconds ago)", date, (guint) delta);
e = sqlite3_prepare_v2 (priv->db, "DELETE FROM message_cache "
diff --git a/telepathy-logger/log-store-xml.c b/telepathy-logger/log-store-xml.c
index c5fe56693..7486e9041 100644
--- a/telepathy-logger/log-store-xml.c
+++ b/telepathy-logger/log-store-xml.c
@@ -49,7 +49,6 @@
#define DEBUG_FLAG TPL_DEBUG_LOG_STORE
#include <telepathy-logger/entity-internal.h>
-#include <telepathy-logger/datetime-internal.h>
#include <telepathy-logger/debug-internal.h>
#include <telepathy-logger/util-internal.h>
@@ -340,14 +339,15 @@ log_store_xml_get_dir (TplLogStoreXml *self,
static gchar *
log_store_xml_get_timestamp_filename (void)
{
- time_t t;
gchar *time_str;
gchar *filename;
+ GDateTime *now;
- t = _tpl_time_get_current ();
- time_str = _tpl_time_to_string_local (t, LOG_TIME_FORMAT);
+ now = g_date_time_new_now_local ();
+ time_str = g_date_time_format (now, LOG_TIME_FORMAT);
filename = g_strconcat (time_str, LOG_FILENAME_SUFFIX, NULL);
+ g_date_time_unref (now);
g_free (time_str);
return filename;
@@ -357,12 +357,15 @@ log_store_xml_get_timestamp_filename (void)
static gchar *
log_store_xml_get_timestamp_from_event (TplEvent *event)
{
- time_t t;
+ GDateTime *ts;
+ gchar *ts_str;
- t = tpl_event_get_timestamp (event);
+ ts = g_date_time_new_from_unix_utc (tpl_event_get_timestamp (event));
+ ts_str = g_date_time_format (ts, LOG_TIME_FORMAT_FULL);
- /* We keep the timestamps in the events as UTC */
- return _tpl_time_to_string_utc (t, LOG_TIME_FORMAT_FULL);
+ g_date_time_unref (ts);
+
+ return ts_str;
}
diff --git a/telepathy-logger/text-channel.c b/telepathy-logger/text-channel.c
index 67b9a5b38..0c02562fa 100644
--- a/telepathy-logger/text-channel.c
+++ b/telepathy-logger/text-channel.c
@@ -38,7 +38,6 @@
#define DEBUG_FLAG TPL_DEBUG_CHANNEL
#include <telepathy-logger/action-chain-internal.h>
#include <telepathy-logger/entity-internal.h>
-#include <telepathy-logger/datetime-internal.h>
#include <telepathy-logger/debug-internal.h>
#include <telepathy-logger/util-internal.h>
@@ -712,7 +711,7 @@ got_message_pending_messages_cb (TpProxy *proxy,
GList *l;
const gchar *message_token;
gchar *tpl_message_token;
- guint64 message_timestamp;
+ gint64 message_timestamp;
guint message_type = TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL;
guint message_flags = 0;
guint message_id;
@@ -738,7 +737,7 @@ got_message_pending_messages_cb (TpProxy *proxy,
"UNKNOWN");
message_id = TPL_TEXT_EVENT_MSG_ID_UNKNOWN;
}
- message_timestamp = tp_asv_get_uint64 (message_headers,
+ message_timestamp = tp_asv_get_int64 (message_headers,
"message-received", NULL);
tpl_message_token = _tpl_create_message_token (channel_path,
@@ -771,8 +770,9 @@ got_message_pending_messages_cb (TpProxy *proxy,
if (l == NULL)
{
/* call the received signal callback to trigger the message storing */
+ /* FIXME Avoid converting gint64 timestamp into guint timestamp */
on_received_signal_cb (TP_CHANNEL (proxy),
- message_id, message_timestamp, message_sender_handle,
+ message_id, (guint) message_timestamp, message_sender_handle,
message_type, message_flags, message_body,
NULL, NULL);
}
diff --git a/telepathy-logger/util-internal.h b/telepathy-logger/util-internal.h
index e5d75cf41..3c7982eb4 100644
--- a/telepathy-logger/util-internal.h
+++ b/telepathy-logger/util-internal.h
@@ -1,6 +1,7 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
- * Copyright (C) 2009 Collabora Ltd.
+ * Copyright (C) 2009-2011 Collabora Ltd.
+ * Copyright (C) 2003-2007 Imendio AB
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -17,6 +18,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk>
+ * Richard Hult <richard@imendio.com>
*/
#ifndef __TPL_UTIL_H__
@@ -32,5 +34,7 @@ gchar *_tpl_create_message_token (const gchar *channel, gint64 timestamp,
void _tpl_rmdir_recursively (const gchar *dir_name);
+gint64 _tpl_time_parse (const gchar * str);
+
#endif // __TPL_UTIL_H__
diff --git a/telepathy-logger/util.c b/telepathy-logger/util.c
index f7be04488..d242972be 100644
--- a/telepathy-logger/util.c
+++ b/telepathy-logger/util.c
@@ -1,6 +1,7 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
- * Copyright (C) 2009 Collabora Ltd.
+ * Copyright (C) 2009-2011 Collabora Ltd.
+ * Copyright (C) 2003-2007 Imendio AB
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -17,11 +18,11 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk>
+ * Richard Hult <richard@imendio.com>
*/
#include "util-internal.h"
-#include "datetime-internal.h"
#include "log-store-sqlite-internal.h"
#include <errno.h>
@@ -33,14 +34,20 @@
* within itself */
gchar *
_tpl_create_message_token (const gchar *channel,
- gint64 timestamp,
+ gint64 unix_timestamp,
guint msgid)
{
- GChecksum *log_id = g_checksum_new (G_CHECKSUM_SHA1);
gchar *retval;
- gchar *date = _tpl_time_to_string_local (timestamp,
+ gchar *date;
+ GDateTime *timestamp;
+ GChecksum *log_id = g_checksum_new (G_CHECKSUM_SHA1);
+
+ timestamp = g_date_time_new_from_unix_utc (unix_timestamp);
+ date = g_date_time_format (timestamp,
TPL_LOG_STORE_SQLITE_TIMESTAMP_FORMAT);
+ g_date_time_unref (timestamp);
+
g_checksum_update (log_id, (guchar *) channel, -1);
g_checksum_update (log_id, (guchar *) date, -1);
g_checksum_update (log_id, (guchar *) &msgid, sizeof (unsigned int));
@@ -86,3 +93,34 @@ _tpl_rmdir_recursively (const gchar *dir_name)
dir_name, g_strerror (errno));
}
+
+/* The format is: "20021209T23:51:30" and is in UTC. 0 is returned on
+ * failure. The alternative format "20021209" is also accepted.
+ */
+gint64
+_tpl_time_parse (const gchar *str)
+{
+ gint year = 0;
+ gint month = 0;
+ gint day = 0;
+ gint hour = 0;
+ gint min = 0;
+ gint sec = 0;
+ gint n_parsed;
+ GDateTime *dt;
+ gint64 ts;
+
+ n_parsed = sscanf (str, "%4d%2d%2dT%2d:%2d:%2d",
+ &year, &month, &day, &hour,
+ &min, &sec);
+
+ if (n_parsed != 3 && n_parsed != 6)
+ return 0;
+
+ dt = g_date_time_new_utc (year, month, day, hour, min, sec);
+ ts = g_date_time_to_unix (dt);
+
+ g_date_time_unref (dt);
+
+ return ts;
+}