mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-05 13:29:57 -05:00
message-params: Allow parameter strings to contain escaped curly braces
The patch adds the possibility to escape curly braces within parameter strings and introduces several new functions that can be used for writing parameters. For writing, the structure pa_message_params, which is a wrapper for pa_strbuf has been created. Following new write functions are available: pa_message_params_new() - creates a new pa_message_params structure pa_message_params_free() - frees a pa_message_params structure pa_message_param_to_string_free() - converts a pa_message_param to string and frees the structure pa_message_params_begin_list() - starts a list pa_message_params_end_list() - ends a list pa_message_params_write_string() - writes a string to a pa_message_params structure pa_message_params_write_raw() - writes a raw string to a pa_message_params structure For string parameters that contain curly braces or backslashes, those characters will be escaped when using pa_message_params_write_string(), while write_raw() will put the string into the buffer without any changes. For reading, pa_message_params_read_string() reverts the changes that pa_message_params_write_string() might have introduced. The patch also adds more restrictions on the object path name. Now only alphanumeric characters and one of "_", ".", "-" and "/" are allowed. The path name may not end with a / or contain a double slash. If the user specifies a trailing / when sending a message, it will be silently removed. Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/51>
This commit is contained in:
parent
4a28b164d1
commit
590fd1ca69
8 changed files with 249 additions and 47 deletions
|
|
@ -29,6 +29,7 @@
|
|||
#include <pulse/rtclock.h>
|
||||
#include <pulse/timeval.h>
|
||||
#include <pulse/xmalloc.h>
|
||||
#include <pulse/message-params.h>
|
||||
|
||||
#include <pulsecore/module.h>
|
||||
#include <pulsecore/core-rtclock.h>
|
||||
|
|
@ -65,25 +66,26 @@ static void core_free(pa_object *o);
|
|||
|
||||
/* Returns a list of handlers. */
|
||||
static char *message_handler_list(pa_core *c) {
|
||||
pa_strbuf *buf;
|
||||
pa_message_params *param;
|
||||
void *state = NULL;
|
||||
struct pa_message_handler *handler;
|
||||
|
||||
buf = pa_strbuf_new();
|
||||
param = pa_message_params_new();
|
||||
|
||||
pa_strbuf_putc(buf, '{');
|
||||
pa_message_params_begin_list(param);
|
||||
PA_HASHMAP_FOREACH(handler, c->message_handlers, state) {
|
||||
pa_strbuf_putc(buf, '{');
|
||||
pa_message_params_begin_list(param);
|
||||
|
||||
pa_strbuf_printf(buf, "{%s} {", handler->object_path);
|
||||
if (handler->description)
|
||||
pa_strbuf_puts(buf, handler->description);
|
||||
/* object_path cannot contain characters that need escaping, therefore
|
||||
* pa_message_params_write_raw() can safely be used here. */
|
||||
pa_message_params_write_raw(param, handler->object_path, true);
|
||||
pa_message_params_write_string(param, handler->description);
|
||||
|
||||
pa_strbuf_puts(buf, "}}");
|
||||
pa_message_params_end_list(param);
|
||||
}
|
||||
pa_strbuf_putc(buf, '}');
|
||||
pa_message_params_end_list(param);
|
||||
|
||||
return pa_strbuf_to_string_free(buf);
|
||||
return pa_message_params_to_string_free(param);
|
||||
}
|
||||
|
||||
static int core_message_handler(const char *object_path, const char *message, char *message_parameters, char **response, void *userdata) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue