aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-08-07 08:14:04 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-08-07 08:14:04 +0100
commitbe8b130d14166145787f4e8e9b194b98c98c873d (patch)
tree222e8db4421b5ebdfb5fcd124eefdb40c6d174b5 /src
parent3f97820a4301e3062561e2a6339c111a208fb4fa (diff)
downloadrspamd-be8b130d14166145787f4e8e9b194b98c98c873d.tar.gz
rspamd-be8b130d14166145787f4e8e9b194b98c98c873d.zip
[Minor] Allow to detect torch support from Lua
Diffstat (limited to 'src')
-rw-r--r--src/lua/lua_config.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index b01b0c5a0..79dd11e76 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -639,6 +639,14 @@ LUA_FUNCTION_DEF (config, set_peak_cb);
*/
LUA_FUNCTION_DEF (config, get_cpu_flags);
+/***
+ * @method rspamd_config:has_torch()
+ * Returns true if Rspamd is compiled with torch support and the runtime CPU
+ * supports sse4.2 required for torch.
+ * @return {boolean} true if torch is compiled and supported
+ */
+LUA_FUNCTION_DEF (config, has_torch);
+
static const struct luaL_reg configlib_m[] = {
LUA_INTERFACE_DEF (config, get_module_opt),
LUA_INTERFACE_DEF (config, get_mempool),
@@ -686,6 +694,7 @@ static const struct luaL_reg configlib_m[] = {
LUA_INTERFACE_DEF (config, add_example),
LUA_INTERFACE_DEF (config, set_peak_cb),
LUA_INTERFACE_DEF (config, get_cpu_flags),
+ LUA_INTERFACE_DEF (config, get_cpu_flags),
{"__tostring", rspamd_lua_class_tostring},
{"__newindex", lua_config_newindex},
{NULL, NULL}
@@ -2870,6 +2879,33 @@ lua_config_get_cpu_flags (lua_State *L)
}
static gint
+lua_config_has_torch (lua_State *L)
+{
+ struct rspamd_config *cfg = lua_check_config (L, 1);
+ struct rspamd_cryptobox_library_ctx *crypto_ctx;
+
+ if (cfg != NULL) {
+ crypto_ctx = cfg->libs_ctx->crypto_ctx;
+#ifndef WITH_TORCH
+ lua_pushboolean (L, false);
+ (void)crypto_ctx;
+#else
+ if (crypto_ctx->cpu_config & CPUID_SSE42) {
+ lua_pushboolean (L, true);
+ }
+ else {
+ lua_pushboolean (L, false);
+ }
+#endif
+ }
+ else {
+ return luaL_error (L, "invalid arguments");
+ }
+
+ return 1;
+}
+
+static gint
lua_monitored_alive (lua_State *L)
{
struct rspamd_monitored *m = lua_check_monitored (L, 1);