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

phk at projects.linpro.no phk at projects.linpro.no
Mon Jun 25 11:10:20 CEST 2007


Author: phk
Date: 2007-06-25 11:10:20 +0200 (Mon, 25 Jun 2007)
New Revision: 1554

Modified:
   trunk/varnish-cache/bin/varnishd/cache_vrt.c
   trunk/varnish-cache/include/vrt.h
   trunk/varnish-cache/lib/libvcl/vcc_compile.h
   trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
   trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl
   trunk/varnish-cache/lib/libvcl/vcc_obj.c
   trunk/varnish-cache/lib/libvcl/vcc_var.c
Log:
Use an enum instead of magic '1' and '2' values to VRT_GetHdr.

Remove bogus "has_string" variable marking, it can be derived from the type.

Make obj.* variables valid in vcl_timeout() and vcl_discard()



Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt.c	2007-06-25 08:57:09 UTC (rev 1553)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt.c	2007-06-25 09:10:20 UTC (rev 1554)
@@ -71,17 +71,17 @@
 /*--------------------------------------------------------------------*/
 
 char *
-VRT_GetHdr(struct sess *sp, int where, const char *n)
+VRT_GetHdr(struct sess *sp, enum gethdr_e where, const char *n)
 {
 	char *p;
 	struct http *hp;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	switch (where) {
-	case 1:
+	case HDR_REQ:
 		hp = sp->http;
 		break;
-	case 2:
+	case HDR_RESP:
 		hp = &sp->obj->http;
 		break;
 	default:

Modified: trunk/varnish-cache/include/vrt.h
===================================================================
--- trunk/varnish-cache/include/vrt.h	2007-06-25 08:57:09 UTC (rev 1553)
+++ trunk/varnish-cache/include/vrt.h	2007-06-25 09:10:20 UTC (rev 1554)
@@ -74,7 +74,8 @@
 void VRT_error(struct sess *, unsigned, const char *);
 int VRT_switch_config(const char *);
 
-char *VRT_GetHdr(struct sess *, int where, const char *);
+enum gethdr_e { HDR_REQ, HDR_RESP };
+char *VRT_GetHdr(struct sess *, enum gethdr_e where, const char *);
 void VRT_handling(struct sess *sp, unsigned hand);
 
 /* Backend related */

Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.h	2007-06-25 08:57:09 UTC (rev 1553)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.h	2007-06-25 09:10:20 UTC (rev 1554)
@@ -120,7 +120,6 @@
 	unsigned		len;
 	const char		*rname;
 	const char		*lname;
-	unsigned		has_string;
 	unsigned		methods;
 };
 

Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c	2007-06-25 08:57:09 UTC (rev 1553)
+++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c	2007-06-25 09:10:20 UTC (rev 1554)
@@ -428,7 +428,8 @@
 	vsb_cat(sb, "void VRT_error(struct sess *, unsigned, const char *);\n");
 	vsb_cat(sb, "int VRT_switch_config(const char *);\n");
 	vsb_cat(sb, "\n");
-	vsb_cat(sb, "char *VRT_GetHdr(struct sess *, int where, const char *);\n");
+	vsb_cat(sb, "enum gethdr_e { HDR_REQ, HDR_RESP };\n");
+	vsb_cat(sb, "char *VRT_GetHdr(struct sess *, enum gethdr_e where, const char *);\n");
 	vsb_cat(sb, "void VRT_handling(struct sess *sp, unsigned hand);\n");
 	vsb_cat(sb, "\n");
 	vsb_cat(sb, "/* Backend related */\n");
@@ -471,6 +472,8 @@
 	vsb_cat(sb, "void VRT_l_req_proto(struct sess *, const char *);\n");
 	vsb_cat(sb, "struct backend * VRT_r_req_backend(struct sess *);\n");
 	vsb_cat(sb, "void VRT_l_req_backend(struct sess *, struct backend *);\n");
+	vsb_cat(sb, "const char * VRT_r_req_http_(struct sess *);\n");
+	vsb_cat(sb, "void VRT_l_req_http_(struct sess *, const char *);\n");
 	vsb_cat(sb, "const char * VRT_r_req_hash(struct sess *);\n");
 	vsb_cat(sb, "void VRT_l_req_hash(struct sess *, const char *);\n");
 	vsb_cat(sb, "unsigned VRT_r_obj_valid(struct sess *);\n");
@@ -479,8 +482,6 @@
 	vsb_cat(sb, "void VRT_l_obj_cacheable(struct sess *, unsigned);\n");
 	vsb_cat(sb, "double VRT_r_obj_ttl(struct sess *);\n");
 	vsb_cat(sb, "void VRT_l_obj_ttl(struct sess *, double);\n");
-	vsb_cat(sb, "const char * VRT_r_req_http_(struct sess *);\n");
-	vsb_cat(sb, "void VRT_l_req_http_(struct sess *, const char *);\n");
 	vsb_cat(sb, "const char * VRT_r_resp_http_(struct sess *);\n");
 	vsb_cat(sb, "void VRT_l_resp_http_(struct sess *, const char *);\n");
 }

Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl	2007-06-25 08:57:09 UTC (rev 1553)
+++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl	2007-06-25 09:10:20 UTC (rev 1554)
@@ -32,53 +32,27 @@
 
 # Objects which operate on backends
 set beobj {
-	{ backend.host		HOSTNAME	0 }
-	{ backend.port		PORTNAME	0 }
-	{ backend.dnsttl	TIME		0 }
+  { backend.host		HOSTNAME }
+  { backend.port		PORTNAME }
+  { backend.dnsttl	TIME	 }
 }
 
 # Objects which operate on sessions
 
 set spobj {
-	{ client.ip		IP 		1
-	    {recv pipe pass hash miss hit fetch}
-	}
-	{ server.ip		IP 		1
-	    {recv pipe pass hash miss hit fetch}
-	}
-	{ req.request		STRING 		1
-	    {recv pipe pass hash miss hit fetch}
-	}
-	{ req.host		STRING 		1
-	    {recv pipe pass hash miss hit fetch}
-	}
-        { req.url		STRING 		1
-	    {recv pipe pass hash miss hit fetch}
-	}
-        { req.proto		STRING 		1
-	    {recv pipe pass hash miss hit fetch}
-	}
-        { req.backend		BACKEND 	0
-	    {recv pipe pass hash miss hit fetch}
-	}
-        { req.http.		HEADER 		1
-	    {recv pipe pass hash miss hit fetch}
-	}
-        { req.hash		HASH 		0
-	    {hash}
-	}
-        { obj.valid		BOOL 		0
-	    {hit fetch}
-	}
-        { obj.cacheable		BOOL 		0
-	    {hit fetch}
-	}
-        { obj.ttl		TIME 		0
-	    {hit fetch}
-	}
-        { resp.http.		HEADER 		1
-	    {fetch}
-	}
+  { client.ip		IP	{recv pipe pass hash miss hit fetch                } }
+  { server.ip		IP	{recv pipe pass hash miss hit fetch                } }
+  { req.request		STRING	{recv pipe pass hash miss hit fetch                } }
+  { req.host		STRING	{recv pipe pass hash miss hit fetch                } }
+  { req.url		STRING	{recv pipe pass hash miss hit fetch                } }
+  { req.proto		STRING	{recv pipe pass hash miss hit fetch                } }
+  { req.backend		BACKEND	{recv pipe pass hash miss hit fetch                } }
+  { req.http.		HEADER	{recv pipe pass hash miss hit fetch                } }
+  { req.hash		HASH	{               hash                               } }
+  { obj.valid		BOOL	{                         hit fetch discard timeout} }
+  { obj.cacheable	BOOL	{                         hit fetch discard timeout} }
+  { obj.ttl		TIME	{                         hit fetch discard timeout} }
+  { resp.http.		HEADER	{                             fetch                } }
 }
 
 set tt(IP)	"struct sockaddr *"
