From 2e95e18594226283956a298999ad5b00bab13a34 Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 23 Jan 2013 11:34:04 +0100 Subject: exit on unsupported types --- misc/freeswitch/scripts/common/str.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'misc/freeswitch/scripts/common') diff --git a/misc/freeswitch/scripts/common/str.lua b/misc/freeswitch/scripts/common/str.lua index 32f054e..793c191 100644 --- a/misc/freeswitch/scripts/common/str.lua +++ b/misc/freeswitch/scripts/common/str.lua @@ -5,6 +5,10 @@ module(...,package.seeall) function try(array, arguments) + if type(arguments) ~= 'string' or type(array) ~= 'table' then + return nil; + end + local result = array; arguments:gsub('([^%.]+)', function(entry) -- cgit v1.2.3 From 0236ddcd35479936b3bb24f74826f0001eee2828 Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 25 Jan 2013 17:22:08 +0100 Subject: call_url method added --- misc/freeswitch/scripts/common/gateway.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'misc/freeswitch/scripts/common') diff --git a/misc/freeswitch/scripts/common/gateway.lua b/misc/freeswitch/scripts/common/gateway.lua index e50c763..1b3b832 100644 --- a/misc/freeswitch/scripts/common/gateway.lua +++ b/misc/freeswitch/scripts/common/gateway.lua @@ -38,10 +38,14 @@ function Gateway.find_by_id(self, id) local gateway = nil; self.database:query(sql_query, function(entry) + require 'common.str'; gateway = Gateway:new(self); gateway.record = entry; gateway.id = tonumber(entry.id); gateway.name = entry.name; + gateway.technology = entry.technology; + gateway.outbound = common.str.to_b(entry.outbound); + gateway.inbound = common.str.to_b(entry.inbound); end) if gateway then @@ -59,10 +63,14 @@ function Gateway.find_by_name(self, name) local gateway = nil; self.database:query(sql_query, function(entry) + require 'common.str'; gateway = Gateway:new(self); gateway.record = entry; gateway.id = tonumber(entry.id); gateway.name = entry.name; + gateway.technology = entry.technology; + gateway.outbound = common.str.to_b(entry.outbound); + gateway.inbound = common.str.to_b(entry.inbound); end) if gateway then @@ -73,6 +81,15 @@ function Gateway.find_by_name(self, name) end +function Gateway.call_url(self, destination_number) + if self.technology == 'sip' then + return 'sofia/gateway/' .. self.GATEWAY_PREFIX .. self.id .. '/' .. tostring(destination_number); + end + + return ''; +end + + function Gateway.authenticate(self, technology, caller) local sql_query = 'SELECT `c`.`name`, `c`.`id`, `a`.`value` `auth_source`, `b`.`value` `auth_pattern` \ FROM `gateway_settings` `a` \ -- cgit v1.2.3 From 45af07cb093eb0202967cf0d0fc058ca58f0b782 Mon Sep 17 00:00:00 2001 From: spag Date: Sun, 27 Jan 2013 10:17:21 +0100 Subject: added gateway technology --- misc/freeswitch/scripts/common/gateway.lua | 85 ++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 28 deletions(-) (limited to 'misc/freeswitch/scripts/common') diff --git a/misc/freeswitch/scripts/common/gateway.lua b/misc/freeswitch/scripts/common/gateway.lua index 1b3b832..c1b50a7 100644 --- a/misc/freeswitch/scripts/common/gateway.lua +++ b/misc/freeswitch/scripts/common/gateway.lua @@ -84,20 +84,30 @@ end function Gateway.call_url(self, destination_number) if self.technology == 'sip' then return 'sofia/gateway/' .. self.GATEWAY_PREFIX .. self.id .. '/' .. tostring(destination_number); + elseif self.technology == 'xmpp' then + local destination_str = tostring(destination_number); + if self.settings.destination_domain then + destination_str = destination_str .. '@' .. self.settings.destination_domain; + end + return 'dingaling/' .. self.GATEWAY_PREFIX .. self.id .. '/' .. destination_str; end return ''; end -function Gateway.authenticate(self, technology, caller) +function Gateway.authenticate(self, caller, technology) local sql_query = 'SELECT `c`.`name`, `c`.`id`, `a`.`value` `auth_source`, `b`.`value` `auth_pattern` \ FROM `gateway_settings` `a` \ INNER JOIN `gateway_settings` `b` \ ON (`a`.`gateway_id` = `b`.`gateway_id` AND `a`.`name` = "auth_source" AND `b`.`name` = "auth_pattern" ) \ LEFT JOIN `gateways` `c` \ ON (`a`.`gateway_id` = `c`.`id`) \ - WHERE `c`.`inbound` IS TRUE AND `c`.`technology` = "' .. tostring(technology) .. '"'; + WHERE `c`.`inbound` IS TRUE'; + + if technology then + sql_query = sql_query .. ' AND `c`.`technology` = "' .. tostring(technology) .. '"'; + end local gateway = false; @@ -142,39 +152,58 @@ function Gateway.config_table_get(self, config_table, gateway_id) end -function Gateway.parameters_build(self, gateway_id) +function Gateway.parameters_build(self, gateway_id, technology) local settings = self:config_table_get('gateway_settings', gateway_id); - local parameters = { - realm = settings.domain, - extension = 'auto_to_user', - }; require 'common.str' + local parameters = {}; + + if technology == 'sip' then + parameters.realm = settings.domain; + parameters.extension = 'auto_to_user'; + + if common.str.blank(settings.username) then + parameters.username = 'gateway' .. gateway_id; + parameters.register = false; + else + parameters.username = settings.username; + parameters.register = true; + end - if common.str.blank(settings.username) then - parameters.username = 'gateway' .. gateway_id; - parameters.register = false; - else - parameters.username = settings.username; - parameters.register = true; - end - - if not common.str.blank(settings.register) then - parameters.register = common.str.to_b(settings.register); - end + if not common.str.blank(settings.register) then + parameters.register = common.str.to_b(settings.register); + end - if common.str.blank(settings.password) then - parameters.password = 'gateway' .. gateway_id; - else - parameters.password = settings.password; - end + if common.str.blank(settings.password) then + parameters.password = 'gateway' .. gateway_id; + else + parameters.password = settings.password; + end - parameters['extension-in-contact'] = true; + parameters['extension-in-contact'] = true; - if common.str.blank(settings.contact) then - parameters['extension'] = 'gateway' .. gateway_id; - else - parameters['extension'] = settings.contact; + if common.str.blank(settings.contact) then + parameters['extension'] = 'gateway' .. gateway_id; + else + parameters['extension'] = settings.contact; + end + elseif technology == 'xmpp' then + parameters.message = 'Gemeinschaft 5 by AMOOMA'; + parameters.dialplan = 'XML'; + parameters.context = 'default'; + parameters['rtp-ip'] = 'auto'; + parameters['auto-login'] = 'true'; + parameters.sasl = 'plain'; + parameters.tls = 'true'; + parameters['use-rtp-timer'] = 'true'; + parameters.vad = 'both'; + parameters.use_jingle = 'true'; + parameters['candidate-acl'] = 'wan.auto'; + parameters.name = self.GATEWAY_PREFIX .. gateway_id; + parameters.server = settings.server; + parameters.login = settings.login; + parameters.password = settings.password; + parameters.exten = settings.inbound_number or parameters.name; end for key, value in pairs(self:config_table_get('gateway_parameters', gateway_id)) do -- cgit v1.2.3