diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-02-18 15:42:43 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-02-18 15:42:43 +0000 |
commit | 8920c4d8faf24ab5eff34f389d01da7635514fb0 (patch) | |
tree | 9890a600debe14de4cf59ce531a8d6dd5690f76b /src/libserver | |
parent | 96ae0fe1867bc3c9ba5ea752bd93bd1b3632fa79 (diff) | |
download | rspamd-8920c4d8faf24ab5eff34f389d01da7635514fb0.tar.gz rspamd-8920c4d8faf24ab5eff34f389d01da7635514fb0.zip |
[Fix] Rework groups scores definitions
Diffstat (limited to 'src/libserver')
-rw-r--r-- | src/libserver/cfg_file.h | 21 | ||||
-rw-r--r-- | src/libserver/cfg_rcl.c | 61 | ||||
-rw-r--r-- | src/libserver/cfg_utils.c | 18 |
3 files changed, 74 insertions, 26 deletions
diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h index c7475c327..c102ef570 100644 --- a/src/libserver/cfg_file.h +++ b/src/libserver/cfg_file.h @@ -98,6 +98,13 @@ enum lua_var_type { LUA_VAR_UNKNOWN }; +enum rspamd_symbol_group_flags { + RSPAMD_SYMBOL_GROUP_NORMAL = 0, + RSPAMD_SYMBOL_GROUP_DISABLED = (1 << 0), + RSPAMD_SYMBOL_GROUP_ONE_SHOT = (1 << 1), + RSPAMD_SYMBOL_GROUP_UNGROUPED = (1 << 2), +}; + /** * Symbols group */ @@ -106,13 +113,15 @@ struct rspamd_symbols_group { gchar *name; GHashTable *symbols; gdouble max_score; - gboolean disabled; - gboolean one_shot; + enum rspamd_symbol_group_flags flags; }; -#define RSPAMD_SYMBOL_FLAG_IGNORE (1 << 1) -#define RSPAMD_SYMBOL_FLAG_ONEPARAM (1 << 2) -#define RSPAMD_SYMBOL_FLAG_UNGROUPPED (1 << 3) +enum rspamd_symbol_flags { + RSPAMD_SYMBOL_FLAG_NORMAL = 0, + RSPAMD_SYMBOL_FLAG_IGNORE = (1 << 1), + RSPAMD_SYMBOL_FLAG_ONEPARAM = (1 << 2), + RSPAMD_SYMBOL_FLAG_UNGROUPPED = (1 << 3), +}; /** * Symbol config definition @@ -125,7 +134,7 @@ struct rspamd_symbol { guint priority; struct rspamd_symbols_group *gr; /* Main group */ GPtrArray *groups; /* Other groups */ - guint flags; + enum rspamd_symbol_flags flags; gint nshots; }; diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c index 21a89c06e..59656392d 100644 --- a/src/libserver/cfg_rcl.c +++ b/src/libserver/cfg_rcl.c @@ -326,7 +326,7 @@ rspamd_rcl_group_handler (rspamd_mempool_t *pool, const ucl_object_t *obj, { struct rspamd_config *cfg = ud; struct rspamd_symbols_group *gr; - const ucl_object_t *val; + const ucl_object_t *val, *elt; struct rspamd_rcl_section *subsection; struct rspamd_rcl_symbol_data sd; @@ -343,6 +343,51 @@ rspamd_rcl_group_handler (rspamd_mempool_t *pool, const ucl_object_t *obj, return FALSE; } + if ((elt = ucl_object_lookup (obj, "one_shot")) != NULL) { + if (ucl_object_type (elt) != UCL_BOOLEAN) { + g_set_error (err, + CFG_RCL_ERROR, + EINVAL, + "one_shot attribute is not boolean for symbol: '%s'", + key); + + return FALSE; + } + if (ucl_object_toboolean (elt)) { + gr->flags |= RSPAMD_SYMBOL_GROUP_ONE_SHOT; + } + } + + if ((elt = ucl_object_lookup (obj, "disabled")) != NULL) { + if (ucl_object_type (elt) != UCL_BOOLEAN) { + g_set_error (err, + CFG_RCL_ERROR, + EINVAL, + "disabled attribute is not boolean for symbol: '%s'", + key); + + return FALSE; + } + if (ucl_object_toboolean (elt)) { + gr->flags |= RSPAMD_SYMBOL_GROUP_DISABLED; + } + } + + if ((elt = ucl_object_lookup (obj, "enabled")) != NULL) { + if (ucl_object_type (elt) != UCL_BOOLEAN) { + g_set_error (err, + CFG_RCL_ERROR, + EINVAL, + "enabled attribute is not boolean for symbol: '%s'", + key); + + return FALSE; + } + if (!ucl_object_toboolean (elt)) { + gr->flags |= RSPAMD_SYMBOL_GROUP_DISABLED; + } + } + sd.gr = gr; sd.cfg = cfg; @@ -1316,7 +1361,7 @@ rspamd_rcl_composite_handler (rspamd_mempool_t *pool, rspamd_config_add_symbol (cfg, composite_name, score, description, group, 0, - ucl_object_get_priority (obj) + 1, + ucl_object_get_priority (obj), /* No +1 as it is default... */ 1); elt = ucl_object_lookup (obj, "groups"); @@ -2194,18 +2239,6 @@ rspamd_rcl_config_init (struct rspamd_config *cfg, GHashTable *skip_sections) /* Group part */ rspamd_rcl_add_default_handler (sub, - "disabled", - rspamd_rcl_parse_struct_boolean, - G_STRUCT_OFFSET (struct rspamd_symbols_group, disabled), - 0, - "Disable symbols group"); - rspamd_rcl_add_default_handler (sub, - "enabled", - rspamd_rcl_parse_struct_boolean, - G_STRUCT_OFFSET (struct rspamd_symbols_group, disabled), - RSPAMD_CL_FLAG_BOOLEAN_INVERSE, - "Enable or disable symbols group"); - rspamd_rcl_add_default_handler (sub, "max_score", rspamd_rcl_parse_struct_double, G_STRUCT_OFFSET (struct rspamd_symbols_group, max_score), diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c index cc07c4007..5c6fc6672 100644 --- a/src/libserver/cfg_utils.c +++ b/src/libserver/cfg_utils.c @@ -1039,6 +1039,10 @@ rspamd_config_new_group (struct rspamd_config *cfg, const gchar *name) (rspamd_mempool_destruct_t)g_hash_table_unref, gr->symbols); gr->name = rspamd_mempool_strdup (cfg->cfg_pool, name); + if (strcmp (gr->name, "ungrouped") == 0) { + gr->flags |= RSPAMD_SYMBOL_GROUP_UNGROUPED; + } + g_hash_table_insert (cfg->groups, gr->name, gr); return gr; @@ -1684,10 +1688,7 @@ rspamd_config_add_symbol (struct rspamd_config *cfg, /* We also check group information in this case */ if (group != NULL && sym_def->gr != NULL && strcmp (group, sym_def->gr->name) != 0) { - msg_debug_config ("move symbol %s from group %s to %s", - sym_def->gr->name, group); - g_hash_table_remove (sym_def->gr->symbols, sym_def->name); sym_group = g_hash_table_lookup (cfg->groups, group); if (sym_group == NULL) { @@ -1695,8 +1696,13 @@ rspamd_config_add_symbol (struct rspamd_config *cfg, sym_group = rspamd_config_new_group (cfg, group); } - sym_def->gr = sym_group; - g_hash_table_insert (sym_group->symbols, sym_def->name, sym_def); + if (!(sym_group->flags & RSPAMD_SYMBOL_GROUP_UNGROUPED)) { + msg_debug_config ("move symbol %s from group %s to %s", + sym_def->gr->name, group); + g_hash_table_remove (sym_def->gr->symbols, sym_def->name); + sym_def->gr = sym_group; + g_hash_table_insert (sym_group->symbols, sym_def->name, sym_def); + } } return TRUE; @@ -1870,7 +1876,7 @@ rspamd_config_is_module_enabled (struct rspamd_config *cfg, gr = g_hash_table_lookup (cfg->groups, module_name); if (gr) { - if (gr->disabled) { + if (gr->flags & RSPAMD_SYMBOL_GROUP_DISABLED) { rspamd_plugins_table_push_elt (L, "disabled_explicitly", module_name); msg_info_config ("%s module %s is disabled in the configuration as " |