Commit 3d9d5c5b by Geoff Simmons

Reduce code duplication for set.string() and .backend().

parent b0bf452d
Pipeline #336 skipped
......@@ -810,76 +810,58 @@ vmod_set_nmatches(VRT_CTX, struct vmod_re2_set *set)
return task->nmatches;
}
VCL_STRING
vmod_set_string(VRT_CTX, struct vmod_re2_set *set, VCL_INT n)
static int
get_match_idx(VRT_CTX, struct vmod_re2_set *set, VCL_INT n, const char *method)
{
struct task_set_match *task;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(set, VMOD_RE2_SET_MAGIC);
if (n > set->npatterns) {
VERR(ctx, "%s.string(%lld): set has %d patterns", set->vcl_name,
n, set->npatterns);
return NULL;
VERR(ctx, "%s.%s(%lld): set has %d patterns", set->vcl_name,
method, n, set->npatterns);
return -1;
}
if (n > 0)
return set->string[n - 1];
return n - 1;
if ((task = get_task_data(ctx, set)) == NULL) {
VERR(ctx, "%s.string() called without prior match",
set->vcl_name);
return NULL;
VERR(ctx, "%s.%s() called without prior match", set->vcl_name,
method);
return -1;
}
if (task->nmatches == 0) {
VERR(ctx, "%s.string(%lld): previous match was unsuccessful",
set->vcl_name, n);
return NULL;
VERR(ctx, "%s.%s(%lld): previous match was unsuccessful",
set->vcl_name, method, n);
return -1;
}
if (task->nmatches > 1) {
VERR(ctx, "%s.string(%lld): %d successful matches",
set->vcl_name, n, task->nmatches);
return NULL;
VERR(ctx, "%s.%s(%lld): %d successful matches", set->vcl_name,
method, n, task->nmatches);
return -1;
}
WS_Assert_Allocated(ctx->ws, task->matches,
task->nmatches * sizeof(int));
return set->string[task->matches[0]];
return task->matches[0];
}
VCL_BACKEND
vmod_set_backend(VRT_CTX, struct vmod_re2_set *set, VCL_INT n)
VCL_STRING
vmod_set_string(VRT_CTX, struct vmod_re2_set *set, VCL_INT n)
{
struct task_set_match *task;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(set, VMOD_RE2_SET_MAGIC);
if (n > set->npatterns) {
VERR(ctx, "%s.backend(%lld): set has %d patterns",
set->vcl_name, n, set->npatterns);
return NULL;
}
if (n > 0)
return set->backend[n - 1];
if ((task = get_task_data(ctx, set)) == NULL) {
VERR(ctx, "%s.backend() called without prior match",
set->vcl_name);
int idx = get_match_idx(ctx, set, n, "string");
if (idx < 0)
return NULL;
}
return set->string[idx];
}
if (task->nmatches == 0) {
VERR(ctx, "%s.backend(%lld): previous match was unsuccessful",
set->vcl_name, n);
return NULL;
}
if (task->nmatches > 1) {
VERR(ctx, "%s.backend(%lld): %d successful matches",
set->vcl_name, n, task->nmatches);
VCL_BACKEND
vmod_set_backend(VRT_CTX, struct vmod_re2_set *set, VCL_INT n)
{
int idx = get_match_idx(ctx, set, n, "backend");
if (idx < 0)
return NULL;
}
WS_Assert_Allocated(ctx->ws, task->matches,
task->nmatches * sizeof(int));
return set->backend[task->matches[0]];
return set->backend[idx];
}
/* Regex function interface */
......
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