[master] 8216919 Add VSLb_bin() which is meant for dumping binary blurbs into VSL.

Poul-Henning Kamp phk at FreeBSD.org
Tue Aug 30 10:58:11 CEST 2016


commit 8216919c48135f66e90a70c4e23484084b693f7a
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Aug 30 08:56:50 2016 +0000

    Add VSLb_bin() which is meant for dumping binary blurbs into VSL.
    
    For now it hex-dumps them, but something smarter will happen once
    Martin has time.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index c04662f..923a8d2 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -993,6 +993,7 @@ void VSLb(struct vsl_log *, enum VSL_tag_e tag, const char *fmt, ...)
 void VSLbt(struct vsl_log *, enum VSL_tag_e tag, txt t);
 void VSLb_ts(struct vsl_log *, const char *event, double first, double *pprev,
     double now);
+void VSLb_bin(struct vsl_log *, enum VSL_tag_e, ssize_t, const void*);
 
 static inline void
 VSLb_ts_req(struct req *req, const char *event, double now)
diff --git a/bin/varnishd/cache/cache_shmlog.c b/bin/varnishd/cache/cache_shmlog.c
index 789e902..a4aee4a 100644
--- a/bin/varnishd/cache/cache_shmlog.c
+++ b/bin/varnishd/cache/cache_shmlog.c
@@ -378,6 +378,39 @@ VSLb_ts(struct vsl_log *vsl, const char *event, double first, double *pprev,
 	*pprev = now;
 }
 
+void
+VSLb_bin(struct vsl_log *vsl, enum VSL_tag_e tag, ssize_t len, const void *ptr)
+{
+	char *p;
+	const uint8_t *pp = ptr;
+	int suff = 0;
+	size_t ll;
+
+	assert(len >= 0);
+	AN(ptr);
+	if (vsl_tag_is_masked(tag))
+		return;
+	vsl_sanity(vsl);
+	if (len * 2 + 1 > cache_param->vsl_reclen) {
+		len = (cache_param->vsl_reclen - 2) / 2;
+		suff = 1;
+	}
+	if (VSL_END(vsl->wlp, len * 2 + 1) >= vsl->wle)
+		VSL_Flush(vsl, 1);
+	assert(VSL_END(vsl->wlp, len * 2 + 1) < vsl->wle);
+	p = VSL_DATA(vsl->wlp);
+	for (ll = 0; ll < len; ll++) {
+		(void)sprintf(p, "%02x", *pp++);
+		p += 2;
+	}
+	if (suff)
+		*p++ = '-';
+	*p = '\0';
+	vsl->wlp = vsl_hdr(tag, vsl->wlp, len * 2 + 1, vsl->wid);
+	assert(vsl->wlp < vsl->wle);
+	vsl->wlr++;
+}
+
 /*--------------------------------------------------------------------
  * Setup a VSL buffer, allocate space if none provided.
  */



More information about the varnish-commit mailing list