From: Vsevolod Stakhov Date: Tue, 26 Aug 2014 10:57:21 +0000 (+0100) Subject: Add create_cached for rspamd_regexp. X-Git-Tag: 0.7.0~80 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2cae92ba6e7c413e55ac29dee7863f78635caf0b;p=rspamd.git Add create_cached for rspamd_regexp. --- diff --git a/src/lua/lua_regexp.c b/src/lua/lua_regexp.c index c7c55bf53..e479110bb 100644 --- a/src/lua/lua_regexp.c +++ b/src/lua/lua_regexp.c @@ -25,6 +25,7 @@ #include "expressions.h" LUA_FUNCTION_DEF (regexp, create); +LUA_FUNCTION_DEF (regexp, create_cached); LUA_FUNCTION_DEF (regexp, get_cached); LUA_FUNCTION_DEF (regexp, get_pattern); LUA_FUNCTION_DEF (regexp, match); @@ -42,6 +43,7 @@ static const struct luaL_reg regexplib_m[] = { static const struct luaL_reg regexplib_f[] = { LUA_INTERFACE_DEF (regexp, create), LUA_INTERFACE_DEF (regexp, get_cached), + LUA_INTERFACE_DEF (regexp, create_cached), {NULL, NULL} }; @@ -167,6 +169,26 @@ lua_regexp_get_cached (lua_State *L) return 1; } +static int +lua_regexp_create_cached (lua_State *L) +{ + const gchar *line; + struct rspamd_lua_regexp *new, **pnew; + + line = luaL_checkstring (L, 1); + new = re_cache_check (line, regexp_static_pool); + if (new) { + pnew = lua_newuserdata (L, sizeof (struct rspamd_lua_regexp *)); + rspamd_lua_setclass (L, "rspamd{regexp}", -1); + *pnew = new; + } + else { + return lua_regexp_create (L); + } + + return 1; +} + static int lua_regexp_get_pattern (lua_State *L) {