r5133 - in trunk/varnish-cache: bin/varnishd bin/varnishtest/tests lib/libvcl

phk at varnish-cache.org phk at varnish-cache.org
Thu Aug 26 12:40:27 CEST 2010


Author: phk
Date: 2010-08-26 12:40:26 +0200 (Thu, 26 Aug 2010)
New Revision: 5133

Modified:
   trunk/varnish-cache/bin/varnishd/default.vcl
   trunk/varnish-cache/bin/varnishd/flint.lnt
   trunk/varnish-cache/bin/varnishtest/tests/c00022.vtc
   trunk/varnish-cache/bin/varnishtest/tests/v00010.vtc
   trunk/varnish-cache/bin/varnishtest/tests/v00018.vtc
   trunk/varnish-cache/lib/libvcl/vcc_action.c
   trunk/varnish-cache/lib/libvcl/vcc_expr.c
   trunk/varnish-cache/lib/libvcl/vcc_string.c
Log:
Push the new expressions into all other actions.

Get precedence of the implicit cast to STRING right.



Modified: trunk/varnish-cache/bin/varnishd/default.vcl
===================================================================
--- trunk/varnish-cache/bin/varnishd/default.vcl	2010-08-26 09:30:18 UTC (rev 5132)
+++ trunk/varnish-cache/bin/varnishd/default.vcl	2010-08-26 10:40:26 UTC (rev 5133)
@@ -126,13 +126,13 @@
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html>
   <head>
-    <title>"} obj.status " " obj.response {"</title>
+    <title>"} + obj.status + " " + obj.response + {"</title>
   </head>
   <body>
-    <h1>Error "} obj.status " " obj.response {"</h1>
-    <p>"} obj.response {"</p>
+    <h1>Error "} + obj.status + " " + obj.response + {"</h1>
+    <p>"} + obj.response + {"</p>
     <h3>Guru Meditation:</h3>
-    <p>XID: "} req.xid {"</p>
+    <p>XID: "} + req.xid + {"</p>
     <hr>
     <p>Varnish cache server</p>
   </body>

Modified: trunk/varnish-cache/bin/varnishd/flint.lnt
===================================================================
--- trunk/varnish-cache/bin/varnishd/flint.lnt	2010-08-26 09:30:18 UTC (rev 5132)
+++ trunk/varnish-cache/bin/varnishd/flint.lnt	2010-08-26 10:40:26 UTC (rev 5133)
@@ -73,6 +73,7 @@
 -efile(451, "http_headers.h")	// No include guard
 -efile(451, "stat_field.h")	// No include guard
 -efile(451, "acct_fields.h")	// No include guard
+-efile(451, "vcc_types.h")	// No include guard
 -efile(451, "config.h")	// No include guard
 //////////////
 // -e458			// unprotected access

Modified: trunk/varnish-cache/bin/varnishtest/tests/c00022.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/c00022.vtc	2010-08-26 09:30:18 UTC (rev 5132)
+++ trunk/varnish-cache/bin/varnishtest/tests/c00022.vtc	2010-08-26 10:40:26 UTC (rev 5133)
@@ -27,7 +27,7 @@
 			error 410;
 		}
 		if (req.request == "PURGESTR") {
-			purge ("" req.http.purge);
+			purge ("" + req.http.purge);
 			error 410;
 		}
 	}

Modified: trunk/varnish-cache/bin/varnishtest/tests/v00010.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/v00010.vtc	2010-08-26 09:30:18 UTC (rev 5132)
+++ trunk/varnish-cache/bin/varnishtest/tests/v00010.vtc	2010-08-26 10:40:26 UTC (rev 5133)
@@ -17,7 +17,7 @@
 
 	sub vcl_fetch {
 		if (beresp.http.panic) {
-			panic "Had Panic header: " beresp.http.panic;
+			panic "Had Panic header: " + beresp.http.panic;
 		}
 	}
 } -start

