[master] 6cf1138fd refactor VRT_ban_string() error reporting

Nils Goroll nils.goroll at uplex.de
Mon Dec 21 13:47:07 UTC 2020


commit 6cf1138fd0c397bb59ad4761a31c17087f32a292
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Mon Dec 21 14:44:36 2020 +0100

    refactor VRT_ban_string() error reporting
    
    more re-use coming up in a PR

diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index f5fa84ea3..3ceb7b775 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -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]);


More information about the varnish-commit mailing list