[master] 7ab13b1 Add support for stringifying generic symbols.
Poul-Henning Kamp
phk at FreeBSD.org
Thu May 19 00:44:05 CEST 2016
commit 7ab13b1bcd5d4163f28238c03c1f5d905c49e702
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed May 18 22:41:51 2016 +0000
Add support for stringifying generic symbols.
This means that if you:
acl foobar { .... }
sub vcl_recv {
set req.http.acl = foobar;
}
Then the HTTP header gets set to the name of the ACL, ie: "foobar"
diff --git a/bin/varnishtest/tests/c00005.vtc b/bin/varnishtest/tests/c00005.vtc
index afa103c..99a7e5d 100644
--- a/bin/varnishtest/tests/c00005.vtc
+++ b/bin/varnishtest/tests/c00005.vtc
@@ -19,12 +19,16 @@ varnish v1 -arg "-p vsl_mask=+VCL_trace" -vcl+backend {
set req.url = "/";
}
}
+ sub vcl_deliver {
+ set resp.http.acl = acl1;
+ }
} -start
client c1 {
txreq -url "foo"
rxresp
expect resp.status == 200
+ expect resp.http.acl == acl1
} -run
varnish v1 -vcl+backend {
@@ -39,6 +43,9 @@ varnish v1 -vcl+backend {
set req.url = "/";
}
}
+ sub vcl_deliver {
+ set resp.http.acl = acl1;
+ }
}
client c1 -run
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index bfb661a..d20059b 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -106,7 +106,7 @@ enum symkind {
};
typedef void sym_expr_t(struct vcc *tl, struct expr **,
- const struct symbol *sym);
+ const struct symbol *sym, enum var_type);
typedef struct symbol *sym_wildcard_t(struct vcc *tl, const struct token *t,
const struct symbol *sym);
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index 6b74f8e..e65acd1 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -446,14 +446,16 @@ vcc_expr_tostring(struct vcc *tl, struct expr **e, enum var_type fmt)
/*--------------------------------------------------------------------
*/
-static void
-vcc_Eval_Regsub(struct vcc *tl, struct expr **e, const struct symbol *sym)
+static void __match_proto__(sym_expr_t)
+vcc_Eval_Regsub(struct vcc *tl, struct expr **e, const struct symbol *sym,
+ enum var_type fmt)
{
struct expr *e2;
int all = sym->eval_priv == NULL ? 0 : 1;
const char *p;
char buf[128];
+ (void)fmt;
vcc_delete_expr(*e);
SkipToken(tl, ID);
SkipToken(tl, '(');
@@ -481,10 +483,12 @@ vcc_Eval_Regsub(struct vcc *tl, struct expr **e, const struct symbol *sym)
/*--------------------------------------------------------------------
*/
-static void
-vcc_Eval_BoolConst(struct vcc *tl, struct expr **e, const struct symbol *sym)
+static void __match_proto__(sym_expr_t)
+vcc_Eval_BoolConst(struct vcc *tl, struct expr **e, const struct symbol *sym,
+ enum var_type fmt)
{
+ (void)fmt;
vcc_NextToken(tl);
*e = vcc_mk_expr(BOOL, "(0==%d)", sym->eval_priv == NULL ? 1 : 0);
(*e)->constant = EXPR_CONST;
@@ -493,28 +497,36 @@ vcc_Eval_BoolConst(struct vcc *tl, struct expr **e, const struct symbol *sym)
/*--------------------------------------------------------------------
*/
-void
-vcc_Eval_Generic(struct vcc *tl, struct expr **e, const struct symbol *sym)
+void __match_proto__(sym_expr_t)
+vcc_Eval_Generic(struct vcc *tl, struct expr **e, const struct symbol *sym,
+ enum var_type fmt)
{
assert(sym->kind == sym->kind);
AN(sym->eval_priv);
- vcc_ExpectCid(tl);
- vcc_AddRef(tl, tl->t, sym->kind);
- *e = vcc_mk_expr(sym->fmt, "%s", (const char *)sym->eval_priv);
- (*e)->constant = EXPR_VAR; /* XXX ? */
+ if (sym->fmt != STRING && (fmt == STRING || fmt == STRING_LIST)) {
+ *e = vcc_mk_expr(STRING, "\"%s\"", sym->name);
+ vcc_AddRef(tl, tl->t, sym->kind);
+ } else {
+ vcc_ExpectCid(tl);
+ vcc_AddRef(tl, tl->t, sym->kind);
+ *e = vcc_mk_expr(sym->fmt, "%s", (const char *)sym->eval_priv);
+ (*e)->constant = EXPR_VAR; /* XXX ? */
+ }
vcc_NextToken(tl);
}
/*--------------------------------------------------------------------
*/
-void
-vcc_Eval_Var(struct vcc *tl, struct expr **e, const struct symbol *sym)
+void __match_proto__(sym_expr_t)
+vcc_Eval_Var(struct vcc *tl, struct expr **e, const struct symbol *sym,
+ enum var_type fmt)
{
const struct var *vp;
+ (void)fmt;
assert(sym->kind == SYM_VAR);
vcc_AddUses(tl, tl->t, sym->r_methods, "Not available");
vp = vcc_FindVar(tl, tl->t, 0, "cannot be read");
@@ -758,10 +770,12 @@ vcc_Eval_Func(struct vcc *tl, const char *cfunc,
/*--------------------------------------------------------------------
*/
-void
-vcc_Eval_SymFunc(struct vcc *tl, struct expr **e, const struct symbol *sym)
+void __match_proto__(sym_expr_t)
+vcc_Eval_SymFunc(struct vcc *tl, struct expr **e, const struct symbol *sym,
+ enum var_type fmt)
{
+ (void)fmt;
assert(sym->kind == SYM_FUNC);
/* XXX */
AN(sym->cfunc);
@@ -842,7 +856,7 @@ vcc_expr4(struct vcc *tl, struct expr **e, enum var_type fmt)
case SYM_PROBE:
AN(sym->eval);
AZ(*e);
- sym->eval(tl, e, sym);
+ sym->eval(tl, e, sym, fmt);
ERRCHK(tl);
/* Unless asked for a HEADER, fold to string here */
if (*e && fmt != HEADER && (*e)->fmt == HEADER) {
@@ -1399,7 +1413,7 @@ vcc_Expr_Call(struct vcc *tl, const struct symbol *sym)
t1 = tl->t;
e = NULL;
- vcc_Eval_SymFunc(tl, &e, sym);
+ vcc_Eval_SymFunc(tl, &e, sym, VOID);
if (!tl->err) {
vcc_expr_fmt(tl->fb, tl->indent, e);
VSB_cat(tl->fb, ";\n");
More information about the varnish-commit
mailing list