Stop using VRT_re_*

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