aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-05-02 13:49:01 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-05-02 13:49:39 +0100
commit9afd92715f7be38bfe90ea68fdfc6b65e526f65b (patch)
tree128f67e9f36bb61b8cd25695680e6fc36ec6ac97 /src/libserver
parent5cda7efaff4db73310a2eb03fd0da3318252d1bb (diff)
downloadrspamd-9afd92715f7be38bfe90ea68fdfc6b65e526f65b.tar.gz
rspamd-9afd92715f7be38bfe90ea68fdfc6b65e526f65b.zip
[Feature] Add 'symbols_enabled' and 'groups_enabled' to settings
Diffstat (limited to 'src/libserver')
-rw-r--r--src/libserver/symbols_cache.c93
1 files changed, 92 insertions, 1 deletions
diff --git a/src/libserver/symbols_cache.c b/src/libserver/symbols_cache.c
index 20c2a8ec0..e9d366114 100644
--- a/src/libserver/symbols_cache.c
+++ b/src/libserver/symbols_cache.c
@@ -155,6 +155,10 @@ static gboolean rspamd_symbols_cache_check_deps (struct rspamd_task *task,
struct symbols_cache *cache,
struct cache_item *item,
struct cache_savepoint *checkpoint);
+static void rspamd_symbols_cache_enable_symbol (struct rspamd_task *task,
+ struct symbols_cache *cache, const gchar *symbol);
+static void rspamd_symbols_cache_disable_all_symbols (struct rspamd_task *task,
+ struct symbols_cache *cache);
static GQuark
rspamd_symbols_cache_quark (void)
@@ -1287,7 +1291,7 @@ static gboolean
rspamd_symbols_cache_process_settings (struct rspamd_task *task,
struct symbols_cache *cache)
{
- const ucl_object_t *wl, *cur, *disabled;
+ const ucl_object_t *wl, *cur, *disabled, *enabled;
struct metric *def;
struct rspamd_symbols_group *gr;
GHashTableIter gr_it;
@@ -1302,6 +1306,42 @@ rspamd_symbols_cache_process_settings (struct rspamd_task *task,
return TRUE;
}
+ enabled = ucl_object_lookup (task->settings, "symbols_enabled");
+
+ if (enabled) {
+ /* Disable all symbols but selected */
+ rspamd_symbols_cache_disable_all_symbols (task, cache);
+ it = NULL;
+
+ while ((cur = ucl_iterate_object (enabled, &it, true)) != NULL) {
+ rspamd_symbols_cache_enable_symbol (task, cache,
+ ucl_object_tostring (cur));
+ }
+ }
+
+ /* Enable groups of symbols */
+ enabled = ucl_object_lookup (task->settings, "groups_enabled");
+ def = g_hash_table_lookup (task->cfg->metrics, DEFAULT_METRIC);
+
+ if (def && enabled) {
+ it = NULL;
+
+ while ((cur = ucl_iterate_object (enabled, &it, true)) != NULL) {
+ if (ucl_object_type (cur) == UCL_STRING) {
+ gr = g_hash_table_lookup (def->groups,
+ ucl_object_tostring (cur));
+
+ if (gr) {
+ g_hash_table_iter_init (&gr_it, gr->symbols);
+
+ while (g_hash_table_iter_next (&gr_it, &k, &v)) {
+ rspamd_symbols_cache_enable_symbol (task, cache, k);
+ }
+ }
+ }
+ }
+ }
+
disabled = ucl_object_lookup (task->settings, "symbols_disabled");
if (disabled) {
@@ -1721,6 +1761,25 @@ rspamd_symbols_cache_symbols_count (struct symbols_cache *cache)
return cache->items_by_id->len;
}
+static void
+rspamd_symbols_cache_disable_all_symbols (struct rspamd_task *task,
+ struct symbols_cache *cache)
+{
+ struct cache_savepoint *checkpoint;
+
+ if (task->checkpoint == NULL) {
+ checkpoint = rspamd_symbols_cache_make_checkpoint (task, cache);
+ task->checkpoint = checkpoint;
+ }
+ else {
+ checkpoint = task->checkpoint;
+ }
+
+ /* Set all symbols as started + finished to disable their execution */
+ memset (checkpoint->processed_bits, 0xff,
+ NBYTES (cache->used_items) * 2);
+}
+
void
rspamd_symbols_cache_disable_symbol (struct rspamd_task *task,
struct symbols_cache *cache, const gchar *symbol)
@@ -1753,6 +1812,38 @@ rspamd_symbols_cache_disable_symbol (struct rspamd_task *task,
}
}
+static void
+rspamd_symbols_cache_enable_symbol (struct rspamd_task *task,
+ struct symbols_cache *cache, const gchar *symbol)
+{
+ struct cache_savepoint *checkpoint;
+ struct cache_item *item;
+ gint id;
+
+ if (task->checkpoint == NULL) {
+ checkpoint = rspamd_symbols_cache_make_checkpoint (task, cache);
+ task->checkpoint = checkpoint;
+ }
+ else {
+ checkpoint = task->checkpoint;
+ }
+
+ id = rspamd_symbols_cache_find_symbol_parent (cache, symbol);
+
+ if (id > 0) {
+ /* Set executed and finished flags */
+ item = g_ptr_array_index (cache->items_by_id, id);
+
+ clrbit (checkpoint->processed_bits, item->id * 2);
+ clrbit (checkpoint->processed_bits, item->id * 2 + 1);
+
+ msg_debug_task ("enable execution of %s", symbol);
+ }
+ else {
+ msg_info_task ("cannot enable %s: not found", symbol);
+ }
+}
+
struct rspamd_abstract_callback_data* rspamd_symbols_cache_get_cbdata (
struct symbols_cache *cache, const gchar *symbol)
{