Adjust to new VRE interface

parent 184eefe0
...@@ -113,20 +113,19 @@ VRBT_GENERATE(assign_tree, assignment, entry, path_cmp) ...@@ -113,20 +113,19 @@ VRBT_GENERATE(assign_tree, assignment, entry, path_cmp)
void void
validation_init(void) validation_init(void)
{ {
const char *err; int err, off;
int off;
chars = VRE_compile( chars = VRE_compile(
"([^A-Za-z0-9 _\\-~.%:/\\[\\]@!$&()*+,;=]+)", 0, &err, &off); "([^A-Za-z0-9 _\\-~.%:/\\[\\]@!$&()*+,;=]+)", 0, &err, &off, 0);
AN(chars); AN(chars);
dots = VRE_compile( dots = VRE_compile(
"([^/]\\.\\.\\.[^/]*|[^/]*\\.\\.\\.[^/])", 0, &err, &off); "([^/]\\.\\.\\.[^/]*|[^/]*\\.\\.\\.[^/])", 0, &err, &off, 0);
AN(dots); AN(dots);
stars = VRE_compile( stars = VRE_compile(
"(.?\\*{2,}.?)", 0, &err, &off); "(.?\\*{2,}.?)", 0, &err, &off, 0);
AN(stars); AN(stars);
meta = VRE_compile( meta = VRE_compile(
"([[\\]$()+])", 0, &err, &off); "([[\\]$()+])", 0, &err, &off, 0);
AN(meta); AN(meta);
} }
...@@ -147,41 +146,42 @@ const char * ...@@ -147,41 +146,42 @@ const char *
valid(VRT_CTX, const char * restrict const path) valid(VRT_CTX, const char * restrict const path)
{ {
const char *errmsg = NULL; const char *errmsg = NULL;
int r, ovector[6]; int r;
txt groups[2];
size_t len; size_t len;
AN(path); AN(path);
len = strlen(path); len = strlen(path);
memset(ovector, 0, sizeof(ovector)); memset(groups, 0, sizeof groups);
r = VRE_exec(chars, path, len, 0, 0, ovector, 6, NULL); r = VRE_capture(chars, path, len, 0, groups, 2, NULL);
if (r >= 0) { if (r >= 0) {
if ((errmsg = WS_Printf(ctx->ws, if ((errmsg = WS_Printf(ctx->ws,
"invalid character(s) in pattern: %.*s", "invalid character(s) in pattern: %.*s",
ovector[3] - ovector[2], (int)(groups[1].e - groups[1].b),
path + ovector[2])) groups[1].b))
== NULL) == NULL)
return "invalid character(s) in pattern"; return "invalid character(s) in pattern";
return errmsg; return errmsg;
} }
memset(ovector, 0, sizeof(ovector)); memset(groups, 0, sizeof groups);
r = VRE_exec(dots, path, len, 0, 0, ovector, 6, NULL); r = VRE_capture(dots, path, len, 0, groups, 2, NULL);
if (r >= 0) { if (r >= 0) {
if ((errmsg = WS_Printf(ctx->ws, if ((errmsg = WS_Printf(ctx->ws,
"... must only be used before and " "... must only be used before and "
"after slashes: %.*s", "after slashes: %.*s",
ovector[3] - ovector[2], (int)(groups[1].e - groups[1].b),
path + ovector[2])) groups[1].b))
== NULL) == NULL)
return "... must only be used before and after slashes"; return "... must only be used before and after slashes";
return errmsg; return errmsg;
} }
memset(ovector, 0, sizeof(ovector)); memset(groups, 0, sizeof groups);
r = VRE_exec(stars, path, len, 0, 0, ovector, 6, NULL); r = VRE_capture(stars, path, len, 0, groups, 2, NULL);
if (r >= 0) { if (r >= 0) {
if ((errmsg = WS_Printf(ctx->ws, if ((errmsg = WS_Printf(ctx->ws,
"more than one *: %.*s", "more than one *: %.*s",
ovector[3] - ovector[2], (int)(groups[1].e - groups[1].b),
path + ovector[2])) groups[1].b))
== NULL) == NULL)
return "more than one *"; return "more than one *";
return errmsg; return errmsg;
...@@ -193,9 +193,9 @@ vre_t * ...@@ -193,9 +193,9 @@ vre_t *
pattern2re(VRT_CTX, const char * restrict const path) pattern2re(VRT_CTX, const char * restrict const path)
{ {
struct vsb *regex; struct vsb *regex;
const char *esc, *p, *end, *regex_errstr; const char *esc, *p, *end;
uintptr_t snap; uintptr_t snap;
int end_anchor = 1, regex_erroffset; int end_anchor = 1, err, off;
vre_t *re; vre_t *re;
AN(path); AN(path);
...@@ -250,8 +250,8 @@ pattern2re(VRT_CTX, const char * restrict const path) ...@@ -250,8 +250,8 @@ pattern2re(VRT_CTX, const char * restrict const path)
VSB_putc(regex, '$'); VSB_putc(regex, '$');
VSB_finish(regex); VSB_finish(regex);
re = VRE_compile(VSB_data(regex), 0, &regex_errstr, &regex_erroffset); re = VRE_compile(VSB_data(regex), 0, &err, &off, 0);
assert(re != NULL && regex_errstr == NULL); assert(re != NULL);
VSB_destroy(&regex); VSB_destroy(&regex);
WS_Reset(ctx->ws, snap); WS_Reset(ctx->ws, snap);
return re; return re;
......
...@@ -597,8 +597,7 @@ vmod_hosts_policy(VRT_CTX, struct vmod_hoailona_hosts *hosts, ...@@ -597,8 +597,7 @@ vmod_hosts_policy(VRT_CTX, struct vmod_hoailona_hosts *hosts,
VMOD_HOAILONA_PATTERN_MAGIC); VMOD_HOAILONA_PATTERN_MAGIC);
AN(a->pattern->re); AN(a->pattern->re);
match = VRE_exec(a->pattern->re, pathname, pathlen, match = VRE_match(a->pattern->re, pathname, pathlen, 0, NULL);
0, 0, NULL, 0, NULL);
if (match >= 0) { if (match >= 0) {
assignment = a; assignment = a;
break; break;
......
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