diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2018-07-18 19:50:57 +0200 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2018-07-21 10:05:16 +0000 |
commit | 3f00d0fea4b8db29ef8268f2189704a3ea8e3360 (patch) | |
tree | 03d2d6abb708a8830682250653c43d79d24100cf /src/mapis.c | |
parent | 99043faef2d12b70dc27e2c816738a9ba2fff659 (diff) |
Fix: events callback aren't correctly registered
They were stored in the mapis sections instead of the events
one.
Clean and handle raw events as well. Before that it could
only process events coming from monitoring api. Now it could
receive the event directly.
Make sure that the event handle is valid before sends the
request response. This prevent to subcribe or push an event
while the event handle hasn't been correctly created. This
could happens if the testVerb hasn't not been called from a
session. In that case, the response will just be that tests
has been launched.
Format.
Change-Id: I0aa522939162684f91dd426cc14919bb0ec3f69e
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'src/mapis.c')
-rw-r--r-- | src/mapis.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/mapis.c b/src/mapis.c index 145c01f..64543e5 100644 --- a/src/mapis.c +++ b/src/mapis.c @@ -16,8 +16,9 @@ * limitations under the License. */ +#include <string.h> #include <mapis.h> -#include <ctl-plugin.h> +#include <ctl-config.h> struct mapisHandleT { AFB_ApiT mainApiHandle; @@ -27,11 +28,11 @@ struct mapisHandleT { json_object *eventsJ; }; -static int LoadOneMapi(void *data, AFB_ApiT apiHandle) -{ - int savedCount = 0, count = 0; +static int LoadOneMapi(void *data, AFB_ApiT apiHandle) { + int savedCount = 0, count = 0, idx = 0; CtlActionT *savedActions = NULL, *newActions = NULL; struct mapisHandleT *mapisHandle = (struct mapisHandleT*)data; + CtlConfigT *ctrlConfig = afb_dynapi_get_userdata(mapisHandle->mainApiHandle); if(PluginConfig(apiHandle, mapisHandle->section, mapisHandle->mapiJ)) { AFB_ApiError(apiHandle, "Problem loading the plugin as an API for %s, see log message above", json_object_get_string(mapisHandle->mapiJ)); @@ -45,7 +46,12 @@ static int LoadOneMapi(void *data, AFB_ApiT apiHandle) } // Add actions to the section to be able to respond to defined events. - savedActions = mapisHandle->section->actions; + for(idx = 0; ctrlConfig->sections[idx].key != NULL; ++idx) { + if(! strcasecmp(ctrlConfig->sections[idx].key, "events")) { + savedActions = ctrlConfig->sections[idx].actions; + break; + } + } newActions = ActionConfig(apiHandle, mapisHandle->eventsJ, 0); if(savedActions) { @@ -71,10 +77,10 @@ static int LoadOneMapi(void *data, AFB_ApiT apiHandle) while(newActions[savedCount].uid != NULL && count <= total) { mergedActions[count] = newActions[savedCount]; count++; - savedActions++; + savedCount++; } - mapisHandle->section->actions = mergedActions; + ctrlConfig->sections[idx].actions = mergedActions; // declare an event event manager for this API; afb_dynapi_on_event(apiHandle, CtrlDispatchApiEvent); @@ -96,8 +102,8 @@ static void OneMapiConfig(void *data, json_object *mapiJ) { "lua", NULL, "verbs", &mapisHandle->verbsJ, "events", &mapisHandle->eventsJ)) { - AFB_ApiError(mapisHandle->mainApiHandle, "Wrong mapis specification, missing uid|[info]|[spath]|libs|[lua]|verbs|[events] for %s", json_object_get_string(mapiJ)); - return; + AFB_ApiError(mapisHandle->mainApiHandle, "Wrong mapis specification, missing uid|[info]|[spath]|libs|[lua]|verbs|[events] for %s", json_object_get_string(mapiJ)); + return; } json_object_get(mapisHandle->verbsJ); |