Ensure the phrases_dir is not nil.

This commit is contained in:
markjcrane 2016-03-04 15:08:58 -07:00
parent b4b86b0478
commit 7cbb32dcd3
1 changed files with 22 additions and 16 deletions

View File

@ -34,6 +34,14 @@
--action = params:getHeader("action"); --action = params:getHeader("action");
language = params:getHeader("lang"); language = params:getHeader("lang");
--make sure phrase_dir variable is not nil
if (phrases_dir == nil) then
--define the variable
phrases_dir = '';
--include the config.lua and local.lua
require "resources.functions.config";
end
--additional information --additional information
--event_calling_function = params:getHeader("Event-Calling-Function"); --event_calling_function = params:getHeader("Event-Calling-Function");
@ -143,21 +151,19 @@
end end
--read root xml language file, parse included xml files --read root xml language file, parse included xml files
if (phrases_dir ~= nil) then local xml_file_paths = {}
local xml_file_paths = {} local file_handle = io.open(phrases_dir.."/"..language.."/"..language..".xml", "r");
local file_handle = io.open(phrases_dir.."/"..language.."/"..language..".xml", "r"); if (file_handle ~= nil) then
if (file_handle ~= nil) then for file_line in file_handle:lines() do
for file_line in file_handle:lines() do if (string.find(file_line, 'cmd="include" data="', 0, true) ~= nil) then
if (string.find(file_line, 'cmd="include" data="', 0, true) ~= nil) then pos_beg = string.find(file_line, 'cmd="include" data="', 0, true) + 20;
pos_beg = string.find(file_line, 'cmd="include" data="', 0, true) + 20; pos_end = string.find(file_line, '"/>', 0, true) - 1;
pos_end = string.find(file_line, '"/>', 0, true) - 1; xml_file_path = string.sub(file_line, pos_beg, pos_end);
xml_file_path = string.sub(file_line, pos_beg, pos_end); table.insert(xml_file_paths, phrases_dir.."/"..language.."/"..xml_file_path);
table.insert(xml_file_paths, phrases_dir.."/"..language.."/"..xml_file_path); --freeswitch.consoleLog("notice", "file path = "..xml_file_path.."\n");
--freeswitch.consoleLog("notice", "file path = "..xml_file_path.."\n");
end
end end
file_handle:close();
end end
file_handle:close();
end end
--iterate array of file paths, get contents of other xml macro files --iterate array of file paths, get contents of other xml macro files