瀏覽代碼

ctl: proper handling of rpc array type in response

Daniel-Constantin Mierla 8 年之前
父節點
當前提交
0252969c39
共有 1 個文件被更改,包括 24 次插入6 次删除
  1. 24 6
      src/modules/ctl/binrpc_run.c

+ 24 - 6
src/modules/ctl/binrpc_run.c

@@ -974,12 +974,18 @@ static int rpc_add(struct binrpc_ctx* ctx, char* fmt, ...)
 				break;
 				break;
 			case '{':
 			case '{':
 			case '[':
 			case '[':
-				err=binrpc_start_struct(&ctx->out.pkt);
+				if(*fmt == '{')
+					err=binrpc_start_struct(&ctx->out.pkt);
+				else
+					err=binrpc_start_array(&ctx->out.pkt);
 				if (err<0) goto error_add;
 				if (err<0) goto error_add;
 				rs=new_rpc_struct();
 				rs=new_rpc_struct();
 				if (rs==0) goto error_mem;
 				if (rs==0) goto error_mem;
 				rs->offset=binrpc_pkt_len(&ctx->out.pkt);
 				rs->offset=binrpc_pkt_len(&ctx->out.pkt);
-				err=binrpc_end_struct(&ctx->out.pkt);
+				if(*fmt == '{')
+					err=binrpc_end_struct(&ctx->out.pkt);
+				else
+					err=binrpc_end_array(&ctx->out.pkt);
 				if (err<0) goto error_add;
 				if (err<0) goto error_add;
 				clist_append(&ctx->out.structs, rs, next, prev);
 				clist_append(&ctx->out.structs, rs, next, prev);
 				*(va_arg(ap, void**))=rs;
 				*(va_arg(ap, void**))=rs;
@@ -1080,7 +1086,10 @@ static int rpc_struct_add(struct rpc_struct_l* s, char* fmt, ...)
 				break;
 				break;
 			case '{':
 			case '{':
 			case '[':
 			case '[':
-				avp.type=BINRPC_T_STRUCT;
+				if(*fmt == '{')
+					avp.type=BINRPC_T_STRUCT;
+				else
+					avp.type=BINRPC_T_ARRAY;
 				err=binrpc_addavp(&s->pkt, &avp);
 				err=binrpc_addavp(&s->pkt, &avp);
 				if (err<0){
 				if (err<0){
 					LM_ERR("failed to add attribute-value (%c)\n", *fmt);
 					LM_ERR("failed to add attribute-value (%c)\n", *fmt);
@@ -1092,7 +1101,10 @@ static int rpc_struct_add(struct rpc_struct_l* s, char* fmt, ...)
 					goto error_mem;
 					goto error_mem;
 				}
 				}
 				rs->offset=binrpc_pkt_len(&s->pkt);
 				rs->offset=binrpc_pkt_len(&s->pkt);
-				err=binrpc_end_struct(&s->pkt);
+				if(*fmt == '{')
+					err=binrpc_end_struct(&s->pkt);
+				else
+					err=binrpc_end_array(&s->pkt);
 				if (err<0) {
 				if (err<0) {
 					LM_ERR("failed to end struct (%c)\n", *fmt);
 					LM_ERR("failed to end struct (%c)\n", *fmt);
 					goto error_add;
 					goto error_add;
@@ -1156,12 +1168,18 @@ static int rpc_array_add(struct rpc_struct_l* s, char* fmt, ...)
 				break;
 				break;
 			case '{':
 			case '{':
 			case '[':
 			case '[':
-				err=binrpc_start_struct(&s->pkt);
+				if(*fmt == '{')
+					err=binrpc_start_struct(&s->pkt);
+				else
+					err=binrpc_start_array(&s->pkt);
 				if (err<0) goto error_add;
 				if (err<0) goto error_add;
 				rs=new_rpc_struct();
 				rs=new_rpc_struct();
 				if (rs==0) goto error_mem;
 				if (rs==0) goto error_mem;
 				rs->offset=binrpc_pkt_len(&s->pkt);
 				rs->offset=binrpc_pkt_len(&s->pkt);
-				err=binrpc_end_struct(&s->pkt);
+				if(*fmt == '{')
+					err=binrpc_end_struct(&s->pkt);
+				else
+					err=binrpc_end_array(&s->pkt);
 				if (err<0) goto error_add;
 				if (err<0) goto error_add;
 				clist_append(&s->substructs, rs, next, prev);
 				clist_append(&s->substructs, rs, next, prev);
 				*(va_arg(ap, void**))=rs;
 				*(va_arg(ap, void**))=rs;