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
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, [[ </condition>]]);
table.insert(xml, [[ </extension>]]);
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, [[ </condition>]]);
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 ]] .. condition_attribute .. condition_break .. [[/>]]);
condition_attribute = "";
elseif (condition and (string.len(condition) > 0)) then
table.insert(xml, condition .. [[/>]]);
condition = "";
elseif (condition_tag_status ~= "closed") then
table.insert(xml, [[ </condition>]]);
end
condition_tag_status = "closed";
end
end
if (previous_dialplan_uuid ~= dialplan_uuid) then
table.insert(xml, [[ </extension>]]);
dialplan_tag_status = "closed";
end
end
--open the tags
@ -170,6 +174,8 @@
table.insert(xml, [[ <extension name="]] .. dialplan_name .. [[" continue="]] .. dialplan_continue .. [[" uuid="]] .. dialplan_uuid .. [[">]]);
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 ]] .. 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
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>]]);
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 = [[ <condition field="]] .. dialplan_detail_type .. [[" expression="]] .. dialplan_detail_data .. [["]] .. condition_break;
elseif (condition_type == "time") then
if (condition_attribute) then
condition_attribute = condition_attribute .. dialplan_detail_type .. [[="]] .. dialplan_detail_data .. [[" ]];
if (condition_type == "default") then
condition = [[ <condition field="]] .. dialplan_detail_type .. [[" expression="]] .. dialplan_detail_data .. [["]] .. condition_break;
elseif (condition_type == "time") then
if (condition_attribute) then
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
condition_attribute = dialplan_detail_type .. [[="]] .. dialplan_detail_data .. [[" ]];
condition = [[ <condition field="]] .. dialplan_detail_type .. [[" expression="]] .. dialplan_detail_data .. [["]] .. condition_break;
end
condition_expression = "";
condition = ""; --prevents a duplicate time condition
else
condition = [[ <condition field="]] .. dialplan_detail_type .. [[" expression="]] .. dialplan_detail_data .. [["]] .. condition_break;
end
condition_tag_status = "open";
condition_tag_status = "open";
end
if (dialplan_detail_tag == "action" or dialplan_detail_tag == "anti-action") then
if (previous_dialplan_detail_tag == "condition") then
--add the condition ending
if (condition_type == "time") then
condition = [[ <condition ]] .. condition_attribute .. condition_break;
condition_attribute = ""; --prevents the condition attribute from being used on every condition
else
if (previous_dialplan_detail_type) then
condition = [[ <condition field="]] .. previous_dialplan_detail_type .. [[" expression="]] .. previous_dialplan_detail_data .. [["]] .. condition_break;
end
if (condition_tag_status == "open") then
if (condition_attribute and (string.len(condition_attribute) > 0)) then
table.insert(xml, [[ <condition ]] .. condition_attribute .. condition_break .. [[>]]);
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, [[ </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>]]);
end