summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2018-07-06 14:39:42 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-12-13 15:02:55 +0100
commitad4d3750daa2ec3734ad79a87829a2c529a021a7 (patch)
tree9207db4db6aa22581fdc433a65fd2b27d738473e
parentd0035a84e055fe2224fd1333f814873578e3dde6 (diff)
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 <jonathan.aillet@iot.bzh>
-rw-r--r--ctl-lib/ctl-action.c19
1 files changed, 12 insertions, 7 deletions
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))