Ver Fonte

jsonrpc-s: Don't make up a random reply when the reply is empty

In case the function was registered with RET_ARRAY, return an empty array,
as that is a valid response.

Else, there is no sane response, send an empty object for now. This should
maybe become an error repsonse instead.
Alex Hermann há 11 anos atrás
pai
commit
1a55331227
1 ficheiros alterados com 12 adições e 7 exclusões
  1. 12 7
      modules/jsonrpc-s/jsonrpc-s_mod.c

+ 12 - 7
modules/jsonrpc-s/jsonrpc-s_mod.c

@@ -229,14 +229,19 @@ static int jsonrpc_send(jsonrpc_ctx_t* ctx)
 	} else {
 		nj = srjson_GetObjectItem(ctx->jrpl, ctx->jrpl->root, "result");
 		if(nj==NULL) {
-			if(ctx->rpl_node!=NULL) {
-				srjson_AddItemToObject(ctx->jrpl, ctx->jrpl->root,
-					"result", ctx->rpl_node);
-				ctx->rpl_node = 0;
-			} else {
-				srjson_AddStrStrToObject(ctx->jrpl, ctx->jrpl->root,
-					"result", 6, "ok", 2);
+			if (!ctx->rpl_node) {
+				if(ctx->flags & RET_ARRAY) {
+					ctx->rpl_node = srjson_CreateArray(ctx->jrpl);
+				} else {
+					ctx->rpl_node = srjson_CreateObject(ctx->jrpl);
+				}
+				if(ctx->rpl_node == 0) {
+					LM_ERR("failed to create the root array node\n");
+				}
 			}
+			srjson_AddItemToObject(ctx->jrpl, ctx->jrpl->root,
+				"result", ctx->rpl_node);
+			ctx->rpl_node = 0;
 		}
 	}
 	nj = srjson_GetObjectItem(ctx->jreq, ctx->jreq->root, "id");