Revert "Use the VCL_REGEX type"

The VCL_REGEX type requires that the pattern consist of constant strings only.

In contrast, with a STRING argument and compilation in this vmod, we can support
patterns to be constructed dynamically in vcl_init {}, which is a relevant
advantage.

I did consider to support both a STRING and a VCL_REGEX argument (both being
optional, requiring at least one to be set) but found no compelling reason
for using the VCL_REGEX type, because the pattern is checked anyway and it
does not make a relevant difference if that check happens at the VCC or
the vcl_init stage.

This reverts commit 0ee2f4ae.
parent 5892385e
......@@ -115,13 +115,13 @@ never changes during the lifetime of VCL, use ``match``.
.. _re.regex():
new xregex = re.regex(REGEX, INT limit, INT limit_recursion)
------------------------------------------------------------
new xregex = re.regex(STRING, INT limit, INT limit_recursion)
-------------------------------------------------------------
::
new xregex = re.regex(
REGEX,
STRING,
INT limit=1000,
INT limit_recursion=1000
)
......
......@@ -2,7 +2,7 @@ varnishtest "regex constructor errors"
varnish v1 -vcl { backend b { .host = "${bad_ip}"; } } -start
varnish v1 -errvcl {Regexp compilation error} {
varnish v1 -errvcl {vmod re: error compiling regex} {
import re from "${vmod_topbuild}/src/.libs/libvmod_re.so";
backend b { .host = "${bad_ip}"; }
......
......@@ -48,7 +48,7 @@
struct vmod_re_regex {
unsigned magic;
#define VMOD_RE_REGEX_MAGIC 0x955706ee
VCL_REGEX vre;
vre_t *vre;
struct vre_limits vre_limits;
};
......@@ -94,9 +94,10 @@ re_compile(const char *pattern, unsigned options, char *errbuf,
VCL_VOID
vmod_regex__init(VRT_CTX, struct vmod_re_regex **rep, const char *vcl_name,
VCL_REGEX vre, VCL_INT limit, VCL_INT limit_recursion)
VCL_STRING pattern, VCL_INT limit, VCL_INT limit_recursion)
{
struct vmod_re_regex *re;
vre_t *vre;
char errbuf[VRE_ERROR_LEN];
int erroffset;
const char *error;
......@@ -105,7 +106,7 @@ vmod_regex__init(VRT_CTX, struct vmod_re_regex **rep, const char *vcl_name,
AN(rep);
AZ(*rep);
AN(vcl_name);
AN(vre);
AN(pattern);
if (limit < 1) {
VRT_fail(ctx, "vmod re: invalid limit %ld in %s constructor",
......@@ -119,6 +120,14 @@ vmod_regex__init(VRT_CTX, struct vmod_re_regex **rep, const char *vcl_name,
return;
}
vre = re_compile(pattern, 0, errbuf, sizeof errbuf, &erroffset);
if (vre == NULL) {
VRT_fail(ctx, "vmod re: error compiling regex \"%s\" in %s "
"constructor: %s (at offset %d)", pattern, vcl_name,
errbuf, erroffset);
return;
}
ALLOC_OBJ(re, VMOD_RE_REGEX_MAGIC);
AN(re);
re->vre = vre;
......@@ -137,6 +146,8 @@ vmod_regex__fini(struct vmod_re_regex **rep)
re = *rep;
*rep = NULL;
CHECK_OBJ_NOTNULL(re, VMOD_RE_REGEX_MAGIC);
if (re->vre != NULL)
VRE_free(&re->vre);
FREE_OBJ(re);
}
......
......@@ -109,7 +109,7 @@ since it re-uses the compiled expression obtained at VCL
initialization. So if you are matching against a fixed pattern that
never changes during the lifetime of VCL, use ``match``.
$Object regex(REGEX, INT limit=1000, INT limit_recursion=1000)
$Object regex(STRING, INT limit=1000, INT limit_recursion=1000)
Description
Create a regex object with the given regular expression. The
......
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