aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_regexp.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2014-08-26 11:57:21 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2014-08-26 11:57:21 +0100
commit2cae92ba6e7c413e55ac29dee7863f78635caf0b (patch)
treef6dbaaecf6b872071e93bd50857a211a54c593b8 /src/lua/lua_regexp.c
parentcda7d9cd4da526883645a56c58cb333ac2b1e30b (diff)
downloadrspamd-2cae92ba6e7c413e55ac29dee7863f78635caf0b.tar.gz
rspamd-2cae92ba6e7c413e55ac29dee7863f78635caf0b.zip
Add create_cached for rspamd_regexp.
Diffstat (limited to 'src/lua/lua_regexp.c')
-rw-r--r--src/lua/lua_regexp.c22
1 files changed, 22 insertions, 0 deletions
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}
};
@@ -168,6 +170,26 @@ lua_regexp_get_cached (lua_State *L)
}
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)
{
struct rspamd_lua_regexp *re = lua_check_regexp (L);