From a6b3a069c2723e321ebfb79a06026bfe97cec9e6 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Fri, 15 Mar 2013 08:40:36 -0400 Subject: prefer destination variables --- misc/freeswitch/scripts/dialplan/router.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index 751d24f..c335186 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -83,11 +83,16 @@ function Router.element_match(self, pattern, search_string, replacement, route_v end -function Router.element_match_group(self, pattern, groups, replacement, use_key, route_variables) +function Router.element_match_group(self, pattern, groups, replacement, use_key, route_variables, variable_name) if type(groups) ~= 'table' then + self.log:debug('ELEMENT_FIND_IN_ARRAY - no such array: ', variable_name, ', use_keys: ', tostring(use_key)); return false; end + if self.log_details then + self.log:debug('ELEMENT_FIND_IN_ARRAY - array: ', variable_name, ', use_keys: ', tostring(use_key)); + end + for key, value in pairs(groups) do if use_key then value = key; @@ -136,8 +141,8 @@ function Router.route_match(self, route) local search_string = tostring(common.array.try(self.caller, element.var_in)); result, replacement = self:element_match(tostring(element.pattern), search_string, tostring(element.replacement)); elseif command == 'key' or command == 'val' then - local groups = common.array.try(self.caller, variable_name); - result, replacement = self:element_match_group(tostring(element.pattern), groups, tostring(element.replacement), command == 'key'); + local groups = common.array.try(destination, variable_name) or common.array.try(self.caller, variable_name); + result, replacement = self:element_match_group(tostring(element.pattern), groups, tostring(element.replacement), command == 'key', destination, variable_name); elseif command == 'chv' then local search_string = self.caller:to_s(variable_name); result, replacement = self:element_match(tostring(element.pattern), search_string, tostring(element.replacement)); -- cgit v1.2.3