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)
*/
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
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),
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)
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);