aboutsummaryrefslogtreecommitdiffstats
path: root/main/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'main/config.c')
-rw-r--r--main/config.c65
1 files changed, 26 insertions, 39 deletions
diff --git a/main/config.c b/main/config.c
index 153478c08..9dafa72fd 100644
--- a/main/config.c
+++ b/main/config.c
@@ -467,54 +467,41 @@ int ast_variable_delete(struct ast_category *category, char *variable, char *mat
return res;
}
-int ast_variable_update(struct ast_category *category, char *variable, char *value, char *match)
+int ast_variable_update(struct ast_category *category, const char *variable,
+ const char *value, const char *match, unsigned int object)
{
struct ast_variable *cur, *prev=NULL, *newer;
- newer = ast_variable_new(variable, value);
- if (!newer)
+
+ if (!(newer = ast_variable_new(variable, value)))
return -1;
- cur = category->root;
- while (cur) {
- if (cur->name == variable) {
- newer->next = cur->next;
- newer->object = cur->object;
- if (prev)
- prev->next = newer;
- else
- category->root = newer;
- if (category->last == cur)
- category->last = newer;
- cur->next = NULL;
- ast_variables_destroy(cur);
- return 0;
- }
- prev = cur;
- cur = cur->next;
- }
+
+ newer->object = object;
- prev = NULL;
- cur = category->root;
- while (cur) {
- if (!strcasecmp(cur->name, variable) && (ast_strlen_zero(match) || !strcasecmp(cur->value, match))) {
- newer->next = cur->next;
- newer->object = cur->object;
- if (prev)
- prev->next = newer;
- else
- category->root = newer;
- if (category->last == cur)
- category->last = newer;
- cur->next = NULL;
- ast_variables_destroy(cur);
- return 0;
- }
- prev = cur;
- cur = cur->next;
+ for (cur = category->root; cur; prev = cur, cur = cur->next) {
+ if (strcasecmp(cur->name, variable) ||
+ (!ast_strlen_zero(match) && strcasecmp(cur->value, match)))
+ continue;
+
+ newer->next = cur->next;
+ newer->object = cur->object || object;
+ if (prev)
+ prev->next = newer;
+ else
+ category->root = newer;
+ if (category->last == cur)
+ category->last = newer;
+
+ cur->next = NULL;
+ ast_variables_destroy(cur);
+
+ return 0;
}
+
if (prev)
prev->next = newer;
else
category->root = newer;
+
return 0;
}