@@ -131,8 +105,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    [method_map [lindex $v 3]]"
+		puts $fo  "\t    [method_map [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-06-25 08:57:09 UTC (rev 1553)
+++ trunk/varnish-cache/lib/libvcl/vcc_obj.c	2007-06-25 09:10:20 UTC (rev 1554)
@@ -13,19 +13,16 @@
 	{ "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 }
@@ -35,79 +32,66 @@
 	{ "client.ip", IP, 9,
 	    "VRT_r_client_ip(sp)",
 	    "VRT_l_client_ip(sp, ",
-	    1, 
 	    VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH
 	},
 	{ "server.ip", IP, 9,
 	    "VRT_r_server_ip(sp)",
 	    "VRT_l_server_ip(sp, ",
-	    1, 
 	    VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH
 	},
 	{ "req.request", STRING, 11,
 	    "VRT_r_req_request(sp)",
 	    "VRT_l_req_request(sp, ",
-	    1, 
 	    VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH
 	},
 	{ "req.host", STRING, 8,
 	    "VRT_r_req_host(sp)",
 	    "VRT_l_req_host(sp, ",
-	    1, 
 	    VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH
 	},
 	{ "req.url", STRING, 7,
 	    "VRT_r_req_url(sp)",
 	    "VRT_l_req_url(sp, ",
-	    1, 
 	    VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH
 	},
 	{ "req.proto", STRING, 9,
 	    "VRT_r_req_proto(sp)",
 	    "VRT_l_req_proto(sp, ",
-	    1, 
 	    VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH
 	},
 	{ "req.backend", BACKEND, 11,
 	    "VRT_r_req_backend(sp)",
 	    "VRT_l_req_backend(sp, ",
-	    0, 
 	    VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH
 	},
 	{ "req.http.", HEADER, 9,
 	    "VRT_r_req_http_(sp)",
 	    "VRT_l_req_http_(sp, ",
-	    1, 
 	    VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH
 	},
 	{ "req.hash", HASH, 8,
 	    "VRT_r_req_hash(sp)",
 	    "VRT_l_req_hash(sp, ",
-	    0, 
 	    VCL_MET_HASH
 	},
 	{ "obj.valid", BOOL, 9,
 	    "VRT_r_obj_valid(sp)",
 	    "VRT_l_obj_valid(sp, ",
-	    0, 
-	    VCL_MET_HIT | VCL_MET_FETCH
+	    VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT
 	},
 	{ "obj.cacheable", BOOL, 13,
 	    "VRT_r_obj_cacheable(sp)",
 	    "VRT_l_obj_cacheable(sp, ",
-	    0, 
-	    VCL_MET_HIT | VCL_MET_FETCH
+	    VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT
 	},
 	{ "obj.ttl", TIME, 7,
 	    "VRT_r_obj_ttl(sp)",
 	    "VRT_l_obj_ttl(sp, ",
-	    0, 
-	    VCL_MET_HIT | VCL_MET_FETCH
+	    VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT
 	},
 	{ "resp.http.", HEADER, 10,
 	    "VRT_r_resp_http_(sp)",
 	    "VRT_l_resp_http_(sp, ",
-	    1, 
 	    VCL_MET_FETCH
 	},
 	{ NULL }

Modified: trunk/varnish-cache/lib/libvcl/vcc_var.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_var.c	2007-06-25 08:57:09 UTC (rev 1553)
+++ trunk/varnish-cache/lib/libvcl/vcc_var.c	2007-06-25 09:10:20 UTC (rev 1554)
@@ -56,12 +56,6 @@
 	vt = tl->t;
 	vp = vcc_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);
@@ -82,8 +76,9 @@
 HeaderVar(struct tokenlist *tl, const struct token *t, const struct var *vh)
 {
 	char *p;
+	const char *wh;
 	struct var *v;
-	int i, w;
+	int i;
 
 	(void)tl;
 
@@ -96,12 +91,14 @@
 	p[i] = '\0';
 	v->name = p;
 	v->fmt = STRING;
-	v->has_string = vh->has_string;
+	v->methods = vh->methods;
 	if (!memcmp(vh->name, "req.", 4))
-		w = 1;
+		wh = "HDR_REQ";
+	else if (!memcmp(vh->name, "resp.", 5))
+		wh = "HDR_RESP";
 	else
-		w = 2;
-	asprintf(&p, "VRT_GetHdr(sp, %d, \"\\%03o%s:\")", w,
+		assert(0 == 1);
+	asprintf(&p, "VRT_GetHdr(sp, %s, \"\\%03o%s:\")", wh,
 	    (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len);
 	assert(p != NULL);
 	v->rname = p;




More information about the varnish-commit mailing list