aboutsummaryrefslogtreecommitdiffstats
path: root/ucs2-afb
diff options
context:
space:
mode:
Diffstat (limited to 'ucs2-afb')
-rw-r--r--ucs2-afb/ucs_apidef.h44
-rw-r--r--ucs2-afb/ucs_apidef.json21
-rw-r--r--ucs2-afb/ucs_binding.c58
3 files changed, 103 insertions, 20 deletions
diff --git a/ucs2-afb/ucs_apidef.h b/ucs2-afb/ucs_apidef.h
index c8ce266..c23f066 100644
--- a/ucs2-afb/ucs_apidef.h
+++ b/ucs2-afb/ucs_apidef.h
@@ -24,19 +24,23 @@ static const char _afb_description_v2_UNICENS[] =
"or\":{\"permission\":\"urn:AGL:permission:UNICENS:public:monitor\"}},\"r"
"esponses\":{\"200\":{\"description\":\"A complex object array response\""
",\"content\":{\"application/json\":{\"schema\":{\"$ref\":\"#/components/"
- "schemas/afb-reply\"}}}}}},\"paths\":{\"/configure\":{\"description\":\"c"
- "onfigure Unicens2 lib from NetworkConfig.XML.\",\"get\":{\"x-permissions"
- "\":{\"$ref\":\"#/components/x-permissions/config\"},\"parameters\":[{\"i"
- "n\":\"query\",\"name\":\"filename\",\"required\":true,\"schema\":{\"type"
- "\":\"string\"}}],\"responses\":{\"200\":{\"$ref\":\"#/components/respons"
- "es/200\"}}}},\"/volume\":{\"description\":\"Set Master Volume.\",\"get\""
- ":{\"x-permissions\":{\"$ref\":\"#/components/x-permissions/monitor\"},\""
- "parameters\":[{\"in\":\"query\",\"name\":\"value\",\"required\":true,\"s"
- "chema\":{\"type\":\"integer\"}}],\"responses\":{\"200\":{\"$ref\":\"#/co"
- "mponents/responses/200\"}}}},\"/monitor\":{\"description\":\"Subscribe t"
- "o Unicens Event.\",\"get\":{\"x-permissions\":{\"$ref\":\"#/components/x"
- "-permissions/monitor\"},\"responses\":{\"200\":{\"$ref\":\"#/components/"
- "responses/200\"}}}}}}"
+ "schemas/afb-reply\"}}}}}},\"paths\":{\"/listconfig\":{\"description\":\""
+ "List Config Files\",\"get\":{\"x-permissions\":{\"$ref\":\"#/components/"
+ "x-permissions/config\"},\"parameters\":[{\"in\":\"query\",\"name\":\"cfg"
+ "path\",\"required\":false,\"schema\":{\"type\":\"string\"}}],\"responses"
+ "\":{\"200\":{\"$ref\":\"#/components/responses/200\"}}}},\"/initialise\""
+ ":{\"description\":\"configure Unicens2 lib from NetworkConfig.XML.\",\"g"
+ "et\":{\"x-permissions\":{\"$ref\":\"#/components/x-permissions/config\"}"
+ ",\"parameters\":[{\"in\":\"query\",\"name\":\"filename\",\"required\":tr"
+ "ue,\"schema\":{\"type\":\"string\"}}],\"responses\":{\"200\":{\"$ref\":\""
+ "#/components/responses/200\"}}}},\"/volume\":{\"description\":\"Set Mast"
+ "er Volume.\",\"get\":{\"x-permissions\":{\"$ref\":\"#/components/x-permi"
+ "ssions/monitor\"},\"parameters\":[{\"in\":\"query\",\"name\":\"value\",\""
+ "required\":true,\"schema\":{\"type\":\"integer\"}}],\"responses\":{\"200"
+ "\":{\"$ref\":\"#/components/responses/200\"}}}},\"/monitor\":{\"descript"
+ "ion\":\"Subscribe to Unicens Event.\",\"get\":{\"x-permissions\":{\"$ref"
+ "\":\"#/components/x-permissions/monitor\"},\"responses\":{\"200\":{\"$re"
+ "f\":\"#/components/responses/200\"}}}}}}"
;
static const struct afb_auth _afb_auths_v2_UNICENS[] = {
@@ -44,14 +48,22 @@ static const struct afb_auth _afb_auths_v2_UNICENS[] = {
{ .type = afb_auth_Permission, .text = "urn:AGL:permission:UNICENS:public:monitor" }
};
- void ucs2_configure(struct afb_req req);
+ void ucs2_listconfig(struct afb_req req);
+ void ucs2_initialise(struct afb_req req);
void ucs2_volume(struct afb_req req);
void ucs2_monitor(struct afb_req req);
static const struct afb_verb_v2 _afb_verbs_v2_UNICENS[] = {
{
- .verb = "configure",
- .callback = ucs2_configure,
+ .verb = "listconfig",
+ .callback = ucs2_listconfig,
+ .auth = &_afb_auths_v2_UNICENS[0],
+ .info = NULL,
+ .session = AFB_SESSION_NONE_V2
+ },
+ {
+ .verb = "initialise",
+ .callback = ucs2_initialise,
.auth = &_afb_auths_v2_UNICENS[0],
.info = NULL,
.session = AFB_SESSION_NONE_V2
diff --git a/ucs2-afb/ucs_apidef.json b/ucs2-afb/ucs_apidef.json
index 274ce73..c200f74 100644
--- a/ucs2-afb/ucs_apidef.json
+++ b/ucs2-afb/ucs_apidef.json
@@ -102,7 +102,26 @@
}
},
"paths": {
- "/configure": {
+ "/listconfig": {
+ "description": "List Config Files",
+ "get": {
+ "x-permissions": {
+ "$ref": "#/components/x-permissions/config"
+ },
+ "parameters": [
+ {
+ "in": "query",
+ "name": "cfgpath",
+ "required": false,
+ "schema": { "type": "string" }
+ }
+ ],
+ "responses": {
+ "200": {"$ref": "#/components/responses/200"}
+ }
+ }
+ },
+ "/initialise": {
"description": "configure Unicens2 lib from NetworkConfig.XML.",
"get": {
"x-permissions": {
diff --git a/ucs2-afb/ucs_binding.c b/ucs2-afb/ucs_binding.c
index efb4928..1c318fa 100644
--- a/ucs2-afb/ucs_binding.c
+++ b/ucs2-afb/ucs_binding.c
@@ -34,6 +34,7 @@
#include <time.h>
#include <assert.h>
#include <errno.h>
+#include <dirent.h>
#include "ucs_binding.h"
#include "ucs_interface.h"
@@ -379,7 +380,6 @@ STATIC int volSndCmd (struct afb_req request, struct json_object *commandJ, ucsC
return 1;
}
-
PUBLIC void ucs2_volume (struct afb_req request) {
struct json_object *queryJ;
int err;
@@ -423,7 +423,7 @@ PUBLIC void ucs2_volume (struct afb_req request) {
}
-PUBLIC void ucs2_configure (struct afb_req request) {
+PUBLIC void ucs2_initialise (struct afb_req request) {
static UcsXmlVal_t *ucsConfig;
static ucsContextT ucsContext;
@@ -473,7 +473,59 @@ PUBLIC void ucs2_configure (struct afb_req request) {
return;
}
+
+// List Avaliable Configuration Files
+PUBLIC void ucs2_listconfig (struct afb_req request) {
+ struct json_object *queryJ, *tmpJ, *responseJ;
+ DIR *dirHandle;
+ char *dirPath, *dirList;
+ int error=0;
+
+ queryJ = afb_req_json(request);
+ if (queryJ && json_object_object_get_ex (queryJ, "cfgpath" , &tmpJ)) {
+ strdup (json_object_get_string(tmpJ));
+ } else {
+ dirList = strdup (UCS2_CFG_PATH);
+ AFB_NOTICE ("fgpath:missing uses UCS2_CFG_PATH=%s", UCS2_CFG_PATH);
+ }
+
+ responseJ = json_object_new_array();
+ for (dirPath= strtok(dirList, ":"); dirPath && *dirPath; dirPath=strtok(NULL,":")) {
+ struct dirent *dirEnt;
+
+ dirHandle = opendir (dirPath);
+ if (!dirHandle) {
+ AFB_NOTICE ("ucs2_listconfig dir=%s not readable", dirPath);
+ error++;
+ continue;
+ }
+
+ AFB_NOTICE ("ucs2_listconfig scanning: %s", dirPath);
+ while ((dirEnt = readdir(dirHandle)) != NULL) {
+ // Unknown type is accepted to support dump filesystems
+ if (dirEnt->d_type == DT_REG || dirEnt->d_type == DT_UNKNOWN) {
+ struct json_object *pathJ = json_object_new_object();
+ json_object_object_add(pathJ, "dirpath", json_object_new_string(dirPath));
+ json_object_object_add(pathJ, "basename", json_object_new_string(dirEnt->d_name));
+ json_object_array_add(responseJ, pathJ);
+ }
+ }
+ }
+
+ free (dirList);
+
+ if (!error) afb_req_success(request,responseJ,NULL);
+ else {
+ char info[40];
+ snprintf (info, sizeof(info), "[%d] where not scanned", error);
+ afb_req_success(request,responseJ, info);
+ }
+
+ return;
+}
+
PUBLIC void ucs2_monitor (struct afb_req request) {
afb_req_success(request,NULL,"UNICENS-to_be_done");
-} \ No newline at end of file
+}
+