From: Vsevolod Stakhov Date: Tue, 1 Dec 2015 18:17:55 +0000 (+0000) Subject: Add routines to get count of captures and backrefs X-Git-Tag: 1.1.0~436 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0e26d4843d7f993547e3d0acf5b91c5bb29ee743;p=thirdparty%2Frspamd.git Add routines to get count of captures and backrefs --- diff --git a/src/libutil/regexp.c b/src/libutil/regexp.c index 5ebcf7db8d..2bf21ca1e6 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 1301e5dd90..2c33f780dd 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