aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-01-25 18:47:45 +0100
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-01-25 18:47:45 +0100
commit056aa12f69614263ce10328b9ef0742d73c650b4 (patch)
treeabf89ce3c09088b4d3d980be23d669be9841387b
parent0219aa93778c8937059d4856ba8223236bbe8abd (diff)
Send back cardid only if request is valid
When trying to get information about ALSA card, fail if request JSON is malformed. However, send back information about all ALSA cards when no request JSON has been transfered. Change-Id: I2d45abb59d00cea27bfb09e74b15cc82cf84a086 Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
-rw-r--r--alsa-binding/Alsa-SetGet.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/alsa-binding/Alsa-SetGet.c b/alsa-binding/Alsa-SetGet.c
index 29c82b3..b23e8d7 100644
--- a/alsa-binding/Alsa-SetGet.c
+++ b/alsa-binding/Alsa-SetGet.c
@@ -66,10 +66,8 @@ PUBLIC void NumidsListParse(ActionSetGetT action, queryValuesT *queryValues, ctl
break;
case json_type_string:
- if(action == ACTION_GET) {
- ctlRequest[idx].tag = json_object_get_string(ctlRequest[idx].jToken);
- ctlRequest[idx].numId = 0;
- }
+ ctlRequest[idx].tag = json_object_get_string(ctlRequest[idx].jToken);
+ ctlRequest[idx].numId = 0;
break;
case json_type_array:
@@ -435,25 +433,26 @@ PUBLIC void alsaGetInfo(afb_req_t request) {
json_object *ctlDev, *ctlDevs;
char devid[32];
+ json_object *rqtJ = afb_req_json(request);
const char *rqtSndId = afb_req_value(request, "devid");
const char *rqtDevPath = afb_req_value(request, "devpath");
// if no specific card requested loop on all
- if (rqtSndId != NULL) {
+ if (rqtSndId) {
// only one card was requested let's probe it
ctlDev = alsaCardProbe(rqtSndId, INFO_BY_DEVID);
if (ctlDev != NULL) afb_req_success(request, ctlDev, NULL);
else afb_req_fail_f(request, "sndscard-notfound", "SndCard '%s' Not Found", rqtSndId);
}
- else if (rqtDevPath != NULL) {
+ else if (rqtDevPath) {
// only one card was requested let's probe it
ctlDev = alsaCardProbe(rqtDevPath, INFO_BY_PATH);
if (ctlDev != NULL) afb_req_success(request, ctlDev, NULL);
else afb_req_fail_f(request, "sndscard-notfound", "SndCard '%s' Not Found", rqtSndId);
}
- else {
+ else if (!rqtJ) {
// return an array of ctlDev
ctlDevs = json_object_new_array();
@@ -472,6 +471,9 @@ PUBLIC void alsaGetInfo(afb_req_t request) {
}
afb_req_success(request, ctlDevs, NULL);
}
+ else {
+ afb_req_fail_f(request, "sndscard-notfound", "Invalid request json '%s'", json_object_get_string(rqtJ));
+ }
}
// pack Alsa element's ACL into a JSON object