]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Add routines to get count of captures and backrefs
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 1 Dec 2015 18:17:55 +0000 (18:17 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 1 Dec 2015 18:17:55 +0000 (18:17 +0000)
src/libutil/regexp.c
src/libutil/regexp.h

index 5ebcf7db8dbee28b76a47c8019f250656462e891..2bf21ca1e671fb34c52043b2f7c46dbfa6643598 100644 (file)
@@ -53,6 +53,7 @@ struct rspamd_regexp_s {
        gpointer ud;
        gint flags;
        gint ncaptures;
+       gint nbackref;
 };
 
 struct rspamd_regexp_cache {
@@ -340,6 +341,12 @@ fin:
                res->ncaptures = ncaptures;
        }
 
+       /* Check number of backrefs */
+       if (pcre_fullinfo (res->raw_re, res->extra, PCRE_INFO_BACKREFMAX,
+                       &ncaptures) == 0) {
+               res->nbackref = ncaptures;
+       }
+
        return res;
 }
 
@@ -476,6 +483,22 @@ rspamd_regexp_get_pattern (rspamd_regexp_t *re)
        return re->pattern;
 }
 
+gint
+rspamd_regexp_get_nbackrefs (rspamd_regexp_t *re)
+{
+       g_assert (re != NULL);
+
+       return re->nbackref;
+}
+
+gint
+rspamd_regexp_get_ncaptures (rspamd_regexp_t *re)
+{
+       g_assert (re != NULL);
+
+       return re->ncaptures;
+}
+
 gboolean
 rspamd_regexp_match (rspamd_regexp_t *re, const gchar *text, gsize len,
                gboolean raw)
index 1301e5dd90e3a83bc66fd4aeaeac7bd9f31d13d9..2c33f780dd72bbf1b63f85020afd5d05c23ee694 100644 (file)
@@ -110,6 +110,16 @@ gpointer rspamd_regexp_get_id (rspamd_regexp_t *re);
  */
 const char* rspamd_regexp_get_pattern (rspamd_regexp_t *re);
 
+/**
+ * Returns number of backreferences in a regexp
+ */
+gint rspamd_regexp_get_nbackrefs (rspamd_regexp_t *re);
+
+/**
+ * Returns number of capture groups in a regexp
+ */
+gint rspamd_regexp_get_ncaptures (rspamd_regexp_t *re);
+
 /**
  * Create new regexp cache
  * @return