aboutsummaryrefslogtreecommitdiffstats
path: root/controller
diff options
context:
space:
mode:
Diffstat (limited to 'controller')
-rw-r--r--controller/ctl-action.c3
-rw-r--r--controller/ctl-config.c109
-rw-r--r--controller/ctl-plugin.c37
3 files changed, 83 insertions, 66 deletions
diff --git a/controller/ctl-action.c b/controller/ctl-action.c
index 5da24e8..8e2db1a 100644
--- a/controller/ctl-action.c
+++ b/controller/ctl-action.c
@@ -28,7 +28,6 @@
int ActionExecOne(CtlActionT* action, json_object *queryJ) {
int err;
-
switch (action->type) {
case CTL_TYPE_API:
{
@@ -146,7 +145,7 @@ OnErrorExit:
};
CtlActionT *ActionLoad(json_object *actionsJ) {
- int err;
+ int err = 0;
CtlActionT *actions;
// action array is close with a nullvalue;
diff --git a/controller/ctl-config.c b/controller/ctl-config.c
index 948f0d1..888b420 100644
--- a/controller/ctl-config.c
+++ b/controller/ctl-config.c
@@ -25,7 +25,6 @@
#include "filescan-utils.h"
#include "ctl-config.h"
-
// Load control config file
char* CtlConfigSearch(const char *dirList, const char* fileName) {
@@ -69,6 +68,61 @@ char* CtlConfigSearch(const char *dirList, const char* fileName) {
return NULL;
}
+json_object* loadJSON(const char* filepath, const char* fileName)
+{
+ // Search for config in filepath
+ const char* filepathFound = CtlConfigSearch(filepath, fileName);
+ if(!filepathFound)
+ {
+ AFB_ERROR("CTL-LOAD-CONFIG No JSON Config found in %s", filepath);
+ return NULL;
+ }
+ return json_object_from_file(filepathFound);
+}
+
+int browseAdditionnalFiles(CtlConfigT* ctlConfig, const char* filepath, int sectionIdx){
+ int err = 0;
+ int done = 0;
+ const char* fileName;
+ json_object* configJ = NULL, *sectionJ = NULL;
+ CtlSectionT* sections = ctlConfig->sections;
+
+ if (json_object_get_type(ctlConfig->filesJ) == json_type_array) {
+ int filesEnd = json_object_array_length(ctlConfig->filesJ);
+ for (int jdx = 0; jdx < filesEnd; jdx++) {
+ fileName = json_object_get_string(json_object_array_get_idx(ctlConfig->filesJ, jdx));
+ configJ = loadJSON(filepath, fileName);
+ if(json_object_object_get_ex(configJ, sections[sectionIdx].key, &sectionJ))
+ {
+ err += sections[sectionIdx].loadCB(&sections[sectionIdx], sectionJ);
+ done++;
+ }
+ }
+ if(!done) {
+ AFB_ERROR("CtlConfigLoad: fail to find '%s' section in config '%s' with '%s' in its name", sections[sectionIdx].key, filepath, fileName);
+ err++;
+ }
+ if(err) {goto OnErrorExit;}
+ } else {
+ fileName = json_object_get_string(ctlConfig->filesJ);
+ configJ = loadJSON(filepath, fileName);
+ if(json_object_object_get_ex(configJ, sections[sectionIdx].key, &sectionJ)) {
+ err += sections[sectionIdx].loadCB(&sections[sectionIdx], sectionJ);
+ done++;
+ }
+ else {
+ AFB_ERROR("CtlConfigLoad: fail to find '%s' section in config '%s' with '%s' in its name", sections[sectionIdx].key, filepath, fileName);
+ err++;
+ }
+ if(err) {goto OnErrorExit;}
+ }
+
+ return err;
+
+ OnErrorExit:
+ return err;
+}
+
int CtlConfigExec(CtlConfigT *ctlConfig) {
// best effort to initialise everything before starting
if (ctlConfig->requireJ) {
@@ -113,20 +167,8 @@ CtlConfigT *CtlConfigLoad(const char* filepath, CtlSectionT *sections) {
if (err) goto OnErrorExit;
#endif
- json_object* loadJSON(const char* fileName)
- {
- // Search for config in filepath
- const char* filepathFound = CtlConfigSearch(filepath, fileName);
- if(!filepathFound)
- {
- AFB_ERROR("CTL-LOAD-CONFIG No JSON Config found in %s", filepath);
- return NULL;
- }
- return json_object_from_file(filepathFound);
- }
-
// Load JSON file
- ctlConfigJ = loadJSON(NULL);
+ ctlConfigJ = loadJSON(filepath, NULL);
if (!ctlConfigJ) {
AFB_ERROR("CTL-LOAD-CONFIG Invalid JSON %s ", filepath);
goto OnErrorExit;
@@ -161,42 +203,11 @@ CtlConfigT *CtlConfigLoad(const char* filepath, CtlSectionT *sections) {
ctlConfig->sections = sections;
for (int idx = 0; sections[idx].key != NULL; idx++) {
- json_object * sectionJ;
+ json_object * sectionJ = NULL;
int done = json_object_object_get_ex(ctlConfigJ, sections[idx].key, &sectionJ);
if (!done) {
- json_object* configJ = NULL;
- const char* fileName;
AFB_DEBUG("CtlConfigLoad: fail to find '%s' section in config '%s'. Searching deeper", sections[idx].key, filepath);
- if (json_object_get_type(ctlConfig->filesJ) == json_type_array) {
- int filesEnd = json_object_array_length(ctlConfig->filesJ);
- for (int jdx = 0; jdx < filesEnd; jdx++) {
- fileName = json_object_get_string(json_object_array_get_idx(ctlConfig->filesJ, jdx));
- configJ = loadJSON(fileName);
- if(json_object_object_get_ex(configJ, sections[idx].key, &sectionJ))
- {
- const char* k = sections[idx].key;
- err += sections[idx].loadCB(&sections[idx], sectionJ);
- done++;
- }
- }
- if(!done) {
- AFB_ERROR("CtlConfigLoad: fail to find '%s' section in config '%s' with '%s' in its name", sections[idx].key, filepath, fileName);
- err++;
- }
- if(err) {goto OnErrorExit;}
- } else {
- fileName = json_object_get_string(ctlConfig->filesJ);
- configJ = loadJSON(fileName);
- if(json_object_object_get_ex(configJ, sections[idx].key, &sectionJ)) {
- err += sections[idx].loadCB(&sections[idx], sectionJ);
- done++;
- }
- else {
- AFB_ERROR("CtlConfigLoad: fail to find '%s' section in config '%s' with '%s' in its name", sections[idx].key, filepath, fileName);
- err++;
- }
- if(err) {goto OnErrorExit;}
- }
+ err += browseAdditionnalFiles(ctlConfig, filepath, idx);
} else {
err += sections[idx].loadCB(&sections[idx], sectionJ);
}
@@ -209,7 +220,3 @@ OnErrorExit:
free(ctlConfig);
return NULL;
}
-
-
-
-
diff --git a/controller/ctl-plugin.c b/controller/ctl-plugin.c
index ae203af..b14d591 100644
--- a/controller/ctl-plugin.c
+++ b/controller/ctl-plugin.c
@@ -153,10 +153,6 @@ STATIC int PluginLoadOne (CtlPluginT *ctlPlugin, json_object *pluginJ, void* han
// store dlopen handle to enable onload action at exec time
ctlPlugin->dlHandle = dlHandle;
- // Jose hack to make verbosity visible from sharedlib
- struct afb_binding_data_v2 *afbHidenData = dlsym(dlHandle, "afbBindingV2data");
- if (afbHidenData) *afbHidenData = afbBindingV2data;
-
// Push lua2cWrapper @ into plugin
Lua2cWrapperT *lua2cInPlug = dlsym(dlHandle, "Lua2cWrap");
#ifndef CONTROL_SUPPORT_LUA
@@ -219,16 +215,31 @@ OnErrorExit:
int PluginConfig(CtlSectionT *section, json_object *pluginsJ) {
int err=0;
- if (json_object_get_type(pluginsJ) == json_type_array) {
- int length = json_object_array_length(pluginsJ);
- ctlPlugins = calloc (length+1, sizeof(CtlPluginT));
- for (int idx=0; idx < length; idx++) {
- json_object *pluginJ = json_object_array_get_idx(pluginsJ, idx);
- err += PluginLoadOne(&ctlPlugins[idx], pluginJ, section->handle);
+ if (ctlPlugins)
+ {
+ int pluginsCount = (sizeof(ctlPlugins) / sizeof(CtlPluginT)) + 1;
+ for(int idx = 0; idx < pluginsCount; idx++)
+ {
+ // Jose hack to make verbosity visible from sharedlib and
+ // be able to call verb from others api inside the binder
+ struct afb_binding_data_v2 *afbHidenData = dlsym(ctlPlugins[idx].dlHandle, "afbBindingV2data");
+ if (afbHidenData) *afbHidenData = afbBindingV2data;
+ }
+ return 0;
+ }
+ else
+ {
+ if (json_object_get_type(pluginsJ) == json_type_array) {
+ int length = json_object_array_length(pluginsJ);
+ ctlPlugins = calloc (length+1, sizeof(CtlPluginT));
+ for (int idx=0; idx < length; idx++) {
+ json_object *pluginJ = json_object_array_get_idx(pluginsJ, idx);
+ err += PluginLoadOne(&ctlPlugins[idx], pluginJ, section->handle);
+ }
+ } else {
+ ctlPlugins = calloc (2, sizeof(CtlPluginT));
+ err += PluginLoadOne(&ctlPlugins[0], pluginsJ, section->handle);
}
- } else {
- ctlPlugins = calloc (2, sizeof(CtlPluginT));
- err += PluginLoadOne(&ctlPlugins[0], pluginsJ, section->handle);
}
return err;