summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/aft.c10
-rw-r--r--src/mapis.c24
2 files changed, 20 insertions, 14 deletions
diff --git a/src/aft.c b/src/aft.c
index 36a8b17..1a5edc1 100644
--- a/src/aft.c
+++ b/src/aft.c
@@ -62,7 +62,7 @@ static AFB_ApiVerbs CtrlApiVerbs[] = {
static int CtrlLoadStaticVerbs(afb_dynapi *apiHandle, AFB_ApiVerbs *verbs) {
int errcount = 0;
- for (int idx = 0; verbs[idx].verb; idx++) {
+ for(int idx = 0; verbs[idx].verb; idx++) {
errcount += afb_dynapi_add_verb(
apiHandle, CtrlApiVerbs[idx].verb, NULL, CtrlApiVerbs[idx].callback,
(void *)&CtrlApiVerbs[idx], CtrlApiVerbs[idx].auth, 0);
@@ -91,7 +91,7 @@ static int CtrlLoadOneApi(void *cbdata, AFB_ApiT apiHandle) {
// add static controls verbs
int err = CtrlLoadStaticVerbs(apiHandle, CtrlApiVerbs);
- if (err) {
+ if(err) {
AFB_ApiError(apiHandle, "CtrlLoadSection fail to register static V2 verbs");
return ERROR;
}
@@ -132,21 +132,21 @@ int afbBindingEntry(afb_dynapi *apiHandle) {
}
configPath = CtlConfigSearch(apiHandle, dirList, prefix);
- if (!configPath) {
+ if(!configPath) {
AFB_ApiError(apiHandle, "CtlPreInit: No %s* config found in %s ", GetBinderName(), dirList);
return ERROR;
}
// load config file and create API
ctrlConfig = CtlLoadMetaDataUsingPrefix(apiHandle, configPath, prefix);
- if (!ctrlConfig) {
+ if(!ctrlConfig) {
AFB_ApiError(apiHandle,
"CtrlBindingDyn No valid control config file in:\n-- %s",
configPath);
return ERROR;
}
- if (!ctrlConfig->api) {
+ if(!ctrlConfig->api) {
AFB_ApiError(apiHandle,
"CtrlBindingDyn API Missing from metadata in:\n-- %s",
configPath);
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);