r5134 - in trunk/varnish-cache: bin/varnishd include lib/libvcl

phk at varnish-cache.org phk at varnish-cache.org
Thu Aug 26 15:12:55 CEST 2010


Author: phk
Date: 2010-08-26 15:12:55 +0200 (Thu, 26 Aug 2010)
New Revision: 5134

Modified:
   trunk/varnish-cache/bin/varnishd/cache_vrt.c
   trunk/varnish-cache/include/vrt.h
   trunk/varnish-cache/lib/libvcl/vcc_action.c
   trunk/varnish-cache/lib/libvcl/vcc_expr.c
   trunk/varnish-cache/lib/libvcl/vcc_parse.c
   trunk/varnish-cache/lib/libvcl/vcc_types.h
Log:
Introduce STRING_LIST type so we don't needlessly assemble strings on
the thrad workspace.

Fix multiplication.

Cleanup indentation in C-source output




Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt.c	2010-08-26 10:40:26 UTC (rev 5133)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt.c	2010-08-26 13:12:55 UTC (rev 5134)
@@ -1007,15 +1007,10 @@
 /*--------------------------------------------------------------------*/
 
 void
-VRT_log(struct sess *sp, const char *str, ...)
+VRT_log(struct sess *sp, const char *str)
 {
-	va_list ap;
-	char *b;
 
-	va_start(ap, str);
-	b = vrt_assemble_string(sp->http, NULL, str, ap);
-	va_end(ap);
-	WSP(sp, SLT_VCL_Log, "%s", b);
+	WSP(sp, SLT_VCL_Log, "%s", str);
 }
 
 /*--------------------------------------------------------------------*/
@@ -1056,22 +1051,16 @@
 /*--------------------------------------------------------------------*/
 
 void
-VRT_ban_string(struct sess *sp, const char *str, ...)
+VRT_ban_string(struct sess *sp, const char *str)
 {
-	char *p, *a1, *a2, *a3;
+	char *a1, *a2, *a3;
 	char **av;
-	va_list ap;
 	struct ban *b;
 	int good;
 	int i;
 
-	va_start(ap, str);
-	p = vrt_assemble_string(sp->http, NULL, str, ap);
-	if (p == NULL)
-		/* XXX: report error how ? */
-		return;
-
-	av = ParseArgv(p, 0);
+	(void)sp;
+	av = ParseArgv(str, 0);
 	if (av[0] != NULL) {
 		/* XXX: report error how ? */
 		FreeArgv(av);

Modified: trunk/varnish-cache/include/vrt.h
===================================================================
--- trunk/varnish-cache/include/vrt.h	2010-08-26 10:40:26 UTC (rev 5133)
+++ trunk/varnish-cache/include/vrt.h	2010-08-26 13:12:55 UTC (rev 5134)
@@ -153,9 +153,9 @@
 
 void VRT_panic(struct sess *sp, const char *, ...);
 void VRT_ban(struct sess *sp, char *, ...);
-void VRT_ban_string(struct sess *sp, const char *, ...);
+void VRT_ban_string(struct sess *sp, const char *);
 void VRT_purge(struct sess *sp, double ttl, double grace);
-void VRT_log(struct sess *, const char *msg, ...);
+void VRT_log(struct sess *, const char *msg);
 
 void VRT_count(const struct sess *, unsigned);
 int VRT_rewrite(const char *, const char *);

Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_action.c	2010-08-26 10:40:26 UTC (rev 5133)
+++ trunk/varnish-cache/lib/libvcl/vcc_action.c	2010-08-26 13:12:55 UTC (rev 5134)
@@ -146,10 +146,12 @@
 	}
 	if (ap->type == VOID)
 		SkipToken(tl, ap->oper);
-	vcc_Expr(tl, fmt);
-	if (vp->fmt == STRING)
-		Fb(tl, 1, ", vrt_magic_string_end");
-	Fb(tl, 0, ");\n");
+	if (fmt == STRING) {
+		vcc_Expr(tl, STRING_LIST);
+	} else {
+		vcc_Expr(tl, fmt);
+	}
+	Fb(tl, 1, ");\n");
 }
 
 /*--------------------------------------------------------------------*/
@@ -253,8 +255,7 @@
 		Fb(tl, 1, "VRT_ban_string(sp, ");
 		vcc_Expr(tl, STRING);
 		ERRCHK(tl);
-		Fb(tl, 0, ", ");
-		Fb(tl, 0, "vrt_magic_string_end);\n");
+		Fb(tl, 0, ");\n");
 	}
 
 	ExpectErr(tl, ')');
@@ -309,9 +310,9 @@
 	SkipToken(tl, '(');
 
 	Fb(tl, 1, "VRT_hashdata(sp, ");
-	vcc_Expr(tl, STRING);
+	vcc_Expr(tl, STRING_LIST);
 	ERRCHK(tl);
