summaryrefslogtreecommitdiff
path: root/pbx
diff options
context:
space:
mode:
authorGeorge Joseph <george.joseph@fairview5.com>2014-11-05 00:15:48 +0000
committerGeorge Joseph <george.joseph@fairview5.com>2014-11-05 00:15:48 +0000
commit9d1b3ec22af43ea531365e9bec9b559852c25be7 (patch)
tree5efe8874db797561b6dcd67d38091f6b5719b9ce /pbx
parente5e29897fa5e5a4d468790e37077e66bc4704376 (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 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@427276 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'pbx')
-rw-r--r--pbx/pbx_config.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/pbx/pbx_config.c b/pbx/pbx_config.c
index 01550c0b1..1dd09850c 100644
--- a/pbx/pbx_config.c
+++ b/pbx/pbx_config.c
@@ -890,7 +890,11 @@ static char *handle_cli_dialplan_save(struct ast_cli_entry *e, int cmd, struct a
if ((v = ast_variable_browse(cfg, "globals"))) {
fprintf(output, "[globals]\n");
while(v) {
- fprintf(output, "%s => %s\n", v->name, v->value);
+ int escaped_len = 2 * strlen(v->value) + 1;
+ char escaped[escaped_len];
+
+ ast_escape_semicolons(v->value, escaped, escaped_len);
+ fprintf(output, "%s => %s\n", v->name, escaped);
v = v->next;
}
fprintf(output, "\n");
@@ -951,20 +955,33 @@ static char *handle_cli_dialplan_save(struct ast_cli_entry *e, int cmd, struct a
const char *sep, *cid;
const char *el = ast_get_extension_label(p);
char label[128] = "";
-
+ char *appdata = ast_get_extension_app_data(p);
+ char *escaped;
+
if (ast_get_extension_matchcid(p)) {
sep = "/";
cid = ast_get_extension_cidmatch(p);
- } else
+ } else {
sep = cid = "";
-
- if (el && (snprintf(label, sizeof(label), "(%s)", el) != (strlen(el) + 2)))
+ }
+
+ if (el && (snprintf(label, sizeof(label), "(%s)", el) != (strlen(el) + 2))) {
incomplete = 1; /* error encountered or label > 125 chars */
-
+ }
+
+ if (!ast_strlen_zero(appdata)) {
+ int escaped_len = 2 * strlen(appdata) + 1;
+ char escaped[escaped_len];
+
+ ast_escape_semicolons(appdata, escaped, escaped_len);
+ } else {
+ escaped = "";
+ }
+
fprintf(output, "exten => %s%s%s,%d%s,%s(%s)\n",
ast_get_extension_name(p), (ast_strlen_zero(sep) ? "" : sep), (ast_strlen_zero(cid) ? "" : cid),
ast_get_extension_priority(p), label,
- ast_get_extension_app(p), (ast_strlen_zero(ast_get_extension_app_data(p)) ? "" : (const char *)ast_get_extension_app_data(p)));
+ ast_get_extension_app(p), escaped);
}
}
}