From 72f2dbab3121cd6c34fc25e55336c482f9bddaa5 Mon Sep 17 00:00:00 2001 From: nostikj Date: Thu, 25 Aug 2016 07:50:54 -0700 Subject: [PATCH] Corrects some cases where dialplan conditions were not fully handled (#1850) * Remove unsed variable * Fix cases where time condition are lost When processing a new condition statement and condition_tag_status == "open", then there has been a previous condition statement that is in one of three possible states: (1) a previous condition of type default has been saved into the 'condition' string and will need to be output as XML with either '>' or '/>' (2) one or more time conditions have been saved into the 'condition_attribute' string. More time conditions may be added. After the last time condition it will need to be output as XML with either '>' or '/>' (3) a previous start tag has already been output as XML and needs to be closed with a statement. The change here checks for all three above situations at the places where pending condition statements need to be finalized. Note that when processing condition new statements and we are finalizing a previous time condition, the XML statement uses the 'condition_break' value from the previous loop, therefore setting condition_break for the new condition must be after previous conditions are finalized. At the start of each new extension, initialize 'condition' and 'condition_attribute'. * Remove unused variables * Indent one block to match surrounding code at same level * Prevent two dialplans uuids being merged into single extension If a dialplan manager entry ended with an action statement NOT inside a condition, the generated XML would combine this dialplan uuid with the next uuid by not closing and reopening a new extension. This change ensures each dialplan uuid is enclosed in it own . --- .../resources/scripts/dialplan/dialplan.lua | 123 ++++++++++-------- 1 file changed, 66 insertions(+), 57 deletions(-) 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 2aacabf627..ec8fa62f18 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 @@ -83,9 +83,6 @@ --set defaults previous_dialplan_uuid = ""; previous_dialplan_detail_group = ""; - previous_dialplan_detail_tag = ""; - previous_dialplan_detail_type = ""; - previous_dialplan_detail_data = ""; dialplan_tag_status = "closed"; condition_tag_status = "closed"; @@ -151,18 +148,25 @@ end --close the tags - if (condition_tag_status ~= "closed") then - if (previous_dialplan_uuid ~= dialplan_uuid) then - table.insert(xml, [[ ]]); - table.insert(xml, [[ ]]); - dialplan_tag_status = "closed"; - condition_tag_status = "closed"; - else - if (previous_dialplan_detail_group ~= dialplan_detail_group and previous_dialplan_detail_tag == "condition") then - table.insert(xml, [[ ]]); + 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 @@ -170,6 +174,8 @@ 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 @@ -201,6 +207,27 @@ 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 @@ -209,53 +236,30 @@ end end - if (condition_tag_status == "open") then - if (previous_dialplan_detail_tag == "condition") then - --add the condition self closing tag - if (condition) then - if (string.len(condition) > 0) then - table.insert(xml, condition .. [[/>]]); - end - end - end - if (previous_dialplan_detail_tag == "action" or previous_dialplan_detail_tag == "anti-action") then - table.insert(xml, [[ ]]); - condition_tag_status = "closed"; - condition_type = ""; - condition_attribute = ""; - condition_expression = ""; - 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 - table.insert(xml, condition .. [[>]]); - condition = ""; --prevents duplicate time conditions end end @@ -285,9 +289,6 @@ --save the previous values previous_dialplan_uuid = dialplan_uuid; previous_dialplan_detail_group = dialplan_detail_group; - previous_dialplan_detail_tag = dialplan_detail_tag; - previous_dialplan_detail_type = dialplan_detail_type; - previous_dialplan_detail_data = dialplan_detail_data; --increment the x x = x + 1; @@ -315,7 +316,15 @@ --close the extension tag if it was left open if (dialplan_tag_status == "open") then - table.insert(xml, [[ ]]); + 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