# endif
# endif
ssize_t regex_compile(TALLOC_CTX *ctx, regex_t **out, char const *pattern, size_t len,
- bool ignore_case, bool multiline, bool runtime);
+ bool ignore_case, bool multiline, bool subcaptures, bool runtime);
int regex_exec(regex_t *preg, char const *string, size_t len, regmatch_t pmatch[], size_t *nmatch);
# ifdef __cplusplus
}
talloc_free(vp);
- slen = regex_compile(ctx, &preg, value, strlen(value), false, false, true);
+ slen = regex_compile(ctx, &preg, value, strlen(value), false, false, false, true);
if (slen <= 0) {
fr_strerror_printf("Error at offset %zu compiling regex for %s: %s", -slen,
attribute, fr_strerror());
if (!fr_assert(a->da->type == PW_TYPE_STRING)) return -1;
- slen = regex_compile(NULL, &preg, a->vp_strvalue, a->vp_length, false, false, true);
+ slen = regex_compile(NULL, &preg, a->vp_strvalue, a->vp_length, false, false, false, true);
if (slen <= 0) {
fr_strerror_printf("Error at offset %zu compiling regex for %s: %s",
-slen, a->da->name, fr_strerror());
* @param len of pattern.
* @param ignore_case whether to do case insensitive matching.
* @param multiline If true $ matches newlines.
+ * @param subcaptures Whether to compile the regular expression to store subcapture
+ * data.
* @param runtime If false run the pattern through the PCRE JIT to convert it to machine code.
* This trades startup time (longer) for runtime performance (better).
* @return >= 1 on success, <= 0 on error. Negative value is offset of parse error.
*/
ssize_t regex_compile(TALLOC_CTX *ctx, regex_t **out, char const *pattern, size_t len,
- bool ignore_case, bool multiline, bool runtime)
+ bool ignore_case, bool multiline, bool subcaptures, bool runtime)
{
char const *error;
int offset;
if (ignore_case) cflags |= PCRE_CASELESS;
if (multiline) cflags |= PCRE_MULTILINE;
+ if (!subcaptures) cflags |= PCRE_NO_AUTO_CAPTURE;
preg = talloc_zero(ctx, regex_t);
talloc_set_destructor(preg, _regex_free);
* @param len of pattern.
* @param ignore_case Whether the match should be case ignore_case.
* @param multiline If true $ matches newlines.
+ * @param subcaptures Whether to compile the regular expression to store subcapture
+ * data.
* @param runtime Whether the compilation is being done at runtime.
* @return >= 1 on success, <= 0 on error. Negative value is offset of parse error.
* With POSIX regex we only give the correct offset for embedded \0 errors.
*/
ssize_t regex_compile(TALLOC_CTX *ctx, regex_t **out, char const *pattern, size_t len,
- bool ignore_case, bool multiline, UNUSED bool runtime)
+ bool ignore_case, bool multiline, bool subcaptures, UNUSED bool runtime)
{
int ret;
int cflags = REG_EXTENDED;
if (ignore_case) cflags |= REG_ICASE;
if (multiline) cflags |= REG_NEWLINE;
+ if (!subcaptures) cflags |= REG_NOSUB;
#ifndef HAVE_REGNCOMP
{
rad_assert(rhs_type == PW_TYPE_STRING);
rad_assert(rhs->strvalue);
slen = regex_compile(request, &rreg, rhs->strvalue, rhs_len,
- map->rhs->tmpl_iflag, map->rhs->tmpl_mflag, true);
+ map->rhs->tmpl_iflag, map->rhs->tmpl_mflag, true, true);
if (slen <= 0) {
REMARKER(rhs->strvalue, -slen, fr_strerror());
EVAL_DEBUG("FAIL %d", __LINE__);
}
slen = regex_compile(vpt, &preg, vpt->name, vpt->len,
- vpt->tmpl_iflag, vpt->tmpl_mflag, false);
+ vpt->tmpl_iflag, vpt->tmpl_mflag, true, false);
if (slen <= 0) {
char *spaces, *text;
/*
* Include substring matches.
*/
- slen = regex_compile(request, &preg, expr_p, talloc_array_length(expr_p) - 1, false, false, true);
+ slen = regex_compile(request, &preg, expr_p, talloc_array_length(expr_p) - 1, false, false, true, true);
if (slen <= 0) {
REMARKER(expr_p, -slen, fr_strerror());
/*
* Include substring matches.
*/
- slen = regex_compile(rr, &rr->preg, r->name + 1, strlen(r->name) - 1, true, false, false);
+ slen = regex_compile(rr, &rr->preg, r->name + 1, strlen(r->name) - 1, true, false, false, false);
if (slen <= 0) {
char *spaces, *text;