aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ctl-lib/ctl-config.c30
-rw-r--r--ctl-lib/ctl-config.h3
2 files changed, 18 insertions, 15 deletions
diff --git a/ctl-lib/ctl-config.c b/ctl-lib/ctl-config.c
index a98cb34..339b14c 100644
--- a/ctl-lib/ctl-config.c
+++ b/ctl-lib/ctl-config.c
@@ -161,21 +161,11 @@ int CtlConfigExec(AFB_ApiT apiHandle, CtlConfigT *ctlConfig) {
return errcount;
}
-CtlConfigT *CtlLoadMetaDataUsingPrefix(AFB_ApiT apiHandle,const char* filepath, const char *prefix) {
- json_object *ctlConfigJ;
+CtlConfigT *CtlLoadMetaDataJson(AFB_ApiT apiHandle, json_object *ctlConfigJ, const char *prefix) {
+ json_object *metadataJ;
CtlConfigT *ctlHandle=NULL;
int err;
- // Load JSON file
- ctlConfigJ = json_object_from_file(filepath);
- if (!ctlConfigJ) {
- AFB_ApiError(apiHandle, "CTL-LOAD-CONFIG Not invalid JSON %s ", filepath);
- return NULL;
- }
-
- AFB_ApiInfo(apiHandle, "CTL-LOAD-CONFIG: loading config filepath=%s", filepath);
-
- json_object *metadataJ;
int done = json_object_object_get_ex(ctlConfigJ, "metadata", &metadataJ);
if (done) {
ctlHandle = calloc(1, sizeof (CtlConfigT));
@@ -199,8 +189,20 @@ CtlConfigT *CtlLoadMetaDataUsingPrefix(AFB_ApiT apiHandle,const char* filepath,
return ctlHandle;
}
-CtlConfigT *CtlLoadMetaData(AFB_ApiT apiHandle, const char* filepath) {
- return CtlLoadMetaDataUsingPrefix(apiHandle, filepath, NULL);
+CtlConfigT *CtlLoadMetaDataUsingPrefix(AFB_ApiT apiHandle,const char* filepath, const char *prefix) {
+ json_object *ctlConfigJ;
+
+
+ // Load JSON file
+ ctlConfigJ = json_object_from_file(filepath);
+ if (!ctlConfigJ) {
+ AFB_ApiError(apiHandle, "CTL-LOAD-CONFIG Not invalid JSON %s ", filepath);
+ return NULL;
+ }
+
+ AFB_ApiInfo(apiHandle, "CTL-LOAD-CONFIG: loading config filepath=%s", filepath);
+
+ return CtlLoadMetaDataJson(apiHandle, ctlConfigJ, prefix);
}
void wrap_json_array_add(void* array, json_object *val) {
diff --git a/ctl-lib/ctl-config.h b/ctl-lib/ctl-config.h
index 2fc51cb..c130ece 100644
--- a/ctl-lib/ctl-config.h
+++ b/ctl-lib/ctl-config.h
@@ -103,9 +103,10 @@ extern char* ConfigSearch(AFB_ApiT apiHandle, json_object *responseJ);
extern char* CtlConfigSearch(AFB_ApiT apiHandle, const char *dirList, const char *prefix) ;
extern void DispatchRequireApi(AFB_ApiT apiHandle, json_object * requireJ);
extern int CtlConfigExec(AFB_ApiT apiHandle, CtlConfigT *ctlConfig) ;
-extern CtlConfigT *CtlLoadMetaData(AFB_ApiT apiHandle,const char* filepath) ;
+extern CtlConfigT *CtlLoadMetaDataJson(AFB_ApiT apiHandle,json_object *ctlConfigJ, const char *prefix) ;
extern CtlConfigT *CtlLoadMetaDataUsingPrefix(AFB_ApiT apiHandle,const char* filepath, const char *prefix) ;
extern int CtlLoadSections(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, CtlSectionT *sections);
+#define CtlLoadMetaData(api, filepath, prefix) CtlLoadMetaDataUsingPrefix(api, filepath, NULL)
// ctl-event.c
extern int EventConfig(AFB_ApiT apihandle, CtlSectionT *section, json_object *actionsJ);