r5650 - trunk/varnish-cache/lib/libvcl

phk at varnish-cache.org phk at varnish-cache.org
Fri Dec 17 16:13:56 CET 2010


Author: phk
Date: 2010-12-17 16:13:56 +0100 (Fri, 17 Dec 2010)
New Revision: 5650

Modified:
   trunk/varnish-cache/lib/libvcl/symbol_kind.h
   trunk/varnish-cache/lib/libvcl/vcc_compile.c
   trunk/varnish-cache/lib/libvcl/vcc_compile.h
   trunk/varnish-cache/lib/libvcl/vcc_symb.c
   trunk/varnish-cache/lib/libvcl/vcc_var.c
   trunk/varnish-cache/lib/libvcl/vcc_vmod.c
Log:
Add a new type of symbols: Wildcards.

This is a generalization of the trick we have used for things like
req.http.foobar, which can now also be used with other parts of
the namespace.

The plan is to use it for storage.disk1.free and similar.



Modified: trunk/varnish-cache/lib/libvcl/symbol_kind.h
===================================================================
--- trunk/varnish-cache/lib/libvcl/symbol_kind.h	2010-12-17 14:05:40 UTC (rev 5649)
+++ trunk/varnish-cache/lib/libvcl/symbol_kind.h	2010-12-17 15:13:56 UTC (rev 5650)
@@ -38,4 +38,5 @@
 VCC_SYMB(SUB,		sub,		"sub")		/* VCL subroutine */
 VCC_SYMB(BACKEND,	backend,	"backend")
 VCC_SYMB(PROBE,		probe,		"probe")
+VCC_SYMB(WILDCARD,	wildcard,	"wildcard")
 /*lint -restore */

Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.c	2010-12-17 14:05:40 UTC (rev 5649)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.c	2010-12-17 15:13:56 UTC (rev 5650)
@@ -568,13 +568,16 @@
 	vcc_Expr_Init(tl);
 
 	for (v = tl->vars; v->name != NULL; v++) {
-		sym = VCC_AddSymbolStr(tl, v->name, SYM_VAR);
+		if (v->fmt == HEADER) {
+			sym = VCC_AddSymbolStr(tl, v->name, SYM_WILDCARD);
+			sym->wildcard = vcc_Var_Wildcard;
+		} else {
+			sym = VCC_AddSymbolStr(tl, v->name, SYM_VAR);
+		}
 		sym->var = v;
 		sym->fmt = v->fmt;
 		sym->eval = vcc_Eval_Var;
 		sym->r_methods = v->r_methods;
-		if (v->fmt == HEADER)
-			sym->wildcard = 1;
 	}
 
 	vcl_output_lang_h(tl->fh);

Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.h	2010-12-17 14:05:40 UTC (rev 5649)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.h	2010-12-17 15:13:56 UTC (rev 5650)
@@ -79,6 +79,8 @@
 };
 
 typedef void sym_expr_t(struct vcc *tl, struct expr **, const struct symbol *sym);
+typedef struct symbol *sym_wildcard_t(struct vcc *tl, const struct token *t,
+    const struct symbol *sym);
 
 struct symbol {
 	unsigned			magic;
@@ -87,7 +89,7 @@
 
 	char				*name;
 	unsigned			nlen;
-	unsigned			wildcard;
+	sym_wildcard_t			*wildcard;
 	enum symkind			kind;
 
 	const struct token		*def_b, *def_e;
@@ -264,9 +266,10 @@
 
 /* vcc_symb.c */
 struct symbol *VCC_AddSymbolStr(struct vcc *tl, const char *name, enum symkind);
+struct symbol *VCC_AddSymbolTok(struct vcc *tl, const struct token *t, enum symkind kind);
 struct symbol *VCC_GetSymbolTok(struct vcc *tl, const struct token *tok,
     enum symkind);
-struct symbol *VCC_FindSymbol(const struct vcc *tl,
+struct symbol *VCC_FindSymbol(struct vcc *tl,
     const struct token *t, enum symkind kind);
 const char * VCC_SymKind(struct vcc *tl, const struct symbol *s);
 typedef void symwalk_f(struct vcc *tl, const struct symbol *s);
@@ -291,6 +294,7 @@
     const char *e);
 
 /* vcc_var.c */
+sym_wildcard_t vcc_Var_Wildcard;
 const struct var *vcc_FindVar(struct vcc *tl, const struct token *t,
     int wr_access, const char *use);
 void vcc_VarVal(struct vcc *tl, const struct var *vp,

Modified: trunk/varnish-cache/lib/libvcl/vcc_symb.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_symb.c	2010-12-17 14:05:40 UTC (rev 5649)
+++ trunk/varnish-cache/lib/libvcl/vcc_symb.c	2010-12-17 15:13:56 UTC (rev 5650)
@@ -82,7 +82,7 @@
 	memcpy(sym->name, nb, l);
 	sym->name[l] = '\0';
 	sym->nlen = l;
-	VTAILQ_INSERT_TAIL(&tl->symbols, sym, list);
+	VTAILQ_INSERT_HEAD(&tl->symbols, sym, list);
 	sym->kind = kind;
 	return (sym);
 }
@@ -95,6 +95,13 @@
 }
 
 struct symbol *
