diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-08-06 14:57:00 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-08-06 14:57:00 +0100 |
commit | 2c33c006c2b7f8cea8bbbb157c39268705211e8a (patch) | |
tree | a90228ae8500e25aff7f3e4cd7f17e72ea1f8af8 /src/libserver/cfg_rcl.c | |
parent | fb999abf1898f5159982ad5d872b930225b556f7 (diff) | |
download | rspamd-2c33c006c2b7f8cea8bbbb157c39268705211e8a.tar.gz rspamd-2c33c006c2b7f8cea8bbbb157c39268705211e8a.zip |
Add universal routine to check if a modules is enabled.
Diffstat (limited to 'src/libserver/cfg_rcl.c')
-rw-r--r-- | src/libserver/cfg_rcl.c | 59 |
1 files changed, 41 insertions, 18 deletions
diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c index a14a43146..46dd1b60f 100644 --- a/src/libserver/cfg_rcl.c +++ b/src/libserver/cfg_rcl.c @@ -250,9 +250,10 @@ rspamd_rcl_options_handler (rspamd_mempool_t *pool, const ucl_object_t *obj, */ static gboolean rspamd_rcl_insert_symbol (struct rspamd_config *cfg, struct metric *metric, - const ucl_object_t *obj, const gchar *group, gboolean is_legacy, GError **err) + const ucl_object_t *obj, struct rspamd_symbols_group *gr, + gboolean is_legacy, GError **err) { - const gchar *description = NULL, *sym_name; + const gchar *description = NULL, *sym_name, *group; gdouble symbol_score; const ucl_object_t *val; gboolean one_shot = FALSE; @@ -280,9 +281,13 @@ rspamd_rcl_insert_symbol (struct rspamd_config *cfg, struct metric *metric, sym_name = ucl_object_key (obj); } - if (group == NULL) { + if (gr == NULL) { group = "ungrouped"; } + else { + group = gr->name; + one_shot = gr->one_shot; + } if (ucl_object_todouble_safe (obj, &symbol_score)) { description = NULL; @@ -336,7 +341,7 @@ rspamd_rcl_insert_symbol (struct rspamd_config *cfg, struct metric *metric, static gboolean rspamd_rcl_symbols_handler (rspamd_mempool_t *pool, const ucl_object_t *obj, struct rspamd_config *cfg, struct metric *metric, - const gchar *group, gboolean new, GError **err) + struct rspamd_symbols_group *gr, gboolean new, GError **err) { const ucl_object_t *val, *cur; ucl_object_iter_t it = NULL; @@ -350,7 +355,7 @@ rspamd_rcl_symbols_handler (rspamd_mempool_t *pool, const ucl_object_t *obj, } it = NULL; while ((cur = ucl_iterate_object (val, &it, true)) != NULL) { - if (!rspamd_rcl_insert_symbol (cfg, metric, cur, group, FALSE, err)) { + if (!rspamd_rcl_insert_symbol (cfg, metric, cur, gr, FALSE, err)) { return FALSE; } } @@ -369,7 +374,7 @@ rspamd_rcl_symbols_handler (rspamd_mempool_t *pool, const ucl_object_t *obj, it = NULL; while ((cur = ucl_iterate_object (val, &it, false)) != NULL) { - if (!rspamd_rcl_insert_symbol (cfg, metric, cur, group, TRUE, err)) { + if (!rspamd_rcl_insert_symbol (cfg, metric, cur, gr, TRUE, err)) { return FALSE; } } @@ -504,23 +509,41 @@ rspamd_rcl_metric_handler (rspamd_mempool_t *pool, const ucl_object_t *obj, elt = ucl_object_find_key (cur, "name"); if (elt) { - if (!rspamd_rcl_symbols_handler (pool, cur, cfg, metric, - ucl_object_tostring (elt), - !have_symbols, err)) { - return FALSE; - } - - have_symbols = TRUE; gr = g_hash_table_lookup (cfg->symbols_groups, ucl_object_tostring (elt)); + if (gr == NULL) { + gr = + rspamd_mempool_alloc0 (cfg->cfg_pool, + sizeof (struct rspamd_symbols_group)); + gr->name = rspamd_mempool_strdup (cfg->cfg_pool, + ucl_object_tostring (elt)); + g_hash_table_insert (cfg->symbols_groups, gr->name, gr); + } - if (gr != NULL) { - elt = ucl_object_find_key (cur, "max_score"); + elt = ucl_object_find_key (cur, "max_score"); - if (elt) { - gr->max_score = ucl_object_todouble (elt); - } + if (elt) { + gr->max_score = ucl_object_todouble (elt); } + + elt = ucl_object_find_key (cur, "disabled"); + + if (elt) { + gr->disabled = ucl_object_toboolean (elt); + } + + elt = ucl_object_find_key (cur, "one_shot"); + + if (elt) { + gr->one_shot = ucl_object_toboolean (elt); + } + + if (!rspamd_rcl_symbols_handler (pool, cur, cfg, metric, + gr, !have_symbols, err)) { + return FALSE; + } + + have_symbols = TRUE; } } } |