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 <condition ....> start tag has already been output as XML
      and needs to be closed with a </condition> 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 <extension></extension>.
This commit is contained in:
nostikj 2016-08-25 07:50:54 -07:00 committed by FusionPBX
parent df3822b623
commit 72f2dbab31
1 changed files with 66 additions and 57 deletions

View File

@ -83,9 +83,6 @@
--set defaults --set defaults
previous_dialplan_uuid = ""; previous_dialplan_uuid = "";
previous_dialplan_detail_group = ""; previous_dialplan_detail_group = "";
previous_dialplan_detail_tag = "";
previous_dialplan_detail_type = "";
previous_dialplan_detail_data = "";
dialplan_tag_status = "closed"; dialplan_tag_status = "closed";
condition_tag_status = "closed"; condition_tag_status = "closed";
@ -151,18 +148,25 @@
end end
--close the tags --close the tags
if (condition_tag_status ~= "closed") then if (dialplan_tag_status ~= "closed") then
if (previous_dialplan_uuid ~= dialplan_uuid) then if ((previous_dialplan_uuid ~= dialplan_uuid) or (previous_dialplan_detail_group ~= dialplan_detail_group)) then
table.insert(xml, [[ </condition>]]); if (condition_tag_status ~= "closed") then
table.insert(xml, [[ </extension>]]); if (condition_attribute and (string.len(condition_attribute) > 0)) then
dialplan_tag_status = "closed"; table.insert(xml, [[ <condition ]] .. condition_attribute .. condition_break .. [[/>]]);
condition_tag_status = "closed"; condition_attribute = "";
else elseif (condition and (string.len(condition) > 0)) then
if (previous_dialplan_detail_group ~= dialplan_detail_group and previous_dialplan_detail_tag == "condition") then table.insert(xml, condition .. [[/>]]);
table.insert(xml, [[ </condition>]]); condition = "";
elseif (condition_tag_status ~= "closed") then
table.insert(xml, [[ </condition>]]);
end
condition_tag_status = "closed"; condition_tag_status = "closed";
end end
end end
if (previous_dialplan_uuid ~= dialplan_uuid) then
table.insert(xml, [[ </extension>]]);
dialplan_tag_status = "closed";
end
end end
--open the tags --open the tags
@ -170,6 +174,8 @@
table.insert(xml, [[ <extension name="]] .. dialplan_name .. [[" continue="]] .. dialplan_continue .. [[" uuid="]] .. dialplan_uuid .. [[">]]); table.insert(xml, [[ <extension name="]] .. dialplan_name .. [[" continue="]] .. dialplan_continue .. [[" uuid="]] .. dialplan_uuid .. [[">]]);
dialplan_tag_status = "open"; dialplan_tag_status = "open";
first_action = true; first_action = true;
condition = "";
condition_attribute = "";
end end
if (dialplan_detail_tag == "condition") then if (dialplan_detail_tag == "condition") then
--determine the type of condition --determine the type of condition
@ -201,6 +207,27 @@
condition_type = 'default'; condition_type = 'default';
end 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 ]] .. condition_attribute .. condition_break .. [[/>]]);
condition_attribute = '';
condition_tag_status = "closed";
end
else
table.insert(xml, [[ </condition>]]);
condition_tag_status = "closed";
end
end
--get the condition break attribute --get the condition break attribute
condition_break = ""; condition_break = "";
if (dialplan_detail_break) then if (dialplan_detail_break) then
@ -209,53 +236,30 @@
end end
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>]]);
condition_tag_status = "closed";
condition_type = "";
condition_attribute = "";
condition_expression = "";
end
end
--condition tag but leave off the ending --condition tag but leave off the ending
if (condition_type == "default") then if (condition_type == "default") then
condition = [[ <condition field="]] .. dialplan_detail_type .. [[" expression="]] .. dialplan_detail_data .. [["]] .. condition_break; condition = [[ <condition field="]] .. dialplan_detail_type .. [[" expression="]] .. dialplan_detail_data .. [["]] .. condition_break;
elseif (condition_type == "time") then elseif (condition_type == "time") then
if (condition_attribute) then if (condition_attribute) then
condition_attribute = condition_attribute .. dialplan_detail_type .. [[="]] .. dialplan_detail_data .. [[" ]]; condition_attribute = condition_attribute .. dialplan_detail_type .. [[="]] .. dialplan_detail_data .. [[" ]];
else
condition_attribute = dialplan_detail_type .. [[="]] .. dialplan_detail_data .. [[" ]];
end
condition = ""; --prevents a duplicate time condition
else else
condition_attribute = dialplan_detail_type .. [[="]] .. dialplan_detail_data .. [[" ]]; condition = [[ <condition field="]] .. dialplan_detail_type .. [[" expression="]] .. dialplan_detail_data .. [["]] .. condition_break;
end end
condition_expression = ""; condition_tag_status = "open";
condition = ""; --prevents a duplicate time condition
else
condition = [[ <condition field="]] .. dialplan_detail_type .. [[" expression="]] .. dialplan_detail_data .. [["]] .. condition_break;
end
condition_tag_status = "open";
end end
if (dialplan_detail_tag == "action" or dialplan_detail_tag == "anti-action") then if (dialplan_detail_tag == "action" or dialplan_detail_tag == "anti-action") then
if (previous_dialplan_detail_tag == "condition") then if (condition_tag_status == "open") then
--add the condition ending if (condition_attribute and (string.len(condition_attribute) > 0)) then
if (condition_type == "time") then table.insert(xml, [[ <condition ]] .. condition_attribute .. condition_break .. [[>]]);
condition = [[ <condition ]] .. condition_attribute .. condition_break; condition_attribute = "";
condition_attribute = ""; --prevents the condition attribute from being used on every condition elseif (condition and (string.len(condition) > 0)) then
else table.insert(xml, condition .. [[>]]);
if (previous_dialplan_detail_type) then condition = "";
condition = [[ <condition field="]] .. previous_dialplan_detail_type .. [[" expression="]] .. previous_dialplan_detail_data .. [["]] .. condition_break;
end
end end
table.insert(xml, condition .. [[>]]);
condition = ""; --prevents duplicate time conditions
end end
end end
@ -285,9 +289,6 @@
--save the previous values --save the previous values
previous_dialplan_uuid = dialplan_uuid; previous_dialplan_uuid = dialplan_uuid;
previous_dialplan_detail_group = dialplan_detail_group; 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 --increment the x
x = x + 1; x = x + 1;
@ -315,7 +316,15 @@
--close the extension tag if it was left open --close the extension tag if it was left open
if (dialplan_tag_status == "open") then if (dialplan_tag_status == "open") then
table.insert(xml, [[ </condition>]]); if (condition_tag_status == "open") then
if (condition_attribute and (string.len(condition_attribute) > 0)) then
table.insert(xml, [[ <condition ]] .. condition_attribute .. condition_break .. [[/>]]);
elseif (condition and (string.len(condition) > 0)) then
table.insert(xml, condition .. [[/>]]);
else
table.insert(xml, [[ </condition>]]);
end
end
table.insert(xml, [[ </extension>]]); table.insert(xml, [[ </extension>]]);
end end