diff options
Diffstat (limited to 'telepathy-logger')
60 files changed, 0 insertions, 15212 deletions
diff --git a/telepathy-logger/Makefile.am b/telepathy-logger/Makefile.am deleted file mode 100644 index 96a410a..0000000 --- a/telepathy-logger/Makefile.am +++ /dev/null @@ -1,142 +0,0 @@ -include $(top_srcdir)/tools/flymake.mk - -if HAVE_INTROSPECTION -include $(INTROSPECTION_MAKEFILE) -endif -INTROSPECTION_GIRS = -INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) --add-include-path=$(top_srcdir) -I$(top_srcdir) -INTROSPECTION_COMPILER_ARGS = --includedir=$(srcdir) --includedir=$(top_srcdir) - -AM_CPPFLAGS = \ - -I$(top_builddir) \ - -I$(top_builddir)/extensions \ - -I$(top_srcdir) \ - $(ERROR_CFLAGS) \ - -DG_LOG_DOMAIN=\"tp-logger\" \ - -DTPL_DATA_DIR=\"$(PACKAGE_NAME)\" \ - -DTP_DISABLE_SINGLE_INCLUDE \ - $(TPL_CFLAGS) \ - $(DISABLE_DEPRECATED) \ - $(WARN_CFLAGS) - -pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = telepathy-logger-1.pc - -lib_LTLIBRARIES = libtelepathy-logger-1.la - -EXTRA_DIST = \ - tpl-marshal.list \ - $(NULL) - -LIBTPLdir = $(includedir)/telepathy-logger-1/telepathy-logger -LIBTPL_HEADERS = \ - entity.h \ - event.h \ - log-manager.h \ - log-walker.h \ - telepathy-logger.h \ - text-event.h \ - call-event.h \ - $(NULL) - -%-marshal.c: %-marshal.list Makefile.am - $(AM_V_GEN)echo "#include \"tpl-marshal.h\"" > $@ - $(AM_V_GEN)glib-genmarshal --body --prefix=tpl_marshal $< >> $@ - -%-marshal.h: %-marshal.list Makefile.am - $(AM_V_GEN)glib-genmarshal --header --prefix=tpl_marshal $< > $@ - -BUILT_SOURCES = \ - tpl-marshal.c tpl-marshal.h \ - $(NULL) - -libtelepathy_logger_1_la_SOURCES = \ - action-chain.c \ - action-chain-internal.h \ - call-event.c \ - call-event-internal.h \ - client-factory.c \ - client-factory-internal.h \ - conf.c \ - conf-internal.h \ - entity.c \ - entity-internal.h \ - dbus-service.c \ - dbus-service-internal.h \ - debug-internal.h \ - debug.c \ - event.c \ - event-internal.h \ - log-iter.c \ - log-iter-internal.h \ - log-iter-pidgin.c \ - log-iter-pidgin-internal.h \ - log-iter-xml.c \ - log-iter-xml-internal.h \ - log-manager.c \ - log-manager-internal.h \ - log-store.c \ - log-store-internal.h \ - log-store-xml.c \ - log-store-xml-internal.h \ - log-store-empathy.c \ - log-store-empathy-internal.h \ - log-store-sqlite.c \ - log-store-sqlite-internal.h \ - log-store-pidgin.c \ - log-store-pidgin-internal.h \ - log-store-factory.c \ - log-store-factory-internal.h \ - log-walker.c \ - log-walker-internal.h \ - observer.c \ - observer-internal.h \ - text-channel.c \ - text-channel-internal.h \ - text-event.c \ - text-event-internal.h \ - util-internal.h \ - util.c \ - call-channel.c \ - call-channel-internal.h \ - $(NULL) - -nodist_libtelepathy_logger_1_la_SOURCES = \ - $(BUILT_SOURCES) - -libtelepathy_logger_1_la_LIBADD = \ - $(top_builddir)/extensions/libtpl-extensions-convenience.la - -check_c_sources = \ - $(libtelepathy_logger_1_la_SOURCES) \ - $(LIBTPL_HEADERS) -include $(top_srcdir)/tools/check-coding-style.mk -check-local: check-coding-style - -CLEANFILES = $(BUILT_SOURCES) - -if HAVE_INTROSPECTION -introspection_sources = $(libtelepathy_logger_1_la_SOURCES) $(LIBTPL_HEADERS) - -TelepathyLogger1-1.gir: libtelepathy-logger-1.la -TelepathyLogger1_1_gir_SCANNERFLAGS = --identifier-prefix=Tpl --warn-all -TelepathyLogger1_1_gir_INCLUDES = GObject-2.0 TelepathyGLib-0.12 -TelepathyLogger1_1_gir_CFLAGS = $(INCLUDES) -TelepathyLogger1_1_gir_LIBS = libtelepathy-logger-1.la -TelepathyLogger1_1_gir_FILES = $(filter-out %-internal.h, $(introspection_sources)) - -INTROSPECTION_GIRS += TelepathyLogger1-1.gir - -girdir = $(datadir)/gir-1.0 -gir_DATA = $(INTROSPECTION_GIRS) - -typelibdir = $(libdir)/girepository-1.0/ -typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib) - -CLEANFILES += \ - $(gir_DATA) \ - $(typelib_DATA) - -endif - -include abi.am diff --git a/telepathy-logger/abi.am b/telepathy-logger/abi.am deleted file mode 100644 index d63e847..0000000 --- a/telepathy-logger/abi.am +++ /dev/null @@ -1,16 +0,0 @@ -# To be included by Makefile.am. - -# The quoting here is unnecessary but harmless, and has the useful side-effect -# that vim quickfix mode (:make) doesn't interpret the libtool --mode=link -# command as an error message in a bizarrely named file -libtelepathy_logger_1_la_LDFLAGS = \ - -version-info "$(TPL_LT_CURRENT)":"$(TPL_LT_REVISION)":"$(TPL_LT_AGE)" - -_gen/abi.txt: libtelepathy-logger-1.la abi.am - $(NM) .libs/libtelepathy-logger.a > _gen/abi.nm - grep " [DT] " < _gen/abi.nm > _gen/abi.funcs - cut -d" " -f3 < _gen/abi.funcs > _gen/abi.funcnames - grep "^tpl" < _gen/abi.funcnames > _gen/abi.tpfuncnames - $(AM_V_GEN)sort -u < _gen/abi.tpfuncnames > $@ - -# vim:ft=automake: diff --git a/telepathy-logger/action-chain-internal.h b/telepathy-logger/action-chain-internal.h deleted file mode 100644 index 674cc2b..0000000 --- a/telepathy-logger/action-chain-internal.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2009 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: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - */ - -#ifndef __TPL_ACTION_CHAIN_H__ -#define __TPL_ACTION_CHAIN_H__ - -#include <glib-object.h> -#include <gio/gio.h> - -typedef struct { - GQueue *chain; - GSimpleAsyncResult *simple; -} TplActionChain; - -TplActionChain *_tpl_action_chain_new_async (GObject *obj, - GAsyncReadyCallback cb, - gpointer user_data); -void _tpl_action_chain_free (TplActionChain *self); -typedef void (*TplPendingAction) (TplActionChain *ctx, gpointer user_data); -void _tpl_action_chain_append (TplActionChain *self, TplPendingAction func, - gpointer user_data); -void _tpl_action_chain_prepend (TplActionChain *self, TplPendingAction func, - gpointer user_data); -void _tpl_action_chain_continue (TplActionChain *self); -void _tpl_action_chain_terminate (TplActionChain *self, const GError *error); -gpointer _tpl_action_chain_get_object (TplActionChain *self); -gboolean _tpl_action_chain_new_finish (GObject *source, - GAsyncResult *result, GError **error); - -#endif // __TPL_ACTION_CHAIN_H__ diff --git a/telepathy-logger/action-chain.c b/telepathy-logger/action-chain.c deleted file mode 100644 index 14b9452..0000000 --- a/telepathy-logger/action-chain.c +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright (C) 2009 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: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - */ - -#include "config.h" -#include "action-chain-internal.h" - -typedef struct { - TplPendingAction action; - gpointer user_data; -} TplActionLink; - - -TplActionChain * -_tpl_action_chain_new_async (GObject *obj, - GAsyncReadyCallback cb, - gpointer user_data) -{ - TplActionChain *ret = g_slice_new0 (TplActionChain); - - ret->chain = g_queue_new (); - ret->simple = g_simple_async_result_new (obj, cb, user_data, - _tpl_action_chain_new_async); - - g_object_set_data (G_OBJECT (ret->simple), "chain", ret); - - return ret; -} - - -static void -link_free (TplActionLink *l) -{ - g_slice_free (TplActionLink, l); -} - - -void -_tpl_action_chain_free (TplActionChain *self) -{ - g_queue_foreach (self->chain, (GFunc) link_free, NULL); - g_queue_free (self->chain); - g_object_unref (self->simple); - g_slice_free (TplActionChain, self); -} - - -gpointer // FIXME GObject * -_tpl_action_chain_get_object (TplActionChain *self) -{ - GObject *obj; - - g_return_val_if_fail (self != NULL && self->simple != NULL, NULL); - - obj = g_async_result_get_source_object (G_ASYNC_RESULT (self->simple)); - g_object_unref (obj); /* don't want the extra ref */ - - return obj; -} - - -void -_tpl_action_chain_prepend (TplActionChain *self, - TplPendingAction func, - gpointer user_data) -{ - TplActionLink *l; - - l = g_slice_new0 (TplActionLink); - l->action = func; - l->user_data = user_data; - - g_queue_push_head (self->chain, l); -} - - -void -_tpl_action_chain_append (TplActionChain *self, - TplPendingAction func, - gpointer user_data) -{ - TplActionLink *l; - - l = g_slice_new0 (TplActionLink); - l->action = func; - l->user_data = user_data; - - g_queue_push_tail (self->chain, l); -} - - -void -_tpl_action_chain_continue (TplActionChain *self) -{ - if (g_queue_is_empty (self->chain)) - { - g_simple_async_result_complete (self->simple); - _tpl_action_chain_free (self); - } - else - { - TplActionLink *l = g_queue_pop_head (self->chain); - - l->action (self, l->user_data); - link_free (l); - } -} - - -void -_tpl_action_chain_terminate (TplActionChain *self, - const GError *error) -{ - GSimpleAsyncResult *simple = self->simple; - - g_assert (error != NULL); - - g_simple_async_result_set_from_error (simple, error); - g_simple_async_result_complete (simple); - _tpl_action_chain_free (self); -} - - -/** - * _tpl_action_chain_new_finish: - * @source: the #GObject pass to _tpl_action_chain_new_async() - * @result: the #GAsyncResult pass in callback - * @error: a pointer to a #GError that will be set on error, or NULL to ignore - * - * Get the result from running the action chain (%TRUE if the chain completed - * successfully, %FALSE with @error set if it was terminated). - * - * This function also frees the chain. - * - * Returns: %TRUE on success, %FALSE with @error set on error. - */ -gboolean -_tpl_action_chain_new_finish (GObject *source, - GAsyncResult *result, - GError **error) -{ - TplActionChain *chain; - - g_return_val_if_fail (g_simple_async_result_is_valid (result, source, - _tpl_action_chain_new_async), FALSE); - - chain = g_object_get_data (G_OBJECT (result), "chain"); - - g_return_val_if_fail (chain != NULL, FALSE); - - if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), - error)) - return FALSE; - - return TRUE; -} diff --git a/telepathy-logger/call-channel-internal.h b/telepathy-logger/call-channel-internal.h deleted file mode 100644 index 0f7b9a9..0000000 --- a/telepathy-logger/call-channel-internal.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2011 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: Nicolas Dufresne <nicolas.dufresne@collabora.co.uk> - */ - -#ifndef __TPL_CALL_CHANNEL_H__ -#define __TPL_CALL_CHANNEL_H__ - -#include <glib-object.h> -#include <telepathy-glib/telepathy-glib.h> - -G_BEGIN_DECLS -#define TPL_TYPE_CALL_CHANNEL (_tpl_call_channel_get_type ()) -#define TPL_CALL_CHANNEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_CALL_CHANNEL, TplCallChannel)) -#define TPL_CALL_CHANNEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TPL_TYPE_CALL_CHANNEL, TplCallChannelClass)) -#define TPL_IS_CALL_CHANNEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_CALL_CHANNEL)) -#define TPL_IS_CALL_CHANNEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TPL_TYPE_CALL_CHANNEL)) -#define TPL_CALL_CHANNEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_CALL_CHANNEL, TplCallChannelClass)) - -#define TPL_CALL_CHANNEL_ERROR \ - g_quark_from_static_string ("tpl-call-channel-error-quark") - -typedef enum -{ - /* generic error */ - TPL_CALL_CHANNEL_ERROR_FAILED, - TPL_CALL_CHANNEL_ERROR_MISSING_TARGET_CONTACT, -} TplCallChannelError; - -#define TPL_CALL_CHANNEL_FEATURE_CORE \ - _tpl_call_channel_get_feature_quark_core () -GQuark _tpl_call_channel_get_feature_quark_core (void) G_GNUC_CONST; - -typedef struct _TplCallChannelPriv TplCallChannelPriv; -typedef struct -{ - TpCallChannel parent; - - /* private */ - TplCallChannelPriv *priv; -} TplCallChannel; - -typedef struct -{ - TpCallChannelClass parent_class; -} TplCallChannelClass; - -GType _tpl_call_channel_get_type (void); - -TplCallChannel * _tpl_call_channel_new (TpConnection *conn, - const gchar *object_path, - GHashTable *tp_chan_props, - GError **error); - -TplCallChannel * _tpl_call_channel_new_with_factory ( - TpClientFactory *factory, - TpConnection *conn, - const gchar *object_path, - const GHashTable *tp_chan_props, - GError **error); - -G_END_DECLS -#endif /* __TPL_CALL_CHANNEL_H__ */ diff --git a/telepathy-logger/call-channel.c b/telepathy-logger/call-channel.c deleted file mode 100644 index 96bf4ea..0000000 --- a/telepathy-logger/call-channel.c +++ /dev/null @@ -1,492 +0,0 @@ -/* - * Copyright (C) 2011 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: Nicolas Dufresne <nicolas.dufresne@collabora.co.uk> - */ - -#include "config.h" -#include "call-channel-internal.h" - -#include <glib.h> -#include <telepathy-glib/telepathy-glib.h> -#include <telepathy-glib/telepathy-glib-dbus.h> - -#include "call-event.h" -#include "call-event-internal.h" -#include "entity-internal.h" -#include "event-internal.h" -#include "log-manager-internal.h" -#include "observer-internal.h" -#include "tpl-marshal.h" -#include "util-internal.h" - -#define DEBUG_FLAG TPL_DEBUG_CHANNEL -#include "debug-internal.h" - -struct _TplCallChannelPriv -{ - TpAccount *account; - GHashTable *entities; - TplEntity *sender; - TplEntity *receiver; - GDateTime *timestamp; - GTimer *timer; - gboolean timer_started; - TplEntity *end_actor; - TpCallStateChangeReason end_reason; - gchar *detailed_end_reason; -}; - -G_DEFINE_TYPE (TplCallChannel, _tpl_call_channel, TP_TYPE_CALL_CHANNEL) - - -static gboolean -get_contacts (TplCallChannel *self, - GError **error) -{ - TplCallChannelPriv *priv = self->priv; - TpChannel *chan = TP_CHANNEL (self); - TpConnection *con = tp_channel_get_connection (chan); - GHashTable *members; - GHashTableIter iter; - TpHandle handle; - TpHandleType handle_type; - gboolean is_room; - TpContact *contact; - TplEntity *entity; - - /* Get and store entities */ - members = tp_call_channel_get_members (TP_CALL_CHANNEL (self)); - - g_hash_table_iter_init (&iter, members); - while (g_hash_table_iter_next (&iter, (gpointer *) &contact, NULL)) - { - handle = tp_contact_get_handle (contact); - g_hash_table_insert (priv->entities, GUINT_TO_POINTER (handle), - tpl_entity_new_from_tp_contact (contact, TPL_ENTITY_CONTACT)); - } - - /* Identify target */ - handle = tp_channel_get_handle (chan, &handle_type); - is_room = (handle_type == TP_HANDLE_TYPE_ROOM); - - if (is_room) - { - priv->receiver = - tpl_entity_new_from_room_id (tp_channel_get_identifier (chan)); - } - else - { - entity = g_hash_table_lookup (priv->entities, GUINT_TO_POINTER (handle)); - - if (entity == NULL) - { - g_set_error (error, TPL_CALL_CHANNEL_ERROR, - TPL_CALL_CHANNEL_ERROR_MISSING_TARGET_CONTACT, - "Failed to resolve target contact"); - return FALSE; - } - - if (tp_channel_get_requested (chan)) - priv->receiver = g_object_ref (entity); - else - priv->sender = g_object_ref (entity); - } - - /* Get and store self entity */ - contact = tp_channel_group_get_self_contact (chan); - if (contact == NULL) - contact = tp_connection_get_self_contact (con); - - handle = tp_contact_get_handle (contact); - entity = tpl_entity_new_from_tp_contact (contact, TPL_ENTITY_SELF); - g_hash_table_insert (priv->entities, GUINT_TO_POINTER (handle), entity); - - if (tp_channel_get_requested (chan) || is_room) - priv->sender = g_object_ref (entity); - else - priv->receiver = g_object_ref (entity); - - return TRUE; -} - - -static void -call_state_changed_cb (TpCallChannel *call, - TpCallState state, - TpCallFlags flags, - TpCallStateReason *reason, - GHashTable *details, - gpointer user_data) -{ - TplCallChannel *self = TPL_CALL_CHANNEL (user_data); - TplCallChannelPriv *priv = self->priv; - - switch (state) - { - case TP_CALL_STATE_ACCEPTED: - { - if (!priv->timer_started) - { - DEBUG ("Moving to ACCEPTED_STATE, start_time=%li", - time (NULL)); - g_timer_start (priv->timer); - priv->timer_started = TRUE; - } - } - break; - - case TP_CALL_STATE_ENDED: - { - if (priv->end_actor != NULL) - g_object_unref (priv->end_actor); - - priv->end_actor = g_hash_table_lookup (priv->entities, - GUINT_TO_POINTER (reason->actor)); - - if (priv->end_actor == NULL) - priv->end_actor = tpl_entity_new ("unknown", TPL_ENTITY_UNKNOWN, - NULL, NULL); - else - g_object_ref (priv->end_actor); - - priv->end_reason = reason->reason; - - g_free (priv->detailed_end_reason); - - if (reason->dbus_reason == NULL) - priv->detailed_end_reason = g_strdup (""); - else - priv->detailed_end_reason = g_strdup (reason->dbus_reason); - - g_timer_stop (priv->timer); - - DEBUG ( - "Moving to ENDED_STATE, duration=%" G_GINT64_FORMAT " reason=%s details=%s", - (gint64) (priv->timer_started ? g_timer_elapsed (priv->timer, NULL) : -1), - _tpl_call_event_end_reason_to_str (priv->end_reason), - priv->detailed_end_reason); - } - break; - - default: - /* just wait */ - break; - } -} - - -static void -call_members_changed_cb (TpCallChannel *call, - GHashTable *updates, - GArray *removed, - TpCallStateReason reason, - gpointer user_data) -{ - TplCallChannel *self = TPL_CALL_CHANNEL (call); - TplCallChannelPriv *priv = self->priv; - GHashTableIter iter; - TpContact *contact; - - g_hash_table_iter_init (&iter, updates); - while (g_hash_table_iter_next (&iter, (gpointer *) &contact, NULL)) - { - TpHandle handle = tp_contact_get_handle (contact); - TplEntity *entity = g_hash_table_lookup (priv->entities, - GUINT_TO_POINTER (handle)); - - if (!entity) - { - entity = tpl_entity_new_from_tp_contact (contact, - TPL_ENTITY_CONTACT); - g_hash_table_insert (priv->entities, GUINT_TO_POINTER (handle), - entity); - } - } -} - - -static void -store_call (TplCallChannel *self) -{ - TplCallChannelPriv *priv = self->priv; - GError *error = NULL; - TplCallEvent *call_log; - TplLogManager *logmanager; - const gchar *channel_path = tp_proxy_get_object_path (TP_PROXY (self)); - GTimeSpan duration = -1; - - if (priv->timer_started) - duration = g_timer_elapsed (priv->timer, NULL); - - /* Initialize data for TplEntity */ - call_log = g_object_new (TPL_TYPE_CALL_EVENT, - /* TplEvent */ - "account", priv->account, - "channel-path", channel_path, - "receiver", priv->receiver, - "sender", priv->sender, - "timestamp", g_date_time_to_unix (priv->timestamp), - /* TplCallEvent */ - "duration", duration, - "end-actor", priv->end_actor, - "end-reason", priv->end_reason, - "detailed-end-reason", priv->detailed_end_reason, - NULL); - - logmanager = tpl_log_manager_dup_singleton (); - _tpl_log_manager_add_event (logmanager, TPL_EVENT (call_log), &error); - - if (error != NULL) - { - PATH_DEBUG (self, "TplCallChannel: %s", error->message); - g_error_free (error); - } - - g_object_unref (logmanager); - g_object_unref (call_log); -} - - -static void -channel_invalidated_cb (TpProxy *proxy, - guint domain, - gint code, - gchar *message, - gpointer user_data) -{ - TpChannel *chan = TP_CHANNEL (user_data); - TplObserver *observer = _tpl_observer_dup (NULL); - - g_return_if_fail (observer); - - PATH_DEBUG (chan, "%s #%d %s", - g_quark_to_string (domain), code, message); - - store_call (TPL_CALL_CHANNEL (user_data)); - - if (!_tpl_observer_unregister_channel (observer, chan)) - PATH_DEBUG (chan, "Channel couldn't be unregistered correctly (BUG?)"); - - g_object_unref (observer); -} - - -static void -connect_signals (TplCallChannel *self) -{ - tp_g_signal_connect_object (self, "state-changed", - G_CALLBACK (call_state_changed_cb), self, 0); - - tp_g_signal_connect_object (self, "members-changed", - G_CALLBACK (call_members_changed_cb), self, 0); - - tp_g_signal_connect_object (TP_CHANNEL (self), "invalidated", - G_CALLBACK (channel_invalidated_cb), self, 0); -} - - -static void -_tpl_call_channel_prepare_core_async (TpProxy *proxy, - const TpProxyFeature *feature, - GAsyncReadyCallback callback, - gpointer user_data) -{ - TplCallChannel *self = (TplCallChannel *) proxy; - GError *error = NULL; - - connect_signals (self); - - if (!get_contacts (self, &error)) - { - g_simple_async_report_take_gerror_in_idle ((GObject *) self, callback, - user_data, error); - return; - } - - tp_simple_async_report_success_in_idle ((GObject *) self, callback, user_data, - _tpl_call_channel_prepare_core_async); -} - -GQuark -_tpl_call_channel_get_feature_quark_core (void) -{ - return g_quark_from_static_string ("tpl-call-channel-feature-core"); -} - -enum { - FEAT_CORE, - N_FEAT -}; - -static const TpProxyFeature * -tpl_call_channel_list_features (TpProxyClass *cls G_GNUC_UNUSED) -{ - static TpProxyFeature features[N_FEAT + 1] = { { 0 } }; - - if (G_LIKELY (features[0].name != 0)) - return features; - - features[FEAT_CORE].name = TPL_CALL_CHANNEL_FEATURE_CORE; - features[FEAT_CORE].prepare_async = _tpl_call_channel_prepare_core_async; - - /* assert that the terminator at the end is there */ - g_assert (features[N_FEAT].name == 0); - - return features; -} - - -static void -tpl_call_channel_dispose (GObject *obj) -{ - TplCallChannelPriv *priv = TPL_CALL_CHANNEL (obj)->priv; - - tp_clear_object (&priv->account); - tp_clear_pointer (&priv->entities, g_hash_table_unref); - tp_clear_object (&priv->sender); - tp_clear_object (&priv->receiver); - tp_clear_pointer (&priv->timestamp, g_date_time_unref); - tp_clear_pointer (&priv->timer, g_timer_destroy); - tp_clear_object (&priv->end_actor); - tp_clear_pointer (&priv->detailed_end_reason, g_free); - - G_OBJECT_CLASS (_tpl_call_channel_parent_class)->dispose (obj); -} - - -static void -tpl_call_channel_finalize (GObject *obj) -{ - PATH_DEBUG (obj, "finalizing channel %p", obj); - - G_OBJECT_CLASS (_tpl_call_channel_parent_class)->finalize (obj); -} - - -static void -_tpl_call_channel_class_init (TplCallChannelClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - TpProxyClass *proxy_class = (TpProxyClass *) klass; - - object_class->dispose = tpl_call_channel_dispose; - object_class->finalize = tpl_call_channel_finalize; - - proxy_class->list_features = tpl_call_channel_list_features; - - g_type_class_add_private (object_class, sizeof (TplCallChannelPriv)); - - dbus_g_object_register_marshaller (tpl_marshal_VOID__UINT_UINT_BOXED_BOXED, - G_TYPE_NONE, - G_TYPE_UINT, G_TYPE_UINT, G_TYPE_BOXED, G_TYPE_BOXED, - G_TYPE_INVALID); - - dbus_g_object_register_marshaller (tpl_marshal_VOID__BOXED_BOXED, - G_TYPE_NONE, - G_TYPE_BOXED, G_TYPE_BOXED, - G_TYPE_INVALID); -} - - -static void -_tpl_call_channel_init (TplCallChannel *self) -{ - gchar *date; - - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - TPL_TYPE_CALL_CHANNEL, TplCallChannelPriv); - - self->priv->timestamp = g_date_time_new_now_utc (); - self->priv->timer = g_timer_new (); - - date = g_date_time_format (self->priv->timestamp, "%Y-%m-%d %H:%M:%S"); - DEBUG ("New call, timestamp=%s UTC", date); - g_free (date); - - self->priv->entities = g_hash_table_new_full (NULL, NULL, NULL, - (GDestroyNotify) g_object_unref); -} - - -/** - * _tpl_call_channel_new: - * @conn: TpConnection instance owning the channel - * @object_path: the channel's DBus path - * @tp_chan_props: channel's immutable properties, obtained for example by - * %tp_channel_borrow_immutable_properties() - * @error: location of the GError, used in case a problem is raised while - * creating the channel - * - * Convenience function to create a new TPL Call Channel proxy. - * The returned #TplCallChannel is not guaranteed to be ready - * at the point of return. - * - * TplCallChannel is actually a subclass of #TpChannel implementing - * interface #TplChannel. Use #TpChannel methods, casting the #TplCallChannel - * instance to a TpChannel, to access TpChannel data/methods from it. - * - * TplCallChannel is usually created using - * #tpl_channel_factory_build, from within a #TplObserver singleton, - * when its Observer_Channel method is called by the Channel Dispatcher. - * - * Returns: the TplCallChannel instance or %NULL if - * @object_path is not valid. - */ -TplCallChannel * -_tpl_call_channel_new (TpConnection *conn, - const gchar *object_path, - GHashTable *tp_chan_props, - GError **error) -{ - return _tpl_call_channel_new_with_factory (NULL, conn, object_path, - tp_chan_props, error); -} - -TplCallChannel * -_tpl_call_channel_new_with_factory (TpClientFactory *factory, - TpConnection *conn, - const gchar *object_path, - const GHashTable *tp_chan_props, - GError **error) -{ - TplCallChannel *self; - - /* Do what tpl_channel_new does + set TplCallChannel - * specific properties */ - - g_return_val_if_fail (TP_IS_CONNECTION (conn), NULL); - g_return_val_if_fail (!TPL_STR_EMPTY (object_path), NULL); - g_return_val_if_fail (tp_chan_props != NULL, NULL); - - if (!tp_dbus_check_valid_object_path (object_path, error)) - return NULL; - - self = g_object_new (TPL_TYPE_CALL_CHANNEL, - "factory", factory, - "connection", conn, - "dbus-daemon", tp_proxy_get_dbus_daemon (conn), - "bus-name", tp_proxy_get_bus_name (conn), - "object-path", object_path, - "handle-type", (guint) TP_UNKNOWN_HANDLE_TYPE, - "channel-properties", tp_chan_props, - NULL); - - self->priv->account = g_object_ref (tp_connection_get_account (conn)); - - return self; -} diff --git a/telepathy-logger/call-event-internal.h b/telepathy-logger/call-event-internal.h deleted file mode 100644 index 11cf810..0000000 --- a/telepathy-logger/call-event-internal.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2011 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: Nicolas Dufresne <nicolas.dufresne@collabora.co.uk> - */ - -#ifndef __TPL_CALL_EVENT_INTERNAL_H__ -#define __TPL_CALL_EVENT_INTERNAL_H__ - -#include <telepathy-logger/call-event.h> -#include <telepathy-logger/event-internal.h> - -G_BEGIN_DECLS - -struct _TplCallEvent -{ - TplEvent parent; - - /* Private */ - TplCallEventPriv *priv; -}; - -struct _TplCallEventClass -{ - TplEventClass parent_class; -}; - -const gchar * _tpl_call_event_end_reason_to_str (TpCallStateChangeReason reason); -TpCallStateChangeReason _tpl_call_event_str_to_end_reason (const gchar *str); - - -G_END_DECLS -#endif // __TPL_CALL_EVENT_INTERNAL_H__ diff --git a/telepathy-logger/call-event.c b/telepathy-logger/call-event.c deleted file mode 100644 index 68c0d86..0000000 --- a/telepathy-logger/call-event.c +++ /dev/null @@ -1,284 +0,0 @@ -/* - * Copyright (C) 2011 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: Nicolas Dufresne <nicolas.dufresne@collabora.co.uk> - */ - -#include "config.h" -#include "call-event.h" -#include "call-event-internal.h" - -#include <glib-object.h> -#include <telepathy-glib/telepathy-glib.h> - -#include "entity.h" -#include "event.h" -#include "event-internal.h" -#include "util-internal.h" - -#define DEBUG_FLAG TPL_DEBUG_LOG_EVENT -#include "debug-internal.h" - -/** - * SECTION:call-event - * @title: TplCallEvent - * @short_description: Representation of a call log event - * - * A subclass of #TplEvent representing a call log event. - */ - -/** - * TplCallEvent: - * - * An object representing a call log event. - */ - -G_DEFINE_TYPE (TplCallEvent, tpl_call_event, TPL_TYPE_EVENT) - -struct _TplCallEventPriv -{ - GTimeSpan duration; - TplEntity *end_actor; - TpCallStateChangeReason end_reason; - gchar *detailed_end_reason; -}; - -enum -{ - PROP_DURATION = 1, - PROP_END_ACTOR, - PROP_END_REASON, - PROP_DETAILED_END_REASON -}; - -static const gchar* end_reasons[] = { - "unknown", - "progress-made", - "user-requested", - "forwared", - "rejected", - "no-answer", - "invalid-contact", - "permission-denied", - "busy", - "internal-error", - "service-error", - "network-error", - "media-error", - "connectivity-error" -}; - - -static void -tpl_call_event_dispose (GObject *object) -{ - TplCallEventPriv *priv = TPL_CALL_EVENT (object)->priv; - - tp_clear_object (&priv->end_actor); - tp_clear_pointer (&priv->detailed_end_reason, g_free); - - G_OBJECT_CLASS (tpl_call_event_parent_class)->dispose (object); -} - - -static void -tpl_call_event_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - TplCallEventPriv *priv = TPL_CALL_EVENT (object)->priv; - - switch (param_id) - { - case PROP_DURATION: - g_value_set_int64 (value, priv->duration); - break; - case PROP_END_ACTOR: - g_value_set_object (value, priv->end_actor); - break; - case PROP_END_REASON: - g_value_set_int (value, priv->end_reason); - break; - case PROP_DETAILED_END_REASON: - g_value_set_string (value, priv->detailed_end_reason); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - - -static void -tpl_call_event_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - TplCallEventPriv *priv = TPL_CALL_EVENT (object)->priv; - - switch (param_id) - { - case PROP_DURATION: - priv->duration = g_value_get_int64 (value); - break; - case PROP_END_ACTOR: - priv->end_actor = g_value_dup_object (value); - break; - case PROP_END_REASON: - priv->end_reason = g_value_get_int (value); - break; - case PROP_DETAILED_END_REASON: - priv->detailed_end_reason = g_value_dup_string (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - -static void tpl_call_event_class_init (TplCallEventClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GParamSpec *param_spec; - - object_class->dispose = tpl_call_event_dispose; - object_class->get_property = tpl_call_event_get_property; - object_class->set_property = tpl_call_event_set_property; - - param_spec = g_param_spec_int64 ("duration", - "Duration", - "The call duration in seconds", - -1, G_MAXINT64, 0, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_DURATION, param_spec); - - param_spec = g_param_spec_object ("end-actor", - "End Actor", - "Actor (a #TplEntity) that caused the call to end", - TPL_TYPE_ENTITY, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_END_ACTOR, param_spec); - - param_spec = g_param_spec_int ("end-reason", - "End Reason", - "Reason for wich this call was ended", - 0, TP_NUM_CALL_STATE_CHANGE_REASONS, TP_CALL_STATE_CHANGE_REASON_UNKNOWN, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_END_REASON, param_spec); - - param_spec = g_param_spec_string ("detailed-end-reason", - "Detailed End Reason", - "A string representing a D-Bus error that gives more details about the end reason", - "", - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_DETAILED_END_REASON, param_spec); - - g_type_class_add_private (object_class, sizeof (TplCallEventPriv)); -} - - -static void -tpl_call_event_init (TplCallEvent *self) -{ - TplCallEventPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - TPL_TYPE_CALL_EVENT, TplCallEventPriv); - self->priv = priv; -} - - -/** - * tpl_call_event_get_duration: - * @self: a #TplCallEvent - * - * Returns: the same duration as the #TplCallEvent:duration property - */ -GTimeSpan -tpl_call_event_get_duration (TplCallEvent *self) -{ - g_return_val_if_fail (TPL_IS_CALL_EVENT (self), 0); - - return self->priv->duration; -} - -/** - * tpl_call_event_get_end_actor: - * @self: a #TplCallEvent - * - * Returns: (transfer none): the same #TplEntity - * as #TplCallEvent:end-actor property - */ -TplEntity * -tpl_call_event_get_end_actor (TplCallEvent *self) -{ - g_return_val_if_fail (TPL_IS_CALL_EVENT (self), NULL); - - return self->priv->end_actor; -} - - -/** - * tpl_call_event_get_end_reason: - * @self: a #TplCallEvent - * - * Returns: the same #TpCallStateChangeReason as #TplCallEvent:end-reason property - */ -TpCallStateChangeReason -tpl_call_event_get_end_reason (TplCallEvent *self) -{ - g_return_val_if_fail (TPL_IS_CALL_EVENT (self), - TP_CALL_STATE_CHANGE_REASON_UNKNOWN); - - return self->priv->end_reason; -} - - -/** - * tpl_call_event_get_detailed_end_reason: - * @self: a #TplCallEvent - * - * Returns: (transfer none): the same string as the - * #TplCallEvent:detailed-end-reason property - */ -const gchar * -tpl_call_event_get_detailed_end_reason (TplCallEvent *self) -{ - g_return_val_if_fail (TPL_IS_CALL_EVENT (self), ""); - - return self->priv->detailed_end_reason; -} - - -const gchar * -_tpl_call_event_end_reason_to_str (TpCallStateChangeReason reason) -{ - g_return_val_if_fail (reason < G_N_ELEMENTS (end_reasons), end_reasons[0]); - return end_reasons[reason]; -} - - -TpCallStateChangeReason -_tpl_call_event_str_to_end_reason (const gchar *str) -{ - guint i; - for (i = 0; i < G_N_ELEMENTS (end_reasons); i++) - if (g_strcmp0 (str, end_reasons[i]) == 0) - return i; - - return TP_CALL_STATE_CHANGE_REASON_UNKNOWN; -} diff --git a/telepathy-logger/call-event.h b/telepathy-logger/call-event.h deleted file mode 100644 index 85dd890..0000000 --- a/telepathy-logger/call-event.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2011 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: Nicolas Dufresne <nicolas.dufresne@collabora.co.uk> - */ - -#ifndef __TPL_CALL_EVENT_H__ -#define __TPL_CALL_EVENT_H__ - -#include <glib-object.h> - -#include <telepathy-logger/event.h> - -G_BEGIN_DECLS -#define TPL_TYPE_CALL_EVENT (tpl_call_event_get_type ()) -#define TPL_CALL_EVENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_CALL_EVENT, TplCallEvent)) -#define TPL_CALL_EVENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TPL_TYPE_CALL_EVENT, TplCallEventClass)) -#define TPL_IS_CALL_EVENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_CALL_EVENT)) -#define TPL_IS_CALL_EVENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TPL_TYPE_CALL_EVENT)) -#define TPL_CALL_EVENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_CALL_EVENT, TplCallEventClass)) - -typedef struct _TplCallEvent TplCallEvent; -typedef struct _TplCallEventClass TplCallEventClass; -typedef struct _TplCallEventPriv TplCallEventPriv; - -GType tpl_call_event_get_type (void); - -GTimeSpan tpl_call_event_get_duration (TplCallEvent *self); -TplEntity * tpl_call_event_get_end_actor (TplCallEvent *self); -TpCallStateChangeReason tpl_call_event_get_end_reason (TplCallEvent *self); -const gchar * tpl_call_event_get_detailed_end_reason (TplCallEvent *self); - - -G_END_DECLS -#endif // __TPL_CALL_EVENT_H__ diff --git a/telepathy-logger/client-factory-internal.h b/telepathy-logger/client-factory-internal.h deleted file mode 100644 index f678d64..0000000 --- a/telepathy-logger/client-factory-internal.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2012 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: Xavier Claessens <xavier.claessens@collabora.co.uk> - */ - -#ifndef __TPL_CLIENT_FACTORY_H__ -#define __TPL_CLIENT_FACTORY_H__ - -#include <telepathy-glib/telepathy-glib.h> -#include <telepathy-glib/telepathy-glib-dbus.h> - -typedef struct _TplClientFactory TplClientFactory; -typedef struct _TplClientFactoryClass TplClientFactoryClass; - -struct _TplClientFactoryClass { - /*<public>*/ - TpAutomaticClientFactoryClass parent_class; -}; - -struct _TplClientFactory { - /*<private>*/ - TpAutomaticClientFactory parent; -}; - -GType _tpl_client_factory_get_type (void); - -#define TPL_TYPE_CLIENT_FACTORY \ - (_tpl_client_factory_get_type ()) -#define TPL_CLIENT_FACTORY(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_CLIENT_FACTORY, \ - TplClientFactory)) -#define TPL_CLIENT_FACTORY_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), TPL_TYPE_CLIENT_FACTORY, \ - TplClientFactoryClass)) -#define TPL_IS_CLIENT_FACTORY(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_CLIENT_FACTORY)) -#define TPL_IS_CLIENT_FACTORY_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), TPL_TYPE_CLIENT_FACTORY)) -#define TPL_CLIENT_FACTORY_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_CLIENT_FACTORY, \ - TplClientFactoryClass)) - -TpClientFactory *_tpl_client_factory_dup (TpDBusDaemon *dbus); - -#endif /* __TPL_CLIENT_FACTORY_H__ */ diff --git a/telepathy-logger/client-factory.c b/telepathy-logger/client-factory.c deleted file mode 100644 index cedd189..0000000 --- a/telepathy-logger/client-factory.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (C) 2012 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: Xavier Claessens <xavier.claessens@collabora.co.uk> - */ - -#include "config.h" -#include "client-factory-internal.h" - -#include <telepathy-glib/telepathy-glib.h> - -#include <telepathy-logger/text-channel-internal.h> -#include <telepathy-logger/call-channel-internal.h> - -G_DEFINE_TYPE (TplClientFactory, _tpl_client_factory, - TP_TYPE_AUTOMATIC_CLIENT_FACTORY) - -#define chainup ((TpClientFactoryClass *) \ - _tpl_client_factory_parent_class) - -static TpChannel * -create_channel_impl (TpClientFactory *self, - TpConnection *conn, - const gchar *object_path, - const GHashTable *properties, - GError **error) -{ - const gchar *chan_type; - - chan_type = tp_asv_get_string (properties, TP_PROP_CHANNEL_CHANNEL_TYPE); - - if (!tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_TEXT)) - { - return (TpChannel *) _tpl_text_channel_new_with_factory (self, conn, - object_path, properties, error); - } - else if (!tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_CALL1)) - { - return (TpChannel *) _tpl_call_channel_new_with_factory (self, conn, - object_path, properties, error); - } - - return chainup->create_channel (self, conn, object_path, properties, error); -} - -static GArray * -dup_channel_features_impl (TpClientFactory *self, - TpChannel *channel) -{ - GArray *features; - GQuark f; - - features = chainup->dup_channel_features (self, channel); - - if (TPL_IS_CALL_CHANNEL (channel)) - { - f = TPL_CALL_CHANNEL_FEATURE_CORE; - g_array_append_val (features, f); - } - else if (TPL_IS_TEXT_CHANNEL (channel)) - { - f = TPL_TEXT_CHANNEL_FEATURE_CORE; - g_array_append_val (features, f); - } - - return features; -} - -static void -_tpl_client_factory_init (TplClientFactory *self) -{ -} - -static void -_tpl_client_factory_class_init (TplClientFactoryClass *cls) -{ - TpClientFactoryClass *simple_class = (TpClientFactoryClass *) cls; - - simple_class->create_channel = create_channel_impl; - simple_class->dup_channel_features = dup_channel_features_impl; -} - - -static TpClientFactory * -_tpl_client_factory_new (TpDBusDaemon *dbus) -{ - return g_object_new (TPL_TYPE_CLIENT_FACTORY, - "dbus-daemon", dbus, - NULL); -} - -TpClientFactory * -_tpl_client_factory_dup (TpDBusDaemon *dbus) -{ - static TpClientFactory *singleton = NULL; - - if (singleton != NULL) - return g_object_ref (singleton); - - singleton = _tpl_client_factory_new (dbus); - - g_object_add_weak_pointer (G_OBJECT (singleton), (gpointer) &singleton); - - return singleton; -} diff --git a/telepathy-logger/conf-internal.h b/telepathy-logger/conf-internal.h deleted file mode 100644 index f88aa33..0000000 --- a/telepathy-logger/conf-internal.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2009 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: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - */ - -#ifndef __TPL_CONF_H__ -#define __TPL_CONF_H__ - -#include <glib-object.h> - -G_BEGIN_DECLS - -#define TPL_TYPE_CONF (_tpl_conf_get_type ()) -#define TPL_CONF(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_CONF, TplConf)) -#define TPL_CONF_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TPL_TYPE_CONF, TplConfClass)) -#define TPL_IS_CONF(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_CONF)) -#define TPL_IS_CONF_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TPL_TYPE_CONF)) -#define TPL_CONF_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_CONF, TplConfClass)) - -typedef struct -{ - GObject parent; - - /* private */ - gpointer priv; -} TplConf; - -typedef struct -{ - GObjectClass parent_class; -} TplConfClass; - -GType _tpl_conf_get_type (void); -TplConf *_tpl_conf_dup (void); - -gboolean _tpl_conf_is_globally_enabled (TplConf *self); -const gchar **_tpl_conf_get_ignorelist (TplConf *self); - -void _tpl_conf_globally_enable (TplConf *self, gboolean enable); -void _tpl_conf_set_ignorelist (TplConf *self, const gchar **newlist); -G_END_DECLS - -#endif // __TPL_CONF_H__ diff --git a/telepathy-logger/conf.c b/telepathy-logger/conf.c deleted file mode 100644 index 888114d..0000000 --- a/telepathy-logger/conf.c +++ /dev/null @@ -1,308 +0,0 @@ -/* - * Copyright (C) 2009-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: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - * Danielle Madeley <danielle.madeley@collabora.co.uk> - */ - -#include "config.h" -#include "conf-internal.h" - -#include <glib.h> -#include <gio/gio.h> -#include <telepathy-glib/telepathy-glib.h> - -#define DEBUG_FLAG TPL_DEBUG_CONF -#include <telepathy-logger/debug-internal.h> -#include <telepathy-logger/util-internal.h> - -#define GET_PRIV(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TPL_TYPE_CONF, TplConfPriv)) - -#define GSETTINGS_SCHEMA "org.freedesktop.Telepathy.Logger" -#define KEY_ENABLED "enabled" - -G_DEFINE_TYPE (TplConf, _tpl_conf, G_TYPE_OBJECT) - -static TplConf *conf_singleton = NULL; - -typedef struct -{ - gboolean test_mode; - gchar **ignore_list; - GSettings *gsettings; -} TplConfPriv; - - -enum /* properties */ -{ - PROP_0, - PROP_GLOBALLY_ENABLED, - PROP_IGNORE_LIST, -}; - - -static void -_notify_globally_enable (GSettings *gsettings, - const gchar *key, - GObject *self) -{ - g_object_notify (self, "globally-enabled"); -} - - -static void -tpl_conf_get_property (GObject *self, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - switch (prop_id) - { - case PROP_GLOBALLY_ENABLED: - g_value_set_boolean (value, - _tpl_conf_is_globally_enabled (TPL_CONF (self))); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (self, prop_id, pspec); - break; - } -} - -static void -tpl_conf_set_property (GObject *self, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - switch (prop_id) - { - case PROP_GLOBALLY_ENABLED: - _tpl_conf_globally_enable (TPL_CONF (self), - g_value_get_boolean (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (self, prop_id, pspec); - break; - } -} - - -static void -tpl_conf_finalize (GObject *obj) -{ - TplConfPriv *priv; - - priv = GET_PRIV (obj); - - g_strfreev (priv->ignore_list); - priv->ignore_list = NULL; - - if (priv->gsettings != NULL) - { - g_object_unref (priv->gsettings); - priv->gsettings = NULL; - } - - G_OBJECT_CLASS (_tpl_conf_parent_class)->finalize (obj); -} - - -static GObject * -tpl_conf_constructor (GType type, - guint n_props, - GObjectConstructParam *props) -{ - GObject *retval; - - if (conf_singleton != NULL) - { - retval = g_object_ref (conf_singleton); - } - else - { - retval = G_OBJECT_CLASS (_tpl_conf_parent_class)->constructor (type, - n_props, props); - conf_singleton = TPL_CONF (retval); - g_object_add_weak_pointer (retval, (gpointer *) &conf_singleton); - } - return retval; -} - - -static void -_tpl_conf_class_init (TplConfClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->get_property = tpl_conf_get_property; - object_class->set_property = tpl_conf_set_property; - object_class->finalize = tpl_conf_finalize; - object_class->constructor = tpl_conf_constructor; - - g_object_class_install_property (object_class, PROP_GLOBALLY_ENABLED, - g_param_spec_boolean ("globally-enabled", - "Globally Enabled", - "TRUE if logging is enabled (may still be disabled for specific users)", - TRUE, - G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE)); - - g_object_class_install_property (object_class, PROP_IGNORE_LIST, - g_param_spec_pointer ("ignore-list", - "Ignore List", - "List of TplEntities with which not to log conversations.", - G_PARAM_READWRITE)); - - g_type_class_add_private (object_class, sizeof (TplConfPriv)); -} - - -static void -_tpl_conf_init (TplConf *self) -{ - TplConfPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - TPL_TYPE_CONF, TplConfPriv); - - if (g_getenv ("TPL_TEST_MODE") != NULL) - { - priv->test_mode = TRUE; - } - else - { - priv->gsettings = g_settings_new (GSETTINGS_SCHEMA); - - g_signal_connect (priv->gsettings, "changed::" KEY_ENABLED, - G_CALLBACK (_notify_globally_enable), self); - } - - priv->ignore_list = NULL; -} - - -/** - * _tpl_conf_dup: - * - * Convenience function to obtain a TPL Configuration object, which is a - * singleton. - * - * Returns: a TplConf signleton instance with its reference counter - * incremented. Remember to unref the counter. - */ -TplConf * -_tpl_conf_dup (void) -{ - return g_object_new (TPL_TYPE_CONF, NULL); -} - - -/** - * _tpl_conf_is_globally_enabled: - * @self: a TplConf instance - * - * Whether TPL is globally enabled or not. If it's not globally enabled, no - * signals will be logged at all. - * To enable/disable a single account use _tpl_conf_set_accounts_ignorelist() - * - * Returns: %TRUE if TPL logging is globally enabled, otherwise returns - * %FALSE. - */ -gboolean -_tpl_conf_is_globally_enabled (TplConf *self) -{ - g_return_val_if_fail (TPL_IS_CONF (self), FALSE); - - if (GET_PRIV (self)->test_mode) - return TRUE; - else - return g_settings_get_boolean (GET_PRIV (self)->gsettings, KEY_ENABLED); -} - - -/** - * _tpl_conf_globally_enable: - * @self: a TplConf instance - * @enable: wether to globally enable or globally disable logging. - * - * Globally enables or disables logging for TPL. If it's globally disabled, no - * signals will be logged at all. - * Note that this will change the global TPL configuration, affecting all the - * TPL instances, including the TPL logging process and all the clients using - * libtelepathy-logger. - */ -void -_tpl_conf_globally_enable (TplConf *self, - gboolean enable) -{ - g_return_if_fail (TPL_IS_CONF (self)); - - if (GET_PRIV (self)->test_mode) - return; - - g_settings_set_boolean (GET_PRIV (self)->gsettings, - KEY_ENABLED, enable); -} - -/** - * _tpl_conf_set_accounts_ignorelist: - * @self: a TplConf instance - * @newlist: a NULL-terminated list of account/entity IDs that should not be logged - */ -void -_tpl_conf_set_ignorelist (TplConf *self, - const gchar **newlist) -{ - TplConfPriv *priv; - - g_return_if_fail (TPL_IS_CONF (self)); - - priv = GET_PRIV (self); - - if (!priv->test_mode) { - g_settings_set_strv (GET_PRIV (self)->gsettings, "ignorelist", newlist); - } - - g_strfreev (priv->ignore_list); - priv->ignore_list = g_strdupv ((gchar **) newlist); - - g_object_notify (G_OBJECT (self), "ignore-list"); -} - -/** - * _tpl_conf_get_accounts_ignorelist: - * @self: a TplConf instance - * - * Provides list of IDs in "account_id/entity_id" format. Events from or to - * this entities should not be logged. - * - * Returns: (transfer none) NULL-terminated list of contact IDs. - */ -const gchar ** -_tpl_conf_get_ignorelist (TplConf *self) -{ - TplConfPriv *priv; - - g_return_val_if_fail (TPL_IS_CONF (self), NULL); - - priv = GET_PRIV (self); - - if ((priv->ignore_list == NULL) && (!priv->test_mode)) { - priv->ignore_list = g_settings_get_strv (priv->gsettings, "ignorelist"); - } - - return (const gchar **) priv->ignore_list; -} diff --git a/telepathy-logger/dbus-service-internal.h b/telepathy-logger/dbus-service-internal.h deleted file mode 100644 index b2dc657..0000000 --- a/telepathy-logger/dbus-service-internal.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) 2009 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: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - */ - -#ifndef __TPL_DBUS_SERVICE_H__ -#define __TPL_DBUS_SERVICE_H__ - -#include <glib-object.h> -#include <telepathy-glib/telepathy-glib.h> - -#include <telepathy-logger/log-manager.h> - -#define TPL_DBUS_SRV_WELL_KNOWN_BUS_NAME \ - "im.telepathy1.Logger" -#define TPL_DBUS_SRV_OBJECT_PATH \ - "/im.telepathy1/Logger" - -G_BEGIN_DECLS - -#define TPL_TYPE_DBUS_SERVICE (_tpl_dbus_service_get_type ()) -#define TPL_DBUS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_DBUS_SERVICE, TplDBusService)) -#define TPL_DBUS_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TPL_TYPE_DBUS_SERVICE, TplDBusServiceClass)) -#define TPL_IS_DBUS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_DBUS_SERVICE)) -#define TPL_IS_DBUS_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TPL_TYPE_DBUS_SERVICE)) -#define TPL_DBUS_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_DBUS_SERVICE, TplDBusServiceClass)) - -#define TPL_DBUS_SERVICE_ERROR g_quark_from_string ( \ - "tpl-dbus-service-error-quark") -typedef enum -{ - TPL_DBUS_SERVICE_ERROR_FAILED, - /* >= 1 argument(s) is/are invalid */ - TPL_DBUS_SERVICE_ERROR_INVALID_ARGS, - TPL_DBUS_SERVICE_ERROR_NOT_READY, -} TplDBusServiceError; - -typedef struct _TplDBusServicePriv TplDBusServicePriv; -typedef struct -{ - GObject parent; - /* Private */ - TplDBusServicePriv *priv; -} TplDBusService; - - -typedef struct -{ - GObjectClass parent_class; -} TplDBusServiceClass; - -typedef struct -{ - long unsigned timestamp; - gchar *sender; - gchar *message; -} TplDBusServiceChatMessage; - -GType _tpl_dbus_service_get_type (void); - -TplDBusService * _tpl_dbus_service_new (void); - -G_END_DECLS - -#endif diff --git a/telepathy-logger/dbus-service.c b/telepathy-logger/dbus-service.c deleted file mode 100644 index 1bc79f9..0000000 --- a/telepathy-logger/dbus-service.c +++ /dev/null @@ -1,870 +0,0 @@ -/* - * Copyright (C) 2009-2011 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: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - */ - -#include "config.h" -#include "dbus-service-internal.h" - -#include <string.h> -#include <sys/stat.h> - -#include <glib.h> -#include <telepathy-glib/telepathy-glib.h> -#include <telepathy-glib/telepathy-glib-dbus.h> - -#include <telepathy-logger/event-internal.h> -#include <telepathy-logger/text-event.h> -#include <telepathy-logger/log-manager.h> -#include <telepathy-logger/log-manager-internal.h> -#include <telepathy-logger/client-factory-internal.h> - -#include <extensions/extensions.h> - -#define DEBUG_FLAG TPL_DEBUG_DBUS_SERVICE -#include <telepathy-logger/action-chain-internal.h> -#include <telepathy-logger/debug-internal.h> -#include <telepathy-logger/util-internal.h> - -#define FAVOURITE_CONTACTS_FILENAME "favourite-contacts.txt" - -static void tpl_logger_iface_init (gpointer iface, gpointer iface_data); - -struct _TplDBusServicePriv -{ - TplLogManager *manager; - /* map of (string) account name -> (string set) contact ID */ - /* (the set is implemented as a hash table) */ - GHashTable *accounts_contacts_map; - TplActionChain *favourite_contacts_actions; -}; - -G_DEFINE_TYPE_WITH_CODE (TplDBusService, _tpl_dbus_service, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (TPL_TYPE_SVC_LOGGER, tpl_logger_iface_init)); - -typedef struct _FavouriteContactClosure FavouriteContactClosure; -typedef void (*FavouriteContactCallback) (gboolean success, - FavouriteContactClosure *closure); - - -struct _FavouriteContactClosure { - TplDBusService *service; - gchar *account; - gchar *contact_id; - gchar *file_contents; - DBusGMethodInvocation *context; - FavouriteContactCallback cb; -}; - - -static void -favourite_contact_closure_free (FavouriteContactClosure *closure) -{ - if (closure == NULL) - return; - - if (closure->service != NULL) - g_object_unref (closure->service); - - g_free (closure->account); - g_free (closure->contact_id); - g_free (closure->file_contents); - g_slice_free (FavouriteContactClosure, closure); -} - - -static FavouriteContactClosure * -favourite_contact_closure_new (TplDBusService *self, - const gchar *account, - const gchar *contact_id, - DBusGMethodInvocation *context) -{ - FavouriteContactClosure *closure; - - closure = g_slice_new0 (FavouriteContactClosure); - closure->service = g_object_ref (G_OBJECT (self)); - closure->account = g_strdup (account); - closure->contact_id = g_strdup (contact_id); - /* XXX: ideally we'd up the ref count or duplicate this */ - closure->context = context; - - return closure; -} - - -static gboolean -favourite_contacts_add_event (TplDBusService *self, - const gchar *account, - const gchar *contact_id) -{ - GHashTable *contacts; - gboolean new_event = FALSE; - TplDBusServicePriv *priv; - - g_return_val_if_fail (TPL_IS_DBUS_SERVICE (self), FALSE); - g_return_val_if_fail (account != NULL, FALSE); - g_return_val_if_fail (contact_id != NULL, FALSE); - - priv = self->priv; - - DEBUG ("adding favourite contact: account '%s', ID '%s'", - account, contact_id); - - contacts = g_hash_table_lookup (priv->accounts_contacts_map, account); - if (contacts == NULL) - { - contacts = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify) g_free, NULL); - g_hash_table_insert (priv->accounts_contacts_map, g_strdup (account), - contacts); - new_event = TRUE; - } - else if (g_hash_table_lookup (contacts, contact_id) == NULL) - { - new_event = TRUE; - } - - if (new_event) - { - /* add dummy string for the value just for the convenience of looking up - * whether the key already exists */ - g_hash_table_insert (contacts, g_strdup (contact_id), - GINT_TO_POINTER (TRUE)); - } - - return new_event; -} - - -static const gchar * -favourite_contacts_get_filename (void) -{ - static gchar *filename = NULL; - - if (filename == NULL) - { - filename = g_build_filename (g_get_user_data_dir (), TPL_DATA_DIR, - FAVOURITE_CONTACTS_FILENAME, NULL); - } - - return filename; -} - - -static gboolean -favourite_contacts_parse_line (TplDBusService *self, - const gchar *line) -{ - gboolean success = TRUE; - gchar **elements; - - if (line == NULL || line[0] == '\0') - return TRUE; - - /* this works on the assumption that account names can't have spaces in them - */ - elements = g_strsplit (line, " ", 2); - if (g_strv_length (elements) < 2) - { - DEBUG ("invalid number of elements on favourite contacts file line:\n" - "%s\n", line); - success = FALSE; - } - else - favourite_contacts_add_event (self, elements[0], elements[1]); - - g_strfreev (elements); - - return success; -} - - -static void -favourite_contacts_file_read_line_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - GDataInputStream *data_stream = G_DATA_INPUT_STREAM (object); - TplActionChain *action_chain = (TplActionChain *) (user_data); - TplDBusService *self = _tpl_action_chain_get_object (action_chain); - gchar *line; - GError *error = NULL; - - line = g_data_input_stream_read_line_finish (data_stream, result, NULL, &error); - - if (error != NULL) - { - g_prefix_error (&error, "failed to open favourite contacts file: "); - _tpl_action_chain_terminate (action_chain, error); - g_clear_error (&error); - } - else if (line != NULL) - { - favourite_contacts_parse_line (self, line); - - g_data_input_stream_read_line_async (data_stream, G_PRIORITY_DEFAULT, - NULL, favourite_contacts_file_read_line_cb, action_chain); - } - else - _tpl_action_chain_continue (action_chain); -} - - -static void -favourite_contacts_file_open_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - GFile *file = G_FILE (object); - TplActionChain *action_chain = (TplActionChain *) user_data; - GFileInputStream *stream; - GError *error = NULL; - - if ((stream = g_file_read_finish (file, result, &error))) - { - GDataInputStream *data_stream = g_data_input_stream_new ( - G_INPUT_STREAM (stream)); - - g_data_input_stream_read_line_async (data_stream, G_PRIORITY_DEFAULT, - NULL, favourite_contacts_file_read_line_cb, action_chain); - - g_object_unref (stream); - } - else if (error->code == G_IO_ERROR_NOT_FOUND) - { - DEBUG ("Favourite contacts file doesn't exist yet. Will create as " - "necessary."); - - g_clear_error (&error); - _tpl_action_chain_continue (action_chain); - } - else - { - g_prefix_error (&error, "Failed to open the favourite contacts file: "); - _tpl_action_chain_terminate (action_chain, error); - g_clear_error (&error); - } -} - - -static void -pendingproc_favourite_contacts_file_open (TplActionChain *action_chain, - gpointer user_data) -{ - const gchar *filename; - GFile *file; - - filename = favourite_contacts_get_filename (); - file = g_file_new_for_path (filename); - - g_file_read_async (file, G_PRIORITY_DEFAULT, NULL, - favourite_contacts_file_open_cb, action_chain); - - g_object_unref (G_OBJECT (file)); -} - - -static void -tpl_dbus_service_dispose (GObject *obj) -{ - TplDBusServicePriv *priv = TPL_DBUS_SERVICE (obj)->priv; - - if (priv->accounts_contacts_map != NULL) - { - g_hash_table_unref (priv->accounts_contacts_map); - priv->accounts_contacts_map = NULL; - } - - if (priv->favourite_contacts_actions != NULL) - priv->favourite_contacts_actions = NULL; - - G_OBJECT_CLASS (_tpl_dbus_service_parent_class)->dispose (obj); -} - - -static void -favourite_contacts_file_parsed_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - TplDBusService *self = TPL_DBUS_SERVICE (object); - TplDBusServicePriv *priv = self->priv; - GError *error = NULL; - - if (!_tpl_action_chain_new_finish (object, result, &error)) - { - DEBUG ("Failed to parse the favourite contacts file and/or execute " - "subsequent queued method calls: %s", error->message); - g_error_free (error); - } - - priv->favourite_contacts_actions = NULL; -} - - -static void -tpl_dbus_service_constructed (GObject *object) -{ - TplDBusServicePriv *priv = TPL_DBUS_SERVICE (object)->priv; - - priv->favourite_contacts_actions = _tpl_action_chain_new_async (object, - favourite_contacts_file_parsed_cb, object); - - _tpl_action_chain_append (priv->favourite_contacts_actions, - pendingproc_favourite_contacts_file_open, NULL); - _tpl_action_chain_continue (priv->favourite_contacts_actions); -} - - -static void -_tpl_dbus_service_class_init (TplDBusServiceClass *klass) -{ - GObjectClass* object_class = G_OBJECT_CLASS (klass); - - object_class->constructed = tpl_dbus_service_constructed; - object_class->dispose = tpl_dbus_service_dispose; - - g_type_class_add_private (object_class, sizeof (TplDBusServicePriv)); -} - - -static void -_tpl_dbus_service_init (TplDBusService *self) -{ - TplDBusServicePriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - TPL_TYPE_DBUS_SERVICE, TplDBusServicePriv); - - g_return_if_fail (TPL_IS_DBUS_SERVICE (self)); - - self->priv = priv; - priv->manager = tpl_log_manager_dup_singleton (); - priv->accounts_contacts_map = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify) g_free, (GDestroyNotify) g_hash_table_unref); - priv->favourite_contacts_actions = NULL; -} - - -TplDBusService * -_tpl_dbus_service_new (void) -{ - return g_object_new (TPL_TYPE_DBUS_SERVICE, NULL); -} - - -static void -append_favourite_contacts_account_and_contacts (const gchar *account, - GHashTable *contacts, - GPtrArray *packed) -{ - GList *l; - gchar **contact_ids; - gint i; - - /* this case shouldn't happen, but this is just some basic sanity checking */ - if (g_hash_table_size (contacts) < 1) - return; - - /* includes room for the terminal NULL */ - contact_ids = g_new0 (gchar *, g_hash_table_size (contacts)+1); - - for (i = 0, l = g_hash_table_get_keys (contacts); - l; - i++, l = g_list_delete_link (l, l)) - { - contact_ids[i] = l->data; - } - - g_ptr_array_add (packed, tp_value_array_build (2, - DBUS_TYPE_G_OBJECT_PATH, account, - G_TYPE_STRV, contact_ids, - G_TYPE_INVALID)); - - g_free (contact_ids); -} - - -static void -pendingproc_get_favourite_contacts (TplActionChain *action_chain, - gpointer user_data) -{ - FavouriteContactClosure *closure = user_data; - TplDBusServicePriv *priv; - GPtrArray *packed; - - g_return_if_fail (closure); - g_return_if_fail (TPL_IS_DBUS_SERVICE (closure->service)); - g_return_if_fail (closure->context != NULL); - - priv = closure->service->priv; - - packed = g_ptr_array_new_with_free_func ((GDestroyNotify) g_value_array_free); - - g_hash_table_foreach (priv->accounts_contacts_map, - (GHFunc) append_favourite_contacts_account_and_contacts, packed); - - tpl_svc_logger_return_from_get_favourite_contacts (closure->context, packed); - - g_ptr_array_unref (packed); - favourite_contact_closure_free (closure); - - if (action_chain != NULL) - _tpl_action_chain_continue (action_chain); -} - - -static void -tpl_dbus_service_get_favourite_contacts (TplSvcLogger *logger, - DBusGMethodInvocation *context) -{ - TplDBusService *self; - TplDBusServicePriv *priv; - FavouriteContactClosure *closure; - - g_return_if_fail (TPL_IS_DBUS_SERVICE (logger)); - g_return_if_fail (context != NULL); - - self = TPL_DBUS_SERVICE (logger); - priv = self->priv; - - closure = favourite_contact_closure_new (self, NULL, NULL, context); - - /* If we're still waiting on the contacts to finish being parsed from disk, - * queue this action */ - if (priv->favourite_contacts_actions != NULL) - { - _tpl_action_chain_append (priv->favourite_contacts_actions, - pendingproc_get_favourite_contacts, closure); - } - else - pendingproc_get_favourite_contacts (NULL, closure); -} - - -static void -append_favourite_contacts_file_entries (const gchar *account, - GHashTable *contacts, - GString *string) -{ - GList *l; - - for (l = g_hash_table_get_keys (contacts); l; l = g_list_delete_link (l, l)) - g_string_append_printf (string, "%s %s\n", account, (const gchar*) l->data); -} - - -static gchar * -favourite_contacts_to_string (TplDBusService *self) -{ - TplDBusServicePriv *priv = self->priv; - GString *string; - - string = g_string_new (""); - - g_hash_table_foreach (priv->accounts_contacts_map, - (GHFunc) append_favourite_contacts_file_entries, string); - - return g_string_free (string, FALSE); -} - - -static void -favourite_contacts_file_replace_contents_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - GFile *file = G_FILE (object); - GError *error = NULL; - FavouriteContactClosure *closure = user_data; - gboolean success; - - if (g_file_replace_contents_finish (file, result, NULL, &error)) - { - success = TRUE; - } - else - { - DEBUG ("Failed to save favourite contacts file: %s", error->message); - success = FALSE; - g_clear_error (&error); - } - - ((FavouriteContactCallback) closure->cb) (success, closure); -} - - -static void -favourite_contacts_file_save_async (TplDBusService *self, - FavouriteContactClosure *closure) -{ - gchar *dir; - const gchar *filename; - GFile *file; - gchar *file_contents; - - g_return_if_fail (closure != NULL); - - filename = favourite_contacts_get_filename (); - dir = g_path_get_dirname (filename); - g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR); - g_free (dir); - - file = g_file_new_for_path (filename); - - file_contents = favourite_contacts_to_string (self); - - closure->file_contents = file_contents; - - g_file_replace_contents_async (file, - file_contents, strlen (file_contents), NULL, FALSE, - G_FILE_CREATE_REPLACE_DESTINATION, NULL, - favourite_contacts_file_replace_contents_cb, closure); - - g_object_unref (file); -} - - -static void -add_favourite_contact_file_save_cb (gboolean added_favourite, - FavouriteContactClosure *closure) -{ - TplDBusServicePriv *priv = closure->service->priv; - TplActionChain *action_chain = priv->favourite_contacts_actions; - - if (added_favourite) - { - const gchar *added[] = { NULL, NULL }; - const gchar *removed[] = { NULL }; - - added[0] = closure->contact_id; - - tpl_svc_logger_emit_favourite_contacts_changed (closure->service, - closure->account, added, removed); - } - - tpl_svc_logger_return_from_add_favourite_contact (closure->context); - - favourite_contact_closure_free (closure); - if (action_chain != NULL) - _tpl_action_chain_continue (action_chain); -} - - -static void -pendingproc_add_favourite_contact (TplActionChain *action_chain, - gpointer user_data) -{ - FavouriteContactClosure *closure = user_data; - gboolean should_add = FALSE; - GError *error = NULL; - - g_return_if_fail (closure); - g_return_if_fail (TPL_IS_DBUS_SERVICE (closure->service)); - g_return_if_fail (closure->context != NULL); - - if (!tp_dbus_check_valid_object_path (closure->account, &error)) - { - dbus_g_method_return_error (closure->context, error); - - goto pendingproc_add_favourite_contact_ERROR; - } - - should_add = favourite_contacts_add_event (closure->service, closure->account, - closure->contact_id); - - closure->cb = add_favourite_contact_file_save_cb; - - if (should_add) - favourite_contacts_file_save_async (closure->service, closure); - else - add_favourite_contact_file_save_cb (FALSE, closure); - - return; - -pendingproc_add_favourite_contact_ERROR: - if (action_chain != NULL) - _tpl_action_chain_terminate (action_chain, error); - - g_clear_error (&error); -} - - -static void -tpl_dbus_service_add_favourite_contact (TplSvcLogger *logger, - const gchar *account, - const gchar *contact_id, - DBusGMethodInvocation *context) -{ - TplDBusService *self = TPL_DBUS_SERVICE (logger); - TplDBusServicePriv *priv; - FavouriteContactClosure *closure; - - g_return_if_fail (TPL_IS_DBUS_SERVICE (self)); - g_return_if_fail (context != NULL); - - priv = self->priv; - - closure = favourite_contact_closure_new (self, account, contact_id, context); - - /* If we're still waiting on the contacts to finish being parsed from disk, - * queue this action */ - if (priv->favourite_contacts_actions != NULL) - { - _tpl_action_chain_append (priv->favourite_contacts_actions, - pendingproc_add_favourite_contact, closure); - } - else - pendingproc_add_favourite_contact (NULL, closure); -} - -static void -remove_favourite_contact_file_save_cb (gboolean removed_favourite, - FavouriteContactClosure *closure) -{ - TplDBusServicePriv *priv = closure->service->priv; - TplActionChain *action_chain = priv->favourite_contacts_actions; - - if (removed_favourite) - { - const gchar *added[] = { NULL }; - const gchar *removed[] = { NULL, NULL }; - - removed[0] = closure->contact_id; - - tpl_svc_logger_emit_favourite_contacts_changed (closure->service, - closure->account, added, removed); - } - - tpl_svc_logger_return_from_remove_favourite_contact (closure->context); - - favourite_contact_closure_free (closure); - if (action_chain != NULL) - _tpl_action_chain_continue (action_chain); -} - - -static void -pendingproc_remove_favourite_contact (TplActionChain *action_chain, - gpointer user_data) -{ - FavouriteContactClosure *closure = user_data; - GHashTable *contacts; - gboolean removed = FALSE; - GError *error = NULL; - - g_return_if_fail (closure != NULL); - g_return_if_fail (TPL_IS_DBUS_SERVICE (closure->service)); - g_return_if_fail (closure->context != NULL); - - TplDBusServicePriv *priv = closure->service->priv; - - if (!tp_dbus_check_valid_object_path (closure->account, &error)) - { - dbus_g_method_return_error (closure->context, error); - - goto pendingproc_remove_favourite_contact_ERROR; - } - - DEBUG ("removing favourite contact: account '%s', ID '%s'", - closure->account, closure->contact_id); - - contacts = g_hash_table_lookup (priv->accounts_contacts_map, - closure->account); - if (contacts != NULL && g_hash_table_remove (contacts, closure->contact_id)) - removed = TRUE; - - closure->cb = remove_favourite_contact_file_save_cb; - - if (removed) - favourite_contacts_file_save_async (closure->service, closure); - else - remove_favourite_contact_file_save_cb (FALSE, closure); - - return; - -pendingproc_remove_favourite_contact_ERROR: - if (action_chain != NULL) - _tpl_action_chain_terminate (action_chain, error); - - g_clear_error (&error); -} - -static void -tpl_dbus_service_remove_favourite_contact (TplSvcLogger *logger, - const gchar *account, - const gchar *contact_id, - DBusGMethodInvocation *context) -{ - TplDBusService *self = TPL_DBUS_SERVICE (logger); - TplDBusServicePriv *priv; - FavouriteContactClosure *closure; - - g_return_if_fail (TPL_IS_DBUS_SERVICE (self)); - g_return_if_fail (context != NULL); - - priv = self->priv; - - closure = favourite_contact_closure_new (self, account, contact_id, context); - - /* If we're still waiting on the contacts to finish being parsed from disk, - * queue this action */ - if (priv->favourite_contacts_actions != NULL) - { - _tpl_action_chain_append (priv->favourite_contacts_actions, - pendingproc_remove_favourite_contact, closure); - } - else - pendingproc_remove_favourite_contact (NULL, closure); -} - - -static void -tpl_dbus_service_clear (TplSvcLogger *logger, - DBusGMethodInvocation *context) -{ - TplDBusService *self = TPL_DBUS_SERVICE (logger); - - g_return_if_fail (TPL_IS_DBUS_SERVICE (self)); - g_return_if_fail (context != NULL); - - /* We want to clear synchronously to avoid concurent write */ - _tpl_log_manager_clear (self->priv->manager); - - tpl_svc_logger_return_from_clear (context); -} - - -static void -tpl_dbus_service_clear_account (TplSvcLogger *logger, - const gchar *account_path, - DBusGMethodInvocation *context) -{ - TplDBusService *self = TPL_DBUS_SERVICE (logger); - TpDBusDaemon *bus; - TpAccount *account; - GError *error = NULL; - TpClientFactory *factory = NULL; - - g_return_if_fail (TPL_IS_DBUS_SERVICE (self)); - g_return_if_fail (context != NULL); - - bus = tp_dbus_daemon_dup (&error); - if (bus == NULL) - { - DEBUG ("Unable to acquire the bus daemon: %s", error->message); - dbus_g_method_return_error (context, error); - goto out; - } - - factory = _tpl_client_factory_dup (bus); - - account = tp_client_factory_ensure_account (factory, account_path, - NULL, &error); - if (account == NULL) - { - DEBUG ("Unable to acquire the account for %s: %s", account_path, - error->message); - dbus_g_method_return_error (context, error); - goto out; - } - - /* We want to clear synchronously to avoid concurent write */ - _tpl_log_manager_clear_account (self->priv->manager, account); - g_object_unref (account); - - tpl_svc_logger_return_from_clear_account (context); - -out: - if (bus != NULL) - g_object_unref (bus); - - g_clear_error (&error); - g_clear_object (&factory); -} - - -static void -tpl_dbus_service_clear_entity (TplSvcLogger *logger, - const gchar *account_path, - const gchar *identifier, - gint type, - DBusGMethodInvocation *context) -{ - TplDBusService *self = TPL_DBUS_SERVICE (logger); - TpDBusDaemon *bus; - TpAccount *account; - TplEntity *entity; - GError *error = NULL; - TpClientFactory *factory = NULL; - - g_return_if_fail (TPL_IS_DBUS_SERVICE (self)); - g_return_if_fail (context != NULL); - g_return_if_fail (!TPL_STR_EMPTY (identifier)); - - bus = tp_dbus_daemon_dup (&error); - if (bus == NULL) - { - DEBUG ("Unable to acquire the bus daemon: %s", error->message); - dbus_g_method_return_error (context, error); - goto out; - } - - factory = _tpl_client_factory_dup (bus); - - account = tp_client_factory_ensure_account (factory, account_path, - NULL, &error); - if (account == NULL) - { - DEBUG ("Unable to acquire the account for %s: %s", account_path, - error->message); - dbus_g_method_return_error (context, error); - goto out; - } - - entity = tpl_entity_new (identifier, type, NULL, NULL); - - /* We want to clear synchronously to avoid concurent write */ - _tpl_log_manager_clear_entity (self->priv->manager, account, entity); - - g_object_unref (account); - g_object_unref (entity); - g_clear_object (&factory); - - tpl_svc_logger_return_from_clear_account (context); - -out: - if (bus != NULL) - g_object_unref (bus); - - g_clear_error (&error); -} - -static void -tpl_logger_iface_init (gpointer iface, - gpointer iface_data) -{ - TplSvcLoggerClass *klass = (TplSvcLoggerClass *) iface; - -#define IMPLEMENT(x) tpl_svc_logger_implement_##x (klass, tpl_dbus_service_##x) - IMPLEMENT (get_favourite_contacts); - IMPLEMENT (add_favourite_contact); - IMPLEMENT (remove_favourite_contact); - IMPLEMENT (clear); - IMPLEMENT (clear_account); - IMPLEMENT (clear_entity); -#undef IMPLEMENT -} diff --git a/telepathy-logger/debug-internal.h b/telepathy-logger/debug-internal.h deleted file mode 100644 index 8d39bcc..0000000 --- a/telepathy-logger/debug-internal.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) 2009 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: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - */ - -#ifndef __TPL_DEBUG_H__ -#define __TPL_DEBUG_H__ - -#include "config.h" - -#include <string.h> - -#include <glib.h> -#include <telepathy-glib/telepathy-glib.h> - -#ifdef ENABLE_DEBUG - -G_BEGIN_DECLS - -typedef enum -{ - TPL_DEBUG_ACTION_CHAIN = 1 << 0, - TPL_DEBUG_CONF = 1 << 1, - TPL_DEBUG_ENTITY = 1 << 2, - TPL_DEBUG_CHANNEL = 1 << 3, - TPL_DEBUG_DBUS_SERVICE = 1 << 4, - TPL_DEBUG_LOG_EVENT = 1 << 5, - TPL_DEBUG_LOG_MANAGER = 1 << 6, - TPL_DEBUG_LOG_STORE = 1 << 7, - TPL_DEBUG_MAIN = 1 << 8, - TPL_DEBUG_OBSERVER = 1 << 9, - TPL_DEBUG_TESTSUITE = 1 << 10 -} TplDebugFlags; - -void _tpl_debug_set_flags_from_env (void); -void _tpl_debug_set_flags (TplDebugFlags flags); -gboolean _tpl_debug_flag_is_set (TplDebugFlags flag); -void _tpl_debug_free (void); -void _tpl_debug (TplDebugFlags flag, const gchar *format, ...) - G_GNUC_PRINTF (2, 3); -void _tpl_critical (TplDebugFlags flag, const gchar *format, ...) - G_GNUC_PRINTF (2, 3); - - -G_END_DECLS - -/* CRITICAL/PATH_CRITICAL needs to be always defined */ -#define CRITICAL(format, ...) \ - _tpl_critical (DEBUG_FLAG, "%s: " format, G_STRFUNC, ##__VA_ARGS__) -#define PATH_CRITICAL(_proxy, _format, ...) \ -G_STMT_START { \ - const gchar *_path; \ - g_assert (TP_IS_PROXY (_proxy)); \ - _path = tp_proxy_get_object_path (TP_PROXY (_proxy)); \ - if (TP_IS_CHANNEL (_proxy)) \ - _path += strlen (TP_CONN_OBJECT_PATH_BASE); \ - else if (TP_IS_ACCOUNT (_proxy)) \ - _path += strlen (TP_ACCOUNT_OBJECT_PATH_BASE); \ - CRITICAL (" %s: " _format, _path, ##__VA_ARGS__); \ -} G_STMT_END - -#ifdef DEBUG_FLAG - -#define DEBUG(format, ...) \ - _tpl_debug (DEBUG_FLAG, "%s: " format, G_STRFUNC, ##__VA_ARGS__) - -#define DEBUGGING _tpl_debug_flag_is_set (DEBUG_FLAG) - -/* The same of DEBUG, printing also the object-path property for the TpProxy, - * passed as first arg. prepending '_' to avoid shadowing local variables */ -#define PATH_DEBUG(_proxy, _format, ...) \ -G_STMT_START { \ - const gchar *_path; \ - g_assert (TP_IS_PROXY (_proxy)); \ - _path = tp_proxy_get_object_path (TP_PROXY (_proxy)); \ - if (TP_IS_CHANNEL (_proxy)) \ - _path += strlen (TP_CONN_OBJECT_PATH_BASE); \ - else if (TP_IS_ACCOUNT (_proxy)) \ - _path += strlen (TP_ACCOUNT_OBJECT_PATH_BASE); \ - DEBUG (" %s: " _format, _path, ##__VA_ARGS__); \ -} G_STMT_END - -#endif /* DEBUG_FLAG */ - -#else /* ENABLE_DEBUG */ - -#ifdef DEBUG_FLAG - -#define DEBUG(format, ...) G_STMT_START { } G_STMT_END -#define DEBUGGING 0 -#define PATH_DEBUG(chan, format, ...) G_STMT_START { } G_STMT_END - -#endif /* DEBUG_FLAG */ - -#define _tpl_debug_free() G_STMT_START { } G_STMT_END - -#endif /* ENABLE_DEBUG */ - -#endif /* __TPL_DEBUG_H__ */ diff --git a/telepathy-logger/debug.c b/telepathy-logger/debug.c deleted file mode 100644 index 7b38564..0000000 --- a/telepathy-logger/debug.c +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (C) 2009 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: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - */ - -#include "config.h" -#include "telepathy-logger/debug-internal.h" - -#include <telepathy-glib/telepathy-glib.h> - -#ifdef ENABLE_DEBUG - -static TplDebugFlags flags = 0; - -static GDebugKey keys[] = { - { "action-chain", TPL_DEBUG_ACTION_CHAIN }, - { "channel", TPL_DEBUG_CHANNEL }, - { "conf", TPL_DEBUG_CONF }, - { "entity", TPL_DEBUG_ENTITY }, - { "dbus-service", TPL_DEBUG_DBUS_SERVICE }, - { "log-event", TPL_DEBUG_LOG_EVENT }, - { "log-manager", TPL_DEBUG_LOG_MANAGER }, - { "log-store", TPL_DEBUG_LOG_STORE }, - { "main", TPL_DEBUG_MAIN }, - { "observer", TPL_DEBUG_OBSERVER }, - { "testsuite", TPL_DEBUG_TESTSUITE }, - { 0, }, -}; - -void -_tpl_debug_set_flags_from_env (void) -{ - guint nkeys; - const gchar *flags_string; - - for (nkeys = 0; keys[nkeys].value; nkeys++); - - flags_string = g_getenv ("TPL_DEBUG"); - - if (flags_string != NULL) - _tpl_debug_set_flags (g_parse_debug_string (flags_string, keys, nkeys)); - - tp_debug_set_flags (g_getenv ("TP_DEBUG")); -} - - -void -_tpl_debug_set_flags (TplDebugFlags new_flags) -{ - flags |= new_flags; -} - - -gboolean -_tpl_debug_flag_is_set (TplDebugFlags flag) -{ - return flag & flags; -} - -GHashTable *flag_to_domains = NULL; - - -void -_tpl_debug_free (void) -{ - if (flag_to_domains == NULL) - return; - - g_hash_table_unref (flag_to_domains); - flag_to_domains = NULL; -} - - -void _tpl_debug (TplDebugFlags flag, - const gchar *format, - ...) -{ - gchar *message; - va_list args; - - va_start (args, format); - message = g_strdup_vprintf (format, args); - va_end (args); - - if (flag & flags) - g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "%s", message); - - g_free (message); -} - -#endif /* ENABLE_DEBUG */ - -/* The following function has to be always define or CRITICAL messages won't - * be shown */ - -void _tpl_critical (TplDebugFlags flag, - const gchar *format, - ...) -{ - gchar *message; - va_list args; - - va_start (args, format); - message = g_strdup_vprintf (format, args); - va_end (args); - - if (flag & flags) - g_log (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "%s", message); - - g_free (message); -} diff --git a/telepathy-logger/entity-internal.h b/telepathy-logger/entity-internal.h deleted file mode 100644 index d9c6eef..0000000 --- a/telepathy-logger/entity-internal.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - *Copyright (C) 2009-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: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - */ - -#ifndef __TPL_ENTITY_INTERNAL_H__ -#define __TPL_ENTITY_INTERNAL_H__ - -#include <telepathy-logger/entity.h> - -#include <glib-object.h> -#include <telepathy-glib/telepathy-glib.h> - -G_BEGIN_DECLS -#define TPL_ENTITY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TPL_TYPE_ENTITY, TplEntityClass)) -#define TPL_IS_ENTITY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TPL_TYPE_ENTITY)) -#define TPL_ENTITY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_ENTITY, TplEntityClass)) - -typedef struct -{ - GObjectClass parent_class; -} TplEntityClass; - -gint _tpl_entity_compare (TplEntity *e1, TplEntity *e2); -TplEntityType _tpl_entity_type_from_str (const gchar *type_str); -const gchar * _tpl_entity_type_to_str (TplEntityType type); - -G_END_DECLS -#endif // __TPL_ENTITY_INTERNAL_H__ diff --git a/telepathy-logger/entity.c b/telepathy-logger/entity.c deleted file mode 100644 index e2e3240..0000000 --- a/telepathy-logger/entity.c +++ /dev/null @@ -1,409 +0,0 @@ -/* - * Copyright (C) 2009-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: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - */ - -#include "config.h" -#include "entity.h" -#include "entity-internal.h" - -#include <telepathy-glib/telepathy-glib.h> - -#define DEBUG_FLAG TPL_DEBUG_ENTITY -#include <telepathy-logger/debug-internal.h> -#include <telepathy-logger/util-internal.h> - -/** - * SECTION:entity - * @title: TplEntity - * @short_description: Representation of a contact or room - * - * An object representing a contact or room. - */ - -/** - * TplEntity: - * - * An object representing a contact or room. - */ - -G_DEFINE_TYPE (TplEntity, tpl_entity, G_TYPE_OBJECT) - -struct _TplEntityPriv -{ - TplEntityType type; - gchar *alias; - gchar *identifier; - gchar *avatar_token; -}; - -enum -{ - PROP0, - PROP_TYPE, - PROP_IDENTIFIER, - PROP_ALIAS, - PROP_AVATAR_TOKEN -}; - -static const gchar * entity_types[] = { - "unknown", - "contact", - "room", - "self" -}; - - -static void -tpl_entity_finalize (GObject *obj) -{ - TplEntity *self = TPL_ENTITY (obj); - TplEntityPriv *priv = self->priv; - - tp_clear_pointer (&priv->alias, g_free); - tp_clear_pointer (&priv->identifier, g_free); - tp_clear_pointer (&priv->avatar_token, g_free); - - G_OBJECT_CLASS (tpl_entity_parent_class)->finalize (obj); -} - - -static void -tpl_entity_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - TplEntityPriv *priv = TPL_ENTITY (object)->priv; - - switch (param_id) - { - case PROP_TYPE: - g_value_set_int (value, priv->type); - break; - case PROP_IDENTIFIER: - g_value_set_string (value, priv->identifier); - break; - case PROP_ALIAS: - g_value_set_string (value, priv->alias); - break; - case PROP_AVATAR_TOKEN: - g_value_set_string (value, priv->avatar_token); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - }; -} - - -static void -tpl_entity_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - TplEntityPriv *priv = TPL_ENTITY (object)->priv; - - switch (param_id) - { - case PROP_TYPE: - priv->type = g_value_get_int (value); - break; - case PROP_IDENTIFIER: - g_assert (priv->identifier == NULL); - priv->identifier = g_value_dup_string (value); - break; - case PROP_ALIAS: - g_assert (priv->alias == NULL); - priv->alias = g_value_dup_string (value); - break; - case PROP_AVATAR_TOKEN: - g_assert (priv->avatar_token == NULL); - priv->avatar_token = g_value_dup_string (value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - }; - -} - - -static void tpl_entity_class_init (TplEntityClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GParamSpec *param_spec; - - object_class->finalize = tpl_entity_finalize; - object_class->get_property = tpl_entity_get_property; - object_class->set_property = tpl_entity_set_property; - - /** - * TplEntity:type: - * - * The entity's type (see #TplEntityType). - */ - param_spec = g_param_spec_int ("type", - "Type", - "The entity's type", - TPL_ENTITY_UNKNOWN, - TPL_ENTITY_SELF, - TPL_ENTITY_UNKNOWN, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_TYPE, param_spec); - - /** - * TplEntity:identifier: - * - * The entity's identifier - */ - param_spec = g_param_spec_string ("identifier", - "Identifier", - "The entity's identifier", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_IDENTIFIER, param_spec); - - /** - * TplEntity:alias: - * - * The entity's alias - */ - param_spec = g_param_spec_string ("alias", - "Alias", - "The entity's alias", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_ALIAS, param_spec); - - /** - * TplEntity:avatar-token: - * - * The entity's avatar token - */ - param_spec = g_param_spec_string ("avatar-token", - "AvatarToken", - "The entity's avatar's token", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_AVATAR_TOKEN, param_spec); - - g_type_class_add_private (object_class, sizeof (TplEntityPriv)); -} - - -static void -tpl_entity_init (TplEntity *self) -{ - TplEntityPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - TPL_TYPE_ENTITY, TplEntityPriv); - - self->priv = priv; -} - -TplEntity * -tpl_entity_new (const gchar *id, - TplEntityType type, - const gchar *alias, - const gchar *avatar_token) -{ - TplEntity *ret; - - g_return_val_if_fail (!TPL_STR_EMPTY (id), NULL); - - ret = g_object_new (TPL_TYPE_ENTITY, - "identifier", id, - "type", type, - "alias", alias == NULL ? id : alias, - "avatar-token", avatar_token == NULL ? "" : avatar_token, - NULL); - - switch (type) - { - case TPL_ENTITY_ROOM: - DEBUG ("Room id: %s", id); - break; - case TPL_ENTITY_CONTACT: - DEBUG ("Contact id: %s, tok: %s", id, avatar_token); - break; - case TPL_ENTITY_SELF: - DEBUG ("Self id: %s, tok: %s", id, avatar_token); - break; - case TPL_ENTITY_UNKNOWN: - DEBUG ("Unknown entity."); - break; - default: - g_warning ("Unknown entity type %i", type); - g_object_unref (ret); - ret = NULL; - } - - return ret; -} - -/** - * tpl_entity_new_from_room_id: - * @room_id: the room id which will be the identifier for the entity - * - * Returns: a TplEntity instance with identifier, alias copied from - * @room_id. It also sets %TPL_ENTITY_ROOM as type for - * the #TplEntity returned. - */ -TplEntity * -tpl_entity_new_from_room_id (const gchar *room_id) -{ - return tpl_entity_new (room_id, TPL_ENTITY_ROOM, NULL, NULL); -} - - -/** - * tpl_entity_new_from_tp_contact: - * @contact: the TpContact instance to create the TplEntity from - * @type: the #TplEntity type - * - * Returns: a TplEntity instance with identifier, alias and - * avatar's token copied. Type parameter is useful to differentiate between - * normal contact and self contact, thus only %TPL_ENTITY_CONTACT and - * %TPL_ENTITY_SELF are accepted. If contact is %NULL, an entity of type - * %TPL_ENTITY_UNKNOWN with id set to "unknown" is returned. - */ -TplEntity * -tpl_entity_new_from_tp_contact (TpContact *contact, - TplEntityType type) -{ - g_return_val_if_fail (contact == NULL || TP_IS_CONTACT (contact), NULL); - g_return_val_if_fail (type == TPL_ENTITY_CONTACT || type == TPL_ENTITY_SELF, - NULL); - - if (contact != NULL) - return tpl_entity_new (tp_contact_get_identifier (contact), - type, - tp_contact_get_alias (contact), - tp_contact_get_avatar_token (contact)); - else - return tpl_entity_new ("unknown", TPL_ENTITY_UNKNOWN, NULL, NULL); -} - - -/** - * tpl_entity_get_alias: - * @self: a #TplEntity - * - * Returns: the alias of the entity, or %NULL - */ -const gchar * -tpl_entity_get_alias (TplEntity *self) -{ - g_return_val_if_fail (TPL_IS_ENTITY (self), NULL); - - return self->priv->alias; -} - - -/** - * tpl_entity_get_identifier: - * @self: a #TplEntity - * - * Returns: the identifier of the entity - */ -const gchar * -tpl_entity_get_identifier (TplEntity *self) -{ - g_return_val_if_fail (TPL_IS_ENTITY (self), NULL); - - return self->priv->identifier; -} - - -/** - * tpl_entity_get_entity_type: - * @self: a #TplEntity - * - * Returns: the type of the entity - */ -TplEntityType -tpl_entity_get_entity_type (TplEntity *self) -{ - g_return_val_if_fail (TPL_IS_ENTITY (self), TPL_ENTITY_UNKNOWN); - - return self->priv->type; -} - - -/** - * tpl_entity_get_avatar_token: - * @self: a #TplEntity - * - * Returns: a token representing the avatar of the token, or %NULL - */ -const gchar * -tpl_entity_get_avatar_token (TplEntity *self) -{ - g_return_val_if_fail (TPL_IS_ENTITY (self), NULL); - - return self->priv->avatar_token; -} - - -/* - * _tpl_entity_compare: - * @a: a #TplEntity - * @b: a #TplEntity - * - * Compares @a and @b. - * - * Returns: 0 if a == b, -1 if a < b, 1 otherwise. - */ -gint -_tpl_entity_compare (TplEntity *a, - TplEntity *b) -{ - g_return_val_if_fail (TPL_IS_ENTITY (a), TPL_IS_ENTITY (b) ? -1 : 0); - g_return_val_if_fail (TPL_IS_ENTITY (b), 1); - - if (tpl_entity_get_entity_type (a) == tpl_entity_get_entity_type (b)) - return g_strcmp0 (tpl_entity_get_identifier (a), - tpl_entity_get_identifier (b)); - else if (tpl_entity_get_entity_type (a) < tpl_entity_get_entity_type (b)) - return -1; - else - return 1; -} - - -TplEntityType -_tpl_entity_type_from_str (const gchar *type_str) -{ - guint i; - for (i = 0; i < G_N_ELEMENTS (entity_types); ++i) - if (!tp_strdiff (type_str, entity_types[i])) - return (TplEntityType) i; - - /* default case */ - return TPL_ENTITY_UNKNOWN; -} - - -const gchar * -_tpl_entity_type_to_str (TplEntityType type) -{ - g_return_val_if_fail (G_N_ELEMENTS (entity_types) >= type, "unknown"); - return entity_types[type]; -} diff --git a/telepathy-logger/entity.h b/telepathy-logger/entity.h deleted file mode 100644 index 5f61b99..0000000 --- a/telepathy-logger/entity.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - *Copyright (C) 2009-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: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - */ - -#ifndef __TPL_ENTITY_H__ -#define __TPL_ENTITY_H__ - -#include <glib-object.h> -#include <telepathy-glib/telepathy-glib.h> - -G_BEGIN_DECLS -#define TPL_TYPE_ENTITY (tpl_entity_get_type ()) -#define TPL_ENTITY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_ENTITY, TplEntity)) -#define TPL_ENTITY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TPL_TYPE_ENTITY, TplEntityClass)) -#define TPL_IS_ENTITY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_ENTITY)) -#define TPL_IS_ENTITY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TPL_TYPE_ENTITY)) -#define TPL_ENTITY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_ENTITY, TplEntityClass)) - -/** - * TplEntityType: - * @TPL_ENTITY_UNKNOWN: the current contact's type is unknown - * @TPL_ENTITY_CONTACT: the contact's type represents a user (buddy), but not - * the account's owner for which @TPL_ENTITY_SELF is used - * @TPL_ENTITY_ROOM: a named room (#TP_HANDLE_TYPE_ROOM) - * @TPL_ENTITY_SELF: the contact's type represents the owner of the account - * whose channel has been logged, as opposed to @TPL_ENTITY_CONTACT which - * represents any other user - */ -typedef enum -{ - TPL_ENTITY_UNKNOWN, - TPL_ENTITY_CONTACT, - TPL_ENTITY_ROOM, - TPL_ENTITY_SELF -} TplEntityType; - -typedef struct _TplEntity TplEntity; -typedef struct _TplEntityPriv TplEntityPriv; - -struct _TplEntity -{ - GObject parent; - - /*Private */ - TplEntityPriv *priv; -}; - - -GType tpl_entity_get_type (void); - -TplEntity *tpl_entity_new (const gchar *id, - TplEntityType type, - const gchar *alias, - const gchar *avatar_token); -TplEntity *tpl_entity_new_from_tp_contact (TpContact *contact, TplEntityType type); -TplEntity *tpl_entity_new_from_room_id (const gchar *room_id); - -const gchar *tpl_entity_get_alias (TplEntity *self); -const gchar *tpl_entity_get_identifier (TplEntity *self); -TplEntityType tpl_entity_get_entity_type (TplEntity *self); -const gchar *tpl_entity_get_avatar_token (TplEntity *self); - -G_END_DECLS -#endif // __TPL_ENTITY_H__ diff --git a/telepathy-logger/event-internal.h b/telepathy-logger/event-internal.h deleted file mode 100644 index 57bb9ad..0000000 --- a/telepathy-logger/event-internal.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2009 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: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - */ - -#ifndef __TPL_EVENT_INTERNAL_H__ -#define __TPL_EVENT_INTERNAL_H__ - -#include <telepathy-logger/event.h> - -G_BEGIN_DECLS - -struct _TplEvent -{ - GObject parent; - - /* Private */ - TplEventPriv *priv; -}; - -struct _TplEventClass { - GObjectClass parent_class; - - gboolean (*equal) (TplEvent *event1, TplEvent *event2); -}; - -TplEntity * _tpl_event_get_target (TplEvent *self); - -const gchar * _tpl_event_get_target_id (TplEvent * self); - -gboolean _tpl_event_target_is_room (TplEvent *self); - -const gchar * _tpl_event_get_channel_path (TplEvent *self); - -G_END_DECLS -#endif // __TPL_EVENT_INTERNAL_H__ diff --git a/telepathy-logger/event.c b/telepathy-logger/event.c deleted file mode 100644 index f061ce0..0000000 --- a/telepathy-logger/event.c +++ /dev/null @@ -1,403 +0,0 @@ -/* - * Copyright (C) 2009 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: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - */ - -#include "config.h" -#include "event.h" -#include "event-internal.h" - -#include <glib.h> -#include "entity-internal.h" - -#define DEBUG_FLAG TPL_DEBUG_EVENT -#include <telepathy-logger/debug-internal.h> -#include <telepathy-logger/util-internal.h> - -/** - * SECTION:event - * @title: TplEvent - * @short_description: Abstract representation of a log event - * @see_also: #TplTextEvent and other subclasses when they'll exist - * - * The TPLogger log event represents a generic log event, which will be - * specialized by subclasses of #TplEvent. - */ - -/** - * TplEvent: - * - * An object representing a generic log event. - */ - -G_DEFINE_ABSTRACT_TYPE (TplEvent, tpl_event, G_TYPE_OBJECT) - -struct _TplEventPriv -{ - gint64 timestamp; - TpAccount *account; - gchar *channel_path; - - /* message and receiver may be NULL depending on the signal. ie. status - * changed signals set only the sender */ - TplEntity *sender; - TplEntity *receiver; -}; - -enum { - PROP_TIMESTAMP = 1, - PROP_TARGET_ID, - PROP_ACCOUNT, - PROP_ACCOUNT_PATH, - PROP_CHANNEL_PATH, - PROP_SENDER, - PROP_RECEIVER -}; - - -static void -tpl_event_finalize (GObject *obj) -{ - TplEvent *self = TPL_EVENT (obj); - TplEventPriv *priv = self->priv; - - tp_clear_pointer (&priv->channel_path, g_free); - - G_OBJECT_CLASS (tpl_event_parent_class)->finalize (obj); -} - - -static void -tpl_event_dispose (GObject *obj) -{ - TplEvent *self = TPL_EVENT (obj); - TplEventPriv *priv = self->priv; - - tp_clear_object (&priv->account); - tp_clear_object (&priv->sender); - tp_clear_object (&priv->receiver); - - G_OBJECT_CLASS (tpl_event_parent_class)->dispose (obj); -} - - -static void -tpl_event_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - TplEvent *self = TPL_EVENT (object); - TplEventPriv *priv = self->priv; - - switch (param_id) - { - case PROP_TIMESTAMP: - g_value_set_int64 (value, priv->timestamp); - break; - case PROP_ACCOUNT: - g_value_set_object (value, priv->account); - break; - case PROP_ACCOUNT_PATH: - g_value_set_string (value, tpl_event_get_account_path (self)); - break; - case PROP_CHANNEL_PATH: - g_value_set_string (value, priv->channel_path); - break; - case PROP_SENDER: - g_value_set_object (value, priv->sender); - break; - case PROP_RECEIVER: - g_value_set_object (value, priv->receiver); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - }; -} - - -static void -tpl_event_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - TplEvent *self = TPL_EVENT (object); - TplEventPriv *priv = self->priv; - - switch (param_id) { - case PROP_TIMESTAMP: - g_assert (priv->timestamp == 0); - priv->timestamp = g_value_get_int64 (value); - break; - case PROP_ACCOUNT: - g_assert (priv->account == NULL); - priv->account = g_value_dup_object (value); - break; - case PROP_CHANNEL_PATH: - g_assert (priv->channel_path == NULL); - priv->channel_path = g_value_dup_string (value); - break; - case PROP_SENDER: - g_assert (priv->sender == NULL); - g_return_if_fail (TPL_IS_ENTITY (g_value_get_object (value))); - priv->sender = g_value_dup_object (value); - break; - case PROP_RECEIVER: - g_assert (priv->receiver == NULL); - /* can be NULL */ - priv->receiver = g_value_dup_object (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - }; -} - -static inline gboolean -account_equal (TpAccount *account1, TpAccount *account2) -{ - g_return_val_if_fail (TP_IS_PROXY (account1), FALSE); - g_return_val_if_fail (TP_IS_PROXY (account2), FALSE); - - return !tp_strdiff (tp_proxy_get_object_path (TP_PROXY (account1)), - tp_proxy_get_object_path (TP_PROXY (account2))); -} - - -static gboolean -tpl_event_equal_default (TplEvent *message1, - TplEvent *message2) -{ - g_return_val_if_fail (TPL_IS_EVENT (message1), FALSE); - g_return_val_if_fail (TPL_IS_EVENT (message2), FALSE); - - return message1->priv->timestamp == message2->priv->timestamp - && account_equal (message1->priv->account, message2->priv->account) - && _tpl_entity_compare (message1->priv->sender, message2->priv->sender) - && _tpl_entity_compare (message1->priv->receiver, message2->priv->receiver); -} - - -static void -tpl_event_class_init (TplEventClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GParamSpec *param_spec; - - /* to be used by subclasses */ - object_class->finalize = tpl_event_finalize; - object_class->dispose = tpl_event_dispose; - object_class->get_property = tpl_event_get_property; - object_class->set_property = tpl_event_set_property; - - klass->equal = tpl_event_equal_default; - - param_spec = g_param_spec_int64 ("timestamp", - "Timestamp", - "The timestamp (gint64) for the log event", - G_MININT64, G_MAXINT64, 0, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_TIMESTAMP, param_spec); - - param_spec = g_param_spec_object ("account", - "TpAccount", - "The TpAccount to which the log event is related", - TP_TYPE_ACCOUNT, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_ACCOUNT, param_spec); - - param_spec = g_param_spec_string ("account-path", - "AccountPath", - "The account path of the TpAccount to which the log event is related", - NULL, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_ACCOUNT_PATH, param_spec); - - param_spec = g_param_spec_string ("channel-path", - "ChannelPath", - "The channel path of the TpChannel to which the log event is related", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_CHANNEL_PATH, param_spec); - - param_spec = g_param_spec_object ("sender", - "Sender", - "TplEntity instance who originated the log event", - TPL_TYPE_ENTITY, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_SENDER, param_spec); - - param_spec = g_param_spec_object ("receiver", - "Receiver", - "TplEntity instance destination for the log event " - "(may be NULL with some log stores)", - TPL_TYPE_ENTITY, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_RECEIVER, param_spec); - - g_type_class_add_private (object_class, sizeof (TplEventPriv)); -} - - -static void -tpl_event_init (TplEvent *self) -{ - TplEventPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - TPL_TYPE_EVENT, TplEventPriv); - self->priv = priv; -} - -/** - * tpl_event_get_timestamp: - * @self: a #TplEvent - * - * Returns: the same timestamp as the #TplEvent:timestamp property - */ -gint64 -tpl_event_get_timestamp (TplEvent *self) -{ - g_return_val_if_fail (TPL_IS_EVENT (self), -1); - - return self->priv->timestamp; -} - - -/** - * tpl_event_get_sender: - * @self: a #TplEvent - * - * Returns: (transfer none): the same #TplEntity as the #TplEvent:sender property - */ -TplEntity * -tpl_event_get_sender (TplEvent *self) -{ - g_return_val_if_fail (TPL_IS_EVENT (self), NULL); - - return self->priv->sender; -} - -/** - * tpl_event_get_receiver: - * @self: a #TplEvent - * - * Returns: (transfer none): the same #TplEntity as the #TplEvent:receiver property - */ -TplEntity * -tpl_event_get_receiver (TplEvent *self) -{ - g_return_val_if_fail (TPL_IS_EVENT (self), NULL); - - return self->priv->receiver; -} - - -TplEntity * -_tpl_event_get_target (TplEvent *self) -{ - g_return_val_if_fail (TPL_IS_EVENT (self), NULL); - - if (_tpl_event_target_is_room (self) - || tpl_entity_get_entity_type (self->priv->sender) == TPL_ENTITY_SELF) - return self->priv->receiver; - else - return self->priv->sender; -} - - -const gchar * -_tpl_event_get_target_id (TplEvent *self) -{ - g_return_val_if_fail (TPL_IS_EVENT (self), NULL); - - return tpl_entity_get_identifier (_tpl_event_get_target (self)); -} - -gboolean -_tpl_event_target_is_room (TplEvent *self) -{ - /* Some log-store like Pidgin text mode does not know about receiver, so - * having a NULL receiver is fine. */ - if (self->priv->receiver == NULL) - return FALSE; - - return (tpl_entity_get_entity_type (self->priv->receiver) == TPL_ENTITY_ROOM); -} - - -/** - * tpl_event_get_account_path: - * @self: a #TplEvent - * - * <!-- no more to say --> - * - * Returns: the path as the #TplEvent:account property - */ -const gchar * -tpl_event_get_account_path (TplEvent *self) -{ - g_return_val_if_fail (TPL_IS_EVENT (self), NULL); - g_return_val_if_fail (TP_IS_ACCOUNT (self->priv->account), NULL); - - return tp_proxy_get_object_path (self->priv->account); -} - - -const gchar * -_tpl_event_get_channel_path (TplEvent *self) -{ - g_return_val_if_fail (TPL_IS_EVENT (self), NULL); - - return self->priv->channel_path; -} - - -/** - * tpl_event_equal: - * @self: TplEvent subclass instance - * @data: an instance of the same TplEvent subclass of @self - * - * Checks if two instances of TplEvent represent the same data - * - * Returns: %TRUE if @data is the same type of @self and they hold the same - * data, %FALSE otherwise - */ -gboolean -tpl_event_equal (TplEvent *self, - TplEvent *data) -{ - g_return_val_if_fail (TPL_IS_EVENT (self), FALSE); - g_return_val_if_fail (TPL_IS_EVENT (data), FALSE); - - return TPL_EVENT_GET_CLASS (self)->equal (self, data); -} - -/** - * tpl_event_get_account: - * @self: a #TplEvent - * - * <!-- no more to say --> - * - * Returns: (transfer none): the same account as the #TplEvent:account property - */ -TpAccount * -tpl_event_get_account (TplEvent *self) -{ - return self->priv->account; -} diff --git a/telepathy-logger/event.h b/telepathy-logger/event.h deleted file mode 100644 index 8e0301e..0000000 --- a/telepathy-logger/event.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2009 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: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - */ - -#ifndef __TPL_EVENT_H__ -#define __TPL_EVENT_H__ - -#include <glib-object.h> - -#include <telepathy-glib/telepathy-glib.h> - -#include <telepathy-logger/entity.h> - -G_BEGIN_DECLS -#define TPL_TYPE_EVENT (tpl_event_get_type ()) -#define TPL_EVENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_EVENT, TplEvent)) -#define TPL_EVENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TPL_TYPE_EVENT, TplEventClass)) -#define TPL_IS_EVENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_EVENT)) -#define TPL_IS_EVENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TPL_TYPE_EVENT)) -#define TPL_EVENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_EVENT, TplEventClass)) - -typedef struct _TplEvent TplEvent; -typedef struct _TplEventClass TplEventClass; -typedef struct _TplEventPriv TplEventPriv; - -GType tpl_event_get_type (void); - -gint64 tpl_event_get_timestamp (TplEvent *self); - -const gchar *tpl_event_get_account_path (TplEvent *self); -TpAccount * tpl_event_get_account (TplEvent *self); - -TplEntity * tpl_event_get_sender (TplEvent *self); -TplEntity * tpl_event_get_receiver (TplEvent *self); - -gboolean tpl_event_equal (TplEvent *self, TplEvent *data); - -G_END_DECLS -#endif // __TPL_EVENT_H__ diff --git a/telepathy-logger/log-iter-internal.h b/telepathy-logger/log-iter-internal.h deleted file mode 100644 index ec5589f..0000000 --- a/telepathy-logger/log-iter-internal.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2012 Red Hat, Inc. - * - * 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 - * - * Author: Debarshi Ray <debarshir@freedesktop.org> - */ - -#ifndef __TPL_LOG_ITER_H__ -#define __TPL_LOG_ITER_H__ - -#include <glib.h> -#include <glib-object.h> - -G_BEGIN_DECLS - -#define TPL_TYPE_LOG_ITER (tpl_log_iter_get_type ()) - -#define TPL_LOG_ITER(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - TPL_TYPE_LOG_ITER, TplLogIter)) - -#define TPL_LOG_ITER_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), \ - TPL_TYPE_LOG_ITER, TplLogIterClass)) - -#define TPL_IS_LOG_ITER(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - TPL_TYPE_LOG_ITER)) - -#define TPL_IS_LOG_ITER_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), \ - TPL_TYPE_LOG_ITER)) - -#define TPL_LOG_ITER_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), \ - TPL_TYPE_LOG_ITER, TplLogIterClass)) - -typedef struct _TplLogIter TplLogIter; -typedef struct _TplLogIterClass TplLogIterClass; - -struct _TplLogIter -{ - GObject parent_instance; -}; - -struct _TplLogIterClass -{ - GObjectClass parent_class; - - GList * (*get_events) (TplLogIter *self, guint num_events, GError **error); - void (*rewind) (TplLogIter *self, guint num_events, GError **error); -}; - -GType tpl_log_iter_get_type (void) G_GNUC_CONST; - -GList *tpl_log_iter_get_events (TplLogIter *self, - guint num_events, - GError **error); - -void tpl_log_iter_rewind (TplLogIter *self, - guint num_events, - GError **error); - -G_END_DECLS - -#endif /* __TPL_LOG_ITER_H__ */ diff --git a/telepathy-logger/log-iter-pidgin-internal.h b/telepathy-logger/log-iter-pidgin-internal.h deleted file mode 100644 index 230a57e..0000000 --- a/telepathy-logger/log-iter-pidgin-internal.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2012 Red Hat, Inc. - * - * 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 - * - * Author: Debarshi Ray <debarshir@freedesktop.org> - */ - -#ifndef __TPL_LOG_ITER_PIDGIN_H__ -#define __TPL_LOG_ITER_PIDGIN_H__ - -#include <telepathy-glib/telepathy-glib.h> - -#include <telepathy-logger/entity.h> -#include <telepathy-logger/log-iter-internal.h> -#include <telepathy-logger/log-store-internal.h> - -G_BEGIN_DECLS - -#define TPL_TYPE_LOG_ITER_PIDGIN (tpl_log_iter_pidgin_get_type ()) - -#define TPL_LOG_ITER_PIDGIN(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - TPL_TYPE_LOG_ITER_PIDGIN, TplLogIterPidgin)) - -#define TPL_LOG_ITER_PIDGIN_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), \ - TPL_TYPE_LOG_ITER_PIDGIN, TplLogIterPidginClass)) - -#define TPL_IS_LOG_ITER_PIDGIN(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - TPL_TYPE_LOG_ITER_PIDGIN)) - -#define TPL_IS_LOG_ITER_PIDGIN_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), \ - TPL_TYPE_LOG_ITER_PIDGIN)) - -#define TPL_LOG_ITER_PIDGIN_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), \ - TPL_TYPE_LOG_ITER_PIDGIN, TplLogIterPidginClass)) - -typedef struct _TplLogIterPidgin TplLogIterPidgin; -typedef struct _TplLogIterPidginClass TplLogIterPidginClass; -typedef struct _TplLogIterPidginPriv TplLogIterPidginPriv; - -struct _TplLogIterPidgin -{ - TplLogIter parent_instance; - TplLogIterPidginPriv *priv; -}; - -struct _TplLogIterPidginClass -{ - TplLogIterClass parent_class; -}; - -GType tpl_log_iter_pidgin_get_type (void) G_GNUC_CONST; - -TplLogIter *tpl_log_iter_pidgin_new (TplLogStore *store, - TpAccount *account, - TplEntity *target, - gint type_mask); - -G_END_DECLS - -#endif /* __TPL_LOG_ITER_PIDGIN_H__ */ diff --git a/telepathy-logger/log-iter-pidgin.c b/telepathy-logger/log-iter-pidgin.c deleted file mode 100644 index a9263d4..0000000 --- a/telepathy-logger/log-iter-pidgin.c +++ /dev/null @@ -1,325 +0,0 @@ -/* - * Copyright (C) 2012 Red Hat, Inc. - * - * 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 - * - * Author: Debarshi Ray <debarshir@freedesktop.org> - */ - -#include "config.h" -#include "log-iter-pidgin-internal.h" - - -struct _TplLogIterPidginPriv -{ - GList *dates; - GList *events; - GList *next_date; - GList *next_event; - TpAccount *account; - TplEntity *target; - TplLogStore *store; - gint type_mask; -}; - -enum -{ - PROP_ACCOUNT = 1, - PROP_STORE, - PROP_TARGET, - PROP_TYPE_MASK -}; - - -G_DEFINE_TYPE (TplLogIterPidgin, tpl_log_iter_pidgin, TPL_TYPE_LOG_ITER); - - -static GList * -tpl_log_iter_pidgin_get_events (TplLogIter *iter, - guint num_events, - GError **error) -{ - TplLogIterPidginPriv *priv; - GList *events; - guint i; - - priv = TPL_LOG_ITER_PIDGIN (iter)->priv; - events = NULL; - - if (priv->dates == NULL) - { - priv->dates = _tpl_log_store_get_dates (priv->store, priv->account, - priv->target, priv->type_mask); - priv->next_date = g_list_last (priv->dates); - } - - i = 0; - while (i < num_events) - { - TplEvent *event; - - if (priv->next_event == NULL) - { - if (priv->next_date == NULL) - break; - - g_list_free_full (priv->events, g_object_unref); - priv->events = _tpl_log_store_get_events_for_date (priv->store, - priv->account, priv->target, priv->type_mask, - (GDate *) priv->next_date->data); - - priv->next_event = g_list_last (priv->events); - priv->next_date = g_list_previous (priv->next_date); - } - - event = TPL_EVENT (priv->next_event->data); - events = g_list_prepend (events, g_object_ref (event)); - i++; - - priv->next_event = g_list_previous (priv->next_event); - } - - return events; -} - - -static void -tpl_log_iter_pidgin_rewind (TplLogIter *iter, - guint num_events, - GError **error) -{ - GList *e; - TplLogIterPidginPriv *priv; - guint i; - - priv = TPL_LOG_ITER_PIDGIN (iter)->priv; - e = NULL; - - /* Set e to the last event that was returned */ - if (priv->next_event == NULL) - e = priv->events; - else - e = g_list_next (priv->next_event); - - i = 0; - while (i < num_events) - { - if (e == NULL) - { - GList *d; - - if (priv->next_date == NULL) - d = priv->dates; - else - d = g_list_next (priv->next_date); - - /* This can happen if get_events was never called or called - * with num_events == 0 - */ - if (d == NULL) - break; - - g_list_free_full (priv->events, g_object_unref); - priv->events = NULL; - priv->next_event = NULL; - - /* Rollback the priv->next_date */ - priv->next_date = d; - - /* Rollback the current date (ie. d) */ - d = g_list_next (d); - if (d == NULL) - break; - - priv->events = _tpl_log_store_get_events_for_date (priv->store, - priv->account, priv->target, priv->type_mask, - (GDate *) d->data); - e = priv->events; - } - - priv->next_event = e; - e = g_list_next (e); - i++; - } -} - - -static void -tpl_log_iter_pidgin_dispose (GObject *object) -{ - TplLogIterPidginPriv *priv; - - priv = TPL_LOG_ITER_PIDGIN (object)->priv; - - g_list_free_full (priv->dates, (GDestroyNotify) g_date_free); - priv->dates = NULL; - - g_list_free_full (priv->events, g_object_unref); - priv->events = NULL; - - g_clear_object (&priv->account); - g_clear_object (&priv->store); - g_clear_object (&priv->target); - - G_OBJECT_CLASS (tpl_log_iter_pidgin_parent_class)->dispose (object); -} - - -static void -tpl_log_iter_pidgin_finalize (GObject *object) -{ - G_OBJECT_CLASS (tpl_log_iter_pidgin_parent_class)->finalize (object); -} - - -static void -tpl_log_iter_pidgin_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - TplLogIterPidginPriv *priv; - - priv = TPL_LOG_ITER_PIDGIN (object)->priv; - - switch (param_id) - { - case PROP_ACCOUNT: - g_value_set_object (value, priv->account); - break; - - case PROP_STORE: - g_value_set_object (value, priv->store); - break; - - case PROP_TARGET: - g_value_set_object (value, priv->target); - break; - - case PROP_TYPE_MASK: - g_value_set_int (value, priv->type_mask); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - - -static void -tpl_log_iter_pidgin_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - TplLogIterPidginPriv *priv; - - priv = TPL_LOG_ITER_PIDGIN (object)->priv; - - switch (param_id) - { - case PROP_ACCOUNT: - priv->account = g_value_dup_object (value); - break; - - case PROP_STORE: - priv->store = g_value_dup_object (value); - break; - - case PROP_TARGET: - priv->target = g_value_dup_object (value); - break; - - case PROP_TYPE_MASK: - priv->type_mask = g_value_get_int (value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - - -static void -tpl_log_iter_pidgin_init (TplLogIterPidgin *iter) -{ - iter->priv = G_TYPE_INSTANCE_GET_PRIVATE (iter, TPL_TYPE_LOG_ITER_PIDGIN, - TplLogIterPidginPriv); -} - - -static void -tpl_log_iter_pidgin_class_init (TplLogIterPidginClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - TplLogIterClass *log_iter_class = TPL_LOG_ITER_CLASS (klass); - GParamSpec *param_spec; - - object_class->dispose = tpl_log_iter_pidgin_dispose; - object_class->finalize = tpl_log_iter_pidgin_finalize; - object_class->get_property = tpl_log_iter_pidgin_get_property; - object_class->set_property = tpl_log_iter_pidgin_set_property; - log_iter_class->get_events = tpl_log_iter_pidgin_get_events; - log_iter_class->rewind = tpl_log_iter_pidgin_rewind; - - param_spec = g_param_spec_object ("account", - "Account", - "The account whose logs are to be traversed", - TP_TYPE_ACCOUNT, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_ACCOUNT, param_spec); - - param_spec = g_param_spec_object ("store", - "Store", - "The storage backend from which the logs are to be retrieved", - TPL_TYPE_LOG_STORE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_STORE, param_spec); - - param_spec = g_param_spec_object ("target", - "Target", - "The target entity with which the account interacted", - TPL_TYPE_ENTITY, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_TARGET, param_spec); - - param_spec = g_param_spec_int ("type-mask", - "Type Mask", - "A bitmask to filter the events to be retrieved", - 1, - 0xffff, - TPL_EVENT_MASK_ANY, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_TYPE_MASK, param_spec); - - g_type_class_add_private (klass, sizeof (TplLogIterPidginPriv)); -} - - -TplLogIter * -tpl_log_iter_pidgin_new (TplLogStore *store, - TpAccount *account, - TplEntity *target, - gint type_mask) -{ - return g_object_new (TPL_TYPE_LOG_ITER_PIDGIN, - "store", store, - "account", account, - "target", target, - "type-mask", type_mask, - NULL); -} diff --git a/telepathy-logger/log-iter-xml-internal.h b/telepathy-logger/log-iter-xml-internal.h deleted file mode 100644 index 789c91f..0000000 --- a/telepathy-logger/log-iter-xml-internal.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2012 Red Hat, Inc. - * - * 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 - * - * Author: Debarshi Ray <debarshir@freedesktop.org> - */ - -#ifndef __TPL_LOG_ITER_XML_H__ -#define __TPL_LOG_ITER_XML_H__ - -#include <telepathy-glib/telepathy-glib.h> - -#include <telepathy-logger/entity.h> -#include <telepathy-logger/log-iter-internal.h> -#include <telepathy-logger/log-manager.h> -#include <telepathy-logger/log-store-internal.h> - -G_BEGIN_DECLS - -#define TPL_TYPE_LOG_ITER_XML (tpl_log_iter_xml_get_type ()) - -#define TPL_LOG_ITER_XML(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - TPL_TYPE_LOG_ITER_XML, TplLogIterXml)) - -#define TPL_LOG_ITER_XML_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), \ - TPL_TYPE_LOG_ITER_XML, TplLogIterXmlClass)) - -#define TPL_IS_LOG_ITER_XML(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - TPL_TYPE_LOG_ITER_XML)) - -#define TPL_IS_LOG_ITER_XML_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), \ - TPL_TYPE_LOG_ITER_XML)) - -#define TPL_LOG_ITER_XML_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), \ - TPL_TYPE_LOG_ITER_XML, TplLogIterXmlClass)) - -typedef struct _TplLogIterXml TplLogIterXml; -typedef struct _TplLogIterXmlClass TplLogIterXmlClass; -typedef struct _TplLogIterXmlPriv TplLogIterXmlPriv; - -struct _TplLogIterXml -{ - TplLogIter parent_instance; - TplLogIterXmlPriv *priv; -}; - -struct _TplLogIterXmlClass -{ - TplLogIterClass parent_class; -}; - -GType tpl_log_iter_xml_get_type (void) G_GNUC_CONST; - -TplLogIter *tpl_log_iter_xml_new (TplLogStore *store, - TpAccount *account, - TplEntity *target, - gint type_mask); - -G_END_DECLS - -#endif /* __TPL_LOG_ITER_XML_H__ */ diff --git a/telepathy-logger/log-iter-xml.c b/telepathy-logger/log-iter-xml.c deleted file mode 100644 index 1684a74..0000000 --- a/telepathy-logger/log-iter-xml.c +++ /dev/null @@ -1,326 +0,0 @@ -/* - * Copyright (C) 2012 Red Hat, Inc. - * - * 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 - * - * Author: Debarshi Ray <debarshir@freedesktop.org> - */ - -#include "config.h" -#include "log-iter-xml-internal.h" - - -struct _TplLogIterXmlPriv -{ - GList *dates; - GList *events; - GList *next_date; - GList *next_event; - TpAccount *account; - TplEntity *target; - TplLogStore *store; - gint type_mask; - -}; - -enum -{ - PROP_ACCOUNT = 1, - PROP_STORE, - PROP_TARGET, - PROP_TYPE_MASK -}; - - -G_DEFINE_TYPE (TplLogIterXml, tpl_log_iter_xml, TPL_TYPE_LOG_ITER); - - -static GList * -tpl_log_iter_xml_get_events (TplLogIter *iter, - guint num_events, - GError **error) -{ - TplLogIterXmlPriv *priv; - GList *events; - guint i; - - priv = TPL_LOG_ITER_XML (iter)->priv; - events = NULL; - - if (priv->dates == NULL) - { - priv->dates = _tpl_log_store_get_dates (priv->store, priv->account, - priv->target, priv->type_mask); - priv->next_date = g_list_last (priv->dates); - } - - i = 0; - while (i < num_events) - { - TplEvent *event; - - if (priv->next_event == NULL) - { - if (priv->next_date == NULL) - break; - - g_list_free_full (priv->events, g_object_unref); - priv->events = _tpl_log_store_get_events_for_date (priv->store, - priv->account, priv->target, priv->type_mask, - (GDate *) priv->next_date->data); - - priv->next_event = g_list_last (priv->events); - priv->next_date = g_list_previous (priv->next_date); - } - - event = TPL_EVENT (priv->next_event->data); - events = g_list_prepend (events, g_object_ref (event)); - i++; - - priv->next_event = g_list_previous (priv->next_event); - } - - return events; -} - - -static void -tpl_log_iter_xml_rewind (TplLogIter *iter, - guint num_events, - GError **error) -{ - GList *e; - TplLogIterXmlPriv *priv; - guint i; - - priv = TPL_LOG_ITER_XML (iter)->priv; - e = NULL; - - /* Set e to the last event that was returned */ - if (priv->next_event == NULL) - e = priv->events; - else - e = g_list_next (priv->next_event); - - i = 0; - while (i < num_events) - { - if (e == NULL) - { - GList *d; - - if (priv->next_date == NULL) - d = priv->dates; - else - d = g_list_next (priv->next_date); - - /* This can happen if get_events was never called or called - * with num_events == 0 - */ - if (d == NULL) - break; - - g_list_free_full (priv->events, g_object_unref); - priv->events = NULL; - priv->next_event = NULL; - - /* Rollback the priv->next_date */ - priv->next_date = d; - - /* Rollback the current date (ie. d) */ - d = g_list_next (d); - if (d == NULL) - break; - - priv->events = _tpl_log_store_get_events_for_date (priv->store, - priv->account, priv->target, priv->type_mask, - (GDate *) d->data); - e = priv->events; - } - - priv->next_event = e; - e = g_list_next (e); - i++; - } -} - - -static void -tpl_log_iter_xml_dispose (GObject *object) -{ - TplLogIterXmlPriv *priv; - - priv = TPL_LOG_ITER_XML (object)->priv; - - g_list_free_full (priv->dates, (GDestroyNotify) g_date_free); - priv->dates = NULL; - - g_list_free_full (priv->events, g_object_unref); - priv->events = NULL; - - g_clear_object (&priv->account); - g_clear_object (&priv->store); - g_clear_object (&priv->target); - - G_OBJECT_CLASS (tpl_log_iter_xml_parent_class)->dispose (object); -} - - -static void -tpl_log_iter_xml_finalize (GObject *object) -{ - G_OBJECT_CLASS (tpl_log_iter_xml_parent_class)->finalize (object); -} - - -static void -tpl_log_iter_xml_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - TplLogIterXmlPriv *priv; - - priv = TPL_LOG_ITER_XML (object)->priv; - - switch (param_id) - { - case PROP_ACCOUNT: - g_value_set_object (value, priv->account); - break; - - case PROP_STORE: - g_value_set_object (value, priv->store); - break; - - case PROP_TARGET: - g_value_set_object (value, priv->target); - break; - - case PROP_TYPE_MASK: - g_value_set_int (value, priv->type_mask); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - - -static void -tpl_log_iter_xml_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - TplLogIterXmlPriv *priv; - - priv = TPL_LOG_ITER_XML (object)->priv; - - switch (param_id) - { - case PROP_ACCOUNT: - priv->account = g_value_dup_object (value); - break; - - case PROP_STORE: - priv->store = g_value_dup_object (value); - break; - - case PROP_TARGET: - priv->target = g_value_dup_object (value); - break; - - case PROP_TYPE_MASK: - priv->type_mask = g_value_get_int (value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - - -static void -tpl_log_iter_xml_init (TplLogIterXml *iter) -{ - iter->priv = G_TYPE_INSTANCE_GET_PRIVATE (iter, TPL_TYPE_LOG_ITER_XML, - TplLogIterXmlPriv); -} - - -static void -tpl_log_iter_xml_class_init (TplLogIterXmlClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - TplLogIterClass *log_iter_class = TPL_LOG_ITER_CLASS (klass); - GParamSpec *param_spec; - - object_class->dispose = tpl_log_iter_xml_dispose; - object_class->finalize = tpl_log_iter_xml_finalize; - object_class->get_property = tpl_log_iter_xml_get_property; - object_class->set_property = tpl_log_iter_xml_set_property; - log_iter_class->get_events = tpl_log_iter_xml_get_events; - log_iter_class->rewind = tpl_log_iter_xml_rewind; - - param_spec = g_param_spec_object ("account", - "Account", - "The account whose logs are to be traversed", - TP_TYPE_ACCOUNT, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_ACCOUNT, param_spec); - - param_spec = g_param_spec_object ("store", - "Store", - "The storage backend from which the logs are to be retrieved", - TPL_TYPE_LOG_STORE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_STORE, param_spec); - - param_spec = g_param_spec_object ("target", - "Target", - "The target entity with which the account interacted", - TPL_TYPE_ENTITY, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_TARGET, param_spec); - - param_spec = g_param_spec_int ("type-mask", - "Type Mask", - "A bitmask to filter the events to be retrieved", - 1, - 0xffff, - TPL_EVENT_MASK_ANY, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_TYPE_MASK, param_spec); - - g_type_class_add_private (klass, sizeof (TplLogIterXmlPriv)); -} - - -TplLogIter * -tpl_log_iter_xml_new (TplLogStore *store, - TpAccount *account, - TplEntity *target, - gint type_mask) -{ - return g_object_new (TPL_TYPE_LOG_ITER_XML, - "store", store, - "account", account, - "target", target, - "type-mask", type_mask, - NULL); -} diff --git a/telepathy-logger/log-iter.c b/telepathy-logger/log-iter.c deleted file mode 100644 index 5ad1f53..0000000 --- a/telepathy-logger/log-iter.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2012 Red Hat, Inc. - * - * 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 - * - * Author: Debarshi Ray <debarshir@freedesktop.org> - */ - -#include "config.h" -#include "log-iter-internal.h" - - -G_DEFINE_TYPE (TplLogIter, tpl_log_iter, G_TYPE_OBJECT); - - -static void -tpl_log_iter_dispose (GObject *object) -{ - G_OBJECT_CLASS (tpl_log_iter_parent_class)->dispose (object); -} - - -static void -tpl_log_iter_finalize (GObject *object) -{ - G_OBJECT_CLASS (tpl_log_iter_parent_class)->finalize (object); -} - - -static void -tpl_log_iter_init (TplLogIter *self) -{ -} - - -static void -tpl_log_iter_class_init (TplLogIterClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - - object_class->dispose = tpl_log_iter_dispose; - object_class->finalize = tpl_log_iter_finalize; -} - - -GList * -tpl_log_iter_get_events (TplLogIter *self, - guint num_events, - GError **error) -{ - TplLogIterClass *log_iter_class; - - g_return_val_if_fail (TPL_IS_LOG_ITER (self), NULL); - - log_iter_class = TPL_LOG_ITER_GET_CLASS (self); - - if (log_iter_class->get_events == NULL) - return NULL; - - return log_iter_class->get_events (self, num_events, error); -} - - -void -tpl_log_iter_rewind (TplLogIter *self, - guint num_events, - GError **error) -{ - TplLogIterClass *log_iter_class; - - g_return_if_fail (TPL_IS_LOG_ITER (self)); - - log_iter_class = TPL_LOG_ITER_GET_CLASS (self); - - if (log_iter_class->rewind == NULL) - return; - - log_iter_class->rewind (self, num_events, error); -} diff --git a/telepathy-logger/log-manager-internal.h b/telepathy-logger/log-manager-internal.h deleted file mode 100644 index 56650de..0000000 --- a/telepathy-logger/log-manager-internal.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2003-2007 Imendio AB - * Copyright (C) 2007-2011 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: Xavier Claessens <xclaesse@gmail.com> - */ - -#ifndef __TPL_LOG_MANAGER_PRIV_H__ -#define __TPL_LOG_MANAGER_PRIV_H__ - -#include <telepathy-logger/log-manager.h> -#include <telepathy-logger/log-store-factory-internal.h> -#include <telepathy-logger/log-store-internal.h> - -#define TPL_TYPE_LOG_SEARCH_HIT (_tpl_log_manager_search_hit_get_type ()) - -gboolean _tpl_log_manager_add_event (TplLogManager *manager, - TplEvent *event, - GError **error); - -gboolean _tpl_log_manager_register_log_store (TplLogManager *self, - TplLogStore *logstore); - -GList * _tpl_log_manager_get_dates (TplLogManager *manager, - TpAccount *account, - TplEntity *target, - gint type_mask); - -GList * _tpl_log_manager_get_events_for_date (TplLogManager *manager, - TpAccount *account, - TplEntity *target, - gint type_mask, - const GDate *date); - -GList * _tpl_log_manager_get_filtered_events (TplLogManager *manager, - TpAccount *account, - TplEntity *target, - gint type_mask, - guint num_events, - TplLogEventFilter filter, - gpointer user_data); - -GList * _tpl_log_manager_get_entities (TplLogManager *manager, - TpAccount *account); - -GList * _tpl_log_manager_search (TplLogManager *manager, - const gchar *text, - gint type_mask); - -void _tpl_log_manager_clear (TplLogManager *self); - -void _tpl_log_manager_clear_account (TplLogManager *self, TpAccount *account); - -void _tpl_log_manager_clear_entity (TplLogManager *self, TpAccount *account, - TplEntity *entity); - -GType _tpl_log_manager_search_hit_get_type (void); - -TplLogSearchHit * _tpl_log_manager_search_hit_new (TpAccount *account, - TplEntity *target, - GDate *date); - -void _tpl_log_manager_search_hit_free (TplLogSearchHit *hit); - -TplLogSearchHit * _tpl_log_manager_search_hit_copy (TplLogSearchHit *hit); - -#endif /* __TPL_LOG_MANAGER_PRIV_H__ */ diff --git a/telepathy-logger/log-manager.c b/telepathy-logger/log-manager.c deleted file mode 100644 index b19d3b2..0000000 --- a/telepathy-logger/log-manager.c +++ /dev/null @@ -1,1682 +0,0 @@ -/* - * Copyright (C) 2003-2007 Imendio AB - * Copyright (C) 2007-2011 Collabora Ltd. - * Copyright (C) 2012 Red Hat, Inc. - * - * 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: Xavier Claessens <xclaesse@gmail.com> - * Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - */ - -#include "config.h" -#include "log-manager.h" -#include "log-manager-internal.h" - -#include <string.h> -#include <stdio.h> -#include <stdlib.h> - -#include <gio/gio.h> -#include <glib/gstdio.h> -#include <telepathy-glib/telepathy-glib.h> -#include <telepathy-glib/telepathy-glib-dbus.h> - -#include <telepathy-logger/conf-internal.h> -#include <telepathy-logger/entity-internal.h> -#include <telepathy-logger/event.h> -#include <telepathy-logger/event-internal.h> -#include <telepathy-logger/log-store-internal.h> -#include <telepathy-logger/log-store-empathy-internal.h> -#include <telepathy-logger/log-store-xml-internal.h> -#include <telepathy-logger/log-store-pidgin-internal.h> -#include <telepathy-logger/log-store-sqlite-internal.h> - -#define DEBUG_FLAG TPL_DEBUG_LOG_MANAGER -#include <telepathy-logger/debug-internal.h> -#include <telepathy-logger/log-walker-internal.h> -#include <telepathy-logger/util-internal.h> - -/** - * SECTION:log-manager - * @title: TplLogManager - * @short_description: Fetch and search through logs - * - * The #TplLogManager object allows user to fetch logs and make searches. - */ - -/** - * TplLogManager: - * - * An object used to access logs - */ - -/** - * TplLogEventFilter: - * @event: the #TplEvent to filter - * @user_data: user-supplied data - * - * Returns: %TRUE if @event should appear in the result - */ - -/** - * TPL_LOG_MANAGER_ERROR: - * - * The error domain for the #TplLogManager. - */ - -/* This macro is used to check if a list has been taken by a _finish() - * function call. It detects the marker set by _take_list() method. Those - * are used to avoid copying the full list on every call. */ -#define _LIST_TAKEN(l) ((l) != NULL && (l)->data == NULL) - -typedef struct -{ - TplConf *conf; - - GList *stores; - GList *writable_stores; - GList *readable_stores; -} TplLogManagerPriv; - - -typedef void (*TplLogManagerFreeFunc) (gpointer *data); - - -typedef struct -{ - TpAccount *account; - TplEntity *target; - gint type_mask; - GDate *date; - guint num_events; - TplLogEventFilter filter; - gchar *search_text; - gpointer user_data; - TplEvent *logevent; -} TplLogManagerEventInfo; - - -typedef struct -{ - TplLogManager *manager; - TplLogManagerEventInfo *request; - TplLogManagerFreeFunc request_free; - GAsyncReadyCallback cb; - gpointer user_data; -} TplLogManagerAsyncData; - - -G_DEFINE_TYPE (TplLogManager, tpl_log_manager, G_TYPE_OBJECT); - -G_DEFINE_BOXED_TYPE (TplLogSearchHit, - _tpl_log_manager_search_hit, - _tpl_log_manager_search_hit_copy, - _tpl_log_manager_search_hit_free); - -static TplLogManager *manager_singleton = NULL; - - -static void -log_manager_finalize (GObject *object) -{ - TplLogManagerPriv *priv; - - priv = TPL_LOG_MANAGER (object)->priv; - - g_object_unref (priv->conf); - - g_list_foreach (priv->stores, (GFunc) g_object_unref, NULL); - g_list_free (priv->stores); - /* no unref needed here, the only reference kept is in priv->stores */ - g_list_free (priv->writable_stores); - g_list_free (priv->readable_stores); - - G_OBJECT_CLASS (tpl_log_manager_parent_class)->finalize (object); -} - - -/* - * - Singleton LogManager constructor - - * Initialises LogStores with LogStoreEmpathy instance - */ -static GObject * -log_manager_constructor (GType type, - guint n_props, - GObjectConstructParam *props) -{ - GObject *retval = NULL; - - if (G_LIKELY (manager_singleton)) - retval = g_object_ref (manager_singleton); - else - { - retval = G_OBJECT_CLASS (tpl_log_manager_parent_class)->constructor ( - type, n_props, props); - if (retval == NULL) - return NULL; - - manager_singleton = TPL_LOG_MANAGER (retval); - g_object_add_weak_pointer (retval, (gpointer *) &manager_singleton); - } - - return retval; -} - - -static void -tpl_log_manager_class_init (TplLogManagerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->constructor = log_manager_constructor; - object_class->finalize = log_manager_finalize; - - g_type_class_add_private (object_class, sizeof (TplLogManagerPriv)); -} - - -static void -add_log_store (TplLogManager *self, - TplLogStore *store) -{ - g_return_if_fail (TPL_IS_LOG_STORE (store)); - - /* set the log store in "testmode" if it supports it and the environment is - * currently in test mode */ - if (g_object_class_find_property (G_OBJECT_GET_CLASS (store), "testmode")) - g_object_set (store, - "testmode", (g_getenv ("TPL_TEST_MODE") != NULL), - NULL); - - if (!_tpl_log_manager_register_log_store (self, store)) - CRITICAL ("Failed to register store name=%s", - _tpl_log_store_get_name (store)); - - /* drop the initial ref */ - g_object_unref (store); -} - - -static void -_globally_enabled_changed (TplConf *conf, - GParamSpec *pspec, - gpointer user_data) -{ - DEBUG ("Logging has been globally %s", - _tpl_conf_is_globally_enabled (conf) ? "enabled" : "disabled"); -} - - -static GList * -_take_list (GList *list) -{ - GList *copy = NULL; - - if (list != NULL) - { - copy = g_list_alloc (); - memcpy (copy, list, sizeof (GList)); - memset (list, 0, sizeof (GList)); - } - - return copy; -} - - -static void -_list_of_object_free (gpointer data) -{ - GList *lst = data; /* list of GObject */ - - if (!_LIST_TAKEN (lst)) - g_list_foreach (lst, (GFunc) g_object_unref, NULL); - - g_list_free (lst); -} - - -static void -_list_of_date_free (gpointer data) -{ - GList *lst = data; /* list of (GDate *) */ - - if (!_LIST_TAKEN (lst)) - g_list_foreach (lst, (GFunc) g_date_free, NULL); - - g_list_free (lst); -} - - -static void -tpl_log_manager_init (TplLogManager *self) -{ - TplLogManagerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - TPL_TYPE_LOG_MANAGER, TplLogManagerPriv); - - self->priv = priv; - - DEBUG ("Initialising the Log Manager"); - - priv->conf = _tpl_conf_dup (); - - g_signal_connect (priv->conf, "notify::globally-enabled", - G_CALLBACK (_globally_enabled_changed), NULL); - - /* The TPL's default read-write logstore */ - add_log_store (self, - g_object_new (TPL_TYPE_LOG_STORE_XML, - NULL)); - - /* Load by default the Empathy's legacy 'past coversations' LogStore */ - add_log_store (self, - g_object_new (TPL_TYPE_LOG_STORE_EMPATHY, - NULL)); - - add_log_store (self, - g_object_new (TPL_TYPE_LOG_STORE_PIDGIN, - NULL)); - - /* Load the event counting cache */ - add_log_store (self, - g_object_new (TPL_TYPE_LOG_STORE_SQLITE, - NULL)); - - DEBUG ("Log Manager initialised"); -} - - -/** - * tpl_log_manager_dup_singleton: - * - * Returns: (transfer full): a new reference on the log manager - */ -TplLogManager * -tpl_log_manager_dup_singleton (void) -{ - return g_object_new (TPL_TYPE_LOG_MANAGER, NULL); -} - -/* - * _tpl_log_manager_add_event: - * @manager: the log manager - * @event: a TplEvent subclass's instance - * @error: the memory location of GError, filled if an error occurs - * - * It stores @event, sending it to all the writable registered #TplLogStore objects. - * (Every TplLogManager is guaranteed to have at least one writable log store.) - * - * Returns: %TRUE if the event has been successfully added, otherwise %FALSE. - */ -gboolean -_tpl_log_manager_add_event (TplLogManager *manager, - TplEvent *event, - GError **error) -{ - TplLogManagerPriv *priv; - GList *l; - gboolean retval = FALSE; - - TplEntity *target; - TpAccount *account; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - g_return_val_if_fail (TPL_IS_LOG_MANAGER (manager), FALSE); - g_return_val_if_fail (TPL_IS_EVENT (event), FALSE); - - priv = manager->priv; - - if (!_tpl_conf_is_globally_enabled (priv->conf)) - { - /* ignore event, logging is globally disabled */ - return FALSE; - } - - account = tpl_event_get_account (event); - - /* check whether receiver is in the list of contacts to ignore */ - target = tpl_event_get_receiver (event); - if (tpl_log_manager_is_disabled_for_entity (manager, account, target)) - return FALSE; - - /* check whether sender is in the list of contacts to ignore */ - target = tpl_event_get_sender (event); - if (tpl_log_manager_is_disabled_for_entity (manager, account, target)) - return FALSE; - - /* send the event to any writable log store */ - for (l = priv->writable_stores; l != NULL; l = g_list_next (l)) - { - GError *loc_error = NULL; - TplLogStore *store = l->data; - gboolean result; - - result = _tpl_log_store_add_event (store, event, &loc_error); - if (!result) - { - CRITICAL ("logstore name=%s: %s. " - "Event may not be logged properly.", - _tpl_log_store_get_name (store), - loc_error != NULL ? loc_error->message : "no error message"); - g_clear_error (&loc_error); - } - /* TRUE if at least one LogStore succeeds */ - retval = result || retval; - } - if (!retval) - { - CRITICAL ("Failed to write event to all writable LogStores."); - g_set_error_literal (error, TPL_LOG_MANAGER_ERROR, - TPL_LOG_MANAGER_ERROR_ADD_EVENT, - "Non recoverable error occurred during log manager's " - "add_event() execution"); - } - return retval; -} - - -/* - * _tpl_log_manager_register_log_store: - * @self: the log manager - * @logstore: a TplLogStore interface implementation - * - * It registers @logstore into @manager, the log store has to be an - * implementation of the TplLogStore interface. - * - * @logstore has to properly implement all the search/query methods if the - * TplLogStore:readable is set to %TRUE. - */ -gboolean -_tpl_log_manager_register_log_store (TplLogManager *self, - TplLogStore *logstore) -{ - TplLogManagerPriv *priv = self->priv; - const gchar *name = _tpl_log_store_get_name (logstore); - GList *l; - - g_return_val_if_fail (TPL_IS_LOG_MANAGER (self), FALSE); - g_return_val_if_fail (TPL_IS_LOG_STORE (logstore), FALSE); - - /* check that the logstore name is not already used */ - for (l = priv->stores; l != NULL; l = g_list_next (l)) - { - TplLogStore *store = l->data; - - if (!tp_strdiff (name, _tpl_log_store_get_name (store))) - { - DEBUG ("name=%s: already registered", name); - return FALSE; - } - } - - if (_tpl_log_store_is_readable (logstore)) - priv->readable_stores = g_list_prepend (priv->readable_stores, logstore); - - if (_tpl_log_store_is_writable (logstore)) - priv->writable_stores = g_list_prepend (priv->writable_stores, logstore); - - /* reference just once, writable/readable lists are kept in sync with the - * general list and never written separately */ - priv->stores = g_list_prepend (priv->stores, g_object_ref (logstore)); - DEBUG ("LogStore name=%s registered", _tpl_log_store_get_name (logstore)); - - return TRUE; -} - - -/** - * tpl_log_manager_exists: - * @manager: TplLogManager - * @account: TpAccount - * @target: a non-NULL #TplEntity - * @type_mask: event type filter see #TplEventTypeMask - * - * Checks if logs exist for @target. - * - * It applies for any registered TplLogStore with the TplLogStore:readable - * property %TRUE. - - * Returns: %TRUE logs exist for @target, otherwise %FALSE - */ -gboolean -tpl_log_manager_exists (TplLogManager *manager, - TpAccount *account, - TplEntity *target, - gint type_mask) -{ - GList *l; - TplLogManagerPriv *priv; - - g_return_val_if_fail (TPL_IS_LOG_MANAGER (manager), FALSE); - g_return_val_if_fail (TPL_IS_ENTITY (target), FALSE); - - priv = manager->priv; - - for (l = priv->readable_stores; l != NULL; l = g_list_next (l)) - { - if (_tpl_log_store_exists (TPL_LOG_STORE (l->data), account, target, - type_mask)) - return TRUE; - } - - return FALSE; -} - - -/* - * _tpl_log_manager_get_dates: - * @manager: a #TplLogManager - * @account: a #TpAccount - * @target: a non-NULL #TplEntity - * - * Retrieves a list of #GDate corresponding to each day - * at least an event exist for @target_id. - * - * It applies for any registered TplLogStore with the TplLogStore:readable - * property %TRUE. - * - * Returns: a GList of (GDate *), to be freed using something like - * g_list_free_full (lst, g_date_free); - */ -GList * -_tpl_log_manager_get_dates (TplLogManager *manager, - TpAccount *account, - TplEntity *target, - gint type_mask) -{ - GList *l, *out = NULL; - TplLogManagerPriv *priv; - - g_return_val_if_fail (TPL_IS_LOG_MANAGER (manager), NULL); - g_return_val_if_fail (TPL_IS_ENTITY (target), NULL); - - priv = manager->priv; - - for (l = priv->readable_stores; l != NULL; 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, target, type_mask); - while (new) - { - 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) g_date_compare); - - new = g_list_delete_link (new, new); - } - } - - return out; -} - - -GList * -_tpl_log_manager_get_events_for_date (TplLogManager *manager, - TpAccount *account, - TplEntity *target, - gint type_mask, - const GDate *date) -{ - GList *l, *out = NULL; - TplLogManagerPriv *priv; - - g_return_val_if_fail (TPL_IS_LOG_MANAGER (manager), NULL); - g_return_val_if_fail (TPL_IS_ENTITY (target), NULL); - - priv = manager->priv; - - for (l = priv->readable_stores; l != NULL; l = g_list_next (l)) - { - TplLogStore *store = TPL_LOG_STORE (l->data); - - out = g_list_concat (out, _tpl_log_store_get_events_for_date (store, - account, target, type_mask, date)); - } - - return out; -} - - -GList * -_tpl_log_manager_get_filtered_events (TplLogManager *manager, - TpAccount *account, - TplEntity *target, - gint type_mask, - guint num_events, - TplLogEventFilter filter, - gpointer user_data) -{ - TplLogManagerPriv *priv; - GQueue out = G_QUEUE_INIT; - GList *l; - - g_return_val_if_fail (TPL_IS_LOG_MANAGER (manager), NULL); - g_return_val_if_fail (TPL_IS_ENTITY (target), NULL); - - priv = manager->priv; - - /* Get num_events from each log store and keep only the - * newest ones in the out list. Keep that list sorted: olders first. */ - for (l = priv->readable_stores; l != NULL; l = g_list_next (l)) - { - TplLogStore *store = TPL_LOG_STORE (l->data); - GList *new, *index = NULL; - - new = _tpl_log_store_get_filtered_events (store, account, target, - type_mask, num_events, filter, user_data); - - while (new != NULL) - { - index = _tpl_event_queue_insert_sorted_after (&out, index, new->data); - - if (out.length > num_events) - { - /* We have too many elements. Remove the oldest event. */ - g_object_unref (g_queue_pop_head (&out)); - } - - new = g_list_delete_link (new, new); - } - } - - return out.head; -} - - -/* - * _tpl_log_manager_get_entities: - * @manager: the log manager - * @account: a TpAccount the query will return data related to - * - * It queries the readable TplLogStores in @manager for all the buddies the - * log store has at least a conversation stored originated using @account. - * - * Returns: a list of pointer to #TplEntity, to be freed using something like - * g_list_free_full (lst, g_object_unref) - */ -GList * -_tpl_log_manager_get_entities (TplLogManager *manager, - TpAccount *account) -{ - GList *l, *out = NULL; - TplLogManagerPriv *priv; - - g_return_val_if_fail (TPL_IS_LOG_MANAGER (manager), NULL); - g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL); - - priv = manager->priv; - - for (l = priv->readable_stores; l != NULL; l = g_list_next (l)) - { - TplLogStore *store = TPL_LOG_STORE (l->data); - GList *in, *j; - - in = _tpl_log_store_get_entities (store, account); - /* merge the lists avoiding duplicates */ - for (j = in; j != NULL; j = g_list_next (j)) - { - TplEntity *entity = TPL_ENTITY (j->data); - - if (g_list_find_custom (out, entity, - (GCompareFunc) _tpl_entity_compare) == NULL) - { - /* add data if not already present */ - out = g_list_prepend (out, entity); - } - else - /* free hit if already present in out */ - g_object_unref (entity); - } - g_list_free (in); - } - - return out; -} - - -GList * -_tpl_log_manager_search (TplLogManager *manager, - const gchar *text, - gint type_mask) -{ - GList *l, *out = NULL; - TplLogManagerPriv *priv; - - g_return_val_if_fail (TPL_IS_LOG_MANAGER (manager), NULL); - g_return_val_if_fail (!TPL_STR_EMPTY (text), NULL); - - priv = manager->priv; - - for (l = priv->readable_stores; l != NULL; l = g_list_next (l)) - { - TplLogStore *store = TPL_LOG_STORE (l->data); - - out = g_list_concat (out, _tpl_log_store_search_new (store, text, - type_mask)); - } - - return out; -} - - -TplLogSearchHit * -_tpl_log_manager_search_hit_new (TpAccount *account, - TplEntity *target, - GDate *date) -{ - TplLogSearchHit *hit = g_slice_new0 (TplLogSearchHit); - - g_return_val_if_fail (TPL_IS_ENTITY (target), NULL); - - if (account != NULL) - hit->account = g_object_ref (account); - - hit->target = g_object_ref (target); - - if (date != NULL) - hit->date = g_date_new_dmy (g_date_get_day (date), g_date_get_month (date), - g_date_get_year (date)); - - return hit; -} - -void -_tpl_log_manager_search_hit_free (TplLogSearchHit *hit) -{ - if (hit->account != NULL) - g_object_unref (hit->account); - - if (hit->date != NULL) - g_date_free (hit->date); - - if (hit->target != NULL) - g_object_unref (hit->target); - - g_slice_free (TplLogSearchHit, hit); -} - - -/** - * tpl_log_manager_search_free: (skip) - * @hits: a #GList of #TplLogSearchHit - * - * Free @hits and its content. - */ -void -tpl_log_manager_search_free (GList *hits) -{ - GList *l; - - for (l = hits; l != NULL; l = g_list_next (l)) - { - if (l->data != NULL) - _tpl_log_manager_search_hit_free (l->data); - } - - g_list_free (hits); -} - - -/* start of Async definitions */ -static TplLogManagerAsyncData * -tpl_log_manager_async_data_new (void) -{ - return g_slice_new0 (TplLogManagerAsyncData); -} - - -static void -tpl_log_manager_async_data_free (TplLogManagerAsyncData *data) -{ - if (data->manager != NULL) - g_object_unref (data->manager); - data->request_free ((gpointer) data->request); - g_slice_free (TplLogManagerAsyncData, data); -} - - -static TplLogManagerEventInfo * -tpl_log_manager_event_info_new (void) -{ - return g_slice_new0 (TplLogManagerEventInfo); -} - - -static void -tpl_log_manager_event_info_free (TplLogManagerEventInfo *data) -{ - tp_clear_object (&data->account); - tp_clear_object (&data->logevent); - tp_clear_object (&data->target); - - tp_clear_pointer (&data->date, g_date_free); - tp_clear_pointer (&data->search_text, g_free); - g_slice_free (TplLogManagerEventInfo, data); -} - - -static void -_tpl_log_manager_async_operation_cb (GObject *source_object, - GAsyncResult *result, - gpointer user_data) -{ - TplLogManagerAsyncData *async_data = (TplLogManagerAsyncData *) user_data; - - if (async_data->cb) - async_data->cb (G_OBJECT (async_data->manager), result, - async_data->user_data); - - tpl_log_manager_async_data_free (async_data); -} - - -void -_tpl_log_manager_clear (TplLogManager *self) -{ - GList *l; - TplLogManagerPriv *priv; - - g_return_if_fail (TPL_IS_LOG_MANAGER (self)); - - priv = self->priv; - - for (l = priv->stores; l != NULL; l = g_list_next (l)) - { - _tpl_log_store_clear (TPL_LOG_STORE (l->data)); - } -} - - -void -_tpl_log_manager_clear_account (TplLogManager *self, - TpAccount *account) -{ - GList *l; - TplLogManagerPriv *priv; - - g_return_if_fail (TPL_IS_LOG_MANAGER (self)); - - priv = self->priv; - - for (l = priv->stores; l != NULL; l = g_list_next (l)) - { - _tpl_log_store_clear_account (TPL_LOG_STORE (l->data), account); - } -} - - -void -_tpl_log_manager_clear_entity (TplLogManager *self, - TpAccount *account, - TplEntity *entity) -{ - GList *l; - TplLogManagerPriv *priv; - - g_return_if_fail (TPL_IS_LOG_MANAGER (self)); - - priv = self->priv; - - for (l = priv->stores; l != NULL; l = g_list_next (l)) - { - _tpl_log_store_clear_entity (TPL_LOG_STORE (l->data), account, entity); - } -} - - -/* There is no g_date_copy() */ -static GDate * -copy_date (const GDate *date) -{ - return g_date_new_julian (g_date_get_julian (date)); -} - - -static void -_get_dates_async_thread (GSimpleAsyncResult *simple, - GObject *object, - GCancellable *cancellable) -{ - TplLogManagerAsyncData *async_data; - TplLogManagerEventInfo *event_info; - GList *lst = NULL; - - async_data = g_async_result_get_user_data (G_ASYNC_RESULT (simple)); - event_info = async_data->request; - - lst = _tpl_log_manager_get_dates (async_data->manager, - event_info->account, event_info->target, event_info->type_mask); - - g_simple_async_result_set_op_res_gpointer (simple, lst, - _list_of_date_free); -} - -typedef struct -{ - GSimpleAsyncResult *result; - GSimpleAsyncThreadFunc func; -} AsyncOpData; - -static AsyncOpData * -async_op_data_new (GSimpleAsyncResult *result, - GSimpleAsyncThreadFunc func) -{ - AsyncOpData *data = g_slice_new (AsyncOpData); - - data->result = g_object_ref (result); - data->func = func; - return data; -} - -static void -async_op_data_free (AsyncOpData *data) -{ - g_object_unref (data->result); - g_slice_free (AsyncOpData, data); -} - -static void -account_prepared_cb (GObject *source, - GAsyncResult *result, - gpointer user_data) -{ - AsyncOpData *data = user_data; - GError *error = NULL; - - if (!tp_proxy_prepare_finish (source, result, &error)) - { - g_simple_async_result_take_error (data->result, error); - g_simple_async_result_complete (data->result); - } - else - { - g_simple_async_result_run_in_thread (data->result, data->func, 0, NULL); - } - - async_op_data_free (data); -} - -static void -start_async_op_in_thread (TpAccount *account, - GSimpleAsyncResult *result, - GSimpleAsyncThreadFunc func) -{ - if (account != NULL) - { - GQuark features[] = { TP_ACCOUNT_FEATURE_CORE, 0 }; - - /* Most APIs rely on TpAccount being prepared, so make sure - * it is. telepathy-glib is not thread-safe, so we must do - * this in the main thread, before starting the actual - * operation in the other thread. */ - tp_proxy_prepare_async (account, features, account_prepared_cb, - async_op_data_new (result, func)); - } - else - { - g_simple_async_result_run_in_thread (result, func, 0, NULL); - } -} - -/** - * tpl_log_manager_get_dates_async: - * @manager: a #TplLogManager - * @account: a #TpAccount - * @target: a non-NULL #TplEntity - * @type_mask: event type filter see #TplEventTypeMask - * @callback: a callback to call when the request is satisfied - * @user_data: data to pass to @callback - * - * Retrieves a list of #GDate corresponding to each day where - * at least one event exist for @target. - * - * It applies for any registered TplLogStore with the TplLogStore:readable - * property %TRUE. - */ -void -tpl_log_manager_get_dates_async (TplLogManager *manager, - TpAccount *account, - TplEntity *target, - gint type_mask, - GAsyncReadyCallback callback, - gpointer user_data) -{ - TplLogManagerEventInfo *event_info = tpl_log_manager_event_info_new (); - TplLogManagerAsyncData *async_data = tpl_log_manager_async_data_new (); - GSimpleAsyncResult *simple; - - g_return_if_fail (TPL_IS_LOG_MANAGER (manager)); - g_return_if_fail (TP_IS_ACCOUNT (account)); - g_return_if_fail (TPL_IS_ENTITY (target)); - - event_info->account = g_object_ref (account); - event_info->target = g_object_ref (target); - event_info->type_mask = type_mask; - - async_data->manager = g_object_ref (manager); - async_data->request = event_info; - async_data->request_free = - (TplLogManagerFreeFunc) tpl_log_manager_event_info_free; - async_data->cb = callback; - async_data->user_data = user_data; - - simple = g_simple_async_result_new (G_OBJECT (manager), - _tpl_log_manager_async_operation_cb, async_data, - tpl_log_manager_get_dates_async); - - start_async_op_in_thread (account, simple, _get_dates_async_thread); - - g_object_unref (simple); -} - - -/** - * tpl_log_manager_get_dates_finish: - * @self: a #TplLogManager - * @result: a #GAsyncResult - * @dates: (out) (transfer full) (element-type GLib.Date): a pointer to a - * #GList used to return the list of #GDate - * @error: a #GError to fill - * - * Returns: #TRUE if the operation was successful, otherwise #FALSE - */ -gboolean -tpl_log_manager_get_dates_finish (TplLogManager *self, - GAsyncResult *result, - GList **dates, - GError **error) -{ - GSimpleAsyncResult *simple; - - g_return_val_if_fail (TPL_IS_LOG_MANAGER (self), FALSE); - g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE); - g_return_val_if_fail (g_simple_async_result_is_valid (result, - G_OBJECT (self), tpl_log_manager_get_dates_async), FALSE); - - simple = G_SIMPLE_ASYNC_RESULT (result); - - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - - if (dates != NULL) - *dates = _take_list (g_simple_async_result_get_op_res_gpointer (simple)); - - return TRUE; -} - - -static void -_get_events_for_date_async_thread (GSimpleAsyncResult *simple, - GObject *object, - GCancellable *cancellable) -{ - TplLogManagerAsyncData *async_data; - TplLogManagerEventInfo *event_info; - GList *lst; - - async_data = g_async_result_get_user_data (G_ASYNC_RESULT (simple)); - event_info = async_data->request; - - lst = _tpl_log_manager_get_events_for_date (async_data->manager, - event_info->account, - event_info->target, - event_info->type_mask, - event_info->date); - - g_simple_async_result_set_op_res_gpointer (simple, lst, - _list_of_object_free); -} - - -/** - * tpl_log_manager_get_events_for_date_async: - * @manager: a #TplLogManager - * @account: a #TpAccount - * @target: a non-NULL #TplEntity - * @type_mask: event type filter see #TplEventTypeMask - * @date: a #GDate - * @callback: a callback to call when the request is satisfied - * @user_data: data to pass to @callback - * - * Retrieve a list of #TplEvent at @date with @target. - */ -void -tpl_log_manager_get_events_for_date_async (TplLogManager *manager, - TpAccount *account, - TplEntity *target, - gint type_mask, - const GDate *date, - GAsyncReadyCallback callback, - gpointer user_data) -{ - TplLogManagerEventInfo *event_info = tpl_log_manager_event_info_new (); - TplLogManagerAsyncData *async_data = tpl_log_manager_async_data_new (); - GSimpleAsyncResult *simple; - - g_return_if_fail (TPL_IS_LOG_MANAGER (manager)); - g_return_if_fail (TP_IS_ACCOUNT (account)); - g_return_if_fail (TPL_IS_ENTITY (target)); - g_return_if_fail (date != NULL); - - event_info->account = g_object_ref (account); - event_info->target = g_object_ref (target); - event_info->type_mask = type_mask; - event_info->date = copy_date (date); - - async_data->manager = g_object_ref (manager); - async_data->request = event_info; - async_data->request_free = - (TplLogManagerFreeFunc) tpl_log_manager_event_info_free; - async_data->cb = callback; - async_data->user_data = user_data; - - simple = g_simple_async_result_new (G_OBJECT (manager), - _tpl_log_manager_async_operation_cb, async_data, - tpl_log_manager_get_events_for_date_async); - - start_async_op_in_thread (account, simple, _get_events_for_date_async_thread); - - g_object_unref (simple); -} - - -/** - * tpl_log_manager_get_events_for_date_finish: - * @self: a #TplLogManager - * @result: a #GAsyncResult - * @events: (out) (transfer full) (element-type TelepathyLogger1.Event): a - * pointer to a #GList used to return the list of #TplEvent - * @error: a #GError to fill - * - * Returns: #TRUE if the operation was successful, otherwise #FALSE - */ -gboolean -tpl_log_manager_get_events_for_date_finish (TplLogManager *self, - GAsyncResult *result, - GList **events, - GError **error) -{ - GSimpleAsyncResult *simple; - - g_return_val_if_fail (TPL_IS_LOG_MANAGER (self), FALSE); - g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE); - g_return_val_if_fail (g_simple_async_result_is_valid (result, - G_OBJECT (self), tpl_log_manager_get_events_for_date_async), FALSE); - - simple = G_SIMPLE_ASYNC_RESULT (result); - - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - - if (events != NULL) - *events = _take_list (g_simple_async_result_get_op_res_gpointer (simple)); - - return TRUE; -} - - -static void -_get_filtered_events_async_thread (GSimpleAsyncResult *simple, - GObject *object, - GCancellable *cancellable) -{ - TplLogManagerAsyncData *async_data; - TplLogManagerEventInfo *event_info; - GList *lst; - - async_data = g_async_result_get_user_data (G_ASYNC_RESULT (simple)); - event_info = async_data->request; - - lst = _tpl_log_manager_get_filtered_events (async_data->manager, - event_info->account, event_info->target, - event_info->type_mask, event_info->num_events, - event_info->filter, event_info->user_data); - - g_simple_async_result_set_op_res_gpointer (simple, lst, - _list_of_object_free); -} - - -/** - * tpl_log_manager_get_filtered_events_async: - * @manager: a #TplLogManager - * @account: a #TpAccount - * @target: a non-NULL #TplEntity - * @type_mask: event type filter see #TplEventTypeMask - * @num_events: number of maximum events to fetch - * @filter: (scope call) (allow-none): an optional filter function - * @filter_user_data: user data to pass to @filter - * @callback: (scope async) (allow-none): a callback to call when - * the request is satisfied - * @user_data: data to pass to @callback - * - * Retrieve the most recent @num_event events exchanged with @target. - */ -void -tpl_log_manager_get_filtered_events_async (TplLogManager *manager, - TpAccount *account, - TplEntity *target, - gint type_mask, - guint num_events, - TplLogEventFilter filter, - gpointer filter_user_data, - GAsyncReadyCallback callback, - gpointer user_data) -{ - TplLogManagerEventInfo *event_info = tpl_log_manager_event_info_new (); - TplLogManagerAsyncData *async_data = tpl_log_manager_async_data_new (); - GSimpleAsyncResult *simple; - - g_return_if_fail (TPL_IS_LOG_MANAGER (manager)); - g_return_if_fail (TP_IS_ACCOUNT (account)); - g_return_if_fail (TPL_IS_ENTITY (target)); - g_return_if_fail (num_events > 0); - - event_info->account = g_object_ref (account); - event_info->target = g_object_ref (target); - event_info->type_mask = type_mask; - event_info->num_events = num_events; - event_info->filter = filter; - event_info->user_data = filter_user_data; - - async_data->manager = g_object_ref (manager); - async_data->request = event_info; - async_data->request_free = - (TplLogManagerFreeFunc) tpl_log_manager_event_info_free; - async_data->cb = callback; - async_data->user_data = user_data; - - simple = g_simple_async_result_new (G_OBJECT (manager), - _tpl_log_manager_async_operation_cb, async_data, - tpl_log_manager_get_filtered_events_async); - - start_async_op_in_thread (account, simple, _get_filtered_events_async_thread); - - g_object_unref (simple); -} - - -/** - * tpl_log_manager_get_filtered_events_finish: - * @self: a #TplLogManager - * @result: a #GAsyncResult - * @events: (out) (transfer full) (element-type TelepathyLogger1.Event): - * a pointer to a #GList used to return the list #TplEvent - * @error: a #GError to fill - * - * Returns: #TRUE if the operation was successful, otherwise #FALSE. - */ -gboolean -tpl_log_manager_get_filtered_events_finish (TplLogManager *self, - GAsyncResult *result, - GList **events, - GError **error) -{ - GSimpleAsyncResult *simple; - - g_return_val_if_fail (TPL_IS_LOG_MANAGER (self), FALSE); - g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE); - g_return_val_if_fail (g_simple_async_result_is_valid (result, - G_OBJECT (self), tpl_log_manager_get_filtered_events_async), FALSE); - - simple = G_SIMPLE_ASYNC_RESULT (result); - - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - - if (events != NULL) - *events = _take_list (g_simple_async_result_get_op_res_gpointer (simple)); - - return TRUE; -} - - -/** - * tpl_log_manager_walk_filtered_events: - * @manager: a #TplLogManager - * @account: a #TpAccount - * @target: a non-NULL #TplEntity - * @type_mask: event type filter see #TplEventTypeMask - * @filter: (scope call) (allow-none): an optional filter function - * @filter_data: user data to pass to @filter - * - * Create a #TplLogWalker to traverse all the events exchanged with @target. - - * Returns: (transfer full): a #TplLogWalker - */ -TplLogWalker * -tpl_log_manager_walk_filtered_events (TplLogManager *manager, - TpAccount *account, - TplEntity *target, - gint type_mask, - TplLogEventFilter filter, - gpointer filter_data) -{ - TplLogManagerPriv *priv; - TplLogWalker *walker; - GList *l; - - g_return_val_if_fail (TPL_IS_LOG_MANAGER (manager), NULL); - g_return_val_if_fail (TPL_IS_ENTITY (target), NULL); - - priv = manager->priv; - walker = tpl_log_walker_new (filter, filter_data); - - for (l = priv->readable_stores; l != NULL; l = g_list_next (l)) - { - TplLogStore *store = TPL_LOG_STORE (l->data); - TplLogIter *iter; - - iter = _tpl_log_store_create_iter (store, account, target, type_mask); - if (iter != NULL) - tpl_log_walker_add_iter (walker, iter); - } - - return walker; -} - - -static void -_get_entities_async_thread (GSimpleAsyncResult *simple, - GObject *object, - GCancellable *cancellable) -{ - TplLogManagerAsyncData *async_data; - TplLogManagerEventInfo *event_info; - GList *lst; - - async_data = g_async_result_get_user_data (G_ASYNC_RESULT (simple)); - event_info = async_data->request; - - lst = _tpl_log_manager_get_entities (async_data->manager, event_info->account); - - g_simple_async_result_set_op_res_gpointer (simple, lst, - _list_of_object_free); -} - - -/** - * tpl_log_manager_get_entities_async: - * @self: a #TplLogManager - * @account: a #TpAccount - * @callback: a callback to call when the request is satisfied - * @user_data: data to pass to @callback - * - * Start a query looking for all entities for which you have logs in the @account. - */ -void -tpl_log_manager_get_entities_async (TplLogManager *self, - TpAccount *account, - GAsyncReadyCallback callback, - gpointer user_data) -{ - TplLogManagerEventInfo *event_info = tpl_log_manager_event_info_new (); - TplLogManagerAsyncData *async_data = tpl_log_manager_async_data_new (); - GSimpleAsyncResult *simple; - - g_return_if_fail (TPL_IS_LOG_MANAGER (self)); - g_return_if_fail (TP_IS_ACCOUNT (account)); - - event_info->account = g_object_ref (account); - - async_data->manager = g_object_ref (self); - async_data->request = event_info; - async_data->request_free = - (TplLogManagerFreeFunc) tpl_log_manager_event_info_free; - async_data->cb = callback; - async_data->user_data = user_data; - - simple = g_simple_async_result_new (G_OBJECT (self), - _tpl_log_manager_async_operation_cb, async_data, - tpl_log_manager_get_entities_async); - - start_async_op_in_thread (account, simple, _get_entities_async_thread); - - g_object_unref (simple); -} - - -/** - * tpl_log_manager_get_entities_finish: - * @self: a #TplLogManager - * @result: a #GAsyncResult - * @entities: (out) (transfer full) (element-type TelepathyLogger1.Entity): a - * pointer to a #GList used to return the list of #TplEntity, to be freed - * using something like g_list_free_full (lst, g_object_unref) - * @error: a #GError to fill - * - * Returns: #TRUE if the operation was successful, otherwise #FALSE - */ -gboolean -tpl_log_manager_get_entities_finish (TplLogManager *self, - GAsyncResult *result, - GList **entities, - GError **error) -{ - GSimpleAsyncResult *simple; - - g_return_val_if_fail (TPL_IS_LOG_MANAGER (self), FALSE); - g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE); - g_return_val_if_fail (g_simple_async_result_is_valid (result, - G_OBJECT (self), tpl_log_manager_get_entities_async), FALSE); - - simple = G_SIMPLE_ASYNC_RESULT (result); - - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - - if (entities != NULL) - *entities = _take_list (g_simple_async_result_get_op_res_gpointer (simple)); - - return TRUE; -} - - -static void -_search_async_thread (GSimpleAsyncResult *simple, - GObject *object, - GCancellable *cancellable) -{ - TplLogManagerAsyncData *async_data; - TplLogManagerEventInfo *event_info; - GList *lst; - - async_data = g_async_result_get_user_data (G_ASYNC_RESULT (simple)); - event_info = async_data->request; - - lst = _tpl_log_manager_search (async_data->manager, - event_info->search_text, event_info->type_mask); - - g_simple_async_result_set_op_res_gpointer (simple, lst, - (GDestroyNotify) tpl_log_manager_search_free); -} - - -/** - * tpl_log_manager_search_async: - * @manager: a #TplLogManager - * @text: the pattern to search - * @type_mask: event type filter see #TplEventTypeMask - * @callback: a callback to call when the request is satisfied - * @user_data: data to pass to @callback - * - * Search for all the conversations containing @text. - */ -void -tpl_log_manager_search_async (TplLogManager *manager, - const gchar *text, - gint type_mask, - GAsyncReadyCallback callback, - gpointer user_data) -{ - TplLogManagerEventInfo *event_info = tpl_log_manager_event_info_new (); - TplLogManagerAsyncData *async_data = tpl_log_manager_async_data_new (); - GSimpleAsyncResult *simple; - - g_return_if_fail (TPL_IS_LOG_MANAGER (manager)); - - event_info->search_text = g_strdup (text); - event_info->type_mask = type_mask; - - async_data->manager = g_object_ref (manager); - async_data->request = event_info; - async_data->request_free = - (TplLogManagerFreeFunc) tpl_log_manager_event_info_free; - async_data->cb = callback; - async_data->user_data = user_data; - - simple = g_simple_async_result_new (G_OBJECT (manager), - _tpl_log_manager_async_operation_cb, async_data, - tpl_log_manager_search_async); - - start_async_op_in_thread (NULL, simple, _search_async_thread); - - g_object_unref (simple); -} - - -/** - * tpl_log_manager_search_finish: - * @self: a #TplLogManager - * @result: a #GAsyncResult - * @hits: (out) (transfer full) (element-type TelepathyLogger1.LogSearchHit): a - * pointer to a #GList used to return the list of #TplLogSearchHit - * @error: a #GError to fill - * - * Returns: #TRUE if the operation was successful, otherwise #FALSE - */ -gboolean -tpl_log_manager_search_finish (TplLogManager *self, - GAsyncResult *result, - GList **hits, - GError **error) -{ - GSimpleAsyncResult *simple; - - g_return_val_if_fail (TPL_IS_LOG_MANAGER (self), FALSE); - g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE); - g_return_val_if_fail (g_simple_async_result_is_valid (result, - G_OBJECT (self), tpl_log_manager_search_async), FALSE); - - simple = G_SIMPLE_ASYNC_RESULT (result); - - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - - if (hits != NULL) - *hits = _take_list (g_simple_async_result_get_op_res_gpointer (simple)); - return TRUE; -} - - -/** - * tpl_log_manager_errors_quark: - * - * Returns: the #GQuark associated with the error domain of #TplLogManager - */ -GQuark -tpl_log_manager_errors_quark (void) -{ - static gsize quark = 0; - - if (g_once_init_enter (&quark)) - { - GQuark domain = g_quark_from_static_string ( - "tpl_log_manager_errors"); - - g_once_init_leave (&quark, domain); - } - - return (GQuark) quark; -} - - -TplLogSearchHit * -_tpl_log_manager_search_hit_copy (TplLogSearchHit *hit) -{ - return _tpl_log_manager_search_hit_new (hit->account, hit->target, - hit->date); -} - -static gchar * -_tpl_log_manager_build_identifier (TpAccount *account, - TplEntity *entity) -{ - gchar *identifier; - const gchar *acc_name = tp_proxy_get_object_path (account); - if (g_str_has_prefix (acc_name, TP_ACCOUNT_OBJECT_PATH_BASE)) - acc_name += strlen (TP_ACCOUNT_OBJECT_PATH_BASE); - - identifier = g_strconcat (acc_name, "/", tpl_entity_get_identifier (entity), NULL); - - return identifier; -} - -static gboolean -_tpl_log_manager_is_disabled_for_entity (TplLogManager *self, - const gchar *identifier) -{ - gint i; - TplLogManagerPriv *priv = self->priv; - const gchar **ignorelist; - - priv = self->priv; - ignorelist = _tpl_conf_get_ignorelist (priv->conf); - - for (i = 0; ignorelist && ignorelist[i]; i++) - { - if (g_strcmp0 (ignorelist[i], identifier) == 0) - { - return TRUE; - } - } - - return FALSE; -} - -/** - * tpl_log_manager_disable_for_entity: - * @self: the log manager - * @entity a TplEntity - * - * Disables logging of events for given entity. By default logging is enabled - * for all entities. - */ -void -tpl_log_manager_disable_for_entity (TplLogManager *self, - TpAccount *account, - TplEntity *entity) -{ - TplLogManagerPriv *priv; - gchar *identifier; - - g_return_if_fail (TPL_IS_LOG_MANAGER (self)); - g_return_if_fail (TP_IS_ACCOUNT (account)); - g_return_if_fail (TPL_IS_ENTITY (entity)); - - priv = self->priv; - identifier = _tpl_log_manager_build_identifier (account, entity); - if (!_tpl_log_manager_is_disabled_for_entity (self, identifier)) - { - const gchar **ignorelist = _tpl_conf_get_ignorelist (priv->conf); - gchar **newlist; - if (ignorelist) - { - gint newlen; - newlist = g_strdupv ((gchar **) ignorelist); - newlen = g_strv_length (newlist) + 1; - newlist = g_realloc (newlist, sizeof (gchar *) * newlen ); - newlist[newlen - 1] = g_strdup (identifier); - } - else - { - newlist = g_malloc0_n (2, sizeof (gchar *)); - newlist[0] = g_strdup (identifier); - } - - _tpl_conf_set_ignorelist (priv->conf, (const gchar **) newlist); - g_strfreev (newlist); - } - - g_free (identifier); -} - -/** - * tpl_log_manager_enable_for_entity: - * @self: the log manager - * @entity: a TplEntity - * - * Re-enables logging of events for entity previously disabled by - * tpl_log_manager_disable_for_entity(). By default logging is enabled for all - * entities. - */ -void -tpl_log_manager_enable_for_entity (TplLogManager *self, - TpAccount *account, - TplEntity *entity) -{ - TplLogManagerPriv *priv; - gchar *identifier; - - g_return_if_fail (TPL_IS_LOG_MANAGER (self)); - g_return_if_fail (TP_IS_ACCOUNT (account)); - g_return_if_fail (TPL_IS_ENTITY (entity)); - - priv = self->priv; - identifier = _tpl_log_manager_build_identifier (account, entity); - if (_tpl_log_manager_is_disabled_for_entity (self, identifier)) - { - gint i, j; - const gchar **ignorelist = _tpl_conf_get_ignorelist (priv->conf); - gchar **newlist; - - if (!ignorelist) - return; - - newlist = g_malloc0_n (g_strv_length ((gchar **) ignorelist) - 1, - sizeof (gchar *)); - j = 0; - for (i = 0; ignorelist && ignorelist[i]; i++) - { - if (g_strcmp0 (ignorelist[i], identifier) != 0) - { - newlist[j] = g_strdup (ignorelist[i]); - j++; - } - } - - _tpl_conf_set_ignorelist (priv->conf, (const gchar **) newlist); - g_strfreev (newlist); - } - - g_free (identifier); -} - -/** - * tpl_log_manager_is_disabled_for_entity: - * @self: the log manager - * @entity: a TplEntity - * - * Checks, whether logging is disabled for given entity. By default, logging - * is enabled for all entities. - * - * Returns: %TRUE if logging for the entity has been disabled, %FALSE otherwise. - */ -gboolean -tpl_log_manager_is_disabled_for_entity (TplLogManager *self, - TpAccount *account, - TplEntity *entity) -{ - gboolean is_disabled; - gchar *identifier; - - g_return_val_if_fail (TPL_IS_LOG_MANAGER (self), FALSE); - g_return_val_if_fail (TP_IS_ACCOUNT (account), FALSE); - g_return_val_if_fail (TPL_IS_ENTITY (entity), FALSE); - - identifier = _tpl_log_manager_build_identifier (account, entity); - is_disabled = _tpl_log_manager_is_disabled_for_entity (self, identifier); - g_free (identifier); - - return is_disabled; -} diff --git a/telepathy-logger/log-manager.h b/telepathy-logger/log-manager.h deleted file mode 100644 index df8c0bc..0000000 --- a/telepathy-logger/log-manager.h +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (C) 2003-2007 Imendio AB - * Copyright (C) 2007-2011 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: Xavier Claessens <xclaesse@gmail.com> - */ - -#ifndef __TPL_LOG_MANAGER_H__ -#define __TPL_LOG_MANAGER_H__ - -#include <gio/gio.h> -#include <glib-object.h> -#include <telepathy-glib/telepathy-glib.h> - -#include <telepathy-logger/event.h> -#include <telepathy-logger/log-walker.h> - -G_BEGIN_DECLS -#define TPL_TYPE_LOG_MANAGER (tpl_log_manager_get_type ()) -#define TPL_LOG_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TPL_TYPE_LOG_MANAGER, TplLogManager)) -#define TPL_LOG_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), TPL_TYPE_LOG_MANAGER, TplLogManagerClass)) -#define TPL_IS_LOG_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TPL_TYPE_LOG_MANAGER)) -#define TPL_IS_LOG_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TPL_TYPE_LOG_MANAGER)) -#define TPL_LOG_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TPL_TYPE_LOG_MANAGER, TplLogManagerClass)) - -#define TPL_LOG_MANAGER_ERROR tpl_log_manager_errors_quark() - -GQuark tpl_log_manager_errors_quark (void); - -/** - * TplLogManagerError: - * @TPL_LOG_MANAGER_ERROR_ADD_EVENT: Error return when adding logs fails - */ -typedef enum -{ - TPL_LOG_MANAGER_ERROR_ADD_EVENT -} TplLogManagerError; - -typedef struct _TplLogManager TplLogManager; - -struct _TplLogManager -{ - GObject parent; - - gpointer priv; -}; - -typedef struct -{ - GObjectClass parent_class; -} TplLogManagerClass; - -/** - * TplEventTypeMask: - * @TPL_EVENT_MASK_TEXT: Mask to #TplTextEvent - * @TPL_EVENT_MASK_CALL: Mask to #TplCallEvent - * @TPL_EVENT_MASK_ANY: Special value to select all type of #TplEvent - * - * Mask used to filter type of #TplEvent returned. - */ -typedef enum -{ - TPL_EVENT_MASK_TEXT = 1 << 0, - TPL_EVENT_MASK_CALL = 1 << 1, - TPL_EVENT_MASK_ANY = 0xffff -} TplEventTypeMask; - -/** - * TplLogSearchHit: - * @account: the #TpAccount - * @target: the #TplEntity - * @date: the #GDate - * - * Represent the context where the search has results. - */ -typedef struct _TplLogSearchHit TplLogSearchHit; -struct _TplLogSearchHit -{ - TpAccount *account; - TplEntity *target; - GDate *date; -}; - -typedef gboolean (*TplLogEventFilter) (TplEvent *event, - gpointer user_data); - -GType tpl_log_manager_get_type (void); - -TplLogManager *tpl_log_manager_dup_singleton (void); - -gboolean tpl_log_manager_exists (TplLogManager *manager, - TpAccount *account, - TplEntity *target, - gint type_mask); - -void tpl_log_manager_get_dates_async (TplLogManager *manager, - TpAccount *account, - TplEntity *target, - gint type_mask, - GAsyncReadyCallback callback, - gpointer user_data); - -gboolean tpl_log_manager_get_dates_finish (TplLogManager *self, - GAsyncResult *result, - GList **dates, - GError **error); - -void tpl_log_manager_get_events_for_date_async (TplLogManager *manager, - TpAccount *account, - TplEntity *target, - gint type_mask, - const GDate *date, - GAsyncReadyCallback callback, - gpointer user_data); - -gboolean tpl_log_manager_get_events_for_date_finish (TplLogManager *self, - GAsyncResult *result, - GList **events, - GError **error); - -void tpl_log_manager_get_filtered_events_async (TplLogManager *manager, - TpAccount *account, - TplEntity *target, - gint type_mask, - guint num_events, - TplLogEventFilter filter, - gpointer filter_user_data, - GAsyncReadyCallback callback, - gpointer user_data); - -gboolean tpl_log_manager_get_filtered_events_finish (TplLogManager *self, - GAsyncResult *result, - GList **events, - GError **error); - -TplLogWalker *tpl_log_manager_walk_filtered_events (TplLogManager *manager, - TpAccount *account, - TplEntity *target, - gint type_mask, - TplLogEventFilter filter, - gpointer filter_data); - -void tpl_log_manager_get_entities_async (TplLogManager *self, - TpAccount *account, - GAsyncReadyCallback callback, - gpointer user_data); - -gboolean tpl_log_manager_get_entities_finish (TplLogManager *self, - GAsyncResult *result, - GList **entities, - GError **error); - -void tpl_log_manager_search_async (TplLogManager *manager, - const gchar *text, - gint type_mask, - GAsyncReadyCallback callback, - gpointer user_data); - -gboolean tpl_log_manager_search_finish (TplLogManager *self, - GAsyncResult *result, - GList **hits, - GError **error); - -void tpl_log_manager_disable_for_entity (TplLogManager *self, - TpAccount *account, - TplEntity *entity); - -void tpl_log_manager_enable_for_entity (TplLogManager *self, - TpAccount *account, - TplEntity *entity); - -gboolean tpl_log_manager_is_disabled_for_entity (TplLogManager *self, - TpAccount *account, - TplEntity *entity); - -void tpl_log_manager_search_free (GList *hits); - -G_END_DECLS -#endif /* __TPL_LOG_MANAGER_H__ */ diff --git a/telepathy-logger/log-store-empathy-internal.h b/telepathy-logger/log-store-empathy-internal.h deleted file mode 100644 index e4645bd..0000000 --- a/telepathy-logger/log-store-empathy-internal.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright © 2013 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 - */ - -#ifndef TPL_LOG_STORE_EMPATHY_H -#define TPL_LOG_STORE_EMPATHY_H - -#include "log-store-xml-internal.h" - -typedef struct _TplLogStoreEmpathy TplLogStoreEmpathy; -typedef struct _TplLogStoreEmpathyClass TplLogStoreEmpathyClass; - -struct _TplLogStoreEmpathyClass { - /*< private >*/ - TplLogStoreXmlClass parent_class; -}; - -struct _TplLogStoreEmpathy { - TplLogStoreXml parent; -}; - -GType _tpl_log_store_empathy_get_type (void); - -/* TYPE MACROS */ -#define TPL_TYPE_LOG_STORE_EMPATHY \ - (_tpl_log_store_empathy_get_type ()) -#define TPL_LOG_STORE_EMPATHY(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), TPL_TYPE_LOG_STORE_EMPATHY, TplLogStoreEmpathy)) -#define TPL_LOG_STORE_EMPATHY_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass), TPL_TYPE_LOG_STORE_EMPATHY,\ - TplLogStoreEmpathyClass)) -#define TPL_IS_LOG_STORE_EMPATHY(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj), TPL_TYPE_LOG_STORE_EMPATHY)) -#define TPL_IS_LOG_STORE_EMPATHY_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass), TPL_TYPE_LOG_STORE_EMPATHY)) -#define TPL_LOG_STORE_EMPATHY_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_LOG_STORE_EMPATHY, \ - TplLogStoreEmpathyClass)) - -#endif /* TPL_LOG_STORE_EMPATHY_H */ diff --git a/telepathy-logger/log-store-empathy.c b/telepathy-logger/log-store-empathy.c deleted file mode 100644 index 651c721..0000000 --- a/telepathy-logger/log-store-empathy.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright ©2013 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 - */ - -/* - * This is a subclass of TplLogStoreXml to read logs from the directory Empathy - * used to store them it. It disables writing to that legacy location. - */ - -#include "config.h" -#include "log-store-empathy-internal.h" - -#include "telepathy-logger/log-store-internal.h" - -static void log_store_iface_init (gpointer g_iface, gpointer iface_data); - -G_DEFINE_TYPE_WITH_CODE (TplLogStoreEmpathy, _tpl_log_store_empathy, - TPL_TYPE_LOG_STORE_XML, - G_IMPLEMENT_INTERFACE (TPL_TYPE_LOG_STORE, log_store_iface_init)) - -static void -_tpl_log_store_empathy_init (TplLogStoreEmpathy *self) -{ -} - -static void -_tpl_log_store_empathy_class_init (TplLogStoreEmpathyClass *klass) -{ -} - - -static const gchar * -log_store_empathy_get_name (TplLogStore *store) -{ - TplLogStoreXml *self = (TplLogStoreXml *) store; - - g_return_val_if_fail (TPL_IS_LOG_STORE_EMPATHY (self), NULL); - - return "Empathy"; -} - -static void -log_store_iface_init (gpointer g_iface, - gpointer iface_data) -{ - TplLogStoreInterface *iface = (TplLogStoreInterface *) g_iface; - - iface->get_name = log_store_empathy_get_name; - - /* We don't want to store new logs in Empathy's directory, just read the old - * ones. */ - iface->add_event = NULL; -} diff --git a/telepathy-logger/log-store-factory-internal.h b/telepathy-logger/log-store-factory-internal.h deleted file mode 100644 index 84708f3..0000000 --- a/telepathy-logger/log-store-factory-internal.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2009 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: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - */ - -#ifndef __TPL_LOG_STORE_FACTORY_H__ -#define __TPL_LOG_STORE_FACTORY_H__ - -#include <glib-object.h> - -#include <telepathy-logger/log-store-internal.h> - -typedef TplLogStore* (*TplLogStoreConstructor) (const gchar *name, - gboolean write_access, gboolean read_access); -typedef TplLogStore* (*TplLogStoreFactory) (const gchar *logstore_type, - const gchar *name, gboolean write_access, gboolean read_access); - -void _tpl_log_store_factory_init (void); -void _tpl_log_store_factory_deinit (void); -void _tpl_log_store_factory_add (const gchar *logstore_type, - TplLogStoreConstructor constructor); -TplLogStoreConstructor _tpl_log_store_factory_lookup (const gchar *logstore_type); -TplLogStore * _tpl_log_store_factory_build (const gchar *logstore_type, - const gchar *name, gboolean write_access, gboolean read_access); - -#endif /* __TPL_LOG_STORE_FACTORY_H__ */ diff --git a/telepathy-logger/log-store-factory.c b/telepathy-logger/log-store-factory.c deleted file mode 100644 index 894677a..0000000 --- a/telepathy-logger/log-store-factory.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) 2009 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: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - */ - -#include "config.h" -#include "log-store-factory-internal.h" - -#define DEBUG_FLAG TPL_DEBUG_LOG_STORE -#include <telepathy-logger/debug-internal.h> -#include <telepathy-logger/util-internal.h> - -static GHashTable *logstores_table = NULL; - -void -_tpl_log_store_factory_init (void) -{ - g_return_if_fail (logstores_table == NULL); - - logstores_table = g_hash_table_new_full (g_str_hash, - (GEqualFunc) g_str_equal, g_free, NULL); -} - - -void -_tpl_log_store_factory_add (const gchar *logstore_type, - TplLogStoreConstructor constructor) -{ - gchar *key; - - g_return_if_fail (!TPL_STR_EMPTY (logstore_type)); - g_return_if_fail (constructor != NULL); - g_return_if_fail (logstores_table != NULL); - - key = g_strdup (logstore_type); - - if (g_hash_table_lookup (logstores_table, logstore_type) != NULL) - { - g_warning ("Type %s already mapped. replacing constructor.", - logstore_type); - g_hash_table_replace (logstores_table, key, constructor); - } - else - g_hash_table_insert (logstores_table, key, constructor); -} - - -TplLogStoreConstructor -_tpl_log_store_factory_lookup (const gchar *logstore_type) -{ - g_return_val_if_fail (!TPL_STR_EMPTY (logstore_type), NULL); - g_return_val_if_fail (logstores_table != NULL, NULL); - - return g_hash_table_lookup (logstores_table, logstore_type); -} - -void -_tpl_log_store_factory_deinit (void) -{ - g_return_if_fail (logstores_table != NULL); - - g_hash_table_unref (logstores_table); - logstores_table = NULL; -} - -TplLogStore * -_tpl_log_store_factory_build (const gchar *logstore_type, - const gchar *name, - gboolean write_access, - gboolean read_access) -{ - TplLogStoreConstructor constructor; - - g_return_val_if_fail (logstores_table != NULL, NULL); - - constructor = _tpl_log_store_factory_lookup (logstore_type); - if (constructor == NULL) - { - DEBUG ("%s: log store type not handled by this logger", logstore_type); - return NULL; - } - - return constructor (name, write_access, read_access); -} diff --git a/telepathy-logger/log-store-internal.h b/telepathy-logger/log-store-internal.h deleted file mode 100644 index 9b0a666..0000000 --- a/telepathy-logger/log-store-internal.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (C) 2008-2011 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: Jonny Lamb <jonny.lamb@collabora.co.uk> - * Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - */ - -#ifndef __TPL_LOG_STORE_H__ -#define __TPL_LOG_STORE_H__ - -#include <glib-object.h> -#include <telepathy-glib/telepathy-glib.h> - -#include <telepathy-logger/event.h> -#include <telepathy-logger/log-iter-internal.h> -#include <telepathy-logger/log-manager.h> - -G_BEGIN_DECLS - -#define TPL_TYPE_LOG_STORE (_tpl_log_store_get_type ()) -#define TPL_LOG_STORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - TPL_TYPE_LOG_STORE, TplLogStore)) -#define TPL_IS_LOG_STORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - TPL_TYPE_LOG_STORE)) -#define TPL_LOG_STORE_GET_INTERFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ( \ - (inst), TPL_TYPE_LOG_STORE, TplLogStoreInterface)) - -#define TPL_LOG_STORE_ERROR g_quark_from_static_string ("tpl-log-store-error-quark") -typedef enum -{ - /* generic error */ - TPL_LOG_STORE_ERROR_FAILED, - /* generic failure for add_event() method, when nothing else applies */ - TPL_LOG_STORE_ERROR_ADD_EVENT, - /* data is already present in the LogStore */ - TPL_LOG_STORE_ERROR_PRESENT, - /* data is not present in the LogStore */ - TPL_LOG_STORE_ERROR_NOT_PRESENT, - /* to be used in TplLogStoreIndexError as first value, so that value won't - * overlap */ - TPL_LOG_STORE_ERROR_LAST -} TplLogStoreError; - -typedef struct _TplLogStore TplLogStore; /*dummy object */ - -typedef struct -{ - GTypeInterface parent; - - const gchar * (*get_name) (TplLogStore *self); - gboolean (*exists) (TplLogStore *self, TpAccount *account, - TplEntity *target, gint type_mask); - gboolean (*add_event) (TplLogStore *self, TplEvent *event, - GError **error); - GList * (*get_dates) (TplLogStore *self, TpAccount *account, - TplEntity *target, gint type_mask); - GList * (*get_events_for_date) (TplLogStore *self, TpAccount *account, - TplEntity *target, gint type_mask, const GDate *date); - GList * (*get_recent_events) (TplLogStore *self, TpAccount *account, - TplEntity *target, gint type_mask); - GList * (*get_entities) (TplLogStore *self, TpAccount *account); - GList * (*search_new) (TplLogStore *self, const gchar *text, gint type_mask); - GList * (*get_filtered_events) (TplLogStore *self, TpAccount *account, - TplEntity *target, gint type_mask, guint num_events, - TplLogEventFilter filter, gpointer user_data); - void (*clear) (TplLogStore *self); - void (*clear_account) (TplLogStore *self, TpAccount *account); - void (*clear_entity) (TplLogStore *self, TpAccount *account, - TplEntity *entity); - TplLogIter * (*create_iter) (TplLogStore *self, TpAccount *account, - TplEntity *target, gint type_mask); -} TplLogStoreInterface; - -GType _tpl_log_store_get_type (void); - -const gchar * _tpl_log_store_get_name (TplLogStore *self); -gboolean _tpl_log_store_exists (TplLogStore *self, TpAccount *account, - TplEntity *target, gint type_mask); -gboolean _tpl_log_store_add_event (TplLogStore *self, TplEvent *event, - GError **error); -GList * _tpl_log_store_get_dates (TplLogStore *self, TpAccount *account, - TplEntity *target, gint type_mask); -GList * _tpl_log_store_get_events_for_date (TplLogStore *self, - TpAccount *account, TplEntity *target, gint type_mask, const GDate *date); -GList * _tpl_log_store_get_recent_events (TplLogStore *self, - TpAccount *account, TplEntity *target, gint type_mask); -GList * _tpl_log_store_get_entities (TplLogStore *self, TpAccount *account); -GList * _tpl_log_store_search_new (TplLogStore *self, const gchar *text, - gint type_mask); -GList * _tpl_log_store_get_filtered_events (TplLogStore *self, - TpAccount *account, TplEntity *target, gint type_mask, guint num_events, - TplLogEventFilter filter, gpointer user_data); -void _tpl_log_store_clear (TplLogStore *self); -void _tpl_log_store_clear_account (TplLogStore *self, TpAccount *account); -void _tpl_log_store_clear_entity (TplLogStore *self, TpAccount *account, - TplEntity *entity); -TplLogIter * _tpl_log_store_create_iter (TplLogStore *self, - TpAccount *account, TplEntity *target, gint type_mask); -gboolean _tpl_log_store_is_writable (TplLogStore *self); -gboolean _tpl_log_store_is_readable (TplLogStore *self); - -G_END_DECLS - -#endif /*__TPL_LOG_STORE_H__ */ diff --git a/telepathy-logger/log-store-pidgin-internal.h b/telepathy-logger/log-store-pidgin-internal.h deleted file mode 100644 index abe214e..0000000 --- a/telepathy-logger/log-store-pidgin-internal.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2008-2011 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: Jonny Lamb <jonny.lamb@collabora.co.uk> - * Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - */ - -#ifndef __TPL_LOG_STORE_PIDGIN_H__ -#define __TPL_LOG_STORE_PIDGIN_H__ - -#include <glib.h> -#include <glib-object.h> - -G_BEGIN_DECLS - -#define TPL_TYPE_LOG_STORE_PIDGIN \ - (tpl_log_store_pidgin_get_type ()) -#define TPL_LOG_STORE_PIDGIN(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_LOG_STORE_PIDGIN, \ - TplLogStorePidgin)) -#define TPL_LOG_STORE_PIDGIN_CLASS(vtable) \ - (G_TYPE_CHECK_CLASS_CAST ((vtable), TPL_TYPE_LOG_STORE_PIDGIN, \ - TplLogStorePidginClass)) -#define TPL_IS_LOG_STORE_PIDGIN(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_LOG_STORE_PIDGIN)) -#define TPL_IS_LOG_STORE_PIDGIN_CLASS(vtable) \ - (G_TYPE_CHECK_CLASS_TYPE ((vtable), TPL_TYPE_LOG_STORE_PIDGIN)) -#define TPL_LOG_STORE_PIDGIN_GET_CLASS(inst) \ - (G_TYPE_INSTANCE_GET_CLASS ((inst), TPL_TYPE_LOG_STORE_PIDGIN, \ - TplLogStorePidginClass)) - -typedef struct _TplLogStorePidginPriv TplLogStorePidginPriv; - -typedef struct -{ - GObject parent; - TplLogStorePidginPriv *priv; -} TplLogStorePidgin; - -typedef struct -{ - GObjectClass parent; -} TplLogStorePidginClass; - -GType tpl_log_store_pidgin_get_type (void); - -G_END_DECLS - -#endif /* __TPL_LOG_STORE_PIDGIN_H__ */ diff --git a/telepathy-logger/log-store-pidgin.c b/telepathy-logger/log-store-pidgin.c deleted file mode 100644 index c2c12cf..0000000 --- a/telepathy-logger/log-store-pidgin.c +++ /dev/null @@ -1,1161 +0,0 @@ -/* - * Copyright (C) 2008-2011 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: Jonny Lamb <jonny.lamb@collabora.co.uk> - * Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - */ - -#include <config.h> - -#define _XOPEN_SOURCE -#include <time.h> -#include <string.h> -#include <stdio.h> - -#include <telepathy-glib/telepathy-glib.h> - -#include "log-iter-pidgin-internal.h" -#include "log-store-internal.h" -#include "log-store-pidgin-internal.h" -#include "log-manager-internal.h" -#include "text-event-internal.h" -#include "entity-internal.h" -#include "util-internal.h" - -#define DEBUG_FLAG TPL_DEBUG_LOG_STORE -#include "debug-internal.h" - -#define TPL_LOG_STORE_PIDGIN_NAME "Pidgin" - -#define TXT_LOG_FILENAME_SUFFIX ".txt" -#define HTML_LOG_FILENAME_SUFFIX ".html" - -struct _TplLogStorePidginPriv -{ - gboolean test_mode; - TpAccountManager *account_manager; - - gchar *basedir; -}; - -enum { - PROP_0, - PROP_READABLE, - PROP_BASEDIR, - PROP_TESTMODE, -}; - - - -static void log_store_iface_init (gpointer g_iface, gpointer iface_data); -static void tpl_log_store_pidgin_get_property (GObject *object, guint param_id, GValue *value, - GParamSpec *pspec); -static void tpl_log_store_pidgin_set_property (GObject *object, guint param_id, const GValue *value, - GParamSpec *pspec); -static const gchar *log_store_pidgin_get_name (TplLogStore *store); -static const gchar *log_store_pidgin_get_basedir (TplLogStorePidgin *self); -static void log_store_pidgin_set_basedir (TplLogStorePidgin *self, - const gchar *data); - - -G_DEFINE_TYPE_WITH_CODE (TplLogStorePidgin, tpl_log_store_pidgin, - G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (TPL_TYPE_LOG_STORE, log_store_iface_init)); - -static void -tpl_log_store_pidgin_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - TplLogStorePidginPriv *priv = TPL_LOG_STORE_PIDGIN (object)->priv; - - switch (param_id) - { - case PROP_READABLE: - g_value_set_boolean (value, TRUE); - break; - case PROP_BASEDIR: - g_value_set_string (value, priv->basedir); - break; - case PROP_TESTMODE: - g_value_set_boolean (value, priv->test_mode); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - }; -} - - -static void -tpl_log_store_pidgin_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - TplLogStorePidgin *self = TPL_LOG_STORE_PIDGIN (object); - - switch (param_id) - { - case PROP_BASEDIR: - log_store_pidgin_set_basedir (self, g_value_get_string (value)); - break; - case PROP_TESTMODE: - self->priv->test_mode = g_value_get_boolean (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - }; -} - - -static void -tpl_log_store_pidgin_dispose (GObject *self) -{ - TplLogStorePidginPriv *priv = TPL_LOG_STORE_PIDGIN (self)->priv; - - g_clear_object (&priv->account_manager); - g_free (priv->basedir); - priv->basedir = NULL; - - G_OBJECT_CLASS (tpl_log_store_pidgin_parent_class)->dispose (self); -} - - -static void -tpl_log_store_pidgin_class_init (TplLogStorePidginClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GParamSpec *param_spec; - - object_class->get_property = tpl_log_store_pidgin_get_property; - object_class->set_property = tpl_log_store_pidgin_set_property; - object_class->dispose = tpl_log_store_pidgin_dispose; - - g_object_class_override_property (object_class, PROP_READABLE, "readable"); - - /** - * TplLogStorePidgin:basedir: - * - * The log store's basedir. - */ - param_spec = g_param_spec_string ("basedir", - "Basedir", - "The directory where the LogStore will look for data", - NULL, G_PARAM_READABLE | G_PARAM_WRITABLE | - G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_BASEDIR, param_spec); - - - param_spec = g_param_spec_boolean ("testmode", - "TestMode", - "Whether the logstore is in testmode, for testsuite use only", - FALSE, G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_TESTMODE, param_spec); - - - g_type_class_add_private (object_class, sizeof (TplLogStorePidginPriv)); -} - - -static void -tpl_log_store_pidgin_init (TplLogStorePidgin *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - TPL_TYPE_LOG_STORE_PIDGIN, TplLogStorePidginPriv); - - self->priv->account_manager = tp_account_manager_dup (); -} - - -static const gchar * -log_store_pidgin_get_name (TplLogStore *store) -{ - TplLogStorePidgin *self = (TplLogStorePidgin *) store; - - g_return_val_if_fail (TPL_IS_LOG_STORE_PIDGIN (self), NULL); - - return TPL_LOG_STORE_PIDGIN_NAME; -} - - -/* returns an absolute path for the base directory of LogStore */ -static const gchar * -log_store_pidgin_get_basedir (TplLogStorePidgin *self) -{ - g_return_val_if_fail (TPL_IS_LOG_STORE_PIDGIN (self), NULL); - - /* If basedir isn't yet set (defaults to NULL), use the libpurple default - * location, useful for testing logstore with a different basedir */ - if (self->priv->basedir == NULL) - { - gchar *dir; - - if (self->priv->test_mode && g_getenv ("TPL_TEST_LOG_DIR") != NULL) - dir = g_build_path (G_DIR_SEPARATOR_S, g_getenv ("TPL_TEST_LOG_DIR"), - "purple", NULL); - else - dir = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir (), ".purple", - "logs", NULL); - log_store_pidgin_set_basedir (self, dir); - - g_free (dir); - } - - return self->priv->basedir; -} - - -static void -log_store_pidgin_set_basedir (TplLogStorePidgin *self, - const gchar *data) -{ - g_return_if_fail (TPL_IS_LOG_STORE_PIDGIN (self)); - g_return_if_fail (self->priv->basedir == NULL); - /* data may be NULL when the class is initialized and the default value is - * set */ - - self->priv->basedir = g_strdup (data); - - /* at install_spec time, default value is set to NULL, ignore it */ - if (self->priv->basedir != NULL) - DEBUG ("logstore set to dir: %s", data); -} - - -/* internal: get the full name of the storing directory, including protocol - * and id */ -static gchar * -log_store_pidgin_get_dir (TplLogStore *self, - TpAccount *account, - TplEntity *target) -{ - const gchar *protocol; - gchar *basedir; - gchar *username, *normalized, *tmp; - gchar *id = NULL; /* if not NULL, it contains a modified version of - target id, to be g_free'd */ - const GHashTable *params; - - params = tp_account_get_parameters (account); - protocol = tp_account_get_protocol_name (account); - - if (tp_strdiff (protocol, "irc") == 0) - { - const gchar *account_param, *server; - - account_param = tp_asv_get_string (params, "account"); - server = tp_asv_get_string (params, "server"); - - username = g_strdup_printf ("%s@%s", account_param, server); - } - else - { - username = g_strdup (tp_asv_get_string (params, "account")); - } - - if (username == NULL) - { - DEBUG ("Failed to get account"); - return NULL; - } - - normalized = g_utf8_normalize (username, -1, G_NORMALIZE_DEFAULT); - g_free (username); - - if (target != NULL) - { - const gchar *orig_id = tpl_entity_get_identifier (target); - - if (tpl_entity_get_entity_type (target) == TPL_ENTITY_ROOM) - id = g_strdup_printf ("%s.chat", orig_id); - else if (g_str_has_suffix (orig_id, "#1")) - /* Small butterfly workaround */ - id = g_strndup (orig_id, strlen (orig_id) - 2); - else - id = g_strdup (orig_id); - } - - tmp = g_uri_escape_string (normalized, "#@", TRUE); - g_free (normalized); - normalized = tmp; /* now normalized and escaped */ - - /* purple basedir + protocol name + account name + recipient id */ - basedir = g_build_path (G_DIR_SEPARATOR_S, - log_store_pidgin_get_basedir (TPL_LOG_STORE_PIDGIN (self)), - protocol, - normalized, - id, - NULL); - - g_free (id); - g_free (normalized); - - return basedir; -} - - -/* public: returns whether some data for @id exist in @account */ -static gboolean -log_store_pidgin_exists (TplLogStore *self, - TpAccount *account, - TplEntity *target, - gint type_mask) -{ - gchar *dir; - gboolean exists; - - if (!(type_mask & TPL_EVENT_MASK_TEXT)) - return FALSE; - - dir = log_store_pidgin_get_dir (self, account, target); - - if (dir != NULL) - exists = g_file_test (dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR); - else - exists = FALSE; - - g_free (dir); - - return exists; -} - - -/* internal */ -static GDate * -log_store_pidgin_get_time (const gchar *filename) -{ - gchar *date; - GDate *retval = NULL; - const gchar *p; - - gint year; - gint month; - gint day; - - if (filename == NULL) - return NULL; - - if (g_str_has_suffix (filename, TXT_LOG_FILENAME_SUFFIX)) - { - p = strstr (filename, TXT_LOG_FILENAME_SUFFIX); - date = g_strndup (filename, p - filename); - } - else if (g_str_has_suffix (filename, HTML_LOG_FILENAME_SUFFIX)) - { - p = strstr (filename, HTML_LOG_FILENAME_SUFFIX); - date = g_strndup (filename, p - filename); - } - else - { - date = g_strdup (filename); - } - - sscanf (date, "%4d-%2d-%2d.*s", &year, &month, &day); - - DEBUG ("date is %s", date); - retval = g_date_new_dmy (day, month, year); - g_free (date); - - return retval; -} - - -static GList * -log_store_pidgin_get_dates (TplLogStore *self, - TpAccount *account, - TplEntity *target, - gint type_mask) -{ - GList *dates = NULL; - gchar *directory; - GDir *dir; - const gchar *filename; - - g_return_val_if_fail (TPL_IS_LOG_STORE_PIDGIN (self), NULL); - g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL); - g_return_val_if_fail (TPL_IS_ENTITY (target), NULL); - - if (!(type_mask & TPL_EVENT_MASK_TEXT)) - return NULL; - - directory = log_store_pidgin_get_dir (self, account, target); - - if (directory == NULL) - return NULL; - - dir = g_dir_open (directory, 0, NULL); - if (dir == NULL) - { - DEBUG ("Could not open directory:'%s'", directory); - g_free (directory); - return NULL; - } - - DEBUG ("Collating a list of dates in: '%s'", directory); - - while ((filename = g_dir_read_name (dir)) != NULL) - { - GDate *date; - - if (!g_str_has_suffix (filename, TXT_LOG_FILENAME_SUFFIX) - && !g_str_has_suffix (filename, HTML_LOG_FILENAME_SUFFIX)) - continue; - DEBUG ("%s: %s %s\n", G_STRFUNC, directory, filename); - - date = log_store_pidgin_get_time (filename); - dates = g_list_insert_sorted (dates, date, (GCompareFunc) g_date_compare); - } - - g_free (directory); - g_dir_close (dir); - - DEBUG ("Parsed %d dates", g_list_length (dates)); - - return dates; -} - - -static GList * -log_store_pidgin_get_filenames_for_date (TplLogStore *self, - TpAccount *account, - TplEntity *target, - const GDate *date) -{ - gchar *basedir; - gchar timestamp[11]; - GList *filenames = NULL; - GDir *dir; - const gchar *dirfile; - - basedir = log_store_pidgin_get_dir (self, account, target); - - if (basedir == NULL) - return NULL; - - dir = g_dir_open (basedir, 0, NULL); - if (dir == NULL) - { - g_free (basedir); - return NULL; - } - - g_date_strftime (timestamp, 11, "%F", date); - - while ((dirfile = g_dir_read_name (dir)) != NULL) - { - if (!g_str_has_suffix (dirfile, TXT_LOG_FILENAME_SUFFIX) - && !g_str_has_suffix (dirfile, HTML_LOG_FILENAME_SUFFIX)) - continue; - - if (g_str_has_prefix (dirfile, timestamp)) - { - filenames = g_list_insert_sorted (filenames, - g_build_filename (basedir, dirfile, NULL), - (GCompareFunc) g_strcmp0); - } - } - - g_dir_close (dir); - - g_free (basedir); - - return filenames; -} - - -static TpAccount * -log_store_pidgin_dup_account (TplLogStorePidgin *self, - const gchar *filename) -{ - GList *accounts, *l; - TpAccount *account = NULL; - gchar **strv; - guint len; - gchar *protocol, *username, *server = NULL, *tmp; - gboolean is_irc; - - accounts = tp_account_manager_dup_usable_accounts ( - self->priv->account_manager); - - strv = g_strsplit (filename, G_DIR_SEPARATOR_S, -1); - len = g_strv_length (strv); - - protocol = strv[len - 4]; - tmp = strchr (strv[len - 3], '@'); - is_irc = !tp_strdiff (protocol, "irc"); - - if (is_irc && tmp != NULL) - { - username = g_strndup (strv[len - 3], tmp - strv[len - 3]); - server = g_strdup (strv[len - 3] + (tmp - strv[len - 3]) + 1); - } - else - { - username = g_strdup (strv[len - 3]); - } - - /* You can have multiple accounts with the same username so we have to - * look at all the accounts to find the right one going on the username and - * protocol. */ - for (l = accounts; l != NULL; l = l->next) - { - TpAccount *acc = (TpAccount *) l->data; - const GHashTable *params; - - if (tp_strdiff (tp_account_get_protocol_name (acc), protocol)) - continue; - - params = tp_account_get_parameters (acc); - - if (!tp_strdiff (username, tp_asv_get_string (params, "account"))) - { - if (is_irc && tp_strdiff (server, tp_asv_get_string (params, "server"))) - continue; - - account = g_object_ref (acc); - break; - } - } - - g_free (username); - g_free (server); - g_list_free_full (accounts, g_object_unref); - g_strfreev (strv); - - return account; -} - - -static TplLogSearchHit * -log_store_pidgin_search_hit_new (TplLogStore *self, - const gchar *filename) -{ - TplLogSearchHit *hit; - gchar **strv; - guint len; - TplEntityType type; - gchar *id; - - if (!g_str_has_suffix (filename, TXT_LOG_FILENAME_SUFFIX) - && !g_str_has_suffix (filename, HTML_LOG_FILENAME_SUFFIX)) - return NULL; - - strv = g_strsplit (filename, G_DIR_SEPARATOR_S, -1); - len = g_strv_length (strv); - - hit = g_slice_new0 (TplLogSearchHit); - hit->date = log_store_pidgin_get_time (strv[len-1]); - - type = g_str_has_suffix (strv[len-2], ".chat") - ? TPL_ENTITY_ROOM : TPL_ENTITY_CONTACT; - - /* Remove ".chat" suffix. */ - if (type == TPL_ENTITY_ROOM) - id = g_strndup (strv[len-2], (strlen (strv[len-2]) - 5)); - else - id = g_strdup (strv[len-2]); - - hit->target = tpl_entity_new (id, type, NULL, NULL); - - g_free (id); - - hit->account = log_store_pidgin_dup_account (TPL_LOG_STORE_PIDGIN (self), - filename); - - g_strfreev (strv); - - return hit; -} - - -static GList * -log_store_pidgin_get_events_for_files (TplLogStore *self, - TpAccount *account, - const GList *filenames) -{ - GList *events = NULL; - const GList *l; - - g_return_val_if_fail (TPL_IS_LOG_STORE_PIDGIN (self), NULL); - g_return_val_if_fail (filenames != NULL, NULL); - - for (l = filenames; l != NULL; l = l->next) - { - const gchar *filename; - - gchar *target_id = NULL; - gchar *date = NULL; - gchar *own_user = NULL; - gchar *protocol = NULL; - gboolean is_room; - gchar *dirname; - gchar *date_str; - gchar *basename; - gchar **split; - - gchar *buffer; - GError *error = NULL; - gchar **lines; - int i; - - GRegex *regex; - GMatchInfo *match_info; - gchar **hits = NULL; - gboolean is_html = FALSE; - - filename = (gchar *) l->data; - - DEBUG ("Attempting to parse filename:'%s'...", filename); - - if (!g_file_test (filename, G_FILE_TEST_EXISTS)) - { - DEBUG ("Filename:'%s' does not exist", filename); - continue; - } - - if (!g_file_get_contents (filename, &buffer, NULL, &error)) - { - DEBUG ("Failed to read file: %s", - error ? error->message : "no event"); - g_error_free (error); - continue; - } - - dirname = g_path_get_dirname (filename); - is_room = g_str_has_suffix (dirname, ".chat"); - g_free (dirname); - - basename = g_path_get_basename (filename); - split = g_strsplit_set (basename, "-.", 4); - - if (g_strv_length (split) < 3) - { - DEBUG ("Unexpected filename: %s (expected YYYY-MM-DD ...)", - basename); - g_strfreev (split); - g_free (basename); - g_free (buffer); - continue; - } - - date_str = g_strdup_printf ("%s%s%sT", split[0], split[1], split[2]); - g_free (basename); - g_strfreev (split); - - lines = g_strsplit (buffer, "\n", -1); - - g_free (buffer); - - is_html = g_str_has_suffix (filename, HTML_LOG_FILENAME_SUFFIX); - - if (is_html) - { - regex = g_regex_new ("<h3>Conversation with (.+) at (.+) on (.+) \\((.+)\\)</h3>", - 0, 0, NULL); - } - else - { - regex = g_regex_new ("Conversation with (.+) at (.+) on (.+) \\((.+)\\)", - 0, 0, NULL); - } - - if (lines[0] != NULL) - { - g_regex_match (regex, lines[0], 0, &match_info); - hits = g_match_info_fetch_all (match_info); - - g_match_info_free (match_info); - } - - g_regex_unref (regex); - - if (hits == NULL) - { - g_strfreev (lines); - continue; - } - - if (g_strv_length (hits) != 5) - { - g_strfreev (lines); - g_strfreev (hits); - continue; - } - - target_id = g_strdup (hits[1]); - own_user = g_strdup (hits[3]); - protocol = g_strdup (hits[4]); - - g_strfreev (hits); - - for (i = 1; lines[i] != NULL; i++) - { - TplTextEvent *event; - TplEntity *sender; - TplEntity *receiver = NULL; - gchar *sender_name = NULL; - gchar *time_str = NULL; - gchar *timestamp_str = NULL; - gchar *body = NULL; - int j = i + 1; - gboolean is_user = FALSE; - gint64 timestamp; - - if (is_html) - { - if (!tp_strdiff (lines[i], "</body></html>")) - break; - - regex = g_regex_new ( - "<font size=\"2\">\\((.+)\\)</font> <b>(.+):</b></font> (<body>|)(.*)(</body>|)<br/>$", - G_REGEX_UNGREEDY, 0, NULL); - } - else - { - regex = g_regex_new ("^\\((.+)\\) (.+): (.+)", 0, 0, NULL); - } - - g_regex_match (regex, lines[i], 0, &match_info); - hits = g_match_info_fetch_all (match_info); - - g_match_info_free (match_info); - g_regex_unref (regex); - - if (hits == NULL - || (is_html && g_strv_length (hits) < 5) - || (g_strv_length (hits) < 4)) - { - g_strfreev (hits); - continue; - } - - time_str = g_strdup (hits[1]); - sender_name = g_strdup (hits[2]); - - if (is_html) - { - GRegex *r; - - r = g_regex_new ("<br/>", 0, 0, NULL); - body = g_regex_replace (r, hits[4], -1, 0, "\n", 0, NULL); - g_regex_unref (r); - - is_user = strstr (lines[i], "16569E") != NULL; - } - else - { - body = g_strdup (hits[3]); - } - - g_strfreev (hits); - - /* time_str -> "%H:%M:%S" */ - timestamp_str = g_strdup_printf ("%s%s", date_str, time_str); - timestamp = _tpl_time_parse (timestamp_str); - g_free (timestamp_str); - - /* Unfortunately, there's no way to tell which user is you in plain - * text logs as they appear like this: - * - * Conversation with contacts@jid at date on my@jid (protocol) - * (10:17:18) Some Person: hello - * (10:17:19) Another person: hey - * - * We can hack around it in the HTML logs because we know what - * colour the local user will be displayed as. sigh. - */ - - /* FIXME: in text format (is_html==FALSE) there is no actual way to - * understand what type the entity is, it might lead to inaccuracy, - * as is_user will be always FALSE */ - sender = tpl_entity_new ( - is_user ? own_user : sender_name, - is_user ? TPL_ENTITY_SELF : TPL_ENTITY_CONTACT, - sender_name, NULL); - - /* FIXME: in text format it's not possible to guess who is the - * receiver (unless we are in a room). In this case the receiver will - * be left to NULL in the generated event. */ - if (is_html || is_room) - { - const gchar *receiver_id; - TplEntityType receiver_type; - - /* In chatrooms, the receiver is always the room */ - if (is_room) - { - receiver_id = target_id; - receiver_type = TPL_ENTITY_ROOM; - } - else if (is_user) - { - receiver_id = target_id; - receiver_type = TPL_ENTITY_CONTACT; - } - else - { - receiver_id = own_user; - receiver_type = TPL_ENTITY_SELF; - } - - receiver = tpl_entity_new (receiver_id, receiver_type, - NULL, NULL); - } - - event = g_object_new (TPL_TYPE_TEXT_EVENT, - /* TplEvent */ - "account", account, - /* MISSING: "channel-path", channel_path, */ - "receiver", receiver, - "sender", sender, - "timestamp", timestamp, - /* TplTextEvent */ - "message-type", TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL, - "message", body, - NULL); - - /* prepend and then reverse is better than append */ - events = g_list_prepend (events, event); - - g_free (sender_name); - g_free (time_str); - g_object_unref (sender); - - i = j - 1; - } - events = g_list_reverse (events); - - g_free (target_id); - g_free (own_user); - g_free (date); - g_free (protocol); - - g_strfreev (lines); - } - - DEBUG ("Parsed %d events", g_list_length (events)); - - return events; -} - - -/* internal: return a GList of file names (char *) which need to be freed with - * g_free */ -static GList * -log_store_pidgin_get_all_files (TplLogStore *self, - const gchar *dir) -{ - GDir *gdir; - GList *files = NULL; - const gchar *name; - const gchar *basedir; - - - basedir = (dir != NULL) ? - dir : log_store_pidgin_get_basedir (TPL_LOG_STORE_PIDGIN (self)); - - gdir = g_dir_open (basedir, 0, NULL); - if (gdir == NULL) - return NULL; - - while ((name = g_dir_read_name (gdir)) != NULL) - { - gchar *filename; - - filename = g_build_filename (basedir, name, NULL); - if (g_str_has_suffix (filename, TXT_LOG_FILENAME_SUFFIX) - || g_str_has_suffix (filename, HTML_LOG_FILENAME_SUFFIX)) - { - files = g_list_prepend (files, filename); - continue; - } - - if (g_file_test (filename, G_FILE_TEST_IS_DIR)) - { - files = g_list_concat (files, - log_store_pidgin_get_all_files (self, filename)); - } - - g_free (filename); - } - - g_dir_close (gdir); - - return files; -} - - -static GList * -_log_store_pidgin_search_in_files (TplLogStorePidgin *self, - const gchar *text, - GList *files) -{ - GList *l; - GList *hits = NULL; - gchar *text_casefold; - - text_casefold = g_utf8_casefold (text, -1); - - for (l = files; l != NULL; l = l->next) - { - gchar *filename; - GMappedFile *file; - gsize length; - gchar *contents; - gchar *contents_casefold = NULL; - - filename = l->data; - - file = g_mapped_file_new (filename, FALSE, NULL); - if (file == NULL) - continue; - - length = g_mapped_file_get_length (file); - contents = g_mapped_file_get_contents (file); - - if (contents != NULL) - contents_casefold = g_utf8_casefold (contents, length); - - g_mapped_file_unref (file); - - if (contents_casefold == NULL) - continue; - - if (strstr (contents_casefold, text_casefold)) - { - TplLogSearchHit *hit; - - hit = log_store_pidgin_search_hit_new (TPL_LOG_STORE (self), - filename); - - if (hit != NULL) - { - hits = g_list_prepend (hits, hit); - DEBUG ("Found text:'%s' in file:'%s' on date:'%04u-%02u-%02u'", - text_casefold, filename, g_date_get_year (hit->date), - g_date_get_month (hit->date), g_date_get_day (hit->date)); - } - } - - g_free (contents_casefold); - } - - g_free (text_casefold); - - return hits; -} - - -static GList * -log_store_pidgin_search_new (TplLogStore *self, - const gchar *text, - gint type_mask) -{ - GList *files; - GList *retval; - - g_return_val_if_fail (TPL_IS_LOG_STORE_PIDGIN (self), NULL); - g_return_val_if_fail (!tp_str_empty (text), NULL); - - if (!(type_mask & TPL_EVENT_MASK_TEXT)) - return NULL; - - files = log_store_pidgin_get_all_files (self, NULL); - DEBUG ("Found %d log files in total", g_list_length (files)); - - retval = _log_store_pidgin_search_in_files (TPL_LOG_STORE_PIDGIN (self), - text, files); - - g_list_foreach (files, (GFunc) g_free, NULL); - g_list_free (files); - - return retval; -} - - -static GList * -log_store_pidgin_get_entities_for_dir (TplLogStore *self, - const gchar *dir) -{ - GDir *gdir; - GList *entities = NULL; - const gchar *name; - - gdir = g_dir_open (dir, 0, NULL); - if (gdir == NULL) - return NULL; - - while ((name = g_dir_read_name (gdir)) != NULL) - { - TplEntity *entity; - - /* pidgin internal ".system" directory is not a target ID */ - if (g_strcmp0 (name, ".system") == 0) - continue; - - /* Check if it's a chatroom */ - if (g_str_has_suffix (name, ".chat")) - { - gchar *id = g_strndup (name, strlen (name) - 5); - entity = tpl_entity_new_from_room_id (id); - g_free (id); - } - else - entity = tpl_entity_new (name, TPL_ENTITY_CONTACT, NULL, NULL); - - entities = g_list_prepend (entities, entity); - } - - g_dir_close (gdir); - - return entities; -} - - -static GList * -log_store_pidgin_get_events_for_date (TplLogStore *self, - TpAccount *account, - TplEntity *target, - gint type_mask, - const GDate *date) -{ - GList *events, *filenames; - - g_return_val_if_fail (TPL_IS_LOG_STORE_PIDGIN (self), NULL); - g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL); - g_return_val_if_fail (TPL_IS_ENTITY (target), NULL); - - if (!(type_mask & TPL_EVENT_MASK_TEXT)) - return NULL; - - /* pidgin stores multiple files related to the same date */ - filenames = log_store_pidgin_get_filenames_for_date (self, account, - target, date); - - if (filenames == NULL) - return NULL; - - events = log_store_pidgin_get_events_for_files (self, account, filenames); - - g_list_foreach (filenames, (GFunc) g_free, NULL); - g_list_free (filenames); - - return events; -} - - -static GList * -log_store_pidgin_get_entities (TplLogStore *self, - TpAccount *account) -{ - gchar *dir; - GList *hits; - - dir = log_store_pidgin_get_dir (self, account, NULL); - - if (dir != NULL) - hits = log_store_pidgin_get_entities_for_dir (self, dir); - else - hits = NULL; - - g_free (dir); - - return hits; -} - - -static GList * -log_store_pidgin_get_filtered_events (TplLogStore *self, - TpAccount *account, - TplEntity *target, - gint type_mask, - guint num_events, - TplLogEventFilter filter, - gpointer user_data) -{ - GList *dates, *l, *events = NULL; - guint i = 0; - - dates = log_store_pidgin_get_dates (self, account, target, type_mask); - - for (l = g_list_last (dates); l != NULL && i < num_events; l = l->prev) - { - GList *new_events, *n, *next; - - /* FIXME: We should really restrict the event parsing to get only - * the newest num_events. */ - new_events = log_store_pidgin_get_events_for_date (self, account, - target, type_mask, l->data); - - n = new_events; - while (n != NULL) - { - next = n->next; - if (filter != NULL && !filter (n->data, user_data)) - { - g_object_unref (n->data); - new_events = g_list_delete_link (new_events, n); - } - else - { - i++; - } - n = next; - } - events = g_list_concat (events, new_events); - } - - g_list_foreach (dates, (GFunc) g_free, NULL); - g_list_free (dates); - - return events; -} - - -static TplLogIter * -log_store_pidgin_create_iter (TplLogStore *store, - TpAccount *account, - TplEntity *target, - gint type_mask) -{ - g_return_val_if_fail (TPL_IS_LOG_STORE_PIDGIN (store), NULL); - g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL); - g_return_val_if_fail (TPL_IS_ENTITY (target), NULL); - - return tpl_log_iter_pidgin_new (store, account, target, type_mask); -} - - -static void -log_store_iface_init (gpointer g_iface, - gpointer iface_data) -{ - TplLogStoreInterface *iface = (TplLogStoreInterface *) g_iface; - - iface->get_name = log_store_pidgin_get_name; - iface->exists = log_store_pidgin_exists; - iface->add_event = NULL; - iface->get_dates = log_store_pidgin_get_dates; - iface->get_events_for_date = log_store_pidgin_get_events_for_date; - iface->get_entities = log_store_pidgin_get_entities; - iface->search_new = log_store_pidgin_search_new; - iface->get_filtered_events = log_store_pidgin_get_filtered_events; - iface->create_iter = log_store_pidgin_create_iter; -} diff --git a/telepathy-logger/log-store-sqlite-internal.h b/telepathy-logger/log-store-sqlite-internal.h deleted file mode 100644 index 026a123..0000000 --- a/telepathy-logger/log-store-sqlite-internal.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) 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: Danielle Madeley <danielle.madeley@collabora.co.uk> - */ - -#ifndef __TPL_LOG_STORE_SQLITE_H__ -#define __TPL_LOG_STORE_SQLITE_H__ - -#include <glib-object.h> - -#include <telepathy-glib/telepathy-glib.h> - -#include <telepathy-logger/log-store-internal.h> - -G_BEGIN_DECLS - -#define TPL_TYPE_LOG_STORE_SQLITE \ - (_tpl_log_store_sqlite_get_type ()) -#define TPL_LOG_STORE_SQLITE(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_LOG_STORE_SQLITE, \ - TplLogStoreSqlite)) -#define TPL_LOG_STORE_SQLITE_CLASS(obj) \ - (G_TYPE_CHECK_CLASS_CAST ((obj), TPL_TYPE_LOG_STORE_SQLITE, \ - TplLogStoreSqliteClass)) -#define TPL_IS_LOG_STORE_SQLITE(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_LOG_STORE_SQLITE)) -#define TPL_IS_LOG_STORE_SQLITE_CLASS(obj) \ - (G_TYPE_CHECK_CLASS_TYPE ((obj), TPL_TYPE_LOG_STORE_SQLITE)) -#define TPL_LOG_STORE_SQLITE_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_LOG_STORE_SQLITE, \ - TplLogStoreSqliteClass)) - -#define TPL_LOG_STORE_SQLITE_CLEANUP_DELTA_LIMIT (60*60) -#define TPL_LOG_STORE_SQLITE_TIMESTAMP_FORMAT "%Y-%m-%d %H:%M:%S" -#define TPL_LOG_STORE_SQLITE_ERROR g_quark_from_static_string ( \ - "tpl-log-store-index-error-quark") -typedef enum -{ - /* generic error, avoids clashing with TPL_LOG_STORE_ERROR using its last - * value */ - TPL_LOG_STORE_SQLITE_ERROR_FAILED = TPL_LOG_STORE_ERROR_LAST, - /* generic _tpl_log_store_sqlite_get_pending_messages() error, to be used when - * any other code cannot be use, including TPL_LOG_STORE_ERROR ones */ - TPL_LOG_STORE_SQLITE_ERROR_GET_PENDING_MESSAGES, - TPL_LOG_STORE_SQLITE_ERROR_REMOVE_PENDING_MESSAGES, - TPL_LOG_STORE_SQLITE_ERROR_ADD_PENDING_MESSAGE -} TplLogStoreSqliteError; - -typedef struct _TplLogStoreSqlite TplLogStoreSqlite; -typedef struct _TplLogStoreSqlitePrivate TplLogStoreSqlitePrivate; -typedef struct _TplLogStoreSqliteClass TplLogStoreSqliteClass; -typedef struct _TplPendingMessage TplPendingMessage; - -struct _TplLogStoreSqlite -{ - GObject parent; - TplLogStoreSqlitePrivate *priv; -}; - -struct _TplLogStoreSqliteClass -{ - GObjectClass parent_class; -}; - -struct _TplPendingMessage -{ - guint id; - gint64 timestamp; -}; - -GType _tpl_log_store_sqlite_get_type (void); -TplLogStore * _tpl_log_store_sqlite_dup (void); - -GList * _tpl_log_store_sqlite_get_pending_messages (TplLogStore *self, - TpChannel *channel, GError **error); -gboolean _tpl_log_store_sqlite_remove_pending_messages (TplLogStore *self, - TpChannel *channel, GList *log_ids, GError **error); -gboolean _tpl_log_store_sqlite_add_pending_message (TplLogStore *self, - TpChannel *channel, guint id, gint64 timestamp, GError **error); - -gint64 _tpl_log_store_sqlite_get_most_recent (TplLogStoreSqlite *self, - TpAccount *account, const char *identifier); -double _tpl_log_store_sqlite_get_frequency (TplLogStoreSqlite *self, - TpAccount *account, const char *identifier); - -G_END_DECLS - -#endif diff --git a/telepathy-logger/log-store-sqlite.c b/telepathy-logger/log-store-sqlite.c deleted file mode 100644 index bd86340..0000000 --- a/telepathy-logger/log-store-sqlite.c +++ /dev/null @@ -1,992 +0,0 @@ -/* - * Copyright (C) 2010-2011 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: Danielle Madeley <danielle.madeley@collabora.co.uk> - * Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - * Nicolas Dufresne <nicolas.dufresne@collabora.co.uk> - */ - -#include <config.h> -#include "log-store-sqlite-internal.h" - -#include <string.h> - -#include <telepathy-glib/telepathy-glib.h> -#include <telepathy-glib/telepathy-glib-dbus.h> -#include <sqlite3.h> - -#include "event-internal.h" -#include "text-event.h" -#include "text-event-internal.h" -#include "entity-internal.h" -#include "log-manager-internal.h" - -#define DEBUG_FLAG TPL_DEBUG_LOG_STORE -#include "debug-internal.h" -#include "util-internal.h" - -#define TPL_LOG_STORE_SQLITE_NAME "Sqlite" - -static void log_store_iface_init (TplLogStoreInterface *iface); - -G_DEFINE_TYPE_WITH_CODE (TplLogStoreSqlite, _tpl_log_store_sqlite, - G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (TPL_TYPE_LOG_STORE, log_store_iface_init)); - -enum /* properties */ -{ - PROP_0, - PROP_READABLE, -}; - -struct _TplLogStoreSqlitePrivate -{ - sqlite3 *db; -}; - -static GObject *singleton = NULL; - - -static GObject * -tpl_log_store_sqlite_constructor (GType type, - guint n_props, - GObjectConstructParam *props) -{ - if (singleton != NULL) - g_object_ref (singleton); - else - { - singleton = - G_OBJECT_CLASS (_tpl_log_store_sqlite_parent_class)->constructor ( - type, n_props, props); - - if (singleton == NULL) - return NULL; - - g_object_add_weak_pointer (singleton, (gpointer *) &singleton); - } - - return singleton; -} - - -static char * -get_db_filename (void) -{ - return g_build_filename (g_get_user_cache_dir (), - "telepathy", - "logger", - "sqlite-data", - NULL); -} - - -static void -tpl_log_store_sqlite_get_property (GObject *self, - guint id, - GValue *value, - GParamSpec *pspec) -{ - switch (id) - { - case PROP_READABLE: - /* this store should never be queried by the LogManager */ - g_value_set_boolean (value, FALSE); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (self, id, pspec); - break; - } -} - - -static void -purge_pending_messages (TplLogStoreSqlitePrivate *priv, - GTimeSpan delta, - GError **error) -{ - sqlite3_stmt *sql = NULL; - GDateTime *now; - GDateTime *timestamp; - gchar *date; - int e; - - g_return_if_fail (error == NULL || *error == NULL); - - now = g_date_time_new_now_utc (); - timestamp = g_date_time_add (now, -(delta * G_TIME_SPAN_SECOND)); - - date = g_date_time_format (timestamp, - TPL_LOG_STORE_SQLITE_TIMESTAMP_FORMAT); - - g_date_time_unref (now); - - DEBUG ("Purging entries older than %s (%u seconds ago)", date, (guint) delta); - - e = sqlite3_prepare_v2 (priv->db, - "DELETE FROM pending_messages WHERE timestamp<?", - -1, &sql, NULL); - - if (e != SQLITE_OK) - { - g_set_error (error, TPL_LOG_STORE_ERROR, - TPL_LOG_STORE_ERROR_ADD_EVENT, - "SQL Error preparing statement in %s: %s", G_STRFUNC, - sqlite3_errmsg (priv->db)); - - goto out; - } - - sqlite3_bind_int64 (sql, 1, g_date_time_to_unix (timestamp)); - - e = sqlite3_step (sql); - if (e != SQLITE_DONE) - { - g_set_error (error, TPL_LOG_STORE_ERROR, - TPL_LOG_STORE_ERROR_ADD_EVENT, - "SQL Error in %s: %s", G_STRFUNC, sqlite3_errmsg (priv->db)); - } - -out: - g_date_time_unref (timestamp); - - if (sql != NULL) - sqlite3_finalize (sql); - - g_free (date); -} - - -static void -_tpl_log_store_sqlite_init (TplLogStoreSqlite *self) -{ - TplLogStoreSqlitePrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - TPL_TYPE_LOG_STORE_SQLITE, TplLogStoreSqlitePrivate); - char *filename = get_db_filename (); - int e; - char *errmsg = NULL; - GError *error = NULL; - - self->priv = priv; - - DEBUG ("cache file is '%s'", filename); - - /* counter & cache tables - common part */ - /* check to see if the sqlite db exists */ - if (!g_file_test (filename, G_FILE_TEST_EXISTS)) - { - char *dirname = g_path_get_dirname (filename); - - DEBUG ("Creating cache"); - - g_mkdir_with_parents (dirname, 0700); - g_free (dirname); - } - - e = sqlite3_open_v2 (filename, &priv->db, - SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, - NULL); - if (e != SQLITE_OK) - { - CRITICAL ("Failed to open Sqlite3 DB: %s\n", - sqlite3_errmsg (priv->db)); - goto out; - } - /* end of common part */ - - /* start of cache table init */ - - /* drop deprecated table (since 0.2.6) */ - sqlite3_exec (priv->db, "DROP TABLE IF EXISTS message_cache", - NULL, NULL, &errmsg); - if (errmsg != NULL) - { - CRITICAL ("Failed to drop deprecated message_cache table: %s\n", errmsg); - sqlite3_free (errmsg); - goto out; - } - - sqlite3_exec (priv->db, "CREATE TABLE IF NOT EXISTS pending_messages ( " - "channel TEXT NOT NULL, " - "id INTEGER, " - "timestamp INTEGER)", - NULL, NULL, &errmsg); - if (errmsg != NULL) - { - CRITICAL ("Failed to create table pending_messages: %s\n", errmsg); - sqlite3_free (errmsg); - goto out; - } - - /* purge old entries */ - purge_pending_messages (priv, - TPL_LOG_STORE_SQLITE_CLEANUP_DELTA_LIMIT, &error); - if (error != NULL) - { - CRITICAL ("Failed to purge pending messages: %s", error->message); - g_error_free (error); - goto out; - } - - /* end of cache table init */ - - /* start of counter table init */ - sqlite3_exec (priv->db, - "CREATE TABLE IF NOT EXISTS messagecounts (" - "account TEXT, " - "identifier TEXT, " - "chatroom BOOLEAN, " - "date DATE, " - "messages INTEGER)", - NULL, - NULL, - &errmsg); - if (errmsg != NULL) - { - CRITICAL ("Failed to create table messagecounts: %s\n", errmsg); - sqlite3_free (errmsg); - goto out; - } - /* end of counter table init */ - -out: - g_free (filename); -} - - -static void -tpl_log_store_sqlite_dispose (GObject *self) -{ - TplLogStoreSqlitePrivate *priv = TPL_LOG_STORE_SQLITE (self)->priv; - - if (priv->db != NULL) - { - sqlite3_close (priv->db); - priv->db = NULL; - } - - G_OBJECT_CLASS (_tpl_log_store_sqlite_parent_class)->dispose (self); -} - - -static void -_tpl_log_store_sqlite_class_init (TplLogStoreSqliteClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - gobject_class->constructor = tpl_log_store_sqlite_constructor; - gobject_class->get_property = tpl_log_store_sqlite_get_property; - gobject_class->dispose = tpl_log_store_sqlite_dispose; - - g_object_class_override_property (gobject_class, PROP_READABLE, "readable"); - - g_type_class_add_private (gobject_class, sizeof (TplLogStoreSqlitePrivate)); -} - - -static const char * -get_account_name (TpAccount *account) -{ - return tp_proxy_get_object_path (account) + - strlen (TP_ACCOUNT_OBJECT_PATH_BASE); -} - - -static const char * -get_account_name_from_event (TplEvent *event) -{ - return tpl_event_get_account_path (event) + - strlen (TP_ACCOUNT_OBJECT_PATH_BASE); -} - - -static const char * -get_channel_name (TpChannel *chan) -{ - return tp_proxy_get_object_path (chan) + - strlen (TP_CONN_OBJECT_PATH_BASE); -} - - -static char * -get_date (TplEvent *event) -{ - GDateTime *ts; - gchar *date; - - ts = g_date_time_new_from_unix_utc (tpl_event_get_timestamp (event)); - g_return_val_if_fail (ts != NULL, NULL); - date = g_date_time_format (ts, "%Y-%m-%d"); - - g_date_time_unref (ts); - - return date; -} - - -static char * -get_datetime (gint64 timestamp) -{ - GDateTime *ts; - gchar *date; - - ts = g_date_time_new_from_unix_utc (timestamp); - date = g_date_time_format (ts, TPL_LOG_STORE_SQLITE_TIMESTAMP_FORMAT); - - g_date_time_unref (ts); - - return date; -} - - -static const char * -tpl_log_store_sqlite_get_name (TplLogStore *self) -{ - return TPL_LOG_STORE_SQLITE_NAME; -} - - -static gboolean -tpl_log_store_sqlite_add_message_counter (TplLogStore *self, - TplEvent *message, - GError **error) -{ - TplLogStoreSqlitePrivate *priv = TPL_LOG_STORE_SQLITE (self)->priv; - const char *account, *identifier; - gboolean chatroom; - char *date = NULL; - int count = 0; - sqlite3_stmt *sql = NULL; - gboolean retval = FALSE; - gboolean insert = FALSE; - int e; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (TPL_IS_TEXT_EVENT (message) == FALSE) - { - DEBUG ("ignoring non-text event not intersting for message-counter"); - retval = TRUE; - goto out; - } - - DEBUG ("message received"); - - account = get_account_name_from_event (message); - identifier = _tpl_event_get_target_id (message); - chatroom = _tpl_event_target_is_room (message); - date = get_date (message); - - DEBUG ("account = %s", account); - DEBUG ("identifier = %s", identifier); - DEBUG ("chatroom = %i", chatroom); - DEBUG ("date = %s", date); - - /* get the existing row */ - e = sqlite3_prepare_v2 (priv->db, - "SELECT messages FROM messagecounts WHERE " - "account=? AND " - "identifier=? AND " - "chatroom=? AND " - "date=date(?)", - -1, &sql, NULL); - if (e != SQLITE_OK) - { - g_set_error (error, TPL_LOG_STORE_ERROR, - TPL_LOG_STORE_ERROR_ADD_EVENT, - "SQL Error checking current counter in %s: %s", G_STRFUNC, - sqlite3_errmsg (priv->db)); - - goto out; - } - - sqlite3_bind_text (sql, 1, account, -1, SQLITE_TRANSIENT); - sqlite3_bind_text (sql, 2, identifier, -1, SQLITE_TRANSIENT); - sqlite3_bind_int (sql, 3, chatroom); - sqlite3_bind_text (sql, 4, date, -1, SQLITE_TRANSIENT); - - e = sqlite3_step (sql); - if (e == SQLITE_DONE) - { - DEBUG ("no rows, insert"); - insert = TRUE; - } - else if (e == SQLITE_ROW) - { - count = sqlite3_column_int (sql, 0); - DEBUG ("got row, count = %i", count); - } - else - { - g_set_error (error, TPL_LOG_STORE_ERROR, - TPL_LOG_STORE_ERROR_ADD_EVENT, - "SQL Error binding counter checking query in %s: %s", G_STRFUNC, - sqlite3_errmsg (priv->db)); - - goto out; - } - - sqlite3_finalize (sql); - sql = NULL; - - /* increment the message count */ - count++; - - DEBUG ("new count = %i, insert = %i", count, insert); - - /* update table with new message count */ - if (insert) - e = sqlite3_prepare_v2 (priv->db, - "INSERT INTO messagecounts " - "(messages, account, identifier, chatroom, date) " - "VALUES (?, ?, ?, ?, date(?))", - -1, &sql, NULL); - else - e = sqlite3_prepare_v2 (priv->db, - "UPDATE messagecounts SET messages=? WHERE " - "account=? AND " - "identifier=? AND " - "chatroom=? AND " - "date=date(?)", - -1, &sql, NULL); - - if (e != SQLITE_OK) - { - g_set_error (error, TPL_LOG_STORE_ERROR, - TPL_LOG_STORE_ERROR_ADD_EVENT, - "SQL Error preparing query in %s: %s", G_STRFUNC, - sqlite3_errmsg (priv->db)); - - goto out; - } - - sqlite3_bind_int (sql, 1, count); - sqlite3_bind_text (sql, 2, account, -1, SQLITE_TRANSIENT); - sqlite3_bind_text (sql, 3, identifier, -1, SQLITE_TRANSIENT); - sqlite3_bind_int (sql, 4, chatroom); - sqlite3_bind_text (sql, 5, date, -1, SQLITE_TRANSIENT); - - e = sqlite3_step (sql); - if (e != SQLITE_DONE) - { - g_set_error (error, TPL_LOG_STORE_ERROR, - TPL_LOG_STORE_ERROR_ADD_EVENT, - "SQL Error %s counter in %s: %s", - (insert ? "inserting new" : "updating"), - G_STRFUNC, sqlite3_errmsg (priv->db)); - - goto out; - } - - retval = TRUE; - -out: - g_free (date); - - if (sql != NULL) - sqlite3_finalize (sql); - - /* check that we set an error if appropriate */ - g_assert ((retval == TRUE && *error == NULL) || - (retval == FALSE && *error != NULL)); - - return retval; -} - - -/** - * tpl_log_store_sqlite_add_event: - * @self: TplLogstoreSqlite instance - * @message: a TplEvent instance - * @error: memory pointer use in case of error - * - * Text messages will be accounted for statistics purpose. - * - * Returns: %TRUE if @self was able to store, %FALSE with @error set if an error occurred. - */ -static gboolean -tpl_log_store_sqlite_add_event (TplLogStore *self, - TplEvent *message, - GError **error) -{ - gboolean retval = FALSE; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (!TPL_IS_LOG_STORE_SQLITE (self)) - { - g_set_error (error, TPL_LOG_STORE_ERROR, - TPL_LOG_STORE_ERROR_ADD_EVENT, - "TplLogStoreSqlite intance needed"); - goto out; - } - - if (!TPL_IS_EVENT (message)) - { - g_set_error (error, TPL_LOG_STORE_ERROR, - TPL_LOG_STORE_ERROR_ADD_EVENT, "TplEvent instance needed"); - goto out; - } - - retval = tpl_log_store_sqlite_add_message_counter (self, message, error); - -out: - /* check that we set an error if appropriate */ - g_assert ((retval == TRUE && *error == NULL) || - (retval == FALSE && *error != NULL)); - - DEBUG ("returning with %d", retval); - return retval; -} - - -static GList * -tpl_log_store_sqlite_get_entities (TplLogStore *self, - TpAccount *account) -{ - TplLogStoreSqlitePrivate *priv = TPL_LOG_STORE_SQLITE (self)->priv; - sqlite3_stmt *sql = NULL; - int e; - GList *list = NULL; - const char *account_name = get_account_name (account); - - DEBUG ("account = %s", account_name); - - /* list all the identifiers known to the database */ - e = sqlite3_prepare_v2 (priv->db, - "SELECT DISTINCT identifier, chatroom FROM messagecounts WHERE " - "account=?", - -1, &sql, NULL); - if (e != SQLITE_OK) - { - DEBUG ("Failed to prepare SQL: %s", - sqlite3_errmsg (priv->db)); - - goto out; - } - - sqlite3_bind_text (sql, 1, account_name, -1, SQLITE_TRANSIENT); - - while ((e = sqlite3_step (sql)) == SQLITE_ROW) - { - TplEntity *entity; - const char *identifier; - gboolean chatroom; - TplEntityType type; - - /* for some reason this returns unsigned char */ - identifier = (const char *) sqlite3_column_text (sql, 0); - chatroom = sqlite3_column_int (sql, 1); - type = chatroom ? TPL_ENTITY_ROOM : TPL_ENTITY_CONTACT; - - DEBUG ("identifier = %s, chatroom = %i", identifier, chatroom); - - entity = tpl_entity_new (identifier, type, NULL, NULL); - - list = g_list_prepend (list, entity); - } - if (e != SQLITE_DONE) - { - DEBUG ("Failed to execute SQL: %s", - sqlite3_errmsg (priv->db)); - goto out; - } - -out: - if (sql != NULL) - sqlite3_finalize (sql); - - return list; -} - -static void -log_store_iface_init (TplLogStoreInterface *iface) -{ - iface->get_name = tpl_log_store_sqlite_get_name; - iface->add_event = tpl_log_store_sqlite_add_event; - iface->get_entities = tpl_log_store_sqlite_get_entities; -} - -TplLogStore * -_tpl_log_store_sqlite_dup (void) -{ - return g_object_new (TPL_TYPE_LOG_STORE_SQLITE, NULL); -} - - -/** - * _tpl_log_store_sqlite_get_pending_messages: - * @self: a TplLogStoreSqlite instance - * @channel: a pointer to a TpChannel - * @error: set if an error occurs - * - * Returns the list of pending message IDs and timestamp for this @channel. - * Note that those message might not be valid anymore, check timestamp match - * before assuming a message is not new. - * - * Returns: (transfer full): a #GList of #TplLogStoreSqlitePendingMessage - */ -GList * -_tpl_log_store_sqlite_get_pending_messages (TplLogStore *self, - TpChannel *channel, - GError **error) -{ - TplLogStoreSqlitePrivate *priv = TPL_LOG_STORE_SQLITE (self)->priv; - sqlite3_stmt *sql = NULL; - GList *retval = NULL; - int e; - - g_return_val_if_fail (TPL_IS_LOG_STORE_SQLITE (self), NULL); - g_return_val_if_fail (TP_IS_CHANNEL (channel), NULL); - g_return_val_if_fail (error == NULL || *error == NULL, NULL); - - DEBUG ("Listing pending messages for channel %s", - get_channel_name (channel)); - - e = sqlite3_prepare_v2 (priv->db, "SELECT id,timestamp " - "FROM pending_messages " - "WHERE channel=? " - "ORDER BY id ASC", - -1, &sql, NULL); - - if (e != SQLITE_OK) - { - CRITICAL ("Error preparing SQL for pending messages list: %s", - sqlite3_errmsg (priv->db)); - g_set_error (error, TPL_LOG_STORE_SQLITE_ERROR, - TPL_LOG_STORE_SQLITE_ERROR_GET_PENDING_MESSAGES, - "SQL Error in %s: %s", G_STRFUNC, sqlite3_errmsg (priv->db)); - goto out; - } - - sqlite3_bind_text (sql, 1, get_channel_name (channel), -1, - SQLITE_TRANSIENT); - - while (SQLITE_ROW == (e = sqlite3_step (sql))) - { - /* create the pending messages list */ - TplPendingMessage *pending; - - pending = g_new (TplPendingMessage, 1); - - pending->id = (guint) sqlite3_column_int64 (sql, 0); - pending->timestamp = sqlite3_column_int64 (sql, 1); - - DEBUG (" - pending id=%u timestamp=%"G_GINT64_FORMAT, - pending->id, pending->timestamp); - - retval = g_list_prepend (retval, pending); - } - - if (e != SQLITE_DONE) - { - g_set_error (error, TPL_LOG_STORE_SQLITE_ERROR, - TPL_LOG_STORE_SQLITE_ERROR_GET_PENDING_MESSAGES, - "SQL Error in %s: %s", G_STRFUNC, sqlite3_errmsg (priv->db)); - - /* free partial result, which might be misleading */ - g_list_foreach (retval, (GFunc) g_free, NULL); - g_list_free (retval); - retval = NULL; - } - -out: - if (sql != NULL) - sqlite3_finalize (sql); - - /* check that we set an error if appropriate - * NOTE: retval == NULL && *error != - * NULL doesn't apply to this method, since NULL is also for an empty list */ - g_assert ((retval != NULL && *error == NULL) || retval == NULL); - - return retval; -} - - -/** - *_tpl_log_store_sqlite_remove_pending_messages: - * @self: a #TplLogStore - * @channel: a #TpAccount - * @pending_ids: a #GList of pending message IDs (guint) - * @error: a #GError to be set on error, or NULL - * - * Removes listed pending IDs for @channel. - * - * Returns: #TRUE on success, #FALSE on error with @error set - */ -gboolean -_tpl_log_store_sqlite_remove_pending_messages (TplLogStore *self, - TpChannel *channel, - GList *pending_ids, - GError **error) -{ - TplLogStoreSqlitePrivate *priv = TPL_LOG_STORE_SQLITE (self)->priv; - gboolean retval = TRUE; - GString *query = NULL; - GList *it; - sqlite3_stmt *sql = NULL; - - g_return_val_if_fail (TPL_IS_LOG_STORE_SQLITE (self), FALSE); - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - g_return_val_if_fail (pending_ids != NULL, FALSE); - - DEBUG ("Removing pending messages for channel %s", - get_channel_name (channel)); - - query = g_string_new ("DELETE FROM pending_messages WHERE "); - - g_string_append_printf (query, "channel='%s' AND id IN (%u", - get_channel_name (channel), GPOINTER_TO_UINT (pending_ids->data)); - - DEBUG (" - pending_id: %u", GPOINTER_TO_UINT (pending_ids->data)); - - for (it = g_list_next (pending_ids); it != NULL; it = g_list_next (it)) - { - DEBUG (" - pending_id: %u", GPOINTER_TO_UINT (it->data)); - g_string_append_printf (query, ",%u", GPOINTER_TO_UINT (it->data)); - } - - g_string_append (query, ")"); - - if (sqlite3_prepare_v2 (priv->db, query->str, -1, &sql, NULL) != SQLITE_OK) - { - g_set_error (error, TPL_LOG_STORE_SQLITE_ERROR, - TPL_LOG_STORE_SQLITE_ERROR_REMOVE_PENDING_MESSAGES, - "SQL Error in %s: %s", G_STRFUNC, sqlite3_errmsg (priv->db)); - retval = FALSE; - goto out; - } - - if (sqlite3_step (sql) != SQLITE_DONE) - { - g_set_error (error, TPL_LOG_STORE_SQLITE_ERROR, - TPL_LOG_STORE_SQLITE_ERROR_REMOVE_PENDING_MESSAGES, - "SQL Error in %s: %s", G_STRFUNC, sqlite3_errmsg (priv->db)); - retval = FALSE; - goto out; - } - -out: - if (query != NULL) - g_string_free (query, TRUE); - - if (sql != NULL) - sqlite3_finalize (sql); - - return retval; -} - -/** - *_tpl_log_store_sqlite_add_pending_message: - * @self: a #TplLogStore - * @channel: a #TpChannel - * @pending_msg_id: the pending message ID - * @timestamp: a unix utc timestamp - * @error: a #GError to be set on error, or NULL - * - * Add an entry to the list of pending message. - * - * Returns: #TRUE on success, #FALSE on error with @error set - */ -gboolean -_tpl_log_store_sqlite_add_pending_message (TplLogStore *self, - TpChannel *channel, - guint id, - gint64 timestamp, - GError **error) -{ - TplLogStoreSqlitePrivate *priv = TPL_LOG_STORE_SQLITE (self)->priv; - gboolean retval = FALSE; - const gchar *channel_path; - gchar *date = NULL; - sqlite3_stmt *sql = NULL; - int e; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - channel_path = get_channel_name (channel); - date = get_datetime (timestamp); - - DEBUG ("Caching pending message %u", id); - DEBUG (" - channel = %s", channel_path); - DEBUG (" - date = %s", date); - - if (TPL_STR_EMPTY (channel_path) - || timestamp <= 0) - { - g_set_error_literal (error, TPL_LOG_STORE_ERROR, - TPL_LOG_STORE_SQLITE_ERROR_ADD_PENDING_MESSAGE, - "passed LogStore has at least one of the needed properties unset: " - "channel-path, timestamp"); - goto out; - } - - e = sqlite3_prepare_v2 (priv->db, - "INSERT INTO pending_messages (channel, id, timestamp) VALUES (?, ?, ?)", - -1, &sql, NULL); - if (e != SQLITE_OK) - { - g_set_error (error, TPL_LOG_STORE_ERROR, - TPL_LOG_STORE_SQLITE_ERROR_ADD_PENDING_MESSAGE, - "SQL Error in %s: %s", G_STRFUNC, sqlite3_errmsg (priv->db)); - goto out; - } - - sqlite3_bind_text (sql, 1, channel_path, -1, SQLITE_TRANSIENT); - sqlite3_bind_int (sql, 2, (gint) id); - sqlite3_bind_int64 (sql, 3, timestamp); - - e = sqlite3_step (sql); - if (e != SQLITE_DONE) - { - g_set_error (error, TPL_LOG_STORE_ERROR, - TPL_LOG_STORE_SQLITE_ERROR_ADD_PENDING_MESSAGE, - "SQL Error bind in %s: %s", G_STRFUNC, sqlite3_errmsg (priv->db)); - goto out; - } - - retval = TRUE; - -out: - g_free (date); - - if (sql != NULL) - sqlite3_finalize (sql); - - /* check that we set an error if appropriate */ - g_assert ((retval == TRUE && *error == NULL) || - (retval == FALSE && *error != NULL)); - - return retval; -} - - -gint64 -_tpl_log_store_sqlite_get_most_recent (TplLogStoreSqlite *self, - TpAccount *account, - const char *identifier) -{ - TplLogStoreSqlitePrivate *priv = TPL_LOG_STORE_SQLITE (self)->priv; - sqlite3_stmt *sql = NULL; - int e; - gint64 date = -1;; - const char *account_name; - - account_name = get_account_name (account); - - /* this SQL gets this most recent date for a single identifier */ - e = sqlite3_prepare_v2 (priv->db, - "SELECT STRFTIME('%s', date) FROM messagecounts WHERE " - "account=? AND " - "identifier=? " - "ORDER BY date DESC LIMIT 1", - -1, &sql, NULL); - if (e != SQLITE_OK) - { - DEBUG ("Failed to prepare SQL: %s", - sqlite3_errmsg (priv->db)); - - goto out; - } - - sqlite3_bind_text (sql, 1, account_name, -1, SQLITE_TRANSIENT); - sqlite3_bind_text (sql, 2, identifier, -1, SQLITE_TRANSIENT); - - e = sqlite3_step (sql); - if (e == SQLITE_DONE) - { - DEBUG ("no rows (account identifer doesn't exist?)"); - } - else if (e == SQLITE_ROW) - { - date = sqlite3_column_int64 (sql, 0); - DEBUG ("got row, date = %" G_GINT64_FORMAT, date); - } - else - { - DEBUG ("Failed to execute SQL: %s", - sqlite3_errmsg (priv->db)); - - goto out; - } - -out: - - if (sql != NULL) - sqlite3_finalize (sql); - - return date; -} - - -double -_tpl_log_store_sqlite_get_frequency (TplLogStoreSqlite *self, - TpAccount *account, - const char *identifier) -{ - TplLogStoreSqlitePrivate *priv = TPL_LOG_STORE_SQLITE (self)->priv; - sqlite3_stmt *sql = NULL; - int e; - double freq = -1.; - const char *account_name; - - account_name = get_account_name (account); - - /* this SQL query builds the frequency for a single identifier */ - e = sqlite3_prepare_v2 (priv->db, - "SELECT SUM(messages / ROUND(JULIANDAY('now') - JULIANDAY(date) + 1)) " - "FROM messagecounts WHERE " - "account=? AND " - "identifier=?", - -1, &sql, NULL); - if (e != SQLITE_OK) - { - DEBUG ("Failed to prepare SQL: %s", - sqlite3_errmsg (priv->db)); - - goto out; - } - - sqlite3_bind_text (sql, 1, account_name, -1, SQLITE_TRANSIENT); - sqlite3_bind_text (sql, 2, identifier, -1, SQLITE_TRANSIENT); - - e = sqlite3_step (sql); - if (e == SQLITE_DONE) - { - DEBUG ("no rows (account identifer doesn't exist?)"); - } - else if (e == SQLITE_ROW) - { - freq = sqlite3_column_double (sql, 0); - DEBUG ("got row, freq = %g", freq); - } - else - { - DEBUG ("Failed to execute SQL: %s", - sqlite3_errmsg (priv->db)); - - goto out; - } - -out: - - if (sql != NULL) - sqlite3_finalize (sql); - - return freq; -} diff --git a/telepathy-logger/log-store-xml-internal.h b/telepathy-logger/log-store-xml-internal.h deleted file mode 100644 index 4351936..0000000 --- a/telepathy-logger/log-store-xml-internal.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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: Xavier Claessens <xclaesse@gmail.com> - * Jonny Lamb <jonny.lamb@collabora.co.uk> - */ - -#ifndef __TPL_LOG_STORE_XML_H__ -#define __TPL_LOG_STORE_XML_H__ - -#include <glib.h> -#include <glib-object.h> - -G_BEGIN_DECLS -#define TPL_TYPE_LOG_STORE_XML \ - (_tpl_log_store_xml_get_type ()) -#define TPL_LOG_STORE_XML(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_LOG_STORE_XML, \ - TplLogStoreXml)) -#define TPL_LOG_STORE_XML_CLASS(vtable) \ - (G_TYPE_CHECK_CLASS_CAST ((vtable), TPL_TYPE_LOG_STORE_XML, \ - TplLogStoreXmlClass)) -#define TPL_IS_LOG_STORE_XML(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_LOG_STORE_XML)) -#define TPL_IS_LOG_STORE_XML_CLASS(vtable) \ - (G_TYPE_CHECK_CLASS_TYPE ((vtable), TPL_TYPE_LOG_STORE_XML)) -#define TPL_LOG_STORE_XML_GET_CLASS(inst) \ - (G_TYPE_INSTANCE_GET_CLASS ((inst), TPL_TYPE_LOG_STORE_XML, \ - TplLogStoreXmlClass)) - -typedef struct _TplLogStoreXmlPriv TplLogStoreXmlPriv; - -typedef struct TplLogStoreXml -{ - GObject parent; - TplLogStoreXmlPriv *priv; -} TplLogStoreXml; - -typedef struct -{ - GObjectClass parent; -} TplLogStoreXmlClass; - -GType _tpl_log_store_xml_get_type (void); - -G_END_DECLS -#endif /* __TPL_LOG_STORE_XML_H__ */ diff --git a/telepathy-logger/log-store-xml.c b/telepathy-logger/log-store-xml.c deleted file mode 100644 index 9d56900..0000000 --- a/telepathy-logger/log-store-xml.c +++ /dev/null @@ -1,1939 +0,0 @@ -/* - * Copyright (C) 2003-2007 Imendio AB - * Copyright (C) 2007-2013 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: Xavier Claessens <xclaesse@gmail.com> - * Jonny Lamb <jonny.lamb@collabora.co.uk> - * Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - */ - -#include "config.h" -#include "log-store-xml-internal.h" - -#include <errno.h> -#include <string.h> -#include <stdio.h> -#include <stdlib.h> -#include <glib/gstdio.h> - -#include <glib-object.h> -#include <libxml/parser.h> -#include <libxml/tree.h> - -#include <telepathy-glib/telepathy-glib.h> -#include <telepathy-glib/telepathy-glib-dbus.h> - -#include "telepathy-logger/call-event.h" -#include "telepathy-logger/call-event-internal.h" -#include "telepathy-logger/entity-internal.h" -#include "telepathy-logger/event-internal.h" -#include "telepathy-logger/text-event.h" -#include "telepathy-logger/text-event-internal.h" -#include "telepathy-logger/log-iter-xml-internal.h" -#include "telepathy-logger/log-manager.h" -#include "telepathy-logger/log-store-internal.h" -#include "telepathy-logger/log-manager-internal.h" -#include "telepathy-logger/util-internal.h" - -#define DEBUG_FLAG TPL_DEBUG_LOG_STORE -#include "telepathy-logger/debug-internal.h" - -#define LOG_DIR_CREATE_MODE (S_IRUSR | S_IWUSR | S_IXUSR) -#define LOG_FILE_CREATE_MODE (S_IRUSR | S_IWUSR) -#define LOG_DIR_CHATROOMS "chatrooms" -#define LOG_FILENAME_SUFFIX ".log" -#define LOG_FILENAME_CALL_TAG ".call" -#define LOG_FILENAME_CALL_SUFFIX LOG_FILENAME_CALL_TAG LOG_FILENAME_SUFFIX -#define LOG_DATE_PATTERN "[0-9]{8,}" -#define LOG_FILENAME_PATTERN "^" LOG_DATE_PATTERN "\\" LOG_FILENAME_SUFFIX "$" -#define LOG_FILENAME_CALL_PATTERN "^" LOG_DATE_PATTERN "\\" LOG_FILENAME_CALL_TAG "\\" LOG_FILENAME_SUFFIX "$" - -#define LOG_TIME_FORMAT_FULL "%Y%m%dT%H:%M:%S" -#define LOG_TIME_FORMAT "%Y%m%d" -#define LOG_HEADER \ - "<?xml version='1.0' encoding='utf-8'?>\n" \ - "<?xml-stylesheet type=\"text/xsl\" href=\"log-store-xml.xsl\"?>\n" \ - "<log>\n" - -#define LOG_FOOTER \ - "</log>\n" - -#define ALL_SUPPORTED_TYPES (TPL_EVENT_MASK_TEXT | TPL_EVENT_MASK_CALL) -#define CONTAINS_ALL_SUPPORTED_TYPES(type_mask) \ - (((type_mask) & ALL_SUPPORTED_TYPES) == ALL_SUPPORTED_TYPES) - - -struct _TplLogStoreXmlPriv -{ - gchar *basedir; - gboolean test_mode; - TpAccountManager *account_manager; -}; - -enum { - PROP_0, - PROP_READABLE, - PROP_BASEDIR, - PROP_TESTMODE -}; - -static void log_store_iface_init (gpointer g_iface, gpointer iface_data); -static void tpl_log_store_xml_get_property (GObject *object, guint param_id, GValue *value, - GParamSpec *pspec); -static void tpl_log_store_xml_set_property (GObject *object, guint param_id, const GValue *value, - GParamSpec *pspec); -static const gchar *log_store_xml_get_basedir (TplLogStoreXml *self); -static void log_store_xml_set_basedir (TplLogStoreXml *self, - const gchar *data); - - -G_DEFINE_TYPE_WITH_CODE (TplLogStoreXml, _tpl_log_store_xml, - G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (TPL_TYPE_LOG_STORE, log_store_iface_init)) - - -static void -log_store_xml_dispose (GObject *object) -{ - TplLogStoreXml *self = TPL_LOG_STORE_XML (object); - TplLogStoreXmlPriv *priv = self->priv; - - /* FIXME See TP-bug #25569, when dispose a non prepared TP_AM, it - might segfault. - To avoid it, a *klduge*, a reference in the TplObserver to - the TplLogManager is kept, so that until TplObserver is instanced, - there will always be a TpLogManager reference and it won't be - diposed */ - if (priv->account_manager != NULL) - { - g_object_unref (priv->account_manager); - priv->account_manager = NULL; - } - - G_OBJECT_CLASS (_tpl_log_store_xml_parent_class)->dispose (object); -} - - -static void -log_store_xml_finalize (GObject *object) -{ - TplLogStoreXml *self = TPL_LOG_STORE_XML (object); - TplLogStoreXmlPriv *priv = self->priv; - - if (priv->basedir != NULL) - { - g_free (priv->basedir); - priv->basedir = NULL; - } -} - - -static void -tpl_log_store_xml_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - TplLogStoreXmlPriv *priv = TPL_LOG_STORE_XML (object)->priv; - - switch (param_id) - { - case PROP_READABLE: - g_value_set_boolean (value, TRUE); - break; - case PROP_BASEDIR: - g_value_set_string (value, priv->basedir); - break; - case PROP_TESTMODE: - g_value_set_boolean (value, priv->test_mode); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - }; -} - - -static void -tpl_log_store_xml_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - TplLogStoreXml *self = TPL_LOG_STORE_XML (object); - - switch (param_id) - { - case PROP_BASEDIR: - log_store_xml_set_basedir (self, g_value_get_string (value)); - break; - case PROP_TESTMODE: - self->priv->test_mode = g_value_get_boolean (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - }; -} - - -static void -_tpl_log_store_xml_class_init (TplLogStoreXmlClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GParamSpec *param_spec; - - object_class->finalize = log_store_xml_finalize; - object_class->dispose = log_store_xml_dispose; - object_class->get_property = tpl_log_store_xml_get_property; - object_class->set_property = tpl_log_store_xml_set_property; - - g_object_class_override_property (object_class, PROP_READABLE, "readable"); - - /** - * TplLogStoreXml:basedir: - * - * The log store's basedir. - */ - param_spec = g_param_spec_string ("basedir", - "Basedir", - "The TplLogStore implementation's name", - NULL, G_PARAM_READABLE | G_PARAM_WRITABLE | - G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_BASEDIR, param_spec); - - param_spec = g_param_spec_boolean ("testmode", - "TestMode", - "Whether the logstore is in testmode, for testsuite use only", - FALSE, G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_TESTMODE, param_spec); - - g_type_class_add_private (object_class, sizeof (TplLogStoreXmlPriv)); -} - - -static void -_tpl_log_store_xml_init (TplLogStoreXml *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - TPL_TYPE_LOG_STORE_XML, TplLogStoreXmlPriv); - self->priv->account_manager = tp_account_manager_dup (); -} - - -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); - - return g_strdelimit (g_strdup (name), "/", '_'); -} - - -/* id can be NULL, but if present have to be a non zero-lenght string. - * If NULL, the returned dir will be composed until the account part. - * If non-NULL, the returned dir will be composed until the id part */ -static gchar * -log_store_xml_get_dir (TplLogStoreXml *self, - TpAccount *account, - TplEntity *target) -{ - gchar *basedir; - gchar *escaped_account; - gchar *escaped_id = NULL; - - g_return_val_if_fail (TPL_IS_LOG_STORE_XML (self), NULL); - g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL); - - escaped_account = log_store_account_to_dirname (account); - - if (target != NULL) - { - /* FIXME This may be source of bug (does that case still exist ?) - * avoid that 1-1 conversation generated from a chatroom, having id similar - * to room@conference.domain/My_Alias (in XMPP) are treated as a directory - * path, creating My_Alias as a subdirectory of room@conference.domain */ - escaped_id = g_strdelimit ( - g_strdup (tpl_entity_get_identifier (target)), - "/", '_'); - } - - if (target != NULL - && tpl_entity_get_entity_type (target) == TPL_ENTITY_ROOM) - basedir = g_build_path (G_DIR_SEPARATOR_S, - log_store_xml_get_basedir (self), escaped_account, LOG_DIR_CHATROOMS, - escaped_id, NULL); - else - basedir = g_build_path (G_DIR_SEPARATOR_S, - log_store_xml_get_basedir (self), escaped_account, escaped_id, NULL); - - g_free (escaped_account); - g_free (escaped_id); - - return basedir; -} - - -static const gchar * -log_store_xml_get_file_suffix (GType type) -{ - if (type == TPL_TYPE_TEXT_EVENT) - return LOG_FILENAME_SUFFIX; - else if (type == TPL_TYPE_CALL_EVENT) - return LOG_FILENAME_CALL_SUFFIX; - else - g_return_val_if_reached (NULL); -} - - -static gchar * -log_store_xml_get_timestamp_filename (GType type, - gint64 timestamp) -{ - gchar *date_str; - gchar *filename; - GDateTime *date; - - date = g_date_time_new_from_unix_utc (timestamp); - date_str = g_date_time_format (date, LOG_TIME_FORMAT); - filename = g_strconcat (date_str, log_store_xml_get_file_suffix (type), - NULL); - - g_date_time_unref (date); - g_free (date_str); - - return filename; -} - - -static gchar * -log_store_xml_format_timestamp (gint64 timestamp) -{ - GDateTime *ts; - gchar *ts_str; - - ts = g_date_time_new_from_unix_utc (timestamp); - ts_str = g_date_time_format (ts, LOG_TIME_FORMAT_FULL); - - g_date_time_unref (ts); - - return ts_str; -} - - -static gchar * -log_store_xml_get_timestamp_from_event (TplEvent *event) -{ - return log_store_xml_format_timestamp (tpl_event_get_timestamp (event)); -} - - -static gchar * -log_store_xml_get_filename (TplLogStoreXml *self, - TpAccount *account, - TplEntity *target, - GType type, - gint64 timestamp) -{ - gchar *id_dir; - gchar *timestamp_str; - gchar *filename; - - id_dir = log_store_xml_get_dir (self, account, target); - timestamp_str = log_store_xml_get_timestamp_filename (type, timestamp); - filename = g_build_filename (id_dir, timestamp_str, NULL); - - g_free (id_dir); - g_free (timestamp_str); - - return filename; -} - - -/* this is a method used at the end of the add_event process, used by any - * Event<Type> instance. it should the only method allowed to write to the - * store */ -static gboolean -_log_store_xml_write_to_store (TplLogStoreXml *self, - TpAccount *account, - TplEntity *target, - const gchar *event, - GType type, - gint64 timestamp, - GError **error) -{ - FILE *file; - gchar *filename; - gchar *basedir; - gboolean ret = TRUE; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - g_return_val_if_fail (TPL_IS_LOG_STORE_XML (self), FALSE); - g_return_val_if_fail (TP_IS_ACCOUNT (account), FALSE); - g_return_val_if_fail (TPL_IS_ENTITY (target), FALSE); - - - filename = log_store_xml_get_filename (self, account, target, type, timestamp); - basedir = g_path_get_dirname (filename); - - if (!g_file_test (basedir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) - { - DEBUG ("Creating directory: '%s'", basedir); - g_mkdir_with_parents (basedir, LOG_DIR_CREATE_MODE); - } - - g_free (basedir); - - if (!g_file_test (filename, G_FILE_TEST_EXISTS)) - { - file = g_fopen (filename, "w+"); - if (file != NULL) - g_fprintf (file, LOG_HEADER); - - g_chmod (filename, LOG_FILE_CREATE_MODE); - } - else - { - file = g_fopen (filename, "r+"); - if (file != NULL) - fseek (file, -strlen (LOG_FOOTER), SEEK_END); - } - - if (file == NULL) - { - g_set_error (error, TPL_LOG_STORE_ERROR, - TPL_LOG_STORE_ERROR_FAILED, - "Couldn't open log file: %s", filename); - ret = FALSE; - goto out; - } - - g_fprintf (file, "%s", event); - DEBUG ("%s: written: %s", filename, event); - - fclose (file); - out: - g_free (filename); - return ret; -} - - -static gboolean -add_text_event (TplLogStoreXml *self, - TplTextEvent *message, - GError **error) -{ - gboolean ret = FALSE; - gint64 timestamp; - TpDBusDaemon *bus_daemon; - TpAccount *account; - TplEntity *sender; - const gchar *body_str; - const gchar *token_str; - gchar *avatar_token = NULL; - gchar *body = NULL; - gchar *time_str = NULL; - gchar *contact_name = NULL; - gchar *contact_id = NULL; - GString *event = NULL; - TpChannelTextMessageType msg_type; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - g_return_val_if_fail (TPL_IS_LOG_STORE_XML (self), FALSE); - g_return_val_if_fail (TPL_IS_TEXT_EVENT (message), FALSE); - - bus_daemon = tp_dbus_daemon_dup (error); - if (bus_daemon == NULL) - { - DEBUG ("Error acquiring bus daemon: %s", (*error)->message); - goto out; - } - - account = tpl_event_get_account (TPL_EVENT (message)); - - body_str = tpl_text_event_get_message (message); - if (TPL_STR_EMPTY (body_str)) - { - g_set_error (error, TPL_LOG_STORE_ERROR, - TPL_LOG_STORE_ERROR_FAILED, - "The message body is empty or NULL"); - goto out; - } - - body = g_markup_escape_text (body_str, -1); - msg_type = tpl_text_event_get_message_type (message); - time_str = log_store_xml_get_timestamp_from_event ( - TPL_EVENT (message)); - - sender = tpl_event_get_sender (TPL_EVENT (message)); - - if (sender != NULL) - { - contact_id = g_markup_escape_text (tpl_entity_get_identifier (sender), -1); - contact_name = g_markup_escape_text (tpl_entity_get_alias (sender), -1); - avatar_token = g_markup_escape_text (tpl_entity_get_avatar_token (sender), - -1); - } - - event = g_string_new (NULL); - g_string_printf (event, "<message time='%s' id='%s' name='%s' " - "token='%s' isuser='%s' type='%s'", - time_str, - contact_id ? contact_id : "", - contact_name ? contact_name : "", - avatar_token ? avatar_token : "", - (sender && tpl_entity_get_entity_type (sender) - == TPL_ENTITY_SELF) ? "true" : "false", - _tpl_text_event_message_type_to_str (msg_type)); - - token_str = tpl_text_event_get_message_token (message); - if (!TPL_STR_EMPTY (token_str)) - { - gchar *message_token = g_markup_escape_text (token_str, -1); - g_string_append_printf (event, " message-token='%s'", message_token); - g_free (message_token); - - token_str = tpl_text_event_get_supersedes_token (message); - if (!TPL_STR_EMPTY (token_str)) - { - gchar *supersedes_token = g_markup_escape_text (token_str, -1); - guint edit_timestamp; - g_string_append_printf (event, " supersedes-token='%s'", - supersedes_token); - - edit_timestamp = tpl_text_event_get_edit_timestamp (message); - if (edit_timestamp != 0) - { - gchar *edit_timestamp_str = - log_store_xml_format_timestamp (edit_timestamp); - g_string_append_printf (event, " edit-timestamp='%s'", - edit_timestamp_str); - g_free (edit_timestamp_str); - } - } - - } - - timestamp = tpl_event_get_timestamp (TPL_EVENT (message)); - - g_string_append_printf (event, ">%s</message>\n" LOG_FOOTER, body); - - DEBUG ("writing text event from %s (ts %s)", - contact_id, time_str); - - ret = _log_store_xml_write_to_store (self, account, - _tpl_event_get_target (TPL_EVENT (message)), event->str, - TPL_TYPE_TEXT_EVENT, timestamp, error); - -out: - g_free (contact_id); - g_free (contact_name); - g_free (time_str); - g_free (body); - g_string_free (event, TRUE); - g_free (avatar_token); - - if (bus_daemon != NULL) - g_object_unref (bus_daemon); - - return ret; -} - - -static gboolean -add_call_event (TplLogStoreXml *self, - TplCallEvent *event, - GError **error) -{ - gboolean ret = FALSE; - TpDBusDaemon *bus_daemon; - TpAccount *account; - TplEntity *sender; - TplEntity *actor; - TplEntity *target; - gchar *time_str = NULL; - gchar *sender_avatar = NULL; - gchar *sender_name = NULL; - gchar *sender_id = NULL; - gchar *actor_name = NULL; - gchar *actor_avatar = NULL; - gchar *actor_id = NULL; - gchar *log_str = NULL; - TpCallStateChangeReason reason; - - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - g_return_val_if_fail (TPL_IS_LOG_STORE_XML (self), FALSE); - g_return_val_if_fail (TPL_IS_CALL_EVENT (event), FALSE); - - bus_daemon = tp_dbus_daemon_dup (error); - if (bus_daemon == NULL) - { - DEBUG ("Error acquiring bus daemon: %s", (*error)->message); - goto out; - } - - account = tpl_event_get_account (TPL_EVENT (event)); - - time_str = log_store_xml_get_timestamp_from_event ( - TPL_EVENT (event)); - reason = tpl_call_event_get_end_reason (event); - - sender = tpl_event_get_sender (TPL_EVENT (event)); - actor = tpl_call_event_get_end_actor (event); - target = _tpl_event_get_target (TPL_EVENT (event)); - - if (sender != NULL) - { - sender_id = g_markup_escape_text (tpl_entity_get_identifier (sender), -1); - sender_name = g_markup_escape_text (tpl_entity_get_alias (sender), -1); - sender_avatar = g_markup_escape_text (tpl_entity_get_avatar_token (sender), - -1); - } - - if (actor != NULL) - { - actor_id = g_markup_escape_text (tpl_entity_get_identifier (actor), -1); - actor_name = g_markup_escape_text (tpl_entity_get_alias (actor), -1); - actor_avatar = g_markup_escape_text (tpl_entity_get_avatar_token (actor), - -1); - } - - - log_str = g_strdup_printf ("<call time='%s' " - "id='%s' name='%s' isuser='%s' token='%s' " - "duration='%" G_GINT64_FORMAT "' " - "actor='%s' actortype='%s' " - "actorname='%s' actortoken='%s' " - "reason='%s' detail='%s'/>\n" - LOG_FOOTER, - time_str, - sender_id ? sender_id : "", - sender_name ? sender_name : "", - (sender && tpl_entity_get_entity_type (sender) == - TPL_ENTITY_SELF) ? "true" : "false", - sender_avatar ? sender_avatar : "", - tpl_call_event_get_duration (event), - actor_id ? actor_id : "", - actor ? _tpl_entity_type_to_str (tpl_entity_get_entity_type (actor)) : "", - actor_name ? actor_name : "", - actor_avatar ? actor_avatar : "", - _tpl_call_event_end_reason_to_str (reason), - tpl_call_event_get_detailed_end_reason (event)); - - DEBUG ("writing call event from %s (ts %s)", - tpl_entity_get_identifier (target), - time_str); - - ret = _log_store_xml_write_to_store (self, account, target, log_str, - TPL_TYPE_CALL_EVENT, tpl_event_get_timestamp (TPL_EVENT (event)), - error); - -out: - g_free (sender_id); - g_free (sender_name); - g_free (sender_avatar); - g_free (actor_id); - g_free (actor_name); - g_free (actor_avatar); - g_free (time_str); - g_free (log_str); - - if (bus_daemon != NULL) - g_object_unref (bus_daemon); - - return ret; -} - - -/* First of two phases selection: understand the type Event */ -static gboolean -log_store_xml_add_event (TplLogStore *store, - TplEvent *event, - GError **error) -{ - TplLogStoreXml *self = TPL_LOG_STORE_XML (store); - - g_return_val_if_fail (TPL_IS_EVENT (event), FALSE); - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (TPL_IS_TEXT_EVENT (event)) - return add_text_event (self, TPL_TEXT_EVENT (event), error); - else if (TPL_IS_CALL_EVENT (event)) - return add_call_event (self, TPL_CALL_EVENT (event), error); - - DEBUG ("TplEntry not handled by this LogStore (%s). " - "Ignoring Event", _tpl_log_store_get_name (store)); - /* do not consider it an error, this LogStore simply do not want/need - * this Event */ - return TRUE; -} - - -static gboolean -log_store_xml_exists_in_directory (const gchar *dirname, - GRegex *regex, - gint type_mask, - gboolean recursive) -{ - gboolean exists; - const gchar *basename; - GDir *dir; - - DEBUG ("Looking in directory '%s' %s", - dirname, recursive ? "resursively" : ""); - - dir = g_dir_open (dirname, 0, NULL); - exists = (dir != NULL); - - if (CONTAINS_ALL_SUPPORTED_TYPES (type_mask) || !exists) - goto out; - - exists = FALSE; - while ((basename = g_dir_read_name (dir)) != NULL) - { - gchar *filename; - - filename = g_build_filename (dirname, basename, NULL); - - DEBUG ("Matching with filename '%s'", basename); - - if (recursive && g_file_test (filename, G_FILE_TEST_IS_DIR)) - exists = log_store_xml_exists_in_directory (filename, regex, type_mask, - !tp_strdiff (basename, LOG_DIR_CHATROOMS)); - else if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) - exists = g_regex_match (regex, basename, 0, 0); - - g_free (filename); - - if (exists) - break; - } - -out: - if (dir != NULL) - g_dir_close (dir); - - return exists; -} - - -static GRegex * -log_store_xml_create_filename_regex (gint type_mask) -{ - GString *pattern; - GRegex *regex = NULL; - GError *error = NULL; - - pattern = g_string_new (""); - - if (type_mask & TPL_EVENT_MASK_TEXT) - g_string_append (pattern, LOG_FILENAME_PATTERN); - - if (type_mask & TPL_EVENT_MASK_CALL) - g_string_append_printf (pattern, - "%s" LOG_FILENAME_CALL_PATTERN, - pattern->len == 0 ? "" : "|"); - - if (pattern->len == 0) - goto out; - - DEBUG ("Pattern is '%s'", pattern->str); - - regex = g_regex_new (pattern->str, G_REGEX_OPTIMIZE, 0, &error); - - if (regex == NULL) - { - DEBUG ("Failed to create regex: %s", error->message); - g_error_free (error); - } - -out: - g_string_free (pattern, TRUE); - - return regex; -} - - -static gboolean -log_store_xml_exists (TplLogStore *store, - TpAccount *account, - TplEntity *target, - gint type_mask) -{ - TplLogStoreXml *self = (TplLogStoreXml *) store; - gchar *dirname; - GRegex *regex; - gboolean exists = FALSE; - - g_return_val_if_fail (TPL_IS_LOG_STORE_XML (self), FALSE); - g_return_val_if_fail (TP_IS_ACCOUNT (account), FALSE); - g_return_val_if_fail (target == NULL || TPL_IS_ENTITY (target), FALSE); - - dirname = log_store_xml_get_dir (self, account, target); - regex = log_store_xml_create_filename_regex (type_mask); - - if (regex != NULL) - exists = log_store_xml_exists_in_directory (dirname, regex, type_mask, - target == NULL); - - g_free (dirname); - - if (regex != NULL) - g_regex_unref (regex); - - return exists; -} - -static GDate * -create_date_from_string (const gchar *str) -{ - GDate *date; - guint u; - guint day, month, year; - - if (sscanf (str, "%u", &u) != 1) - return NULL; - - day = (u % 100); - month = ((u / 100) % 100); - year = (u / 10000); - - if (!g_date_valid_dmy (day, month, year)) - return NULL; - - date = g_date_new_dmy (day, month, year); - - return date; -} - - -static gboolean -log_store_xml_match_in_file (const gchar *filename, - GRegex *regex) -{ - gboolean retval = FALSE; - GMappedFile *file; - gsize length; - gchar *contents = NULL; - - file = g_mapped_file_new (filename, FALSE, NULL); - if (file == NULL) - goto out; - - length = g_mapped_file_get_length (file); - contents = g_mapped_file_get_contents (file); - - if (length == 0 || contents == NULL) - goto out; - - retval = g_regex_match_full (regex, contents, length, 0, 0, NULL, NULL); - - DEBUG ("%s pattern '%s' in file '%s'", - retval ? "Matched" : "Not matched", - g_regex_get_pattern (regex), - filename); - -out: - if (file != NULL) - g_mapped_file_unref (file); - - return retval; -} - - -static GList * -log_store_xml_get_dates (TplLogStore *store, - TpAccount *account, - TplEntity *target, - gint type_mask) -{ - TplLogStoreXml *self = (TplLogStoreXml *) store; - GList *dates = NULL; - GList *l; - gchar *directory = NULL; - GDir *dir = NULL; - GString *pattern = NULL; - GRegex *regex = NULL; - const gchar *basename; - - 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_IS_ENTITY (target), NULL); - - directory = log_store_xml_get_dir (self, account, target); - dir = g_dir_open (directory, 0, NULL); - if (!dir) - { - DEBUG ("Could not open directory:'%s'", directory); - goto out; - } - - DEBUG ("Collating a list of dates in:'%s'", directory); - regex = log_store_xml_create_filename_regex (type_mask); - - if (regex == NULL) - goto out; - - while ((basename = g_dir_read_name (dir)) != NULL) - { - const gchar *p; - gchar *str; - GDate *date; - - if (!g_regex_match (regex, basename, 0, NULL)) - continue; - - p = strstr (basename, LOG_FILENAME_CALL_SUFFIX); - - if (p == NULL) - p = strstr (basename, LOG_FILENAME_SUFFIX); - - str = g_strndup (basename, p - basename); - - if (str == NULL) - continue; - - date = create_date_from_string (str); - - if (date != NULL) - dates = g_list_insert_sorted (dates, date, - (GCompareFunc) g_date_compare); - - g_free (str); - } - - /* Filter out duplicate dates in-place */ - for (l = dates; g_list_next (l) != NULL; l = g_list_next (l)) - { - GList *next = g_list_next (l); - - if (g_date_compare ((GDate *) next->data, (GDate *) l->data) == 0) - { - g_date_free ((GDate *) next->data); - l = g_list_delete_link (l, next); - } - } - -out: - g_free (directory); - - if (dir != NULL) - g_dir_close (dir); - - if (pattern != NULL) - g_string_free (pattern, TRUE); - - if (regex != NULL) - g_regex_unref (regex); - - DEBUG ("Parsed %d dates", g_list_length (dates)); - - return dates; -} - - -static gchar * -log_store_xml_get_filename_for_date (TplLogStoreXml *self, - TpAccount *account, - TplEntity *target, - const GDate *date, - GType type) -{ - 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_IS_ENTITY (target), 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, target); - timestamp = g_strconcat (str, log_store_xml_get_file_suffix (type), NULL); - filename = g_build_filename (basedir, timestamp, NULL); - - g_free (basedir); - g_free (timestamp); - - return filename; -} - - -static TplLogSearchHit * -log_store_xml_search_hit_new (TplLogStoreXml *self, - const gchar *filename) -{ - TplLogSearchHit *hit; - gchar *account_name; - const gchar *end; - gchar **strv; - guint len; - GList *accounts, *l; - gchar *tmp; - TpAccount *account = NULL; - GDate *date; - const gchar *chat_id; - gboolean is_chatroom; - TplEntity *target; - - g_return_val_if_fail (TPL_IS_LOG_STORE_XML (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); - - end = strstr (strv[len - 1], LOG_FILENAME_SUFFIX); - tmp = g_strndup (strv[len - 1], end - strv[len - 1]); - date = create_date_from_string (tmp); - g_free (tmp); - chat_id = strv[len - 2]; - is_chatroom = (strcmp (strv[len - 3], LOG_DIR_CHATROOMS) == 0); - - if (is_chatroom) - account_name = strv[len - 4]; - else - account_name = strv[len - 3]; - - /* FIXME: This assumes the account manager is prepared, but the - * synchronous API forces this. See bug #599189. */ - accounts = tp_account_manager_dup_usable_accounts ( - self->priv->account_manager); - - for (l = accounts; l != NULL && account == NULL; l = g_list_next (l)) - { - TpAccount *acc = TP_ACCOUNT (l->data); - gchar *name; - - name = log_store_account_to_dirname (acc); - if (!tp_strdiff (name, account_name)) - account = acc; - g_free (name); - } - g_list_free_full (accounts, g_object_unref); - - if (is_chatroom) - target = tpl_entity_new_from_room_id (chat_id); - else - target = tpl_entity_new (chat_id, TPL_ENTITY_CONTACT, NULL, NULL); - - hit = _tpl_log_manager_search_hit_new (account, target, date); - - g_strfreev (strv); - g_date_free (date); - g_object_unref (target); - - return hit; -} - - -static TplEvent * -parse_text_node (TplLogStoreXml *self, - xmlNodePtr node, - gboolean is_room, - const gchar *target_id, - TpAccount *account) -{ - TplEvent *event; - TplEntity *sender; - TplEntity *receiver; - gchar *time_str; - gint64 timestamp; - gchar *edit_time_str; - gint64 edit_timestamp = 0; - gchar *sender_id; - gchar *sender_name; - gchar *sender_avatar_token; - gchar *body; - gchar *message_token; - gchar *supersedes_token; - gchar *is_user_str; - gboolean is_user = FALSE; - gchar *msg_type_str; - TpChannelTextMessageType msg_type = TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL; - - body = (gchar *) xmlNodeGetContent (node); - time_str = (gchar *) xmlGetProp (node, (const xmlChar *) "time"); - edit_time_str = (gchar *) xmlGetProp (node, - (const xmlChar *) "edit-timestamp"); - sender_id = (gchar *) xmlGetProp (node, (const xmlChar *) "id"); - sender_name = (gchar *) xmlGetProp (node, (const xmlChar *) "name"); - sender_avatar_token = (gchar *) xmlGetProp (node, - (const xmlChar *) "token"); - message_token = (gchar *) xmlGetProp (node, - (const xmlChar *) "message-token"); - supersedes_token = (gchar *) xmlGetProp (node, - (const xmlChar *) "supersedes-token"); - is_user_str = (gchar *) xmlGetProp (node, (const xmlChar *) "isuser"); - msg_type_str = (gchar *) xmlGetProp (node, (const xmlChar *) "type"); - - if (is_user_str != NULL) - is_user = (!tp_strdiff (is_user_str, "true")); - - if (msg_type_str != NULL) - msg_type = _tpl_text_event_message_type_from_str (msg_type_str); - - timestamp = _tpl_time_parse (time_str); - - if (supersedes_token != NULL && edit_time_str != NULL) - { - edit_timestamp = _tpl_time_parse (edit_time_str); - } - - if (is_room) - receiver = tpl_entity_new_from_room_id (target_id); - else if (is_user) - receiver = tpl_entity_new (target_id, TPL_ENTITY_CONTACT, NULL, NULL); - else - receiver = tpl_entity_new (tp_account_get_normalized_name (account), - TPL_ENTITY_SELF, tp_account_get_nickname (account), NULL); - - sender = tpl_entity_new (sender_id, - is_user ? TPL_ENTITY_SELF : TPL_ENTITY_CONTACT, - sender_name, sender_avatar_token); - - event = g_object_new (TPL_TYPE_TEXT_EVENT, - /* TplEvent */ - "account", account, - /* MISSING: "channel-path", channel_path, */ - "receiver", receiver, - "sender", sender, - "timestamp", timestamp, - /* TplTextEvent */ - "message-type", msg_type, - "message", body, - "message-token", message_token, - "supersedes-token", supersedes_token, - "edit-timestamp", edit_timestamp, - NULL); - - g_object_unref (sender); - g_object_unref (receiver); - xmlFree (time_str); - xmlFree (edit_time_str); - xmlFree (sender_id); - xmlFree (sender_name); - xmlFree (body); - xmlFree (message_token); - xmlFree (supersedes_token); - xmlFree (is_user_str); - xmlFree (msg_type_str); - xmlFree (sender_avatar_token); - - return event; -} - -static gchar * -dup_detailed_reason (xmlNodePtr node) -{ - gchar *d, *result; - const gchar *old_tp_prefix = "org.freedesktop.Telepathy.Error"; - - d = (char *) xmlGetProp (node, (const xmlChar *) "detail"); - - /* Ensure log backward compatiblity if the reason is using the old (pre 1.0) - * Telepathy prefix. */ - if (!g_str_has_prefix (d, old_tp_prefix)) - { - result = g_strdup (d); - xmlFree (d); - return result; - } - - result = g_strdup_printf ("%s.%s", TP_ERROR_PREFIX, - d + strlen (old_tp_prefix) + 1); - - xmlFree (d); - return result; -} - -static TplEvent * -parse_call_node (TplLogStoreXml *self, - xmlNodePtr node, - gboolean is_room, - const gchar *target_id, - TpAccount *account) -{ - TplEvent *event; - TplEntity *sender; - TplEntity *receiver; - TplEntity *actor; - gchar *time_str; - gint64 timestamp; - gchar *sender_id; - gchar *sender_name; - gchar *sender_avatar_token; - gchar *is_user_str; - gboolean is_user = FALSE; - gchar *actor_id; - gchar *actor_name; - gchar *actor_type; - gchar *actor_avatar_token; - gchar *duration_str; - gint64 duration = -1; - gchar *reason_str; - TpCallStateChangeReason reason = TP_CALL_STATE_CHANGE_REASON_UNKNOWN; - gchar *detailed_reason; - - time_str = (gchar *) xmlGetProp (node, (const xmlChar *) "time"); - sender_id = (gchar *) xmlGetProp (node, (const xmlChar *) "id"); - sender_name = (gchar *) xmlGetProp (node, (const xmlChar *) "name"); - sender_avatar_token = (gchar *) xmlGetProp (node, - (const xmlChar *) "token"); - is_user_str = (gchar *) xmlGetProp (node, (const xmlChar *) "isuser"); - duration_str = (char *) xmlGetProp (node, (const xmlChar*) "duration"); - actor_id = (char *) xmlGetProp (node, (const xmlChar *) "actor"); - actor_name = (char *) xmlGetProp (node, (const xmlChar *) "actorname"); - actor_type = (char *) xmlGetProp (node, (const xmlChar *) "actortype"); - actor_avatar_token = (char *) xmlGetProp (node, - (const xmlChar *) "actortoken"); - reason_str = (char *) xmlGetProp (node, (const xmlChar *) "reason"); - detailed_reason = dup_detailed_reason (node); - - if (is_user_str != NULL) - is_user = (!tp_strdiff (is_user_str, "true")); - - if (reason_str != NULL) - reason = _tpl_call_event_str_to_end_reason (reason_str); - - timestamp = _tpl_time_parse (time_str); - - if (is_room) - receiver = tpl_entity_new_from_room_id (target_id); - else if (is_user) - receiver = tpl_entity_new (target_id, TPL_ENTITY_CONTACT, NULL, NULL); - else - receiver = tpl_entity_new (tp_account_get_normalized_name (account), - TPL_ENTITY_SELF, tp_account_get_nickname (account), NULL); - - sender = tpl_entity_new (sender_id, - is_user ? TPL_ENTITY_SELF : TPL_ENTITY_CONTACT, - sender_name, sender_avatar_token); - - actor = tpl_entity_new (actor_id, - _tpl_entity_type_from_str (actor_type), - actor_name, actor_avatar_token); - - if (duration_str != NULL) - duration = atoll (duration_str); - - event = g_object_new (TPL_TYPE_CALL_EVENT, - /* TplEvent */ - "account", account, - /* MISSING: "channel-path", channel_path, */ - "receiver", receiver, - "sender", sender, - "timestamp", timestamp, - /* TplCallEvent */ - "duration", duration, - "end-actor", actor, - "end-reason", reason, - "detailed-end-reason", detailed_reason, - NULL); - - g_object_unref (sender); - g_object_unref (receiver); - g_object_unref (actor); - xmlFree (time_str); - xmlFree (sender_id); - xmlFree (sender_name); - xmlFree (sender_avatar_token); - xmlFree (is_user_str); - xmlFree (actor_id); - xmlFree (actor_name); - xmlFree (actor_type); - xmlFree (actor_avatar_token); - xmlFree (duration_str); - xmlFree (reason_str); - g_free (detailed_reason); - - return event; -} - - -static void -event_queue_replace_and_supersede (GQueue *events, - GList *index, - GHashTable *superseded_links, - TplTextEvent *event) -{ - _tpl_text_event_add_supersedes (event, index->data); - g_hash_table_insert (superseded_links, - (gpointer) tpl_text_event_get_message_token (index->data), index); - g_object_unref (index->data); - index->data = event; -} - - -static GList * -event_queue_add_text_event (GQueue *events, - GList *index, - GHashTable *superseded_links, - TplTextEvent *event) -{ - GList *l = NULL; - const gchar *supersedes_token = tpl_text_event_get_supersedes_token (event); - TplTextEvent *dummy_event; - - if (supersedes_token == NULL) - return _tpl_event_queue_insert_sorted_after (events, index, - TPL_EVENT (event)); - - l = g_hash_table_lookup (superseded_links, supersedes_token); - if (l != NULL) - { - event_queue_replace_and_supersede (events, l, superseded_links, event); - return index; - } - - /* Search backwards from "now" and insert (but don't update "now") */ - for (l = index; l != NULL; l = g_list_previous (l)) - { - if (!tp_strdiff (tpl_text_event_get_message_token (l->data), - supersedes_token)) - { - event_queue_replace_and_supersede (events, l, superseded_links, - event); - return index; - } - } - - DEBUG ("Can't find event %s (superseded by %s). " - "Adding Dummy event.", - supersedes_token, tpl_text_event_get_message_token (event)); - - dummy_event = g_object_new (TPL_TYPE_TEXT_EVENT, - /* TplEvent */ - "account", tpl_event_get_account (TPL_EVENT (event)), - /* MISSING: "channel-path", channel_path, */ - "receiver", tpl_event_get_receiver (TPL_EVENT (event)), - "sender", tpl_event_get_sender (TPL_EVENT (event)), - "timestamp", tpl_event_get_timestamp (TPL_EVENT (event)), - /* TplTextEvent */ - "message-type", tpl_text_event_get_message_type (event), - "message", "", - "message-token", supersedes_token, - NULL); - - index = _tpl_event_queue_insert_sorted_after (events, index, - TPL_EVENT (dummy_event)); - event_queue_replace_and_supersede (events, index, superseded_links, event); - return index; -} - - -/* returns a Glist of TplEvent instances. - * - * @account needs to have TP_ACCOUNT_FEATURE_CORE prepared (we use - * tp_account_get_nickname() and tp_account_get_normalized_name() which rely - * on CORE being prepared). - * */ -static void -log_store_xml_get_events_for_file (TplLogStoreXml *self, - TpAccount *account, - const gchar *filename, - GType type, - GQueue *events) -{ - xmlParserCtxtPtr ctxt; - xmlDocPtr doc; - xmlNodePtr log_node; - xmlNodePtr node; - gboolean is_room; - gchar *dirname; - gchar *tmp; - gchar *target_id; - GHashTable *supersedes_links; - guint num_events = 0; - GList *index; - - g_return_if_fail (TPL_IS_LOG_STORE_XML (self)); - g_return_if_fail (TP_IS_ACCOUNT (account)); - g_return_if_fail (!TPL_STR_EMPTY (filename)); - g_return_if_fail (tp_proxy_is_prepared (account, TP_ACCOUNT_FEATURE_CORE)); - - DEBUG ("Attempting to parse filename:'%s'...", filename); - - if (!g_file_test (filename, G_FILE_TEST_EXISTS)) - { - DEBUG ("Filename:'%s' does not exist", filename); - return; - } - - /* Create parser. */ - ctxt = xmlNewParserCtxt (); - - /* Parse and validate the file. */ - doc = xmlCtxtReadFile (ctxt, filename, NULL, 0); - if (!doc) - { - g_warning ("Failed to parse file:'%s'", filename); - xmlFreeParserCtxt (ctxt); - return; - } - - /* The root node, presets. */ - log_node = xmlDocGetRootElement (doc); - if (!log_node) - { - xmlFreeDoc (doc); - xmlFreeParserCtxt (ctxt); - return; - } - - /* Guess the target based on directory name */ - dirname = g_path_get_dirname (filename); - target_id = g_path_get_basename (dirname); - - /* Determine if it's a chatroom */ - tmp = dirname; - dirname = g_path_get_dirname (tmp); - g_free (tmp); - tmp = g_path_get_basename (dirname); - is_room = (g_strcmp0 (LOG_DIR_CHATROOMS, tmp) == 0); - g_free (dirname); - g_free (tmp); - - /* Temporary hash from (borrowed) supersedes-token to (borrowed) link in - * events, for any event that was once in events, but has since been - * superseded (and therefore won't be found by a linear search). */ - supersedes_links = g_hash_table_new (g_str_hash, g_str_equal); - - /* Now get the events. */ - index = NULL; - for (node = log_node->children; node; node = node->next) - { - TplEvent *event = NULL; - - if (type == TPL_TYPE_TEXT_EVENT - && strcmp ((const gchar *) node->name, "message") == 0) - { - event = parse_text_node (self, node, is_room, target_id, account); - - if (event == NULL) - continue; - - index = event_queue_add_text_event (events, index, - supersedes_links, TPL_TEXT_EVENT (event)); - num_events++; - } - else if (type == TPL_TYPE_CALL_EVENT - && strcmp ((const char*) node->name, "call") == 0) - { - event = parse_call_node (self, node, is_room, target_id, account); - - if (event == NULL) - continue; - - index = _tpl_event_queue_insert_sorted_after (events, index, event); - num_events++; - } - } - - DEBUG ("Parsed %u events", num_events); - - g_free (target_id); - xmlFreeDoc (doc); - xmlFreeParserCtxt (ctxt); - g_hash_table_unref (supersedes_links); -} - - -/* If dir is NULL, basedir will be used instead. - * Used to make possible the full search vs. specific subtrees search */ -static GList * -log_store_xml_get_all_files (TplLogStoreXml *self, - const gchar *dir, - gint type_mask) -{ - GDir *gdir; - GList *files = NULL; - const gchar *name; - const gchar *basedir; - GRegex *regex; - - g_return_val_if_fail (TPL_IS_LOG_STORE_XML (self), NULL); - /* dir can be NULL, do not check */ - - basedir = (dir != NULL) ? dir : log_store_xml_get_basedir (self); - - gdir = g_dir_open (basedir, 0, NULL); - if (!gdir) - return NULL; - - regex = log_store_xml_create_filename_regex (type_mask); - - if (regex == NULL) - goto out; - - while ((name = g_dir_read_name (gdir)) != NULL) - { - gchar *filename; - - filename = g_build_filename (basedir, name, NULL); - - if (g_regex_match (regex, name, 0, NULL)) - files = g_list_prepend (files, filename); - else if (g_file_test (filename, G_FILE_TEST_IS_DIR)) - { - /* Recursively get all log files */ - files = g_list_concat (files, - log_store_xml_get_all_files (self, filename, type_mask)); - g_free (filename); - } - } - -out: - g_dir_close (gdir); - - if (regex != NULL) - g_regex_unref (regex); - - return files; -} - - -static GList * -_log_store_xml_search_in_files (TplLogStoreXml *self, - const gchar *text, - GList *files, - gint type_mask) -{ - GList *l; - GList *hits = NULL; - gchar *markup_text; - gchar *escaped_text; - GString *pattern = NULL; - GRegex *regex = NULL; - GError *error = NULL; - - g_return_val_if_fail (TPL_IS_LOG_STORE_XML (self), NULL); - g_return_val_if_fail (!TPL_STR_EMPTY (text), NULL); - - markup_text = g_markup_escape_text (text, -1); - escaped_text = g_regex_escape_string (markup_text, -1); - g_free (markup_text); - - pattern = g_string_new (""); - - if (type_mask & TPL_EVENT_MASK_TEXT) - g_string_append_printf (pattern, - "<message [^>]*>[^<]*%s[^<]*</message>" - "|<message( [^>]* | )id='[^>]*%s[^>]*'" - "|<message( [^>]* | )name='[^>]*%s[^>]*'", - escaped_text, escaped_text, escaped_text); - - if (type_mask & TPL_EVENT_MASK_CALL) - g_string_append_printf (pattern, - "%s<call( [^>]* | )id='[^>]*%s[^>]*'" - "|<call( [^>]* | )name='[^>]*%s[^>]*'" - "|<call( [^>]* | )actor='[^>]*%s[^>]*'" - "|<call( [^>]* | )actorname='[^>]*%s[^>]*'", - pattern->len == 0 ? "" : "|", - escaped_text, escaped_text, escaped_text, escaped_text); - - if (TPL_STR_EMPTY (pattern->str)) - goto out; - - regex = g_regex_new (pattern->str, - G_REGEX_CASELESS | G_REGEX_OPTIMIZE, - 0, - &error); - - if (!regex) - { - DEBUG ("Failed to compile regex: %s", error->message); - g_error_free (error); - goto out; - } - - for (l = files; l; l = g_list_next (l)) - { - gchar *filename = l->data; - - if (log_store_xml_match_in_file (filename, regex)) - { - TplLogSearchHit *hit; - - hit = log_store_xml_search_hit_new (self, filename); - if (hit != NULL) - { - hits = g_list_prepend (hits, hit); - DEBUG ("Found text:'%s' in file:'%s' on date: %04u-%02u-%02u", - text, filename, g_date_get_year (hit->date), - g_date_get_month (hit->date), g_date_get_day (hit->date)); - } - } - } - -out: - g_free (escaped_text); - - if (pattern != NULL) - g_string_free (pattern, TRUE); - - if (regex != NULL) - g_regex_unref (regex); - - g_list_free (files); - return hits; -} - - -static GList * -log_store_xml_search_new (TplLogStore *store, - const gchar *text, - gint type_mask) -{ - TplLogStoreXml *self = (TplLogStoreXml *) store; - GList *files; - - g_return_val_if_fail (TPL_IS_LOG_STORE_XML (self), NULL); - g_return_val_if_fail (!TPL_STR_EMPTY (text), NULL); - - files = log_store_xml_get_all_files (self, NULL, type_mask); - DEBUG ("Found %d log files in total", g_list_length (files)); - - return _log_store_xml_search_in_files (self, text, files, type_mask); -} - - -/* Returns: (GList *) of (TplLogSearchHit *) */ -static GList * -log_store_xml_get_entities_for_dir (TplLogStoreXml *self, - const gchar *dir, - gboolean is_chatroom, - TpAccount *account) -{ - GDir *gdir; - GList *entities = NULL; - const gchar *name; - GError *error = NULL; - - g_return_val_if_fail (TPL_IS_LOG_STORE_XML (self), NULL); - g_return_val_if_fail (!TPL_STR_EMPTY (dir), 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) - { - TplEntity *entity; - - if (!is_chatroom && strcmp (name, LOG_DIR_CHATROOMS) == 0) - { - gchar *filename = g_build_filename (dir, name, NULL); - entities = g_list_concat (entities, - log_store_xml_get_entities_for_dir (self, filename, TRUE, account)); - g_free (filename); - continue; - } - - if (is_chatroom) - entity = tpl_entity_new_from_room_id (name); - else - entity = tpl_entity_new (name, TPL_ENTITY_CONTACT, NULL, NULL); - - entities = g_list_prepend (entities, entity); - } - - g_dir_close (gdir); - - return entities; -} - - -/* returns a Glist of TplEvent instances */ -static GList * -log_store_xml_get_events_for_date (TplLogStore *store, - TpAccount *account, - TplEntity *target, - gint type_mask, - const GDate *date) -{ - TplLogStoreXml *self = (TplLogStoreXml *) store; - gchar *filename; - GQueue events = G_QUEUE_INIT; - - 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_IS_ENTITY (target), NULL); - g_return_val_if_fail (date != NULL, NULL); - - if (type_mask & TPL_EVENT_MASK_TEXT) - { - filename = log_store_xml_get_filename_for_date (self, account, target, - date, TPL_TYPE_TEXT_EVENT); - log_store_xml_get_events_for_file (self, account, filename, - TPL_TYPE_TEXT_EVENT, &events); - g_free (filename); - } - - if (type_mask & TPL_EVENT_MASK_CALL) - { - filename = log_store_xml_get_filename_for_date (self, account, target, - date, TPL_TYPE_CALL_EVENT); - log_store_xml_get_events_for_file (self, account, filename, - TPL_TYPE_CALL_EVENT, &events); - g_free (filename); - } - - return events.head; -} - - -static GList * -log_store_xml_get_entities (TplLogStore *store, - TpAccount *account) -{ - TplLogStoreXml *self = (TplLogStoreXml *) store; - gchar *dir; - GList *entities; - - g_return_val_if_fail (TPL_IS_LOG_STORE_XML (self), NULL); - g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL); - - dir = log_store_xml_get_dir (self, account, NULL); - entities = log_store_xml_get_entities_for_dir (self, dir, FALSE, account); - g_free (dir); - - return entities; -} - - -static const gchar * -log_store_xml_get_name (TplLogStore *store) -{ - TplLogStoreXml *self = (TplLogStoreXml *) store; - - g_return_val_if_fail (TPL_IS_LOG_STORE_XML (self), NULL); - - return "TpLogger"; -} - - -/* returns am absolute path for the base directory of LogStore */ -static const gchar * -log_store_xml_get_basedir (TplLogStoreXml *self) -{ - g_return_val_if_fail (TPL_IS_LOG_STORE_XML (self), NULL); - - /* set default based on name if NULL, see prop's comment about it in - * class_init method */ - if (self->priv->basedir == NULL) - { - gchar *dir; - const char *user_data_dir; - const char *name; - - if (self->priv->test_mode && g_getenv ("TPL_TEST_LOG_DIR") != NULL) - { - user_data_dir = g_getenv ("TPL_TEST_LOG_DIR"); - } - else - { - user_data_dir = g_get_user_data_dir (); - } - - name = _tpl_log_store_get_name ((TplLogStore *) self); - dir = g_build_path (G_DIR_SEPARATOR_S, user_data_dir, name, "logs", - NULL); - log_store_xml_set_basedir (self, dir); - g_free (dir); - } - - return self->priv->basedir; -} - - -static void -log_store_xml_set_basedir (TplLogStoreXml *self, - const gchar *data) -{ - g_return_if_fail (TPL_IS_LOG_STORE_XML (self)); - g_return_if_fail (self->priv->basedir == NULL); - /* data may be NULL when the class is initialized and the default value is - * set */ - - self->priv->basedir = g_strdup (data); - - /* at install_spec time, default value is set to NULL, ignore it */ - if (self->priv->basedir != NULL) - DEBUG ("logstore set to dir: %s", data); -} - - -static GList * -log_store_xml_get_filtered_events (TplLogStore *store, - TpAccount *account, - TplEntity *target, - gint type_mask, - guint num_events, - TplLogEventFilter filter, - gpointer user_data) -{ - TplLogStoreXml *self = (TplLogStoreXml *) store; - GList *dates, *l, *events = NULL; - guint i = 0; - - 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_IS_ENTITY (target), NULL); - - dates = log_store_xml_get_dates (store, account, target, type_mask); - - for (l = g_list_last (dates); l != NULL && i < num_events; - l = g_list_previous (l)) - { - GList *new_events, *n; - - /* FIXME: We should really restrict the event parsing to get only - * the newest num_events. */ - new_events = log_store_xml_get_events_for_date (store, account, - target, type_mask, l->data); - - n = g_list_last (new_events); - while (n != NULL && i < num_events) - { - if (filter == NULL || filter (n->data, user_data)) - { - events = g_list_prepend (events, g_object_ref (n->data)); - i++; - } - n = g_list_previous (n); - } - g_list_foreach (new_events, (GFunc) g_object_unref, NULL); - g_list_free (new_events); - } - - g_list_foreach (dates, (GFunc) g_date_free, NULL); - g_list_free (dates); - - return events; -} - - -static void -log_store_xml_clear (TplLogStore *store) -{ - TplLogStoreXml *self = TPL_LOG_STORE_XML (store); - const gchar *basedir; - - /* We need to use the getter otherwise the basedir might not be set yet */ - basedir = log_store_xml_get_basedir (self); - - DEBUG ("Clear all logs from XML store in: %s", basedir); - - _tpl_rmdir_recursively (basedir); -} - - -static void -log_store_xml_clear_account (TplLogStore *store, - TpAccount *account) -{ - TplLogStoreXml *self = TPL_LOG_STORE_XML (store); - gchar *account_dir; - - account_dir = log_store_xml_get_dir (self, account, NULL); - - if (account_dir) - { - DEBUG ("Clear account logs from XML store in: %s", - account_dir); - _tpl_rmdir_recursively (account_dir); - g_free (account_dir); - } - else - DEBUG ("Nothing to clear in account: %s", - tp_proxy_get_object_path (TP_PROXY (account))); -} - - -static void -log_store_xml_clear_entity (TplLogStore *store, - TpAccount *account, - TplEntity *entity) -{ - TplLogStoreXml *self = TPL_LOG_STORE_XML (store); - gchar *entity_dir; - - entity_dir = log_store_xml_get_dir (self, account, entity); - - if (entity_dir) - { - DEBUG ("Clear entity logs from XML store in: %s", - entity_dir); - - _tpl_rmdir_recursively (entity_dir); - g_free (entity_dir); - } - else - DEBUG ("Nothing to clear for account/entity: %s/%s", - tp_proxy_get_object_path (TP_PROXY (account)), - tpl_entity_get_identifier (entity)); -} - - -static TplLogIter * -log_store_xml_create_iter (TplLogStore *store, - TpAccount *account, - TplEntity *target, - gint type_mask) -{ - g_return_val_if_fail (TPL_IS_LOG_STORE_XML (store), NULL); - g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL); - g_return_val_if_fail (TPL_IS_ENTITY (target), NULL); - - return tpl_log_iter_xml_new (store, account, target, type_mask); -} - - -static void -log_store_iface_init (gpointer g_iface, - gpointer iface_data) -{ - TplLogStoreInterface *iface = (TplLogStoreInterface *) g_iface; - - iface->get_name = log_store_xml_get_name; - iface->exists = log_store_xml_exists; - iface->add_event = log_store_xml_add_event; - iface->get_dates = log_store_xml_get_dates; - iface->get_events_for_date = log_store_xml_get_events_for_date; - iface->get_entities = log_store_xml_get_entities; - iface->search_new = log_store_xml_search_new; - iface->get_filtered_events = log_store_xml_get_filtered_events; - iface->clear = log_store_xml_clear; - iface->clear_account = log_store_xml_clear_account; - iface->clear_entity = log_store_xml_clear_entity; - iface->create_iter = log_store_xml_create_iter; -} diff --git a/telepathy-logger/log-store.c b/telepathy-logger/log-store.c deleted file mode 100644 index 6e1d10f..0000000 --- a/telepathy-logger/log-store.c +++ /dev/null @@ -1,377 +0,0 @@ -/* - * Copyright (C) 2008-2011 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: Jonny Lamb <jonny.lamb@collabora.co.uk>, - * Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - */ - -#include "config.h" - -#include <telepathy-logger/log-store-internal.h> - -#define DEBUG_FLAG TPL_DEBUG_LOG_STORE -#include <telepathy-logger/debug-internal.h> - -/* - * SECTION:log-store - * @title: TplLogStore - * @short_description: LogStore interface can register into #TplLogManager as - * readable and/or writable log stores. - * @see_also: #text-event:#TplTextEvent and other subclasses when they'll exist - * - * The #TplLogStore defines all the public methods that a TPL Log Store has to - * implement in order to be used into a #TplLogManager. - */ - -static void _tpl_log_store_init (gpointer g_iface); - -GType -_tpl_log_store_get_type (void) -{ - static GType type = 0; - if (type == 0) - { - static const GTypeInfo info = { - sizeof (TplLogStoreInterface), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) _tpl_log_store_init, /* class_init */ - NULL, /* class_finalize */ - NULL, /* class_data */ - 0, - 0, /* n_preallocs */ - NULL /* instance_init */ - }; - type = g_type_register_static (G_TYPE_INTERFACE, "TplLogStore", - &info, 0); - g_type_interface_add_prerequisite (type, G_TYPE_OBJECT); - } - return type; -} - -static void -_tpl_log_store_init (gpointer g_iface) -{ - /** - * TplLogStore:readable: - * - * Defines whether the object is readable for a #TplLogManager. - * - * If an TplLogStore implementation is readable, the #TplLogManager will - * use the query methods against the instance (e.g. _tpl_log_store_get_dates()) - * every time a #TplLogManager instance is queried (e.g. - * _tpl_log_manager_get_dates()). - */ - g_object_interface_install_property (g_iface, - g_param_spec_boolean ("readable", - "Readable", - "Whether this log store is readable", - TRUE, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); -} - -const gchar * -_tpl_log_store_get_name (TplLogStore *self) -{ - g_return_val_if_fail (TPL_IS_LOG_STORE (self), NULL); - if (!TPL_LOG_STORE_GET_INTERFACE (self)->get_name) - return NULL; - - return TPL_LOG_STORE_GET_INTERFACE (self)->get_name (self); -} - - -gboolean -_tpl_log_store_exists (TplLogStore *self, - TpAccount *account, - TplEntity *target, - gint type_mask) -{ - g_return_val_if_fail (TPL_IS_LOG_STORE (self), FALSE); - if (!TPL_LOG_STORE_GET_INTERFACE (self)->exists) - return FALSE; - - return TPL_LOG_STORE_GET_INTERFACE (self)->exists (self, account, target, - type_mask); -} - - -/** - * _tpl_log_store_add_event: - * @self: a TplLogStore - * @event: an instance of a subclass of TplEvent (ie TplTextEvent) - * @error: memory location used if an error occurs - * - * Sends @event to the LogStore @self, in order to be stored. - * - * Returns: %TRUE if succeeds, %FALSE with @error set otherwise - */ -gboolean -_tpl_log_store_add_event (TplLogStore *self, - TplEvent *event, - GError **error) -{ - g_return_val_if_fail (TPL_IS_LOG_STORE (self), FALSE); - g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - - if (TPL_LOG_STORE_GET_INTERFACE (self)->add_event == NULL) - { - g_set_error (error, TPL_LOG_STORE_ERROR, - TPL_LOG_STORE_ERROR_ADD_EVENT, - "%s: %s is not writable", - G_STRFUNC, G_OBJECT_CLASS_NAME (self)); - return FALSE; - } - - return TPL_LOG_STORE_GET_INTERFACE (self)->add_event (self, event, - error); -} - - -/** - * _tpl_log_store_get_dates: - * @self: a TplLogStore - * @account: a TpAccount - * @target: a #TplEntity - * @type_mask: event type mask see #TplEventTypeMask - * - * Retrieves a list of #GDate, corresponding to each day - * at least an event was sent to or received from @id. - * - * Returns: a GList of (GDate *), to be freed using something like - * g_list_foreach (lst, g_date_free, NULL); - * g_list_free (lst); - */ -GList * -_tpl_log_store_get_dates (TplLogStore *self, - TpAccount *account, - TplEntity *target, - gint type_mask) -{ - g_return_val_if_fail (TPL_IS_LOG_STORE (self), NULL); - if (TPL_LOG_STORE_GET_INTERFACE (self)->get_dates == NULL) - return NULL; - - return TPL_LOG_STORE_GET_INTERFACE (self)->get_dates (self, account, - target, type_mask); -} - - -/** - * _tpl_log_store_get_events_for_date: - * @self: a TplLogStore - * @account: a TpAccount - * @target: a #TplEntity - * @type_mask: event type mask see #TplEventTypeMask - * @date: a #GDate - * - * Retrieves a list of events, with timestamp matching @date. - * - * Returns: a GList of TplTextEvent, to be freed using something like - * g_list_foreach (lst, g_object_unref, NULL); - * g_list_free (lst); - */ -GList * -_tpl_log_store_get_events_for_date (TplLogStore *self, - TpAccount *account, - TplEntity *target, - gint type_mask, - const GDate *date) -{ - g_return_val_if_fail (TPL_IS_LOG_STORE (self), NULL); - if (TPL_LOG_STORE_GET_INTERFACE (self)->get_events_for_date == NULL) - return NULL; - - return TPL_LOG_STORE_GET_INTERFACE (self)->get_events_for_date (self, - account, target, type_mask, date); -} - - -GList * -_tpl_log_store_get_recent_events (TplLogStore *self, - TpAccount *account, - TplEntity *target, - gint type_mask) -{ - g_return_val_if_fail (TPL_IS_LOG_STORE (self), NULL); - if (TPL_LOG_STORE_GET_INTERFACE (self)->get_recent_events == NULL) - return NULL; - - return TPL_LOG_STORE_GET_INTERFACE (self)->get_recent_events (self, account, - target, type_mask); -} - - -/** - * _tpl_log_store_get_entities: - * @self: a TplLogStore - * @account: a TpAccount - * - * Retrieves a list of #TplEntity, corresponding to each buddy/chatroom id - * the user exchanged at least a event with inside @account. - * - * Returns: a GList of #TplEntity, to be freed using something like - * g_list_foreach (lst, g_object_unref, NULL); - * g_list_free (lst); - */ -GList * -_tpl_log_store_get_entities (TplLogStore *self, - TpAccount *account) -{ - g_return_val_if_fail (TPL_IS_LOG_STORE (self), NULL); - if (TPL_LOG_STORE_GET_INTERFACE (self)->get_entities == NULL) - return NULL; - - return TPL_LOG_STORE_GET_INTERFACE (self)->get_entities (self, account); -} - - -/** - * _tpl_log_store_search_new: - * @self: a TplLogStore - * @text: a text to be searched among text messages - * @type_mask: event type mask see #TplEventTypeMask - * - * Searches all textual log entries matching @text. - * - * Returns: a GList of (TplLogSearchHit *), to be freed using something like - * g_list_foreach (lst, tpl_log_manager_search_free, NULL); - * g_list_free (lst); - */ -GList * -_tpl_log_store_search_new (TplLogStore *self, - const gchar *text, - gint type_mask) -{ - g_return_val_if_fail (TPL_IS_LOG_STORE (self), NULL); - if (TPL_LOG_STORE_GET_INTERFACE (self)->search_new == NULL) - return NULL; - - return TPL_LOG_STORE_GET_INTERFACE (self)->search_new (self, text, - type_mask); -} - - -/** - * _tpl_log_store_get_filtered_events: - * @self: a TplLogStore - * @account: a TpAccount - * @target: a #TplEntity - * @type_mask: event type mask see #TplEventTypeMask - * @num_events: max number of events to return - * @filter: filter function - * @user_data: data be passed to @filter, may be NULL - * - * Filters all events related to @id, using the boolean function - * @filter. - * It will return at most the last (ie most recent) @num_events events. - * Pass G_MAXUINT if all the events are needed. - * - * Returns: a GList of TplTextEvent, to be freed using something like - * g_list_foreach (lst, g_object_unref, NULL); - * g_list_free (lst); - */ -GList * -_tpl_log_store_get_filtered_events (TplLogStore *self, - TpAccount *account, - TplEntity *target, - gint type_mask, - guint num_events, - TplLogEventFilter filter, - gpointer user_data) -{ - g_return_val_if_fail (TPL_IS_LOG_STORE (self), NULL); - if (TPL_LOG_STORE_GET_INTERFACE (self)->get_filtered_events == NULL) - return NULL; - - return TPL_LOG_STORE_GET_INTERFACE (self)->get_filtered_events (self, - account, target, type_mask, num_events, filter, user_data); -} - - -void -_tpl_log_store_clear (TplLogStore *self) -{ - g_return_if_fail (TPL_IS_LOG_STORE (self)); - if (TPL_LOG_STORE_GET_INTERFACE (self)->clear == NULL) - return; - - TPL_LOG_STORE_GET_INTERFACE (self)->clear (self); -} - - -void -_tpl_log_store_clear_account (TplLogStore *self, TpAccount *account) -{ - g_return_if_fail (TPL_IS_LOG_STORE (self)); - if (TPL_LOG_STORE_GET_INTERFACE (self)->clear_account == NULL) - return; - - TPL_LOG_STORE_GET_INTERFACE (self)->clear_account (self, account); -} - - -void -_tpl_log_store_clear_entity (TplLogStore *self, - TpAccount *account, - TplEntity *entity) -{ - g_return_if_fail (TPL_IS_LOG_STORE (self)); - if (TPL_LOG_STORE_GET_INTERFACE (self)->clear_entity == NULL) - return; - - TPL_LOG_STORE_GET_INTERFACE (self)->clear_entity (self, account, entity); -} - - -TplLogIter * -_tpl_log_store_create_iter (TplLogStore *self, - TpAccount *account, - TplEntity *target, - gint type_mask) -{ - g_return_val_if_fail (TPL_IS_LOG_STORE (self), NULL); - if (TPL_LOG_STORE_GET_INTERFACE (self)->create_iter == NULL) - return NULL; - - return TPL_LOG_STORE_GET_INTERFACE (self)->create_iter (self, - account, target, type_mask); -} - - -gboolean -_tpl_log_store_is_writable (TplLogStore *self) -{ - g_return_val_if_fail (TPL_IS_LOG_STORE (self), FALSE); - - return (TPL_LOG_STORE_GET_INTERFACE (self)->add_event != NULL); -} - - -gboolean -_tpl_log_store_is_readable (TplLogStore *self) -{ - gboolean readable; - - g_return_val_if_fail (TPL_IS_LOG_STORE (self), FALSE); - - g_object_get (self, - "readable", &readable, - NULL); - - return readable; -} diff --git a/telepathy-logger/log-walker-internal.h b/telepathy-logger/log-walker-internal.h deleted file mode 100644 index 7425290..0000000 --- a/telepathy-logger/log-walker-internal.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2012 Red Hat, Inc. - * - * 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 - * - * Author: Debarshi Ray <debarshir@freedesktop.org> - */ - -#ifndef __TPL_LOG_WALKER_INTERNAL_H__ -#define __TPL_LOG_WALKER_INTERNAL_H__ - -#include "log-iter-internal.h" -#include "log-manager.h" -#include "log-walker.h" - -G_BEGIN_DECLS - -TplLogWalker *tpl_log_walker_new (TplLogEventFilter filter, - gpointer filter_data); - -void tpl_log_walker_add_iter (TplLogWalker *walker, - TplLogIter *iter); - -G_END_DECLS - -#endif /* __TPL_LOG_WALKER_INTERNAL_H__ */ diff --git a/telepathy-logger/log-walker.c b/telepathy-logger/log-walker.c deleted file mode 100644 index f4763e1..0000000 --- a/telepathy-logger/log-walker.c +++ /dev/null @@ -1,975 +0,0 @@ -/* - * Copyright (C) 2012 Red Hat, Inc. - * - * 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 - * - * Author: Debarshi Ray <debarshir@freedesktop.org> - */ - -#include "config.h" - -#include "log-walker.h" -#include "log-walker-internal.h" - -#include <telepathy-logger/event.h> -#include <telepathy-logger/log-iter-internal.h> - -/** - * SECTION:log-walker - * @title: TplLogWalker - * @short_description: Iterate over the logs - * - * The #TplLogWalker object allows the user to sequentially iterate - * over the logs. - * - * <example> - * <title>Using a TplLogWalker to fetch text events from the logs.</title> - * <programlisting> - * #include <telepathy-glib/telepathy-glib.h> - * #include <telepathy-logger/telepathy-logger.h> - * - * static GMainLoop * loop = NULL; - * - * static void - * events_foreach (gpointer data, gpointer user_data) - * { - * TplEvent *event = TPL_EVENT (data); - * const gchar *message; - * gint64 timestamp; - * - * timestamp = tpl_event_get_timestamp (event); - * message = tpl_text_event_get_message (TPL_TEXT_EVENT (event)); - * g_message ("%" G_GINT64_FORMAT " %s", timestamp, message); - * } - * - * static void - * log_walker_get_events_cb (GObject *source_object, - * GAsyncResult *res, - * gpointer user_data) - * { - * TplLogWalker *walker = TPL_LOG_WALKER (source_object); - * GList *events; - * - * if (!tpl_log_walker_get_events_finish (walker, res, &events, NULL)) - * { - * g_main_loop_quit (loop); - * return; - * } - * - * g_list_foreach (events, events_foreach, NULL); - * g_list_free_full (events, g_object_unref); - * if (tpl_log_walker_is_end (walker)) - * { - * g_main_loop_quit (loop); - * return; - * } - * - * g_message (""); - * tpl_log_walker_get_events_async (walker, - * 5, - * log_walker_get_events_cb, - * NULL); - * } - * - * static void - * accounts_foreach (gpointer data, gpointer user_data) - * { - * TpAccount **account_out = (TpAccount **) user_data; - * TpAccount *account = TP_ACCOUNT (data); - * const gchar *display_name; - * - * display_name = tp_account_get_display_name (account); - * if (0 != g_strcmp0 (display_name, "alice@bar.net")) - * return; - * - * g_object_ref (account); - * *account_out = account; - * } - * - * static void - * account_manager_prepare_cb (GObject * source_object, - * GAsyncResult * res, - * gpointer user_data) - * { - * TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object); - * GList *accounts; - * TpAccount *account = NULL; - * TplLogManager *log_manager; - * TplLogWalker *walker; - * TplEntity *target; - * - * if (!tp_proxy_prepare_finish (source_object, res, NULL)) - * return; - * - * accounts = tp_account_manager_dup_usable_accounts (account_manager); - * g_list_foreach (accounts, accounts_foreach, &account); - * g_list_free_full (accounts, g_object_unref); - * if (account == NULL) - * { - * g_main_loop_quit (loop); - * return; - * } - * - * log_manager = tpl_log_manager_dup_singleton (); - * - * target = tpl_entity_new ("bob@foo.net", TPL_ENTITY_CONTACT, NULL, NULL); - * - * walker = tpl_log_manager_walk_filtered_events (log_manager, - * account, - * target, - * TPL_EVENT_MASK_TEXT, - * NULL, - * NULL); - * - * tpl_log_walker_get_events_async (walker, - * 5, - * log_walker_get_events_cb, - * NULL); - * - * g_object_unref (walker); - * g_object_unref (target); - * g_object_unref (log_manager); - * g_object_unref (account); - * } - * - * int - * main (int argc, - * char *argv[]) - * { - * GQuark features[] = { TP_ACCOUNT_MANAGER_FEATURE_CORE, 0 }; - * TpAccountManager * account_manager; - * - * g_type_init (); - * loop = g_main_loop_new (NULL, FALSE); - * - * account_manager = tp_account_manager_dup (); - * tp_proxy_prepare_async (account_manager, - * features, - * account_manager_prepare_cb, - * NULL); - * - * g_main_loop_run (loop); - * - * g_object_unref (account_manager); - * g_main_loop_unref (loop); - * return 0; - * } - * </programlisting> - * </example> - * - * Since: 0.8.0 - */ - -/** - * TplLogWalker: - * - * An object used to iterate over the logs - * - * Since: 0.8.0 - */ - -struct _TplLogWalkerPriv -{ - GList *caches; - GList *history; - GList *iters; - GQueue *queue; - TplLogEventFilter filter; - gboolean is_start; - gboolean is_end; - gpointer filter_data; -}; - -enum -{ - PROP_FILTER = 1, - PROP_FILTER_DATA -}; - - -G_DEFINE_TYPE (TplLogWalker, tpl_log_walker, G_TYPE_OBJECT); - - -static const gsize CACHE_SIZE = 5; - -typedef enum -{ - TPL_LOG_WALKER_OP_GET_EVENTS, - TPL_LOG_WALKER_OP_REWIND -} TplLogWalkerOpType; - -typedef struct -{ - GAsyncReadyCallback cb; - GList *events; - GList *fill_cache; - GList *fill_iter; - GList *latest_cache; - GList *latest_event; - GList *latest_iter; - TplLogWalkerOpType op_type; - gint64 latest_timestamp; - guint num_events; -} TplLogWalkerAsyncData; - -typedef struct -{ - TplLogIter *iter; - gboolean skip; - guint count; -} TplLogWalkerHistoryData; - -static void tpl_log_walker_op_run (TplLogWalker *walker); - - -static TplLogWalkerAsyncData * -tpl_log_walker_async_data_new (void) -{ - return g_slice_new0 (TplLogWalkerAsyncData); -} - - -static void -tpl_log_walker_async_data_free (TplLogWalkerAsyncData *data) -{ - g_list_free_full (data->events, g_object_unref); - g_slice_free (TplLogWalkerAsyncData, data); -} - - -static TplLogWalkerHistoryData * -tpl_log_walker_history_data_new (void) -{ - return g_slice_new0 (TplLogWalkerHistoryData); -} - - -static void -tpl_log_walker_history_data_free (TplLogWalkerHistoryData *data) -{ - g_object_unref (data->iter); - g_slice_free (TplLogWalkerHistoryData, data); -} - - -static void -tpl_log_walker_async_operation_cb (GObject *source_object, - GAsyncResult *result, - gpointer user_data) -{ - TplLogWalker *walker; - TplLogWalkerPriv *priv; - GSimpleAsyncResult *simple; - TplLogWalkerAsyncData *async_data; - - walker = TPL_LOG_WALKER (source_object); - priv = walker->priv; - - simple = G_SIMPLE_ASYNC_RESULT (result); - async_data = (TplLogWalkerAsyncData *) - g_simple_async_result_get_op_res_gpointer (simple); - - if (async_data->cb) - async_data->cb (source_object, result, user_data); - - g_object_unref (g_queue_pop_head (priv->queue)); - tpl_log_walker_op_run (walker); -} - - -static void -tpl_log_walker_caches_free_func (gpointer data) -{ - g_list_free_full ((GList *) data, g_object_unref); -} - - -static void -tpl_log_walker_fill_cache_async_thread (GSimpleAsyncResult *simple, - GObject *object, - GCancellable *cancellable) -{ - GError *error = NULL; - TplLogWalkerAsyncData *async_data; - - async_data = (TplLogWalkerAsyncData *) - g_simple_async_result_get_op_res_gpointer (simple); - - async_data->fill_cache->data = tpl_log_iter_get_events ( - TPL_LOG_ITER (async_data->fill_iter->data), CACHE_SIZE, &error); - - if (error != NULL) - g_simple_async_result_take_error (simple, error); -} - - -static void -tpl_log_walker_fill_cache_async (TplLogWalker *walker, - GList *cache, - GList *iter, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GSimpleAsyncResult *simple; - TplLogWalkerAsyncData *async_data; - - g_return_if_fail (TPL_IS_LOG_WALKER (walker)); - - async_data = tpl_log_walker_async_data_new (); - async_data->fill_cache = cache; - async_data->fill_iter = iter; - - simple = g_simple_async_result_new (G_OBJECT (walker), callback, user_data, - tpl_log_walker_fill_cache_async); - - g_simple_async_result_set_op_res_gpointer (simple, async_data, - (GDestroyNotify) tpl_log_walker_async_data_free); - - g_simple_async_result_run_in_thread (simple, - tpl_log_walker_fill_cache_async_thread, G_PRIORITY_DEFAULT, - NULL); - - g_object_unref (simple); -} - - -static gboolean -tpl_log_walker_fill_cache_finish (TplLogWalker *walker, - GAsyncResult *result, - GError **error) -{ - GSimpleAsyncResult *simple; - - g_return_val_if_fail (TPL_IS_LOG_WALKER (walker), FALSE); - g_return_val_if_fail (g_simple_async_result_is_valid (result, - G_OBJECT (walker), tpl_log_walker_fill_cache_async), FALSE); - - simple = G_SIMPLE_ASYNC_RESULT (result); - - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - - return TRUE; -} - - -static void -tpl_log_walker_get_events (GObject *source_object, - GAsyncResult *result, - gpointer user_data) -{ - GSimpleAsyncResult *simple; - TplLogWalker *walker; - TplLogWalkerPriv *priv; - TplLogWalkerAsyncData *async_data; - guint i; - - walker = TPL_LOG_WALKER (source_object); - priv = walker->priv; - - simple = G_SIMPLE_ASYNC_RESULT (user_data); - async_data = (TplLogWalkerAsyncData *) - g_simple_async_result_get_op_res_gpointer (simple); - - /* If we are returning from a prior call to - * tpl_log_walker_fill_cache_async then finish it. - */ - if (result != NULL) - tpl_log_walker_fill_cache_finish (walker, result, NULL); - - if (priv->is_end == TRUE) - goto out; - - i = g_list_length (async_data->events); - - while (i < async_data->num_events && priv->is_end == FALSE) - { - GList *cache; - GList *iter; - - /* Continue the loop from where we left, or start from the - * beginning as the case maybe. - */ - - cache = (async_data->fill_cache != NULL) ? - async_data->fill_cache : priv->caches; - - iter = (async_data->fill_iter != NULL) ? - async_data->fill_iter : priv->iters; - - for (; cache != NULL && iter != NULL; - cache = g_list_next (cache), iter = g_list_next (iter)) - { - GList *event; - gint64 timestamp; - - if (cache->data == NULL) - { - /* If the cache could not be filled, then the store - * must be empty. - */ - if (cache == async_data->fill_cache) - continue; - - /* Otherwise, try to fill it up. */ - async_data->fill_cache = cache; - async_data->fill_iter = iter; - tpl_log_walker_fill_cache_async (walker, cache, iter, - tpl_log_walker_get_events, simple); - return; - } - - event = g_list_last (cache->data); - timestamp = tpl_event_get_timestamp (TPL_EVENT (event->data)); - if (timestamp > async_data->latest_timestamp) - { - async_data->latest_cache = cache; - async_data->latest_event = event; - async_data->latest_iter = iter; - async_data->latest_timestamp = timestamp; - } - } - - /* These are used to maintain the continuity of the for loop - * which can get interrupted by the calls to - * tpl_log_walker_fill_cache_async(). Now that we are out of the - * loop we should reset them. - */ - async_data->fill_cache = NULL; - async_data->fill_iter = NULL; - async_data->latest_timestamp = 0; - - if (async_data->latest_event != NULL) - { - TplEvent *event; - TplLogWalkerHistoryData *data; - gboolean skip; - - event = async_data->latest_event->data; - skip = TRUE; - - if (priv->filter == NULL || - (*priv->filter) (event, priv->filter_data)) - { - async_data->events = g_list_prepend (async_data->events, event); - i++; - skip = FALSE; - } - - async_data->latest_cache->data = g_list_delete_link ( - async_data->latest_cache->data, async_data->latest_event); - - data = (priv->history != NULL) ? - (TplLogWalkerHistoryData *) priv->history->data : NULL; - - if (data == NULL || - data->iter != async_data->latest_iter->data || - data->skip != skip) - { - data = tpl_log_walker_history_data_new (); - data->iter = g_object_ref (async_data->latest_iter->data); - data->skip = skip; - priv->history = g_list_prepend (priv->history, data); - } - - data->count++; - - /* Now that the event has been inserted into the list we can - * forget about it. - */ - async_data->latest_event = NULL; - } - else - priv->is_end = TRUE; - } - - /* We are still at the beginning if all the log stores were empty. */ - if (priv->history != NULL) - priv->is_start = FALSE; - - out: - g_simple_async_result_complete_in_idle (simple); -} - - -static void -tpl_log_walker_rewind (TplLogWalker *walker, - guint num_events, - GError **error) -{ - TplLogWalkerPriv *priv; - GList *k; - GList *l; - guint i; - - g_return_if_fail (TPL_IS_LOG_WALKER (walker)); - - priv = walker->priv; - i = 0; - - if (priv->is_start == TRUE || num_events == 0) - return; - - priv->is_end = FALSE; - - for (k = priv->caches, l = priv->iters; - k != NULL && l != NULL; - k = g_list_next (k), l = g_list_next (l)) - { - GList **cache; - TplLogIter *iter; - guint length; - - cache = (GList **) &k->data; - iter = TPL_LOG_ITER (l->data); - - /* Flush the cache. */ - length = g_list_length (*cache); - tpl_log_iter_rewind (iter, length, error); - g_list_free_full (*cache, g_object_unref); - *cache = NULL; - } - - while (i < num_events && priv->is_start == FALSE) - { - TplLogWalkerHistoryData *data; - - data = (TplLogWalkerHistoryData *) priv->history->data; - tpl_log_iter_rewind (data->iter, 1, error); - data->count--; - if (!data->skip) - i++; - - if (data->count == 0) - { - tpl_log_walker_history_data_free (data); - priv->history = g_list_delete_link (priv->history, priv->history); - if (priv->history == NULL) - priv->is_start = TRUE; - } - } -} - - -static void -tpl_log_walker_rewind_async_thread (GSimpleAsyncResult *simple, - GObject *object, - GCancellable *cancellable) -{ - GError *error = NULL; - TplLogWalkerAsyncData *async_data; - - async_data = (TplLogWalkerAsyncData *) - g_simple_async_result_get_op_res_gpointer (simple); - - tpl_log_walker_rewind (TPL_LOG_WALKER (object), - async_data->num_events, &error); - - if (error != NULL) - g_simple_async_result_take_error (simple, error); -} - - -static void -tpl_log_walker_op_run (TplLogWalker *walker) -{ - TplLogWalkerPriv *priv; - GSimpleAsyncResult *simple; - TplLogWalkerAsyncData *async_data; - - priv = walker->priv; - - if (g_queue_is_empty (priv->queue)) - return; - - simple = G_SIMPLE_ASYNC_RESULT (g_queue_peek_head (priv->queue)); - async_data = (TplLogWalkerAsyncData *) - g_simple_async_result_get_op_res_gpointer (simple); - - switch (async_data->op_type) - { - case TPL_LOG_WALKER_OP_GET_EVENTS: - tpl_log_walker_get_events (G_OBJECT (walker), NULL, simple); - break; - - case TPL_LOG_WALKER_OP_REWIND: - g_simple_async_result_run_in_thread (simple, - tpl_log_walker_rewind_async_thread, G_PRIORITY_DEFAULT, NULL); - break; - } -} - - -static void -tpl_log_walker_dispose (GObject *object) -{ - TplLogWalkerPriv *priv; - - priv = TPL_LOG_WALKER (object)->priv; - - g_list_free_full (priv->caches, tpl_log_walker_caches_free_func); - priv->caches = NULL; - - g_list_free_full (priv->history, - (GDestroyNotify) tpl_log_walker_history_data_free); - priv->history = NULL; - - g_list_free_full (priv->iters, g_object_unref); - priv->iters = NULL; - - G_OBJECT_CLASS (tpl_log_walker_parent_class)->dispose (object); -} - - -static void -tpl_log_walker_finalize (GObject *object) -{ - TplLogWalkerPriv *priv; - - priv = TPL_LOG_WALKER (object)->priv; - g_queue_free_full (priv->queue, g_object_unref); - - G_OBJECT_CLASS (tpl_log_walker_parent_class)->finalize (object); -} - - -static void -tpl_log_walker_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - TplLogWalkerPriv *priv; - - priv = TPL_LOG_WALKER (object)->priv; - - switch (param_id) - { - case PROP_FILTER: - g_value_set_pointer (value, priv->filter); - break; - - case PROP_FILTER_DATA: - g_value_set_pointer (value, priv->filter_data); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - - -static void -tpl_log_walker_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - TplLogWalkerPriv *priv; - - priv = TPL_LOG_WALKER (object)->priv; - - switch (param_id) - { - case PROP_FILTER: - priv->filter = g_value_get_pointer (value); - break; - - case PROP_FILTER_DATA: - priv->filter_data = g_value_get_pointer (value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - - -static void -tpl_log_walker_init (TplLogWalker *walker) -{ - TplLogWalkerPriv *priv; - - walker->priv = G_TYPE_INSTANCE_GET_PRIVATE (walker, TPL_TYPE_LOG_WALKER, - TplLogWalkerPriv); - priv = walker->priv; - - priv->queue = g_queue_new (); - priv->is_start = TRUE; - priv->is_end = FALSE; -} - - -static void -tpl_log_walker_class_init (TplLogWalkerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GParamSpec *param_spec; - - object_class->dispose = tpl_log_walker_dispose; - object_class->finalize = tpl_log_walker_finalize; - object_class->get_property = tpl_log_walker_get_property; - object_class->set_property = tpl_log_walker_set_property; - - param_spec = g_param_spec_pointer ("filter", - "Filter", - "An optional filter function", - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_FILTER, param_spec); - - param_spec = g_param_spec_pointer ("filter-data", - "Filter Data", - "User data to pass to the filter function", - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_FILTER_DATA, param_spec); - - g_type_class_add_private (klass, sizeof (TplLogWalkerPriv)); -} - - -TplLogWalker * -tpl_log_walker_new (TplLogEventFilter filter, gpointer filter_data) -{ - return g_object_new (TPL_TYPE_LOG_WALKER, - "filter", filter, - "filter-data", filter_data, - NULL); -} - - -void -tpl_log_walker_add_iter (TplLogWalker *walker, TplLogIter *iter) -{ - TplLogWalkerPriv *priv; - - g_return_if_fail (TPL_IS_LOG_WALKER (walker)); - g_return_if_fail (TPL_IS_LOG_ITER (iter)); - - priv = walker->priv; - - priv->iters = g_list_prepend (priv->iters, g_object_ref (iter)); - priv->caches = g_list_prepend (priv->caches, NULL); -} - - -/** - * tpl_log_walker_get_events_async: - * @walker: a #TplLogWalker - * @num_events: number of maximum events to fetch - * @callback: (scope async) (allow-none): a callback to call when - * the request is satisfied - * @user_data: data to pass to @callback - * - * Walk the logs to retrieve the next most recent @num_event events. - * - * Since: 0.8.0 - */ -void -tpl_log_walker_get_events_async (TplLogWalker *walker, - guint num_events, - GAsyncReadyCallback callback, - gpointer user_data) -{ - TplLogWalkerPriv *priv; - GSimpleAsyncResult *simple; - TplLogWalkerAsyncData *async_data; - - g_return_if_fail (TPL_IS_LOG_WALKER (walker)); - - priv = walker->priv; - - async_data = tpl_log_walker_async_data_new (); - async_data->cb = callback; - async_data->num_events = num_events; - async_data->op_type = TPL_LOG_WALKER_OP_GET_EVENTS; - - simple = g_simple_async_result_new (G_OBJECT (walker), - tpl_log_walker_async_operation_cb, user_data, - tpl_log_walker_get_events_async); - - g_simple_async_result_set_op_res_gpointer (simple, async_data, - (GDestroyNotify) tpl_log_walker_async_data_free); - - g_queue_push_tail (priv->queue, g_object_ref (simple)); - if (g_queue_get_length (priv->queue) == 1) - tpl_log_walker_op_run (walker); - - g_object_unref (simple); -} - - -/** - * tpl_log_walker_get_events_finish: - * @walker: a #TplLogWalker - * @result: a #GAsyncResult - * @events: (out) (transfer full) (element-type TelepathyLogger1.Event): - * a pointer to a #GList used to return the list #TplEvent - * @error: a #GError to fill - * - * Returns: #TRUE if the operation was successful, otherwise #FALSE. - * - * Since: 0.8.0 - */ -gboolean -tpl_log_walker_get_events_finish (TplLogWalker *walker, - GAsyncResult *result, - GList **events, - GError **error) -{ - GSimpleAsyncResult *simple; - TplLogWalkerAsyncData *async_data; - - g_return_val_if_fail (TPL_IS_LOG_WALKER (walker), FALSE); - g_return_val_if_fail (g_simple_async_result_is_valid (result, - G_OBJECT (walker), tpl_log_walker_get_events_async), FALSE); - - simple = G_SIMPLE_ASYNC_RESULT (result); - async_data = (TplLogWalkerAsyncData *) - g_simple_async_result_get_op_res_gpointer (simple); - - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - - if (events != NULL) - { - *events = async_data->events; - async_data->events = NULL; - } - - return TRUE; -} - - -/** - * tpl_log_walker_rewind_async: - * @walker: a #TplLogWalker - * @num_events: number of events to move back - * @callback: (scope async) (allow-none): a callback to call when - * the request is satisfied - * @user_data: data to pass to @callback - * - * Move the @walker back by the last @num_event events that were - * returned by tpl_log_walker_get_events_async(). - * - * Since: 0.8.0 - */ -void -tpl_log_walker_rewind_async (TplLogWalker *walker, - guint num_events, - GAsyncReadyCallback callback, - gpointer user_data) -{ - TplLogWalkerPriv *priv; - GSimpleAsyncResult *simple; - TplLogWalkerAsyncData *async_data; - - g_return_if_fail (TPL_IS_LOG_WALKER (walker)); - - priv = walker->priv; - - async_data = tpl_log_walker_async_data_new (); - async_data->cb = callback; - async_data->num_events = num_events; - async_data->op_type = TPL_LOG_WALKER_OP_REWIND; - - simple = g_simple_async_result_new (G_OBJECT (walker), - tpl_log_walker_async_operation_cb, user_data, - tpl_log_walker_rewind_async); - - g_simple_async_result_set_op_res_gpointer (simple, async_data, - (GDestroyNotify) tpl_log_walker_async_data_free); - - g_queue_push_tail (priv->queue, g_object_ref (simple)); - if (g_queue_get_length (priv->queue) == 1) - tpl_log_walker_op_run (walker); - - g_object_unref (simple); -} - - -/** - * tpl_log_walker_rewind_finish: - * @walker: a #TplLogWalker - * @result: a #GAsyncResult - * @error: a #GError to fill - * - * Returns: #TRUE if the operation was successful, otherwise #FALSE. - * - * Since: 0.8.0 - */ -gboolean -tpl_log_walker_rewind_finish (TplLogWalker *walker, - GAsyncResult *result, - GError **error) -{ - GSimpleAsyncResult *simple; - - g_return_val_if_fail (TPL_IS_LOG_WALKER (walker), FALSE); - g_return_val_if_fail (g_simple_async_result_is_valid (result, - G_OBJECT (walker), tpl_log_walker_rewind_async), FALSE); - - simple = G_SIMPLE_ASYNC_RESULT (result); - - if (g_simple_async_result_propagate_error (simple, error)) - return FALSE; - - return TRUE; -} - - -/** - * tpl_log_walker_is_start: - * @walker: a #TplLogWalker - * - * Determines whether @walker is pointing at the most recent event in - * the logs. This is the case when @walker has not yet returned any - * events or has been rewound completely. - * - * Returns: #TRUE if @walker is pointing at the most recent event, - * otherwise #FALSE. - * - * Since: 0.8.0 - */ -gboolean -tpl_log_walker_is_start (TplLogWalker *walker) -{ - TplLogWalkerPriv *priv; - - priv = walker->priv; - return priv->is_start; -} - - -/** - * tpl_log_walker_is_end: - * @walker: a #TplLogWalker - * - * Determines whether @walker has run out of events. This is the case - * when @walker has returned all the events from the logs. - * - * Returns: #TRUE if @walker has run out of events, otherwise #FALSE. - * - * Since: 0.8.0 - */ -gboolean -tpl_log_walker_is_end (TplLogWalker *walker) -{ - TplLogWalkerPriv *priv; - - priv = walker->priv; - return priv->is_end; -} diff --git a/telepathy-logger/log-walker.h b/telepathy-logger/log-walker.h deleted file mode 100644 index b341dc6..0000000 --- a/telepathy-logger/log-walker.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2012 Red Hat, Inc. - * - * 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 - * - * Author: Debarshi Ray <debarshir@freedesktop.org> - */ - -#ifndef __TPL_LOG_WALKER_H__ -#define __TPL_LOG_WALKER_H__ - -#include <glib-object.h> -#include <gio/gio.h> - -G_BEGIN_DECLS - -#define TPL_TYPE_LOG_WALKER (tpl_log_walker_get_type ()) - -#define TPL_LOG_WALKER(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - TPL_TYPE_LOG_WALKER, TplLogWalker)) - -#define TPL_LOG_WALKER_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), \ - TPL_TYPE_LOG_WALKER, TplLogWalkerClass)) - -#define TPL_IS_LOG_WALKER(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - TPL_TYPE_LOG_WALKER)) - -#define TPL_IS_LOG_WALKER_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), \ - TPL_TYPE_LOG_WALKER)) - -#define TPL_LOG_WALKER_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), \ - TPL_TYPE_LOG_WALKER, TplLogWalkerClass)) - -typedef struct _TplLogWalker TplLogWalker; -typedef struct _TplLogWalkerClass TplLogWalkerClass; -typedef struct _TplLogWalkerPriv TplLogWalkerPriv; - -struct _TplLogWalker -{ - GObject parent_instance; - TplLogWalkerPriv *priv; -}; - -struct _TplLogWalkerClass -{ - /*< private >*/ - GObjectClass parent_class; -}; - -GType tpl_log_walker_get_type (void) G_GNUC_CONST; - -void tpl_log_walker_get_events_async (TplLogWalker *walker, - guint num_events, - GAsyncReadyCallback callback, - gpointer user_data); - -gboolean tpl_log_walker_get_events_finish (TplLogWalker *walker, - GAsyncResult *result, - GList **events, - GError **error); - -void tpl_log_walker_rewind_async (TplLogWalker *walker, - guint num_events, - GAsyncReadyCallback callback, - gpointer user_data); - -gboolean tpl_log_walker_rewind_finish (TplLogWalker *walker, - GAsyncResult *result, - GError **error); - -gboolean tpl_log_walker_is_start (TplLogWalker *walker); - -gboolean tpl_log_walker_is_end (TplLogWalker *walker); - -G_END_DECLS - -#endif /* __TPL_LOG_WALKER_H__ */ diff --git a/telepathy-logger/observer-internal.h b/telepathy-logger/observer-internal.h deleted file mode 100644 index a0f1acf..0000000 --- a/telepathy-logger/observer-internal.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2009 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: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - */ - -#ifndef __TPL_OBSERVER_H__ -#define __TPL_OBSERVER_H__ - -#include <glib-object.h> - -#include <telepathy-glib/telepathy-glib.h> - -#define TPL_OBSERVER_WELL_KNOWN_BUS_NAME \ - "im.telepathy1.Client.Logger" -#define TPL_OBSERVER_OBJECT_PATH \ - "/im.telepathy1/Client/Logger" - - -G_BEGIN_DECLS -#define TPL_TYPE_OBSERVER (_tpl_observer_get_type ()) -#define TPL_OBSERVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_OBSERVER, TplObserver)) -#define TPL_OBSERVER_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), TPL_TYPE_OBSERVER, TplObserverClass)) -#define TPL_IS_OBSERVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_OBSERVER)) -#define TPL_IS_OBSERVER_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), TPL_TYPE_OBSERVER)) -#define TPL_OBSERVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_OBSERVER, TplObserverClass)) - -typedef struct _TplObserverPriv TplObserverPriv; - -typedef struct -{ - TpBaseClient parent; - - /* private */ - TplObserverPriv *priv; -} TplObserver; - -typedef struct -{ - TpBaseClientClass parent_class; -} TplObserverClass; - -GType _tpl_observer_get_type (void); - -TplObserver * _tpl_observer_dup (GError **error); - -gboolean _tpl_observer_unregister_channel (TplObserver *self, - TpChannel *channel); - - -G_END_DECLS -#endif // __TPL_OBSERVER_H__ diff --git a/telepathy-logger/observer.c b/telepathy-logger/observer.c deleted file mode 100644 index 7307ffb..0000000 --- a/telepathy-logger/observer.c +++ /dev/null @@ -1,363 +0,0 @@ -/* - * Copyright (C) 2009 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: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - */ - -#include "config.h" -#include "observer-internal.h" - -#include <glib.h> -#include <telepathy-glib/telepathy-glib.h> -#include <telepathy-glib/telepathy-glib-dbus.h> - -#include <telepathy-logger/log-manager.h> - -#define DEBUG_FLAG TPL_DEBUG_OBSERVER -#include <telepathy-logger/action-chain-internal.h> -#include <telepathy-logger/client-factory-internal.h> -#include <telepathy-logger/debug-internal.h> -#include <telepathy-logger/util-internal.h> - -/* - * SECTION:observer - * @title: TplObserver - * @short_description: TPL Observer main class, used to handle received - * signals - * @see_also: #TpSvcClientObserver - * - * The Telepathy Logger's Observer implements - * im.telepathy1.Client.Observer DBus interface and is called by - * the Channel Dispatcher when a new channel is created, in order to log - * received signals. - * - * Since: 0.1 - */ - -/** - * TplObserver: - * - * The Telepathy Logger's Observer implements - * im.telepathy1.Client.Observer DBus interface and is called by - * the Channel Dispatcher when a new channel is created, in order to log - * received signals using its #LogManager. - * - * This object is a signleton, any call to tpl_observer_new will return the - * same object with an incremented reference counter. One has to - * unreference the object properly when the used reference is not used - * anymore. - * - * This object will register to it's DBus interface when - * tp_base_client_register is called, ensuring that the registration will - * happen only once per singleton instance. - * - * Since: 0.1 - */ - -/** - * TplObserverClass: - * - * The class of a #TplObserver. - */ - -static void tpl_observer_dispose (GObject * obj); -static gboolean _tpl_observer_register_channel (TplObserver *self, - TpChannel *channel); - -struct _TplObserverPriv -{ - /* Registered channels - * channel path borrowed from the TplChannel => reffed TplChannel */ - GHashTable *channels; - TplLogManager *logmanager; - gboolean dbus_registered; -}; - -typedef struct -{ - TplObserver *self; - guint chan_n; - TpObserveChannelsContext *ctx; -} ObservingContext; - -static TplObserver *observer_singleton = NULL; - -enum -{ - PROP_0, - PROP_REGISTERED_CHANNELS -}; - -G_DEFINE_TYPE (TplObserver, _tpl_observer, TP_TYPE_BASE_CLIENT) - -static void -tpl_observer_observe_channels (TpBaseClient *client, - TpAccount *account, - TpConnection *connection, - GList *channels, - TpChannelDispatchOperation *dispatch_operation, - GList *requests, - TpObserveChannelsContext *context) -{ - TplObserver *self = TPL_OBSERVER (client); - GList *l; - - for (l = channels; l != NULL; l = g_list_next (l)) - _tpl_observer_register_channel (self, l->data); - - tp_observe_channels_context_accept (context); -} - -static gboolean -_tpl_observer_register_channel (TplObserver *self, - TpChannel *channel) -{ - gchar *key; - - g_return_val_if_fail (TPL_IS_OBSERVER (self), FALSE); - g_return_val_if_fail (TP_IS_CHANNEL (channel), FALSE); - - key = (char *) tp_proxy_get_object_path (G_OBJECT (channel)); - - DEBUG ("Registering channel %s", key); - - g_hash_table_insert (self->priv->channels, key, g_object_ref (channel)); - g_object_notify (G_OBJECT (self), "registered-channels"); - - return TRUE; -} - - -static void -tpl_observer_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - TplObserver *self = TPL_OBSERVER (object); - - switch (property_id) - { - case PROP_REGISTERED_CHANNELS: - { - GPtrArray *array = g_ptr_array_new (); - GList *keys, *ptr; - - keys = g_hash_table_get_keys (self->priv->channels); - - for (ptr = keys; ptr != NULL; ptr = ptr->next) - { - g_ptr_array_add (array, ptr->data); - } - - g_value_set_boxed (value, array); - - g_ptr_array_unref (array); - g_list_free (keys); - - break; - } - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (self, property_id, pspec); - break; - } -} - -static void -_tpl_observer_class_init (TplObserverClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - TpBaseClientClass *base_clt_cls = TP_BASE_CLIENT_CLASS (klass); - - object_class->dispose = tpl_observer_dispose; - object_class->get_property = tpl_observer_get_property; - - /** - * TplObserver:registered-channels: - * - * A list of channel's paths currently registered to this object. - * - * One can receive change notifications on this property by connecting - * to the #GObject::notify signal and using this property as the signal - * detail. - */ - g_object_class_install_property (object_class, PROP_REGISTERED_CHANNELS, - g_param_spec_boxed ("registered-channels", - "Registered Channels", - "open TpChannels which the TplObserver is logging", - TP_ARRAY_TYPE_OBJECT_PATH_LIST, - G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - - g_type_class_add_private (object_class, sizeof (TplObserverPriv)); - - tp_base_client_implement_observe_channels (base_clt_cls, - tpl_observer_observe_channels); -} - -static void -_tpl_observer_init (TplObserver *self) -{ - TplObserverPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - TPL_TYPE_OBSERVER, TplObserverPriv); - self->priv = priv; - - priv->channels = g_hash_table_new_full (g_str_hash, g_str_equal, - NULL, g_object_unref); - - priv->logmanager = tpl_log_manager_dup_singleton (); - - /* Observe contact text channels */ - tp_base_client_take_observer_filter (TP_BASE_CLIENT (self), - tp_asv_new ( - TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, - TP_IFACE_CHANNEL_TYPE_TEXT, - TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, - TP_HANDLE_TYPE_CONTACT, - NULL)); - - /* Observe room text channels */ - tp_base_client_take_observer_filter (TP_BASE_CLIENT (self), - tp_asv_new ( - TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, - TP_IFACE_CHANNEL_TYPE_TEXT, - TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, - TP_HANDLE_TYPE_ROOM, - NULL)); - - /* Observe contact call channels */ - tp_base_client_take_observer_filter (TP_BASE_CLIENT (self), - tp_asv_new ( - TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, - "im.telepathy1.Channel.Type.Call1", - TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, - TP_HANDLE_TYPE_CONTACT, - NULL)); - - /* Observe room call channels */ - tp_base_client_take_observer_filter (TP_BASE_CLIENT (self), - tp_asv_new ( - TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, - "im.telepathy1.Channel.Type.Call1", - TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, - TP_HANDLE_TYPE_ROOM, - NULL)); - - tp_base_client_set_observer_recover (TP_BASE_CLIENT (self), TRUE); -} - - -static void -tpl_observer_dispose (GObject *obj) -{ - TplObserverPriv *priv = TPL_OBSERVER (obj)->priv; - - tp_clear_pointer (&priv->channels, g_hash_table_unref); - g_clear_object (&priv->logmanager); - - G_OBJECT_CLASS (_tpl_observer_parent_class)->dispose (obj); -} - - -TplObserver * -_tpl_observer_dup (GError **error) -{ - /* WARNING Not thread safe */ - if (G_UNLIKELY (observer_singleton == NULL)) - { - GError *dbus_error = NULL; - TpDBusDaemon *dbus = tp_dbus_daemon_dup (&dbus_error); - TpClientFactory *factory; - - if (dbus == NULL) - { - g_propagate_error (error, dbus_error); - return NULL; - } - - factory = _tpl_client_factory_dup (dbus); - - /* Pre-select feature to be initialized. */ - tp_client_factory_add_contact_features_varargs (factory, - TP_CONTACT_FEATURE_ALIAS, - TP_CONTACT_FEATURE_PRESENCE, - TP_CONTACT_FEATURE_AVATAR_TOKEN, - 0); - - observer_singleton = g_object_new (TPL_TYPE_OBSERVER, - "factory", factory, - "name", "Logger", - "uniquify-name", FALSE, - NULL); - - g_object_add_weak_pointer (G_OBJECT (observer_singleton), - (gpointer *) &observer_singleton); - - g_object_unref (dbus); - g_object_unref (factory); - } - else - { - g_object_ref (observer_singleton); - } - - return observer_singleton; -} - -/** - * _tpl_observer_unregister_channel: - * @self: #TplObserver instance, cannot be %NULL. - * @channel: a #TplChannel cast of a TplChannel subclass instance - * - * Un-registers a TplChannel subclass instance, i.e. TplTextChannel instance, - * as TplChannel instance. - * It is supposed to be called when the Closed signal for a channel is - * emitted or when an un-recoverable error during the life or a TplChannel - * happens. - * - * Every time that a channel is registered or unregistered, a notification is - * sent for the 'registered-channels' property. - * - * Returns: %TRUE if @channel is registered and can thus be un-registered or - * %FALSE if the @channel is not currently among registered channels and thus - * cannot be un-registered. - */ -gboolean -_tpl_observer_unregister_channel (TplObserver *self, - TpChannel *channel) -{ - gboolean retval; - gchar *key; - - g_return_val_if_fail (TPL_IS_OBSERVER (self), FALSE); - g_return_val_if_fail (TP_IS_CHANNEL (channel), FALSE); - - key = (char *) tp_proxy_get_object_path (TP_PROXY (channel)); - - DEBUG ("Unregistering channel path %s", key); - - /* this will destroy the associated value object: at this point - the hash table reference should be the only one for the - value's object - */ - retval = g_hash_table_remove (self->priv->channels, key); - - if (retval) - g_object_notify (G_OBJECT (self), "registered-channels"); - - return retval; -} diff --git a/telepathy-logger/telepathy-logger-1-uninstalled.pc.in b/telepathy-logger/telepathy-logger-1-uninstalled.pc.in deleted file mode 100644 index 2f993fd..0000000 --- a/telepathy-logger/telepathy-logger-1-uninstalled.pc.in +++ /dev/null @@ -1,11 +0,0 @@ -prefix= -exec_prefix= -abs_top_srcdir=@abs_top_srcdir@ -abs_top_builddir=@abs_top_builddir@ - -Name: Telepathy Logger library (uninstalled copy) -Description: Access to Telepathy logs -Requires: telepathy-glib-1 telepathy-glib-1-dbus libxml-2.0 -Version: @VERSION@ -Libs: ${abs_top_builddir}/telepathy-logger/libtelepathy-logger-1.la -Cflags: -I${abs_top_srcdir} -I${abs_top_builddir} diff --git a/telepathy-logger/telepathy-logger-1.pc.in b/telepathy-logger/telepathy-logger-1.pc.in deleted file mode 100644 index 3da2ce9..0000000 --- a/telepathy-logger/telepathy-logger-1.pc.in +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@/telepathy-logger-1 - -Name: Telepathy Logger library -Description: Access to Telepathy logs -Requires: telepathy-glib-1 telepathy-glib-1-dbus libxml-2.0 -Version: @VERSION@ -Libs: -L${libdir} -ltelepathy-logger-1 -Cflags: -I${includedir} diff --git a/telepathy-logger/telepathy-logger.h b/telepathy-logger/telepathy-logger.h deleted file mode 100644 index 54d42d8..0000000 --- a/telepathy-logger/telepathy-logger.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * telepathy-logger.h - Headers for telepathy-logger - * - * Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/> - * - * 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 - */ - -#ifndef __TELEPATHY_LOGGER_H__ -#define __TELEPATHY_LOGGER_H__ - -#include <telepathy-logger/entity.h> -#include <telepathy-logger/text-event.h> -#include <telepathy-logger/call-event.h> -#include <telepathy-logger/event.h> -#include <telepathy-logger/log-manager.h> -#include <telepathy-logger/log-walker.h> - -#endif diff --git a/telepathy-logger/text-channel-internal.h b/telepathy-logger/text-channel-internal.h deleted file mode 100644 index f4f7db5..0000000 --- a/telepathy-logger/text-channel-internal.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (C) 2009 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: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - */ - -#ifndef __TPL_TEXT_CHANNEL_H__ -#define __TPL_TEXT_CHANNEL_H__ - -/* - * http://telepathy.freedesktop.org/doc/telepathy-glib/telepathy-glib-channel-text.html#tp-cli-channel-type-text-connect-to-received - */ - -#include <glib-object.h> -#include <telepathy-glib/telepathy-glib.h> - -G_BEGIN_DECLS - -#define TPL_TYPE_TEXT_CHANNEL (_tpl_text_channel_get_type ()) -#define TPL_TEXT_CHANNEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_TEXT_CHANNEL, TplTextChannel)) -#define TPL_TEXT_CHANNEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TPL_TYPE_TEXT_CHANNEL, TplTextChannelClass)) -#define TPL_IS_TEXT_CHANNEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_TEXT_CHANNEL)) -#define TPL_IS_TEXT_CHANNEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TPL_TYPE_TEXT_CHANNEL)) -#define TPL_TEXT_CHANNEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_TEXT_CHANNEL, TplTextChannelClass)) - - -#define TPL_TEXT_CHANNEL_ERROR \ - g_quark_from_static_string ("tpl-text-channel-error-quark") - -typedef enum -{ - /* generic error */ - TPL_TEXT_CHANNEL_ERROR_FAILED, - TPL_TEXT_CHANNEL_ERROR_NEED_MESSAGE_INTERFACE, -} TplTextChannelError; - -#define TPL_TEXT_CHANNEL_FEATURE_CORE \ - _tpl_text_channel_get_feature_quark_core () -GQuark _tpl_text_channel_get_feature_quark_core (void) G_GNUC_CONST; - -typedef struct _TplTextChannelPriv TplTextChannelPriv; -typedef struct -{ - TpTextChannel parent; - - /* private */ - TplTextChannelPriv *priv; -} TplTextChannel; - -typedef struct -{ - TpTextChannelClass parent_class; -} TplTextChannelClass; - -GType _tpl_text_channel_get_type (void); - -TplTextChannel * _tpl_text_channel_new (TpConnection *conn, - const gchar *object_path, - GHashTable *tp_chan_props, - GError **error); - -TplTextChannel * _tpl_text_channel_new_with_factory ( - TpClientFactory *factory, - TpConnection *conn, - const gchar *object_path, - const GHashTable *tp_chan_props, - GError **error); - -G_END_DECLS -#endif /* __TPL_TEXT_CHANNEL_H__ */ diff --git a/telepathy-logger/text-channel.c b/telepathy-logger/text-channel.c deleted file mode 100644 index 1444df9..0000000 --- a/telepathy-logger/text-channel.c +++ /dev/null @@ -1,722 +0,0 @@ -/* - * Copyright (C) 2009-2011 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: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - * Nicolas Dufresne <nicolas.dufresne@collabora.co.uk> - */ - -#include "config.h" -#include "text-channel-internal.h" - -#include <glib.h> -#include <telepathy-glib/telepathy-glib.h> -#include <telepathy-glib/telepathy-glib-dbus.h> - -#include "action-chain-internal.h" -#include "entity-internal.h" -#include "event-internal.h" -#include "log-manager-internal.h" -#include "log-store-sqlite-internal.h" -#include "observer-internal.h" -#include "text-event.h" -#include "text-event-internal.h" -#include "util-internal.h" - -#define DEBUG_FLAG TPL_DEBUG_CHANNEL -#include "debug-internal.h" - -struct _TplTextChannelPriv -{ - TpAccount *account; - TplEntity *self; - gboolean is_chatroom; - TplEntity *remote; -}; - -G_DEFINE_TYPE (TplTextChannel, _tpl_text_channel, TP_TYPE_TEXT_CHANNEL) - - -static void -get_my_contact (TplTextChannel *self) -{ - TpChannel *chan = TP_CHANNEL (self); - TpConnection *tp_conn = tp_channel_get_connection (chan); - TpContact *my_contact; - - my_contact = tp_channel_group_get_self_contact (chan); - if (my_contact == 0) - my_contact = tp_connection_get_self_contact (tp_conn); - - self->priv->self = tpl_entity_new_from_tp_contact (my_contact, - TPL_ENTITY_SELF); -} - - -static void -get_remote_contact (TplTextChannel *self) -{ - TpChannel *chan = TP_CHANNEL (self); - TpContact *contact; - - contact = tp_channel_get_target_contact (chan); - - if (contact == NULL) - { - self->priv->is_chatroom = TRUE; - self->priv->remote = - tpl_entity_new_from_room_id (tp_channel_get_identifier (chan)); - - PATH_DEBUG (self, "Chatroom id: %s", - tpl_entity_get_identifier (self->priv->remote)); - } - else - { - self->priv->remote = - tpl_entity_new_from_tp_contact (contact, TPL_ENTITY_CONTACT); - } -} - - -static void -on_channel_invalidated_cb (TpProxy *proxy, - guint domain, - gint code, - gchar *message, - gpointer user_data) -{ - TpChannel *chan = TP_CHANNEL (user_data); - TplObserver *observer = _tpl_observer_dup (NULL); - - g_return_if_fail (observer); - - PATH_DEBUG (chan, "%s #%d %s", - g_quark_to_string (domain), code, message); - - if (!_tpl_observer_unregister_channel (observer, chan)) - PATH_DEBUG (chan, "Channel couldn't be unregistered correctly (BUG?)"); - - g_object_unref (observer); -} - - -static guint -get_message_pending_id (TpMessage *m) -{ - return tp_asv_get_uint32 (tp_message_peek (TP_MESSAGE (m), 0), - "pending-message-id", NULL); -} - - -static gint64 -get_original_message_timestamp (TpMessage *message) -{ - gint64 timestamp; - - timestamp = tp_asv_get_int64 (tp_message_peek (message, 0), - "original-message-sent", NULL); - - if (timestamp == 0) - timestamp = tp_asv_get_int64 (tp_message_peek (message, 0), - "original-message-received", NULL); - - return timestamp; -} - - -static gint64 -get_network_timestamp (TpMessage *message) -{ - GDateTime *datetime = g_date_time_new_now_utc (); - gint64 now = g_date_time_to_unix (datetime); - gint64 timestamp; - - timestamp = tp_message_get_sent_timestamp (message); - - if (timestamp == 0) - timestamp = tp_message_get_received_timestamp (message); - - if (timestamp == 0) - { - DEBUG ("TpMessage is not timestamped. Using current time instead."); - timestamp = now; - } - - if (timestamp - now > 60 * 60) - DEBUG ("timestamp is more than an hour in the future."); - else if (now - timestamp > 60 * 60) - DEBUG ("timestamp is more than an hour in the past."); - - g_date_time_unref (datetime); - - return timestamp; -} - - -static gint64 -get_message_edit_timestamp (TpMessage *message) -{ - if (tp_message_get_supersedes (message) != NULL) - return get_network_timestamp (message); - else - return 0; -} - - -static gint64 -get_message_timestamp (TpMessage *message) -{ - gint64 timestamp; - - timestamp = get_original_message_timestamp (message); - - if (timestamp == 0) - timestamp = get_network_timestamp (message); - - return timestamp; -} - - -static void -tpl_text_channel_store_message (TplTextChannel *self, - TpMessage *message, - TplEntity *sender, - TplEntity *receiver) -{ - TplTextChannelPriv *priv = self->priv; - const gchar *direction; - TpChannelTextMessageType type; - gint64 timestamp; - gchar *text; - TplTextEvent *event; - TplLogManager *logmanager; - GError *error = NULL; - - if (tpl_entity_get_entity_type (sender) == TPL_ENTITY_SELF) - direction = "sent"; - else - direction = "received"; - - if (tp_message_is_scrollback (message)) - { - DEBUG ("Ignoring %s scrollback message.", direction); - return; - } - - if (tp_message_is_rescued (message)) - { - DEBUG ("Ignoring %s rescued message.", direction); - return; - } - - type = tp_message_get_message_type (message); - - if (type == TP_CHANNEL_TEXT_MESSAGE_TYPE_DELIVERY_REPORT) - { - DEBUG ("Ignoring %s delivery report message.", direction); - return; - } - - /* Ensure timestamp */ - timestamp = get_message_timestamp (message); - - text = tp_message_to_text (message); - - if (text == NULL) - { - DEBUG ("Ignoring %s message with no supported content", direction); - return; - } - - if (tpl_entity_get_entity_type (sender) == TPL_ENTITY_SELF) - DEBUG ("Logging message sent to %s (%s)", - tpl_entity_get_alias (receiver), - tpl_entity_get_identifier (receiver)); - else - DEBUG ("Logging message received from %s (%s)", - tpl_entity_get_alias (sender), - tpl_entity_get_identifier (sender)); - - - /* Initialise TplTextEvent */ - event = g_object_new (TPL_TYPE_TEXT_EVENT, - /* TplEvent */ - "account", priv->account, - "channel-path", tp_proxy_get_object_path (TP_PROXY (self)), - "receiver", receiver, - "sender", sender, - "timestamp", timestamp, - "message-token", tp_message_get_token (message), - "supersedes-token", tp_message_get_supersedes (message), - "edit-timestamp", get_message_edit_timestamp (message), - /* TplTextEvent */ - "message-type", type, - "message", text, - NULL); - - /* Store sent event */ - logmanager = tpl_log_manager_dup_singleton (); - _tpl_log_manager_add_event (logmanager, TPL_EVENT (event), &error); - - if (error != NULL) - { - PATH_DEBUG (self, "LogStore: %s", error->message); - g_error_free (error); - } - else if (tpl_entity_get_entity_type (sender) != TPL_ENTITY_SELF) - { - TplLogStore *cache = _tpl_log_store_sqlite_dup (); - _tpl_log_store_sqlite_add_pending_message (cache, - TP_CHANNEL (self), - get_message_pending_id (message), - timestamp, - &error); - - if (error != NULL) - { - PATH_DEBUG (self, "Failed to cache pending message: %s", - error->message); - g_error_free (error); - } - } - - g_object_unref (logmanager); - g_object_unref (event); - g_free (text); -} - - -static void -on_message_received_cb (TpTextChannel *text_chan, - TpSignalledMessage *message, - gpointer user_data) -{ - TplTextChannel *self = TPL_TEXT_CHANNEL (text_chan); - TplTextChannelPriv *priv = self->priv; - TplEntity *receiver; - TplEntity *sender; - - if (priv->is_chatroom) - receiver = priv->remote; - else - receiver = priv->self; - - sender = tpl_entity_new_from_tp_contact ( - tp_signalled_message_get_sender (TP_MESSAGE (message)), - TPL_ENTITY_CONTACT); - - tpl_text_channel_store_message (self, TP_MESSAGE (message), - sender, receiver); - - g_object_unref (sender); -} - - -static void -on_message_sent_cb (TpChannel *proxy, - TpSignalledMessage *message, - guint flags, - const gchar *token, - gpointer user_data, - GObject *weak_object) -{ - TplTextChannel *self = TPL_TEXT_CHANNEL (proxy); - TplTextChannelPriv *priv = self->priv; - TplEntity *sender; - TplEntity *receiver = priv->remote; - - if (tp_signalled_message_get_sender (TP_MESSAGE (message)) != NULL) - sender = tpl_entity_new_from_tp_contact ( - tp_signalled_message_get_sender (TP_MESSAGE (message)), - TPL_ENTITY_SELF); - else - sender = g_object_ref (priv->self); - - tpl_text_channel_store_message (self, TP_MESSAGE (message), - sender, receiver); - - g_object_unref (sender); -} - - -static void -on_pending_message_removed_cb (TpTextChannel *self, - TpSignalledMessage *message, - gpointer user_data) -{ - TplLogStore *cache; - GList *ids = NULL; - GError *error = NULL; - - ids = g_list_prepend (ids, - GUINT_TO_POINTER (get_message_pending_id (TP_MESSAGE (message)))); - - cache = _tpl_log_store_sqlite_dup (); - _tpl_log_store_sqlite_remove_pending_messages (cache, TP_CHANNEL (self), - ids, &error); - - if (error != NULL) - { - PATH_DEBUG (self, "Failed to remove pending message from cache: %s", - error->message); - g_error_free (error); - } - - g_object_unref (cache); -} - - -static gint -pending_message_compare_id (TpSignalledMessage *m1, - TpSignalledMessage *m2) -{ - guint id1, id2; - - id1 = get_message_pending_id (TP_MESSAGE (m1)); - id2 = get_message_pending_id (TP_MESSAGE (m2)); - - if (id1 > id2) - return 1; - else if (id1 < id2) - return -1; - else - return 0; -} - - -static gint -pending_message_compare_timestamp (TpSignalledMessage *m1, - TpSignalledMessage *m2) -{ - gint64 ts1, ts2; - - ts1 = get_message_timestamp (TP_MESSAGE (m1)); - ts2 = get_message_timestamp (TP_MESSAGE (m2)); - - if (ts1 > ts2) - return 1; - else if (ts1 < ts2) - return -1; - else - return 0; -} - - -static void -store_pending_messages (TplTextChannel *self) -{ - TplLogStore *cache; - GError *error = NULL; - GList *cached_messages; - GList *pending_messages; - GList *cached_it, *pending_it; - GList *to_remove = NULL; - GList *to_log = NULL; - - cache = _tpl_log_store_sqlite_dup (); - cached_messages = _tpl_log_store_sqlite_get_pending_messages (cache, - TP_CHANNEL (self), &error); - - if (error != NULL) - { - DEBUG ("Failed to read pending_message cache: %s.", error->message); - g_error_free (error); - /* We simply ignore this error, as if the list was empty */ - } - - pending_messages = - tp_text_channel_dup_pending_messages (TP_TEXT_CHANNEL (self)); - - pending_messages = g_list_sort (pending_messages, - (GCompareFunc) pending_message_compare_id); - - cached_it = cached_messages; - pending_it = pending_messages; - - while (cached_it != NULL || pending_it != NULL) - { - TplPendingMessage *cached; - TpSignalledMessage *pending; - guint pending_id; - gint64 pending_ts; - - if (cached_it == NULL) - { - /* No more cached pending, just log the pending messages */ - to_log = g_list_prepend (to_log, pending_it->data); - pending_it = g_list_next (pending_it); - continue; - } - - cached = cached_it->data; - - if (pending_it == NULL) - { - /* No more pending, just remove the cached messages */ - to_remove = g_list_prepend (to_remove, GUINT_TO_POINTER (cached->id)); - cached_it = g_list_next (cached_it); - continue; - } - - pending = pending_it->data; - pending_id = get_message_pending_id (TP_MESSAGE (pending)); - pending_ts = get_message_timestamp (TP_MESSAGE (pending)); - - if (cached->id == pending_id) - { - if (cached->timestamp != pending_ts) - { - /* The cache messaged is invalid, remove it */ - to_remove = g_list_prepend (to_remove, - GUINT_TO_POINTER (cached->id)); - cached_it = g_list_next (cached_it); - } - else - { - /* The message is already logged */ - cached_it = g_list_next (cached_it); - pending_it = g_list_next (pending_it); - } - } - else if (cached->id < pending_id) - { - /* The cached ID is not valid anymore, remove it */ - to_remove = g_list_prepend (to_remove, GUINT_TO_POINTER (cached->id)); - cached_it = g_list_next (cached_it); - } - else - { - /* The pending message has not been logged */ - to_log = g_list_prepend (to_log, pending); - pending_it = g_list_next (pending_it); - } - } - - g_list_foreach (cached_messages, (GFunc) g_free, NULL); - g_list_free (cached_messages); - g_list_free_full (pending_messages, g_object_unref); - - - /* We need to remove before we log to avoid collisions */ - if (to_remove != NULL) - { - if (!_tpl_log_store_sqlite_remove_pending_messages (cache, - TP_CHANNEL (self), to_remove, &error)) - { - DEBUG ("Failed remove old pending messages from cache: %s", error->message); - g_error_free (error); - } - g_list_free (to_remove); - } - - if (to_log != NULL) - { - GList *it; - - to_log = g_list_sort (to_log, - (GCompareFunc) pending_message_compare_timestamp); - - for (it = to_log; it != NULL; it = g_list_next (it)) - on_message_received_cb (TP_TEXT_CHANNEL (self), - TP_SIGNALLED_MESSAGE (it->data), self); - - g_list_free (to_log); - } - - g_object_unref (cache); -} - - -static void -connect_message_signals (TplTextChannel *self) -{ - tp_g_signal_connect_object (self, "invalidated", - G_CALLBACK (on_channel_invalidated_cb), self, 0); - - tp_g_signal_connect_object (self, "message-received", - G_CALLBACK (on_message_received_cb), self, 0); - - tp_g_signal_connect_object (self, "message-sent", - G_CALLBACK (on_message_sent_cb), self, 0); - - tp_g_signal_connect_object (self, "pending-message-removed", - G_CALLBACK (on_pending_message_removed_cb), self, 0); -} - - -static void -_tpl_text_channel_prepare_core_async (TpProxy *proxy, - const TpProxyFeature *feature, - GAsyncReadyCallback callback, - gpointer user_data) -{ - TplTextChannel *self = (TplTextChannel *) proxy; - - get_my_contact (self); - get_remote_contact (self); - store_pending_messages (self); - connect_message_signals (self); - - tp_simple_async_report_success_in_idle ((GObject *) self, callback, user_data, - _tpl_text_channel_prepare_core_async); -} - - -GQuark -_tpl_text_channel_get_feature_quark_core (void) -{ - return g_quark_from_static_string ("tpl-text-channel-feature-core"); -} - -enum { - FEAT_CORE, - N_FEAT -}; - -static const TpProxyFeature * -tpl_text_channel_list_features (TpProxyClass *cls G_GNUC_UNUSED) -{ - static TpProxyFeature features[N_FEAT + 1] = { { 0 } }; - static GQuark depends_on[3] = { 0, 0, 0 }; - - if (G_LIKELY (features[0].name != 0)) - return features; - - features[FEAT_CORE].name = TPL_TEXT_CHANNEL_FEATURE_CORE; - features[FEAT_CORE].prepare_async = _tpl_text_channel_prepare_core_async; - depends_on[0] = TP_TEXT_CHANNEL_FEATURE_INCOMING_MESSAGES; - depends_on[1] = TP_CHANNEL_FEATURE_GROUP; - features[FEAT_CORE].depends_on = depends_on; - - /* assert that the terminator at the end is there */ - g_assert (features[N_FEAT].name == 0); - - return features; -} - -static void -tpl_text_channel_dispose (GObject *obj) -{ - TplTextChannelPriv *priv = TPL_TEXT_CHANNEL (obj)->priv; - - tp_clear_object (&priv->remote); - tp_clear_object (&priv->self); - - G_OBJECT_CLASS (_tpl_text_channel_parent_class)->dispose (obj); -} - - -static void -tpl_text_channel_finalize (GObject *obj) -{ - PATH_DEBUG (obj, "finalizing channel %p", obj); - - G_OBJECT_CLASS (_tpl_text_channel_parent_class)->finalize (obj); -} - - -static void -_tpl_text_channel_class_init (TplTextChannelClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - TpProxyClass *proxy_class = (TpProxyClass *) klass; - - object_class->dispose = tpl_text_channel_dispose; - object_class->finalize = tpl_text_channel_finalize; - - proxy_class->list_features = tpl_text_channel_list_features; - - g_type_class_add_private (object_class, sizeof (TplTextChannelPriv)); -} - - -static void -_tpl_text_channel_init (TplTextChannel *self) -{ - TplTextChannelPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - TPL_TYPE_TEXT_CHANNEL, TplTextChannelPriv); - - self->priv = priv; -} - - -/** - * _tpl_text_channel_new: - * @conn: TpConnection instance owning the channel - * @object_path: the channel's DBus path - * @tp_chan_props: channel's immutable properties, obtained for example by - * %tp_channel_borrow_immutable_properties() - * @error: location of the GError, used in case a problem is raised while - * creating the channel - * - * Convenience function to create a new TPL Channel Text proxy. - * The returned #TplTextChannel is not guaranteed to be ready at the point of - * return. - * - * TplTextChannel is actually a subclass of the abstract TplChannel which is a - * subclass of TpChannel. - * Use #TpChannel methods, casting the #TplTextChannel instance to a - * TpChannel, to access TpChannel data/methods from it. - * - * TplTextChannel is usually created using #tpl_channel_factory_build, from - * within a #TplObserver singleton, when its Observer_Channel method is called - * by the Channel Dispatcher. - * - * Returns: the TplTextChannel instance or %NULL if @object_path is not valid - */ -TplTextChannel * -_tpl_text_channel_new (TpConnection *conn, - const gchar *object_path, - GHashTable *tp_chan_props, - GError **error) -{ - return _tpl_text_channel_new_with_factory (NULL, conn, object_path, - tp_chan_props, error); -} - -TplTextChannel * -_tpl_text_channel_new_with_factory (TpClientFactory *factory, - TpConnection *conn, - const gchar *object_path, - const GHashTable *tp_chan_props, - GError **error) -{ - TplTextChannel *self; - - /* Do what tpl_channel_new does + set TplTextChannel specific */ - - g_return_val_if_fail (TP_IS_CONNECTION (conn), NULL); - g_return_val_if_fail (!TPL_STR_EMPTY (object_path), NULL); - g_return_val_if_fail (tp_chan_props != NULL, NULL); - - if (!tp_dbus_check_valid_object_path (object_path, error)) - return NULL; - - self = g_object_new (TPL_TYPE_TEXT_CHANNEL, - /* TpChannel properties */ - "factory", factory, - "connection", conn, - "dbus-daemon", tp_proxy_get_dbus_daemon (conn), - "bus-name", tp_proxy_get_bus_name (conn), - "object-path", object_path, - "handle-type", (guint) TP_UNKNOWN_HANDLE_TYPE, - "channel-properties", tp_chan_props, - NULL); - - self->priv->account = g_object_ref (tp_connection_get_account (conn)); - - return self; -} diff --git a/telepathy-logger/text-event-internal.h b/telepathy-logger/text-event-internal.h deleted file mode 100644 index 9725fd1..0000000 --- a/telepathy-logger/text-event-internal.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2009 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: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - */ - -#ifndef __TPL_TEXT_EVENT_INTERNAL_H__ -#define __TPL_TEXT_EVENT_INTERNAL_H__ - -#include <telepathy-logger/text-event.h> -#include <telepathy-logger/event-internal.h> -#include <telepathy-logger/text-channel-internal.h> - -#define TPL_TEXT_EVENT_MSG_ID_IS_VALID(msg) (msg >= 0) - -#define TPL_TEXT_EVENT_MSG_ID_UNKNOWN -2 -#define TPL_TEXT_EVENT_MSG_ID_ACKNOWLEDGED -1 - -G_BEGIN_DECLS - -struct _TplTextEvent -{ - TplEvent parent; - - /* Private */ - TplTextEventPriv *priv; -}; - -struct _TplTextEventClass -{ - TplEventClass parent_class; -}; - -TpChannelTextMessageType _tpl_text_event_message_type_from_str ( - const gchar *type_str); - -const gchar * _tpl_text_event_message_type_to_str ( - TpChannelTextMessageType msg_type); - -gint _tpl_text_event_get_pending_msg_id (TplTextEvent *self); - -gboolean _tpl_text_event_is_pending (TplTextEvent *self); - -void _tpl_text_event_add_supersedes (TplTextEvent *self, - TplTextEvent *old_event); - -G_END_DECLS -#endif // __TPL_TEXT_EVENT_INTERNAL_H__ diff --git a/telepathy-logger/text-event.c b/telepathy-logger/text-event.c deleted file mode 100644 index 4ef6923..0000000 --- a/telepathy-logger/text-event.c +++ /dev/null @@ -1,410 +0,0 @@ -/* - * Copyright (C) 2009 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: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - */ - -#include "config.h" -#include "text-event.h" -#include "text-event-internal.h" - -#include <glib-object.h> -#include <telepathy-glib/telepathy-glib.h> - -#include <telepathy-logger/event.h> -#include <telepathy-logger/event-internal.h> - -#define DEBUG_FLAG TPL_DEBUG_LOG_STORE -#include <telepathy-logger/debug-internal.h> -#include <telepathy-logger/util-internal.h> - -/** - * SECTION:text-event - * @title: TplTextEvent - * @short_description: Representation of a text log event - * - * A subclass of #TplEvent representing a text log event. - */ - -/** - * TplTextEvent: - * - * An object representing a text log event. - */ - - -G_DEFINE_TYPE (TplTextEvent, tpl_text_event, TPL_TYPE_EVENT) - -struct _TplTextEventPriv -{ - TpChannelTextMessageType message_type; - gint64 edit_timestamp; - gchar *message; - gchar *token; - gchar *supersedes_token; - /* A list of TplTextEvent that we supersede. - * This is only populated when reading logs (not storing them). */ - GQueue supersedes; -}; - -enum -{ - PROP_MESSAGE_TYPE = 1, - PROP_EDIT_TIMESTAMP, - PROP_MESSAGE, - PROP_TOKEN, - PROP_SUPERSEDES -}; - -static gchar *message_types[] = { - "normal", - "action", - "notice", - "auto-reply", - "delivery-report", - NULL -}; - - -static void -tpl_text_event_dispose (GObject *obj) -{ - TplTextEventPriv *priv = TPL_TEXT_EVENT (obj)->priv; - - g_list_foreach (priv->supersedes.head, (GFunc) g_object_unref, NULL); - g_list_free (priv->supersedes.head); - g_queue_init (&priv->supersedes); - - G_OBJECT_CLASS (tpl_text_event_parent_class)->dispose (obj); -} - - -static void -tpl_text_event_finalize (GObject *obj) -{ - TplTextEventPriv *priv = TPL_TEXT_EVENT (obj)->priv; - - g_free (priv->message); - priv->message = NULL; - - g_free (priv->token); - priv->token = NULL; - - g_free (priv->supersedes_token); - priv->supersedes_token = NULL; - - G_OBJECT_CLASS (tpl_text_event_parent_class)->finalize (obj); -} - - -static void -tpl_text_event_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - TplTextEventPriv *priv = TPL_TEXT_EVENT (object)->priv; - - switch (param_id) - { - case PROP_MESSAGE_TYPE: - g_value_set_uint (value, priv->message_type); - break; - case PROP_EDIT_TIMESTAMP: - g_value_set_int64 (value, priv->edit_timestamp); - break; - case PROP_MESSAGE: - g_value_set_string (value, priv->message); - break; - case PROP_TOKEN: - g_value_set_string (value, priv->token); - break; - case PROP_SUPERSEDES: - g_value_set_string (value, priv->supersedes_token); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - - -static void -tpl_text_event_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - TplTextEventPriv *priv = TPL_TEXT_EVENT (object)->priv; - - switch (param_id) { - case PROP_MESSAGE_TYPE: - priv->message_type = g_value_get_uint (value); - break; - case PROP_EDIT_TIMESTAMP: - priv->edit_timestamp = g_value_get_int64 (value); - break; - case PROP_MESSAGE: - g_assert (priv->message == NULL); - priv->message = g_value_dup_string (value); - break; - case PROP_TOKEN: - g_assert (priv->token == NULL); - priv->token = g_value_dup_string (value); - break; - case PROP_SUPERSEDES: - g_assert (priv->supersedes_token == NULL); - priv->supersedes_token = g_value_dup_string (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - break; - } -} - - -static gboolean tpl_text_event_equal (TplEvent *event1, - TplEvent *event2) -{ - TplTextEvent *text_event1 = TPL_TEXT_EVENT (event1); - TplTextEvent *text_event2 = TPL_TEXT_EVENT (event2); - - return TPL_EVENT_CLASS (tpl_text_event_parent_class)->equal (event1, event2) - && text_event1->priv->message_type == text_event2->priv->message_type - && !tp_strdiff (text_event1->priv->message, text_event2->priv->message); -} - - -static void tpl_text_event_class_init (TplTextEventClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - TplEventClass *event_class = TPL_EVENT_CLASS (klass); - GParamSpec *param_spec; - - object_class->dispose = tpl_text_event_dispose; - object_class->finalize = tpl_text_event_finalize; - object_class->get_property = tpl_text_event_get_property; - object_class->set_property = tpl_text_event_set_property; - - event_class->equal = tpl_text_event_equal; - - param_spec = g_param_spec_uint ("message-type", - "MessageType", - "The message type for a Text log event", - 0, G_MAXUINT32, TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_MESSAGE_TYPE, param_spec); - - param_spec = g_param_spec_int64 ("edit-timestamp", - "Timestamp of edit message", - "message-{sent,received} if this is an edit, or 0 otherwise.", - G_MININT64, G_MAXINT64, 0, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_EDIT_TIMESTAMP, - param_spec); - - param_spec = g_param_spec_string ("message", - "Message", - "The text message of the log event", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_MESSAGE, param_spec); - - param_spec = g_param_spec_string ("message-token", - "Message Token", - "The message-token field of this message.", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_TOKEN, param_spec); - - param_spec = g_param_spec_string ("supersedes-token", - "Message Token", - "The message-token field of the message that this one supersedes.", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - g_object_class_install_property (object_class, PROP_SUPERSEDES, param_spec); - - g_type_class_add_private (object_class, sizeof (TplTextEventPriv)); -} - - -static void -tpl_text_event_init (TplTextEvent *self) -{ - TplTextEventPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - TPL_TYPE_TEXT_EVENT, TplTextEventPriv); - self->priv = priv; -} - - -/** - * _tpl_text_event_message_type_from_str: - * @type_str: string to transform into a #TpChannelTextMessageType - * - * Maps strings into enum #TpChannelTextMessageType values. - * - * Returns: the relative value from enum #TpChannelTextMessageType if a - * mapping is found, or defaults to %TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL if not. - */ -TpChannelTextMessageType -_tpl_text_event_message_type_from_str (const gchar *type_str) -{ - guint i; - for (i = 0; i < G_N_ELEMENTS (message_types); ++i) - if (!tp_strdiff (type_str, message_types[i])) - return (TpChannelTextMessageType) i; - - /* default case */ - return TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL; -} - - -/** - * _tpl_text_event_message_type_to_str: - * @msg_type: message type to transform into a string - * - * Maps enum #TpChannelTextMessageType values into strings - * - * Returns: a string representation for @msg_type or NULL if @msg_type is not - * a legal value for %TpChannelTextMessageType. - */ -const gchar * -_tpl_text_event_message_type_to_str (TpChannelTextMessageType msg_type) -{ - g_return_val_if_fail (G_N_ELEMENTS (message_types) >= msg_type, NULL); - - return message_types[msg_type]; -} - - -/** - * tpl_text_event_get_message: - * @self: a #TplTextEvent - * - * Returns: the same message as the #TplTextEvent:message property - */ -const gchar * -tpl_text_event_get_message (TplTextEvent *self) -{ - g_return_val_if_fail (TPL_IS_TEXT_EVENT (self), NULL); - - return self->priv->message; -} - - -/** - * tpl_text_event_get_message_token: - * @self: a #TplTextEvent - * - * Returns: the same message as the #TplTextEvent:message-token property - */ -const gchar * -tpl_text_event_get_message_token (TplTextEvent *self) -{ - g_return_val_if_fail (TPL_IS_TEXT_EVENT (self), NULL); - - return self->priv->token; -} - - -/** - * tpl_text_event_get_supersedes_token: - * @self: a #TplTextEvent - * - * Returns: the same message as the #TplTextEvent:supersedes-token property - */ -const gchar * -tpl_text_event_get_supersedes_token (TplTextEvent *self) -{ - g_return_val_if_fail (TPL_IS_TEXT_EVENT (self), NULL); - - return self->priv->supersedes_token; -} - - -/** - * _tpl_text_event_add_supersedes: - * @self: a #TplTextEvent - * @old_event: (transfer none): an #TplTextEvent which this one supersedes - * - * If there are other known entries in the message edit/succession chain, - * they should be added to old_event before linking these two events, - * as they will be copied onto this event for convenience. - */ -void -_tpl_text_event_add_supersedes (TplTextEvent *self, - TplTextEvent *old_event) -{ - GList *l; - - g_object_ref (old_event); - g_queue_push_tail (&self->priv->supersedes, old_event); - - for (l = old_event->priv->supersedes.head; l != NULL; l = g_list_next (l)) - g_queue_push_tail (&self->priv->supersedes, g_object_ref (l->data)); - - if (self->priv->supersedes_token == NULL) - self->priv->supersedes_token = g_strdup (old_event->priv->token); -} - - -/** - * tpl_text_event_get_supersedes: - * @self: a #TplTextEvent - * - * Returns: (transfer none) (element-type TelepathyLogger1.TextEvent): A #GList - * of #TplTextEvent that this event - * supersedes. - */ -GList * -tpl_text_event_get_supersedes (TplTextEvent *self) -{ - return self->priv->supersedes.head; -} - - -/** - * tpl_text_event_get_message_type: - * @self: a #TplTextEvent - * - * Returns: the same message as the #TplTextEvent:message-type property - */ -TpChannelTextMessageType -tpl_text_event_get_message_type (TplTextEvent *self) -{ - g_return_val_if_fail (TPL_IS_TEXT_EVENT (self), - TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL); - - return self->priv->message_type; -} - - -/** - * tpl_text_event_get_edit_timestamp: - * @self: a #TplTextEvent - * - * Returns: the same value as the #TplTextEvent:edit-timestamp property - */ -gint64 -tpl_text_event_get_edit_timestamp (TplTextEvent *self) -{ - g_return_val_if_fail (TPL_IS_TEXT_EVENT (self), 0); - - return self->priv->edit_timestamp; -} - - diff --git a/telepathy-logger/text-event.h b/telepathy-logger/text-event.h deleted file mode 100644 index f765507..0000000 --- a/telepathy-logger/text-event.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2009 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: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - */ - -#ifndef __TPL_TEXT_EVENT_H__ -#define __TPL_TEXT_EVENT_H__ - -#include <glib-object.h> - -#include <telepathy-logger/event.h> - -G_BEGIN_DECLS -#define TPL_TYPE_TEXT_EVENT (tpl_text_event_get_type ()) -#define TPL_TEXT_EVENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TPL_TYPE_TEXT_EVENT, TplTextEvent)) -#define TPL_TEXT_EVENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TPL_TYPE_TEXT_EVENT, TplTextEventClass)) -#define TPL_IS_TEXT_EVENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TPL_TYPE_TEXT_EVENT)) -#define TPL_IS_TEXT_EVENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TPL_TYPE_TEXT_EVENT)) -#define TPL_TEXT_EVENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_TEXT_EVENT, TplTextEventClass)) - -typedef struct _TplTextEvent TplTextEvent; -typedef struct _TplTextEventClass TplTextEventClass; -typedef struct _TplTextEventPriv TplTextEventPriv; - -GType tpl_text_event_get_type (void); - -TpChannelTextMessageType tpl_text_event_get_message_type (TplTextEvent *self); -gint64 tpl_text_event_get_edit_timestamp (TplTextEvent *self); - -const gchar *tpl_text_event_get_message (TplTextEvent *self); -const gchar *tpl_text_event_get_message_token (TplTextEvent *self); -const gchar *tpl_text_event_get_supersedes_token (TplTextEvent *self); - -GList *tpl_text_event_get_supersedes (TplTextEvent *self); - -G_END_DECLS -#endif // __TPL_TEXT_EVENT_H__ diff --git a/telepathy-logger/tpl-marshal.list b/telepathy-logger/tpl-marshal.list deleted file mode 100644 index 2c852dd..0000000 --- a/telepathy-logger/tpl-marshal.list +++ /dev/null @@ -1,3 +0,0 @@ -# add marshallers here -VOID:UINT,UINT,BOXED,BOXED -VOID:BOXED,BOXED diff --git a/telepathy-logger/util-internal.h b/telepathy-logger/util-internal.h deleted file mode 100644 index eabcaa1..0000000 --- a/telepathy-logger/util-internal.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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 - * 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: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - * Richard Hult <richard@imendio.com> - */ - -#ifndef __TPL_UTIL_H__ -#define __TPL_UTIL_H__ - -#include <glib-object.h> -#include <gio/gio.h> - -#include "event.h" - -#define TPL_STR_EMPTY(x) ((x) == NULL || (x)[0] == '\0') - -void _tpl_rmdir_recursively (const gchar *dir_name); - -gint64 _tpl_time_parse (const gchar * str); - -GList *_tpl_event_queue_insert_sorted_after (GQueue *events, - GList *index, - TplEvent *event); - -#endif // __TPL_UTIL_H__ diff --git a/telepathy-logger/util.c b/telepathy-logger/util.c deleted file mode 100644 index fd871bf..0000000 --- a/telepathy-logger/util.c +++ /dev/null @@ -1,135 +0,0 @@ -/* - * 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 - * 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: Cosimo Alfarano <cosimo.alfarano@collabora.co.uk> - * Richard Hult <richard@imendio.com> - */ - -#include "config.h" - -#include "util-internal.h" - -#include <errno.h> -#include <glib.h> -#include <glib/gstdio.h> - - -void -_tpl_rmdir_recursively (const gchar *dir_name) -{ - GDir *dir; - const gchar *name; - - dir = g_dir_open (dir_name, 0, NULL); - - /* Directory does not exist, nothing to do */ - if (dir == NULL) - return; - - while ((name = g_dir_read_name (dir)) != NULL) - { - gchar *filename = g_build_path (G_DIR_SEPARATOR_S, - dir_name, name, NULL); - - if (g_file_test (filename, G_FILE_TEST_IS_DIR)) - _tpl_rmdir_recursively (filename); - else if (g_unlink (filename) < 0) - g_warning ("Could not unlink '%s': %s", filename, g_strerror (errno)); - - g_free (filename); - } - - g_dir_close (dir); - - if (g_rmdir (dir_name) < 0) - g_warning ("Could not remove directory '%s': %s", - dir_name, g_strerror (errno)); -} - -/* We leak a single tz struct as freeing them is not thread-safe, - * see https://bugzilla.gnome.org/show_bug.cgi?id=646435 */ -static GTimeZone *tz; - -/* 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; - - if (G_UNLIKELY (tz == NULL)) - tz = g_time_zone_new_utc (); - - dt = g_date_time_new (tz, year, month, day, hour, min, sec); - ts = g_date_time_to_unix (dt); - - g_date_time_unref (dt); - - return ts; -} - - -GList * -_tpl_event_queue_insert_sorted_after (GQueue *events, - GList *index, - TplEvent *event) -{ - if (g_queue_is_empty (events)) - { - g_queue_push_tail (events, event); - return events->tail; - } - - /* The initial index might go before the first one */ - if (index == NULL) - { - index = events->head; - - if (tpl_event_get_timestamp (event) < - tpl_event_get_timestamp (TPL_EVENT (index->data))) - { - g_queue_insert_before (events, index, event); - return events->head; - } - } - - /* Find the last event that this event can go after */ - while (g_list_next (index) != NULL && - tpl_event_get_timestamp (event) >= - tpl_event_get_timestamp (TPL_EVENT (g_list_next (index)->data))) - index = g_list_next (index); - - g_queue_insert_after (events, index, event); - return g_list_next (index); -} |