From 6a838ff77d6ddc8139a8dfe9d80455032da8d961 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 13 Mar 2013 11:54:48 -0400 Subject: routing test utility --- misc/freeswitch/scripts/test_route.lua | 58 ++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 misc/freeswitch/scripts/test_route.lua (limited to 'misc/freeswitch/scripts/test_route.lua') 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 -- cgit v1.2.3 From 1ea544f5d29d3bc43bf1d7ddfd1f7692f5cbcdda Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 13 Mar 2013 13:42:49 -0400 Subject: retrieve destination and caller_id_numbers --- misc/freeswitch/scripts/test_route.lua | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'misc/freeswitch/scripts/test_route.lua') diff --git a/misc/freeswitch/scripts/test_route.lua b/misc/freeswitch/scripts/test_route.lua index 4ff10b5..9ab00f7 100644 --- a/misc/freeswitch/scripts/test_route.lua +++ b/misc/freeswitch/scripts/test_route.lua @@ -22,9 +22,10 @@ function caller.to_s(variable) return common.str.to_s(arguments[variable]) end +local log_buffer = {}; -- initialize logging require 'common.log'; -log = common.log.Log:new{ disabled = true }; +log = common.log.Log:new{ buffer = log_buffer, prefix = '' }; -- connect to database require 'common.database'; @@ -42,12 +43,35 @@ caller.dialplan = dialplan_object; caller.local_node_id = dialplan_object.node_id; dialplan_object:retrieve_caller_data(); +local destination = arguments.destination or dialplan_object:destination_new{ number = caller.destination_number }; +local routes = {}; -require 'dialplan.router'; -local routes = dialplan.router.Router:new{ log = log, database = database, caller = caller, variables = caller }:route_run(arguments.table or 'outbound'); +if destination.type == 'unknown' then + local clip_no_screening = common.array.try(caller, 'account.record.clip_no_screening'); + caller.caller_id_numbers = {} + if not common.str.blank(clip_no_screening) then + for index, number in ipairs(common.str.strip_to_a(clip_no_screening, ',')) do + table.insert(caller.caller_id_numbers, number); + end + end + if caller.caller_phone_numbers then + for index, number in ipairs(caller.caller_phone_numbers) do + table.insert(caller.caller_id_numbers, number); + end + end + log:info('CALLER_ID_NUMBERS - clir: ', caller.clir, ', numbers: ', table.concat(caller.caller_id_numbers, ',')); + + destination.callee_id_number = destination.number; + destination.callee_id_name = nil; + + require 'dialplan.router'; + routes = dialplan.router.Router:new{ log = log, database = database, caller = caller, variables = caller, log_details = true }:route_run(arguments.table or 'outbound'); +end local result = { - routes = routes + routes = routes, + destination = destination, + log = log_buffer } stream:write(common.array.to_json(result)); -- cgit v1.2.3 From 25a4d0a3e1237f2ef4093149c2a0ca3c3c72378e Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 13 Mar 2013 15:41:42 -0400 Subject: run router --- misc/freeswitch/scripts/test_route.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'misc/freeswitch/scripts/test_route.lua') diff --git a/misc/freeswitch/scripts/test_route.lua b/misc/freeswitch/scripts/test_route.lua index 9ab00f7..e311690 100644 --- a/misc/freeswitch/scripts/test_route.lua +++ b/misc/freeswitch/scripts/test_route.lua @@ -46,7 +46,7 @@ dialplan_object:retrieve_caller_data(); local destination = arguments.destination or dialplan_object:destination_new{ number = caller.destination_number }; local routes = {}; -if destination.type == 'unknown' then +if destination and destination.type == 'unknown' then local clip_no_screening = common.array.try(caller, 'account.record.clip_no_screening'); caller.caller_id_numbers = {} if not common.str.blank(clip_no_screening) then @@ -63,11 +63,11 @@ if destination.type == 'unknown' then destination.callee_id_number = destination.number; destination.callee_id_name = nil; - - require 'dialplan.router'; - routes = dialplan.router.Router:new{ log = log, database = database, caller = caller, variables = caller, log_details = true }:route_run(arguments.table or 'outbound'); end +require 'dialplan.router'; +routes = dialplan.router.Router:new{ log = log, database = database, caller = caller, variables = caller, log_details = true }:route_run(arguments.table or 'outbound'); + local result = { routes = routes, destination = destination, -- cgit v1.2.3 From 05619cea39af74cb538598c598abf4427319de5f Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 14 Mar 2013 05:16:25 -0400 Subject: save destination in caller table --- misc/freeswitch/scripts/test_route.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'misc/freeswitch/scripts/test_route.lua') diff --git a/misc/freeswitch/scripts/test_route.lua b/misc/freeswitch/scripts/test_route.lua index e311690..98dfda9 100644 --- a/misc/freeswitch/scripts/test_route.lua +++ b/misc/freeswitch/scripts/test_route.lua @@ -65,6 +65,8 @@ if destination and destination.type == 'unknown' then destination.callee_id_name = nil; end +caller.destination = destination; + require 'dialplan.router'; routes = dialplan.router.Router:new{ log = log, database = database, caller = caller, variables = caller, log_details = true }:route_run(arguments.table or 'outbound'); -- cgit v1.2.3