[master] a1c936c83 Generalize the VCL flag stuff a little bit.

Poul-Henning Kamp phk at FreeBSD.org
Tue Apr 13 17:23:05 UTC 2021


commit a1c936c83b56d1d5ee211dd550a555830ae44396
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Apr 13 15:09:16 2021 +0000

    Generalize the VCL flag stuff a little bit.

diff --git a/bin/varnishtest/tests/v00017.vtc b/bin/varnishtest/tests/v00017.vtc
index 17f94582d..6ed35abc6 100644
--- a/bin/varnishtest/tests/v00017.vtc
+++ b/bin/varnishtest/tests/v00017.vtc
@@ -101,7 +101,7 @@ varnish v1 -errvcl {/mask only allowed once} {
 	sub vcl_recv { if (client.ip ~ a) { return(pass); } }
 }
 
-varnish v1 -errvcl {Expected ACL flag after:} {
+varnish v1 -errvcl {Expected a flag at:} {
 	backend b { .host = "${localhost}"; }
 	acl a + foobar {
 		"10.0.1.0/22" / 22;
diff --git a/lib/libvcc/vcc_acl.c b/lib/libvcc/vcc_acl.c
index ac6ca3d87..6f595f7ad 100644
--- a/lib/libvcc/vcc_acl.c
+++ b/lib/libvcc/vcc_acl.c
@@ -692,7 +692,7 @@ void
 vcc_ParseAcl(struct vcc *tl)
 {
 	struct symbol *sym;
-	struct token *sign;
+	int sign;
 	struct acl acl[1];
 
 	INIT_OBJ(acl, VCC_ACL_MAGIC);
@@ -706,19 +706,20 @@ vcc_ParseAcl(struct vcc *tl)
 	ERRCHK(tl);
 	AN(sym);
 
-	while (tl->t->tok == '-' || tl->t->tok == '+') {
-		sign = tl->t;
-		vcc_NextToken(tl);
-		if (tl->t->b != sign->e) {
-			VSB_cat(tl->sb, "Expected ACL flag after:\n");
-			vcc_ErrWhere(tl, sign);
+	while (1) {
+		sign = vcc_IsFlag(tl);
+		if (tl->err) {
+			VSB_cat(tl->sb,
+			    "Valid ACL flags are `log` and `table`:\n");
 			return;
 		}
+		if (sign < 0)
+			break;
 		if (vcc_IdIs(tl->t, "log")) {
-			acl->flag_log = sign->tok == '+';
+			acl->flag_log = sign;
 			vcc_NextToken(tl);
 		} else if (vcc_IdIs(tl->t, "table")) {
-			acl->flag_table = sign->tok == '+';
+			acl->flag_table = sign;
 			vcc_NextToken(tl);
 		} else {
 			VSB_cat(tl->sb, "Unknown ACL flag:\n");
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index 76e923693..995399ab6 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -431,6 +431,7 @@ double vcc_DurationUnit(struct vcc *);
 void vcc_ByteVal(struct vcc *, double *);
 void vcc_Duration(struct vcc *tl, double *);
 unsigned vcc_UintVal(struct vcc *tl);
+int vcc_IsFlag(struct vcc *tl);
 
 /* vcc_var.c */
 sym_wildcard_t vcc_Var_Wildcard;
diff --git a/lib/libvcc/vcc_utils.c b/lib/libvcc/vcc_utils.c
index 9cc27c68b..6ecee46fb 100644
--- a/lib/libvcc/vcc_utils.c
+++ b/lib/libvcc/vcc_utils.c
@@ -357,3 +357,22 @@ vcc_ByteVal(struct vcc *tl, double *d)
 	vcc_NextToken(tl);
 	*d = v * sc;
 }
+
+/*--------------------------------------------------------------------*/
+
+int
+vcc_IsFlag(struct vcc *tl)
+{
+	struct token *sign;
+
+	if (tl->t->tok != '-' && tl->t->tok != '+')
+		return (-1);
+	sign = tl->t;
+	vcc_NextToken(tl);
+	if (tl->t->b != sign->e) {
+		VSB_cat(tl->sb, "Expected a flag at:\n");
+		vcc_ErrWhere(tl, sign);
+		return (-1);
+	}
+	return (sign->tok == '+' ? 1 : 0);
+}


More information about the varnish-commit mailing list