summaryrefslogtreecommitdiffstats
path: root/ctl-lib
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-12-04 10:15:57 +0100
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-12-04 15:09:23 +0100
commit2a588b74822cf093198bdbc01fb0f2d57a3f3fec (patch)
tree79abbecfb1243266892eed540039d314d4ba36e0 /ctl-lib
parent3dd9b3710a6724538c9b87581a1d7182808f3ba3 (diff)
Add function to get config default search path
Add a function to get default search path for controller json configuration files. BUG-AGL: SPEC-3011 Change-Id: Ib19824349eb599332c86c8e0647fe60cb5fb0144 Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to 'ctl-lib')
-rw-r--r--ctl-lib/ctl-config.c39
-rw-r--r--ctl-lib/ctl-config.h2
2 files changed, 41 insertions, 0 deletions
diff --git a/ctl-lib/ctl-config.c b/ctl-lib/ctl-config.c
index 9039ac5..e6a16b9 100644
--- a/ctl-lib/ctl-config.c
+++ b/ctl-lib/ctl-config.c
@@ -346,3 +346,42 @@ int CtlLoadSections(afb_api_t apiHandle, CtlConfigT *ctlHandle, CtlSectionT *sec
return 0;
}
+
+char *GetDefaultConfigSearchPath(afb_api_t apiHandle)
+{
+ size_t searchPathLength;
+ char *searchPath, *binderRootDirPath, *bindingParentDirPath;
+
+ if(! apiHandle)
+ return NULL;
+
+ binderRootDirPath = GetAFBRootDirPath(apiHandle);
+ if(! binderRootDirPath)
+ return NULL;
+
+ bindingParentDirPath = GetBindingParentDirPath(apiHandle);
+ if(! bindingParentDirPath) {
+ free(binderRootDirPath);
+ return NULL;
+ }
+
+ /* Allocating with the size of binding root dir path + binding parent directory path
+ * + 1 character for the NULL terminating character + 1 character for the additional separator
+ * between binderRootDirPath and bindingParentDirPath + 2*4 char for '/etc suffixes'.
+ */
+ searchPathLength = strlen(binderRootDirPath) + strlen(bindingParentDirPath) + 10;
+
+ searchPath = malloc(searchPathLength);
+ if(! searchPath) {
+ free(binderRootDirPath);
+ free(bindingParentDirPath);
+ return NULL;
+ }
+
+ snprintf(searchPath, searchPathLength, "%s/etc:%s/etc", binderRootDirPath, bindingParentDirPath);
+
+ free(binderRootDirPath);
+ free(bindingParentDirPath);
+
+ return searchPath;
+}
diff --git a/ctl-lib/ctl-config.h b/ctl-lib/ctl-config.h
index dc98bb2..53a75f4 100644
--- a/ctl-lib/ctl-config.h
+++ b/ctl-lib/ctl-config.h
@@ -111,6 +111,7 @@ extern int CtlConfigExec(afb_api_t apiHandle, CtlConfigT *ctlConfig) ;
extern CtlConfigT *CtlLoadMetaDataJson(afb_api_t apiHandle,json_object *ctlConfigJ, const char *prefix) ;
extern CtlConfigT *CtlLoadMetaDataUsingPrefix(afb_api_t apiHandle,const char* filepath, const char *prefix) ;
extern int CtlLoadSections(afb_api_t apiHandle, CtlConfigT *ctlHandle, CtlSectionT *sections);
+extern char *GetDefaultConfigSearchPath(afb_api_t apiHandle);
#define CtlLoadMetaData(api, filepath) CtlLoadMetaDataUsingPrefix(api, filepath, NULL)
// ctl-event.c
@@ -129,6 +130,7 @@ extern int PluginConfig(afb_api_t UNUSED_ARG(apiHandle), CtlSectionT *section, j
extern int PluginGetCB (afb_api_t apiHandle, CtlActionT *action , json_object *callbackJ);
extern void* getPluginContext(CtlPluginT *plugin);
extern void setPluginContext(CtlPluginT *plugin, void *context);
+
#ifdef __cplusplus
}
#endif