From 68103abba38b3ccd362dd1e9018b4045b9b7cb57 Mon Sep 17 00:00:00 2001 From: Matthew Jordan Date: Wed, 19 Jun 2013 01:28:40 +0000 Subject: [PATCH] Handle variable substitution in dummy variables When func_cdr is used for variable substitution, there is no channel name and hence no run-time information available for CDR variable substitution. In that case, the correct thing to do is to use the CDR object on the channel passed to the function. This patch checks to see if the channel passed in has a name - if not, it uses ast_cdr_format_var instead of ast_cdr_get_var. This allows CDR backends to continue to use variable substitution in order to resolve ast_cdr object properties. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@392214 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- funcs/func_cdr.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/funcs/func_cdr.c b/funcs/func_cdr.c index 492716dcf6..7625238696 100644 --- a/funcs/func_cdr.c +++ b/funcs/func_cdr.c @@ -205,8 +205,9 @@ static int cdr_read(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len) { char format_buf[128]; + char *value = NULL; struct ast_flags flags = { 0 }; - char tempbuf[128]; + char tempbuf[512]; char *info; AST_DECLARE_APP_ARGS(args, AST_APP_ARG(variable); @@ -228,7 +229,15 @@ static int cdr_read(struct ast_channel *chan, const char *cmd, char *parse, ast_app_parse_options(cdr_func_options, &flags, NULL, args.options); } - if (ast_cdr_getvar(ast_channel_name(chan), args.variable, tempbuf, sizeof(tempbuf))) { + if (ast_strlen_zero(ast_channel_name(chan))) { + /* Format request on a dummy channel */ + ast_cdr_format_var(ast_channel_cdr(chan), args.variable, &value, tempbuf, sizeof(tempbuf), 0); + if (ast_strlen_zero(value)) { + return 0; + } + ast_copy_string(tempbuf, value, sizeof(tempbuf)); + ast_set_flag(&flags, OPT_UNPARSED); + }else if (ast_cdr_getvar(ast_channel_name(chan), args.variable, tempbuf, sizeof(tempbuf))) { return 0; }