summaryrefslogtreecommitdiffstats
path: root/signal-composer-binding/signal-composer-binding.cpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-09-16 02:35:35 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-09-27 13:05:37 +0200
commite0655ca2d3d2db4c99d56da6fc90345e9093deb7 (patch)
tree333f2d69b49fd843b1a863963a5968f39b5b4e8e /signal-composer-binding/signal-composer-binding.cpp
parent56237d361bef0715aecad4c24f62608ea0bd629f (diff)
Fix: finding JSON file even if absolute path given
Here, assuming the absolute path leads to a non existent file then only take the file name and do a research in the default search path given by environment var or pre-processor defined variables. Change-Id: Id57428141be908cda65b07f66ca59568708d3608 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'signal-composer-binding/signal-composer-binding.cpp')
-rw-r--r--signal-composer-binding/signal-composer-binding.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/signal-composer-binding/signal-composer-binding.cpp b/signal-composer-binding/signal-composer-binding.cpp
index 234888c..5932640 100644
--- a/signal-composer-binding/signal-composer-binding.cpp
+++ b/signal-composer-binding/signal-composer-binding.cpp
@@ -178,9 +178,16 @@ void addObjects(afb_req request)
if(filepath)
{
objectsJ = json_object_from_file(filepath);
- if(!objectsJ)
+ if(! objectsJ)
{
- json_object* responseJ = ScanForConfig(CONTROL_CONFIG_PATH, CTL_SCAN_RECURSIVE, filepath, ".json");
+ const char *has_slash = strrchr(filepath, '/');
+ char *filename = has_slash ? strdupa(has_slash + 1) : strdupa(filepath);
+ char *filename_end = strrchr(filename, '.');
+ if (filename_end)
+ {*filename_end = '\0';}
+
+ json_object* responseJ = ScanForConfig(CONTROL_CONFIG_PATH, CTL_SCAN_RECURSIVE, filename, ".json");
+
if(responseJ)
{
filepath = ConfigSearch(nullptr, responseJ);