refactor VRT_ban_string() error reporting

more re-use coming up in a PR
parent bffb264d
......@@ -829,6 +829,16 @@ VRT_synth_page(VRT_CTX, VCL_STRANDS s)
/*--------------------------------------------------------------------*/
static VCL_VOID
ban_error(VRT_CTX, VCL_STRING err)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
AN(ctx->vsl);
AN(err);
VSLb(ctx->vsl, SLT_VCL_Error, "ban(): %s", err);
}
VCL_VOID
VRT_ban_string(VRT_CTX, VCL_STRING str)
{
......@@ -839,22 +849,21 @@ VRT_ban_string(VRT_CTX, VCL_STRING str)
int i;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
AN(ctx->vsl);
if (str == NULL) {
VSLb(ctx->vsl, SLT_VCL_Error, "ban(): Null argument");
ban_error(ctx, "Null argument");
return;
}
bp = BAN_Build();
if (bp == NULL) {
VSLb(ctx->vsl, SLT_VCL_Error, "ban(): Out of Memory");
ban_error(ctx, "Out of Memory");
return;
}
av = VAV_Parse(str, NULL, ARGV_NOESC);
AN(av);
if (av[0] != NULL) {
VSLb(ctx->vsl, SLT_VCL_Error, "ban(): %s", av[0]);
ban_error(ctx, av[0]);
VAV_Free(av);
BAN_Abandon(bp);
return;
......@@ -862,25 +871,22 @@ VRT_ban_string(VRT_CTX, VCL_STRING str)
for (i = 0; ;) {
a1 = av[++i];
if (a1 == NULL) {
VSLb(ctx->vsl, SLT_VCL_Error,
"ban(): No ban conditions found.");
ban_error(ctx, "No ban conditions found.");
break;
}
a2 = av[++i];
if (a2 == NULL) {
VSLb(ctx->vsl, SLT_VCL_Error,
"ban(): Expected comparison operator.");
ban_error(ctx, "Expected comparison operator.");
break;
}
a3 = av[++i];
if (a3 == NULL) {
VSLb(ctx->vsl, SLT_VCL_Error,
"ban(): Expected second operand.");
ban_error(ctx, "Expected second operand.");
break;
}
err = BAN_AddTest(bp, a1, a2, a3);
if (err) {
VSLb(ctx->vsl, SLT_VCL_Error, "ban(): %s", err);
if (err != NULL) {
ban_error(ctx, err);
break;
}
if (av[++i] == NULL) {
......@@ -888,10 +894,11 @@ VRT_ban_string(VRT_CTX, VCL_STRING str)
if (err == NULL)
bp = NULL;
else
VSLb(ctx->vsl, SLT_VCL_Error, "ban(): %s", err);
ban_error(ctx, err);
break;
}
if (strcmp(av[i], "&&")) {
// XXX refactoring pending via PR
VSLb(ctx->vsl, SLT_VCL_Error,
"ban(): Expected && between conditions,"
" found \"%s\"", av[i]);
......
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