aboutsummaryrefslogtreecommitdiffstats
path: root/ctl-lib/ctl-event.c
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-05-16 14:26:46 +0200
commit8f7e2014d030eb5117be6bac1aae88cd10e2127a (patch)
tree5ef3d9c38ba884a5ee982d1ab6cb981f2c08589a /ctl-lib/ctl-event.c
parenta633eb46a70d74fdb4a6f383ae5f3af34abb5bc1 (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/ctl-event.c')
-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