Commit b7f35ba4 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp Committed by Lasse Karstensen

Teach VSB_quote() to hexdump. All zero bits will be elided to "0x0...0"

Conflicts:
	include/vsb.h
	lib/libvarnish/vsb.c
parent 090ebb9c
......@@ -76,8 +76,10 @@ char *VSB_data(const struct vsb *);
ssize_t VSB_len(const struct vsb *);
void VSB_delete(struct vsb *);
void VSB_destroy(struct vsb **);
void VSB_quote(struct vsb *, const void *, int len, int how);
#define VSB_QUOTE_NONL 1
void VSB_quote(struct vsb *s, const char *p, int len, int how);
#define VSB_QUOTE_JSON 2
#define VSB_QUOTE_HEX 4
void VSB_indent(struct vsb *, int);
#ifdef __cplusplus
};
......
......@@ -500,14 +500,32 @@ VSB_destroy(struct vsb **s)
* Quote a string
*/
void
VSB_quote(struct vsb *s, const char *p, int len, int how)
VSB_quote(struct vsb *s, const void *v, int len, int how)
{
const char *p;
const char *q;
int quote = 0;
const unsigned char *u, *w;
(void)how; /* For future enhancements */
assert(v != NULL);
if (len == -1)
len = strlen(p);
len = strlen(v);
if (how & VSB_QUOTE_HEX) {
u = v;
for (w = u; w < u + len; w++)
if (*w != 0x00)
break;
VSB_printf(s, "0x");
if (w == u + len) {
VSB_printf(s, "0...0");
} else {
for (w = u; w < u + len; w++)
VSB_printf(s, "%02x", *w);
}
return;
}
p = v;
for (q = p; q < p + len; q++) {
if (!isgraph(*q) || *q == '"' || *q == '\\') {
......
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