r1395 - in trunk/varnish-cache: include lib/libvcl

phk at projects.linpro.no phk at projects.linpro.no
Wed May 9 13:07:59 CEST 2007


Author: phk
Date: 2007-05-09 13:07:59 +0200 (Wed, 09 May 2007)
New Revision: 1395

Modified:
   trunk/varnish-cache/include/vrt_obj.h
   trunk/varnish-cache/lib/libvcl/vcc_action.c
   trunk/varnish-cache/lib/libvcl/vcc_compile.c
   trunk/varnish-cache/lib/libvcl/vcc_compile.h
   trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl
   trunk/varnish-cache/lib/libvcl/vcc_obj.c
Log:
Mark variables/objects as having a string representation or not
and create a function to figure this out, if present.

Add the req.hash variable and the += operator for it, so we
can put the actual hash contents under vcl control.

The runtime half of this stuff is not done yet.



Modified: trunk/varnish-cache/include/vrt_obj.h
===================================================================
--- trunk/varnish-cache/include/vrt_obj.h	2007-05-09 10:55:33 UTC (rev 1394)
+++ trunk/varnish-cache/include/vrt_obj.h	2007-05-09 11:07:59 UTC (rev 1395)
@@ -26,6 +26,8 @@
 void VRT_l_req_proto(struct sess *, const char *);
 struct backend * VRT_r_req_backend(struct sess *);
 void VRT_l_req_backend(struct sess *, struct backend *);
+int VRT_r_req_hash(struct sess *);
+void VRT_l_req_hash(struct sess *, int);
 double VRT_r_obj_valid(struct sess *);
 void VRT_l_obj_valid(struct sess *, double);
 double VRT_r_obj_cacheable(struct sess *);

Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_action.c	2007-05-09 10:55:33 UTC (rev 1394)
+++ trunk/varnish-cache/lib/libvcl/vcc_action.c	2007-05-09 11:07:59 UTC (rev 1395)
@@ -37,7 +37,44 @@
 #include "vcc_compile.h"
 #include "libvarnish.h"
 
+/*--------------------------------------------------------------------*/
 
+static void
+StringVal(struct tokenlist *tl) 
+{
+	struct var *vp;
+	struct token *vt;
+
+	if (tl->t->tok == CSTR) {
+		EncToken(tl->fb, tl->t);
+		vcc_NextToken(tl);
+		return;
+	} 
+	ExpectErr(tl, VAR);
+	ERRCHK(tl);
+	vt = tl->t;
+	vp = FindVar(tl, tl->t, vcc_vars);
+	ERRCHK(tl);
+	if (!vp->has_string) {
+		vsb_printf(tl->sb,
+		    "No string representation of '%s'\n", vp->name);
+		vcc_ErrWhere(tl, tl->t);
+		return;
+	}
+	switch (vp->fmt) {
+	case STRING:
+		Fb(tl, 0, "%s", vp->rname);
+		break;
+	default:
+		vsb_printf(tl->sb,
+		    "String representation of '%s' not implemented yet.\n",
+			vp->name);
+		vcc_ErrWhere(tl, tl->t);
+		return;
+	}
+	vcc_NextToken(tl);
+}
+
 /*--------------------------------------------------------------------*/
 
 #define VCL_RET_MAC(l,u,b,i) 				\
@@ -182,6 +219,12 @@
 		    " only '=' is legal for backend\n");
 		vcc_ErrWhere(tl, tl->t);
 		return;
+	case HASH:
+		ExpectErr(tl, T_INCR);
+		vcc_NextToken(tl);
+		StringVal(tl);
+		Fb(tl, 0, ");\n");
+		return;
 	default:
 		vsb_printf(tl->sb,
 		    "Assignments not possible for '%s'\n", vp->name);

Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.c	2007-05-09 10:55:33 UTC (rev 1394)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.c	2007-05-09 11:07:59 UTC (rev 1395)
@@ -252,6 +252,7 @@
 	p[i] = '\0';
 	v->name = p;
 	v->fmt = STRING;
+	v->has_string = vh->has_string;
 	if (!memcmp(vh->name, "req.", 4))
 		w = 1;
 	else

Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.h	2007-05-09 10:55:33 UTC (rev 1394)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.h	2007-05-09 11:07:59 UTC (rev 1395)
@@ -96,6 +96,7 @@
 	IP,
 	HOSTNAME,
 	PORTNAME,
+	HASH,
 	HEADER
 };
 
@@ -119,6 +120,7 @@
 	unsigned		len;
 	const char		*rname;
 	const char		*lname;
+	unsigned		has_string;
 };
 
 struct method {

Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl	2007-05-09 10:55:33 UTC (rev 1394)
+++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl	2007-05-09 11:07:59 UTC (rev 1395)
@@ -32,26 +32,27 @@
 
 # Objects which operate on backends
 set beobj {
-	{ backend.host		HOSTNAME }
-	{ backend.port		PORTNAME }
-	{ backend.dnsttl	TIME }
+	{ backend.host		HOSTNAME	0 }
+	{ backend.port		PORTNAME	0 }
+	{ backend.dnsttl	TIME		0 }
 }
 
 # Objects which operate on sessions
 
 set spobj {
-	{ client.ip		IP }
-	{ server.ip		IP }
-	{ req.request		STRING }
-	{ req.host		STRING }
-        { req.url		STRING }
-        { req.proto		STRING }
-        { req.backend		BACKEND }
-        { obj.valid		BOOL }
-        { obj.cacheable		BOOL }
-        { obj.ttl		TIME }
-        { req.http.		HEADER }
-        { resp.http.		HEADER }
+	{ client.ip		IP 		1}
+	{ server.ip		IP 		1}
+	{ req.request		STRING 		1}
+	{ req.host		STRING 		1}
+        { req.url		STRING 		1}
+        { req.proto		STRING 		1}
+        { req.backend		BACKEND 	0}
+        { req.hash		HASH 		0}
+        { obj.valid		BOOL 		0}
+        { obj.cacheable		BOOL 		0}
+        { obj.ttl		TIME 		0}
+        { req.http.		HEADER 		1}
+        { resp.http.		HEADER 		1}
 }
 
 set tt(IP)	"struct sockaddr *"
@@ -62,6 +63,7 @@
 set tt(HEADER)	"const char *"
 set tt(HOSTNAME) "const char *"
 set tt(PORTNAME) "const char *"
+set tt(HASH) 	"int"
 
 #----------------------------------------------------------------------
 # Boilerplate warning for all generated files.
@@ -93,6 +95,7 @@
 		puts $fo  "\t\{ \"$n\", $t, [string length $n],"
 		puts $fo  "\t    \"VRT_r_${m}($pa)\","
 		puts $fo  "\t    \"VRT_l_${m}($pa, \","
+		puts $fo  "\t    [lindex $v 2]"
 		puts $fo "\t\},"
 
 		puts $fp  "$tt($t) VRT_r_${m}($ty);"

Modified: trunk/varnish-cache/lib/libvcl/vcc_obj.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_obj.c	2007-05-09 10:55:33 UTC (rev 1394)
+++ trunk/varnish-cache/lib/libvcl/vcc_obj.c	2007-05-09 11:07:59 UTC (rev 1395)
@@ -13,14 +13,17 @@
 	{ "backend.host", HOSTNAME, 12,
 	    "VRT_r_backend_host(backend)",
 	    "VRT_l_backend_host(backend, ",
+	    0
 	},
 	{ "backend.port", PORTNAME, 12,
 	    "VRT_r_backend_port(backend)",
 	    "VRT_l_backend_port(backend, ",
+	    0
 	},
 	{ "backend.dnsttl", TIME, 14,
 	    "VRT_r_backend_dnsttl(backend)",
 	    "VRT_l_backend_dnsttl(backend, ",
+	    0
 	},
 	{ NULL }
 };
@@ -29,50 +32,67 @@
 	{ "client.ip", IP, 9,
 	    "VRT_r_client_ip(sp)",
 	    "VRT_l_client_ip(sp, ",
+	    1
 	},
 	{ "server.ip", IP, 9,
 	    "VRT_r_server_ip(sp)",
 	    "VRT_l_server_ip(sp, ",
+	    1
 	},
 	{ "req.request", STRING, 11,
 	    "VRT_r_req_request(sp)",
 	    "VRT_l_req_request(sp, ",
+	    1
 	},
 	{ "req.host", STRING, 8,
 	    "VRT_r_req_host(sp)",
 	    "VRT_l_req_host(sp, ",
+	    1
 	},
 	{ "req.url", STRING, 7,
 	    "VRT_r_req_url(sp)",
 	    "VRT_l_req_url(sp, ",
+	    1
 	},
 	{ "req.proto", STRING, 9,
 	    "VRT_r_req_proto(sp)",
 	    "VRT_l_req_proto(sp, ",
+	    1
 	},
 	{ "req.backend", BACKEND, 11,
 	    "VRT_r_req_backend(sp)",
 	    "VRT_l_req_backend(sp, ",
+	    0
 	},
+	{ "req.hash", HASH, 8,
+	    "VRT_r_req_hash(sp)",
+	    "VRT_l_req_hash(sp, ",
+	    0
+	},
 	{ "obj.valid", BOOL, 9,
 	    "VRT_r_obj_valid(sp)",
 	    "VRT_l_obj_valid(sp, ",
+	    0
 	},
 	{ "obj.cacheable", BOOL, 13,
 	    "VRT_r_obj_cacheable(sp)",
 	    "VRT_l_obj_cacheable(sp, ",
+	    0
 	},
 	{ "obj.ttl", TIME, 7,
 	    "VRT_r_obj_ttl(sp)",
 	    "VRT_l_obj_ttl(sp, ",
+	    0
 	},
 	{ "req.http.", HEADER, 9,
 	    "VRT_r_req_http_(sp)",
 	    "VRT_l_req_http_(sp, ",
+	    1
 	},
 	{ "resp.http.", HEADER, 10,
 	    "VRT_r_resp_http_(sp)",
 	    "VRT_l_resp_http_(sp, ",
+	    1
 	},
 	{ NULL }
 };




More information about the varnish-commit mailing list