Refactor match() to return the pcre2 match result

This is in preparation for body matching.
parent 21cfecc1
...@@ -156,12 +156,12 @@ vmod_regex__fini(struct vmod_re_regex **rep) ...@@ -156,12 +156,12 @@ vmod_regex__fini(struct vmod_re_regex **rep)
FREE_OBJ(re); FREE_OBJ(re);
} }
static VCL_BOOL static int
match(VRT_CTX, const vre_t *vre, VCL_STRING subject, struct vmod_priv *task, match(VRT_CTX, const vre_t *vre, VCL_STRING subject, struct vmod_priv *task,
const struct vre_limits *vre_limits) const struct vre_limits *vre_limits)
{ {
ov_t *ov; ov_t *ov;
int i, r = 0, s, nov[MAX_OV]; int i, s = PCRE2_ERROR_NOMEMORY, nov[MAX_OV];
size_t cp; size_t cp;
pcre2_match_context *re_ctx; pcre2_match_context *re_ctx;
pcre2_match_data *data; pcre2_match_data *data;
...@@ -176,7 +176,7 @@ match(VRT_CTX, const vre_t *vre, VCL_STRING subject, struct vmod_priv *task, ...@@ -176,7 +176,7 @@ match(VRT_CTX, const vre_t *vre, VCL_STRING subject, struct vmod_priv *task,
if ((task->priv = WS_Alloc(ctx->ws, sizeof(*ov))) == NULL) { if ((task->priv = WS_Alloc(ctx->ws, sizeof(*ov))) == NULL) {
VSLb(ctx->vsl, SLT_VCL_Error, "vmod re error: " VSLb(ctx->vsl, SLT_VCL_Error, "vmod re error: "
"insufficient workspace for backref data"); "insufficient workspace for backref data");
return 0; return (s);
} }
task->len = -1; task->len = -1;
AZ(task->methods); AZ(task->methods);
...@@ -194,7 +194,7 @@ match(VRT_CTX, const vre_t *vre, VCL_STRING subject, struct vmod_priv *task, ...@@ -194,7 +194,7 @@ match(VRT_CTX, const vre_t *vre, VCL_STRING subject, struct vmod_priv *task,
data = pcre2_match_data_create_from_pattern(re, NULL); data = pcre2_match_data_create_from_pattern(re, NULL);
if (data == NULL) { if (data == NULL) {
VRT_fail(ctx, "vmod_re: failed to create match data"); VRT_fail(ctx, "vmod_re: failed to create match data");
return 0; return (s);
} }
// END duplication with vre // END duplication with vre
...@@ -212,7 +212,7 @@ match(VRT_CTX, const vre_t *vre, VCL_STRING subject, struct vmod_priv *task, ...@@ -212,7 +212,7 @@ match(VRT_CTX, const vre_t *vre, VCL_STRING subject, struct vmod_priv *task,
0, data, re_ctx); 0, data, re_ctx);
if (s <= PCRE2_ERROR_NOMATCH) { if (s <= PCRE2_ERROR_NOMATCH) {
if (s < PCRE2_ERROR_NOMATCH) if (s < PCRE2_ERROR_PARTIAL)
VSLb(ctx->vsl, SLT_VCL_Error, VSLb(ctx->vsl, SLT_VCL_Error,
"vmod re: regex match returned %d", s); "vmod re: regex match returned %d", s);
goto out; goto out;
...@@ -234,14 +234,12 @@ match(VRT_CTX, const vre_t *vre, VCL_STRING subject, struct vmod_priv *task, ...@@ -234,14 +234,12 @@ match(VRT_CTX, const vre_t *vre, VCL_STRING subject, struct vmod_priv *task,
for ( ; i < MAX_OV; i++) for ( ; i < MAX_OV; i++)
ov->ovector[i] = -1; ov->ovector[i] = -1;
r = 1;
out: // XXX goto because this might be throw-away code out: // XXX goto because this might be throw-away code
AN(data); AN(data);
pcre2_match_data_free(data); pcre2_match_data_free(data);
if (re_ctx != NULL) if (re_ctx != NULL)
pcre2_match_context_free(re_ctx); pcre2_match_context_free(re_ctx);
return (r); return (s);
} }
static VCL_STRING static VCL_STRING
...@@ -334,8 +332,9 @@ vmod_regex_match(VRT_CTX, struct vmod_re_regex *re, VCL_STRING subject, ...@@ -334,8 +332,9 @@ vmod_regex_match(VRT_CTX, struct vmod_re_regex *re, VCL_STRING subject,
AN(task); AN(task);
task->len = 0; task->len = 0;
return match(ctx, re->vre, subject, task, return (match(ctx, re->vre, subject, task,
get_limits(re, &buf, limit, limit_recursion)); get_limits(re, &buf, limit, limit_recursion))
> PCRE2_ERROR_NOMATCH);
} }
VCL_STRING VCL_STRING
...@@ -391,7 +390,8 @@ vmod_match_dyn(VRT_CTX, struct vmod_priv *task, VCL_STRING pattern, ...@@ -391,7 +390,8 @@ vmod_match_dyn(VRT_CTX, struct vmod_priv *task, VCL_STRING pattern,
return 0; return 0;
} }
dyn_return = match(ctx, vre, subject, task, &limits); dyn_return = (match(ctx, vre, subject, task, &limits)
> PCRE2_ERROR_NOMATCH);
VRE_free(&vre); VRE_free(&vre);
return dyn_return; return dyn_return;
......
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