summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Kozak <spag@golwen.net>2013-03-13 11:54:48 -0400
committerPeter Kozak <spag@golwen.net>2013-03-13 11:54:48 -0400
commit6a838ff77d6ddc8139a8dfe9d80455032da8d961 (patch)
tree972076eeae33b7143fb0b702ac42bbe504d44076
parentf3842463e70d5d5bb557f887c62c68509a523825 (diff)
routing test utility
-rw-r--r--misc/freeswitch/scripts/test_route.lua58
1 files changed, 58 insertions, 0 deletions
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