From: Daniil Baturin Date: Sat, 6 Dec 2014 04:58:43 +0000 (+0600) Subject: Make XML report output well formed. X-Git-Tag: v0.86~1^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F61%2Fhead;p=thirdparty%2Fmtr.git Make XML report output well formed. Remove % from Loss tag name, add quotes around attribute names, add XML header. --- diff --git a/report.c b/report.c index 39b2fb2..badb765 100644 --- a/report.c +++ b/report.c @@ -270,19 +270,20 @@ void xml_close(void) ip_t *addr; char name[81]; - printf("\n"); + printf("= 0) { - printf(" PSIZE=%d", cpacketsize); + printf(" PSIZE=\"%d\"", cpacketsize); } else { - printf(" PSIZE=rand(%d-%d)",MINPACKET, -cpacketsize); + printf(" PSIZE=\"rand(%d-%d)\"",MINPACKET, -cpacketsize); } if( bitpattern>=0 ) { - printf(" BITPATTERN=0x%02X", (unsigned char)(bitpattern)); + printf(" BITPATTERN=\"0x%02X\"", (unsigned char)(bitpattern)); } else { - printf(" BITPATTERN=rand(0x00-FF)"); + printf(" BITPATTERN=\"rand(0x00-FF)\""); } - printf(" TESTS=%d>\n", MaxPing); + printf(" TESTS=\"%d\">\n", MaxPing); max = net_max(); at = net_min(); @@ -290,7 +291,7 @@ void xml_close(void) addr = net_addr(at); snprint_addr(name, sizeof(name), addr); - printf(" \n", at+1, name); + printf(" \n", at+1, name); for( i=0; i"); strcat(name, data_fields[j].format); strcat(name, "\n"); + + /* XML doesn't allow "%" in tag names, rename Loss% to just Loss */ + const char *title; + title = data_fields[j].title; + if( strcmp(data_fields[j].title, "Loss%") == 0 ) { + title = "Loss"; + } + /* 1000.0 is a temporay hack for stats usec to ms, impacted net_loss. */ if( index( data_fields[j].format, 'f' ) ) { printf( name, - data_fields[j].title, + title, data_fields[j].net_xxx(at) /1000.0, - data_fields[j].title ); + title ); } else { printf( name, - data_fields[j].title, + title, data_fields[j].net_xxx(at), - data_fields[j].title ); + title ); } } printf(" \n");