Modified: trunk/varnish-cache/bin/varnishtest/tests/v00018.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/v00018.vtc	2010-08-26 09:30:18 UTC (rev 5132)
+++ trunk/varnish-cache/bin/varnishtest/tests/v00018.vtc	2010-08-26 10:40:26 UTC (rev 5133)
@@ -15,8 +15,8 @@
 
 varnish v1 -vcl {
 	backend b { .host = "127.0.0.1"; }
-	sub vcl_miss { error req.url ; }
-	sub vcl_pass { error "the butter please" ; }
+	sub vcl_miss { error 100 req.url ; }
+	sub vcl_pass { error 100 "the butter please" ; }
 	sub vcl_fetch { error beresp.status req.url; }
 }
 

Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_action.c	2010-08-26 09:30:18 UTC (rev 5132)
+++ trunk/varnish-cache/lib/libvcl/vcc_action.c	2010-08-26 10:40:26 UTC (rev 5133)
@@ -65,24 +65,27 @@
 static void
 parse_error(struct vcc *tl)
 {
-	int paran = 0;
 
 	vcc_NextToken(tl);
+	Fb(tl, 1, "VRT_error(sp,\n");
 	if (tl->t->tok == '(') {
-		paran = 1;
 		vcc_NextToken(tl);
-	}
-	Fb(tl, 1, "VRT_error(sp,\n");
-	vcc_Expr(tl, INT);
-	if (tl->t->tok == ',') {
-		Fb(tl, 1, ",\n");
-		vcc_NextToken(tl);
-		vcc_Expr(tl, STRING);
+		vcc_Expr(tl, INT);
+		if (tl->t->tok == ',') {
+			Fb(tl, 1, ",\n");
+			vcc_NextToken(tl);
+			vcc_Expr(tl, STRING);
+		} else
+			Fb(tl, 1, ", 0\n");
+		SkipToken(tl, ')');
 	} else {
-		Fb(tl, 1, ", 0\n");
+		vcc_Expr(tl, INT);
+		if (tl->t->tok != ';') {
+			Fb(tl, 1, ",\n");
+			vcc_Expr(tl, STRING);
+		} else
+			Fb(tl, 1, ", 0\n");
 	}
-	if (paran)
-		SkipToken(tl, ')');
 	Fb(tl, 1, ");\n");
 	Fb(tl, 1, "VRT_done(sp, VCL_RET_ERROR);\n");
 }
@@ -235,10 +238,8 @@
 			}
 			vcc_NextToken(tl);
 			Fb(tl, 1, "  ");
-			if (!vcc_StringVal(tl)) {
-				vcc_ExpectedStringval(tl);
-				return;
-			}
+			vcc_Expr(tl, STRING);
+			ERRCHK(tl);
 			Fb(tl, 0, ",\n");
 			if (tl->t->tok == ')')
 				break;
@@ -250,13 +251,9 @@
 		tl->indent -= INDENT;
 	} else {
 		Fb(tl, 1, "VRT_ban_string(sp, ");
-		if (!vcc_StringVal(tl)) {
-			vcc_ExpectedStringval(tl);
-			return;
-		}
-		do
-			Fb(tl, 0, ", ");
-		while (vcc_StringVal(tl));
+		vcc_Expr(tl, STRING);
+		ERRCHK(tl);
+		Fb(tl, 0, ", ");
 		Fb(tl, 0, "vrt_magic_string_end);\n");
 	}
 
@@ -275,10 +272,8 @@
 	vcc_NextToken(tl);
 
 	Fb(tl, 1, "VRT_ban(sp, \"req.url\", \"~\", ");
-	if (!vcc_StringVal(tl)) {
-		vcc_ExpectedStringval(tl);
-		return;
-	}
+	vcc_Expr(tl, STRING);
+	ERRCHK(tl);
 	ExpectErr(tl, ')');
 	vcc_NextToken(tl);
 	Fb(tl, 0, ", 0);\n");
