]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Feature] Add method to get number of symbols in the cache
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 5 Apr 2016 16:26:28 +0000 (17:26 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 5 Apr 2016 16:26:28 +0000 (17:26 +0100)
src/libserver/symbols_cache.c
src/libserver/symbols_cache.h
src/lua/lua_config.c

index 862bd0f11c487db353444d1d7c6d157245f74a3e..eea7f84b29fdfab26a08191e8e80a7550862dad0 100644 (file)
@@ -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)
index e199741298e69f685f8da091aa73c01e2b457919..0874ac475702b1da49853ceffcc4b04b20e0071b 100644 (file)
@@ -117,6 +117,13 @@ gint rspamd_symbols_cache_find_symbol (struct symbols_cache *cache,
 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
index cbf68dd071e3025b1115de8199ab11622b993c37..aa4327b276415b58ce0e72db14b272822c6cd9af 100644 (file)
@@ -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)
 {