[experimental-ims] 56ce6e3 More VRT sp->req work

Poul-Henning Kamp phk at FreeBSD.org
Thu Dec 18 10:27:48 CET 2014


commit 56ce6e353960411f281a5114993ef2e7f51cf3dd
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Jun 18 08:48:53 2012 +0000

    More VRT sp->req work

diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index f1b1f3c..5675311 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -54,17 +54,16 @@ const void * const vrt_magic_string_end = &vrt_magic_string_end;
 /*--------------------------------------------------------------------*/
 
 void
-VRT_error(const struct sess *sp, unsigned code, const char *reason)
+VRT_error(struct req *req, unsigned code, const char *reason)
 {
 
-	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	VSLb(sp->req->vsl, SLT_Debug, "VCL_error(%u, %s)", code, reason ?
-	    reason : "(null)");
+	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+	VSLb(req->vsl, SLT_Debug, "VCL_error(%u, %s)", code,
+	    reason ?  reason : "(null)");
 	if (code < 100 || code > 999)
 		code = 503;
-	sp->req->err_code = (uint16_t)code;
-	sp->req->err_reason =
-	    reason ? reason : http_StatusMessage(sp->req->err_code);
+	req->err_code = (uint16_t)code;
+	req->err_reason = reason ? reason : http_StatusMessage(req->err_code);
 }
 
 /*--------------------------------------------------------------------*/
@@ -196,18 +195,18 @@ VRT_String(struct ws *ws, const char *h, const char *p, va_list ap)
 }
 
 /*--------------------------------------------------------------------
- * Build a string on the worker threads workspace
+ * Build a string on the request workspace
  */
 
 const char *
-VRT_WrkString(const struct sess *sp, const char *p, ...)
+VRT_ReqString(struct req *req, const char *p, ...)
 {
 	va_list ap;
 	char *b;
 
-	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	va_start(ap, p);
-	b = VRT_String(sp->wrk->aws, NULL, p, ap);
+	b = VRT_String(req->ws, NULL, p, ap);
 	va_end(ap);
 	return (b);
 }
@@ -287,7 +286,7 @@ VRT_r_now(const struct req *req)
 /*--------------------------------------------------------------------*/
 
 char *
-VRT_IP_string(const struct sess *sp, const struct sockaddr_storage *sa)
+VRT_IP_string(struct req *req, const struct sockaddr_storage *sa)
 {
 	char *p;
 	const struct sockaddr_in *si4;
@@ -295,6 +294,7 @@ VRT_IP_string(const struct sess *sp, const struct sockaddr_storage *sa)
 	const void *addr;
 	int len;
 
+	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	switch (sa->ss_family) {
 	case AF_INET:
 		len = INET_ADDRSTRLEN;
@@ -310,61 +310,65 @@ VRT_IP_string(const struct sess *sp, const struct sockaddr_storage *sa)
 		INCOMPL();
 	}
 	XXXAN(len);
-	AN(p = WS_Alloc(sp->req->http->ws, len));
+	AN(p = WS_Alloc(req->http->ws, len));
 	AN(inet_ntop(sa->ss_family, addr, p, len));
 	return (p);
 }
 
 char *
-VRT_int_string(const struct sess *sp, int num)
+VRT_int_string(struct req *req, int num)
 {
 	char *p;
 	int size;
 
+	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	size = snprintf(NULL, 0, "%d", num) + 1;
-	AN(p = WS_Alloc(sp->req->http->ws, size));
+	AN(p = WS_Alloc(req->http->ws, size));
 	assert(snprintf(p, size, "%d", num) < size);
 	return (p);
 }
 
 char *
-VRT_double_string(const struct sess *sp, double num)
+VRT_double_string(struct req *req, double num)
 {
 	char *p;
 	int size;
 
+	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	size = snprintf(NULL, 0, "%.3f", num) + 1;
-	AN(p = WS_Alloc(sp->req->http->ws, size));
+	AN(p = WS_Alloc(req->http->ws, size));
 	assert(snprintf(p, size, "%.3f", num) < size);
 	return (p);
 }
 
 char *
