[master] 2e3b542 Make the VRT_[GS]etHdr() take vrt_ctx arg.

Poul-Henning Kamp phk at varnish-cache.org
Tue Apr 30 11:37:29 CEST 2013


commit 2e3b542dc27671ca2c3233544f34463e44212725
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Apr 30 09:37:04 2013 +0000

    Make the VRT_[GS]etHdr() take vrt_ctx arg.

diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index 7dd3c8b..d17d6aa 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -376,7 +376,7 @@ vcl_call_method(struct worker *wrk, struct req *req, struct busyobj *bo,
     struct ws *ws, unsigned method, vcl_func_f *func)
 {
 	char *aws;
-	struct vsl_log *vsl;
+	struct vsl_log *vsl = NULL;
 	struct vrt_ctx ctx;
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
@@ -389,14 +389,11 @@ vcl_call_method(struct worker *wrk, struct req *req, struct busyobj *bo,
 		vsl = req->vsl;
 		ctx.vsl = vsl;
 		ctx.vcl = req->vcl;
-	} else {
-		AZ(req);
-		CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
-		vsl = bo->vsl;
-		ctx.vsl = vsl;
-		ctx.vcl = bo->vcl;
+		ctx.http_req = req->http;
+		ctx.http_resp = req->resp;
+		if (req->obj)
+			ctx.http_obj = req->obj->http;
 	}
-	ctx.ws = ws;
 	if (method == VCL_MET_BACKEND_FETCH ||
 	    method == VCL_MET_PASS ||
 	    method == VCL_MET_MISS ||
@@ -407,9 +404,20 @@ vcl_call_method(struct worker *wrk, struct req *req, struct busyobj *bo,
 		bo = req->busyobj;
 		CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 	}
+	if (bo != NULL) {
+		// AZ(req);
+		CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
+		vsl = bo->vsl;
+		ctx.vsl = vsl;
+		ctx.vcl = bo->vcl;
+		ctx.http_bereq = bo->bereq;
+		ctx.http_beresp = bo->beresp;
+	}
+	ctx.ws = ws;
 	aws = WS_Snapshot(wrk->aws);
 	wrk->handling = 0;
 	wrk->cur_method = method;
+	AN(vsl);
 	VSLb(vsl, SLT_VCL_call, "%s", VCL_Method_Name(method));
 	(void)func(&ctx, wrk, req, bo, ws);
 	VSLb(vsl, SLT_VCL_return, "%s", VCL_Return_Name(wrk->handling));
diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index 4f87829..8449a6a 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -107,43 +107,42 @@ VRT_acl_log(struct req *req, const char *msg)
 /*--------------------------------------------------------------------*/
 
 static struct http *
-vrt_selecthttp(const struct req *req, enum gethdr_e where)
+vrt_selecthttp(const struct vrt_ctx *ctx, enum gethdr_e where)
 {
 	struct http *hp;
 
-	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
 	switch (where) {
 	case HDR_REQ:
-		hp = req->http;
+		hp = ctx->http_req;
 		break;
 	case HDR_BEREQ:
-		hp = req->busyobj->bereq;
+		hp = ctx->http_bereq;
 		break;
 	case HDR_BERESP:
-		hp = req->busyobj->beresp;
+		hp = ctx->http_beresp;
 		break;
 	case HDR_RESP:
-		hp = req->resp;
+		hp = ctx->http_resp;
 		break;
 	case HDR_OBJ:
-		CHECK_OBJ_NOTNULL(req->obj, OBJECT_MAGIC);
-		hp = req->obj->http;
+		hp = ctx->http_obj;
 		break;
 	default:
 		INCOMPL();
 	}
-	CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
 	return (hp);
 }
 
 char *
-VRT_GetHdr(const struct req *req, const struct gethdr_s *hs)
+VRT_GetHdr(const struct vrt_ctx *ctx, const struct gethdr_s *hs)
 {
 	char *p;
 	struct http *hp;
 
-	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
-	hp = vrt_selecthttp(req, hs->where);
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	hp = vrt_selecthttp(ctx, hs->where);
+	CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
 	if (!http_GetHdr(hp, hs->what, &p))
 		return (NULL);
 	return (p);
@@ -229,23 +228,25 @@ VRT_CollectString(struct ws *ws, const char *p, ...)
 /*--------------------------------------------------------------------*/
 
 void
-VRT_SetHdr(struct req *req , const struct gethdr_s *hs, const char *p, ...)
+VRT_SetHdr(const struct vrt_ctx *ctx , const struct gethdr_s *hs,
+    const char *p, ...)
 {
 	struct http *hp;
 	va_list ap;
 	char *b;
 
-	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
 	AN(hs);
 	AN(hs->what);
-	hp = vrt_selecthttp(req, hs->where);
+	hp = vrt_selecthttp(ctx, hs->where);
+	CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
 	va_start(ap, p);
 	if (p == vrt_magic_string_unset) {
 		http_Unset(hp, hs->what);
 	} else {
 		b = VRT_String(hp->ws, hs->what + 1, p, ap);
 		if (b == NULL) {
-			VSLb(req->vsl, SLT_LostHeader, "%s", hs->what + 1);
+			VSLb(ctx->vsl, SLT_LostHeader, "%s", hs->what + 1);
 		} else {
 			http_Unset(hp, hs->what);
 			http_SetHeader(hp, b);
diff --git a/include/vrt.h b/include/vrt.h
index acf736b..b0e752f 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -204,8 +204,8 @@ void VRT_error(struct req *, unsigned, const char *);
 int VRT_switch_config(const char *);
 
 const struct gethdr_s *VRT_MkGethdr(struct req *,enum gethdr_e, const char *);
-char *VRT_GetHdr(const struct req *, const struct gethdr_s *);
-void VRT_SetHdr(struct req *, const struct gethdr_s *, const char *, ...);
+char *VRT_GetHdr(const struct vrt_ctx *, const struct gethdr_s *);
+void VRT_SetHdr(const struct vrt_ctx *, const struct gethdr_s *, const char *, ...);
 void VRT_handling(struct worker *, unsigned hand);
 
 void VRT_hashdata(struct req *, const char *str, ...);
diff --git a/lib/libvcl/generate.py b/lib/libvcl/generate.py
index 1a1c2bd..140635b 100755
--- a/lib/libvcl/generate.py
+++ b/lib/libvcl/generate.py
@@ -165,7 +165,7 @@ sp_variables = (
 		'HEADER',
 		( 'client',),
 		( 'client',),
-		'cR'
+		'C'
 	),
 	('req.restarts',
 		'INT',
@@ -279,7 +279,7 @@ sp_variables = (
 		'HEADER',
 		( 'pipe', 'backend_fetch', 'pass', 'miss', 'backend_response',),
 		( 'pipe', 'backend_fetch', 'pass', 'miss', 'backend_response',),
-		'cR'
+		'C'
 	),
 	('bereq.connect_timeout',
 		'DURATION',
@@ -327,7 +327,7 @@ sp_variables = (
 		'HEADER',
 		( 'backend_response',),
 		( 'backend_response',),
-		'cR'
+		'C'
 	),
 	('beresp.do_esi',
 		'BOOL',
@@ -435,7 +435,7 @@ sp_variables = (
 		'HEADER',
 		( 'lookup', 'error',),
 		( 'error',),		# XXX ?
-		'cR'
+		'C'
 	),
 	('obj.ttl',
 		'DURATION',
@@ -489,7 +489,7 @@ sp_variables = (
 		'HEADER',
 		( 'deliver',),
 		( 'deliver',),
-		'cR'
+		'C'
 	),
 	('now',
 		'TIME',
@@ -885,6 +885,8 @@ def mk_proto(c, r=False):
 			s += " const"
 		elif i == "c":
 			pass
+		elif i == "C":
+			s += "const struct vrt_ctx *"
 		elif i == "R":
 			if r:
 				s += " const"
diff --git a/lib/libvcl/vcc_expr.c b/lib/libvcl/vcc_expr.c
index 7caf25e..715a4c9 100644
--- a/lib/libvcl/vcc_expr.c
+++ b/lib/libvcl/vcc_expr.c
@@ -418,7 +418,7 @@ vcc_expr_tostring(struct expr **e, enum var_type fmt)
 	case BYTES:	p = "VRT_REAL_string(ws, \v1)"; break; /* XXX */
 	case REAL:	p = "VRT_REAL_string(ws, \v1)"; break;
 	case TIME:	p = "VRT_TIME_string(ws, \v1)"; break;
-	case HEADER:	p = "VRT_GetHdr(req, \v1)"; break;
+	case HEADER:	p = "VRT_GetHdr(ctx, \v1)"; break;
 	case ENUM:
 	case STRING:
 	case STRING_LIST:
diff --git a/lib/libvcl/vcc_var.c b/lib/libvcl/vcc_var.c
index 5afec43..74713b8 100644
--- a/lib/libvcl/vcc_var.c
+++ b/lib/libvcl/vcc_var.c
@@ -78,7 +78,7 @@ vcc_Var_Wildcard(struct vcc *tl, const struct token *t, const struct symbol *wc)
 
 	bprintf(buf, "&VGC_%s_%s", vh->rname, cnam);
 	v->rname = TlDup(tl, buf);
-	bprintf(buf, "VRT_SetHdr(req, %s, ", v->rname);
+	bprintf(buf, "VRT_SetHdr(ctx, %s, ", v->rname);
 	v->lname = TlDup(tl, buf);
 
 	sym = VCC_AddSymbolTok(tl, t, SYM_VAR);



More information about the varnish-commit mailing list