From 8e417220d3329226d07bcf6fcbe5b2e3999e7bb0 Mon Sep 17 00:00:00 2001 From: colm Date: Wed, 15 Feb 2017 21:17:13 -0500 Subject: [PATCH] FS-9952: Add blade rpc error response creation --- libs/libblade/src/blade_rpcproto.c | 25 ++++++++++++++++++++++ libs/libblade/src/include/blade_rpcproto.h | 4 ++++ libs/libks/src/ks_rpcmessage.c | 5 ++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/libs/libblade/src/blade_rpcproto.c b/libs/libblade/src/blade_rpcproto.c index 3123a77118..bedfd1c505 100644 --- a/libs/libblade/src/blade_rpcproto.c +++ b/libs/libblade/src/blade_rpcproto.c @@ -811,6 +811,31 @@ KS_DECLARE(ks_rpcmessageid_t) blade_rpc_create_response(cJSON *request, return msgid; } +KS_DECLARE(ks_rpcmessageid_t) blade_rpc_create_errorresponse(cJSON *request, + cJSON **errorP, + cJSON **responseP) +{ + ks_rpcmessageid_t msgid = blade_rpc_create_response(request, NULL, responseP); + + if (msgid) { + + if (errorP) { + + if (*errorP) { + cJSON_AddItemToObject(*responseP, "error", *errorP); + } + else { + cJSON *error = cJSON_CreateObject(); + cJSON_AddItemToObject(*responseP, "error", error); + *errorP = error; + } + } + } + + return msgid; +} + + const char BLADE_JRPC_METHOD[] = "method"; const char BLADE_JRPC_ID[] = "id"; const char BLADE_JRPC_FIELDS[] = "blade"; diff --git a/libs/libblade/src/include/blade_rpcproto.h b/libs/libblade/src/include/blade_rpcproto.h index 3a8421c6da..f108c981e6 100644 --- a/libs/libblade/src/include/blade_rpcproto.h +++ b/libs/libblade/src/include/blade_rpcproto.h @@ -127,6 +127,10 @@ KS_DECLARE(ks_rpcmessageid_t) blade_rpc_create_response(cJSON *request, cJSON **reply, cJSON **response); +KS_DECLARE(ks_rpcmessageid_t) blade_rpc_create_errorresponse(cJSON *request, + cJSON **reply, + cJSON **response); + KS_DECLARE(ks_status_t) blade_rpc_parse_message(cJSON *message, char **namespace, char **method, diff --git a/libs/libks/src/ks_rpcmessage.c b/libs/libks/src/ks_rpcmessage.c index 1b5e48754e..e950c693e8 100644 --- a/libs/libks/src/ks_rpcmessage.c +++ b/libs/libks/src/ks_rpcmessage.c @@ -286,7 +286,7 @@ KS_DECLARE(ks_rpcmessageid_t) ks_rpcmessage_create_errorresponse( cJSON **errorP, cJSON **responseP) { - ks_rpcmessageid_t msgid = ks_rpcmessage_new_response(request, errorP, responseP); + ks_rpcmessageid_t msgid = ks_rpcmessage_new_response(request, NULL, responseP); cJSON *respmsg = *responseP; if (msgid) { @@ -296,6 +296,9 @@ KS_DECLARE(ks_rpcmessageid_t) ks_rpcmessage_create_errorresponse( *errorP = error; cJSON_AddItemToObject(respmsg, ERROR, error); } + else if (errorP && *errorP) { + cJSON_AddItemToObject(*responseP, ERROR, *errorP); + } } return msgid;