@@ -314,14 +309,9 @@
 	SkipToken(tl, '(');
 
 	Fb(tl, 1, "VRT_hashdata(sp, ");
-	if (!vcc_StringVal(tl)) {
-		vcc_ExpectedStringval(tl);
-		return;
-	}
-	do
-		Fb(tl, 0, ", ");
-	while (vcc_StringVal(tl));
-	Fb(tl, 0, " vrt_magic_string_end);\n");
+	vcc_Expr(tl, STRING);
+	ERRCHK(tl);
+	Fb(tl, 0, ", vrt_magic_string_end);\n");
 	SkipToken(tl, ')');
 }
 
@@ -333,14 +323,9 @@
 	vcc_NextToken(tl);
 
 	Fb(tl, 1, "VRT_panic(sp, ");
-	if (!vcc_StringVal(tl)) {
-		vcc_ExpectedStringval(tl);
-		return;
-	}
-	do
-		Fb(tl, 0, ", ");
-	while (vcc_StringVal(tl));
-	Fb(tl, 0, " vrt_magic_string_end);\n");
+	vcc_Expr(tl, STRING);
+	ERRCHK(tl);
+	Fb(tl, 0, ", vrt_magic_string_end);\n");
 }
 
 /*--------------------------------------------------------------------*/
@@ -393,14 +378,9 @@
 	vcc_NextToken(tl);
 
 	Fb(tl, 1, "VRT_synth_page(sp, 0, ");
-	if (!vcc_StringVal(tl)) {
-		vcc_ExpectedStringval(tl);
-		return;
-	}
-	do
-		Fb(tl, 0, ", ");
-	while (vcc_StringVal(tl));
-	Fb(tl, 0, " vrt_magic_string_end);\n");
+	vcc_Expr(tl, STRING);
+	ERRCHK(tl);
+	Fb(tl, 0, ", vrt_magic_string_end);\n");
 }
 
 /*--------------------------------------------------------------------*/
@@ -410,14 +390,9 @@
 	vcc_NextToken(tl);
 
 	Fb(tl, 1, "VRT_log(sp, ");
-	if (!vcc_StringVal(tl)) {
-		vcc_ExpectedStringval(tl);
-		return;
-	}
-	do
-		Fb(tl, 0, ", ");
-	while (vcc_StringVal(tl));
-	Fb(tl, 0, " vrt_magic_string_end);\n");
+	vcc_Expr(tl, STRING);
+	ERRCHK(tl);
+	Fb(tl, 0, ", vrt_magic_string_end);\n");
 }
 
 /*--------------------------------------------------------------------*/

Modified: trunk/varnish-cache/lib/libvcl/vcc_expr.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_expr.c	2010-08-26 09:30:18 UTC (rev 5132)
+++ trunk/varnish-cache/lib/libvcl/vcc_expr.c	2010-08-26 10:40:26 UTC (rev 5133)
@@ -359,14 +359,14 @@
 
 /*--------------------------------------------------------------------
  * SYNTAX:
- *    Expr4:
+ *    Expr5:
  *	'(' Expr0 ')'
  *	CNUM
  *	CSTR
  */
 
 static void