+VCC_AddSymbolTok(struct vcc *tl, const struct token *t, enum symkind kind)
+{
+
+	return (vcc_AddSymbol(tl, t->b, t->e - t->b, kind));
+}
+
+struct symbol *
 VCC_GetSymbolTok(struct vcc *tl, const struct token *tok, enum symkind kind)
 {
 	struct symbol *sym;
@@ -109,22 +116,21 @@
 }
 
 struct symbol *
-VCC_FindSymbol(const struct vcc *tl, const struct token *t, enum symkind kind)
+VCC_FindSymbol(struct vcc *tl, const struct token *t, enum symkind kind)
 {
 	struct symbol *sym;
 
 	assert(t->tok == ID);
 	VTAILQ_FOREACH(sym, &tl->symbols, list) {
+		if (sym->kind == SYM_WILDCARD &&
+		   (t->e - t->b > sym->nlen) &&
+		   !memcmp(sym->name, t->b, sym->nlen)) {
+			AN (sym->wildcard);
+			return (sym->wildcard(tl, t, sym));
+		}
 		if (kind != SYM_NONE && kind != sym->kind)
 			continue;
-		if (!sym->wildcard) {
-			if (vcc_IdIs(t, sym->name))
-				return (sym);
-			continue;
-		}
-		if (t->e - t->b <= sym->nlen)
-			continue;
-		if (!memcmp(sym->name, t->b, sym->nlen))
+		if (vcc_IdIs(t, sym->name))
 			return (sym);
 	}
 	return (NULL);

Modified: trunk/varnish-cache/lib/libvcl/vcc_var.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_var.c	2010-12-17 14:05:40 UTC (rev 5649)
+++ trunk/varnish-cache/lib/libvcl/vcc_var.c	2010-12-17 15:13:56 UTC (rev 5650)
@@ -43,18 +43,21 @@
 
 /*--------------------------------------------------------------------*/
 
-static struct var *
-HeaderVar(struct vcc *tl, const struct token *t, const struct var *vh)
+struct symbol *
+vcc_Var_Wildcard(struct vcc *tl, const struct token *t, const struct symbol *wc)
 {
 	char *p;
+	struct symbol *sym;
 	struct var *v;
+	const struct var *vh;
 	int i, l;
 	char buf[258];
 
-	(void)tl;
+	vh = wc->var;
 
 	v = TlAlloc(tl, sizeof *v);
 	assert(v != NULL);
+
 	i = t->e - t->b;
 	p = TlAlloc(tl, i + 1);
 	assert(p != NULL);
@@ -81,7 +84,13 @@
 	memcpy(p, buf, i + 1);
 	v->lname = p;
 
-	return (v);
+	sym = VCC_AddSymbolTok(tl, t, SYM_VAR);
+	AN(sym);
+	sym->var = v;
+	sym->fmt = v->fmt;
+	sym->eval = vcc_Eval_Var;
+	sym->r_methods = v->r_methods;
+	return (sym);
 }
 
 /*--------------------------------------------------------------------*/
@@ -118,9 +127,8 @@
 		} else {
 			vcc_AddUses(tl, t, v->r_methods, use);
 		}
-		if (v->fmt != HEADER)
-			return (v);
-		return (HeaderVar(tl, t, v));
+		assert(v->fmt != HEADER);
+		return (v);
 	}
 	vsb_printf(tl->sb, "Unknown variable ");
 	vcc_ErrToken(tl, t);

Modified: trunk/varnish-cache/lib/libvcl/vcc_vmod.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_vmod.c	2010-12-17 14:05:40 UTC (rev 5649)
+++ trunk/varnish-cache/lib/libvcl/vcc_vmod.c	2010-12-17 15:13:56 UTC (rev 5650)
@@ -29,7 +29,7 @@
 #include "config.h"
 
 #include "svnid.h"
-SVNID("$Id$");
+SVNID("$Id$")
 
 #include <stdio.h>
 #include <dlfcn.h>




More information about the varnish-commit mailing list