From 26f992edfcb8159d81668db2292e1d776a8f0c7a Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Wed, 16 May 2018 14:26:46 +0200 Subject: Search for Event section Don't use a static and fixed index to reach event section. Rather browse sections array to find it Change-Id: I4eed8abf73f674034da252aa9d133325f82e62c2 Signed-off-by: Romain Forlot --- ctl-lib/ctl-event.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'ctl-lib') diff --git a/ctl-lib/ctl-event.c b/ctl-lib/ctl-event.c index 08cc04f..4e20bba 100644 --- a/ctl-lib/ctl-event.c +++ b/ctl-lib/ctl-event.c @@ -26,27 +26,35 @@ // Event dynamic API-V3 mode #ifdef AFB_BINDING_PREV3 void CtrlDispatchApiEvent (AFB_ApiT apiHandle, const char *evtLabel, struct json_object *eventJ) { + int idx = 0; + CtlActionT* actions = NULL; AFB_ApiNotice (apiHandle, "Received event=%s, query=%s", evtLabel, json_object_get_string(eventJ)); // retrieve section config from api handle CtlConfigT *ctrlConfig = (CtlConfigT*) afb_dynapi_get_userdata(apiHandle); - CtlActionT* actions = ctrlConfig->sections[CTL_SECTION_EVENT].actions; + for (idx = 0; ctrlConfig->sections[idx].key != NULL; ++idx) + { + if(! strcasecmp(ctrlConfig->sections[idx].key, "events")) { + actions = ctrlConfig->sections[idx].actions; + break; + } + } - int index= ActionLabelToIndex(actions, evtLabel); - if (index < 0) { + idx = ActionLabelToIndex(actions, evtLabel); + if (idx < 0) { AFB_ApiWarning(apiHandle, "CtlDispatchEvent: fail to find uid=%s in action event section", evtLabel); return; } // create a dummy source for action CtlSourceT source; - source.uid = actions[index].uid; - source.api = actions[index].api; + source.uid = actions[idx].uid; + source.api = actions[idx].api; source.request = NULL; // Best effort ignoring error to exec corresponding action - (void) ActionExecOne (&source, &actions[index], eventJ); + (void) ActionExecOne (&source, &actions[idx], json_object_get(eventJ)); } #else @@ -69,7 +77,7 @@ void CtrlDispatchV2Event(const char *evtLabel, json_object *eventJ) { source.request = AFB_ReqNone; // Best effort ignoring error to exec corresponding action - (void) ActionExecOne (&source, &actions[index], eventJ); + (void) ActionExecOne (&source, &actions[index], json_object_get(eventJ)); } #endif -- cgit 1.2.3-korg