summaryrefslogtreecommitdiffstats
path: root/src/lua/lua_regexp.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-12-09 14:34:39 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-12-09 14:34:39 +0000
commitb6408a3c963d1bd73931d07004e99d921672d615 (patch)
tree564282d917690770cfb8237c6c2109b5ce2d0969 /src/lua/lua_regexp.c
parent86998b26779a19668828aca9753a7551d2a0daf7 (diff)
downloadrspamd-b6408a3c963d1bd73931d07004e99d921672d615.tar.gz
rspamd-b6408a3c963d1bd73931d07004e99d921672d615.zip
Store max hits inside rspamd_regexp_t
Diffstat (limited to 'src/lua/lua_regexp.c')
-rw-r--r--src/lua/lua_regexp.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/lua/lua_regexp.c b/src/lua/lua_regexp.c
index b878d2a8d..d19ed83e6 100644
--- a/src/lua/lua_regexp.c
+++ b/src/lua/lua_regexp.c
@@ -42,6 +42,7 @@ LUA_FUNCTION_DEF (regexp, create_cached);
LUA_FUNCTION_DEF (regexp, get_cached);
LUA_FUNCTION_DEF (regexp, get_pattern);
LUA_FUNCTION_DEF (regexp, set_limit);
+LUA_FUNCTION_DEF (regexp, set_max_hits);
LUA_FUNCTION_DEF (regexp, search);
LUA_FUNCTION_DEF (regexp, match);
LUA_FUNCTION_DEF (regexp, matchn);
@@ -52,6 +53,7 @@ LUA_FUNCTION_DEF (regexp, gc);
static const struct luaL_reg regexplib_m[] = {
LUA_INTERFACE_DEF (regexp, get_pattern),
LUA_INTERFACE_DEF (regexp, set_limit),
+ LUA_INTERFACE_DEF (regexp, set_max_hits),
LUA_INTERFACE_DEF (regexp, match),
LUA_INTERFACE_DEF (regexp, matchn),
LUA_INTERFACE_DEF (regexp, search),
@@ -267,6 +269,29 @@ lua_regexp_set_limit (lua_State *L)
}
/***
+ * @method re:set_max_hits(lim)
+ * Set maximum number of hits returned by a regexp
+ * @param {number} lim limit in bytes
+ */
+static int
+lua_regexp_set_max_hits (lua_State *L)
+{
+ struct rspamd_lua_regexp *re = lua_check_regexp (L);
+ guint lim;
+
+ lim = luaL_checknumber (L, 2);
+
+ if (re && re->re && !IS_DESTROYED (re)) {
+ lua_pushnumber (L, rspamd_regexp_set_maxhits (re->re, lim));
+ }
+ else {
+ lua_pushnil (L);
+ }
+
+ return 1;
+}
+
+/***
* @method re:search(line[, raw[, capture]])
* Search line in regular expression object. If line matches then this
* function returns the table of captured strings. Otherwise, nil is returned.