mirror of
https://github.com/owntone/owntone-server.git
synced 2025-05-23 18:41:53 -04:00
[api] Fix setting output selected and volume at the same time
player_speaker_enable returned 1 on success, but code expected 0. With these changes the implementation should be more resilient. Closes #1884
This commit is contained in:
parent
180f7393a4
commit
23c67a3eb6
@ -1697,7 +1697,7 @@ static int
|
|||||||
jsonapi_reply_outputs_put_byid(struct httpd_request *hreq)
|
jsonapi_reply_outputs_put_byid(struct httpd_request *hreq)
|
||||||
{
|
{
|
||||||
uint64_t output_id;
|
uint64_t output_id;
|
||||||
json_object* request;
|
json_object *request = NULL;
|
||||||
bool selected;
|
bool selected;
|
||||||
int volume;
|
int volume;
|
||||||
const char *pin;
|
const char *pin;
|
||||||
@ -1708,55 +1708,55 @@ jsonapi_reply_outputs_put_byid(struct httpd_request *hreq)
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_WEB, "No valid output id given to outputs endpoint '%s'\n", hreq->path);
|
DPRINTF(E_LOG, L_WEB, "No valid output id given to outputs endpoint '%s'\n", hreq->path);
|
||||||
|
goto error;
|
||||||
return HTTP_BADREQUEST;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
request = jparse_obj_from_evbuffer(hreq->in_body);
|
request = jparse_obj_from_evbuffer(hreq->in_body);
|
||||||
if (!request)
|
if (!request)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_WEB, "Failed to parse incoming request\n");
|
DPRINTF(E_LOG, L_WEB, "Failed to parse incoming request\n");
|
||||||
|
goto error;
|
||||||
return HTTP_BADREQUEST;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
if (jparse_contains_key(request, "selected", json_type_boolean))
|
if (jparse_contains_key(request, "selected", json_type_boolean))
|
||||||
{
|
{
|
||||||
selected = jparse_bool_from_obj(request, "selected");
|
selected = jparse_bool_from_obj(request, "selected");
|
||||||
if (selected)
|
ret = selected ? player_speaker_enable(output_id) : player_speaker_disable(output_id);
|
||||||
ret = player_speaker_enable(output_id);
|
if (ret < 0)
|
||||||
else
|
goto error;
|
||||||
ret = player_speaker_disable(output_id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret == 0 && jparse_contains_key(request, "volume", json_type_int))
|
if (jparse_contains_key(request, "volume", json_type_int))
|
||||||
{
|
{
|
||||||
volume = jparse_int_from_obj(request, "volume");
|
volume = jparse_int_from_obj(request, "volume");
|
||||||
ret = player_volume_setabs_speaker(output_id, volume);
|
ret = player_volume_setabs_speaker(output_id, volume);
|
||||||
|
if (ret < 0)
|
||||||
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret == 0 && jparse_contains_key(request, "pin", json_type_string))
|
if (jparse_contains_key(request, "pin", json_type_string))
|
||||||
{
|
{
|
||||||
pin = jparse_str_from_obj(request, "pin");
|
pin = jparse_str_from_obj(request, "pin");
|
||||||
if (pin)
|
ret = pin ? player_speaker_authorize(output_id, pin) : 0;
|
||||||
ret = player_speaker_authorize(output_id, pin);
|
if (ret < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret == 0 && jparse_contains_key(request, "format", json_type_string))
|
if (jparse_contains_key(request, "format", json_type_string))
|
||||||
{
|
{
|
||||||
format = jparse_str_from_obj(request, "format");
|
format = jparse_str_from_obj(request, "format");
|
||||||
if (format)
|
ret = format ? player_speaker_format_set(output_id, media_format_from_string(format)) : 0;
|
||||||
ret = player_speaker_format_set(output_id, media_format_from_string(format));
|
if (ret < 0)
|
||||||
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
jparse_free(request);
|
jparse_free(request);
|
||||||
|
|
||||||
if (ret < 0)
|
|
||||||
return HTTP_BADREQUEST;
|
|
||||||
|
|
||||||
return HTTP_NOCONTENT;
|
return HTTP_NOCONTENT;
|
||||||
|
|
||||||
|
error:
|
||||||
|
jparse_free(request);
|
||||||
|
return HTTP_BADREQUEST;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user