Stop using VRT_re_*

parent 93a117ac
......@@ -113,17 +113,36 @@ VRBT_GENERATE(assign_tree, assignment, entry, path_cmp)
void
validation_init(void)
{
VRT_re_init((void **)&chars,
"([^A-Za-z0-9 _\\-~.%:/\\[\\]@!$&()*+,;=]+)");
const char *err;
int off;
chars = VRE_compile(
"([^A-Za-z0-9 _\\-~.%:/\\[\\]@!$&()*+,;=]+)", 0, &err, &off);
AN(chars);
VRT_re_init((void**)&dots, "([^/]\\.\\.\\.[^/]*|[^/]*\\.\\.\\.[^/])");
dots = VRE_compile(
"([^/]\\.\\.\\.[^/]*|[^/]*\\.\\.\\.[^/])", 0, &err, &off);
AN(dots);
VRT_re_init((void **)&stars, "(.?\\*{2,}.?)");
stars = VRE_compile(
"(.?\\*{2,}.?)", 0, &err, &off);
AN(stars);
VRT_re_init((void **)&meta, "([[\\]$()+])");
meta = VRE_compile(
"([[\\]$()+])", 0, &err, &off);
AN(meta);
}
void
validation_fini(void)
{
VRE_free(&chars);
AZ(chars);
VRE_free(&dots);
AZ(dots);
VRE_free(&stars);
AZ(stars);
VRE_free(&meta);
AZ(meta);
}
const char *
valid(VRT_CTX, const char * restrict const path)
{
......
......@@ -110,15 +110,25 @@ get_policy(VRT_CTX, const struct vmod_priv * restrict const,
/* Event function */
static int loadcnt = 0;
int v_matchproto_(vmod_event_f)
vmod_event(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e e)
{
(void) ctx;
(void) priv;
if (e == VCL_EVENT_LOAD)
validation_init();
return 0;
switch(e) {
case VCL_EVENT_LOAD:
if (loadcnt++ == 0)
validation_init();
return (0);
case VCL_EVENT_DISCARD:
if (--loadcnt == 0)
validation_fini();
return (0);
default:
return (0);
}
}
/* Object policy */
......@@ -295,7 +305,7 @@ vmod_hosts__fini(struct vmod_hoailona_hosts **hostsp)
if (a->pattern->path != NULL)
free(a->pattern->path);
if (a->pattern->re != NULL)
VRT_re_fini(a->pattern->re);
VRE_free(&a->pattern->re);
}
next_ass = VRBT_NEXT(assign_tree, a, a);
FREE_OBJ(a);
......@@ -436,7 +446,7 @@ vmod_hosts_add(VRT_CTX, struct vmod_hoailona_hosts *hosts,
result->policy->vcl_name, hostname, path,
hosts->vcl_name);
if (re != NULL)
VRT_re_fini(re);
VRE_free(&re);
return;
}
}
......
......@@ -75,6 +75,7 @@ int path_cmp(const struct assignment * restrict const ass_a,
VRBT_PROTOTYPE(assign_tree, assignment, entry, path_cmp)
void validation_init(void);
void validation_fini(void);
const char * valid(VRT_CTX, const char * restrict const path);
vre_t * pattern2re(VRT_CTX, const char * restrict const path);
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