|
|
@@ -2343,3 +2343,64 @@ rspamd_lua_require_function (lua_State *L, const gchar *modname, |
|
|
|
|
|
|
|
return FALSE; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
gboolean |
|
|
|
rspamd_lua_try_load_redis (lua_State *L, const ucl_object_t *obj, |
|
|
|
struct rspamd_config *cfg, gint *ref_id) |
|
|
|
{ |
|
|
|
gint res_pos, err_idx; |
|
|
|
struct rspamd_config **pcfg; |
|
|
|
|
|
|
|
/* Create results table */ |
|
|
|
lua_createtable (L, 0, 0); |
|
|
|
res_pos = lua_gettop (L); |
|
|
|
lua_pushcfunction (L, &rspamd_lua_traceback); |
|
|
|
err_idx = lua_gettop (L); |
|
|
|
|
|
|
|
/* Obtain function */ |
|
|
|
if (!rspamd_lua_require_function (L, "lua_redis", "try_load_redis_servers")) { |
|
|
|
msg_err_config ("cannot require lua_redis"); |
|
|
|
lua_pop (L, 2); |
|
|
|
|
|
|
|
return FALSE; |
|
|
|
} |
|
|
|
|
|
|
|
/* Function arguments */ |
|
|
|
ucl_object_push_lua (L, obj, true); |
|
|
|
pcfg = lua_newuserdata (L, sizeof (*pcfg)); |
|
|
|
rspamd_lua_setclass (L, "rspamd{config}", -1); |
|
|
|
*pcfg = cfg; |
|
|
|
lua_pushvalue (L, res_pos); |
|
|
|
|
|
|
|
if (lua_pcall (L, 0, 1, err_idx) != 0) { |
|
|
|
GString *tb; |
|
|
|
|
|
|
|
tb = lua_touserdata (L, -1); |
|
|
|
msg_err_config ("cannot call lua try_load_redis_servers script: %s", tb->str); |
|
|
|
g_string_free (tb, TRUE); |
|
|
|
lua_settop (L, 0); |
|
|
|
|
|
|
|
return FALSE; |
|
|
|
} |
|
|
|
|
|
|
|
if (lua_toboolean (L, -1)) { |
|
|
|
if (ref_id) { |
|
|
|
/* Ref table */ |
|
|
|
lua_pushvalue (L, res_pos); |
|
|
|
*ref_id = luaL_ref (L, LUA_REGISTRYINDEX); |
|
|
|
lua_settop (L, 0); |
|
|
|
} |
|
|
|
else { |
|
|
|
/* Leave it on the stack */ |
|
|
|
lua_settop (L, res_pos); |
|
|
|
} |
|
|
|
|
|
|
|
return TRUE; |
|
|
|
} |
|
|
|
else { |
|
|
|
lua_settop (L, 0); |
|
|
|
} |
|
|
|
|
|
|
|
return FALSE; |
|
|
|
} |