From 6d4367e4ab1e7e2d38b94b942f2383e3878a1e7a Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Fri, 29 Sep 2017 09:28:08 +0200 Subject: [PATCH] domain: proper output format for rpc dump command - arrays have to be used to list domains and attributes --- src/modules/domain/domain_mod.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/modules/domain/domain_mod.c b/src/modules/domain/domain_mod.c index 81564168bce..cc6fabb74ee 100644 --- a/src/modules/domain/domain_mod.c +++ b/src/modules/domain/domain_mod.c @@ -291,30 +291,46 @@ static void domain_rpc_dump(rpc_t *rpc, void *ctx) struct domain_list *np; struct attr_list *ap; struct domain_list **ht; + void *rt; + void *at; void *st; if(hash_table == 0 || *hash_table == 0) { rpc->fault(ctx, 404, "Server Domain Cache Empty"); return; } + if(rpc->add(ctx, "{", &rt) < 0) { + rpc->fault(ctx, 500, "Failed to create root struct"); + return; + } + if(rpc->struct_add(rt, "[", "domains", &at) < 0) { + rpc->fault(ctx, 500, "Failed to create domains struct"); + return; + } + ht = *hash_table; for(i = 0; i < DOM_HASH_SIZE; i++) { np = ht[i]; while(np) { - if(rpc->add(ctx, "{", &st) < 0) + if(rpc->array_add(at, "{", &st) < 0) return; rpc->struct_add(st, "SS", "domain", &np->domain, "did", &np->did); np = np->next; } } + if(rpc->struct_add(rt, "[", "attributes", &at) < 0) { + rpc->fault(ctx, 500, "Failed to create attributes struct"); + return; + } np = ht[DOM_HASH_SIZE]; while(np) { - if(rpc->add(ctx, "{", &st) < 0) + if(rpc->array_add(at, "{", &st) < 0) return; rpc->struct_add(st, "S", "did", &np->did); + rpc->struct_add(st, "[", "attrs", &st); ap = np->attrs; while(ap) { - rpc->struct_add(st, "S", "attr", &ap->name); + rpc->array_add(st, "S", &ap->name); ap = ap->next; } np = np->next; @@ -326,7 +342,8 @@ static void domain_rpc_dump(rpc_t *rpc, void *ctx) rpc_export_t domain_rpc_list[] = { {"domain.reload", domain_rpc_reload, domain_rpc_reload_doc, 0}, - {"domain.dump", domain_rpc_dump, domain_rpc_dump_doc, 0}, {0, 0, 0, 0} + {"domain.dump", domain_rpc_dump, domain_rpc_dump_doc, 0}, + {0, 0, 0, 0} }; static int domain_init_rpc(void) @@ -380,4 +397,4 @@ int mod_register(char *path, int *dlflags, void *p1, void *p2) { sr_kemi_modules_add(sr_kemi_domain_exports); return 0; -} \ No newline at end of file +}