diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/fuzzy_storage.c | 23 | ||||
-rw-r--r-- | src/lua/lua_common.h | 2 | ||||
-rw-r--r-- | src/lua/lua_shingles.cxx | 8 |
3 files changed, 24 insertions, 9 deletions
diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c index 00f226532..c7a1af470 100644 --- a/src/fuzzy_storage.c +++ b/src/fuzzy_storage.c @@ -1288,7 +1288,7 @@ rspamd_fuzzy_check_callback(struct rspamd_fuzzy_reply *result, void *ud) if (session->ctx->lua_post_handler_cbref != -1) { /* Start lua post handler */ lua_State *L = session->ctx->cfg->lua_state; - int err_idx, ret; + int err_idx, ret, nargs = 9; lua_pushcfunction(L, &rspamd_lua_traceback); err_idx = lua_gettop(L); @@ -1319,8 +1319,15 @@ rspamd_fuzzy_check_callback(struct rspamd_fuzzy_reply *result, void *ud) lua_pushinteger(L, result->ts); /* TODO: add additional data maybe (encryption, pubkey, etc) */ rspamd_fuzzy_extensions_tolua(L, session); + /* We push shingles merely for commands that modify content to avoid extra work */ + if (is_shingle && cmd->cmd != FUZZY_CHECK) { + struct rspamd_shingle **pshingle = lua_newuserdata(L, sizeof(*pshingle)); + rspamd_lua_setclass(L, RSPAMD_LUA_SHINGLE_CLASS, -1); + *pshingle = &session->cmd.sgl; + nargs++; + } - if ((ret = lua_pcall(L, 9, LUA_MULTRET, err_idx)) != 0) { + if ((ret = lua_pcall(L, nargs, LUA_MULTRET, err_idx)) != 0) { msg_err("call to lua_post_handler lua " "script failed (%d): %s", ret, lua_tostring(L, -1)); @@ -1478,7 +1485,7 @@ rspamd_fuzzy_process_command(struct fuzzy_session *session) if (session->ctx->lua_pre_handler_cbref != -1) { /* Start lua pre handler */ lua_State *L = session->ctx->cfg->lua_state; - int err_idx, ret; + int err_idx, ret, nargs = 5; lua_pushcfunction(L, &rspamd_lua_traceback); err_idx = lua_gettop(L); @@ -1497,7 +1504,15 @@ rspamd_fuzzy_process_command(struct fuzzy_session *session) /* TODO: add additional data maybe (encryption, pubkey, etc) */ rspamd_fuzzy_extensions_tolua(L, session); - if ((ret = lua_pcall(L, 5, LUA_MULTRET, err_idx)) != 0) { + /* We push shingles merely for commands that modify content to avoid extra work */ + if (is_shingle && cmd->cmd != FUZZY_CHECK) { + struct rspamd_shingle **pshingle = lua_newuserdata(L, sizeof(*pshingle)); + rspamd_lua_setclass(L, RSPAMD_LUA_SHINGLE_CLASS, -1); + *pshingle = &session->cmd.sgl; + nargs++; + } + + if ((ret = lua_pcall(L, nargs, LUA_MULTRET, err_idx)) != 0) { msg_err("call to lua_pre_handler lua " "script failed (%d): %s", ret, lua_tostring(L, -1)); diff --git a/src/lua/lua_common.h b/src/lua/lua_common.h index accc6be86..23bccbd30 100644 --- a/src/lua/lua_common.h +++ b/src/lua/lua_common.h @@ -708,6 +708,8 @@ int rspamd_lua_geti(lua_State *L, int index, int i); #define RSPAMD_PREFIX_INDEX "PREFIX" #define RSPAMD_VERSION_INDEX "VERSION" +#define RSPAMD_LUA_SHINGLE_CLASS "rspamd{shingle}" + #ifdef WITH_LUA_TRACE extern ucl_object_t *lua_traces; #define LUA_TRACE_POINT \ diff --git a/src/lua/lua_shingles.cxx b/src/lua/lua_shingles.cxx index 355a9e7f2..b19a00c08 100644 --- a/src/lua/lua_shingles.cxx +++ b/src/lua/lua_shingles.cxx @@ -18,8 +18,6 @@ #include "shingles.h" #include "fmt/format.h" -#define RSPAMD_SHINGLE_CLASS "rspamd{shingle}" - /*** * @module rspamd_shingle * This module provides methods to work with text shingles @@ -58,9 +56,9 @@ static const struct luaL_reg shinglelib_m[] = { static struct rspamd_shingle * lua_check_shingle(lua_State *L, int pos) { - void *ud = rspamd_lua_check_udata(L, pos, RSPAMD_SHINGLE_CLASS); + void *ud = rspamd_lua_check_udata(L, pos, RSPAMD_LUA_SHINGLE_CLASS); luaL_argcheck(L, ud != nullptr, pos, "'shingle' expected"); - return static_cast<struct rspamd_shingle *>(ud); + return *static_cast<struct rspamd_shingle **>(ud); } static int @@ -117,6 +115,6 @@ lua_shingle_get_string(lua_State *L) void luaopen_shingle(lua_State *L) { - rspamd_lua_new_class(L, RSPAMD_SHINGLE_CLASS, shinglelib_m); + rspamd_lua_new_class(L, RSPAMD_LUA_SHINGLE_CLASS, shinglelib_m); lua_pop(L, 1); } |