summaryrefslogtreecommitdiff
path: root/misc/freeswitch/scripts/dialplan
diff options
context:
space:
mode:
Diffstat (limited to 'misc/freeswitch/scripts/dialplan')
-rw-r--r--misc/freeswitch/scripts/dialplan/dialplan.lua24
-rw-r--r--misc/freeswitch/scripts/dialplan/functions.lua17
-rw-r--r--misc/freeswitch/scripts/dialplan/hunt_group.lua2
-rw-r--r--misc/freeswitch/scripts/dialplan/router.lua22
4 files changed, 20 insertions, 45 deletions
diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua
index 6d75d8d..fabc5af 100644
--- a/misc/freeswitch/scripts/dialplan/dialplan.lua
+++ b/misc/freeswitch/scripts/dialplan/dialplan.lua
@@ -22,6 +22,9 @@ local CALL_FORWARDING_SERVICES = {
-- create dialplan object
function Dialplan.new(self, arg)
+ require 'common.str';
+ require 'common.array';
+
arg = arg or {}
object = arg.object or {}
setmetatable(object, self);
@@ -35,7 +38,6 @@ end
function Dialplan.domain_get(self, domain)
- require 'common.str'
local global_domain = freeswitch.API():execute('global_getvar', 'domain');
if common.str.blank(global_domain) then
@@ -74,7 +76,6 @@ end
function Dialplan.configuration_read(self)
- require 'common.str'
require 'common.configuration_table'
-- dialplan configuration
@@ -124,7 +125,6 @@ end
function Dialplan.auth_sip_account(self)
- require 'common.str'
if not common.str.blank(self.caller.auth_account_type) then
self.log:info('AUTH_SIP_ACCOUNT - ', self.caller.auth_account_type, '=', self.caller.account_id, '/', self.caller.account_uuid);
return true;
@@ -163,7 +163,6 @@ end
function Dialplan.retrieve_caller_data(self)
- require 'common.str'
self.caller.caller_phone_numbers_hash = {};
-- TODO: Set auth_account on transfer initiated by calling party
@@ -219,8 +218,6 @@ end
function Dialplan.destination_new(self, arg)
- require 'common.str'
-
local destination = {
number = arg.number or '',
type = arg.type or 'unknown',
@@ -300,7 +297,6 @@ function Dialplan.dial(self, destination)
local user_id = nil;
local tenant_id = nil;
- require 'common.str'
destination.caller_id_number = destination.caller_id_number or self.caller.caller_phone_numbers[1];
if destination.node_local and destination.type == 'sipaccount' then
@@ -334,7 +330,6 @@ function Dialplan.dial(self, destination)
if not self.caller.clir then
if user_id or tenant_id then
- require 'common.str'
if self.phonebook_number_lookup then
require 'dialplan.phone_book'
@@ -591,7 +586,6 @@ end
function Dialplan.voicemail(self, destination)
- require 'common.str';
require 'dialplan.voicemail'
local voicemail_account = nil;
@@ -625,7 +619,6 @@ end
function Dialplan.switch(self, destination)
- require 'common.str'
local result = nil;
self.dial_timeout_active = self.dial_timeout;
@@ -719,7 +712,7 @@ function Dialplan.switch(self, destination)
elseif not common.str.blank(destination.number) then
local result = { continue = false, code = 404, phrase = 'No route' }
- local clip_no_screening = common.str.try(self.caller, 'account.record.clip_no_screening');
+ local clip_no_screening = common.array.try(self.caller, 'account.record.clip_no_screening');
self.caller.caller_id_numbers = {}
if not common.str.blank(clip_no_screening) then
for index, number in ipairs(common.str.strip_to_a(clip_no_screening, ',')) do
@@ -743,9 +736,8 @@ function Dialplan.switch(self, destination)
end
if self.phonebook_number_lookup then
- require 'common.str'
- local user_id = common.str.try(self.caller, 'account.owner.id');
- local tenant_id = common.str.try(self.caller, 'account.owner.record.current_tenant_id');
+ local user_id = common.array.try(self.caller, 'account.owner.id');
+ local tenant_id = common.array.try(self.caller, 'account.owner.record.current_tenant_id');
if user_id or tenant_id then
require 'dialplan.phone_book'
@@ -761,7 +753,6 @@ function Dialplan.switch(self, destination)
require 'dialplan.geo_number'
local geo_number = dialplan.geo_number.GeoNumber:new{ log = self.log, database = self.database }:find(destination.number);
if geo_number then
- require 'common.str'
self.log:info('GEO_NUMBER - found: ', geo_number.name, ', ', geo_number.country);
if geo_number.name then
destination.callee_id_name = common.str.to_ascii(geo_number.name) .. ', ' .. common.str.to_ascii(geo_number.country);
@@ -812,7 +803,6 @@ end
function Dialplan.run(self, destination)
- require 'common.str';
require 'dialplan.router';
self.caller:set_variable('hangup_after_bridge', false);
@@ -897,7 +887,7 @@ function Dialplan.run(self, destination)
end
self.caller:set_variable('default_language', self.caller.language);
- self.caller:set_variable('sound_prefix', common.str.try(self.config, 'sounds.' .. tostring(self.caller.language)));
+ self.caller:set_variable('sound_prefix', common.array.try(self.config, 'sounds.' .. tostring(self.caller.language)));
self.log:info('DIALPLAN start - caller_id: ',self.caller.caller_id_number, ' "', self.caller.caller_id_name, '" , number: ', destination.number, ', language: ', self.caller.language);
local result = { continue = false };
diff --git a/misc/freeswitch/scripts/dialplan/functions.lua b/misc/freeswitch/scripts/dialplan/functions.lua
index 780e3be..88eba2c 100644
--- a/misc/freeswitch/scripts/dialplan/functions.lua
+++ b/misc/freeswitch/scripts/dialplan/functions.lua
@@ -23,7 +23,6 @@ function Functions.ensure_caller_sip_account(self, caller)
end
function Functions.dialplan_function(self, caller, dialed_number)
- require 'common.str'
local parameters = common.str.to_a(dialed_number, '%-');
if not parameters[2] then
return { continue = false, code = 484, phrase = 'Malformed function parameters', no_cdr = true };
@@ -169,12 +168,11 @@ function Functions.intercept_any_number(self, caller, destination_number)
return { continue = false, code = 404, phrase = 'Destination not found', no_cdr = true };
end
- require 'common.str';
require 'common.group';
local group_class = common.group.Group:new{ log = self.log, database = self.database };
- local group_ids = group_class:union(common.str.try(caller, 'auth_account.group_ids'), common.str.try(caller, 'auth_account.owner.group_ids'));
+ local group_ids = group_class:union(common.array.try(caller, 'auth_account.group_ids'), common.array.try(caller, 'auth_account.owner.group_ids'));
local target_groups, target_group_ids = group_class:permission_targets(group_ids, 'pickup');
- local destination_group_ids = group_class:union(common.str.try(phone_numberable, 'group_ids'), common.str.try(phone_numberable, 'owner.group_ids'));
+ local destination_group_ids = group_class:union(common.array.try(phone_numberable, 'group_ids'), common.array.try(phone_numberable, 'owner.group_ids'));
if #group_class:intersection(destination_group_ids, target_group_ids) == 0 then
self.log:notice('FUNCTION_INTERCEPT_ANY_NUMBER - Groups not found or insufficient permissions');
@@ -195,10 +193,9 @@ function Functions.group_pickup(self, caller, group_id)
return { continue = false, code = 505, phrase = 'Incompatible destination', no_cdr = true };
end
- require 'common.str';
require 'common.group';
local group_class = common.group.Group:new{ log = self.log, database = self.database };
- local group_ids = group_class:union(common.str.try(caller, 'auth_account.group_ids'), common.str.try(caller, 'auth_account.owner.group_ids'));
+ local group_ids = group_class:union(common.array.try(caller, 'auth_account.group_ids'), common.array.try(caller, 'auth_account.owner.group_ids'));
local target_group = group_class:is_target(group_id, 'pickup');
if not target_group then
@@ -250,8 +247,6 @@ end
function Functions.user_login(self, caller, number, pin)
- require 'common.str'
-
local PHONE_NUMBER_LEN_MIN = 4;
local PHONE_NUMBER_LEN_MAX = 12;
local PIN_LEN_MIN = 4;
@@ -367,7 +362,6 @@ end
function Functions.user_logout(self, caller)
- require 'common.str'
self.log:info('LOGOUT - caller: ', caller.account_type, '/', caller.account_uuid, ', caller_id: ', caller.caller_id_number);
-- find caller's sip account
@@ -845,8 +839,6 @@ end
function Functions.hangup(self, caller, code, phrase)
- require 'common.str'
-
if not tonumber(code) then
code = 403;
phrase = 'Forbidden';
@@ -885,8 +877,7 @@ function Functions.call_parking_inout_index(self, caller, stall_index)
return { continue = false, code = 404, phrase = 'No parkings stall specified', no_cdr = true }
end
- require 'common.str';
- local owner = common.str.try(caller, 'auth_account.owner');
+ local owner = common.array.try(caller, 'auth_account.owner');
if not owner then
self.log:notice('FUNCTION_CALL_PARKING_INOUT_INDEX - stall owner not specified');
diff --git a/misc/freeswitch/scripts/dialplan/hunt_group.lua b/misc/freeswitch/scripts/dialplan/hunt_group.lua
index fa3c05b..bff0a8e 100644
--- a/misc/freeswitch/scripts/dialplan/hunt_group.lua
+++ b/misc/freeswitch/scripts/dialplan/hunt_group.lua
@@ -98,7 +98,7 @@ function HuntGroup.run(self, dialplan_object, caller, destination)
self.log:info('HUNTGROUP ', self.record.id, ' - name: ', self.record.name, ', strategy: ', self.record.strategy,', members: ', #hunt_group_members);
- local clip_no_screening = common.str.try(caller, 'account.record.clip_no_screening');
+ local clip_no_screening = common.array.try(caller, 'account.record.clip_no_screening');
caller.caller_id_numbers = {}
if not common.str.blank(clip_no_screening) then
for index, number in ipairs(common.str.strip_to_a(clip_no_screening, ',')) do
diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua
index 8473c2b..277958a 100644
--- a/misc/freeswitch/scripts/dialplan/router.lua
+++ b/misc/freeswitch/scripts/dialplan/router.lua
@@ -9,6 +9,7 @@ Router = {}
-- create route object
function Router.new(self, arg)
require 'common.str';
+ require 'common.array';
arg = arg or {}
object = arg.object or {}
setmetatable(object, self);
@@ -60,20 +61,13 @@ function Router.read_table(self, table_name, force_reload)
end
-function Router.expand_variables(self, line, variables, variables2)
- return (line:gsub('{([%a%d%._]+)}', function(captured)
- return common.str.try(variables, captured) or common.str.try(variables2, captured) or '';
- end))
-end
-
-
function Router.element_match(self, pattern, search_string, replacement, route_variables)
local success, result = pcall(string.find, search_string, pattern);
if not success then
self.log:error('ELEMENT_MATCH - table error - pattern: ', pattern, ', search_string: ', search_string);
elseif result then
- return true, search_string:gsub(pattern, self:expand_variables(replacement, route_variables, self.variables));
+ return true, search_string:gsub(pattern, common.array.expand_variables(replacement, route_variables, self.variables));
end
return false;
@@ -102,7 +96,7 @@ function Router.route_match(self, route)
gateway = 'gateway' .. route.endpoint_id,
['type'] = route.endpoint_type,
id = route.endpoint_id,
- destination_number = common.str.try(self, 'caller.destination_number'),
+ destination_number = common.array.try(self, 'caller.destination_number'),
channel_variables = {},
};
@@ -117,18 +111,18 @@ function Router.route_match(self, route)
if element.action ~= 'none' then
if common.str.blank(element.var_in) or common.str.blank(element.pattern) and element.action == 'set' then
result = true;
- replacement = self:expand_variables(element.replacement, destination, self.variables);
+ replacement = common.array.expand_variables(element.replacement, destination, self.variables);
else
local command, variable_name = common.str.partition(element.var_in, ':');
if not command or not variable_name then
- local search_string = tostring(common.str.try(destination, element.var_in) or common.str.try(self.caller, element.var_in));
+ local search_string = tostring(common.array.try(destination, element.var_in) or common.array.try(self.caller, element.var_in));
result, replacement = self:element_match(tostring(element.pattern), search_string, tostring(element.replacement), destination);
elseif command == 'var' then
- local search_string = tostring(common.str.try(self.caller, element.var_in));
+ 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.str.try(self.caller, variable_name);
+ local groups = common.array.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);
@@ -151,7 +145,7 @@ function Router.route_match(self, route)
if not common.str.blank(element.var_out) then
local command, variable_name = common.str.partition(element.var_out, ':');
if not command or not variable_name or command == 'var' then
- common.str.set(destination, element.var_out, replacement);
+ common.array.set(destination, element.var_out, replacement);
elseif command == 'chv' then
destination.channel_variables[variable_name] = replacement;
elseif command == 'hdr' then