diff --git a/data/org.freedesktop.Telepathy.Logger.gschema.xml.in b/data/org.freedesktop.Telepathy.Logger.gschema.xml.in index ddb4c15..ca39e36 100644 --- a/data/org.freedesktop.Telepathy.Logger.gschema.xml.in +++ b/data/org.freedesktop.Telepathy.Logger.gschema.xml.in @@ -8,5 +8,10 @@ "false" will completely disable all logging. + + [] + <_summary>Ignore list + <_description>Conversations with entities with ID listed here will not be logged. + diff --git a/telepathy-logger/conf-internal.h b/telepathy-logger/conf-internal.h index bf80860..953c5e9 100644 --- a/telepathy-logger/conf-internal.h +++ b/telepathy-logger/conf-internal.h @@ -51,10 +51,10 @@ TplConf *_tpl_conf_dup (void); gboolean _tpl_conf_is_globally_enabled (TplConf *self); gboolean _tpl_conf_is_account_ignored (TplConf *self, const gchar *account_path); -// GSList *_tpl_conf_get_accounts_ignorelist (TplConf *self); +GSList *_tpl_conf_get_accounts_ignorelist (TplConf *self); void _tpl_conf_globally_enable (TplConf *self, gboolean enable); -// void _tpl_conf_set_accounts_ignorelist (TplConf *self, GSList *newlist); +void _tpl_conf_set_accounts_ignorelist (TplConf *self, GSList *newlist); G_END_DECLS #endif // __TPL_CONF_H__ diff --git a/telepathy-logger/conf.c b/telepathy-logger/conf.c index d9e21fb..a86c8c0 100644 --- a/telepathy-logger/conf.c +++ b/telepathy-logger/conf.c @@ -29,6 +29,7 @@ #define DEBUG_FLAG TPL_DEBUG_CONF #include #include +#include #define GET_PRIV(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TPL_TYPE_CONF, TplConfPriv)) @@ -49,7 +50,8 @@ typedef struct enum /* properties */ { PROP_0, - PROP_GLOBALLY_ENABLED + PROP_GLOBALLY_ENABLED, + PROP_IGNORE_LIST, }; @@ -157,6 +159,12 @@ _tpl_conf_class_init (TplConfClass *klass) 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)); } @@ -243,3 +251,60 @@ _tpl_conf_globally_enable (TplConf *self, g_settings_set_boolean (GET_PRIV (self)->gsettings, KEY_ENABLED, enable); } + +/** + * _tpl_conf_set_accounts_ignorelist: + * @self: a TplConf instance + * @newlist: a GSList of account/entity IDs that should not be logged + */ +void +_tpl_conf_set_accounts_ignorelist (TplConf *self, + GSList *newlist) +{ + GSList *iter; + gint ii, len; + gchar **arr; + + g_return_if_fail (TPL_IS_CONF (self)); + + len = g_slist_length (newlist); + arr = g_new0 (gchar *, len); + + for (iter = newlist, ii = 0; iter; iter = g_slist_next (iter), ii++) { + arr[ii] = iter->data; + } + g_settings_set_strv (GET_PRIV (self)->gsettings, "ignorelist", (const gchar * const *) arr); + g_strfreev (arr); + + 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. + * + * Return value: (transfer-full)(element-type string) a list of IDs to be + * ignored. Free the list and it's content when no longer needed. + */ +GSList * +_tpl_conf_get_accounts_ignorelist (TplConf *self) +{ + gchar **arr; + GSList *list; + gint ii; + + g_return_val_if_fail (TPL_IS_CONF (self), NULL); + + arr = g_settings_get_strv (GET_PRIV (self)->gsettings, "ignorelist"); + + list = NULL; + for (ii = 0; arr && arr[ii]; ii++) { + list = g_slist_prepend (list, arr[ii]); + } + g_free (arr); + + return g_slist_reverse (list); +} diff --git a/telepathy-logger/log-manager.c b/telepathy-logger/log-manager.c index b4b92dd..e9a417a 100644 --- a/telepathy-logger/log-manager.c +++ b/telepathy-logger/log-manager.c @@ -314,6 +314,37 @@ tpl_log_manager_dup_singleton (void) return g_object_new (TPL_TYPE_LOG_MANAGER, NULL); } +static gchar * +get_account_entity_id (TpAccount *account, + TplEntity *entity) +{ + const gchar *name; + gchar *id; + gchar *escaped_account, *escaped_id = 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); + escaped_account = g_strdelimit (g_strdup (name), "/", '_'); + + if (entity != NULL) + { + escaped_id = g_strdelimit ( + g_strdup (tpl_entity_get_identifier (entity)), + "/", '_'); + } + + if (entity != NULL + && tpl_entity_get_entity_type (entity) == TPL_ENTITY_ROOM) + id = g_build_path (G_DIR_SEPARATOR_S, escaped_account, "chatroom", escaped_id, NULL); + else + id = g_build_path (G_DIR_SEPARATOR_S, escaped_account, escaped_id, NULL); + + g_free (escaped_account); + g_free (escaped_id); + + return id; +} /* * _tpl_log_manager_add_event: @@ -337,8 +368,13 @@ _tpl_log_manager_add_event (TplLogManager *manager, GError **error) { TplLogManagerPriv *priv; + TpAccount *account; GList *l; + GSList *ignore; gboolean retval = FALSE; + gchar *id; + + TplEntity *target; g_return_val_if_fail (error == NULL || *error == NULL, FALSE); g_return_val_if_fail (TPL_IS_LOG_MANAGER (manager), FALSE); @@ -352,6 +388,33 @@ _tpl_log_manager_add_event (TplLogManager *manager, return FALSE; } + ignore = _tpl_conf_get_accounts_ignorelist (priv->conf); + account = tpl_event_get_account (event); + + target = tpl_event_get_receiver (event); + id = get_account_entity_id (account, target); + if (g_slist_find_custom (ignore, id, (GCompareFunc) g_strcmp0)) + { + /* target is in ignore list, don't log */ + g_free (id); + g_slist_free_full (ignore, g_free); + return FALSE; + } + g_free (id); + + target = tpl_event_get_sender (event); + id = get_account_entity_id (account, target); + if (g_slist_find_custom (ignore, id, (GCompareFunc) g_strcmp0)) + { + /* sender is in ignore list, don't log */ + g_free (id); + g_slist_free_full (ignore, g_free); + return FALSE; + } + g_free (id); + + g_slist_free_full (ignore, g_free); + /* send the event to any writable log store */ for (l = priv->writable_stores; l != NULL; l = g_list_next (l)) {