Signed-off-by: Peter Meerwald <pmeerw at pmeerw.net> --- src/pulsecore/cli-command.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/pulsecore/cli-command.c b/src/pulsecore/cli-command.c index 9a73605..6a38dd9 100644 --- a/src/pulsecore/cli-command.c +++ b/src/pulsecore/cli-command.c @@ -1992,6 +1992,17 @@ static int pa_cli_command_dump_volumes(pa_core *c, pa_tokenizer *t, pa_strbuf *b return 0; } +static bool pa_cli_check_ifstate(pa_strbuf *buf, int *ifstate, const char *cs) { + if (!ifstate) { + pa_strbuf_printf(buf, "Meta command %s is not valid in this context\n", cs); + return false; + } else if (*ifstate != IFSTATE_NONE) { + pa_strbuf_printf(buf, "Nested %s commands not supported\n", cs); + return false; + } else + return true; +} + int pa_cli_command_execute_line_stateful(pa_core *c, const char *s, pa_strbuf *buf, bool *fail, int *ifstate) { const char *cs; @@ -2101,13 +2112,9 @@ int pa_cli_command_execute_line_stateful(pa_core *c, const char *s, pa_strbuf *b } } } else if (l == sizeof(META_IFEXISTS)-1 && !strncmp(cs, META_IFEXISTS, l)) { - if (!ifstate) { - pa_strbuf_printf(buf, "Meta command %s is not valid in this context\n", cs); + if (!pa_cli_check_ifstate(buf, ifstate, cs)) return -1; - } else if (*ifstate != IFSTATE_NONE) { - pa_strbuf_printf(buf, "Nested %s commands not supported\n", cs); - return -1; - } else { + else { const char *filename = cs+l+strspn(cs+l, whitespace); *ifstate = pa_module_exists(filename) ? IFSTATE_TRUE : IFSTATE_FALSE; } -- 1.9.1