From 9276a4370c68844b056b0d078edf23f70fcf0670 Mon Sep 17 00:00:00 2001 From: Tilghman Lesher <tilghman@meg.abyt.es> Date: Thu, 22 May 2008 21:42:50 +0000 Subject: [PATCH] Add a compatibility option for upgrading realtime extensions git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@117986 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- configs/pbx_realtime.conf | 11 +++++++++++ pbx/pbx_realtime.c | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 configs/pbx_realtime.conf diff --git a/configs/pbx_realtime.conf b/configs/pbx_realtime.conf new file mode 100644 index 0000000000..022b3e934e --- /dev/null +++ b/configs/pbx_realtime.conf @@ -0,0 +1,11 @@ +[general] +; The native delimiters for application arguments changed in 1.6 to be commas, +; instead of pipes. For people who don't want to upgrade their databases +; immediately, there is this compatibility option, which will allow them to +; use pipes, via a translation done at runtime. Set compat to 1.4, if you +; want to turn this translation ON. Set compat to 1.6 if you've already made +; the transition. +; +; compat=1.4 +compat=1.6 + diff --git a/pbx/pbx_realtime.c b/pbx/pbx_realtime.c index d4876bd7fe..ea2ee9bab8 100644 --- a/pbx/pbx_realtime.c +++ b/pbx/pbx_realtime.c @@ -53,6 +53,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #define EXT_DATA_SIZE 256 +/* If set to 0, translate commas to "\," and pipes to "," */ +static int compat16 = 1; /* Realtime switch looks up extensions in the supplied realtime table. @@ -176,8 +178,24 @@ static int realtime_exec(struct ast_channel *chan, const char *context, const ch for (v = var; v ; v = v->next) { if (!strcasecmp(v->name, "app")) app = ast_strdupa(v->value); - else if (!strcasecmp(v->name, "appdata")) - tmp = ast_strdupa(v->value); + else if (!strcasecmp(v->name, "appdata")) { + if (!compat16) { + char *ptr; + tmp = alloca(strlen(v->value) * 2 + 1); + for (ptr = tmp; *v->value; v->value++) { + if (*v->value == ',') { + *ptr++ = '\\'; + *ptr++ = ','; + } else if (*v->value == '|') { + *ptr++ = ','; + } else { + *ptr++ = *v->value; + } + } + } else { + tmp = ast_strdupa(v->value); + } + } } ast_variables_destroy(var); if (!ast_strlen_zero(app)) { @@ -243,6 +261,18 @@ static int unload_module(void) static int load_module(void) { + struct ast_flags flags = { 0 }; + struct ast_config *cfg = ast_config_load("pbx_realtime.conf", flags); + if (cfg) { + const char *tmp = ast_variable_retrieve(cfg, "general", "compat"); + if (tmp && strncmp(tmp, "1.6", 3)) { + compat16 = 0; + } else { + compat16 = 1; + } + ast_config_destroy(cfg); + } + if (ast_register_switch(&realtime_switch)) return AST_MODULE_LOAD_FAILURE; return AST_MODULE_LOAD_SUCCESS; -- GitLab