[4.1] b7f35ba Teach VSB_quote() to hexdump. All zero bits will be elided to "0x0...0"
Lasse Karstensen
lkarsten at varnish-software.com
Tue Jun 14 16:27:09 CEST 2016
commit b7f35ba4d181fe464e42cd39d5b725307527b4e2
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Mar 9 23:35:04 2016 +0000
Teach VSB_quote() to hexdump. All zero bits will be elided to "0x0...0"
Conflicts:
include/vsb.h
lib/libvarnish/vsb.c
diff --git a/include/vsb.h b/include/vsb.h
index 83fb602..2b242bc 100644
--- a/include/vsb.h
+++ b/include/vsb.h
@@ -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
};
diff --git a/lib/libvarnish/vsb.c b/lib/libvarnish/vsb.c
index 1f360d5..b710693 100644
--- a/lib/libvarnish/vsb.c
+++ b/lib/libvarnish/vsb.c
@@ -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 == '\\') {
More information about the varnish-commit
mailing list