const char *ast_variable_retrieve(struct ast_config *config, const char *category, const char *variable)
{
struct ast_variable *v;
+ const char *match = NULL;
+
+ /* We can't return as soon as we find a match, because if a config section overrides
+ * something specified in a template, then the actual effective value is the last
+ * one encountered, not the first one.
+ * (This is like using the -1 index for the AST_CONFIG function.)
+ * Also see ast_variable_find_last_in_list
+ */
if (category) {
for (v = ast_variable_browse(config, category); v; v = v->next) {
if (!strcasecmp(variable, v->name)) {
- return v->value;
+ match = v->value;
}
}
} else {
for (cat = config->root; cat; cat = cat->next) {
for (v = cat->root; v; v = v->next) {
if (!strcasecmp(variable, v->name)) {
- return v->value;
+ match = v->value;
}
}
}
}
- return NULL;
+ return match;
}
const char *ast_variable_retrieve_filtered(struct ast_config *config,