diff --git a/resources/install/scripts/app/xml_handler/resources/scripts/dialplan/dialplan.lua b/resources/install/scripts/app/xml_handler/resources/scripts/dialplan/dialplan.lua index 582e763aeb..898aecb7ac 100644 --- a/resources/install/scripts/app/xml_handler/resources/scripts/dialplan/dialplan.lua +++ b/resources/install/scripts/app/xml_handler/resources/scripts/dialplan/dialplan.lua @@ -53,26 +53,6 @@ --exits the script if we didn't connect properly assert(dbh:connected()); - --get the domains - x = 1; - domains = {} - sql = "SELECT * FROM v_domains;"; - dbh:query(sql, function(row) - --add items to the domains array - domains[row["domain_name"]] = row["domain_uuid"]; - domains[row["domain_uuid"]] = row["domain_name"]; - --increment x - x = x + 1; - end); - - --get the domain_uuid - if (domain_uuid == nil) then - --get the domain_uuid - if (domain_name ~= nil) then - domain_uuid = domains[domain_name]; - end - end - --set the xml array and then concatenate the array to a string local xml = {} table.insert(xml, [[]]); @@ -80,253 +60,25 @@ table.insert(xml, [[
]]); table.insert(xml, [[ ]]); - --set defaults - previous_dialplan_uuid = ""; - previous_dialplan_detail_group = ""; - dialplan_tag_status = "closed"; - condition_tag_status = "closed"; - - --get the dialplan and related details - sql = "select * from v_dialplans as p, v_dialplan_details as s "; + --get the dialplan xml + sql = "select dialplan_xml from v_dialplans as p "; if (call_context == "public" or string.sub(call_context, 0, 7) == "public@" or string.sub(call_context, -7) == ".public") then sql = sql .. "where p.dialplan_context = '" .. call_context .. "' "; else sql = sql .. "where (p.dialplan_context = '" .. call_context .. "' or p.dialplan_context = '${domain_name}') "; end sql = sql .. "and p.dialplan_enabled = 'true' "; - sql = sql .. "and p.dialplan_uuid = s.dialplan_uuid "; sql = sql .. "order by "; - sql = sql .. "p.dialplan_order asc, "; - sql = sql .. "p.dialplan_name asc, "; - sql = sql .. "p.dialplan_uuid asc, "; - sql = sql .. "s.dialplan_detail_group asc, "; - sql = sql .. "CASE s.dialplan_detail_tag "; - sql = sql .. "WHEN 'condition' THEN 1 "; - sql = sql .. "WHEN 'action' THEN 2 "; - sql = sql .. "WHEN 'anti-action' THEN 3 "; - sql = sql .. "ELSE 100 END, "; - sql = sql .. "s.dialplan_detail_order asc "; + sql = sql .. "p.dialplan_order asc "; if (debug["sql"]) then log.notice("SQL: " .. sql); end local x = 0; local pass dbh:query(sql, function(row) - --clear flag pass - pass = false - - --get the dialplan - domain_uuid = row.domain_uuid; - dialplan_uuid = row.dialplan_uuid; - --app_uuid = row.app_uuid; - --dialplan_context = row.dialplan_context; - dialplan_name = row.dialplan_name; - --dialplan_number = row.dialplan_number; - dialplan_continue = row.dialplan_continue; - --dialplan_order = row.dialplan_order; - --dialplan_enabled = row.dialplan_enabled; - --dialplan_description = row.dialplan_description; - --get the dialplan details - --dialplan_detail_uuid = row.dialplan_detail_uuid; - dialplan_detail_tag = row.dialplan_detail_tag; - dialplan_detail_type = row.dialplan_detail_type; - dialplan_detail_data = row.dialplan_detail_data; - dialplan_detail_break = row.dialplan_detail_break; - dialplan_detail_inline = row.dialplan_detail_inline; - dialplan_detail_group = row.dialplan_detail_group; - --dialplan_detail_order = row.dialplan_detail_order; - - --remove $$ and replace with $ - dialplan_detail_data = dialplan_detail_data:gsub("%$%$", "$"); - - --get the dialplan detail inline - detail_inline = ""; - if (dialplan_detail_inline) then - if (string.len(dialplan_detail_inline) > 0) then - detail_inline = [[ inline="]] .. dialplan_detail_inline .. [["]]; - end - end - - --close the tags - if (dialplan_tag_status ~= "closed") then - if ((previous_dialplan_uuid ~= dialplan_uuid) or (previous_dialplan_detail_group ~= dialplan_detail_group)) then - if (condition_tag_status ~= "closed") then - if (condition_attribute and (string.len(condition_attribute) > 0)) then - table.insert(xml, [[ ]]); - condition_attribute = ""; - elseif (condition and (string.len(condition) > 0)) then - table.insert(xml, condition .. [[/>]]); - condition = ""; - elseif (condition_tag_status ~= "closed") then - table.insert(xml, [[ ]]); - end - condition_tag_status = "closed"; - end - end - if (previous_dialplan_uuid ~= dialplan_uuid) then - table.insert(xml, [[ ]]); - dialplan_tag_status = "closed"; - end - end - - --open the tags - if (dialplan_tag_status == "closed") then - table.insert(xml, [[ ]]); - dialplan_tag_status = "open"; - first_action = true; - condition = ""; - condition_attribute = ""; - end - if (dialplan_detail_tag == "condition") then - --determine the type of condition - if (dialplan_detail_type == "hour") then - condition_type = 'time'; - elseif (dialplan_detail_type == "minute") then - condition_type = 'time'; - elseif (dialplan_detail_type == "minute-of-day") then - condition_type = 'time'; - elseif (dialplan_detail_type == "mday") then - condition_type = 'time'; - elseif (dialplan_detail_type == "mweek") then - condition_type = 'time'; - elseif (dialplan_detail_type == "mon") then - condition_type = 'time'; - elseif (dialplan_detail_type == "time-of-day") then - condition_type = 'time'; - elseif (dialplan_detail_type == "yday") then - condition_type = 'time'; - elseif (dialplan_detail_type == "year") then - condition_type = 'time'; - elseif (dialplan_detail_type == "wday") then - condition_type = 'time'; - elseif (dialplan_detail_type == "week") then - condition_type = 'time'; - elseif (dialplan_detail_type == "date-time") then - condition_type = 'time'; - else - condition_type = 'default'; - end - - -- finalize any previous pending condition statements - if (condition_tag_status == "open") then - if (condition and (string.len(condition) > 0)) then - table.insert(xml, condition .. [[/>]]); - condition = ''; - condition_tag_status = "closed"; - elseif (condition_attribute and (string.len(condition_attribute) > 0)) then - -- previous condition(s) must have been of type time - -- do not finalize if new condition is also of type time - if (condition_type ~= 'time') then - -- note: condition_break here is value from the previous loop - table.insert(xml, [[ ]]); - condition_attribute = ''; - condition_tag_status = "closed"; - end - else - table.insert(xml, [[ ]]); - condition_tag_status = "closed"; - end - end - - --get the condition break attribute - condition_break = ""; - if (dialplan_detail_break) then - if (string.len(dialplan_detail_break) > 0) then - condition_break = [[ break="]] .. dialplan_detail_break .. [["]]; - end - end - - --condition tag but leave off the ending - if (condition_type == "default") then - condition = [[ 0)) then - table.insert(xml, [[ ]]); - condition_attribute = ""; - elseif (condition and (string.len(condition) > 0)) then - table.insert(xml, condition .. [[>]]); - condition = ""; - end - end - end - - if (call_context == "public" or string.sub(call_context, 0, 7) == "public@" or string.sub(call_context, -7) == ".public") then - if (dialplan_detail_tag == "action") then - if (first_action) then - table.insert(xml, [[ ]]); - if (domain_uuid ~= nil and domain_uuid ~= '') then - domain_name = domains[domain_uuid]; - table.insert(xml, [[ ]]); - end - if (domain_name ~= nil and domain_name ~= '') then - table.insert(xml, [[ ]]); - end - first_action = false; - end - end - end - if (dialplan_detail_tag == "action") then - table.insert(xml, [[ ]]); - end - if (dialplan_detail_tag == "anti-action") then - table.insert(xml, [[ ]]); - end - - --save the previous values - previous_dialplan_uuid = dialplan_uuid; - previous_dialplan_detail_group = dialplan_detail_group; - - --increment the x - x = x + 1; - - --set flag pass - pass = true + table.insert(xml, row.dialplan_xml); end); - -- prevent partial dialplan (pass=nil may be error in sql or empty resultset) - if pass == false then - --send a message to the log - log.errf('context: %s, extension: %s, type: %s, data: %s ', - call_context, - dialplan_name or '----', - dialplan_detail_tag or '----', - dialplan_detail_data or '----' - ) - - --close the database connection - dbh:release(); - - --show an error - error('error while build context: ' .. call_context) - end - - --close the extension tag if it was left open - if (dialplan_tag_status == "open") then - if (condition_tag_status == "open") then - if (condition_attribute and (string.len(condition_attribute) > 0)) then - table.insert(xml, [[ ]]); - elseif (condition and (string.len(condition) > 0)) then - table.insert(xml, condition .. [[/>]]); - else - table.insert(xml, [[ ]]); - end - end - table.insert(xml, [[ ]]); - end - --set the xml array and then concatenate the array to a string table.insert(xml, [[ ]]); table.insert(xml, [[
]]);