summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--telepathy-logger/dbus-service.c7
-rw-r--r--telepathy-logger/log-manager-internal.h2
-rw-r--r--telepathy-logger/log-manager.c33
-rw-r--r--telepathy-logger/log-manager.h4
-rw-r--r--telepathy-logger/log-store-internal.h4
-rw-r--r--telepathy-logger/log-store-xml.c64
-rw-r--r--telepathy-logger/log-store.c10
-rw-r--r--tests/test-searches.c7
8 files changed, 87 insertions, 44 deletions
diff --git a/telepathy-logger/dbus-service.c b/telepathy-logger/dbus-service.c
index 20ab2a6..d0b79cd 100644
--- a/telepathy-logger/dbus-service.c
+++ b/telepathy-logger/dbus-service.c
@@ -438,9 +438,10 @@ _lookup_next_date (RecentMessagesContext *ctx)
if (ctx->ptr != NULL && ctx->lines > 0)
{
- char *date = ctx->ptr->data;
+ GDate *date = ctx->ptr->data;
- DEBUG ("Looking up date %s", date);
+ DEBUG ("Looking up date %u/%u/%u", g_date_get_day (date),
+ g_date_get_month (date), g_date_get_year (date));
tpl_log_manager_get_messages_for_date_async (priv->manager,
ctx->account, ctx->identifier, ctx->is_chatroom, date,
@@ -453,7 +454,7 @@ _lookup_next_date (RecentMessagesContext *ctx)
/* return and release */
DEBUG ("complete, returning");
- g_list_foreach (ctx->dates, (GFunc) g_free, NULL);
+ g_list_foreach (ctx->dates, (GFunc) g_date_free, NULL);
g_list_free (ctx->dates);
tpl_svc_logger_return_from_get_recent_messages (ctx->context,
diff --git a/telepathy-logger/log-manager-internal.h b/telepathy-logger/log-manager-internal.h
index 7c981c0..9ff1258 100644
--- a/telepathy-logger/log-manager-internal.h
+++ b/telepathy-logger/log-manager-internal.h
@@ -50,7 +50,7 @@ GList * _tpl_log_manager_get_messages_for_date (TplLogManager *manager,
TpAccount *account,
const gchar *chat_id,
gboolean chatroom,
- const gchar *date);
+ GDate *date);
GList * _tpl_log_manager_get_filtered_messages (TplLogManager *manager,
TpAccount *account,
diff --git a/telepathy-logger/log-manager.c b/telepathy-logger/log-manager.c
index 9978022..ad1046d 100644
--- a/telepathy-logger/log-manager.c
+++ b/telepathy-logger/log-manager.c
@@ -62,7 +62,7 @@ typedef struct
TpAccount *account;
gchar *chat_id;
gboolean is_chatroom;
- gchar *date;
+ GDate *date;
guint num_messages;
TplLogMessageFilter filter;
gchar *search_text;
@@ -370,7 +370,7 @@ tpl_log_manager_exists (TplLogManager *manager,
* @chat_id: a non-NULL chat identifier
* @chatroom: whather if the request is related to a chatroom or not.
*
- * Retrieves a list of dates, in string form YYYYMMDD, corrisponding to each day
+ * Retrieves a list of #GDate corresponding to each day
* at least a message was sent to or received from @chat_id.
* @chat_id may be the id of a buddy or a chatroom, depending on the value of
* @chatroom.
@@ -378,8 +378,8 @@ tpl_log_manager_exists (TplLogManager *manager,
* It applies for any registered TplLogStore with the #TplLogStore:readable
* property %TRUE.
*
- * Returns: a GList of (char *), to be freed using something like
- * g_list_foreach (lst, g_free, NULL);
+ * Returns: a GList of (GDate *), to be freed using something like
+ * g_list_foreach (lst, g_data_free, NULL);
* g_list_free (lst);
*/
GList *
@@ -406,11 +406,13 @@ _tpl_log_manager_get_dates (TplLogManager *manager,
new = tpl_log_store_get_dates (store, account, chat_id, chatroom);
while (new)
{
- if (g_list_find_custom (out, new->data, (GCompareFunc) strcmp))
- g_free (new->data);
+ if (g_list_find_custom (out, new->data,
+ (GCompareFunc) g_date_compare))
+ g_date_free (new->data);
else
out =
- g_list_insert_sorted (out, new->data, (GCompareFunc) strcmp);
+ g_list_insert_sorted (out, new->data,
+ (GCompareFunc) g_date_compare);
new = g_list_delete_link (new, new);
}
@@ -425,7 +427,7 @@ _tpl_log_manager_get_messages_for_date (TplLogManager *manager,
TpAccount *account,
const gchar *chat_id,
gboolean chatroom,
- const gchar *date)
+ GDate *date)
{
GList *l, *out = NULL;
TplLogManagerPriv *priv;
@@ -687,7 +689,9 @@ _tpl_log_manager_search_hit_free (TplLogSearchHit *hit)
if (hit->account != NULL)
g_object_unref (hit->account);
- g_free (hit->date);
+ if (hit->date != NULL)
+ g_date_free (hit->date);
+
g_free (hit->filename);
g_free (hit->chat_id);
@@ -754,7 +758,7 @@ tpl_log_manager_chat_info_free (TplLogManagerChatInfo *data)
if (data->chat_id != NULL)
g_free (data->chat_id);
if (data->date != NULL)
- g_free (data->date);
+ g_date_free (data->date);
g_slice_free (TplLogManagerChatInfo, data);
}
@@ -1018,7 +1022,7 @@ tpl_log_manager_get_messages_for_date_async (TplLogManager *manager,
TpAccount *account,
const gchar *chat_id,
gboolean is_chatroom,
- const gchar *date,
+ GDate *date,
GAsyncReadyCallback callback,
gpointer user_data)
{
@@ -1038,15 +1042,16 @@ tpl_log_manager_get_messages_for_date_async (TplLogManager *manager,
TPL_LOG_MANAGER, FAILED,
"chat_id argument passed cannot be empty string or NULL ptr",
callback, user_data);
- tpl_call_with_err_if_fail (!TPL_STR_EMPTY (date), manager,
+ tpl_call_with_err_if_fail (date != NULL, manager,
TPL_LOG_MANAGER, FAILED,
- "date argument passed cannot be empty string or NULL ptr",
+ "date argument passed cannot be NULL ptr",
callback, user_data);
chat_info->account = g_object_ref (account);
chat_info->chat_id = g_strdup (chat_id);
chat_info->is_chatroom = is_chatroom;
- chat_info->date = g_strdup (date);
+ /* There is no g_date_copy() */
+ chat_info->date = g_date_new_julian (g_date_get_julian (date));
async_data->manager = g_object_ref (manager);
async_data->request = chat_info;
diff --git a/telepathy-logger/log-manager.h b/telepathy-logger/log-manager.h
index a9529a5..dff2ed3 100644
--- a/telepathy-logger/log-manager.h
+++ b/telepathy-logger/log-manager.h
@@ -67,7 +67,7 @@ typedef struct
gchar *chat_id;
gboolean is_chatroom;
gchar *filename;
- gchar *date;
+ GDate *date;
} TplLogSearchHit;
typedef gboolean (*TplLogMessageFilter) (TplLogEntry *message,
@@ -96,7 +96,7 @@ gboolean tpl_log_manager_get_messages_for_date_finish (TplLogManager *self,
void tpl_log_manager_get_messages_for_date_async (TplLogManager *manager,
TpAccount *account, const gchar *chat_id, gboolean is_chatroom,
- const gchar *date, GAsyncReadyCallback callback, gpointer user_data);
+ GDate *date, GAsyncReadyCallback callback, gpointer user_data);
gboolean tpl_log_manager_get_filtered_messages_finish (TplLogManager *self,
GAsyncResult *result,
diff --git a/telepathy-logger/log-store-internal.h b/telepathy-logger/log-store-internal.h
index 37fe544..679ba32 100644
--- a/telepathy-logger/log-store-internal.h
+++ b/telepathy-logger/log-store-internal.h
@@ -70,7 +70,7 @@ typedef struct
GList * (*get_dates) (TplLogStore *self, TpAccount *account,
const gchar *chat_id, gboolean chatroom);
GList * (*get_messages_for_date) (TplLogStore *self, TpAccount *account,
- const gchar *chat_id, gboolean chatroom, const gchar *date);
+ const gchar *chat_id, gboolean chatroom, GDate *date);
GList * (*get_recent_messages) (TplLogStore *self, TpAccount *account,
const gchar *chat_id, gboolean chatroom);
GList * (*get_chats) (TplLogStore *self, TpAccount *account);
@@ -93,7 +93,7 @@ GList *tpl_log_store_get_dates (TplLogStore *self, TpAccount *account,
const gchar *chat_id, gboolean chatroom);
GList *tpl_log_store_get_messages_for_date (TplLogStore *self,
TpAccount *account, const gchar *chat_id, gboolean chatroom,
- const gchar *date);
+ GDate *date);
GList *tpl_log_store_get_recent_messages (TplLogStore *self,
TpAccount *account, const gchar *chat_id, gboolean chatroom);
GList *tpl_log_store_get_chats (TplLogStore *self, TpAccount *account);
diff --git a/telepathy-logger/log-store-xml.c b/telepathy-logger/log-store-xml.c
index f26c809..ce1e8cd 100644
--- a/telepathy-logger/log-store-xml.c
+++ b/telepathy-logger/log-store-xml.c
@@ -23,12 +23,15 @@
* Cosimo Alfarano <cosimo.alfarano@collabora.co.uk>
*/
+#define _XOPEN_SOURCE /* glibc2 needs this for strptime */
+
#include "config.h"
#include "log-store-xml-internal.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
+#include <time.h>
#include <glib/gstdio.h>
#include <glib-object.h>
@@ -595,6 +598,29 @@ log_store_xml_exists (TplLogStore *store,
return exists;
}
+static GDate *
+create_date_from_string (const gchar *str)
+{
+ GDate *date;
+ struct tm tm;
+ time_t t;
+ gchar *tmp;
+
+ memset (&tm, 0, sizeof (struct tm));
+
+ tmp = strptime (str, "%Y%m%d", &tm);
+ if (tmp == NULL || tmp[0] != '\0')
+ return NULL;
+
+ t = mktime (&tm);
+ if (t == -1)
+ return NULL;
+
+ date = g_date_new ();
+ g_date_set_time_t (date, t);
+
+ return date;
+}
static GList *
log_store_xml_get_dates (TplLogStore *store,
@@ -604,7 +630,6 @@ log_store_xml_get_dates (TplLogStore *store,
{
TplLogStoreXml *self = (TplLogStoreXml *) store;
GList *dates = NULL;
- gchar *date;
gchar *directory;
GDir *dir;
const gchar *filename;
@@ -627,19 +652,23 @@ log_store_xml_get_dates (TplLogStore *store,
while ((filename = g_dir_read_name (dir)) != NULL)
{
+ gchar *str;
+ GDate *date;
+
if (!g_str_has_suffix (filename, LOG_FILENAME_SUFFIX))
continue;
p = strstr (filename, LOG_FILENAME_SUFFIX);
- date = g_strndup (filename, p - filename);
+ str = g_strndup (filename, p - filename);
- if (!date)
+ if (str == NULL)
continue;
- if (!g_regex_match_simple ("\\d{8}", date, 0, 0))
- continue;
+ date = create_date_from_string (str);
+ if (date != NULL)
+ dates = g_list_insert_sorted (dates, date, (GCompareFunc) strcmp);
- dates = g_list_insert_sorted (dates, date, (GCompareFunc) strcmp);
+ g_free (str);
}
g_free (directory);
@@ -656,19 +685,22 @@ log_store_xml_get_filename_for_date (TplLogStoreXml *self,
TpAccount *account,
const gchar *chat_id,
gboolean chatroom,
- const gchar *date)
+ GDate *date)
{
gchar *basedir;
gchar *timestamp;
gchar *filename;
+ gchar str[9];
g_return_val_if_fail (TPL_IS_LOG_STORE_XML (self), NULL);
g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL);
g_return_val_if_fail (!TPL_STR_EMPTY (chat_id), NULL);
- g_return_val_if_fail (!TPL_STR_EMPTY (date), NULL);
+ g_return_val_if_fail (date != NULL, NULL);
+
+ g_date_strftime (str, 9, "%Y%m%d", date);
basedir = log_store_xml_get_dir (self, account, chat_id, chatroom);
- timestamp = g_strconcat (date, LOG_FILENAME_SUFFIX, NULL);
+ timestamp = g_strconcat (str, LOG_FILENAME_SUFFIX, NULL);
filename = g_build_filename (basedir, timestamp, NULL);
g_free (basedir);
@@ -688,6 +720,7 @@ log_store_xml_search_hit_new (TplLogStoreXml *self,
gchar **strv;
guint len;
GList *accounts, *l;
+ gchar *tmp;
g_return_val_if_fail (TPL_IS_LOG_STORE_XML (self), NULL);
g_return_val_if_fail (!TPL_STR_EMPTY (filename), NULL);
@@ -700,7 +733,9 @@ log_store_xml_search_hit_new (TplLogStoreXml *self,
hit = g_slice_new0 (TplLogSearchHit);
end = strstr (strv[len - 1], LOG_FILENAME_SUFFIX);
- hit->date = g_strndup (strv[len - 1], end - strv[len - 1]);
+ tmp = g_strndup (strv[len - 1], end - strv[len - 1]);
+ hit->date = create_date_from_string (tmp);
+ g_free (tmp);
hit->chat_id = g_strdup (strv[len - 2]);
hit->is_chatroom = (strcmp (strv[len - 3], LOG_DIR_CHATROOMS) == 0);
@@ -972,8 +1007,9 @@ _log_store_xml_search_in_files (TplLogStoreXml *self,
if (hit != NULL)
{
hits = g_list_prepend (hits, hit);
- DEBUG ("Found text:'%s' in file:'%s' on date:'%s'", text,
- hit->filename, hit->date);
+ DEBUG ("Found text:'%s' in file:'%s' on date:'%u/%u/%u'", text,
+ hit->filename, g_date_get_day (hit->date),
+ g_date_get_month (hit->date), g_date_get_year (hit->date));
}
}
@@ -1088,7 +1124,7 @@ log_store_xml_get_messages_for_date (TplLogStore *store,
TpAccount *account,
const gchar *chat_id,
gboolean chatroom,
- const gchar *date)
+ GDate *date)
{
TplLogStoreXml *self = (TplLogStoreXml *) store;
gchar *filename;
@@ -1097,7 +1133,7 @@ log_store_xml_get_messages_for_date (TplLogStore *store,
g_return_val_if_fail (TPL_IS_LOG_STORE_XML (self), NULL);
g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL);
g_return_val_if_fail (!TPL_STR_EMPTY (chat_id), NULL);
- g_return_val_if_fail (!TPL_STR_EMPTY (date), NULL);
+ g_return_val_if_fail (date != NULL, NULL);
filename = log_store_xml_get_filename_for_date (self, account, chat_id,
chatroom, date);
diff --git a/telepathy-logger/log-store.c b/telepathy-logger/log-store.c
index edb710e..dc90b9f 100644
--- a/telepathy-logger/log-store.c
+++ b/telepathy-logger/log-store.c
@@ -172,13 +172,13 @@ tpl_log_store_add_message (TplLogStore *self,
* @chat_id: a non-NULL chat identifier
* @chatroom: whather if the request is related to a chatroom or not.
*
- * Retrieves a list of dates, in string form YYYYMMDD, corrisponding to each day
+ * Retrieves a list of #GDate, corresponding to each day
* at least a message was sent to or received from @chat_id.
* @chat_id may be the id of a buddy or a chatroom, depending on the value of
* @chatroom.
*
- * Returns: a GList of (char *), to be freed using something like
- * g_list_foreach (lst, g_free, NULL);
+ * Returns: a GList of (GDate *), to be freed using something like
+ * g_list_foreach (lst, g_date_free, NULL);
* g_list_free (lst);
*/
GList *
@@ -202,7 +202,7 @@ tpl_log_store_get_dates (TplLogStore *self,
* @account: a TpAccount
* @chat_id: a non-NULL chat identifier
* @chatroom: whather if the request is related to a chatroom or not.
- * @date: a date, in YYYYMMDD string form
+ * @date: a #GDate
*
* Retrieves a list of text messages, with timestamp matching @date.
*
@@ -215,7 +215,7 @@ tpl_log_store_get_messages_for_date (TplLogStore *self,
TpAccount *account,
const gchar *chat_id,
gboolean chatroom,
- const gchar *date)
+ GDate *date)
{
g_return_val_if_fail (TPL_IS_LOG_STORE (self), NULL);
if (TPL_LOG_STORE_GET_INTERFACE (self)->get_messages_for_date == NULL)
diff --git a/tests/test-searches.c b/tests/test-searches.c
index a0c4a13..d524ba6 100644
--- a/tests/test-searches.c
+++ b/tests/test-searches.c
@@ -2,6 +2,7 @@
#include <glib.h>
+#include <telepathy-logger/debug-internal.h>
#include <telepathy-logger/log-manager.h>
#include <telepathy-logger/log-manager-internal.h>
#include <telepathy-logger/log-store-internal.h>
@@ -22,9 +23,9 @@ got_dates_cb (GObject *obj, GAsyncResult *result, gpointer user_data)
for (; ret != NULL; ret = g_list_next (ret))
{
- gchar *date = ret->data;
+ GDate *date = ret->data;
/* g_assert (!tp_strdiff (date, "12345678")); */
- g_free (date);
+ g_date_free (date);
}
g_list_free (ret);
g_main_loop_quit (loop);
@@ -67,7 +68,7 @@ main (int argc, char *argv[])
ret = g_list_sort (ret, (GCompareFunc) g_strcmp0);
for (loc = ret; loc; loc = g_list_next (loc))
if (loc->next)
- g_assert (g_strcmp0 (loc->data, loc->next->data) != 0);
+ g_assert (g_date_compare (loc->data, loc->next->data) != 0);
g_list_foreach (ret, (GFunc) g_free, NULL);
g_list_free (ret);