From 59b51b24e78a58ecd76baee530531df64ff3f668 Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 18 Jan 2013 09:47:04 +0100 Subject: set channel variables/headers --- misc/freeswitch/scripts/dialplan/sip_call.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/sip_call.lua b/misc/freeswitch/scripts/dialplan/sip_call.lua index 1513459..06132ab 100644 --- a/misc/freeswitch/scripts/dialplan/sip_call.lua +++ b/misc/freeswitch/scripts/dialplan/sip_call.lua @@ -135,6 +135,12 @@ function SipCall.fork(self, destinations, arg ) if destination.caller_id_name then table.insert(origination_variables, "origination_caller_id_name='" .. destination.caller_id_name .. "'"); end + if destination.channel_variables then + for key, value in pairs(destination.channel_variables) do + self.log:notice('FORK_CHANNEL_VARIABLES: ', tostring(key) .. "='" .. tostring(value) .. "'"); + table.insert(origination_variables, tostring(key) .. "='" .. tostring(value) .. "'"); + end + end table.insert(dial_strings, '[' .. table.concat(origination_variables , ',') .. ']sofia/gateway/' .. tostring(destination.gateway) .. '/' .. tostring(destination.number)); elseif destination.type == 'dial' then if destination.caller_id_number then -- cgit v1.2.3 From 983a3e274ab46609d0563d8e941ac4a8d90400c9 Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 18 Jan 2013 09:47:58 +0100 Subject: set channel variables/headers --- misc/freeswitch/scripts/dialplan/router.lua | 56 +++++++++++------------------ 1 file changed, 21 insertions(+), 35 deletions(-) (limited to 'misc') 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 -- cgit v1.2.3 From 01078d50412183ff4fbeb213643093e6d2cf8714 Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 18 Jan 2013 10:08:47 +0100 Subject: log line removed --- misc/freeswitch/scripts/dialplan/sip_call.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/sip_call.lua b/misc/freeswitch/scripts/dialplan/sip_call.lua index 06132ab..0b799e5 100644 --- a/misc/freeswitch/scripts/dialplan/sip_call.lua +++ b/misc/freeswitch/scripts/dialplan/sip_call.lua @@ -137,7 +137,6 @@ function SipCall.fork(self, destinations, arg ) end if destination.channel_variables then for key, value in pairs(destination.channel_variables) do - self.log:notice('FORK_CHANNEL_VARIABLES: ', tostring(key) .. "='" .. tostring(value) .. "'"); table.insert(origination_variables, tostring(key) .. "='" .. tostring(value) .. "'"); end end -- cgit v1.2.3