jsoninfo: allow key to be NULL when printing an IP address
authorFerry Huberts <ferry.huberts@pelagic.nl>
Thu, 17 Mar 2016 17:31:10 +0000 (18:31 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Thu, 17 Mar 2016 17:40:29 +0000 (18:40 +0100)
For simple lists/sets

Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/jsoninfo/src/olsrd_jsoninfo_helpers.c

index e1fb2d0..360a0c9 100644 (file)
@@ -211,7 +211,7 @@ void abuf_json_ip_address(struct autobuf *abuf, const char* key, union olsr_ip_a
   const char * value;
 
   assert(abuf);
-  assert(key);
+  assert(key || ip);
 
   if (!ip) {
     value = empty;
@@ -221,7 +221,11 @@ void abuf_json_ip_address(struct autobuf *abuf, const char* key, union olsr_ip_a
 
   abuf_json_insert_comma(abuf);
   abuf_json_new_indent(abuf);
-  abuf_appendf(abuf, "\"%s\": \"%s\"", key, value);
+  if (!key) {
+    abuf_appendf(abuf, "\"%s\"", value);
+  } else {
+    abuf_appendf(abuf, "\"%s\": \"%s\"", key, value);
+  }
   entrynumber[currentjsondepth]++;
 }