From ad4d3750daa2ec3734ad79a87829a2c529a021a7 Mon Sep 17 00:00:00 2001 From: Jonathan Aillet Date: Fri, 6 Jul 2018 14:39:42 +0200 Subject: Keep json unmodified during action execution Keep passed json object unmodified during action execution. Before, the action arguments were added in the json passed (so, the json was modified, even for its provider). Now, if action arguments need to be added to the json to execute an action, 'ActionExecOne' function clone the passed json object, add action arguments into it, and use it to call the action. Change-Id: If102cc943326c17aad52cfde735362a72ad35a9a Signed-off-by: Jonathan Aillet --- ctl-lib/ctl-action.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'ctl-lib') diff --git a/ctl-lib/ctl-action.c b/ctl-lib/ctl-action.c index 20a608e..55e810e 100644 --- a/ctl-lib/ctl-action.c +++ b/ctl-lib/ctl-action.c @@ -57,27 +57,32 @@ int ActionExecOne(CtlSourceT *source, CtlActionT* action, json_object *queryJ) { switch (action->type) { case CTL_TYPE_API: { - json_object *returnJ, *toReturnJ; + json_object *returnJ, *toReturnJ, *extendedQueryJ = NULL; if (action->argsJ) { switch(json_object_get_type(queryJ)) { case json_type_object: { - json_object_object_foreach(action->argsJ, key, val) { - json_object_get(val); - json_object_object_add(queryJ, key, val); - } + extendedQueryJ = wrap_json_clone(queryJ); + + wrap_json_object_add(extendedQueryJ, action->argsJ); break; } + case json_type_null: + extendedQueryJ = json_object_get(action->argsJ); break; + default: AFB_ApiError(action->api, "ActionExecOne(queryJ should be an object) uid=%s args=%s", source->uid, json_object_get_string(queryJ)); - return err; + return -1; } } + else { + extendedQueryJ = json_object_get(queryJ); + } /* AFB Subcall will release the json_object doing the json_object_put() call */ - int err = AFB_ServiceSync(action->api, action->exec.subcall.api, action->exec.subcall.verb, json_object_get(queryJ), &returnJ); + int err = AFB_ServiceSync(action->api, action->exec.subcall.api, action->exec.subcall.verb, extendedQueryJ, &returnJ); if(err && AFB_ReqIsValid(source->request)) AFB_ReqFailF(source->request, "subcall-fail", "ActionExecOne(AppFw) uid=%s api=%s verb=%s args=%s", source->uid, action->exec.subcall.api, action->exec.subcall.verb, json_object_get_string(action->argsJ)); else if(err && ! AFB_ReqIsValid(source->request)) -- cgit 1.2.3-korg