summaryrefslogtreecommitdiff
path: root/pbx
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 /pbx
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 '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 e76f6e892..a42ea47fd 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);
}
}
}