Save ultimate match result as either the lowest error ...

... or the highest match
parent 38fd9c23
...@@ -489,6 +489,7 @@ struct re_iter_priv { ...@@ -489,6 +489,7 @@ struct re_iter_priv {
#define RE_ITER_PRIV_MAGIC 0x04383ab8 #define RE_ITER_PRIV_MAGIC 0x04383ab8
uint32_t options; uint32_t options;
int s; int s;
int ret;
VRT_CTX; VRT_CTX;
const vre_t *vre; const vre_t *vre;
PCRE2_SIZE startoffset; PCRE2_SIZE startoffset;
...@@ -548,6 +549,10 @@ reip_iter(struct re_iter_priv *reip, unsigned flush, ...@@ -548,6 +549,10 @@ reip_iter(struct re_iter_priv *reip, unsigned flush,
reip->startoffset, reip->options, reip->task, reip->startoffset, reip->options, reip->task,
reip->vre_limits); reip->vre_limits);
if ((reip->s < PCRE2_ERROR_NOMATCH && reip->s < reip->ret) ||
reip->s > reip->ret)
reip->ret = reip->s;
#ifdef ITERDBG #ifdef ITERDBG
VSLb(reip->ctx->vsl, SLT_Debug, "match=%d, subject=%.*s, len=%zd", VSLb(reip->ctx->vsl, SLT_Debug, "match=%d, subject=%.*s, len=%zd",
reip->s, len, subject, len); reip->s, len, subject, len);
...@@ -643,6 +648,7 @@ reip_match_body(struct re_iter_priv *reip, struct vmod_re_regex *re, ...@@ -643,6 +648,7 @@ reip_match_body(struct re_iter_priv *reip, struct vmod_re_regex *re,
VRT_CTX; VRT_CTX;
struct vmod_priv *task; struct vmod_priv *task;
uint32_t u; uint32_t u;
int r;
CHECK_OBJ_NOTNULL(reip, RE_ITER_PRIV_MAGIC); CHECK_OBJ_NOTNULL(reip, RE_ITER_PRIV_MAGIC);
CHECK_OBJ_NOTNULL(re, VMOD_RE_REGEX_MAGIC); CHECK_OBJ_NOTNULL(re, VMOD_RE_REGEX_MAGIC);
...@@ -715,14 +721,9 @@ reip_match_body(struct re_iter_priv *reip, struct vmod_re_regex *re, ...@@ -715,14 +721,9 @@ reip_match_body(struct re_iter_priv *reip, struct vmod_re_regex *re,
assert(reip->s != PCRE2_ERROR_PARTIAL); assert(reip->s != PCRE2_ERROR_PARTIAL);
if (reip->s > PCRE2_ERROR_NOMATCH) { r = reip->ret;
memset(reip, 0, sizeof *reip);
return (1);
}
// errror or no match
memset(reip, 0, sizeof *reip); memset(reip, 0, sizeof *reip);
return (0); return (r);
} }
VCL_BOOL VCL_BOOL
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment