[3.0] b6580d8 Add a "sendhex" verb
Tollef Fog Heen
tfheen at varnish-cache.org
Wed Aug 17 11:29:03 CEST 2011
commit b6580d8359161c428f7c3cd4fa98a97632c58cb8
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Aug 17 08:31:18 2011 +0000
Add a "sendhex" verb
diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c
index 55228d5..366a5dd 100644
--- a/bin/varnishtest/vtc_http.c
+++ b/bin/varnishtest/vtc_http.c
@@ -904,6 +904,47 @@ cmd_http_send(CMD_ARGS)
}
/**********************************************************************
+ * Send a hex string
+ */
+
+static void
+cmd_http_sendhex(CMD_ARGS)
+{
+ struct http *hp;
+ char buf[3], *q;
+ uint8_t *p;
+ int i, j, l;
+
+ (void)cmd;
+ (void)vl;
+ CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
+ AN(av[1]);
+ AZ(av[2]);
+ l = strlen(av[1]) / 2;
+ p = malloc(l);
+ AN(p);
+ q = av[1];
+ for (i = 0; i < l; i++) {
+ while (vct_issp(*q))
+ q++;
+ if (*q == '\0')
+ break;
+ memcpy(buf, q, 2);
+ q += 2;
+ buf[2] = '\0';
+ if (!vct_ishex(buf[0]) || !vct_ishex(buf[1]))
+ vtc_log(hp->vl, 0, "Illegal Hex char \"%c%c\"",
+ buf[0], buf[1]);
+ p[i] = strtoul(buf, NULL, 16);
+ }
+ vtc_hexdump(hp->vl, 4, "sendhex", (void*)p, i);
+ j = write(hp->fd, p, i);
+ assert(j == i);
+ free(p);
+
+}
+
+/**********************************************************************
* Send a string as chunked encoding
*/
@@ -1080,6 +1121,7 @@ static const struct cmds http_cmds[] = {
{ "gunzip", cmd_http_gunzip_body },
{ "expect", cmd_http_expect },
{ "send", cmd_http_send },
+ { "sendhex", cmd_http_sendhex },
{ "chunked", cmd_http_chunked },
{ "chunkedlen", cmd_http_chunkedlen },
{ "delay", cmd_delay },
diff --git a/bin/varnishtest/vtc_log.c b/bin/varnishtest/vtc_log.c
index f0841c0..18f295a 100644
--- a/bin/varnishtest/vtc_log.c
+++ b/bin/varnishtest/vtc_log.c
@@ -227,8 +227,10 @@ vtc_hexdump(struct vtclog *vl, unsigned lvl, const char *pfx, const unsigned cha
{
int nl = 1;
unsigned l;
+ double tx;
CHECK_OBJ_NOTNULL(vl, VTCLOG_MAGIC);
+ tx = TIM_mono() - t0;
assert(len >= 0);
assert(lvl < NLEAD);
AZ(pthread_mutex_lock(&vl->mtx));
@@ -236,8 +238,8 @@ vtc_hexdump(struct vtclog *vl, unsigned lvl, const char *pfx, const unsigned cha
if (pfx == NULL)
pfx = "";
if (str == NULL)
- VSB_printf(vl->vsb, "%s %-4s %s(null)\n",
- lead[lvl], vl->id, pfx);
+ VSB_printf(vl->vsb, "%s %-4s %4.1f %s| (null)",
+ lead[lvl], vl->id, tx, pfx);
else {
for (l = 0; l < len; l++, str++) {
if (l > 512) {
@@ -245,8 +247,8 @@ vtc_hexdump(struct vtclog *vl, unsigned lvl, const char *pfx, const unsigned cha
break;
}
if (nl) {
- VSB_printf(vl->vsb, "%s %-4s %s| ",
- lead[lvl], vl->id, pfx);
+ VSB_printf(vl->vsb, "%s %-4s %4.1f %s| ",
+ lead[lvl], vl->id, tx, pfx);
nl = 0;
}
VSB_printf(vl->vsb, " %02x", *str);
More information about the varnish-commit
mailing list