err = uc_mgr_evaluate_inplace(uc_mgr, a);
if (err < 0)
return err;
- err = uc_mgr_config_tree_merge(parent, a, before, after);
+ err = uc_mgr_config_tree_merge(uc_mgr, parent, a, before, after);
if (err < 0)
return err;
snd_config_delete(a);
return 0;
}
-int uc_mgr_config_tree_merge(snd_config_t *parent, snd_config_t *new_ctx,
+int uc_mgr_config_tree_merge(snd_use_case_mgr_t *uc_mgr,
+ snd_config_t *parent, snd_config_t *new_ctx,
snd_config_t *before, snd_config_t *after)
{
snd_config_iterator_t i, next;
const char *id;
int err;
+ err = uc_mgr_substitute_tree(uc_mgr, new_ctx);
+ if (err < 0)
+ return err;
+
snd_config_for_each(i, next, new_ctx) {
n = snd_config_iterator_entry(i);
err = snd_config_remove(n);
err = uc_mgr_evaluate_inplace(uc_mgr, a);
if (err < 0)
return err;
- err = uc_mgr_config_tree_merge(parent, a, before, after);
+ err = uc_mgr_config_tree_merge(uc_mgr, parent, a, before, after);
if (err < 0)
return err;
snd_config_delete(a);
char **_rvalue,
const char *value);
-int uc_mgr_config_tree_merge(snd_config_t *parent, snd_config_t *new_ctx,
+int uc_mgr_substitute_tree(snd_use_case_mgr_t *uc_mgr,
+ snd_config_t *node);
+
+int uc_mgr_config_tree_merge(snd_use_case_mgr_t *uc_mgr,
+ snd_config_t *parent, snd_config_t *new_ctx,
snd_config_t *before, snd_config_t *after);
int uc_mgr_evaluate_inplace(snd_use_case_mgr_t *uc_mgr,
free(r);
return err;
}
+
+static inline int uc_mgr_substitute_check(const char *s)
+{
+ return s && strstr(s, "${") != NULL;
+}
+
+int uc_mgr_substitute_tree(snd_use_case_mgr_t *uc_mgr, snd_config_t *node)
+{
+ snd_config_iterator_t i, next;
+ snd_config_t *n;
+ const char *id, *s2;
+ char *s;
+ int err;
+
+ err = snd_config_get_id(node, &id);
+ if (err < 0)
+ return err;
+ if (uc_mgr_substitute_check(id)) {
+ err = uc_mgr_get_substituted_value(uc_mgr, &s, id);
+ if (err < 0)
+ return err;
+ err = snd_config_set_id(node, s);
+ free(s);
+ if (err < 0) {
+ uc_error("unable to set substituted id '%s' (old id '%s')", s, id);
+ return err;
+ }
+ }
+ if (snd_config_get_type(node) != SND_CONFIG_TYPE_COMPOUND) {
+ if (snd_config_get_type(node) == SND_CONFIG_TYPE_STRING) {
+ err = snd_config_get_string(node, &s2);
+ if (err < 0)
+ return err;
+ if (!uc_mgr_substitute_check(s2))
+ return 0;
+ err = uc_mgr_get_substituted_value(uc_mgr, &s, s2);
+ if (err < 0)
+ return err;
+ err = snd_config_set_string(node, s);
+ free(s);
+ if (err < 0)
+ return err;
+ }
+ return 0;
+ }
+ snd_config_for_each(i, next, node) {
+ n = snd_config_iterator_entry(i);
+ err = uc_mgr_substitute_tree(uc_mgr, n);
+ if (err < 0)
+ return err;
+ }
+ return 0;
+}