mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-29 05:40:23 -04:00
message-params: If message paremeters is not JSON, wrap into JSON string
Requiring user to invoke send-message with correctly quoted parameters string
is not good for usability. Wrap parameters string into JSON string and try
again. If that works, log a warning use wrapped JSON string with parameters.
As an example these two commands will now invoke the same action:
pactl send-message /card/bluez_card... switch-codec '"CODECNAME"'
pactl send-message /card/bluez_card... switch-codec CODECNAME
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/648>
This commit is contained in:
parent
5a03d84c32
commit
8262815e94
1 changed files with 20 additions and 2 deletions
|
|
@ -131,8 +131,26 @@ int pa_message_handler_send_message(pa_core *c, const char *object_path, const c
|
|||
if (message_parameters) {
|
||||
parameters = pa_json_parse(message_parameters);
|
||||
|
||||
if (!parameters)
|
||||
return -PA_ERR_INVALID;
|
||||
if (!parameters) {
|
||||
char *wrapped_message_parameters;
|
||||
|
||||
/* Message parameters is not a valid JSON
|
||||
*
|
||||
* Wrap message parameters into JSON string and try again.
|
||||
* User might have missed double-quotes and passed ARGSTRING instead of proper JSON "ARGSTRING"
|
||||
*/
|
||||
pa_log_warn(_("Message parameters is not a valid JSON, wrapping into JSON string '\"%s\"'"), message_parameters);
|
||||
|
||||
wrapped_message_parameters = pa_sprintf_malloc("\"%s\"", message_parameters);
|
||||
parameters = pa_json_parse(wrapped_message_parameters);
|
||||
pa_xfree(wrapped_message_parameters);
|
||||
|
||||
if (!parameters) {
|
||||
pa_log_error(_("Message parameters is not a valid JSON object. Tried both '%s' and '\"%s\"'"),
|
||||
message_parameters, message_parameters);
|
||||
return -PA_ERR_INVALID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* The handler is expected to return an error code and may also
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue