r5693 - trunk/varnish-cache/bin/varnishtest
phk at varnish-cache.org
phk at varnish-cache.org
Thu Jan 6 15:57:11 CET 2011
Author: phk
Date: 2011-01-06 15:57:10 +0100 (Thu, 06 Jan 2011)
New Revision: 5693
Modified:
trunk/varnish-cache/bin/varnishtest/vtc.h
trunk/varnish-cache/bin/varnishtest/vtc_log.c
Log:
Add a hexdump function, now that we fiddle binary stuff.
Modified: trunk/varnish-cache/bin/varnishtest/vtc.h
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc.h 2011-01-06 14:55:05 UTC (rev 5692)
+++ trunk/varnish-cache/bin/varnishtest/vtc.h 2011-01-06 14:57:10 UTC (rev 5693)
@@ -74,6 +74,8 @@
void vtc_log(struct vtclog *vl, unsigned lvl, const char *fmt, ...);
void vtc_dump(struct vtclog *vl, unsigned lvl, const char *pfx,
const char *str, int len);
+void vtc_hexdump(struct vtclog *vl, unsigned lvl, const char *pfx,
+ const unsigned char *str, int len);
int exec_file(const char *fn, const char *script, const char *tmpdir,
char *logbuf, unsigned loglen);
Modified: trunk/varnish-cache/bin/varnishtest/vtc_log.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_log.c 2011-01-06 14:55:05 UTC (rev 5692)
+++ trunk/varnish-cache/bin/varnishtest/vtc_log.c 2011-01-06 14:57:10 UTC (rev 5693)
@@ -162,6 +162,15 @@
CHECK_OBJ_NOTNULL(vl, VTCLOG_MAGIC);
assert(lvl < NLEAD);
+ if (0 && str != NULL && len > 0) {
+ for (l = 0; l < len; l++) {
+ if (str[l] & 0x80) {
+ vtc_hexdump(vl, lvl, pfx,
+ (const void*)str, len);
+ return;
+ }
+ }
+ }
AZ(pthread_mutex_lock(&vl->mtx));
vsb_clear(vl->vsb);
if (pfx == NULL)
@@ -210,3 +219,58 @@
pthread_exit(NULL);
}
}
+
+/**********************************************************************
+ * Hexdump
+ */
+
+//lint -e{818}
+void
+vtc_hexdump(struct vtclog *vl, unsigned lvl, const char *pfx, const unsigned char *str, int len)
+{
+ int nl = 1;
+ unsigned l;
+
+ CHECK_OBJ_NOTNULL(vl, VTCLOG_MAGIC);
+ assert(len >= 0);
+ assert(lvl < NLEAD);
+ AZ(pthread_mutex_lock(&vl->mtx));
+ vsb_clear(vl->vsb);
+ if (pfx == NULL)
+ pfx = "";
+ if (str == NULL)
+ vsb_printf(vl->vsb, "%s %-4s %s(null)\n",
+ lead[lvl], vl->id, pfx);
+ else {
+ for (l = 0; l < len; l++, str++) {
+ if (l > 512) {
+ vsb_printf(vl->vsb, "...");
+ break;
+ }
+ if (nl) {
+ vsb_printf(vl->vsb, "%s %-4s %s| ",
+ lead[lvl], vl->id, pfx);
+ nl = 0;
+ }
+ vsb_printf(vl->vsb, " %02x", *str);
+ if ((l & 0xf) == 0xf) {
+ vsb_printf(vl->vsb, "\n");
+ nl = 1;
+ }
+ }
+ }
+ if (!nl)
+ vsb_printf(vl->vsb, "\n");
+ vsb_finish(vl->vsb);
+ AZ(vsb_overflowed(vl->vsb));
+
+ vtc_log_emit(vl, lvl);
+
+ vsb_clear(vl->vsb);
+ AZ(pthread_mutex_unlock(&vl->mtx));
+ if (lvl == 0) {
+ vtc_error = 1;
+ if (pthread_self() != vtc_thread)
+ pthread_exit(NULL);
+ }
+}
More information about the varnish-commit
mailing list