diff options
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | src/Makefile.am | 9 | ||||
-rw-r--r-- | src/config.h (renamed from include/config.h) | 0 | ||||
-rw-r--r-- | src/test.c | 60 | ||||
-rw-r--r-- | src/tpl-channel.h (renamed from include/tpl-channel.h) | 0 | ||||
-rw-r--r-- | src/tpl-contact.h (renamed from include/tpl-contact.h) | 0 | ||||
-rw-r--r-- | src/tpl-log-entry-text.h (renamed from include/tpl-log-entry-text.h) | 0 | ||||
-rw-r--r-- | src/tpl-log-entry.h (renamed from include/tpl-log-entry.h) | 0 | ||||
-rw-r--r-- | src/tpl-log-manager.c | 3 | ||||
-rw-r--r-- | src/tpl-log-manager.h (renamed from include/tpl-log-manager.h) | 0 | ||||
-rw-r--r-- | src/tpl-log-reader.c | 368 | ||||
-rw-r--r-- | src/tpl-log-reader.h | 91 | ||||
-rw-r--r-- | src/tpl-log-store-empathy.c | 133 | ||||
-rw-r--r-- | src/tpl-log-store-empathy.h (renamed from include/tpl-log-store-empathy.h) | 2 | ||||
-rw-r--r-- | src/tpl-log-store.c | 1 | ||||
-rw-r--r-- | src/tpl-log-store.h (renamed from include/tpl-log-store.h) | 0 | ||||
-rw-r--r-- | src/tpl-observer.h (renamed from include/tpl-observer.h) | 0 | ||||
-rw-r--r-- | src/tpl-text-channel-context.h (renamed from include/tpl-text-channel-context.h) | 0 | ||||
-rw-r--r-- | src/tpl-time.h (renamed from include/tpl-time.h) | 0 | ||||
-rw-r--r-- | src/tpl-utils.h (renamed from include/tpl-utils.h) | 0 |
20 files changed, 618 insertions, 51 deletions
@@ -1,6 +1,8 @@ Those are mini tasks still to do. They should be filed against a bug trucker as soon as TPL will have one: +- add a logstore-ro interface or split the current one in rw and ro + depending on what/who is using it - global configuration object (ie disable logging partially or totally, choose the logstore, etc) - understand if direction from tpl_log_entry_text is to be removed diff --git a/src/Makefile.am b/src/Makefile.am index be491a5..160bf97 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -4,14 +4,14 @@ include $(top_srcdir)/tools/flymake.mk AM_CPPFLAGS = \ $(ERROR_CFLAGS) \ -I$(top_srcdir) \ - -I$(top_srcdir)/include \ - -DG_LOG_DOMAIN=\"TPLogger\" \ + -I$(top_srcdir)/src \ + -DG_LOG_DOMAIN=\"TPLogger\" \ $(TPL_CFLAGS) \ - $(LIBTPL_CFLAGS) \ + $(LIBTPL_CFLAGS) \ $(DISABLE_DEPRECATED) \ $(WARN_CFLAGS) -LDADD = $(TPL_LIBS) \ +LDADD = $(TPL_LIBS) \ $(LIBTPL_LIBS) bin_PROGRAMS = telepathy-logger @@ -28,6 +28,7 @@ telepathy_logger_handwritten_source = \ tpl-log-entry-text.c \ tpl-contact.c \ tpl-log-manager.c \ + tpl-log-reader.c \ tpl-log-store.c \ tpl-log-store-empathy.c \ tpl-utils.c \ diff --git a/include/config.h b/src/config.h index e69de29..e69de29 100644 --- a/include/config.h +++ b/src/config.h @@ -20,19 +20,69 @@ */ #include <glib.h> +#include <stdio.h> -#include <tpl-observer.h> +#include <tpl-log-reader.h> +#include <telepathy-glib/account.h> +#include <telepathy-glib/dbus.h> -static GMainLoop *loop = NULL; +//static GMainLoop *loop = NULL; int main(int argc, char *argv[]) { + TplLogReader *reader; + GList *l; + TpAccount *acc; + //DBusGConnection *bus; + TpDBusDaemon *tp_bus; + GError *err=NULL; g_type_init (); - tpl_headless_logger_init (); + //tpl_headless_logger_init (); + + //bus = tp_get_bus(); + tp_bus = tp_dbus_daemon_dup(&err); + acc = tp_account_new(tp_bus, + "/org/freedesktop/Telepathy/Account/gabble/jabber/cosimo_2ealfarano_40collabora_2eco_2euk0", + &err); - loop = g_main_loop_new (NULL, FALSE); - g_main_loop_run (loop); + if(err) { + g_debug(err->message); + return 0; + } + + reader = tpl_log_reader_dup_singleton (); + + tpl_log_reader_search_new(reader, "foo"); + + + l = tpl_log_reader_get_chats(reader, acc); + int lenght = g_list_length(l); + for(int i=0;i<lenght;++i) { + TplLogSearchHit *hit = g_list_nth_data(l,i); + g_debug("%d: %s\n", i, hit->filename); + GList *gl; + + gl = tpl_log_reader_get_dates (reader, acc, hit->chat_id, hit->is_chatroom); + g_list_foreach (gl, (GFunc) puts, NULL); + + for(guint ii=0;ii<g_list_length(gl);++ii) { + GList *msgs; + gchar *date = g_list_nth_data(gl, i); + msgs = tpl_log_reader_get_messages_for_date(reader, acc, hit->chat_id, + hit->is_chatroom, date); + for(guint m=0;m<g_list_length(msgs);++m) { + TplLogEntry *log = g_list_nth_data(msgs, m); + TplLogEntryText *tlog = TPL_LOG_ENTRY_TEXT(tpl_log_entry_get_entry(log)); + + g_message("BODY: %s\n", tpl_log_entry_text_get_message(tlog)); + } + } + + } + + //loop = g_main_loop_new (NULL, FALSE); + //g_main_loop_run (loop); return 0; } diff --git a/include/tpl-channel.h b/src/tpl-channel.h index 0fc9e30..0fc9e30 100644 --- a/include/tpl-channel.h +++ b/src/tpl-channel.h diff --git a/include/tpl-contact.h b/src/tpl-contact.h index 1d28bbc..1d28bbc 100644 --- a/include/tpl-contact.h +++ b/src/tpl-contact.h diff --git a/include/tpl-log-entry-text.h b/src/tpl-log-entry-text.h index 61c4be1..61c4be1 100644 --- a/include/tpl-log-entry-text.h +++ b/src/tpl-log-entry-text.h diff --git a/include/tpl-log-entry.h b/src/tpl-log-entry.h index 7a5a531..7a5a531 100644 --- a/include/tpl-log-entry.h +++ b/src/tpl-log-entry.h diff --git a/src/tpl-log-manager.c b/src/tpl-log-manager.c index dce5c67..7ac169b 100644 --- a/src/tpl-log-manager.c +++ b/src/tpl-log-manager.c @@ -323,6 +323,8 @@ tpl_log_manager_get_filtered_messages (TplLogManager *manager, return out; } + + GList * tpl_log_manager_get_chats (TplLogManager *manager, TpAccount *account) @@ -331,6 +333,7 @@ tpl_log_manager_get_chats (TplLogManager *manager, TplLogManagerPriv *priv; g_return_val_if_fail (TPL_IS_LOG_MANAGER (manager), NULL); + g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL); priv = GET_PRIV (manager); diff --git a/include/tpl-log-manager.h b/src/tpl-log-manager.h index a27ab23..a27ab23 100644 --- a/include/tpl-log-manager.h +++ b/src/tpl-log-manager.h diff --git a/src/tpl-log-reader.c b/src/tpl-log-reader.c new file mode 100644 index 0000000..2bf13bf --- /dev/null +++ b/src/tpl-log-reader.c @@ -0,0 +1,368 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2003-2007 Imendio AB + * Copyright (C) 2007-2008 Collabora Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authors: Xavier Claessens <xclaesse@gmail.com> + * Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> + */ + +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <glib/gstdio.h> + +#include <telepathy-glib/util.h> +#include <telepathy-glib/interfaces.h> + +#include <tpl-log-entry.h> +#include <tpl-log-reader.h> +#include <tpl-log-store-empathy.h> +#include <tpl-log-store.h> +#include <tpl-utils.h> +#include <tpl-time.h> + +//#define DEBUG_FLAG EMPATHY_DEBUG_OTHER +//#include <empathy-debug.h> + +#define DEBUG g_debug + +#define GET_PRIV(obj) TPL_GET_PRIV (obj, TplLogReader) +typedef struct +{ + GList *stores; +} TplLogReaderPriv; + +G_DEFINE_TYPE (TplLogReader, tpl_log_reader, G_TYPE_OBJECT); + +static TplLogReader * reader_singleton = NULL; + +static void +log_reader_finalize (GObject *object) +{ + TplLogReaderPriv *priv; + + priv = GET_PRIV (object); + + g_list_foreach (priv->stores, (GFunc) g_object_unref, NULL); + g_list_free (priv->stores); +} + +/* + * - Singleton LogReader constructor - + * Initialises LogStores with LogStoreEmpathy instance + */ +static GObject * +log_reader_constructor (GType type, + guint n_props, + GObjectConstructParam *props) +{ + GObject *retval; + TplLogReaderPriv *priv; + + if (reader_singleton) + { + retval = g_object_ref (reader_singleton); + } + else + { + retval = G_OBJECT_CLASS (tpl_log_reader_parent_class)->constructor + (type, n_props, props); + + reader_singleton = TPL_LOG_READER (retval); + g_object_add_weak_pointer (retval, (gpointer *) &reader_singleton); + + priv = GET_PRIV (reader_singleton); + + priv->stores = g_list_append (priv->stores, + g_object_new (TPL_TYPE_LOG_STORE_EMPATHY, NULL)); + } + + return retval; +} + +static void +tpl_log_reader_class_init (TplLogReaderClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->constructor = log_reader_constructor; + object_class->finalize = log_reader_finalize; + + g_type_class_add_private (object_class, sizeof (TplLogReaderPriv)); +} + +static void +tpl_log_reader_init (TplLogReader *reader) +{ + TplLogReaderPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (reader, + TPL_TYPE_LOG_READER, TplLogReaderPriv); + + reader->priv = priv; +} + +TplLogReader * +tpl_log_reader_dup_singleton (void) +{ + return g_object_new (TPL_TYPE_LOG_READER, NULL); +} + +gboolean +tpl_log_reader_exists (TplLogReader *reader, + TpAccount *account, + const gchar *chat_id, + gboolean chatroom) +{ + GList *l; + TplLogReaderPriv *priv; + + g_return_val_if_fail (TPL_IS_LOG_READER (reader), FALSE); + g_return_val_if_fail (chat_id != NULL, FALSE); + + priv = GET_PRIV (reader); + + for (l = priv->stores; l; l = g_list_next (l)) + { + if (tpl_log_store_exists (TPL_LOG_STORE (l->data), + account, chat_id, chatroom)) + return TRUE; + } + + return FALSE; +} + +// returns a list of gchar dates +GList * +tpl_log_reader_get_dates (TplLogReader *reader, + TpAccount *account, + const gchar *chat_id, + gboolean chatroom) +{ + GList *l, *out = NULL; + TplLogReaderPriv *priv; + + g_return_val_if_fail (TPL_IS_LOG_READER (reader), NULL); + g_return_val_if_fail (chat_id != NULL, NULL); + + priv = GET_PRIV (reader); + + for (l = priv->stores; l; l = g_list_next (l)) + { + TplLogStore *store = TPL_LOG_STORE (l->data); + GList *new; + + /* Insert dates of each store in the out list. Keep the out list sorted + * and avoid to insert dups. */ + 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); + else + out = g_list_insert_sorted (out, new->data, (GCompareFunc) strcmp); + + new = g_list_delete_link (new, new); + } + } + + return out; +} + +GList * +tpl_log_reader_get_messages_for_date (TplLogReader *reader, + TpAccount *account, + const gchar *chat_id, + gboolean chatroom, + const gchar *date) +{ + GList *l, *out = NULL; + TplLogReaderPriv *priv; + + g_return_val_if_fail (TPL_IS_LOG_READER (reader), NULL); + g_return_val_if_fail (chat_id != NULL, NULL); + + priv = GET_PRIV (reader); + + for (l = priv->stores; l; l = g_list_next (l)) + { + TplLogStore *store = TPL_LOG_STORE (l->data); + + out = g_list_concat (out, tpl_log_store_get_messages_for_date ( + store, account, chat_id, chatroom, date)); + } + + return out; +} + +static gint +log_reader_message_date_cmp (gconstpointer a, + gconstpointer b) +{ + TplLogEntry *one = (TplLogEntry *) a; + TplLogEntry *two = (TplLogEntry *) b; + time_t one_time, two_time; + + one_time = tpl_log_entry_get_timestamp (one); + two_time = tpl_log_entry_get_timestamp (two); + + /* Return -1 of message1 is older than message2 */ + return one_time < two_time ? -1 : one_time - two_time; +} + +GList * +tpl_log_reader_get_filtered_messages (TplLogReader *reader, + TpAccount *account, + const gchar *chat_id, + gboolean chatroom, + guint num_messages, + TplLogMessageFilter filter, + gpointer user_data) +{ + TplLogReaderPriv *priv; + GList *out = NULL; + GList *l; + guint i = 0; + + g_return_val_if_fail (TPL_IS_LOG_READER (reader), NULL); + g_return_val_if_fail (chat_id != NULL, NULL); + + priv = GET_PRIV (reader); + + /* Get num_messages from each log store and keep only the + * newest ones in the out list. Keep that list sorted: Older first. */ + for (l = priv->stores; l; l = g_list_next (l)) + { + TplLogStore *store = TPL_LOG_STORE (l->data); + GList *new; + + new = tpl_log_store_get_filtered_messages (store, account, chat_id, + chatroom, num_messages, filter, user_data); + while (new) + { + if (i < num_messages) + { + /* We have less message than needed so far. Keep this message */ + out = g_list_insert_sorted (out, new->data, + (GCompareFunc) log_reader_message_date_cmp); + i++; + } + else if (log_reader_message_date_cmp (new->data, out->data) > 0) + { + /* This message is newer than the oldest message we have in out + * list. Remove the head of out list and insert this message */ + g_object_unref (out->data); + out = g_list_delete_link (out, out); + out = g_list_insert_sorted (out, new->data, + (GCompareFunc) log_reader_message_date_cmp); + } + else + { + /* This message is older than the oldest message we have in out + * list. Drop it. */ + g_object_unref (new->data); + } + + new = g_list_delete_link (new, new); + } + } + + return out; +} + +GList * +tpl_log_reader_get_chats (TplLogReader *reader, + TpAccount *account) +{ + GList *l, *out = NULL; + TplLogReaderPriv *priv; + + g_return_val_if_fail (TPL_IS_LOG_READER (reader), NULL); + g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL); + + priv = GET_PRIV (reader); + + for (l = priv->stores; l; l = g_list_next (l)) + { + TplLogStore *store = TPL_LOG_STORE (l->data); + + out = g_list_concat (out, + tpl_log_store_get_chats (store, account)); + } + + return out; +} + +GList * +tpl_log_reader_search_new (TplLogReader *reader, + const gchar *text) +{ + GList *l, *out = NULL; + TplLogReaderPriv *priv; + + g_return_val_if_fail (TPL_IS_LOG_READER (reader), NULL); + g_return_val_if_fail (!TPL_STR_EMPTY (text), NULL); + + priv = GET_PRIV (reader); + + for (l = priv->stores; l; l = g_list_next (l)) + { + TplLogStore *store = TPL_LOG_STORE (l->data); + + out = g_list_concat (out, + tpl_log_store_search_new (store, text)); + } + + return out; +} + +void +tpl_log_reader_search_hit_free (TplLogSearchHit *hit) +{ + if (hit->account != NULL) + g_object_unref (hit->account); + + g_free (hit->date); + g_free (hit->filename); + g_free (hit->chat_id); + + g_slice_free (TplLogSearchHit, hit); +} + +void +tpl_log_reader_search_free (GList *hits) +{ + GList *l; + + for (l = hits; l; l = g_list_next (l)) + { + tpl_log_reader_search_hit_free (l->data); + } + + g_list_free (hits); +} + +/* Format is just date, 20061201. */ +gchar * +tpl_log_reader_get_date_readable (const gchar *date) +{ + time_t t; + + t = tpl_time_parse (date); + + return tpl_time_to_string_local (t, "%a %d %b %Y"); +} diff --git a/src/tpl-log-reader.h b/src/tpl-log-reader.h new file mode 100644 index 0000000..5179b37 --- /dev/null +++ b/src/tpl-log-reader.h @@ -0,0 +1,91 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2003-2007 Imendio AB + * Copyright (C) 2007-2008 Collabora Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authors: Xavier Claessens <xclaesse@gmail.com> + */ + +#ifndef __TPL_LOG_READER_H__ +#define __TPL_LOG_READER_H__ + + +#include <glib-object.h> +//TODO remove it +#include <tpl-log-manager.h> + +G_BEGIN_DECLS + +#define TPL_TYPE_LOG_READER (tpl_log_reader_get_type ()) +#define TPL_LOG_READER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TPL_TYPE_LOG_READER, TplLogReader)) +#define TPL_LOG_READER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), TPL_TYPE_LOG_READER, TplLogReaderClass)) +#define TPL_IS_LOG_READER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TPL_TYPE_LOG_READER)) +#define TPL_IS_LOG_READER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TPL_TYPE_LOG_READER)) +#define TPL_LOG_READER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TPL_TYPE_LOG_READER, TplLogReaderClass)) + +typedef struct +{ + GObject parent; + + gpointer priv; +} TplLogReader; + +typedef struct +{ + GObjectClass parent_class; +} TplLogReaderClass; + +GType tpl_log_reader_get_type (void); + +TplLogReader *tpl_log_reader_dup_singleton (void); + +gboolean tpl_log_reader_exists (TplLogReader *manager, + TpAccount *account, const gchar *chat_id, + gboolean chatroom); + +GList *tpl_log_reader_get_dates (TplLogReader *manager, + TpAccount *account, const gchar *chat_id, + gboolean chatroom); + +GList *tpl_log_reader_get_messages_for_date (TplLogReader *manager, + TpAccount *account, const gchar *chat_id, + gboolean chatroom, const gchar *date); + +GList *tpl_log_reader_get_filtered_messages (TplLogReader *manager, + TpAccount *account, const gchar *chat_id, gboolean chatroom, + guint num_messages, TplLogMessageFilter filter, + gpointer user_data); + +GList *tpl_log_reader_get_chats (TplLogReader *manager, + TpAccount *account); + +GList *tpl_log_reader_search_new (TplLogReader *manager, + const gchar *text); + +void tpl_log_reader_search_free (GList *hits); + +gchar *tpl_log_reader_get_date_readable (const gchar *date); + +void tpl_log_reader_search_hit_free (TplLogSearchHit *hit); + +//void tpl_log_reader_observe (TplLogReader *log_reader, +// EmpathyDispatcher *dispatcher); + +G_END_DECLS + +#endif /* __TPL_LOG_READER_H__ */ diff --git a/src/tpl-log-store-empathy.c b/src/tpl-log-store-empathy.c index 65fd395..5ca2200 100644 --- a/src/tpl-log-store-empathy.c +++ b/src/tpl-log-store-empathy.c @@ -142,6 +142,9 @@ static gchar * log_store_account_to_dirname (TpAccount *account) { const gchar *name; + + g_return_val_if_fail(TP_IS_ACCOUNT(account), NULL); + name = tp_proxy_get_object_path (account); if (g_str_has_prefix (name, TP_ACCOUNT_OBJECT_PATH_BASE)) name += strlen (TP_ACCOUNT_OBJECT_PATH_BASE); @@ -160,6 +163,11 @@ log_store_empathy_get_dir (TplLogStore *self, gchar *escaped; TplLogStoreEmpathyPriv *priv; + g_return_val_if_fail (TPL_IS_LOG_STORE (self), NULL); + g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL); + // chat_id may be NULL, in order to obtain the account part of the + // path. + priv = GET_PRIV (self); escaped = log_store_account_to_dirname (account); @@ -243,7 +251,7 @@ static gboolean _log_store_empathy_write_to_store ( TplLogStore *self, } g_free (basedir); - DEBUG ("Adding log to file: '%s'", filename); + DEBUG ("Adding log to file: '%s': %s", filename, entry); if (!g_file_test (filename, G_FILE_TEST_EXISTS)) { @@ -267,6 +275,7 @@ static gboolean _log_store_empathy_write_to_store ( TplLogStore *self, return TRUE; } +/* currently unused */ static gboolean _log_store_empathy_add_message_text_status_changed ( TplLogStore *self, @@ -432,10 +441,14 @@ _log_store_empathy_add_message_text (TplLogStore *self, chat_id, chatroom, message, error); break; case TPL_LOG_ENTRY_TEXT_SIGNAL_SEND_ERROR: + g_warning("SEND_ERROR log entry not currently handled"); + return FALSE; case TPL_LOG_ENTRY_TEXT_SIGNAL_LOST_MESSAGE: + g_warning("LOST_MESSAGE log entry not currently handled"); + return FALSE; default: - g_warning("received an not handled signal type/signal type unknown"); - return FALSE; + g_warning("LogEntry's signal type unknown"); + return FALSE; } } @@ -470,6 +483,10 @@ log_store_empathy_exists (TplLogStore *self, gchar *dir; gboolean exists; + g_return_val_if_fail(TPL_IS_LOG_ENTRY (self), FALSE); + g_return_val_if_fail(TP_IS_ACCOUNT (account), FALSE); + g_return_val_if_fail(!TPL_STR_EMPTY (chat_id), FALSE); + dir = log_store_empathy_get_dir (self, account, chat_id, chatroom); exists = g_file_test (dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR); g_free (dir); @@ -491,9 +508,11 @@ log_store_empathy_get_dates (TplLogStore *self, const gchar *p; g_return_val_if_fail (TPL_IS_LOG_STORE (self), NULL); - g_return_val_if_fail (chat_id != NULL, NULL); + g_return_val_if_fail( TP_IS_ACCOUNT (account), NULL); + g_return_val_if_fail (!TPL_STR_EMPTY (chat_id), NULL); directory = log_store_empathy_get_dir (self, account, chat_id, chatroom); + g_message("dir %s\n", directory); dir = g_dir_open (directory, 0, NULL); if (!dir) { @@ -540,6 +559,12 @@ log_store_empathy_get_filename_for_date (TplLogStore *self, gchar *timestamp; gchar *filename; + + g_return_val_if_fail (TPL_IS_LOG_STORE (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); + basedir = log_store_empathy_get_dir (self, account, chat_id, chatroom); timestamp = g_strconcat (date, LOG_FILENAME_SUFFIX, NULL); filename = g_build_filename (basedir, timestamp, NULL); @@ -562,8 +587,9 @@ log_store_empathy_search_hit_new (TplLogStore *self, guint len; GList *accounts, *l; - if (!g_str_has_suffix (filename, LOG_FILENAME_SUFFIX)) - return NULL; + g_return_val_if_fail (TPL_IS_LOG_STORE (self), NULL); + g_return_val_if_fail (!TPL_STR_EMPTY (filename), NULL); + g_return_val_if_fail (g_str_has_suffix (filename, LOG_FILENAME_SUFFIX), NULL); strv = g_strsplit (filename, G_DIR_SEPARATOR_S, -1); len = g_strv_length (strv); @@ -575,6 +601,8 @@ log_store_empathy_search_hit_new (TplLogStore *self, hit->chat_id = g_strdup (strv[len-2]); hit->is_chatroom = (strcmp (strv[len-3], LOG_DIR_CHATROOMS) == 0); + g_debug("end %s, date %s, id %s\n", end, hit->date, hit->chat_id); + if (hit->is_chatroom) account_name = strv[len-4]; else @@ -619,7 +647,7 @@ log_store_empathy_get_messages_for_file (TplLogStore *self, xmlNodePtr node; g_return_val_if_fail (TPL_IS_LOG_STORE (self), NULL); - g_return_val_if_fail (filename != NULL, NULL); + g_return_val_if_fail (!TPL_STR_EMPTY(filename), NULL); DEBUG ("Attempting to parse filename:'%s'...", filename); @@ -844,47 +872,59 @@ log_store_empathy_search_new (TplLogStore *self, return hits; } +/* +static gboolean +log_store_empathy_is_logfile (gchar const *filename) { + gchar **path; + guint len; + g_return_val_if_fail(!TPL_STR_EMPTY(filename), FALSE); + + + path = g_strsplit (filename, G_DIR_SEPARATOR_S, -1); + len = g_strv_length (path); + + return g_regex_match_simple ( + TPL_LOG_STORE_EMPATHY_LOGFILE_REGEX, path[len-1], 0, 0); +} +*/ static GList * log_store_empathy_get_chats_for_dir (TplLogStore *self, - const gchar *dir, - gboolean is_chatroom) + const gchar *dir, gboolean is_chatroom) { - GDir *gdir; - GList *hits = NULL; - const gchar *name; - GError *error = NULL; + GDir *gdir; + GList *hits = NULL; + const gchar *name; + GError *error = NULL; + + gdir = g_dir_open (dir, 0, &error); + if (!gdir) { + DEBUG ("Failed to open directory: %s, error: %s", dir, error->message); + g_error_free (error); + return NULL; + } - gdir = g_dir_open (dir, 0, &error); - if (!gdir) - { - DEBUG ("Failed to open directory: %s, error: %s", dir, error->message); - g_error_free (error); - return NULL; - } - while ((name = g_dir_read_name (gdir)) != NULL) - { - TplLogSearchHit *hit; + while ((name = g_dir_read_name (gdir)) != NULL) { + TplLogSearchHit *hit; - if (!is_chatroom && strcmp (name, LOG_DIR_CHATROOMS) == 0) - { - gchar *filename = g_build_filename (dir, name, NULL); - hits = g_list_concat (hits, log_store_empathy_get_chats_for_dir ( - self, filename, TRUE)); - g_free (filename); - continue; - } - hit = g_slice_new0 (TplLogSearchHit); - hit->chat_id = g_strdup (name); - hit->is_chatroom = is_chatroom; + if (!is_chatroom && strcmp (name, LOG_DIR_CHATROOMS) == 0) { + gchar *filename = g_build_filename (dir, name, NULL); + hits = g_list_concat (hits, log_store_empathy_get_chats_for_dir ( + self, filename, TRUE)); + g_free (filename); + continue; + } + hit = g_slice_new0 (TplLogSearchHit); + hit->chat_id = g_strdup (name); + hit->is_chatroom = is_chatroom; - hits = g_list_prepend (hits, hit); - } + hits = g_list_prepend (hits, hit); + } - g_dir_close (gdir); + g_dir_close (gdir); - return hits; + return hits; } @@ -899,13 +939,13 @@ log_store_empathy_get_messages_for_date (TplLogStore *self, GList *messages; g_return_val_if_fail (TPL_IS_LOG_STORE (self), NULL); - g_return_val_if_fail (chat_id != NULL, NULL); - g_return_val_if_fail (account != NULL, NULL); + g_return_val_if_fail (TP_IS_ACCOUNT(account), NULL); + g_return_val_if_fail (!TPL_STR_EMPTY(chat_id), NULL); filename = log_store_empathy_get_filename_for_date (self, account, - chat_id, chatroom, date); + chat_id, chatroom, date); messages = log_store_empathy_get_messages_for_file (self, account, - filename); + filename); g_free (filename); return messages; @@ -927,6 +967,15 @@ log_store_empathy_get_chats (TplLogStore *self, g_free (dir); + g_message("len: %d\n", g_list_length(hits)); + for(guint i=0; i<g_list_length(hits);++i) { + TplLogSearchHit *hit; + hit = g_list_nth_data(hits, i); + g_message("hit: %s\n", hit->chat_id); + g_message("hit: %s\n", hit->filename); + } + + return hits; } diff --git a/include/tpl-log-store-empathy.h b/src/tpl-log-store-empathy.h index 86b5e77..a0cb5ac 100644 --- a/include/tpl-log-store-empathy.h +++ b/src/tpl-log-store-empathy.h @@ -29,6 +29,8 @@ G_BEGIN_DECLS +#define TPL_LOG_STORE_EMPATHY_LOGFILE_REGEX "\\d{8}.log" + #define TPL_TYPE_LOG_STORE_EMPATHY \ (tpl_log_store_empathy_get_type ()) #define TPL_LOG_STORE_EMPATHY(obj) \ diff --git a/src/tpl-log-store.c b/src/tpl-log-store.c index 7ed6a98..a3e76de 100644 --- a/src/tpl-log-store.c +++ b/src/tpl-log-store.c @@ -135,6 +135,7 @@ tpl_log_store_get_chats (TplLogStore *self, return TPL_LOG_STORE_GET_INTERFACE (self)->get_chats (self, account); } + GList * tpl_log_store_search_new (TplLogStore *self, const gchar *text) diff --git a/include/tpl-log-store.h b/src/tpl-log-store.h index 5f3e81c..5f3e81c 100644 --- a/include/tpl-log-store.h +++ b/src/tpl-log-store.h diff --git a/include/tpl-observer.h b/src/tpl-observer.h index 06ff92d..06ff92d 100644 --- a/include/tpl-observer.h +++ b/src/tpl-observer.h diff --git a/include/tpl-text-channel-context.h b/src/tpl-text-channel-context.h index 94a1e1f..94a1e1f 100644 --- a/include/tpl-text-channel-context.h +++ b/src/tpl-text-channel-context.h diff --git a/include/tpl-time.h b/src/tpl-time.h index 5fc5cf3..5fc5cf3 100644 --- a/include/tpl-time.h +++ b/src/tpl-time.h diff --git a/include/tpl-utils.h b/src/tpl-utils.h index 6eccf97..6eccf97 100644 --- a/include/tpl-utils.h +++ b/src/tpl-utils.h |