Commit 04b3e9e0 authored by Geoff Simmons's avatar Geoff Simmons

Add the .check_call() method.

parent 7edfb217
......@@ -1533,6 +1533,15 @@ Example:
XXX ...
#### BOOL xset.check\_call(INT n, ENUM select)
BOOL xset.check_call(
INT n=0,
ENUM {FIRST, LAST, UNIQUE} select=UNIQUE
)
XXX ...
#### BOOL xset.saved(ENUM which, INT n, ENUM select)
BOOL xset.saved(
......
......@@ -782,6 +782,81 @@ vmod_set_subroutine(VRT_CTX, struct VPFX(re2_set) *set, VCL_INT n,
return set->sub[idx];
}
VCL_BOOL
vmod_set_check_call(VRT_CTX, struct VPFX(re2_set) *set, VCL_INT n,
VCL_ENUM selects)
{
struct task_set_match *task;
int idx = 0;
VCL_STRING err;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(set, VMOD_RE2_SET_MAGIC);
if (set->sub == NULL) {
VNOTICE(ctx,
"%s.check_call(%jd): No subroutines were set for %s",
set->vcl_name, (intmax_t)n, set->vcl_name);
return (0);
}
/*
* XXX: considerable DRY with get_match_idx().
* get_match_idx() invokes VRT_fail(), but we need to log
* SLT_Notice here, and the two alternatives are hard to
* disentangle within get_match_idx(). An alternative would be to
* pass in a flag to get_match_idx() that chooses between the two,
* and then we have to add the flag everywhere else. Consider
* that if we add anything else that needs SLT_Notice.
*/
if (n > set->npatterns) {
VNOTICE(ctx, "%s.check_call(%jd): set has %d patterns",
set->vcl_name, (intmax_t)n, set->npatterns);
return (0);
}
if (n <= 0) {
if ((task = get_task_data(ctx, set)) == NULL) {
VNOTICE(ctx,
"%s.check_call() called without prior match",
set->vcl_name);
return (0);
}
if (task->nmatches == 0) {
VNOTICE(ctx, "%s.check_call(%jd): previous match was "
"unsuccessful", set->vcl_name, (intmax_t)n);
return (0);
}
if (task->nmatches > 1) {
if (selects == VENUM(UNIQUE)) {
VNOTICE(ctx, "%s.check_call(%jd): %ld "
"successful matches", set->vcl_name,
(intmax_t)n, task->nmatches);
return (0);
}
if (selects == VENUM(LAST))
idx = task->nmatches - 1;
else
assert(selects == VENUM(FIRST));
}
WS_Assert_Allocated(ctx->ws, task->matches,
task->nmatches * sizeof(int));
idx = task->matches[idx];
}
if (!vbit_test(set->added[SUBROUTINE], idx)) {
AN(selects);
VNOTICE(ctx,
"%s.check_call(%jd, %s): subroutine %d was not added",
set->vcl_name, n, selects, idx + 1);
return (0);
}
if ((err = VRT_check_call(ctx, set->sub[idx])) != NULL) {
VNOTICE(ctx, "%s.check_call(): %s", set->vcl_name, err);
return (0);
}
return (1);
}
VCL_BOOL
vmod_set_saved(VRT_CTX, struct vmod_re2_set *set, VCL_ENUM whichs, VCL_INT n,
VCL_ENUM selects)
......
This diff is collapsed.
......@@ -47,6 +47,9 @@
#define VERRNOMEM(ctx, fmt, ...) \
VFAIL((ctx), fmt ", out of space", __VA_ARGS__)
#define VNOTICE(ctx, fmt, ...) \
VSLb((ctx)->vsl, SLT_Notice, "vmod_re2: " fmt, __VA_ARGS__)
struct vmod_re2_regex {
unsigned magic;
#define VMOD_RE2_REGEX_MAGIC 0x5c3f6f24
......
......@@ -1401,6 +1401,10 @@ $Method SUB .subroutine(INT n=0, ENUM {FIRST, LAST, UNIQUE} select=UNIQUE)
XXX ...
$Method BOOL .check_call(INT n=0, ENUM {FIRST, LAST, UNIQUE} select=UNIQUE)
XXX ...
$Method BOOL .saved(ENUM {REGEX, STR, BE, INT, SUB} which=REGEX, INT n=0,
ENUM {FIRST, LAST, UNIQUE} select=UNIQUE)
......
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