Skip to content

Commit

Permalink
domain: proper output format for rpc dump command
Browse files Browse the repository at this point in the history
- arrays have to be used to list domains and attributes
  • Loading branch information
miconda committed Sep 29, 2017
1 parent 0a3c3d1 commit 6d4367e
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/modules/domain/domain_mod.c
Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 6d4367e

Please sign in to comment.