summaryrefslogtreecommitdiff
path: root/misc/freeswitch/scripts/dialplan/router.lua
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-01-18 10:19:51 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-01-18 10:19:51 +0100
commitbba745bb46b44d3897222e9d14e2c4f79ede4373 (patch)
treee7c5d4672383db91f9987df0b82fa6f42b35fa84 /misc/freeswitch/scripts/dialplan/router.lua
parent5efd9bdd2f78a15569fb7d1569dceff3bb4f8800 (diff)
parent01078d50412183ff4fbeb213643093e6d2cf8714 (diff)
Merge branch 'develop' of github.com:amooma/GS5 into develop
Diffstat (limited to 'misc/freeswitch/scripts/dialplan/router.lua')
-rw-r--r--misc/freeswitch/scripts/dialplan/router.lua56
1 files changed, 21 insertions, 35 deletions
diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua
index 33434ee..6c5b9f1 100644
--- a/misc/freeswitch/scripts/dialplan/router.lua
+++ b/misc/freeswitch/scripts/dialplan/router.lua
@@ -59,25 +59,6 @@ function Router.expand_variables(self, line)
end
-function Router.set_parameter(self, action, name, value)
- if action == 'set_session_var' then
- self.log:debug('ROUTER_SET_SESSION_VARIABLE - ', name, ' = ', value);
- self.caller[name] = value;
- elseif action == 'set_channel_var' then
- self.log:debug('ROUTER_SET_VARIABLE - ', name, ' = ', value);
- self.caller:set_variable(name, value);
- elseif action == 'export_channel_var' then
- self.log:debug('ROUTER_EXPORT_VARIABLE - ', name, ' = ', value);
- self.caller:export_variable(name, value);
- elseif action == 'set_header' then
- self.log:debug('ROUTER_SIP_HEADER - ', name, ': ', value);
- self.caller:export_variable('sip_h_' .. name, value);
- else
- self.log:error('ROUTER_SET_PARAMERER - unknown action: ', action, ', ', name, ' = ', value);
- end
-end
-
-
function Router.element_match(self, pattern, search_string, replacement)
local variables_list = {};
local success, result = pcall(string.find, search_string, pattern);
@@ -126,20 +107,25 @@ function Router.route_match(self, route)
local element = route.elements[index];
if element.action ~= 'none' then
- local command, variable_name = common.str.partition(element.var_in, ':');
-
- 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));
- elseif command == 'hdr' then
- local search_string = self.caller:to_s('sip_h_' .. variable_name);
- result, replacement = self:element_match(tostring(element.pattern), search_string, tostring(element.replacement));
+ if common.str.blank(element.var_in) or common.str.blank(element.pattern) and element.action == 'set' then
+ result = true;
+ replacement = element.replacement;
+ else
+ local command, variable_name = common.str.partition(element.var_in, ':');
+
+ 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));
+ elseif command == 'hdr' then
+ local search_string = self.caller:to_s('sip_h_' .. variable_name);
+ result, replacement = self:element_match(tostring(element.pattern), search_string, tostring(element.replacement));
+ end
end
if element.action == 'not_match' then
@@ -156,9 +142,9 @@ function Router.route_match(self, route)
if not command or not variable_name or command == 'var' then
destination[element.var_out] = replacement;
elseif command == 'chv' then
- table.insert(destination.channel_variables, { name = element.var_out, value = replacement });
+ destination.channel_variables[variable_name] = replacement;
elseif command == 'hdr' then
- table.insert(destination.channel_variables, { name = 'sip_h_' .. tostring(element.var_out), value = replacement });
+ destination.channel_variables['sip_h_' .. variable_name] = replacement;
end
end