From 559f25af7a412a54ee0675877c6a82c3bb36cbe2 Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Fri, 3 Aug 2018 14:10:29 +0200 Subject: Add path to the installed widget path. This resolves the link to the binding library then set the directory path to the widget installation location. Change-Id: Iaad0d8aad6e3b8bfdcdedde19fb7906adf5f9610 Signed-off-by: Romain Forlot --- ctl-lib/ctl-plugin.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'ctl-lib') diff --git a/ctl-lib/ctl-plugin.c b/ctl-lib/ctl-plugin.c index 0c0bacc..7755f4a 100644 --- a/ctl-lib/ctl-plugin.c +++ b/ctl-lib/ctl-plugin.c @@ -239,30 +239,46 @@ static int LoadFoundPlugins(AFB_ApiT apiHandle, json_object *scanResult, json_ob char *GetDefaultPluginSearchPath(AFB_ApiT apiHandle, const char *prefix) { - char *searchPath; + char *searchPath, *rootDir, *path; const char *bindingPath; const char *envDirList; - size_t bindingPath_len, envDirList_len; + size_t envDirList_len; + json_object *settings = afb_api_settings(apiHandle); + json_object *bpath; + + if(json_object_object_get_ex(settings, "binding-path", &bpath)) { + rootDir = strdup(json_object_get_string(bpath)); + path = rindex(rootDir, '/'); + if(strlen(path) < 3) + return NULL; + *++path = '.'; + *++path = '.'; + *++path = '\0'; + } + else { + rootDir = malloc(1); + strcpy(rootDir, ""); + } bindingPath = GetBindingDirPath(apiHandle); - bindingPath_len = strlen(bindingPath); envDirList = getEnvDirList(prefix, "PLUGIN_PATH"); /* Allocating with the size of binding root dir path + environment if found - * + 2 for the NULL terminating character and the additional separator + * for the NULL terminating character and the additional separator * between bindingPath and envDirList concatenation. */ if(envDirList) { - envDirList_len = strlen(CONTROL_PLUGIN_PATH) + strlen(envDirList) + bindingPath_len + 2; + envDirList_len = strlen(CONTROL_PLUGIN_PATH) + strlen(envDirList) + strlen(bindingPath) + strlen(rootDir) + 3; searchPath = malloc(envDirList_len + 1); - snprintf(searchPath, envDirList_len + 1, "%s:%s:%s", bindingPath, envDirList, CONTROL_PLUGIN_PATH); + snprintf(searchPath, envDirList_len + 1, "%s:%s:%s:%s", rootDir, bindingPath, envDirList, CONTROL_PLUGIN_PATH); } else { - envDirList_len = strlen(CONTROL_PLUGIN_PATH) + bindingPath_len + 1; + envDirList_len = strlen(CONTROL_PLUGIN_PATH) + strlen(bindingPath) + strlen(rootDir) + 2; searchPath = malloc(envDirList_len + 1); - snprintf(searchPath, envDirList_len + 1, "%s:%s", bindingPath, CONTROL_PLUGIN_PATH); + snprintf(searchPath, envDirList_len + 1, "%s:%s:%s", rootDir, bindingPath, CONTROL_PLUGIN_PATH); } + free(rootDir); return searchPath; } -- cgit 1.2.3-korg