From: Jaroslav Kysela Date: Mon, 11 Nov 2019 13:22:36 +0000 (+0100) Subject: ucm: add snd_use_case_parse_selem_id() X-Git-Tag: v1.2.1~10 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=5c88b183718ce3df11bc4753c76d95f3e9de6c7e;p=alsa-lib.git ucm: add snd_use_case_parse_selem_id() and add strict ucm_id checks to snd_use_case_parse_ctl_elem_id() Signed-off-by: Jaroslav Kysela --- diff --git a/include/use-case.h b/include/use-case.h index 109502aa..eb4643c8 100644 --- a/include/use-case.h +++ b/include/use-case.h @@ -447,8 +447,19 @@ static __inline__ int snd_use_case_verb_list(snd_use_case_mgr_t *uc_mgr, * \return Zero if success, otherwise a negative error code */ int snd_use_case_parse_ctl_elem_id(snd_ctl_elem_id_t *dst, - const char *ucm_id, char *value); + const char *ucm_id, + const char *value); +/** + * \brief Parse mixer element identifier + * \param dst Simple mixer element identifier + * \param ucm_id Use case identifier + * \param value String value to be parsed + * \return Zero if success, otherwise a negative error code + */ +int snd_use_case_parse_selem_id(snd_mixer_selem_id_t *dst, + const char *ucm_id, + const char *value); /** * \} diff --git a/src/ucm/main.c b/src/ucm/main.c index 773c7258..8ab39006 100644 --- a/src/ucm/main.c +++ b/src/ucm/main.c @@ -1929,17 +1929,43 @@ int snd_use_case_set(snd_use_case_mgr_t *uc_mgr, * \return Zero if success, otherwise a negative error code */ int snd_use_case_parse_ctl_elem_id(snd_ctl_elem_id_t *dst, - const char *ucm_id, char *value) + const char *ucm_id, + const char *value) { snd_ctl_elem_iface_t iface; - + int jack_control; + + jack_control = strcmp(ucm_id, "JackControl") == 0; + if (!jack_control && + strcmp(ucm_id, "PlaybackVolume") && + strcmp(ucm_id, "PlaybackSwitch") && + strcmp(ucm_id, "CaptureVolume") && + strcmp(ucm_id, "CaptureSwitch")) + return -EINVAL; snd_ctl_elem_id_clear(dst); if (strcasestr(ucm_id, "name=")) return __snd_ctl_ascii_elem_id_parse(dst, value, NULL); iface = SND_CTL_ELEM_IFACE_MIXER; - if (strcasecmp(ucm_id, "JackControl") == 0) + if (jack_control) iface = SND_CTL_ELEM_IFACE_CARD; snd_ctl_elem_id_set_interface(dst, iface); snd_ctl_elem_id_set_name(dst, value); return 0; } + +/** + * \brief Parse mixer element identifier + * \param dst Simple mixer element identifier + * \param ucm_id Use case identifier + * \param value String value to be parsed + * \return Zero if success, otherwise a negative error code + */ +int snd_use_case_parse_selem_id(snd_mixer_selem_id_t *dst, + const char *ucm_id, + const char *value) +{ + if (strcmp(ucm_id, "PlaybackMixerId") == 0 || + strcmp(ucm_id, "CaptureMixerId") == 0) + return snd_mixer_selem_id_parse(dst, value); + return -EINVAL; +}