summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2024-03-29 10:55:31 +0100
committerLars-Dominik Braun <lars@6xq.net>2024-03-29 10:55:31 +0100
commitee735ee68792ab93af5c66368e046a77eec3fc6e (patch)
treedc81c852f16e4720bea078350658d2eadbfab320
parentc76bcb27d7864f33e0d64ca4afbb2453cabfdb79 (diff)
downloadpianobar-ee735ee68792ab93af5c66368e046a77eec3fc6e.tar.gz
pianobar-ee735ee68792ab93af5c66368e046a77eec3fc6e.tar.bz2
pianobar-ee735ee68792ab93af5c66368e046a77eec3fc6e.zip
piano: Do not return empty explanation.
Instead return NULL and let the client handle it.
-rw-r--r--src/libpiano/response.c3
-rw-r--r--src/ui_act.c8
2 files changed, 8 insertions, 3 deletions
diff --git a/src/libpiano/response.c b/src/libpiano/response.c
index 42e2ffe..0be8872 100644
--- a/src/libpiano/response.c
+++ b/src/libpiano/response.c
@@ -520,7 +520,8 @@ PianoReturn_t PianoResponse (PianoHandle_t *ph, PianoRequest_t *req) {
assert (reqData != NULL);
json_object *explanations;
- if (json_object_object_get_ex (result, "explanations", &explanations)) {
+ if (json_object_object_get_ex (result, "explanations", &explanations) &&
+ json_object_array_length (explanations) > 0) {
reqData->retExplain = malloc (strSize *
sizeof (*reqData->retExplain));
strncpy (reqData->retExplain, "We're playing this track "
diff --git a/src/ui_act.c b/src/ui_act.c
index 30bd4e5..fa5c43b 100644
--- a/src/ui_act.c
+++ b/src/ui_act.c
@@ -271,8 +271,12 @@ BarUiActCallback(BarUiActExplain) {
BarUiMsg (&app->settings, MSG_INFO, "Receiving explanation... ");
if (BarUiActDefaultPianoCall (PIANO_REQUEST_EXPLAIN, &reqData)) {
- BarUiMsg (&app->settings, MSG_INFO, "%s\n", reqData.retExplain);
- free (reqData.retExplain);
+ if (reqData.retExplain == NULL) {
+ BarUiMsg (&app->settings, MSG_ERR, "No explanation provided.\n");
+ } else {
+ BarUiMsg (&app->settings, MSG_INFO, "%s\n", reqData.retExplain);
+ free (reqData.retExplain);
+ }
}
BarUiActDefaultEventcmd ("songexplain");
}