]> source.dussan.org Git - rspamd.git/commitdiff
Store max hits inside rspamd_regexp_t
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 9 Dec 2015 14:34:39 +0000 (14:34 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 9 Dec 2015 14:34:39 +0000 (14:34 +0000)
src/libutil/regexp.c
src/libutil/regexp.h
src/lua/lua_regexp.c

index 9db0311097d866c8d4afeb18d2988981e559d8e0..39ff5ebf2f83403e4d3827c43c898078b8737dff 100644 (file)
@@ -53,6 +53,7 @@ struct rspamd_regexp_s {
        gpointer ud;
        gpointer re_class;
        guint64 cache_id;
+       guint max_hits;
        gint flags;
        gint pcre_flags;
        gint ncaptures;
@@ -250,6 +251,7 @@ fin:
        res->pattern = real_pattern;
        res->cache_id = RSPAMD_INVALID_ID;
        res->pcre_flags = regexp_flags;
+       res->max_hits = 0;
 
        if (rspamd_flags & RSPAMD_REGEXP_FLAG_RAW) {
                res->raw_re = r;
@@ -523,6 +525,26 @@ rspamd_regexp_get_ncaptures (rspamd_regexp_t *re)
        return re->ncaptures;
 }
 
+guint
+rspamd_regexp_get_maxhits (rspamd_regexp_t *re)
+{
+       g_assert (re != NULL);
+
+       return re->max_hits;
+}
+
+guint
+rspamd_regexp_set_maxhits (rspamd_regexp_t *re, guint new_maxhits)
+{
+       guint old_hits;
+
+       g_assert (re != NULL);
+       old_hits = re->max_hits;
+       re->max_hits = new_maxhits;
+
+       return old_hits;
+}
+
 guint64
 rspamd_regexp_get_cache_id (rspamd_regexp_t *re)
 {
index 8d3720f3eadebc7cff535d4cbc6e7794970c5c6e..0b585ceec5464f1c2d49566c8d0d6c776b8544a7 100644 (file)
@@ -121,6 +121,16 @@ guint rspamd_regexp_get_pcre_flags (rspamd_regexp_t *re);
  */
 guint rspamd_regexp_get_flags (rspamd_regexp_t *re);
 
+/**
+ * Set regexp maximum hits
+ */
+guint rspamd_regexp_get_maxhits (rspamd_regexp_t *re);
+
+/**
+ * Get regexp maximum hits
+ */
+guint rspamd_regexp_set_maxhits (rspamd_regexp_t *re, guint new_maxhits);
+
 /**
  * Returns number of backreferences in a regexp
  */
index b878d2a8d81bb544c26a3b506ecade7b149d154a..d19ed83e6f84bf2a552c9798945ced1d22e1361b 100644 (file)
@@ -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),
@@ -266,6 +268,29 @@ lua_regexp_set_limit (lua_State *L)
        return 0;
 }
 
+/***
+ * @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