summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/call_route.rb16
-rw-r--r--misc/freeswitch/scripts/common/log.lua4
-rw-r--r--misc/freeswitch/scripts/dialplan/router.lua1
-rw-r--r--misc/freeswitch/scripts/test_route.lua58
4 files changed, 79 insertions, 0 deletions
diff --git a/app/models/call_route.rb b/app/models/call_route.rb
index 6c54549..590d49b 100644
--- a/app/models/call_route.rb
+++ b/app/models/call_route.rb
@@ -253,4 +253,20 @@ class CallRoute < ActiveRecord::Base
end
end
+
+ def self.test_route(table, caller)
+ arguments = ["'#{table}' table"]
+ caller.each do |key, value|
+ arguments << "'#{value}' '#{key}'"
+ end
+
+ require 'freeswitch_event'
+ result = FreeswitchAPI.api_result(FreeswitchAPI.api('lua', 'test_route.lua', arguments.join(' ')))
+ if result.blank? then
+ return
+ end
+
+ return JSON.parse(result)
+ end
+
end
diff --git a/misc/freeswitch/scripts/common/log.lua b/misc/freeswitch/scripts/common/log.lua
index b7c8d09..e6aa7fa 100644
--- a/misc/freeswitch/scripts/common/log.lua
+++ b/misc/freeswitch/scripts/common/log.lua
@@ -12,6 +12,7 @@ function Log.new(self, arg)
object = arg.object or {}
setmetatable(object, self);
self.__index = self;
+ self.disabled = arg.disabled or false;
self.prefix = arg.prefix or '### ';
self.level_console = arg.level_console or 0;
@@ -27,6 +28,9 @@ function Log.new(self, arg)
end
function Log.message(self, log_level, message_arguments )
+ if self.disabled then
+ return
+ end
local message = tostring(self.prefix);
for index, value in pairs(message_arguments) do
if type(index) == 'number' then
diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua
index 277958a..2d82f91 100644
--- a/misc/freeswitch/scripts/dialplan/router.lua
+++ b/misc/freeswitch/scripts/dialplan/router.lua
@@ -98,6 +98,7 @@ function Router.route_match(self, route)
id = route.endpoint_id,
destination_number = common.array.try(self, 'caller.destination_number'),
channel_variables = {},
+ route_id = route.id,
};
local route_matches = false;
diff --git a/misc/freeswitch/scripts/test_route.lua b/misc/freeswitch/scripts/test_route.lua
new file mode 100644
index 0000000..4ff10b5
--- /dev/null
+++ b/misc/freeswitch/scripts/test_route.lua
@@ -0,0 +1,58 @@
+-- Gemeinschaft 5 routing test module
+-- (c) AMOOMA GmbH 2013
+--
+
+require 'common.array';
+
+local arguments = {};
+local value = nil;
+
+for index=1, #argv do
+ if math.mod(index, 2) == 0 then
+ common.array.set(arguments, argv[index], value);
+ else
+ value = argv[index];
+ end
+end
+
+local caller = arguments.caller or {};
+local channel_variables = arguments.chv or {};
+
+function caller.to_s(variable)
+ return common.str.to_s(arguments[variable])
+end
+
+-- initialize logging
+require 'common.log';
+log = common.log.Log:new{ disabled = true };
+
+-- connect to database
+require 'common.database';
+local database = common.database.Database:new{ log = log }:connect();
+if not database:connected() then
+ log:critical('TEST_ROUTE - database connection failed');
+ return;
+end
+
+-- dialplan object
+require 'dialplan.dialplan'
+local dialplan_object = dialplan.dialplan.Dialplan:new{ log = log, caller = caller, database = database };
+dialplan_object:configuration_read();
+caller.dialplan = dialplan_object;
+caller.local_node_id = dialplan_object.node_id;
+
+dialplan_object:retrieve_caller_data();
+
+require 'dialplan.router';
+local routes = dialplan.router.Router:new{ log = log, database = database, caller = caller, variables = caller }:route_run(arguments.table or 'outbound');
+
+local result = {
+ routes = routes
+}
+
+stream:write(common.array.to_json(result));
+
+-- release database handle
+if database then
+ database:release();
+end