-vcc_expr4(struct vcc *tl, struct expr **e, enum var_type fmt)
+vcc_expr5(struct vcc *tl, struct expr **e, enum var_type fmt)
 {
 	struct expr *e1, *e2;
 	const struct symbol *sym;
@@ -470,6 +470,34 @@
 }
 
 /*--------------------------------------------------------------------
+ */
+static void
+vcc_expr4(struct vcc *tl, struct expr **e, enum var_type fmt)
+{
+	const char *p;
+
+	*e = NULL;
+	vcc_expr5(tl, e, fmt);
+	ERRCHK(tl);
+	if (fmt == STRING) {
+		p = NULL;
+		switch((*e)->fmt) {
+		case BACKEND:	p = "VRT_backend_string(sp, \v1)"; break;
+		case INT:	p = "VRT_int_string(sp, \v1)"; break;
+		case IP:	p = "VRT_IP_string(sp, \v1)"; break;
+		case TIME:	p = "VRT_time_string(sp, \v1)"; break;
+		case DURATION:	p = "VRT_double_string(sp, \v1)"; break;
+				/* XXX: should have "s" suffix ? */
+		default:	break;
+		}
+		if (p != NULL) {
+			*e = vcc_expr_edit(STRING, p, *e, NULL);
+			return;
+		}
+	}
+}
+
+/*--------------------------------------------------------------------
  * SYNTAX:
  *    Expr3:
  *      Expr4 { {'*'|'/'} Expr4 } *
@@ -497,6 +525,7 @@
 		tk = tl->t;
 		vcc_NextToken(tl);
 		vcc_expr4(tl, &e2, f2);
+		assert(e2->fmt == f2);
 		ERRCHK(tl);
 		if (tk->tok == '+')
 			*e = vcc_expr_edit(f3, "(\v1+\v2)", *e, e2);
@@ -526,9 +555,9 @@
 		*e = vcc_expr_edit(STRING, "\v+VRT_String(sp,\n\v1", *e, NULL);
 		while (tl->t->tok == '+') {
 			vcc_NextToken(tl);
-			vcc_expr0(tl, &e2, STRING);
+			vcc_expr_mul(tl, &e2, STRING);
 			assert(e2->fmt == STRING);
-			*e = vcc_expr_edit(STRING, "\v1, \v2", *e, e2);
+			*e = vcc_expr_edit(STRING, "\v1,\n\v2", *e, e2);
 		}
 		*e = vcc_expr_edit(STRING, "\v1, vrt_magic_string_end)",
 		    *e, NULL);
@@ -546,6 +575,7 @@
 	while (tl->t->tok == '+' || tl->t->tok == '-') {
 		vcc_NextToken(tl);
 		vcc_expr_mul(tl, &e2, f2);
+		assert(e2->fmt == f2);
 		ERRCHK(tl);
 		if (tl->t->tok == '+')
 			*e = vcc_expr_edit(f2, "(\v1+\v2)", *e, e2);
@@ -598,7 +628,6 @@
 	char buf[256];
 	char *re;
 	const char *not;
-	const char *p;
 	struct token *tk;
 
 	*e = NULL;
@@ -684,20 +713,6 @@
 			break;
 		}
 	}
-	if (fmt == STRING) {
-		p = NULL;
-		switch((*e)->fmt) {
-		case BACKEND:	p = "VRT_backend_string(sp, \v1)"; break;
-		case INT:	p = "VRT_int_string(sp, \v1)"; break;
-		case IP:	p = "VRT_IP_string(sp, \v1)"; break;
-		case TIME:	p = "VRT_time_string(sp, \v1)"; break;
-		default:	break;
-		}
-		if (p != NULL) {
-			*e = vcc_expr_edit(STRING, p, *e, NULL);
-			return;
-		}
-	}
 	if (fmt == VOID || fmt != (*e)->fmt) {
 		vsb_printf(tl->sb, "WANT: %s has %s next %.*s (%s)\n",
 		    vcc_Type(fmt), vcc_Type((*e)->fmt),

Modified: trunk/varnish-cache/lib/libvcl/vcc_string.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_string.c	2010-08-26 09:30:18 UTC (rev 5132)
+++ trunk/varnish-cache/lib/libvcl/vcc_string.c	2010-08-26 10:40:26 UTC (rev 5133)
@@ -77,134 +77,3 @@
 	Ff(tl, 0, "\tVRT_re_fini(%s);\n", buf);
 	return (p);
 }
-
-/*--------------------------------------------------------------------*/
-
-static int
-vcc_regsub(struct vcc *tl, int all)
-{
-	char *p;
-
-	vcc_NextToken(tl);
-
-	Fb(tl, 0, "VRT_regsub(sp, %d, ", all);
-
-	Expect(tl, '(');
-	if (tl->err)
-		return (0);
-	vcc_NextToken(tl);
-
-	if (!vcc_StringVal(tl)) {
-		vcc_ExpectedStringval(tl);
-		return (0);
-	}
-
-	Expect(tl, ',');
-	if (tl->err)
-		return (0);
-	vcc_NextToken(tl);
-
-	Expect(tl, CSTR);
-	if (tl->err)
-		return (0);
-	p = vcc_regexp(tl);
-	vcc_NextToken(tl);
-	Fb(tl, 0, ", %s, ", p);
-
-	Expect(tl, ',');
-	if (tl->err)
-		return (0);
-	vcc_NextToken(tl);
-
-	if (!vcc_StringVal(tl)) {
-		vcc_ExpectedStringval(tl);
-		return (0);
-	}
-
-	Expect(tl, ')');
-	if (tl->err)
-		return (0);
-	vcc_NextToken(tl);
-	Fb(tl, 0, ")");
-
-	return (1);
-}
-
-/*--------------------------------------------------------------------
- * Parse a string value and emit something that results in a usable
- * "const char *".
- * There are three possible outcomes:
- *	tl->err != 0 means something bad happened and a message is emitted.
- *	return (0) means "could not use this token"
- *	return (1) means "done"
- */
-
-int
-vcc_StringVal(struct vcc *tl)
-{
-	const struct var *vp;
-
-	if (tl->t->tok == CSTR) {
-		EncToken(tl->fb, tl->t);
-		vcc_NextToken(tl);
-		return (1);
-	}
-	if (tl->t->tok == ID && vcc_IdIs(tl->t, "regsub"))
-		return (vcc_regsub(tl, 0));
-	if (tl->t->tok == ID && vcc_IdIs(tl->t, "regsuball"))
-		return (vcc_regsub(tl, 1));
-	if (tl->t->tok == ID && vcc_IdIs(tl->t, "now")) {
-		Fb(tl, 0, "VRT_time_string(sp, VRT_r_now(sp))");
-		vcc_NextToken(tl);
-		return 1;
-	}
-	if (tl->t->tok == ID) {
-		vp = vcc_FindVar(tl, tl->t, 0, "cannot be read");
-		if (tl->err)
-			return (0);
-		assert(vp != NULL);
-		switch (vp->fmt) {
-		case STRING:
-			Fb(tl, 0, "%s", vp->rname);
-			break;
-		case IP:
-			Fb(tl, 0, "VRT_IP_string(sp, %s)", vp->rname);
-			break;
-		case INT:
-			Fb(tl, 0, "VRT_int_string(sp, %s)", vp->rname);
-			break;
-#if 0
-		case FLOAT:
-			Fb(tl, 0, "VRT_double_string(sp, %s)", vp->rname);
-			break;
-#endif
-		case TIME:
-			Fb(tl, 0, "VRT_time_string(sp, %s)", vp->rname);
-			break;
-		case DURATION:
-			Fb(tl, 0, "VRT_double_string(sp, %s)", vp->rname);
-			break;
-		case BACKEND:
-			Fb(tl, 0, "VRT_backend_string(sp, NULL)");
-			break;
-		default:
-			vsb_printf(tl->sb, "String representation of '%s'"
-			    " not implemented yet.\n", vp->name);
-			vcc_ErrWhere(tl, tl->t);
-			return (0);
-		}
-		vcc_NextToken(tl);
-		return (1);
-	}
-	return (0);
-}
-
-void
-vcc_ExpectedStringval(struct vcc *tl)
-{
-
-	if (!tl->err) {
-		vsb_printf(tl->sb, "Expected string variable or constant\n");
-		vcc_ErrWhere(tl, tl->t);
-	}
-}




More information about the varnish-commit mailing list