summaryrefslogtreecommitdiff
path: root/main/config.c
diff options
context:
space:
mode:
authorGeorge Joseph <george.joseph@fairview5.com>2014-11-05 00:17:10 +0000
committerGeorge Joseph <george.joseph@fairview5.com>2014-11-05 00:17:10 +0000
commitd5de94201e969b3eeb6ffcef2b92c3b94694f5ce (patch)
tree83c69bee90a50cdf99f385195559d6b58cc879ed /main/config.c
parentc77a71ad2fd330c20e8f5055044ede1c9ab495b0 (diff)
config: Make text_file_save and 'dialplan save' escape semicolons in values.
When a config file is read, an unescaped semicolon signals comments which are stripped from the value before it's stored. Escaped semicolons are then unescaped and become part of the value. Both of these behaviors are normal and expected. When the config is serialized either by 'dialplan save' or AMI/UpdateConfig however, the now unescaped semicolons are written as-is. If you actually reload the file just saved, the unescaped semicolons are now treated as start of comments. Since true comments are stripped on read, any semicolons in ast_variable.value must have been escaped originally. This patch re-escapes semicolons in ast_variable.values before they're written to file either by 'dialplan save' or config/ast_config_text_file_save which is called by AMI/UpdateConfig. I also fixed a few pre-existing formatting issues nearby in pbx_config.c Tested-by: George Joseph ASTERISK-20127 #close Review: https://reviewboard.asterisk.org/r/4132/ ........ Merged revisions 427275 from http://svn.asterisk.org/svn/asterisk/branches/12 ........ Merged revisions 427276 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@427277 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/config.c')
-rw-r--r--main/config.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/main/config.c b/main/config.c
index 23de2c8ba..95f0b696e 100644
--- a/main/config.c
+++ b/main/config.c
@@ -2513,6 +2513,7 @@ int ast_config_text_file_save(const char *configfile, const struct ast_config *c
while (var) {
struct ast_category_template_instance *x;
int found = 0;
+
AST_LIST_TRAVERSE(&cat->template_instances, x, next) {
struct ast_variable *v;
for (v = x->inst->root; v; v = v->next) {
@@ -2558,10 +2559,22 @@ int ast_config_text_file_save(const char *configfile, const struct ast_config *c
if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!')
fprintf(f,"%s", cmt->cmt);
}
- if (var->sameline)
- fprintf(f, "%s %s %s %s", var->name, (var->object ? "=>" : "="), var->value, var->sameline->cmt);
- else
- fprintf(f, "%s %s %s\n", var->name, (var->object ? "=>" : "="), var->value);
+
+ { /* Block for 'escaped' scope */
+ int escaped_len = 2 * strlen(var->value) + 1;
+ char escaped[escaped_len];
+
+ ast_escape_semicolons(var->value, escaped, escaped_len);
+
+ if (var->sameline) {
+ fprintf(f, "%s %s %s %s", var->name, (var->object ? "=>" : "="),
+ escaped, var->sameline->cmt);
+ } else {
+ fprintf(f, "%s %s %s\n", var->name, (var->object ? "=>" : "="),
+ escaped);
+ }
+ }
+
for (cmt = var->trailing; cmt; cmt=cmt->next) {
if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!')
fprintf(f,"%s", cmt->cmt);