From: Olivier Doucet Date: Fri, 6 Nov 2015 18:50:07 +0000 (+0100) Subject: Fix JSON and JSONTIME export with gprints or rules X-Git-Tag: v1.6.0~24^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F685%2Fhead;p=thirdparty%2Frrdtool-1.x.git Fix JSON and JSONTIME export with gprints or rules When you have gprints or rules, json is not formated correctly : a comma is inserted after each block, making two mistakes : - there is no comma between "legend" and "gprints" block - there is a trailing comma in "meta" block I decided to rewrite this part and add the comma before each block, so this works in all cases : when you don't have any block, only one of them or both. --- diff --git a/src/rrd_xport.c b/src/rrd_xport.c index 629b118e..971a7b5a 100644 --- a/src/rrd_xport.c +++ b/src/rrd_xport.c @@ -1067,10 +1067,10 @@ int rrd_xport_format_addprints(int flags,stringbuffer_t *buffer,image_desc_t *im /* now add gprints */ if (gprints.len) { if (json){ - snprintf(buf,sizeof(buf)," \"%s\": [\n","gprints"); + snprintf(buf,sizeof(buf)," ,\"%s\": [\n","gprints"); addToBuffer(buffer,buf,0); addToBuffer(buffer,(char*)gprints.data+2,gprints.len-2); - addToBuffer(buffer,"\n ],\n",0); + addToBuffer(buffer,"\n ]\n",0); } else { snprintf(buf,sizeof(buf)," <%s>\n", "gprints"); addToBuffer(buffer,buf,0); @@ -1083,10 +1083,10 @@ int rrd_xport_format_addprints(int flags,stringbuffer_t *buffer,image_desc_t *im /* now add rules */ if (rules.len) { if (json){ - snprintf(buf,sizeof(buf)," \"%s\": [\n","rules"); + snprintf(buf,sizeof(buf)," ,\"%s\": [\n","rules"); addToBuffer(buffer,buf,0); addToBuffer(buffer,(char*)rules.data+2,rules.len-2); - addToBuffer(buffer,"\n ],\n",0); + addToBuffer(buffer,"\n ]\n",0); } else { snprintf(buf,sizeof(buf)," <%s>\n", "rules"); addToBuffer(buffer,buf,0);