aboutsummaryrefslogtreecommitdiffstats
path: root/ctl-lib/ctl-config.c
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-07-25 14:37:48 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-12-13 15:02:55 +0100
commitbd628542a769abf45174d694457c1ff6974bdacb (patch)
tree6b4364896e9a752e8bbd9bab7d1a47f7ba614e4a /ctl-lib/ctl-config.c
parent7fd47c1f35871041ef8959c0591fcd8cd5cff724 (diff)
Split loading JSON controller file.
This make possible to load from a binding either a file or directly a JSON object. Change-Id: If3f3edb8aaed066922982250dd162d483a7dc47a Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'ctl-lib/ctl-config.c')
-rw-r--r--ctl-lib/ctl-config.c30
1 files changed, 16 insertions, 14 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) {