aboutsummaryrefslogtreecommitdiffstats
path: root/ctl-lib
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-05-16 14:26:46 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-12-13 15:02:54 +0100
commit26f992edfcb8159d81668db2292e1d776a8f0c7a (patch)
tree5ef3d9c38ba884a5ee982d1ab6cb981f2c08589a /ctl-lib
parent1817f8b71b99fbd909937bde1812ca3a0c4c4a85 (diff)
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 <romain.forlot@iot.bzh>
Diffstat (limited to 'ctl-lib')
-rw-r--r--ctl-lib/ctl-event.c22
1 files changed, 15 insertions, 7 deletions
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