From: Vsevolod Stakhov Date: Wed, 28 Dec 2016 11:48:19 +0000 (+0000) Subject: [Minor] Add methods to get symbols cache checksum X-Git-Tag: 1.4.3~23^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=aee820262b05a9d7c87d27ab7cccd626455efc90;p=rspamd.git [Minor] Add methods to get symbols cache checksum --- diff --git a/src/libserver/symbols_cache.c b/src/libserver/symbols_cache.c index e57a45ce6..45aca9d2e 100644 --- a/src/libserver/symbols_cache.c +++ b/src/libserver/symbols_cache.c @@ -2196,3 +2196,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 7c2b84609..79faeb322 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -498,6 +498,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 @@ -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), @@ -2171,6 +2179,26 @@ lua_config_get_symbols_count (lua_State *L) return 1; } +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) {