summaryrefslogtreecommitdiff
path: root/misc/freeswitch/scripts/common
diff options
context:
space:
mode:
Diffstat (limited to 'misc/freeswitch/scripts/common')
-rw-r--r--misc/freeswitch/scripts/common/gateway.lua102
-rw-r--r--misc/freeswitch/scripts/common/str.lua4
2 files changed, 78 insertions, 28 deletions
diff --git a/misc/freeswitch/scripts/common/gateway.lua b/misc/freeswitch/scripts/common/gateway.lua
index e50c763..c1b50a7 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,14 +81,33 @@ function Gateway.find_by_name(self, name)
end
-function Gateway.authenticate(self, technology, caller)
+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, 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;
@@ -125,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
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)