[master] ee9e803 Add support for passing a HTTP header-identity to a VMOD function.

Poul-Henning Kamp phk at varnish-cache.org
Mon Mar 14 10:48:48 CET 2011


commit ee9e8034a5dc799f5f467f51cf712d5e3f537a98
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Mar 14 09:45:47 2011 +0000

    Add support for passing a HTTP header-identity to a VMOD function.

diff --git a/lib/libvcl/vcc_expr.c b/lib/libvcl/vcc_expr.c
index 1a5b074..de2df31 100644
--- a/lib/libvcl/vcc_expr.c
+++ b/lib/libvcl/vcc_expr.c
@@ -576,6 +576,32 @@ vcc_Eval_Func(struct vcc *tl, struct expr **e, const struct symbol *sym)
 			SkipToken(tl, ID);
 			if (*p != '\0')
 				SkipToken(tl, ',');
+		} else if (fmt == HEADER) {
+			const struct var *v;
+			sym = VCC_FindSymbol(tl, tl->t, SYM_NONE);
+			vcc_AddUses(tl, tl->t, sym->r_methods, "Not available");
+			ERRCHK(tl);
+			SkipToken(tl, ID);
+			if (sym == NULL) {
+				vsb_printf(tl->sb, "Symbol not found.\n");
+				vcc_ErrWhere(tl, tl->t);
+				return;
+			}
+			if (sym->kind != SYM_VAR) {
+				vsb_printf(tl->sb, "Wrong kind of symbol.\n");
+				vcc_ErrWhere(tl, tl->t);
+				return;
+			}
+			AN(sym->var);
+			v = sym->var;
+			if (v->http == NULL) {
+				vsb_printf(tl->sb,
+				    "Variable not an HTTP header.\n");
+				vcc_ErrWhere(tl, tl->t);
+				return;
+			}
+			e1 = vcc_mk_expr(VOID, "%s, \"%s\"", v->http, v->hdr);
+			p += strlen(p) + 1;
 		} else {
 			vcc_expr0(tl, &e1, fmt);
 			ERRCHK(tl);
diff --git a/lib/libvmod_std/vmod.py b/lib/libvmod_std/vmod.py
index a799dd8..4ad37d0 100755
--- a/lib/libvmod_std/vmod.py
+++ b/lib/libvmod_std/vmod.py
@@ -58,7 +58,7 @@ ctypes = {
 	'REAL':		"double",
 	'DURATION':	"double",
 	'INT':		"int",
-	'HEADER':	"const char *",
+	'HEADER':	"enum gethdr_e, const char *",
 	'PRIV_VCL':	"struct vmod_priv *",
 	'PRIV_CALL':	"struct vmod_priv *",
 	'VOID':		"void",
@@ -281,8 +281,8 @@ fh.write("\n");
 fh.write(plist)
 
 
-fc.write('#include "vcc_if.h"\n')
 fc.write('#include "vrt.h"\n')
+fc.write('#include "vcc_if.h"\n')
 fc.write("\n");
 
 fc.write("\n");
diff --git a/lib/libvmod_std/vmod_std_conversions.c b/lib/libvmod_std/vmod_std_conversions.c
index f17b752..1167f55 100644
--- a/lib/libvmod_std/vmod_std_conversions.c
+++ b/lib/libvmod_std/vmod_std_conversions.c
@@ -33,6 +33,7 @@
 
 #include "../../bin/varnishd/cache.h"
 
+#include "vrt.h"
 #include "vcc_if.h"
 
 double __match_proto__()



More information about the varnish-commit mailing list