diff options
Diffstat (limited to 'misc/freeswitch/scripts/common')
-rw-r--r-- | misc/freeswitch/scripts/common/array.lua | 3 | ||||
-rw-r--r-- | misc/freeswitch/scripts/common/call_history.lua | 1 | ||||
-rw-r--r-- | misc/freeswitch/scripts/common/conference.lua | 13 | ||||
-rw-r--r-- | misc/freeswitch/scripts/common/gateway.lua | 94 | ||||
-rw-r--r-- | misc/freeswitch/scripts/common/object.lua | 13 |
5 files changed, 121 insertions, 3 deletions
diff --git a/misc/freeswitch/scripts/common/array.lua b/misc/freeswitch/scripts/common/array.lua index c3cabec..58a6798 100644 --- a/misc/freeswitch/scripts/common/array.lua +++ b/misc/freeswitch/scripts/common/array.lua @@ -41,10 +41,11 @@ end function expand_variable(variable_path, variable_sets) for index=1, #variable_sets do local result = try(variable_sets[index], variable_path); - if result then + if result ~= nil then return result; end end + return nil; end -- replace variables in a string by array values diff --git a/misc/freeswitch/scripts/common/call_history.lua b/misc/freeswitch/scripts/common/call_history.lua index 7e1e22b..ee73e84 100644 --- a/misc/freeswitch/scripts/common/call_history.lua +++ b/misc/freeswitch/scripts/common/call_history.lua @@ -76,6 +76,7 @@ function CallHistory.insert_event(self, uuid, account_type, account_id, entry_ty call_history.callee_account_id = common.str.to_sql(event:getHeader('variable_gs_destination_id')); call_history.destination_number = common.str.to_sql(event:getHeader('variable_gs_destination_number')); call_history.forwarding_service = common.str.to_sql(event:getHeader('variable_gs_forwarding_service')); + call_history.clir = common.str.to_sql(common.str.to_b(event:getHeader('variable_gs_clir'))); if not common.str.to_b(event:getHeader('variable_gs_clir')) then call_history.caller_account_type = common.str.to_sql(camelize_type(event:getHeader('variable_gs_caller_account_type') or event:getHeader('variable_gs_account_type'))); diff --git a/misc/freeswitch/scripts/common/conference.lua b/misc/freeswitch/scripts/common/conference.lua index 5694f62..423d564 100644 --- a/misc/freeswitch/scripts/common/conference.lua +++ b/misc/freeswitch/scripts/common/conference.lua @@ -52,8 +52,7 @@ function Conference.settings_get(self) end -function Conference.find_by_id(self, id) - local sql_query = 'SELECT *, (NOW() >= `start` AND NOW() <= `end`) AS `open_now` FROM `conferences` WHERE `id`= ' .. tonumber(id) .. ' LIMIT 1'; +function Conference.find_sql(self, sql_query) local conference = nil; self.database:query(sql_query, function(conference_entry) @@ -82,6 +81,16 @@ function Conference.find_by_id(self, id) end +function Conference.find_by_id(self, id) + return self:find_sql('SELECT *, (NOW() >= `start` AND NOW() <= `end`) AS `open_now` FROM `conferences` WHERE `id`= ' .. tonumber(id) .. ' LIMIT 1'); +end + + +function Conference.find_by_uuid(self, uuid) + return self:find_sql('SELECT *, (NOW() >= `start` AND NOW() <= `end`) AS `open_now` FROM `conferences` WHERE `uuid`= ' .. self.database:escape(uuid, '"') .. ' LIMIT 1'); +end + + function Conference.find_invitee_by_numbers(self, phone_numbers) if not self.record then return false; diff --git a/misc/freeswitch/scripts/common/gateway.lua b/misc/freeswitch/scripts/common/gateway.lua index 09e8c4b..8ea6b04 100644 --- a/misc/freeswitch/scripts/common/gateway.lua +++ b/misc/freeswitch/scripts/common/gateway.lua @@ -274,3 +274,97 @@ function Gateway.parameters_build(self, gateway_id, technology) return parameters; end + + +function Gateway.headers_get(self, header_type, gateway_id) + gateway_id = gateway_id or self.id; + + local sql_query = 'SELECT * FROM `gateway_headers` WHERE `gateway_id` = ' .. tonumber(gateway_id) .. ' AND `header_type` = ' .. self.database:escape(header_type, '"'); + + local headers = {}; + self.database:query(sql_query, function(entry) + table.insert(headers, entry); + end) + + return headers; +end + + +function Gateway.constraint_match(self, constraints_str, variable_sets) + if common.str.blank(constraints_str) then + entry_match = true; + else + local constraints = common.str.strip_to_a(constraints_str, ',') + for constraint_index=1, #constraints do + local variable_name, pattern = common.str.partition(constraints[constraint_index], '!=') + local invert = variable_name ~= nil; + if not variable_name then + variable_name, pattern = common.str.partition(constraints[constraint_index], '=') + end + + if not common.str.blank(variable_name) and not common.str.blank(pattern) then + local search_string = common.array.expand_variable(variable_name, variable_sets); + if search_string ~= nil then + local success, result = pcall(string.find, tostring(search_string), pattern); + + entry_match = common.str.to_b(result); + + if invert then + entry_match = not entry_match; + end + + if entry_match == false then + break; + end + end + end + end + end + + return entry_match; +end + + +function Gateway.origination_variables(self, header_type, origination_variables, ...) + local dtmf = tostring(self.settings.dtmf_type):lower(); + if dtmf == 'inband' then + table.insert(origination_variables, "dtmf_type=none"); + elseif dtmf == 'none' or dtmf == 'info' then + table.insert(origination_variables, "dtmf_type=" .. dtmf); + else + table.insert(origination_variables, "dtmf_type=rfc2833"); + end + + local header_to_variable = { + default = { + default = 'sip_h_', + from = 'sip_full_from', + to = 'sip_full_to', + invite = 'sip_req_uri', + }, + invite = { + default = 'sip_h_', + from = 'sip_invite_full_from', + to = 'sip_invite_full_to', + invite = 'sip_invite_req_uri', + route = 'sip_invite_route_uri', + ['Record-Route'] = 'sip_invite_record_route', + } + } + + local variable_sets = {...}; + local headers = self:headers_get('default'); + for index, header in ipairs(self:headers_get(header_type)) do + table.insert(headers, header); + end + + for index, header in ipairs(headers) do + local search_string = common.array.expand_variable(header.constraint_source, variable_sets); + if common.str.blank(header.constraint_value) or self:constraint_match(header.constraint_value, variable_sets) then + if header_to_variable[header.header_type] then + local origination_variable = header_to_variable[header.header_type][header.name:lower()] or header_to_variable[header.header_type].default .. header.name; + table.insert(origination_variables, origination_variable .. "='" .. common.array.expand_variables(header.value, unpack(variable_sets)) .. "'"); + end + end + end +end diff --git a/misc/freeswitch/scripts/common/object.lua b/misc/freeswitch/scripts/common/object.lua index 68e1361..5482168 100644 --- a/misc/freeswitch/scripts/common/object.lua +++ b/misc/freeswitch/scripts/common/object.lua @@ -116,3 +116,16 @@ function Object.find(self, attributes) return object; end + +-- local class from module +function Object.load_one(self, module_path) + result, module_data = pcall(require, module_path); + if not result or not module_data then + return nil, module_data; + end + for object_name in pairs(module_data) do + if tostring(object_name[1]) ~= '_' then + return module_data[object_name]; + end + end +end |