aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-12-20 20:23:29 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-12-20 20:23:29 +0000
commit4b7520470bfcb417f483384c360fa1b498632336 (patch)
treef9b668a551106613aa0cc182e324c02a1c9066af
parente325da73310bc36c61d318f587bbd7655781bd12 (diff)
downloadrspamd-4b7520470bfcb417f483384c360fa1b498632336.tar.gz
rspamd-4b7520470bfcb417f483384c360fa1b498632336.zip
[Minor] Store composite expression in composite structure
-rw-r--r--src/libserver/cfg_rcl.c1
-rw-r--r--src/libserver/composites.h1
-rw-r--r--src/lua/lua_cfg_file.c41
-rw-r--r--src/lua/lua_config.c2
4 files changed, 5 insertions, 40 deletions
diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c
index 62525c3eb..a41b391a0 100644
--- a/src/libserver/cfg_rcl.c
+++ b/src/libserver/cfg_rcl.c
@@ -1437,6 +1437,7 @@ rspamd_rcl_composite_handler (rspamd_mempool_t *pool,
rspamd_mempool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_composite));
composite->expr = expr;
composite->id = g_hash_table_size (cfg->composite_symbols);
+ composite->str_expr = composite_expression;
val = ucl_object_lookup (obj, "score");
if (val != NULL && ucl_object_todouble_safe (val, &score)) {
diff --git a/src/libserver/composites.h b/src/libserver/composites.h
index 9ae3fa5a2..6baa13c14 100644
--- a/src/libserver/composites.h
+++ b/src/libserver/composites.h
@@ -37,6 +37,7 @@ enum rspamd_composite_policy {
* Composite structure
*/
struct rspamd_composite {
+ const gchar *str_expr;
struct rspamd_expression *expr;
gint id;
enum rspamd_composite_policy policy;
diff --git a/src/lua/lua_cfg_file.c b/src/lua/lua_cfg_file.c
index daa8223ff..efd8c8820 100644
--- a/src/lua/lua_cfg_file.c
+++ b/src/lua/lua_cfg_file.c
@@ -95,12 +95,9 @@ void
rspamd_lua_post_load_config (struct rspamd_config *cfg)
{
lua_State *L = cfg->lua_state;
- const gchar *name, *val;
- gchar *sym;
- struct rspamd_expression *expr, *old_expr;
+ const gchar *name;
ucl_object_t *obj;
gsize keylen;
- GError *err = NULL;
/* First check all module options that may be overridden in 'config' global */
lua_getglobal (L, "config");
@@ -139,41 +136,5 @@ rspamd_lua_post_load_config (struct rspamd_config *cfg)
}
}
- /* Check composites */
- lua_getglobal (L, "composites");
-
- if (lua_istable (L, -1)) {
- /* Iterate */
- for (lua_pushnil (L); lua_next (L, -2); lua_pop (L, 1)) {
- /* 'key' is at index -2 and 'value' is at index -1 */
- /* Key must be a string and value must be a table */
- name = luaL_checkstring (L, -2);
- if (name != NULL && lua_isstring (L, -1)) {
- val = lua_tostring (L, -1);
- sym = rspamd_mempool_strdup (cfg->cfg_pool, name);
- if (!rspamd_parse_expression (val, 0, &composite_expr_subr, NULL,
- cfg->cfg_pool, &err, &expr)) {
- msg_err_config("cannot parse composite expression '%s': %s", val,
- err->message);
- g_error_free (err);
- err = NULL;
- continue;
- }
- /* Now check hash table for this composite */
- if ((old_expr =
- g_hash_table_lookup (cfg->composite_symbols,
- name)) != NULL) {
- msg_info_config("replacing composite symbol %s", name);
- g_hash_table_replace (cfg->composite_symbols, sym, expr);
- }
- else {
- g_hash_table_insert (cfg->composite_symbols, sym, expr);
- rspamd_symbols_cache_add_symbol (cfg->cache, sym,
- 0, NULL, NULL, SYMBOL_TYPE_COMPOSITE, -1);
- }
- }
- }
- }
-
lua_settop (L, 0);
}
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index c667e1510..4679b4ede 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -1966,6 +1966,8 @@ lua_config_add_composite (lua_State * L)
sizeof (struct rspamd_composite));
composite->expr = expr;
composite->id = g_hash_table_size (cfg->composite_symbols);
+ composite->str_expr = rspamd_mempool_strdup (cfg->cfg_pool,
+ expr_str);
g_hash_table_insert (cfg->composite_symbols,
(gpointer)name,
composite);