Add 'GetRunningBindingDirPath' function 42/23142/4 8.99.2 8.99.3 8.99.4 icefish/8.99.2 icefish/8.99.3 icefish/8.99.4 icefish_8.99.2 icefish_8.99.3 icefish_8.99.4
authorJonathan Aillet <jonathan.aillet@iot.bzh>
Tue, 3 Dec 2019 16:16:19 +0000 (17:16 +0100)
committerJonathan Aillet <jonathan.aillet@iot.bzh>
Wed, 4 Dec 2019 13:45:36 +0000 (14:45 +0100)
Add 'GetRunningBindingDirPath' function that returns the binding
directory path (the path to the directory that contains the binding).

FYI:
- 'Binding directory path' is the path to the directory that contains
a binding binding launched by the binder.
- 'Binder root directory path' is the path specified at binder launch
using '--rootdir' option. If no option is specified, binder root
directory is set to the current directory.

SPEC-AGL: SPEC-3009

Change-Id: I34b3d17710ebc2bf06541a00ca7f8d7189f6aa18
Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
docs/filescan-utils.md
filescan-utils.c
filescan-utils.h

index d91ff1c..6b52cd2 100644 (file)
@@ -58,6 +58,15 @@ For binding with a version >= 3, same as 'GetAFBRootDirPath' function.
 Deprecated, please use 'GetAFBRootDirPath' function.
 Kept for compatibility issues.
 
+## char *GetRunningBindingDirPath(afb_api_t api)
+
+For binding with a version >= 3, get the binding directory path
+(the path to the directory that contains the binding).
+
+* `api` : pointer to the AFB API.
+
+Returns a string representing the path to the binding directory.
+
 ## const char *getEnvDirList(const char *prefix, const char *suffix)
 
 Get the environment directory colon separated path list. This take the prefix
index 236e192..6ac90fe 100644 (file)
@@ -179,7 +179,33 @@ char *GetAFBRootDirPath(afb_api_t apiHandle)
     return GetAFBRootDirPathUsingFd(fd);
 }
 
+char *GetRunningBindingDirPath(afb_api_t apiHandle)
+{
+    int ret;
+
+    char *lastSlashInPath, *bindingDirectoryPath;
+    const char *bindingPath;
+
+    json_object *settingsJ, *bindingPathJ = NULL;
+
+    settingsJ = afb_api_settings(apiHandle);
+    if(!settingsJ)
+        return NULL;
+
+    ret = json_object_object_get_ex(settingsJ, "binding-path", &bindingPathJ);
+    if(!ret || !bindingPathJ || !json_object_is_type(bindingPathJ, json_type_string))
+        return NULL;
+
+    bindingPath = json_object_get_string(bindingPathJ);
+
+    lastSlashInPath = rindex(bindingPath, '/');
+    if(!lastSlashInPath)
+        return NULL;
+
+    bindingDirectoryPath = strndup(bindingPath, lastSlashInPath - bindingPath);
 
+    return bindingDirectoryPath;
+}
 
 
 /**
index f96d903..0783ebe 100644 (file)
@@ -123,6 +123,16 @@ __attribute__((alias("GetAFBRootDirPath_v3")))
 static char *GetBindingDirPath(afb_api_t api);
 #endif
 
+/*
+ * @brief Get the Binding directory
+ *
+ * @param dynapi : Api use in binding
+ *
+ * @return char* string representing the path to binding directory.
+ * NULL if something wrong happened.
+ */
+extern char *GetRunningBindingDirPath(afb_api_t apiHandle);
+
 /**
  * @brief Get the environment directory colon separated path list. This take the
  * prefix add the binder's name then the suffix as environment variable name and