diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-12-28 11:48:19 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-12-28 11:48:19 +0000 |
commit | 18b98e9580f732681e092c555d6ea784c9922018 (patch) | |
tree | 2c97b7d839f4ced852d258b633f6cd05bf2c705a | |
parent | 8f024cbada9079764c77734b8c3d54a7cfec69d1 (diff) | |
download | rspamd-18b98e9580f732681e092c555d6ea784c9922018.tar.gz rspamd-18b98e9580f732681e092c555d6ea784c9922018.zip |
[Minor] Add methods to get symbols cache checksum
-rw-r--r-- | src/libserver/symbols_cache.c | 8 | ||||
-rw-r--r-- | src/libserver/symbols_cache.h | 7 | ||||
-rw-r--r-- | src/lua/lua_config.c | 28 |
3 files changed, 43 insertions, 0 deletions
diff --git a/src/libserver/symbols_cache.c b/src/libserver/symbols_cache.c index 7b0ec47d4..c37147973 100644 --- a/src/libserver/symbols_cache.c +++ b/src/libserver/symbols_cache.c @@ -2208,3 +2208,11 @@ rspamd_symbols_cache_enable_symbol (struct symbols_cache *cache, item->enabled = TRUE; } } + +guint64 +rspamd_symbols_cache_get_cksum (struct symbols_cache *cache) +{ + g_assert (cache != NULL); + + return cache->cksum; +} diff --git a/src/libserver/symbols_cache.h b/src/libserver/symbols_cache.h index c9877a830..6be4de01c 100644 --- a/src/libserver/symbols_cache.h +++ b/src/libserver/symbols_cache.h @@ -261,4 +261,11 @@ gboolean rspamd_symbols_cache_process_settings (struct rspamd_task *task, */ gboolean rspamd_symbols_cache_is_checked (struct rspamd_task *task, struct symbols_cache *cache, const gchar *symbol); + +/** + * Returns checksum for all cache items + * @param cache + * @return + */ +guint64 rspamd_symbols_cache_get_cksum (struct symbols_cache *cache); #endif diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 43398dfe1..2d84e8b05 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -499,6 +499,13 @@ LUA_FUNCTION_DEF (config, add_periodic); LUA_FUNCTION_DEF (config, get_symbols_count); /*** + * @method rspamd_config:get_symbols_cksum() + * Returns checksum for all symbols in the cache + * @return {int64} boxed value of the 64 bit checksum + */ +LUA_FUNCTION_DEF (config, get_symbols_cksum); + +/*** * @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 @@ -584,6 +591,7 @@ static const struct luaL_reg configlib_m[] = { LUA_INTERFACE_DEF (config, add_on_load), LUA_INTERFACE_DEF (config, add_periodic), LUA_INTERFACE_DEF (config, get_symbols_count), + LUA_INTERFACE_DEF (config, get_symbols_cksum), LUA_INTERFACE_DEF (config, get_symbol_callback), LUA_INTERFACE_DEF (config, set_symbol_callback), LUA_INTERFACE_DEF (config, register_finish_script), @@ -2173,6 +2181,26 @@ lua_config_get_symbols_count (lua_State *L) } static gint +lua_config_get_symbols_cksum (lua_State *L) +{ + struct rspamd_config *cfg = lua_check_config (L, 1); + guint64 res = 0, *pres; + + if (cfg != NULL) { + res = rspamd_symbols_cache_get_cksum (cfg->cache); + } + else { + return luaL_error (L, "invalid arguments"); + } + + pres = lua_newuserdata (L, sizeof (res)); + *pres = res; + rspamd_lua_setclass (L, "rspamd{int64}", -1); + + return 1; +} + +static gint lua_config_get_symbol_callback (lua_State *L) { struct rspamd_config *cfg = lua_check_config (L, 1); |