ucm: substitute arguments in sequences only for syntax 3+

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
Jaroslav Kysela 2020-05-27 15:20:03 +02:00
parent 82d86df37f
commit 3feea064dd

View file

@ -149,19 +149,9 @@ int parse_string_substitute(snd_use_case_mgr_t *uc_mgr,
int parse_string_substitute3(snd_use_case_mgr_t *uc_mgr, int parse_string_substitute3(snd_use_case_mgr_t *uc_mgr,
snd_config_t *n, char **res) snd_config_t *n, char **res)
{ {
const char *str;
char *s;
int err;
if (uc_mgr->conf_format < 3) if (uc_mgr->conf_format < 3)
return parse_string(n, res); return parse_string(n, res);
err = snd_config_get_string(n, &str); return parse_string_substitute(uc_mgr, n, res);
if (err < 0)
return err;
err = uc_mgr_get_substituted_value(uc_mgr, &s, str);
if (err >= 0)
*res = s;
return err;
} }
/* /*
@ -184,6 +174,30 @@ int parse_integer_substitute(snd_use_case_mgr_t *uc_mgr,
return err; return err;
} }
/*
* Parse integer with substitution
*/
int parse_integer_substitute3(snd_use_case_mgr_t *uc_mgr,
snd_config_t *n, long *res)
{
char *s1, *s2;
int err;
err = snd_config_get_ascii(n, &s1);
if (err < 0)
return err;
if (uc_mgr->conf_format < 3)
s2 = s1;
else
err = uc_mgr_get_substituted_value(uc_mgr, &s2, s1);
if (err >= 0)
err = safe_strtol(s2, res);
if (s1 != s2)
free(s2);
free(s1);
return err;
}
/* /*
* Parse safe ID * Parse safe ID
*/ */
@ -672,7 +686,7 @@ static int parse_sequence(snd_use_case_mgr_t *uc_mgr,
if (strcmp(cmd, "cdev") == 0) { if (strcmp(cmd, "cdev") == 0) {
curr->type = SEQUENCE_ELEMENT_TYPE_CDEV; curr->type = SEQUENCE_ELEMENT_TYPE_CDEV;
err = parse_string_substitute(uc_mgr, n, &curr->data.cdev); err = parse_string_substitute3(uc_mgr, n, &curr->data.cdev);
if (err < 0) { if (err < 0) {
uc_error("error: cdev requires a string!"); uc_error("error: cdev requires a string!");
return err; return err;
@ -682,7 +696,7 @@ static int parse_sequence(snd_use_case_mgr_t *uc_mgr,
if (strcmp(cmd, "cset") == 0) { if (strcmp(cmd, "cset") == 0) {
curr->type = SEQUENCE_ELEMENT_TYPE_CSET; curr->type = SEQUENCE_ELEMENT_TYPE_CSET;
err = parse_string_substitute(uc_mgr, n, &curr->data.cset); err = parse_string_substitute3(uc_mgr, n, &curr->data.cset);
if (err < 0) { if (err < 0) {
uc_error("error: cset requires a string!"); uc_error("error: cset requires a string!");
return err; return err;
@ -716,7 +730,7 @@ static int parse_sequence(snd_use_case_mgr_t *uc_mgr,
if (strcmp(cmd, "cset-bin-file") == 0) { if (strcmp(cmd, "cset-bin-file") == 0) {
curr->type = SEQUENCE_ELEMENT_TYPE_CSET_BIN_FILE; curr->type = SEQUENCE_ELEMENT_TYPE_CSET_BIN_FILE;
err = parse_string_substitute(uc_mgr, n, &curr->data.cset); err = parse_string_substitute3(uc_mgr, n, &curr->data.cset);
if (err < 0) { if (err < 0) {
uc_error("error: cset-bin-file requires a string!"); uc_error("error: cset-bin-file requires a string!");
return err; return err;
@ -726,7 +740,7 @@ static int parse_sequence(snd_use_case_mgr_t *uc_mgr,
if (strcmp(cmd, "cset-tlv") == 0) { if (strcmp(cmd, "cset-tlv") == 0) {
curr->type = SEQUENCE_ELEMENT_TYPE_CSET_TLV; curr->type = SEQUENCE_ELEMENT_TYPE_CSET_TLV;
err = parse_string_substitute(uc_mgr, n, &curr->data.cset); err = parse_string_substitute3(uc_mgr, n, &curr->data.cset);
if (err < 0) { if (err < 0) {
uc_error("error: cset-tlv requires a string!"); uc_error("error: cset-tlv requires a string!");
return err; return err;
@ -736,7 +750,7 @@ static int parse_sequence(snd_use_case_mgr_t *uc_mgr,
if (strcmp(cmd, "usleep") == 0) { if (strcmp(cmd, "usleep") == 0) {
curr->type = SEQUENCE_ELEMENT_TYPE_SLEEP; curr->type = SEQUENCE_ELEMENT_TYPE_SLEEP;
err = parse_integer_substitute(uc_mgr, n, &curr->data.sleep); err = parse_integer_substitute3(uc_mgr, n, &curr->data.sleep);
if (err < 0) { if (err < 0) {
uc_error("error: usleep requires integer!"); uc_error("error: usleep requires integer!");
return err; return err;
@ -746,7 +760,7 @@ static int parse_sequence(snd_use_case_mgr_t *uc_mgr,
if (strcmp(cmd, "msleep") == 0) { if (strcmp(cmd, "msleep") == 0) {
curr->type = SEQUENCE_ELEMENT_TYPE_SLEEP; curr->type = SEQUENCE_ELEMENT_TYPE_SLEEP;
err = parse_integer_substitute(uc_mgr, n, &curr->data.sleep); err = parse_integer_substitute3(uc_mgr, n, &curr->data.sleep);
if (err < 0) { if (err < 0) {
uc_error("error: msleep requires integer!"); uc_error("error: msleep requires integer!");
return err; return err;
@ -757,7 +771,7 @@ static int parse_sequence(snd_use_case_mgr_t *uc_mgr,
if (strcmp(cmd, "exec") == 0) { if (strcmp(cmd, "exec") == 0) {
curr->type = SEQUENCE_ELEMENT_TYPE_EXEC; curr->type = SEQUENCE_ELEMENT_TYPE_EXEC;
err = parse_string_substitute(uc_mgr, n, &curr->data.exec); err = parse_string_substitute3(uc_mgr, n, &curr->data.exec);
if (err < 0) { if (err < 0) {
uc_error("error: exec requires a string!"); uc_error("error: exec requires a string!");
return err; return err;