diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-08-28 13:15:57 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-08-28 13:15:57 +0100 |
commit | dcbd11070d3c4b923fce55b30bb1ead93591296c (patch) | |
tree | 6bab2670c71b38c0436f2a6c3337c6608565b872 /src | |
parent | 1450a81b3d117c682611d09c1fce626cf501b69b (diff) | |
download | rspamd-dcbd11070d3c4b923fce55b30bb1ead93591296c.tar.gz rspamd-dcbd11070d3c4b923fce55b30bb1ead93591296c.zip |
Allow complex regexp rules as well.
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/regexp.c | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c index 6e67a3648..179446d3c 100644 --- a/src/plugins/regexp.c +++ b/src/plugins/regexp.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2012, Vsevolod Stakhov + * Copyright (c) 2009-2015, Vsevolod Stakhov * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -167,22 +167,48 @@ regexp_module_config (struct rspamd_config *cfg) SYMBOL_TYPE_NORMAL, -1); } else if (value->type == UCL_OBJECT) { - const gchar *description = NULL, *group = NULL, *metric = DEFAULT_METRIC; + const gchar *description = NULL, *group = NULL, + *metric = DEFAULT_METRIC; gdouble score = 0.0; - gboolean one_shot = FALSE; + gboolean one_shot = FALSE, is_lua = FALSE, valid_expression = TRUE; /* We have some lua table, extract its arguments */ elt = ucl_object_find_key (value, "callback"); if (elt == NULL || elt->type != UCL_USERDATA) { - msg_err ("no callback defined for regexp symbol: %s", ucl_object_key (value)); + + /* Try plain regexp expression */ + elt = ucl_object_find_any_key (value, "regexp", "re", NULL); + + if (elt != NULL && ucl_object_type (elt) == UCL_STRING) { + cur_item = rspamd_mempool_alloc0 (regexp_module_ctx->regexp_pool, + sizeof (struct regexp_module_item)); + cur_item->symbol = ucl_object_key (value); + if (!read_regexp_expression (regexp_module_ctx->regexp_pool, + cur_item, ucl_object_key (value), + ucl_obj_tostring (elt), cfg)) { + res = FALSE; + } + else { + valid_expression = TRUE; + } + } + else { + msg_err ( + "no callback/expression defined for regexp symbol: " + "%s", ucl_object_key (value)); + } } else { + is_lua = TRUE; cur_item = rspamd_mempool_alloc0 ( regexp_module_ctx->regexp_pool, sizeof (struct regexp_module_item)); cur_item->symbol = ucl_object_key (value); cur_item->lua_function = ucl_object_toclosure (value); + } + + if (cur_item && (is_lua || valid_expression)) { id = rspamd_symbols_cache_add_symbol (cfg->cache, cur_item->symbol, 0, |