From c33c0f8f4d16906ebd79fb020db9505158827574 Mon Sep 17 00:00:00 2001 From: Alex Hermann Date: Thu, 29 Oct 2020 14:37:41 +0100 Subject: [PATCH] kex: Make stats.fetch(n) reply with valid JSON {},{} is not valid json. Convert to {}. --- src/modules/kex/core_stats.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/modules/kex/core_stats.c b/src/modules/kex/core_stats.c index 2502a90ba08..048b80dc22c 100644 --- a/src/modules/kex/core_stats.c +++ b/src/modules/kex/core_stats.c @@ -525,25 +525,18 @@ static void rpc_fetch_all_grps_cbk(void* p, str* g) /** * All statistic getter RPC callback. */ -static void stats_fetch_all(rpc_t* rpc, void* ctx, char* stat) +static void stats_fetch_all(rpc_t* rpc, void* ctx, void* th, char* stat) { int len = strlen(stat); struct rpc_list_params packed_params; str s_statistic; stat_var *s_stat; - void *th; char nbuf[128]; char vbuf[32]; char *m; char *n; int i; - if (rpc->add(ctx, "{", &th) < 0) - { - rpc->fault(ctx, 500, "Internal error creating root struct"); - return; - } - if (len==3 && strcmp("all", stat)==0) { packed_params.rpc = rpc; packed_params.ctx = ctx; @@ -618,6 +611,7 @@ static void stats_fetch_all(rpc_t* rpc, void* ctx, char* stat) static void rpc_stats_fetch_statistics(rpc_t* rpc, void* ctx) { char* stat; + void *th; if (stats_support()==0) { rpc->fault(ctx, 400, "stats support not enabled"); @@ -627,9 +621,13 @@ static void rpc_stats_fetch_statistics(rpc_t* rpc, void* ctx) rpc->fault(ctx, 400, "Please provide which stats to retrieve"); return; } - stats_fetch_all(rpc, ctx, stat); + if (rpc->add(ctx, "{", &th) < 0) { + rpc->fault(ctx, 500, "Internal error creating root struct"); + return; + } + stats_fetch_all(rpc, ctx, th, stat); while((rpc->scan(ctx, "*s", &stat)>0)) { - stats_fetch_all(rpc, ctx, stat); + stats_fetch_all(rpc, ctx, th, stat); } return; } @@ -669,23 +667,17 @@ static void rpc_fetchn_all_grps_cbk(void* p, str* g) /** * All statistic getter RPC callback with number value. */ -static void stats_fetchn_all(rpc_t* rpc, void* ctx, char* stat) +static void stats_fetchn_all(rpc_t* rpc, void* ctx, void* th, char* stat) { int len = strlen(stat); struct rpc_list_params packed_params; str s_statistic; stat_var *s_stat; - void *th; char nbuf[128]; char *m; char *n; int i; - if (rpc->add(ctx, "{", &th) < 0) { - rpc->fault(ctx, 500, "Internal error creating root struct"); - return; - } - if (len==3 && strcmp("all", stat)==0) { packed_params.rpc = rpc; packed_params.ctx = ctx; @@ -757,6 +749,7 @@ static void stats_fetchn_all(rpc_t* rpc, void* ctx, char* stat) static void rpc_stats_fetchn_statistics(rpc_t* rpc, void* ctx) { char* stat; + void *th; if (stats_support()==0) { rpc->fault(ctx, 400, "stats support not enabled"); @@ -766,9 +759,13 @@ static void rpc_stats_fetchn_statistics(rpc_t* rpc, void* ctx) rpc->fault(ctx, 400, "Please provide which stats to retrieve"); return; } - stats_fetchn_all(rpc, ctx, stat); + if (rpc->add(ctx, "{", &th) < 0) { + rpc->fault(ctx, 500, "Internal error creating root struct"); + return; + } + stats_fetchn_all(rpc, ctx, th, stat); while((rpc->scan(ctx, "*s", &stat)>0)) { - stats_fetchn_all(rpc, ctx, stat); + stats_fetchn_all(rpc, ctx, th, stat); } return; }