diff options
author | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2013-02-27 12:22:29 +0100 |
---|---|---|
committer | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2013-02-27 12:22:29 +0100 |
commit | 67c1a0a951403a546250ea860a3e3d199cae2fce (patch) | |
tree | f86ec6cedf081a1a57005eca1661e9bead34e4de /misc/freeswitch/scripts/common | |
parent | 5d8ce5f4775ac8bc5f523964e6e36f63ff3c4683 (diff) | |
parent | 211f558a86ae30cdd5b392ab1376e1393f97e22c (diff) |
Merge branch 'develop'5.1-beta6
Diffstat (limited to 'misc/freeswitch/scripts/common')
-rw-r--r-- | misc/freeswitch/scripts/common/call_forwarding.lua | 55 | ||||
-rw-r--r-- | misc/freeswitch/scripts/common/conference.lua | 6 | ||||
-rw-r--r-- | misc/freeswitch/scripts/common/group.lua | 88 | ||||
-rw-r--r-- | misc/freeswitch/scripts/common/phone_number.lua | 55 | ||||
-rw-r--r-- | misc/freeswitch/scripts/common/str.lua | 34 |
5 files changed, 184 insertions, 54 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(); diff --git a/misc/freeswitch/scripts/common/conference.lua b/misc/freeswitch/scripts/common/conference.lua index f6a4d87..b56cba9 100644 --- a/misc/freeswitch/scripts/common/conference.lua +++ b/misc/freeswitch/scripts/common/conference.lua @@ -159,7 +159,7 @@ function Conference.enter(self, caller, domain) caller:sleep(1000); caller.session:sayPhrase('conference_welcome'); - if pin and pin ~= "" then + if not common.str.blank(pin) then local digits = ""; for i = 1, 3, 1 do if digits == pin then @@ -167,7 +167,7 @@ function Conference.enter(self, caller, domain) elseif digits ~= "" then caller.session:sayPhrase('conference_bad_pin'); end - digits = caller.session:read(PIN_LENGTH_MIN, PIN_LENGTH_MAX, 'conference/conf-enter_conf_pin.wav', PIN_TIMEOUT, '#'); + digits = caller.session:read(PIN_LENGTH_MIN, PIN_LENGTH_MAX, 'conference/conf-pin.wav', PIN_TIMEOUT, '#'); end if digits ~= pin then caller.session:sayPhrase('conference_goodbye'); @@ -191,7 +191,7 @@ function Conference.enter(self, caller, domain) -- Record caller's name if common.str.to_b(self.record.announce_new_member_by_name) or common.str.to_b(self.record.announce_left_member_by_name) then local uid = session:get_uuid(); - name_file = "/tmp/conference_caller_name_" .. uid .. ".wav"; + name_file = "/var/spool/freeswitch/conference_caller_name_" .. uid .. ".wav"; caller.session:sayPhrase('conference_record_name'); session:recordFile(name_file, ANNOUNCEMENT_MAX_LEN, ANNOUNCEMENT_SILENCE_THRESHOLD, ANNOUNCEMENT_SILENCE_LEN); caller.session:streamFile(name_file); diff --git a/misc/freeswitch/scripts/common/group.lua b/misc/freeswitch/scripts/common/group.lua new file mode 100644 index 0000000..c4125bc --- /dev/null +++ b/misc/freeswitch/scripts/common/group.lua @@ -0,0 +1,88 @@ +-- Gemeinschaft 5 module: group class +-- (c) AMOOMA GmbH 2013 +-- + +module(...,package.seeall) + +Group = {} + +MAX_GROUP_MEMBERSHIPS = 256; + +-- create group object +function Group.new(self, arg) + arg = arg or {} + object = arg.object or {} + setmetatable(object, self); + self.__index = self; + self.class = 'group'; + self.log = arg.log; + self.database = arg.database; + return object; +end + +-- find group by id +function Group.find_by_id(self, id) + local sql_query = 'SELECT * FROM `groups` WHERE `id`= ' .. tonumber(id) .. ' LIMIT 1'; + local group = nil; + + self.database:query(sql_query, function(account_entry) + group = Group:new(self); + group.record = account_entry; + group.id = tonumber(account_entry.id); + group.name = account_entry.name; + end); + + return group; +end + +-- list groups by member permissions +function Group.name_id_by_permission(self, member_id, member_type, permission) + if not tonumber(member_id) then + return {}; + end + + local sql_query = 'SELECT DISTINCT `c`.`id`, `c`.`name` \ + FROM `group_permissions` `a` \ + JOIN `group_memberships` `b` ON `a`.`target_group_id` = `b`.`group_id` \ + JOIN `groups` `c` ON `c`.`id` = `b`.`group_id` \ + WHERE `b`.`item_type` = ' .. self.database:escape(member_type, '"') .. ' \ + AND `b`.`item_id` = ' .. member_id .. ' \ + AND `a`.`permission` = ' .. self.database:escape(permission, '"') .. ' \ + AND `c`.`active` IS TRUE \ + GROUP BY `b`.`group_id` LIMIT ' .. MAX_GROUP_MEMBERSHIPS; + + local group_names = {}; + local group_ids = {}; + + self.database:query(sql_query, function(account_entry) + table.insert(group_names, account_entry.name); + table.insert(group_ids, tonumber(account_entry.id)); + end); + + return group_names, group_ids; +end + +-- list groups by member +function Group.name_id_by_member(self, member_id, member_type) + if not tonumber(member_id) then + return {}; + end + + local sql_query = 'SELECT DISTINCT `c`.`id`, `c`.`name` \ + FROM `group_memberships` `b` \ + JOIN `groups` `c` ON `c`.`id` = `b`.`group_id` \ + WHERE `b`.`item_type` = ' .. self.database:escape(member_type, '"') .. ' \ + AND `b`.`item_id` = ' .. member_id .. ' \ + AND `c`.`active` IS TRUE \ + GROUP BY `b`.`group_id` LIMIT ' .. MAX_GROUP_MEMBERSHIPS; + + local group_names = {}; + local group_ids = {}; + + self.database:query(sql_query, function(account_entry) + table.insert(group_names, account_entry.name); + table.insert(group_ids, tonumber(account_entry.id)); + end); + + return group_names, group_ids; +end diff --git a/misc/freeswitch/scripts/common/phone_number.lua b/misc/freeswitch/scripts/common/phone_number.lua index 6635296..d6ee42a 100644 --- a/misc/freeswitch/scripts/common/phone_number.lua +++ b/misc/freeswitch/scripts/common/phone_number.lua @@ -55,6 +55,8 @@ function PhoneNumber.find_by_number(self, number, phone_numberable_types) self.database:query(sql_query, function(number_entry) phone_number = PhoneNumber:new(self); phone_number.record = number_entry; + phone_number.id = tonumber(number_entry.id); + phone_number.uuid = number_entry.uuid; end) return phone_number; @@ -68,6 +70,8 @@ function PhoneNumber.find_all_by_owner(self, owner_id, owner_type) self.database:query(sql_query, function(number_entry) phone_numbers[tonumber(number_entry.id)] = PhoneNumber:new(self); phone_numbers[tonumber(number_entry.id)].record = number_entry; + phone_numbers[tonumber(number_entry.id)].id = tonumber(number_entry.id); + phone_numbers[tonumber(number_entry.id)].uuid = number_entry.uuid; end) return phone_numbers; @@ -94,57 +98,6 @@ function PhoneNumber.list_by_same_owner(self, number, owner_types) end end --- Retrieve call forwarding -function PhoneNumber.call_forwarding(self, caller_ids) - require 'common.str' - - sources = sources or {}; - table.insert(sources, ''); - - local sql_query = 'SELECT \ - `a`.`destination` AS `number`, \ - `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'; - - local call_forwarding = {} - - 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 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; -end - function PhoneNumber.call_forwarding_effective(self, service, source) local conditions = {} diff --git a/misc/freeswitch/scripts/common/str.lua b/misc/freeswitch/scripts/common/str.lua index 72ff388..541199f 100644 --- a/misc/freeswitch/scripts/common/str.lua +++ b/misc/freeswitch/scripts/common/str.lua @@ -146,3 +146,37 @@ end function blank(value) return (value == nil or to_s(value) == ''); end + +-- concatenate string to buffer +function append(buffer, value, separator, prefix, suffix) + separator = separator or ''; + prefix = prefix or ''; + suffix = suffix or ''; + if buffer ~= '' then + buffer = buffer .. separator .. prefix .. value .. suffix; + else + buffer = prefix .. value .. suffix; + end + + return buffer; +end + +-- concatenate array values to string +function concat(array, separator, prefix, suffix) + local buffer = ''; + for key, value in pairs(array) do + buffer = append(buffer, value, separator, prefix, suffix); + end + + return buffer; +end + +-- concatenate array keys to string +function concat_keys(array, separator, prefix, suffix) + local buffer = ''; + for key, value in pairs(array) do + buffer = append(buffer, key, separator, prefix, suffix); + end + + return buffer; +end |