From 0e26d4843d7f993547e3d0acf5b91c5bb29ee743 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 1 Dec 2015 18:17:55 +0000 Subject: Add routines to get count of captures and backrefs --- src/libutil/regexp.c | 23 +++++++++++++++++++++++ src/libutil/regexp.h | 10 ++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/libutil/regexp.c b/src/libutil/regexp.c index 5ebcf7db8..2bf21ca1e 100644 --- a/src/libutil/regexp.c +++ b/src/libutil/regexp.c @@ -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) diff --git a/src/libutil/regexp.h b/src/libutil/regexp.h index 1301e5dd9..2c33f780d 100644 --- a/src/libutil/regexp.h +++ b/src/libutil/regexp.h @@ -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 -- cgit v1.2.3