summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libserver/symbols_cache.c8
-rw-r--r--src/libserver/symbols_cache.h7
-rw-r--r--src/lua/lua_config.c26
3 files changed, 41 insertions, 0 deletions
diff --git a/src/libserver/symbols_cache.c b/src/libserver/symbols_cache.c
index 862bd0f11..eea7f84b2 100644
--- a/src/libserver/symbols_cache.c
+++ b/src/libserver/symbols_cache.c
@@ -1710,6 +1710,14 @@ rspamd_symbols_cache_symbol_by_id (struct symbols_cache *cache,
return item->symbol;
}
+guint
+rspamd_symbols_cache_symbols_count (struct symbols_cache *cache)
+{
+ g_assert (cache != NULL);
+
+ return cache->items_by_id->len;
+}
+
void
rspamd_symbols_cache_disable_symbol (struct rspamd_task *task,
struct symbols_cache *cache, const gchar *symbol)
diff --git a/src/libserver/symbols_cache.h b/src/libserver/symbols_cache.h
index e19974129..0874ac475 100644
--- a/src/libserver/symbols_cache.h
+++ b/src/libserver/symbols_cache.h
@@ -118,6 +118,13 @@ const gchar * rspamd_symbols_cache_symbol_by_id (struct symbols_cache *cache,
gint id);
/**
+ * Returns number of symbols registered in symbols cache
+ * @param cache
+ * @return number of symbols in the cache
+ */
+guint rspamd_symbols_cache_symbols_count (struct symbols_cache *cache);
+
+/**
* Call function for cached symbol using saved callback
* @param task task object
* @param cache symbols cache
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index cbf68dd07..aa4327b27 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -404,6 +404,13 @@ LUA_FUNCTION_DEF (config, register_worker_script);
*/
LUA_FUNCTION_DEF (config, add_on_load);
+/***
+ * @method rspamd_config:get_symbols_count()
+ * Returns number of symbols registered in rspamd configuration
+ * @return {number} number of symbols registered in the configuration
+ */
+LUA_FUNCTION_DEF (config, get_symbols_count);
+
static const struct luaL_reg configlib_m[] = {
LUA_INTERFACE_DEF (config, get_module_opt),
LUA_INTERFACE_DEF (config, get_mempool),
@@ -433,6 +440,7 @@ static const struct luaL_reg configlib_m[] = {
LUA_INTERFACE_DEF (config, replace_regexp),
LUA_INTERFACE_DEF (config, register_worker_script),
LUA_INTERFACE_DEF (config, add_on_load),
+ LUA_INTERFACE_DEF (config, get_symbols_count),
{"__tostring", rspamd_lua_class_tostring},
{"__newindex", lua_config_newindex},
{NULL, NULL}
@@ -1702,6 +1710,24 @@ lua_config_add_on_load (lua_State *L)
return 0;
}
+static gint
+lua_config_get_symbols_count (lua_State *L)
+{
+ struct rspamd_config *cfg = lua_check_config (L, 1);
+ guint res = 0;
+
+ if (cfg != NULL) {
+ res = rspamd_symbols_cache_symbols_count (cfg->cache);
+ }
+ else {
+ return luaL_error (L, "invalid arguments");
+ }
+
+ lua_pushnumber (L, res);
+
+ return 1;
+}
+
void
luaopen_config (lua_State * L)
{