Commit b6580d83 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp Committed by Tollef Fog Heen

Add a "sendhex" verb

parent 6aaefe23
......@@ -903,6 +903,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 },
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment