summaryrefslogtreecommitdiffstats
path: root/ctl-lib
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-04-24 15:18:05 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-12-13 15:02:54 +0100
commit1721310eb4b257338894c1a1bf364d4f8a7dd014 (patch)
treef9c34b5394c8382f5cb8df5787779de63e64c7c8 /ctl-lib
parent8cf21886c65c7c4a277eaee1a82edd3f9d894823 (diff)
Use an intermadiary variable avoiding side effets.
Previously using parameter and modifying it which could involves side effects. Better to use an intermediary json_object to be fills with action->argsJ and queryJ object meld together. Also fix segfault after json_object_put called inside AFB_ServiceSync doing a json_object_get() on object to be conserved Change-Id: I4618a7bc87e111afa1fe047168ba7232241ac4c8 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'ctl-lib')
-rw-r--r--ctl-lib/ctl-action.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/ctl-lib/ctl-action.c b/ctl-lib/ctl-action.c
index 87ee40f..cd0fcad 100644
--- a/ctl-lib/ctl-action.c
+++ b/ctl-lib/ctl-action.c
@@ -65,28 +65,31 @@ PUBLIC void ActionExecOne(CtlSourceT *source, CtlActionT* action, json_object *q
switch (action->type) {
case CTL_TYPE_API:
{
- json_object *returnJ;
+ json_object *returnJ, *subcallArgsJ = json_object_new_object();
- // if query is empty increment usage count and pass args
- if (!queryJ || json_object_get_type(queryJ) != json_type_object) {
- json_object_get(action->argsJ);
- queryJ = action->argsJ;
- } else if (action->argsJ) {
+ if(queryJ) {
+ json_object_object_foreach(queryJ, key, val) {
+ json_object_object_add(subcallArgsJ, key, val);
+ }
+ }
+ if (action->argsJ) {
// Merge queryJ and argsJ before sending request
if (json_object_get_type(action->argsJ) == json_type_object) {
json_object_object_foreach(action->argsJ, key, val) {
- json_object_object_add(queryJ, key, val);
+ json_object_get(val);
+ json_object_object_add(subcallArgsJ, key, val);
}
} else {
- json_object_object_add(queryJ, "args", action->argsJ);
+ json_object_get(action->argsJ);
+ json_object_object_add(subcallArgsJ, "args", action->argsJ);
}
}
- json_object_object_add(queryJ, "uid", json_object_new_string(source->uid));
+ json_object_object_add(subcallArgsJ, "uid", json_object_new_string(source->uid));
- int err = AFB_ServiceSync(action->api, action->exec.subcall.api, action->exec.subcall.verb, queryJ, &returnJ);
+ int err = AFB_ServiceSync(action->api, action->exec.subcall.api, action->exec.subcall.verb, subcallArgsJ, &returnJ);
if (err) {
AFB_ApiError(action->api, "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));
}