summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Pawlowski <julian.pawlowski@gmail.com>2012-12-21 13:20:59 +0100
committerJulian Pawlowski <julian.pawlowski@gmail.com>2012-12-21 13:20:59 +0100
commit8192bd2ba0e72513e6750015a3367e8bf1ab7734 (patch)
treeafae79cb9e94f6135b8671039eacdb5c076363e3
parent031d78689668a8f18efbd0e9cf0df1a8f1a38b5d (diff)
parent77a3c41cbb7edb93dcc98b7ae18a1b58e0d2d2ef (diff)
Merge branch 'develop'
-rw-r--r--misc/freeswitch/scripts/common/phone_number.lua37
1 files changed, 28 insertions, 9 deletions
diff --git a/misc/freeswitch/scripts/common/phone_number.lua b/misc/freeswitch/scripts/common/phone_number.lua
index f4f4bfe..4df0d57 100644
--- a/misc/freeswitch/scripts/common/phone_number.lua
+++ b/misc/freeswitch/scripts/common/phone_number.lua
@@ -95,7 +95,7 @@ function PhoneNumber.list_by_same_owner(self, number, owner_types)
end
-- Retrieve call forwarding
-function PhoneNumber.call_forwarding(self, sources)
+function PhoneNumber.call_forwarding(self, caller_ids)
require 'common.str'
sources = sources or {};
@@ -106,21 +106,40 @@ function PhoneNumber.call_forwarding(self, sources)
`a`.`call_forwardable_id` AS `id`, \
`a`.`call_forwardable_type` AS `type`, \
`a`.`timeout`, `a`.`depth`, \
+ `a`.`source`, \
`b`.`value` AS `service` \
FROM `call_forwards` `a` JOIN `call_forward_cases` `b` ON `a`.`call_forward_case_id` = `b`.`id` \
WHERE `a`.`phone_number_id`= ' .. tonumber(self.record.id) .. ' \
- AND `a`.`active` IS TRUE \
- AND (`a`.`source` IS NULL OR `a`.`source` IN ("' .. table.concat( sources, '","') .. '"))';
+ AND `a`.`active` IS TRUE';
local call_forwarding = {}
self.database:query(sql_query, function(forwarding_entry)
- call_forwarding[forwarding_entry.service] = forwarding_entry;
- self.log:debug('CALL_FORWARDING_GET - PhoneNumber=', self.record.id, '/', self.record.uuid, '@', self.record.gs_node_id,
- ', number: ', self.record.number,
- ', service: ', forwarding_entry.service,
- ', destination: ',forwarding_entry.type, '=', forwarding_entry.id,
- ', number: ', forwarding_entry.number);
+ local entry_match = false;
+
+ if common.str.blank(forwarding_entry.source) then
+ entry_match = true;
+ else
+ local sources = common.str.strip_to_a(forwarding_entry.source, ',')
+ for index, source in ipairs(sources) do
+ for index, caller_id in ipairs(caller_ids) do
+ if caller_id:match(source) then
+ entry_match = true;
+ self.log:debug('CALL_FORWARDING_GET - source match: ', source, ' ~ ', caller_id );
+ break;
+ end
+ end
+ end
+ end
+
+ if entry_match then
+ call_forwarding[forwarding_entry.service] = forwarding_entry;
+ self.log:debug('CALL_FORWARDING_GET - PhoneNumber=', self.record.id, '/', self.record.uuid, '@', self.record.gs_node_id,
+ ', number: ', self.record.number,
+ ', service: ', forwarding_entry.service,
+ ', destination: ',forwarding_entry.type, '=', forwarding_entry.id,
+ ', number: ', forwarding_entry.number);
+ end
end)
return call_forwarding;