-	Fb(tl, 0, ", vrt_magic_string_end);\n");
+	Fb(tl, 0, ");\n");
 	SkipToken(tl, ')');
 }
 
@@ -378,9 +379,9 @@
 	vcc_NextToken(tl);
 
 	Fb(tl, 1, "VRT_synth_page(sp, 0, ");
-	vcc_Expr(tl, STRING);
+	vcc_Expr(tl, STRING_LIST);
 	ERRCHK(tl);
-	Fb(tl, 0, ", vrt_magic_string_end);\n");
+	Fb(tl, 0, ");\n");
 }
 
 /*--------------------------------------------------------------------*/
@@ -392,7 +393,7 @@
 	Fb(tl, 1, "VRT_log(sp, ");
 	vcc_Expr(tl, STRING);
 	ERRCHK(tl);
-	Fb(tl, 0, ", vrt_magic_string_end);\n");
+	Fb(tl, 0, ");\n");
 }
 
 /*--------------------------------------------------------------------*/

Modified: trunk/varnish-cache/lib/libvcl/vcc_expr.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_expr.c	2010-08-26 10:40:26 UTC (rev 5133)
+++ trunk/varnish-cache/lib/libvcl/vcc_expr.c	2010-08-26 13:12:55 UTC (rev 5134)
@@ -247,38 +247,68 @@
  * XXX: check line lengths in edit, should pass indent in for this
  */
 
