[master] b57c329 add the blob wrapper to vrt

Nils Goroll nils.goroll at uplex.de
Sun Dec 10 14:15:09 UTC 2017


commit b57c329a33cb512400ba1c068fef0bf81259cdb1
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Sun Dec 10 15:14:13 2017 +0100

    add the blob wrapper to vrt
    
    it is genereally useful also for vmods

diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index 1a95db3..3d0952f 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -590,3 +590,21 @@ VRT_ipcmp(const struct suckaddr *sua1, const struct suckaddr *sua2)
 		return(1);
 	return (VSA_Compare_IP(sua1, sua2));
 }
+
+struct vmod_priv *
+VRT_blob(VRT_CTX, const char *err, const uint8_t *src, size_t len)
+{
+	struct vmod_priv *p;
+	void *d;
+
+	p = (void *)WS_Alloc(ctx->ws, sizeof *p);
+	d = WS_Copy(ctx->ws, src, len);
+	if (p == NULL || d == NULL) {
+		VRT_fail(ctx, "Workspace overflow (%s)", err);
+		return (NULL);
+	}
+	memset(p, 0, sizeof *p);
+	p->len = len;
+	p->priv = d;
+	return (p);
+}
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 01e5997..b99bd9f 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -730,31 +730,12 @@ VRT_BODY_L(resp)
 
 /*--------------------------------------------------------------------*/
 
-static struct vmod_priv *
-vrt_do_blob(VRT_CTX, const char *err, const uint8_t *src, size_t len)
-{
-	struct vmod_priv *p;
-	void *d;
-
-	p = (void *)WS_Alloc(ctx->ws, sizeof *p);
-	d = WS_Copy(ctx->ws, src, len);
-	if (p == NULL || d == NULL) {
-		VRT_fail(ctx, "Workspace overflow (%s)", err);
-		return (NULL);
-	}
-	memset(p, 0, sizeof *p);
-	p->len = len;
-	p->priv = d;
-	return (p);
-}
-
 VCL_BLOB
 VRT_r_req_hash(VRT_CTX)
 {
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
 	CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
-	return (vrt_do_blob(ctx, "req.hash", ctx->req->digest,
-	    DIGEST_LEN));
+	return (VRT_blob(ctx, "req.hash", ctx->req->digest, DIGEST_LEN));
 }
 
 VCL_BLOB
@@ -762,8 +743,7 @@ VRT_r_bereq_hash(VRT_CTX)
 {
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
 	CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
-	return (vrt_do_blob(ctx, "bereq.hash", ctx->bo->digest,
-	    DIGEST_LEN));
+	return (VRT_blob(ctx, "bereq.hash", ctx->bo->digest, DIGEST_LEN));
 }
 
 /*--------------------------------------------------------------------*/
diff --git a/include/vrt.h b/include/vrt.h
index df9e18a..0a78bd1 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -60,6 +60,7 @@
  *	struct director.destroy added
  *	VRT_r_beresp_storage_hint() removed - under discussion #2509
  *	VRT_l_beresp_storage_hint() removed - under discussion #2509
+ *	VRT_blob() added
  * 6.1 (2017-09-15 aka 5.2)
  *	http_CollectHdrSep added
  *	VRT_purge modified (may fail a transaction, signature changed)
@@ -368,6 +369,7 @@ void VRT_hashdata(VRT_CTX, const char *str, ...);
 int VRT_strcmp(const char *s1, const char *s2);
 void VRT_memmove(void *dst, const void *src, unsigned len);
 int VRT_ipcmp(const struct suckaddr *sua1, const struct suckaddr *sua2);
+struct vmod_priv *VRT_blob(VRT_CTX, const char *, const uint8_t *, size_t);
 
 void VRT_Rollback(VRT_CTX, const struct http *);
 


More information about the varnish-commit mailing list