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