From 6d3508fb34675bd329fc9fdd3bb17c7647ad47d2 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 9 Dec 2015 17:46:26 +0000 Subject: Fix pcre post-filtering --- src/lua/lua_regexp.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/lua') diff --git a/src/lua/lua_regexp.c b/src/lua/lua_regexp.c index d19ed83e6..385e974cc 100644 --- a/src/lua/lua_regexp.c +++ b/src/lua/lua_regexp.c @@ -43,6 +43,7 @@ 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, get_max_hits); LUA_FUNCTION_DEF (regexp, search); LUA_FUNCTION_DEF (regexp, match); LUA_FUNCTION_DEF (regexp, matchn); @@ -54,6 +55,7 @@ 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, get_max_hits), LUA_INTERFACE_DEF (regexp, match), LUA_INTERFACE_DEF (regexp, matchn), LUA_INTERFACE_DEF (regexp, search), @@ -271,7 +273,8 @@ 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 + * @param {number} lim limit in hits count + * @return {number} old number of max hits */ static int lua_regexp_set_max_hits (lua_State *L) @@ -291,6 +294,26 @@ lua_regexp_set_max_hits (lua_State *L) return 1; } +/*** + * @method re:get_max_hits(lim) + * Get maximum number of hits returned by a regexp + * @return {number} number of max hits + */ +static int +lua_regexp_get_max_hits (lua_State *L) +{ + struct rspamd_lua_regexp *re = lua_check_regexp (L); + + if (re && re->re && !IS_DESTROYED (re)) { + lua_pushnumber (L, rspamd_regexp_get_maxhits (re->re)); + } + else { + lua_pushnumber (L, 1); + } + + return 1; +} + /*** * @method re:search(line[, raw[, capture]]) * Search line in regular expression object. If line matches then this -- cgit v1.2.3