浏览代码

usrloc: fix format of the ul.dump json reply

- create "Domains" array instead of a single "Domain" object.
Vitaliy Aleksandrov 8 年之前
父节点
当前提交
247e9bf28e
共有 1 个文件被更改,包括 19 次插入4 次删除
  1. 19 4
      src/modules/usrloc/ul_rpc.c

+ 19 - 4
src/modules/usrloc/ul_rpc.c

@@ -217,6 +217,8 @@ static void ul_rpc_dump(rpc_t* rpc, void* ctx)
 	int summary = 0;
 	ucontact_t* c;
 	void* th;
+	void* dah;
+	void* dh;
 	void* ah;
 	void* bh;
 	void* ih;
@@ -228,14 +230,27 @@ static void ul_rpc_dump(rpc_t* rpc, void* ctx)
 	if(brief.len==5 && (strncmp(brief.s, "brief", 5)==0))
 		summary = 1;
 
+	if (rpc->add(ctx, "{", &th) < 0)
+	{
+		rpc->fault(ctx, 500, "Internal error creating top rpc");
+		return;
+	}
+	if (rpc->struct_add(th, "[", "Domains", &dah) < 0)
+	{
+		rpc->fault(ctx, 500, "Internal error creating inner struct");
+		return;
+	}
+	
 	for( dl=root ; dl ; dl=dl->next ) {
 		dom = dl->d;
-		if (rpc->add(ctx, "{", &th) < 0)
+
+		if (rpc->struct_add(dah, "{", "Domain", &dh) < 0)
 		{
-			rpc->fault(ctx, 500, "Internal error creating top rpc");
+			rpc->fault(ctx, 500, "Internal error creating inner struct");
 			return;
 		}
-		if(rpc->struct_add(th, "Sd[",
+
+		if(rpc->struct_add(dh, "Sd[",
 					"Domain",  &dl->name,
 					"Size",    (int)dom->size,
 					"AoRs",    &ah)<0)
@@ -289,7 +304,7 @@ static void ul_rpc_dump(rpc_t* rpc, void* ctx)
 		}
 
 		/* extra attributes node */
-		if(rpc->struct_add(th, "{", "Stats",    &sh)<0)
+		if(rpc->struct_add(dh, "{", "Stats",    &sh)<0)
 		{
 			rpc->fault(ctx, 500, "Internal error creating stats struct");
 			return;