Fix seg in variable replacement (bug #3464)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@4930 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Mark Spencer
2005-01-30 17:34:44 +00:00
parent fda3016dc8
commit 7cd91c85fa

View File

@@ -124,59 +124,13 @@ struct ast_variable *ast_variable_new(const char *name, const char *value)
return variable; return variable;
} }
static struct ast_variable *variable_get(const struct ast_category *category, const char *name)
{
struct ast_variable *variable;
for (variable = category->root; variable; variable = variable->next)
if (!strcasecmp(variable->name, name))
return variable;
return NULL;
}
static void variable_remove(struct ast_category *category, const struct ast_variable *variable)
{
struct ast_variable *prev = category->root;
if (!prev)
return;
if (prev == variable) {
category->root = prev->next;
if (category->last == variable)
category->last = NULL;
} else {
while (prev->next && (prev->next != variable)) prev = prev->next;
if (prev->next) {
prev->next = variable->next;
if (category->last == variable)
category->last = prev;
}
}
}
void ast_variable_append(struct ast_category *category, struct ast_variable *variable) void ast_variable_append(struct ast_category *category, struct ast_variable *variable)
{ {
/* Note: this function also implements "variable replacement"... if the if (category->last)
new variable's value is empty, then existing variables of the same category->last->next = variable;
name in the category are removed (and the new variable is destroyed) else
*/ category->root = variable;
if (variable->value && !ast_strlen_zero(variable->value)) { category->last = variable;
if (category->last)
category->last->next = variable;
else
category->root = variable;
category->last = variable;
} else {
struct ast_variable *v;
while ((v = variable_get(category, variable->name))) {
variable_remove(category, v);
ast_variables_destroy(v);
}
ast_variables_destroy(variable);
}
} }
void ast_variables_destroy(struct ast_variable *v) void ast_variables_destroy(struct ast_variable *v)