summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-05-30 14:07:59 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-05-30 14:07:59 +0100
commit7c15db236e7511e957c540968b0e205c2b1d2b95 (patch)
treef8bab349a5e9e38519e8c83100e4d729e3604819
parentd927a3a73c751adc21694262f0c931b8a6a55372 (diff)
downloadrspamd-7c15db236e7511e957c540968b0e205c2b1d2b95.tar.gz
rspamd-7c15db236e7511e957c540968b0e205c2b1d2b95.zip
[Project] Further reworks of rescore tool
-rw-r--r--lualib/rescore_utility.lua12
-rw-r--r--src/libserver/symbols_cache.c2
-rw-r--r--src/lua/lua_config.c47
3 files changed, 53 insertions, 8 deletions
diff --git a/lualib/rescore_utility.lua b/lualib/rescore_utility.lua
index 268e814d8..39ad63365 100644
--- a/lualib/rescore_utility.lua
+++ b/lualib/rescore_utility.lua
@@ -78,13 +78,13 @@ function utility.get_all_logs(dirs)
end
function utility.get_all_symbol_scores(conf, ignore_symbols)
- local counters = conf:get_symbols_counters()
+ local symbols = conf:get_symbols_scores()
- return fun.tomap(fun.map(function(elt)
- return elt['symbol'],elt['weight']
- end, fun.filter(function(elt)
- return not ignore_symbols[elt['symbol']]
- end, counters)))
+ return fun.tomap(fun.map(function(name, elt)
+ return name,elt['score']
+ end, fun.filter(function(name, elt)
+ return not ignore_symbols[name]
+ end, symbols)))
end
function utility.generate_statistics_from_logs(logs, threshold)
diff --git a/src/libserver/symbols_cache.c b/src/libserver/symbols_cache.c
index abed26fc3..23ad15ed1 100644
--- a/src/libserver/symbols_cache.c
+++ b/src/libserver/symbols_cache.c
@@ -2037,7 +2037,7 @@ rspamd_symbols_cache_counters (struct symbols_cache * cache)
top = ucl_object_typed_new (UCL_ARRAY);
cbd.top = top;
cbd.cache = cache;
- g_ptr_array_foreach (cache->items_by_order->d,
+ g_ptr_array_foreach (cache->items_by_id,
rspamd_symbols_cache_counters_cb, &cbd);
return top;
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index 73724fa51..f54411e88 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -546,6 +546,13 @@ LUA_FUNCTION_DEF (config, get_symbols_cksum);
LUA_FUNCTION_DEF (config, get_symbols_counters);
/***
+ * @method rspamd_config:get_symbols_scores()
+ * Returns table of all scores defined in config
+ * @return {table|tables} all symbols indexed by name
+ */
+LUA_FUNCTION_DEF (config, get_symbols_scores);
+
+/***
* @method rspamd_config:get_symbol_callback(name)
* Returns callback function for the specified symbol if it is a lua registered callback
* @return {function} callback function or nil
@@ -742,6 +749,7 @@ static const struct luaL_reg configlib_m[] = {
LUA_INTERFACE_DEF (config, get_symbols_count),
LUA_INTERFACE_DEF (config, get_symbols_cksum),
LUA_INTERFACE_DEF (config, get_symbols_counters),
+ LUA_INTERFACE_DEF (config, get_symbols_scores),
LUA_INTERFACE_DEF (config, get_symbol_callback),
LUA_INTERFACE_DEF (config, set_symbol_callback),
LUA_INTERFACE_DEF (config, get_symbol_stat),
@@ -2882,6 +2890,44 @@ lua_config_get_symbols_counters (lua_State *L)
return 1;
}
+static void
+lua_metric_symbol_inserter (gpointer k, gpointer v, gpointer ud)
+{
+ lua_State *L = (lua_State *) ud;
+ const gchar *sym = k;
+ struct rspamd_symbol *s = (struct rspamd_symbol *) v;
+
+ lua_pushstring (L, sym);
+
+ lua_createtable (L, 0, 3); /* TODO: add more if needed */
+ lua_pushstring (L, "score");
+ lua_pushnumber (L, s->score);
+ lua_settable (L, -3);
+ lua_pushstring (L, "description");
+ lua_pushstring (L, s->description);
+ lua_settable (L, -3);
+
+ lua_settable (L, -3);
+}
+
+static gint
+lua_config_get_symbols_scores (lua_State *L)
+{
+ struct rspamd_config *cfg = lua_check_config (L, 1);
+
+ if (cfg != NULL) {
+ lua_createtable (L, 0, g_hash_table_size (cfg->symbols));
+ g_hash_table_foreach (cfg->symbols,
+ lua_metric_symbol_inserter,
+ L);
+ }
+ else {
+ return luaL_error (L, "invalid arguments");
+ }
+
+ return 1;
+}
+
static gint
lua_config_get_symbol_callback (lua_State *L)
@@ -3334,7 +3380,6 @@ lua_config_parse_rcl (lua_State *L)
return luaL_error (L, "invalid arguments");
}
- rspamd_config_post_load (cfg, RSPAMD_CONFIG_INIT_SYMCACHE);
g_hash_table_unref (excluded);
rspamd_rcl_section_free (top);
lua_pushboolean (L, true);