Switch to VCL_REGEX

parent 24911df3
...@@ -27,7 +27,7 @@ SYNOPSIS ...@@ -27,7 +27,7 @@ SYNOPSIS
# Set creation # Set creation
new <obj> = selector.set([BOOL case_sensitive] new <obj> = selector.set([BOOL case_sensitive]
[, BOOL allow_overlaps]) [, BOOL allow_overlaps])
VOID <obj>.add(STRING [, STRING string] [, STRING regex] VOID <obj>.add(STRING [, STRING string] [, REGEX regex]
[, BACKEND backend] [, INT integer] [, BOOL bool] [, BACKEND backend] [, INT integer] [, BOOL bool]
[, SUB sub]) [, SUB sub])
VOID <obj>.create_stats() VOID <obj>.create_stats()
...@@ -464,15 +464,15 @@ Examples:: ...@@ -464,15 +464,15 @@ Examples::
.. _xset.add(): .. _xset.add():
VOID xset.add(STRING, [STRING string], [STRING regex], [BACKEND backend], [INT integer], [BOOL bool], [SUB sub]) VOID xset.add(STRING, [STRING string], [REGEX regex], [BACKEND backend], [INT integer], [BOOL bool], [SUB sub])
---------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------
:: ::
VOID xset.add( VOID xset.add(
STRING, STRING,
[STRING string], [STRING string],
[STRING regex], [REGEX regex],
[BACKEND backend], [BACKEND backend],
[INT integer], [INT integer],
[BOOL bool], [BOOL bool],
......
...@@ -214,13 +214,13 @@ vmod_set_integer(VRT_CTX, struct vmod_selector_set * set, VCL_INT n, ...@@ -214,13 +214,13 @@ vmod_set_integer(VRT_CTX, struct vmod_selector_set * set, VCL_INT n,
return (set->table[idx]->integer); return (set->table[idx]->integer);
} }
static vre_t * VCL_REGEX
get_re(VRT_CTX, const struct vmod_selector_set * const restrict set, get_re(VRT_CTX, const struct vmod_selector_set * const restrict set,
VCL_INT n, VCL_STRING element, VCL_ENUM const restrict selects, VCL_INT n, VCL_STRING element, VCL_ENUM const restrict selects,
const char * const restrict method) const char * const restrict method)
{ {
unsigned idx; unsigned idx;
vre_t *re; VCL_REGEX re;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(set, VMOD_SELECTOR_SET_MAGIC); CHECK_OBJ_NOTNULL(set, VMOD_SELECTOR_SET_MAGIC);
...@@ -240,7 +240,7 @@ VCL_BOOL ...@@ -240,7 +240,7 @@ VCL_BOOL
vmod_set_re_match(VRT_CTX, struct vmod_selector_set *set, VCL_STRING subject, vmod_set_re_match(VRT_CTX, struct vmod_selector_set *set, VCL_STRING subject,
VCL_INT n, VCL_STRING element, VCL_ENUM selects) VCL_INT n, VCL_STRING element, VCL_ENUM selects)
{ {
vre_t *re; VCL_REGEX re;
re = get_re(ctx, set, n, element, selects, "re_match"); re = get_re(ctx, set, n, element, selects, "re_match");
if (re == NULL) if (re == NULL)
...@@ -253,7 +253,7 @@ vmod_set_sub(VRT_CTX, struct vmod_selector_set *set, VCL_STRING str, ...@@ -253,7 +253,7 @@ vmod_set_sub(VRT_CTX, struct vmod_selector_set *set, VCL_STRING str,
VCL_STRING sub, VCL_BOOL all, VCL_INT n, VCL_STRING element, VCL_STRING sub, VCL_BOOL all, VCL_INT n, VCL_STRING element,
VCL_ENUM selects) VCL_ENUM selects)
{ {
vre_t *re; VCL_REGEX re;
re = get_re(ctx, set, n, element, selects, "sub"); re = get_re(ctx, set, n, element, selects, "sub");
if (re == NULL) if (re == NULL)
......
...@@ -462,7 +462,7 @@ client c1 { ...@@ -462,7 +462,7 @@ client c1 {
logexpect l1 -wait logexpect l1 -wait
varnish v1 -errvcl {vmod selector failure: s.add(): cannot compile regular expression '(':} { varnish v1 -errvcl {Regexp compilation error:} {
import ${vmod_selector}; import ${vmod_selector};
backend b None; backend b None;
......
...@@ -431,8 +431,6 @@ vmod_set__fini(struct vmod_selector_set **setp) ...@@ -431,8 +431,6 @@ vmod_set__fini(struct vmod_selector_set **setp)
CHECK_OBJ_NOTNULL(entry, CHECK_OBJ_NOTNULL(entry,
VMOD_SELECTOR_ENTRY_MAGIC); VMOD_SELECTOR_ENTRY_MAGIC);
free(entry->string); free(entry->string);
if (entry->re != NULL)
VRE_free(&entry->re);
FREE_OBJ(entry); FREE_OBJ(entry);
break; break;
} }
...@@ -453,9 +451,7 @@ vmod_set_add(VRT_CTX, struct vmod_selector_set *set, ...@@ -453,9 +451,7 @@ vmod_set_add(VRT_CTX, struct vmod_selector_set *set,
{ {
struct entry *entry; struct entry *entry;
unsigned n; unsigned n;
vre_t *re = NULL; VCL_REGEX re = NULL;
const char *error;
int erroffset;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(set, VMOD_SELECTOR_SET_MAGIC); CHECK_OBJ_NOTNULL(set, VMOD_SELECTOR_SET_MAGIC);
...@@ -494,16 +490,8 @@ vmod_set_add(VRT_CTX, struct vmod_selector_set *set, ...@@ -494,16 +490,8 @@ vmod_set_add(VRT_CTX, struct vmod_selector_set *set,
*m = tolower(*m); *m = tolower(*m);
} }
if (args->valid_regex) { if (args->valid_regex)
/* XXX expose VRE options */ re = args->regex;
re = VRE_compile(args->regex, 0, &error, &erroffset);
if (re == NULL) {
VFAIL(ctx, "%s.add(): cannot compile regular expression"
" '%s': %s at offset %d", set->vcl_name,
args->regex, error, erroffset);
return;
}
}
if (!args->valid_string && re == NULL && !args->valid_backend if (!args->valid_string && re == NULL && !args->valid_backend
&& !args->valid_integer && !args->valid_bool && !args->valid_sub) && !args->valid_integer && !args->valid_bool && !args->valid_sub)
......
...@@ -59,7 +59,7 @@ struct entry { ...@@ -59,7 +59,7 @@ struct entry {
char *string; char *string;
VCL_BACKEND backend; VCL_BACKEND backend;
VCL_SUB sub; VCL_SUB sub;
vre_t *re; VCL_REGEX re;
VCL_INT integer; VCL_INT integer;
}; };
......
...@@ -23,7 +23,7 @@ SYNOPSIS ...@@ -23,7 +23,7 @@ SYNOPSIS
# Set creation # Set creation
new <obj> = selector.set([BOOL case_sensitive] new <obj> = selector.set([BOOL case_sensitive]
[, BOOL allow_overlaps]) [, BOOL allow_overlaps])
VOID <obj>.add(STRING [, STRING string] [, STRING regex] VOID <obj>.add(STRING [, STRING string] [, REGEX regex]
[, BACKEND backend] [, INT integer] [, BOOL bool] [, BACKEND backend] [, INT integer] [, BOOL bool]
[, SUB sub]) [, SUB sub])
VOID <obj>.create_stats() VOID <obj>.create_stats()
...@@ -448,7 +448,7 @@ Examples:: ...@@ -448,7 +448,7 @@ Examples::
# ... # ...
} }
$Method VOID .add(STRING, [STRING string], [STRING regex], [BACKEND backend], $Method VOID .add(STRING, [STRING string], [REGEX regex], [BACKEND backend],
[INT integer], [BOOL bool], [SUB sub]) [INT integer], [BOOL bool], [SUB sub])
Add the given string to the set. As indicated above, elements added to Add the given string to the set. As indicated above, elements added to
......
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