-VRT_time_string(const struct sess *sp, double t)
+VRT_time_string(struct req *req, double t)
 {
 	char *p;
 
-	AN(p = WS_Alloc(sp->req->http->ws, VTIM_FORMAT_SIZE));
-	VTIM_format(t, p);
+	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+	p = WS_Alloc(req->http->ws, VTIM_FORMAT_SIZE);
+	if (p != NULL)
+		VTIM_format(t, p);
 	return (p);
 }
 
 const char *
-VRT_backend_string(const struct sess *sp, const struct director *d)
+VRT_backend_string(const struct req *req, const struct director *d)
 {
-	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	if (d == NULL)
-		d = sp->req->director;
+		d = req->director;
 	if (d == NULL)
 		return (NULL);
 	return (d->vcl_name);
 }
 
 const char *
-VRT_bool_string(const struct sess *sp, unsigned val)
+VRT_bool_string(const struct req *req, unsigned val)
 {
 
-	(void)sp;
+	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	return (val ? "true" : "false");
 }
 
@@ -395,16 +399,16 @@ VRT_panic(const struct sess *sp, const char *str, ...)
 /*--------------------------------------------------------------------*/
 
 void
-VRT_synth_page(const struct sess *sp, unsigned flags, const char *str, ...)
+VRT_synth_page(struct req *req, unsigned flags, const char *str, ...)
 {
 	va_list ap;
 	const char *p;
 	struct vsb *vsb;
 
 	(void)flags;
-	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	CHECK_OBJ_NOTNULL(sp->req->obj, OBJECT_MAGIC);
-	vsb = SMS_Makesynth(sp->req->obj);
+	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+	CHECK_OBJ_NOTNULL(req->obj, OBJECT_MAGIC);
+	vsb = SMS_Makesynth(req->obj);
 	AN(vsb);
 
 	VSB_cat(vsb, str);
@@ -417,10 +421,9 @@ VRT_synth_page(const struct sess *sp, unsigned flags, const char *str, ...)
 		p = va_arg(ap, const char *);
 	}
 	va_end(ap);
-	SMS_Finish(sp->req->obj);
-	http_Unset(sp->req->obj->http, H_Content_Length);
-	http_PrintfHeader(sp->req->obj->http,
-	    "Content-Length: %zd", sp->req->obj->len);
+	SMS_Finish(req->obj);
+	http_Unset(req->obj->http, H_Content_Length);
+	http_PrintfHeader(req->obj->http, "Content-Length: %zd", req->obj->len);
 }
 
 /*--------------------------------------------------------------------*/
diff --git a/include/vrt.h b/include/vrt.h
index dc5ba13..a6a2642 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -157,7 +157,7 @@ void VRT_purge(const struct sess *sp, double ttl, double grace);
 
 void VRT_count(struct req *, unsigned);
 int VRT_rewrite(const char *, const char *);
-void VRT_error(const struct sess *, unsigned, const char *);
+void VRT_error(struct req *, unsigned, const char *);
 int VRT_switch_config(const char *);
 
 enum gethdr_e { HDR_REQ, HDR_RESP, HDR_OBJ, HDR_BEREQ, HDR_BERESP };
@@ -176,7 +176,7 @@ void VRT_ESI(const struct sess *sp);
 void VRT_Rollback(const struct sess *sp);
 
 /* Synthetic pages */
