[PATCH v2 5/6] pactl: Implement list message-handlers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 21.01.2018 14:55, Georg Chini wrote:
> For better readability, "pactl list message-handlers" is introduced which
> prints a formatted output of "pactl send-message /core list-handlers".
>
> The patch also adds the function pa_split_message_parameter_string() for
> easy parsing of the message response string.
> ---
>   man/pactl.1.xml.in               |  2 +-
>   shell-completion/bash/pulseaudio |  2 +-
>   shell-completion/zsh/_pulseaudio |  1 +
>   src/pulse/util.c                 | 65 ++++++++++++++++++++++++++++++++++++++++
>   src/pulse/util.h                 |  4 +++
>   src/utils/pactl.c                | 60 +++++++++++++++++++++++++++++++++++--
>   6 files changed, 130 insertions(+), 4 deletions(-)
>
>
> diff --git a/src/pulse/util.c b/src/pulse/util.c
> index 54fe7a28..0324c4a6 100644
> --- a/src/pulse/util.c
> +++ b/src/pulse/util.c
> @@ -342,3 +342,68 @@ int pa_msleep(unsigned long t) {
>   #error "Platform lacks a sleep function."
>   #endif
>   }
> +
> +/* Split the specified string into elements. An element is defined as
> + * a sub-string between curly braces. The function is needed to parse
> + * the parameters of messages. Each time it is called returns the position
> + * of the next element in start_pos and the length of the element in
> + * length. If max_length is not 0, it is verified that the retrieved
> + * element is within the bounds of the parent element. If the parameter
> + * element is not NULL, a newly allocated string containing the retrieved
> + * element is returned. The caller is responsible to free the string.
> + * The variable state points to, should be initialized to NULL before
> + * the first call. */
> +int pa_split_message_parameter_string(const char *c, uint32_t max_length, const char **start_pos, uint32_t *length, char **element, const char **state) {
> +    const char *current = *state ? *state : c;
> +    uint32_t open_braces;
> +
> +    pa_assert(start_pos);
> +
> +    *start_pos = NULL;
> +
> +    /* End of string */
> +    if (!*current || *c == 0)
> +        return 0;
> +
> +    /* Find opening brace */
> +    current = strchr(current, '{');
> +
Simply using strchr() to find the next opening brace is incorrect.
This way, input like {x1} } {x2} will not produce a parse error,
because the excess closing brace is ignored by strchr(). I'll send
an updated version of patch 5 and 6.


[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux