summaryrefslogtreecommitdiff
path: root/main/config.c
diff options
context:
space:
mode:
authorGeorge Joseph <george.joseph@fairview5.com>2015-01-07 16:56:59 +0000
committerGeorge Joseph <george.joseph@fairview5.com>2015-01-07 16:56:59 +0000
commit56de48107fd68d234821d996c1893eba21ac2996 (patch)
treeeece33c8ef5f3ace756c07aad6298c9e02e78f99 /main/config.c
parent0c5234f12a09043843db1d725c24ba3b81b84191 (diff)
config: Add option to NOT preserve effective context when changing a template
Let's say you have a template T with variable VAR1 = ON and you have a context C(T) that doesn't specify VAR1. If you read C, the effective value of VAR1 is ON. Now you change T VAR1 to OFF and call ast_config_text_file_save. The current behavior is that the file gets re-written with T/VAR1=OFF but C/VAR1=ON is added. Personally, I think this is a bug. It's preserving the effective state of C even though I didn't specify C/VAR1 in th first place. I believe the behavior should be that if I didn't specify C/VAR1 originally, then the effective value of C/VAR1 should continue to follow the inherited state. Now, if I DID explicitly specify C/VAR1, the it should be preserved even if the template changes. Even though I think the existing behavior is a bug, it's been that way forever so I'm not changing it. Instead, I've created ast_config_text_file_save2() that takes a bitmask of flags, one of which is to preserve the effective context (the current behavior). The original ast_config_text_file_save calls *2 with the preserve flag. If you want the new behavior, call *2 directly without a flag. I've also updated Manager UpdateConfig with a new parameter 'PreserveEffectiveContext' whose default is 'yes'. If you want the new behavior with UpdateConfig, set 'PreserveEffectiveContext: no'. Tested-by: George Joseph Review: https://reviewboard.asterisk.org/r/4297/ ........ Merged revisions 430295 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@430296 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/config.c')
-rw-r--r--main/config.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/main/config.c b/main/config.c
index fe3ad3f9a..f454544f2 100644
--- a/main/config.c
+++ b/main/config.c
@@ -1250,8 +1250,11 @@ void ast_category_inherit(struct ast_category *new, const struct ast_category *b
strcpy(x->name, base->name);
x->inst = base;
AST_LIST_INSERT_TAIL(&new->template_instances, x, next);
- for (var = base->root; var; var = var->next)
- ast_variable_append(new, variable_clone(var));
+ for (var = base->root; var; var = var->next) {
+ struct ast_variable *cloned = variable_clone(var);
+ cloned->inherited = 1;
+ ast_variable_append(new, cloned);
+ }
}
struct ast_config *ast_config_new(void)
@@ -2358,11 +2361,16 @@ static void insert_leading_blank_lines(FILE *fp, struct inclfile *fi, struct ast
int config_text_file_save(const char *configfile, const struct ast_config *cfg, const char *generator)
{
- return ast_config_text_file_save(configfile, cfg, generator);
+ return ast_config_text_file_save2(configfile, cfg, generator, CONFIG_SAVE_FLAG_PRESERVE_EFFECTIVE_CONTEXT);
}
int ast_config_text_file_save(const char *configfile, const struct ast_config *cfg, const char *generator)
{
+ return ast_config_text_file_save2(configfile, cfg, generator, CONFIG_SAVE_FLAG_PRESERVE_EFFECTIVE_CONTEXT);
+}
+
+int ast_config_text_file_save2(const char *configfile, const struct ast_config *cfg, const char *generator, uint32_t flags)
+{
FILE *f;
char fn[PATH_MAX];
struct ast_variable *var;
@@ -2522,13 +2530,27 @@ int ast_config_text_file_save(const char *configfile, const struct ast_config *c
AST_LIST_TRAVERSE(&cat->template_instances, x, next) {
struct ast_variable *v;
for (v = x->inst->root; v; v = v->next) {
- if (!strcasecmp(var->name, v->name) && !strcmp(var->value, v->value)) {
- found = 1;
- break;
+
+ if (flags & CONFIG_SAVE_FLAG_PRESERVE_EFFECTIVE_CONTEXT) {
+ if (!strcasecmp(var->name, v->name) && !strcmp(var->value, v->value)) {
+ found = 1;
+ break;
+ }
+ } else {
+ if (var->inherited) {
+ found = 1;
+ break;
+ } else {
+ if (!strcasecmp(var->name, v->name) && !strcmp(var->value, v->value)) {
+ found = 1;
+ break;
+ }
+ }
}
}
- if (found)
+ if (found) {
break;
+ }
}
if (found) {
var = var->next;