-void VRT_synth_page(const struct sess *sp, unsigned flags, const char *, ...);
+void VRT_synth_page(struct req *sp, unsigned flags, const char *, ...);
 
 /* Backend related */
 void VRT_init_dir(struct cli *, struct director **, const char *name,
@@ -210,12 +210,12 @@ int VRT_Stv(const char *nm);
 
 /* Convert things to string */
 
-char *VRT_IP_string(const struct sess *sp, const struct sockaddr_storage *sa);
-char *VRT_int_string(const struct sess *sp, int);
-char *VRT_double_string(const struct sess *sp, double);
-char *VRT_time_string(const struct sess *sp, double);
-const char *VRT_bool_string(const struct sess *sp, unsigned);
-const char *VRT_backend_string(const struct sess *sp, const struct director *d);
+char *VRT_IP_string(struct req *, const struct sockaddr_storage *sa);
+char *VRT_int_string(struct req *, int);
+char *VRT_double_string(struct req *, double);
+char *VRT_time_string(struct req *, double);
+const char *VRT_bool_string(const struct req *, unsigned);
+const char *VRT_backend_string(const struct req *, const struct director *d);
 
 #define VRT_done(req, hand)			\
 	do {					\
@@ -223,4 +223,4 @@ const char *VRT_backend_string(const struct sess *sp, const struct director *d);
 		return (1);			\
 	} while (0)
 
-const char *VRT_WrkString(const struct sess *sp, const char *p, ...);
+const char *VRT_ReqString(struct req *, const char *p, ...);
diff --git a/lib/libvcl/vcc_action.c b/lib/libvcl/vcc_action.c
index 31a940b..31b2bad 100644
--- a/lib/libvcl/vcc_action.c
+++ b/lib/libvcl/vcc_action.c
@@ -57,7 +57,7 @@ parse_error(struct vcc *tl)
 {
 
 	vcc_NextToken(tl);
-	Fb(tl, 1, "VRT_error(sp,\n");
+	Fb(tl, 1, "VRT_error(req,\n");
 	if (tl->t->tok == '(') {
 		vcc_NextToken(tl);
 		vcc_Expr(tl, INT);
@@ -303,7 +303,7 @@ parse_synthetic(struct vcc *tl)
 {
 	vcc_NextToken(tl);
 
-	Fb(tl, 1, "VRT_synth_page(sp, 0, ");
+	Fb(tl, 1, "VRT_synth_page(req, 0, ");
 	vcc_Expr(tl, STRING_LIST);
 	ERRCHK(tl);
 	Fb(tl, 0, ");\n");
diff --git a/lib/libvcl/vcc_expr.c b/lib/libvcl/vcc_expr.c
index 19a455c..d964ff1 100644
--- a/lib/libvcl/vcc_expr.c
+++ b/lib/libvcl/vcc_expr.c
@@ -423,15 +423,15 @@ vcc_expr_tostring(struct expr **e, enum var_type fmt)
 
 	p = NULL;
 	switch((*e)->fmt) {
-	case BACKEND:	p = "VRT_backend_string(sp, \v1)"; break;
-	case BOOL:	p = "VRT_bool_string(sp, \v1)"; break;
-	case DURATION:	p = "VRT_double_string(sp, \v1)"; break;
+	case BACKEND:	p = "VRT_backend_string(req, \v1)"; break;
+	case BOOL:	p = "VRT_bool_string(req, \v1)"; break;
+	case DURATION:	p = "VRT_double_string(req, \v1)"; break;
 			 /* XXX: should DURATION insist on "s" suffix ? */
-	case INT:	p = "VRT_int_string(sp, \v1)"; break;
-	case IP:	p = "VRT_IP_string(sp, \v1)"; break;
-	case BYTES:	p = "VRT_double_string(sp, \v1)"; break; /* XXX */
-	case REAL:	p = "VRT_double_string(sp, \v1)"; break;
-	case TIME:	p = "VRT_time_string(sp, \v1)"; break;
+	case INT:	p = "VRT_int_string(req, \v1)"; break;
+	case IP:	p = "VRT_IP_string(req, \v1)"; break;
+	case BYTES:	p = "VRT_double_string(req, \v1)"; break; /* XXX */
+	case REAL:	p = "VRT_double_string(req, \v1)"; break;
+	case TIME:	p = "VRT_time_string(req, \v1)"; break;
 	default:	break;
 	}
 	if (p != NULL) {
@@ -819,7 +819,7 @@ vcc_expr_add(struct vcc *tl, struct expr **e, enum var_type fmt)
 	}
 	if (fmt != STRING_LIST && (*e)->fmt == STRING_LIST)
 		*e = vcc_expr_edit(STRING,
-		    "\v+VRT_WrkString(sp,\n\v1,\nvrt_magic_string_end)",
+		    "\v+VRT_ReqString(req,\n\v1,\nvrt_magic_string_end)",
 		    *e, NULL);
 	if (fmt == STRING_LIST && (*e)->fmt == STRING)
 		(*e)->fmt = STRING_LIST;



More information about the varnish-commit mailing list