From 7cbb32dcd3a3c62a64c693d2d38eb2cbfaa0b405 Mon Sep 17 00:00:00 2001 From: markjcrane Date: Fri, 4 Mar 2016 15:08:58 -0700 Subject: [PATCH] Ensure the phrases_dir is not nil. --- .../resources/scripts/languages/languages.lua | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/languages/languages.lua b/resources/install/scripts/app/xml_handler/resources/scripts/languages/languages.lua index 7316da0eb3..eb618a0eca 100644 --- a/resources/install/scripts/app/xml_handler/resources/scripts/languages/languages.lua +++ b/resources/install/scripts/app/xml_handler/resources/scripts/languages/languages.lua @@ -34,6 +34,14 @@ --action = params:getHeader("action"); 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 --event_calling_function = params:getHeader("Event-Calling-Function"); @@ -116,7 +124,7 @@ match_tag = "open"; x = 0; dbh:query(sql, function(row) - --phrase_uuid,domain_uuid,phrase_name,phrase_language + --phrase_uuid,domain_uuid,phrase_name,phrase_language --phrase_description,phrase_enabled,phrase_detail_uuid --phrase_detail_group,phrase_detail_tag,phrase_detail_pattern --phrase_detail_function,phrase_detail_data,phrase_detail_method @@ -141,23 +149,21 @@ table.insert(xml, [[ ]]); table.insert(xml, [[ ]]); end - + --read root xml language file, parse included xml files - if (phrases_dir ~= nil) then - local xml_file_paths = {} - local file_handle = io.open(phrases_dir.."/"..language.."/"..language..".xml", "r"); - if (file_handle ~= nil) then - for file_line in file_handle:lines() do - 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_end = string.find(file_line, '"/>', 0, true) - 1; - xml_file_path = string.sub(file_line, pos_beg, pos_end); - table.insert(xml_file_paths, phrases_dir.."/"..language.."/"..xml_file_path); - --freeswitch.consoleLog("notice", "file path = "..xml_file_path.."\n"); - end + local xml_file_paths = {} + local file_handle = io.open(phrases_dir.."/"..language.."/"..language..".xml", "r"); + if (file_handle ~= nil) then + for file_line in file_handle:lines() do + 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_end = string.find(file_line, '"/>', 0, true) - 1; + xml_file_path = string.sub(file_line, pos_beg, pos_end); + table.insert(xml_file_paths, phrases_dir.."/"..language.."/"..xml_file_path); + --freeswitch.consoleLog("notice", "file path = "..xml_file_path.."\n"); end - file_handle:close(); end + file_handle:close(); end --iterate array of file paths, get contents of other xml macro files @@ -174,7 +180,7 @@ xml_file:close(); end end - + --output xml & close previous file table.insert(xml, [[ ]]); table.insert(xml, [[ ]]);