diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-07-15 17:35:16 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-07-15 17:35:16 +0100 |
commit | 3262b2b175bb5de9eb3dbd68279f177a1b8b3e29 (patch) | |
tree | facf99da63cd2ffd0ece9ddbac545d84dd2945a8 | |
parent | 9e7c70034a91b90f09dd507b43214f84c05532ca (diff) | |
download | rspamd-3262b2b175bb5de9eb3dbd68279f177a1b8b3e29.tar.gz rspamd-3262b2b175bb5de9eb3dbd68279f177a1b8b3e29.zip |
[Feature] Implement composites policies
-rw-r--r-- | src/libserver/cfg_rcl.c | 17 | ||||
-rw-r--r-- | src/libserver/composites.c | 39 | ||||
-rw-r--r-- | src/libserver/composites.h | 12 |
3 files changed, 66 insertions, 2 deletions
diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c index a099ccda3..2869adacc 100644 --- a/src/libserver/cfg_rcl.c +++ b/src/libserver/cfg_rcl.c @@ -1430,7 +1430,7 @@ rspamd_rcl_composite_handler (rspamd_mempool_t *pool, } composite = - rspamd_mempool_alloc (cfg->cfg_pool, sizeof (struct rspamd_composite)); + rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_composite)); composite->expr = expr; composite->id = g_hash_table_size (cfg->composite_symbols); g_hash_table_insert (cfg->composite_symbols, @@ -1474,6 +1474,21 @@ rspamd_rcl_composite_handler (rspamd_mempool_t *pool, description, group, FALSE, FALSE); } + val = ucl_object_lookup (obj, "policy"); + + if (val) { + composite->policy = rspamd_composite_policy_from_str ( + ucl_object_tostring (val)); + + if (composite->policy == RSPAMD_COMPOSITE_POLICY_UNKNOWN) { + g_set_error (err, + CFG_RCL_ERROR, + EINVAL, + "composite %s has incorrect policy", composite_name); + return FALSE; + } + } + return TRUE; } diff --git a/src/libserver/composites.c b/src/libserver/composites.c index 917d1d0c3..bca87d23a 100644 --- a/src/libserver/composites.c +++ b/src/libserver/composites.c @@ -194,7 +194,21 @@ rspamd_composite_expr_process (gpointer input, rspamd_expression_atom_t *atom) nrd->ms = ms; /* By default remove symbols */ - nrd->action = (RSPAMD_COMPOSITE_REMOVE_SYMBOL|RSPAMD_COMPOSITE_REMOVE_WEIGHT); + switch (cd->composite->policy) { + case RSPAMD_COMPOSITE_POLICY_REMOVE_ALL: + default: + nrd->action = (RSPAMD_COMPOSITE_REMOVE_SYMBOL|RSPAMD_COMPOSITE_REMOVE_WEIGHT); + break; + case RSPAMD_COMPOSITE_POLICY_REMOVE_SYMBOL: + nrd->action = RSPAMD_COMPOSITE_REMOVE_SYMBOL; + break; + case RSPAMD_COMPOSITE_POLICY_REMOVE_WEIGHT: + nrd->action = RSPAMD_COMPOSITE_REMOVE_WEIGHT; + break; + case RSPAMD_COMPOSITE_POLICY_LEAVE: + nrd->action = 0; + break; + } for (;;) { t = *beg; @@ -381,3 +395,26 @@ rspamd_make_composites (struct rspamd_task *task) { g_hash_table_foreach (task->results, composites_metric_callback, task); } + + +enum rspamd_composite_policy +rspamd_composite_policy_from_str (const gchar *string) +{ + enum rspamd_composite_policy ret = RSPAMD_COMPOSITE_POLICY_UNKNOWN; + + if (strcmp (string, "remove") == 0 || strcmp (string, "remove_all") == 0 || + strcmp (string, "default") == 0) { + ret = RSPAMD_COMPOSITE_POLICY_REMOVE_ALL; + } + else if (strcmp (string, "remove_symbol") == 0) { + ret = RSPAMD_COMPOSITE_POLICY_REMOVE_SYMBOL; + } + else if (strcmp (string, "remove_weight") == 0) { + ret = RSPAMD_COMPOSITE_POLICY_REMOVE_WEIGHT; + } + else if (strcmp (string, "leave") == 0 || strcmp (string, "remove_none") == 0) { + ret = RSPAMD_COMPOSITE_POLICY_LEAVE; + } + + return ret; +} diff --git a/src/libserver/composites.h b/src/libserver/composites.h index 353e1734b..9ae3fa5a2 100644 --- a/src/libserver/composites.h +++ b/src/libserver/composites.h @@ -24,12 +24,22 @@ struct rspamd_task; * Subr for composite expressions */ extern const struct rspamd_atom_subr composite_expr_subr; + +enum rspamd_composite_policy { + RSPAMD_COMPOSITE_POLICY_REMOVE_ALL = 0, + RSPAMD_COMPOSITE_POLICY_REMOVE_SYMBOL, + RSPAMD_COMPOSITE_POLICY_REMOVE_WEIGHT, + RSPAMD_COMPOSITE_POLICY_LEAVE, + RSPAMD_COMPOSITE_POLICY_UNKNOWN +}; + /** * Composite structure */ struct rspamd_composite { struct rspamd_expression *expr; gint id; + enum rspamd_composite_policy policy; }; /** @@ -38,4 +48,6 @@ struct rspamd_composite { */ void rspamd_make_composites (struct rspamd_task *task); +enum rspamd_composite_policy rspamd_composite_policy_from_str (const gchar *string); + #endif /* SRC_LIBSERVER_COMPOSITES_H_ */ |