summaryrefslogtreecommitdiff
path: root/misc/freeswitch/scripts/common/call_forwarding.lua
diff options
context:
space:
mode:
authorPeter Kozak <spag@golwen.net>2013-02-25 09:29:40 -0500
committerPeter Kozak <spag@golwen.net>2013-02-25 09:29:40 -0500
commit0442cd19bc9383669b506185356227361a16e442 (patch)
treefd6c9f9220ace7a58bd723e9a7103834a695770c /misc/freeswitch/scripts/common/call_forwarding.lua
parent5dcdeb1c1f8c53fd80a0443d61a289e583091416 (diff)
call_forwards - polymorphism added
Diffstat (limited to 'misc/freeswitch/scripts/common/call_forwarding.lua')
-rw-r--r--misc/freeswitch/scripts/common/call_forwarding.lua55
1 files changed, 55 insertions, 0 deletions
diff --git a/misc/freeswitch/scripts/common/call_forwarding.lua b/misc/freeswitch/scripts/common/call_forwarding.lua
index 400fcde..192c694 100644
--- a/misc/freeswitch/scripts/common/call_forwarding.lua
+++ b/misc/freeswitch/scripts/common/call_forwarding.lua
@@ -37,6 +37,61 @@ function CallForwarding.find_by_id(self, id)
return nil
end
+
+function CallForwarding.list_by_owner(self, call_forwardable_id, call_forwardable_type, caller_ids)
+ require 'common.str';
+
+ if not tonumber(call_forwardable_id) or common.str.blank(call_forwardable_type) then
+ return {};
+ end
+
+ local sql_query = 'SELECT \
+ `a`.`destination` AS `number`, \
+ `a`.`destinationable_id` AS `id`, \
+ `a`.`destinationable_type` AS `type`, \
+ `a`.`call_forwardable_id`, \
+ `a`.`call_forwardable_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`.`call_forwardable_id`= ' .. tonumber(call_forwardable_id) .. ' \
+ AND `a`.`call_forwardable_type`= ' .. self.database:escape(call_forwardable_type, '"') .. ' \
+ AND `a`.`active` IS TRUE';
+
+ local call_forwarding_entries = {};
+
+ self.database:query(sql_query, function(forwarding_entry)
+ 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 source_index=1, #sources do
+ for caller_id_index=1, #caller_ids do
+ if caller_ids[caller_id_index]:match(sources[source_index]) then
+ entry_match = true;
+ self.log:debug('CALL_FORWARDING - source match: ', sources[source_index], ' ~ ', caller_ids[caller_id_index] );
+ break;
+ end
+ end
+ end
+ end
+
+ if entry_match then
+ call_forwarding_entries[forwarding_entry.service] = forwarding_entry;
+ self.log:debug('CALL_FORWARDING - ', call_forwardable_type, '=', call_forwardable_id,
+ ', service: ', forwarding_entry.service,
+ ', destination: ',forwarding_entry.type, '=', forwarding_entry.id,
+ ', number: ', forwarding_entry.number);
+ end
+ end)
+
+ return call_forwarding_entries;
+end
+
+
function CallForwarding.presence_set(self, presence_state)
require 'dialplan.presence'
local presence = dialplan.presence.Presence:new();