+static void
+vcc_show(const char *p)
+{
+
+	fprintf(stderr, "<");
+	for (; *p; p++) {
+		if (*p == '\n')
+			fprintf(stderr, "\\n");
+		else if (*p == '\v')
+			fprintf(stderr, "\\v");
+		else
+			fprintf(stderr, "%c", *p);
+	}
+	fprintf(stderr, ">\n");
+}
+
+
 static struct expr *
 vcc_expr_edit(enum var_type fmt, const char *p, struct expr *e1, struct expr *e2)
 {
 	struct expr *e;
-	char *q;
+	int nl = 1;
 
-	q = strchr(vsb_data(e1->vsb), '\n');
-	if (q == NULL && e2 != NULL)
-		q = strchr(vsb_data(e2->vsb), '\n');
+	fprintf(stderr, "EDIT:");
+	vcc_show(p);
+	if (e1 != NULL) {
+		fprintf(stderr, "E1:");
+		vcc_show(vsb_data(e1->vsb));
+	}
+	if (e2 != NULL) {
+		fprintf(stderr, "E2:");
+		vcc_show(vsb_data(e2->vsb));
+	}
+
 	e = vcc_new_expr();
 	while (*p != '\0') {
+		if (*p == '\n') {
+			if (!nl) 
+				vsb_putc(e->vsb, *p);
+			nl = 1;
+			p++;
+			continue;
+		}
+		nl = 0;
 		if (*p != '\v') {
 			vsb_putc(e->vsb, *p);
 			p++;
 			continue;
 		} 
+		assert(*p == '\v');
 		p++;
 		switch(*p) {
 		case '+': vsb_cat(e->vsb, "\v+"); break;
 		case '-': vsb_cat(e->vsb, "\v-"); break;
 		case '1': 
 		case '2': 
-			if (q != NULL) 
-				vsb_cat(e->vsb, "\v+\n");
 			if (*p == '1')
 				vsb_cat(e->vsb, vsb_data(e1->vsb));
 			else {
 				AN(e2);
 				vsb_cat(e->vsb, vsb_data(e2->vsb));
 			}
-			if (q != NULL) 
-				vsb_cat(e->vsb, "\v-\n");
 			break;
 		default:
 			assert(__LINE__ == 0);
@@ -290,6 +320,8 @@
 	vcc_delete_expr(e1);
 	vcc_delete_expr(e2);
 	e->fmt = fmt;
+	fprintf(stderr, "RESULT:");
+	vcc_show(vsb_data(e->vsb));
 	return (e);
 }
 
@@ -479,7 +511,7 @@
 	*e = NULL;
 	vcc_expr5(tl, e, fmt);
 	ERRCHK(tl);
-	if (fmt == STRING) {
+	if (fmt == STRING || fmt == STRING_LIST) {
 		p = NULL;
 		switch((*e)->fmt) {
 		case BACKEND:	p = "VRT_backend_string(sp, \v1)"; break;
@@ -491,7 +523,7 @@
 		default:	break;
 		}
 		if (p != NULL) {
-			*e = vcc_expr_edit(STRING, p, *e, NULL);
+			*e = vcc_expr_edit(fmt, p, *e, NULL);
 			return;
 		}
 	}
@@ -521,16 +553,16 @@
 	default:
 		return;
 	}
-	while (tl->t->tok == '+' || tl->t->tok == '-') {
+	while (tl->t->tok == '*' || tl->t->tok == '/') {
 		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);
+		if (tk->tok == '*')
+			*e = vcc_expr_edit(f3, "(\v1*\v2)", *e, e2);
 		else
-			*e = vcc_expr_edit(f3, "(\v1-\v2)", *e, e2);
+			*e = vcc_expr_edit(f3, "(\v1/\v2)", *e, e2);
 	}
 }
 
@@ -551,6 +583,17 @@
 	ERRCHK(tl);
 	f2 = (*e)->fmt;
 
+	if (fmt == STRING_LIST && f2 == STRING) {
+		if (f2 == STRING)
+			(*e)->fmt = STRING_LIST;
+		while (tl->t->tok == '+') {
+			vcc_NextToken(tl);
+			vcc_expr_mul(tl, &e2, STRING);
+			*e = vcc_expr_edit(STRING_LIST, "\v1,\n\v2", *e, e2);
+		}
+		return;
+	}
+
 	if (f2 == STRING && tl->t->tok == '+') {
 		*e = vcc_expr_edit(STRING, "\v+VRT_String(sp,\n\v1", *e, NULL);
 		while (tl->t->tok == '+') {
@@ -735,14 +778,16 @@
 	*e = NULL;
 	vcc_expr_cmp(tl, e, fmt);
 	ERRCHK(tl);
-	if ((*e)->fmt != BOOL) 
+	if ((*e)->fmt != BOOL || tl->t->tok != T_CAND)
 		return;
+	*e = vcc_expr_edit(BOOL, "(\v+\n\v1", *e, NULL);
 	while (tl->t->tok == T_CAND) {
 		vcc_NextToken(tl);
 		vcc_expr_cmp(tl, &e2, fmt);
 		ERRCHK(tl);
-		*e = vcc_expr_edit(BOOL, "(\v1&&\v2)", *e, e2);
+		*e = vcc_expr_edit(BOOL, "\v1\v-\n&&\v+\n\v2", *e, e2);
 	}
+	*e = vcc_expr_edit(BOOL, "\v1\v-\n)", *e, NULL);
 }
 
 /*--------------------------------------------------------------------
@@ -792,6 +837,10 @@
 		tl->err = 1;
 	}
 	if (!tl->err) {
+		if (e->fmt == STRING_LIST) {
+			e = vcc_expr_edit(STRING_LIST,
+			    "\v+\n\v1,\nvrt_magic_string_end\v-", e, NULL);
+		}
 		vcc_expr_fmt(tl->fb, tl->indent, e);
 		vsb_putc(tl->fb, '\n');
 	} else {

Modified: trunk/varnish-cache/lib/libvcl/vcc_parse.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_parse.c	2010-08-26 10:40:26 UTC (rev 5133)
+++ trunk/varnish-cache/lib/libvcl/vcc_parse.c	2010-08-26 13:12:55 UTC (rev 5134)
@@ -69,8 +69,8 @@
 {
 
 	SkipToken(tl, '(');
-	Fb(tl, 1, "(\n");
-	vcc_Expr(tl, BOOL);
+	Fb(tl, 0, "(\n");
+	L(tl, vcc_Expr(tl, BOOL));
 	ERRCHK(tl);
 	Fb(tl, 1, ")\n");
 	SkipToken(tl, ')');
@@ -92,8 +92,8 @@
 {
 
 	SkipToken(tl, T_IF);
-	Fb(tl, 1, "if \n");
-	L(tl, vcc_Conditional(tl));
+	Fb(tl, 1, "if ");
+	vcc_Conditional(tl);
 	ERRCHK(tl);
 	L(tl, vcc_Compound(tl));
 	ERRCHK(tl);
@@ -110,9 +110,9 @@
 			/* FALLTHROUGH */
 		case T_ELSEIF:
 		case T_ELSIF:
-			Fb(tl, 1, "else if \n");
+			Fb(tl, 1, "else if ");
 			vcc_NextToken(tl);
-			L(tl, vcc_Conditional(tl));
+			vcc_Conditional(tl);
 			ERRCHK(tl);
 			L(tl, vcc_Compound(tl));
 			ERRCHK(tl);

Modified: trunk/varnish-cache/lib/libvcl/vcc_types.h
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_types.h	2010-08-26 10:40:26 UTC (rev 5133)
+++ trunk/varnish-cache/lib/libvcl/vcc_types.h	2010-08-26 13:12:55 UTC (rev 5134)
@@ -35,6 +35,7 @@
 VCC_TYPE(TIME)
 VCC_TYPE(DURATION)
 VCC_TYPE(STRING)
+VCC_TYPE(STRING_LIST)
 VCC_TYPE(IP)
 VCC_TYPE(HEADER)
 VCC_TYPE(REAL)




More information about the varnish-commit mailing list