[3.0] b1401a8 Simplify json callback
Tollef Fog Heen
tfheen at varnish-cache.org
Mon Apr 16 10:20:35 CEST 2012
commit b1401a81db2514e8d04a5f42c20da269c5e28c3b
Author: Tollef Fog Heen <tfheen at varnish-software.com>
Date: Mon Nov 7 13:26:51 2011 +0100
Simplify json callback
diff --git a/bin/varnishstat/varnishstat.c b/bin/varnishstat/varnishstat.c
index d487b54..f8b8ef0 100644
--- a/bin/varnishstat/varnishstat.c
+++ b/bin/varnishstat/varnishstat.c
@@ -92,8 +92,6 @@ do_json_cb(void *priv, const struct VSC_point * const pt)
{
uint64_t val;
int *jp;
- char jsonkey[255];
- char jsontmp[255];
jp = priv;
@@ -101,18 +99,14 @@ do_json_cb(void *priv, const struct VSC_point * const pt)
val = *(const volatile uint64_t*)pt->ptr;
if (*jp) *jp = 0; else printf(",\n");
- jsonkey[0] = '\0';
+ printf("\t\"");
/* build the JSON key name. */
- if (strcmp(pt->ident, "") && strcmp(pt->class, "")) sprintf(jsonkey, "%s.%s", pt->class, pt->ident);
- if (strcmp(pt->ident, "") && !strcmp(pt->class, "")) sprintf(jsonkey, "%s", pt->ident);
- if (!strcmp(pt->ident, "") && strcmp(pt->class, "")) sprintf(jsonkey, "%s", pt->class);
-
- strcpy(jsontmp, jsonkey);
- if (strcmp(jsonkey, "")) sprintf(jsonkey, "%s.%s", jsontmp, pt->name);
- else strcpy(jsonkey, pt->name);
-
- printf("\t\"%s\": {", jsonkey);
+ if (pt->class[0])
+ printf("%s.", pt->class);
+ if (pt->ident[0])
+ printf("%s.", pt->ident);
+ printf("%s\": {", pt->name);
if (strcmp(pt->class, "")) printf("\"type\": \"%s\", ", pt->class);
if (strcmp(pt->ident, "")) printf("\"ident\": \"%s\", ", pt->ident);
More information about the varnish-commit
mailing list