summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorspag <spag@golwen.net>2013-01-17 11:12:02 +0100
committerspag <spag@golwen.net>2013-01-17 11:12:02 +0100
commit0a3a4c78badb80e7f0f7b5d372421f1e75fd5f02 (patch)
tree3e13d1df34b90b727d833044191fc660d89d14aa
parentf08ec4598b9efcab4692ffa0a355da284fbfd5c2 (diff)
access arrays from within routing elements
-rw-r--r--misc/freeswitch/scripts/dialplan/router.lua40
1 files changed, 25 insertions, 15 deletions
diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua
index 2071288..de543f3 100644
--- a/misc/freeswitch/scripts/dialplan/router.lua
+++ b/misc/freeswitch/scripts/dialplan/router.lua
@@ -92,6 +92,23 @@ function Router.element_match(self, pattern, search_string, replacement)
end
+function Router.element_match_group(self, pattern, groups, replacement, use_key)
+ if type(groups) ~= 'table' then
+ return false;
+ end
+
+ for key, value in pairs(groups) do
+ if use_key then
+ value = key;
+ end
+ result, replaced_value = self:element_match(pattern, tostring(value), replacement);
+ if result then
+ return true, replaced_value;
+ end
+ end
+end
+
+
function Router.route_match(self, route)
local destination = {
gateway = 'gateway' .. route.endpoint_id,
@@ -107,24 +124,17 @@ function Router.route_match(self, route)
local replacement = nil;
local element = route.elements[index];
- if element.var_in == 'group' then
- local groups = common.str.try(self.caller, 'auth_account.owner.groups');
- if not groups or type(groups) ~= 'table' then
- if element.mandatory then
- return false;
- end
- end
+ local command, variable_name = common.str.partition(element.var_in, ':');
- for group_name, value in pairs(groups) do
- result, replacement = self:element_match(tostring(element.pattern), tostring(group_name), tostring(element.replacement));
- if result then
- break;
- end
- end
-
- else
+ if not command or not variable_name or command == 'var' then
local search_string = tostring(common.str.try(self.caller, element.var_in))
result, replacement = self:element_match(tostring(element.pattern), tostring(search_string), tostring(element.replacement));
+ elseif command == 'key' or command == 'val' then
+ local groups = common.str.try(self.caller, variable_name);
+ result, replacement = self:element_match_group(tostring(element.pattern), groups, tostring(element.replacement), command == 'key');
+ 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));
end
if element.action == 'not_match' then