summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ctl-lib/ctl-action.c44
-rw-r--r--ctl-lib/ctl-config.h1
-rw-r--r--ctl-lib/ctl-control.c15
-rw-r--r--ctl-lib/ctl-event.c12
-rw-r--r--ctl-lib/ctl-onload.c9
5 files changed, 59 insertions, 22 deletions
diff --git a/ctl-lib/ctl-action.c b/ctl-lib/ctl-action.c
index 8aa5dc7..a42e8b5 100644
--- a/ctl-lib/ctl-action.c
+++ b/ctl-lib/ctl-action.c
@@ -363,3 +363,47 @@ CtlActionT *ActionConfig(AFB_ApiT apiHandle, json_object *actionsJ, int exportAp
return actions;
}
+
+int AddActionsToSection(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ, int exportApi) {
+ if (actionsJ || section) {
+ CtlActionT *actions = NULL;
+ if(section->actions) {
+ int actionsNb = 0, idx = 0, jdx = 0;
+ CtlActionT *savedActions = section->actions;
+ CtlActionT *newActions = ActionConfig(apiHandle, actionsJ, exportApi);
+
+ while(savedActions[actionsNb].uid)
+ actionsNb++;
+ while(newActions[actionsNb].uid)
+ actionsNb++;
+
+ actions = calloc(actionsNb + 1, sizeof(CtlActionT));
+
+ while(savedActions[idx].uid) {
+ actions[idx] = savedActions[idx];
+ idx++;
+ }
+ while(newActions[jdx].uid && idx <= actionsNb) {
+ actions[idx] = newActions[jdx];
+ idx++;
+ jdx++;
+ }
+ free(savedActions);
+ free(newActions);
+ }
+ else {
+ actions = ActionConfig(apiHandle, actionsJ, exportApi);
+ }
+ section->actions = actions;
+ }
+ else {
+ AFB_ApiError (apiHandle, "Missing actions to add or the section object");
+ return 1;
+ }
+
+ if (!section->actions) {
+ AFB_ApiError (apiHandle, "Adding '%s' fails to section %s", json_object_get_string(actionsJ), section->uid);
+ return 1;
+ }
+ return 0;
+}
diff --git a/ctl-lib/ctl-config.h b/ctl-lib/ctl-config.h
index b2f1e2f..1e9837c 100644
--- a/ctl-lib/ctl-config.h
+++ b/ctl-lib/ctl-config.h
@@ -90,6 +90,7 @@ typedef enum {
} SectionEnumT;
// ctl-action.c
+extern int AddActionsToSection(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ, int exportApi);
extern CtlActionT *ActionConfig(AFB_ApiT apiHandle, json_object *actionsJ, int exportApi);
extern void ActionExecUID(AFB_ReqT request, CtlConfigT *ctlConfig, const char *uid, json_object *queryJ);
extern int ActionExecOne( CtlSourceT *source, CtlActionT* action, json_object *queryJ);
diff --git a/ctl-lib/ctl-control.c b/ctl-lib/ctl-control.c
index 0605d6b..b28ff4c 100644
--- a/ctl-lib/ctl-control.c
+++ b/ctl-lib/ctl-control.c
@@ -24,15 +24,12 @@
// onload section receive one action or an array of actions
int ControlConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ) {
-
- // Load time parse actions in config file
- if (actionsJ != NULL) {
- section->actions= ActionConfig(apiHandle, actionsJ, 1);
-
- if (!section->actions) {
- AFB_ApiError (apiHandle, "ControlLoad config fail processing onload actions");
- return 1;
+ int err = 0;
+ if (actionsJ) {
+ if ( (err= AddActionsToSection(apiHandle, section, actionsJ, 1)) ) {
+ AFB_ApiError (apiHandle, "ControlLoad config fail processing actions for section %s", section->uid);
+ return err;
}
}
- return 0;
+ return err;
}
diff --git a/ctl-lib/ctl-event.c b/ctl-lib/ctl-event.c
index 4174000..1bed333 100644
--- a/ctl-lib/ctl-event.c
+++ b/ctl-lib/ctl-event.c
@@ -86,16 +86,14 @@ void CtrlDispatchV2Event(const char *evtLabel, json_object *eventJ) {
// onload section receive one action or an array of actions
int EventConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ) {
-
+ int err = 0;
// Load time parse actions in config file
if (actionsJ != NULL) {
- section->actions= ActionConfig(apiHandle, actionsJ, 0);
-
- if (!section->actions) {
- AFB_ApiError (apiHandle, "EventLoad config fail processing onload actions");
- return 1;
+ if ( (err= AddActionsToSection(apiHandle, section, actionsJ, 0)) ) {
+ AFB_ApiError (apiHandle, "EventLoad config fail processing actions for section %s", section->uid);
+ return err;
}
}
- return 0;
+ return err;
}
diff --git a/ctl-lib/ctl-onload.c b/ctl-lib/ctl-onload.c
index 9baa689..b537590 100644
--- a/ctl-lib/ctl-onload.c
+++ b/ctl-lib/ctl-onload.c
@@ -28,13 +28,10 @@ int OnloadConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ
// Load time parse actions in control file
if (actionsJ != NULL) {
- section->actions= ActionConfig(apiHandle, actionsJ, 0);
-
- if (!section->actions) {
- AFB_ApiError (apiHandle, "OnloadConfig control fail processing onload actions");
- return 1;
+ if ( (err= AddActionsToSection(apiHandle, section, actionsJ, 0)) ) {
+ AFB_ApiError (apiHandle, "OnloadConfig control fail processing actions for section %s", section->uid);
+ return err;
}
-
} else {
// Exec time process onload action now
if (!section->actions) {