A Big thanks from me as well for the easiest and simplest explanation. :)<div><br></div><div><div><br><div class="gmail_quote">On Wed, Jan 18, 2012 at 2:45 PM, Herman Griffin <span dir="ltr"><<a href="mailto:herman.griffin@gmail.com">herman.griffin@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello Michael,<br>
<br>
That response was prefect. I get it know! Thanks for taking the time to respond.<br>
<span class="HOEnZb"><font color="#888888"><br>
Herman<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Mon, Jan 16, 2012 at 4:29 PM, Michael Collins <<a href="mailto:msc@freeswitch.org">msc@freeswitch.org</a>> wrote:<br>
> Hi Herman,<br>
><br>
> These are common questions when dealing with the dialplan. I highly<br>
> recommend that you acquire the FreeSWITCH "bridge book" (see link near top<br>
> of <a href="http://wiki.freeswitch.org" target="_blank">wiki.freeswitch.org</a>) and read chapters 5 and 8. (Full disclosure: I wrote<br>
> chapter 5 and Darren Schreiber wrote chapter 8.) Both of these chapters<br>
> cover the break attribute in detail. I think you might be confusing the<br>
> purpose of the break attribute.<br>
><br>
> Consider this dp fragment:<br>
> <extension name="test"><br>
> <condition field="foo" expression="bar"/><br>
> <condition field="foo2" expression="bar2"><br>
> <!-- actions here get added to task list only if both conditions are<br>
> true --><br>
> <!-- anti-actions here get added to task list only if foo is true and<br>
> foo2 is false --><br>
> </condition><br>
> </extension><br>
><br>
> When the dialplan parser gets to this extension, the first thing it does is<br>
> test the "foo" field. If the test fails then the parser does not even look<br>
> at the rest of this extension. Why not? Because all conditions have an<br>
> implied break="on-false". The following two conditions are identical in<br>
> function:<br>
> <condition field="foo" expression="bar"/><br>
> <condition field="foo" expression="bar" break="on-false/><br>
><br>
> So, if you want a set of actions to be included only if more than one<br>
> condition is met then "stacking" will work, however you cannot do<br>
> break="never". Why not? Because break="never" tells the dialplan parser,<br>
> "Hey, even if this condition fails, go ahead and evaluate the next condition<br>
> in this extension." If you have break="on-false" (or no 'break' attribute at<br>
> all) then that tells the dialplan parser, "Hey, if this condition fails then<br>
> 'break out' of this extension and continue parsing the dialplan."<br>
><br>
> Using what we've just discussed, let's look at the example you cited in your<br>
> second post.<br>
> Dialplan extension "emergency_set_variables":<br>
><br>
><br>
> <condition field="${caller_id_name}" expression="^Emerg_" break="never"><br>
> <action application="set" data="emergency_call=true" inline="true"/><br>
> </condition><br>
><br>
> <condition wday="2-6" time-of-day="22:00-23:59" break="never"><br>
> <action application="set" data="open=true" inline="true"/><br>
> </condition><br>
><br>
> <condition wday="1,7" time-of-day="05:00-23:59" break="never"><br>
> <action application="set" data="open=true" inline="true"/><br>
> </condition><br>
><br>
> The dialplan parser logged this:<br>
><br>
><br>
> Dialplan: sofia/external/<a href="mailto:Unknown@72.37.252.18">Unknown@72.37.252.18</a> Regex (FAIL)<br>
> [emergency_set_variables] ${caller_id_name}(Unknown) =~ /^Emerg_/<br>
> break=never<br>
> Dialplan: sofia/external/<a href="mailto:Unknown@72.37.252.18">Unknown@72.37.252.18</a> Date/TimeMatch (FAIL)<br>
> [emergency_set_variables] break=never<br>
> Dialplan: sofia/external/<a href="mailto:Unknown@72.37.252.18">Unknown@72.37.252.18</a> Date/Time Match (PASS)<br>
> [emergency_set_variables] break=never<br>
> Dialplan: sofia/external/<a href="mailto:Unknown@72.37.252.18">Unknown@72.37.252.18</a> Action set(open=true) INLINE<br>
> EXECUTE sofia/external/<a href="mailto:Unknown@72.37.252.18">Unknown@72.37.252.18</a> set(open=true)<br>
><br>
> Note: I added the color so that you could see which dialplan lines<br>
> correspond to the log output.<br>
><br>
> The first condition (purple) fails. ({$caller_id_name} has the value<br>
> "Unknown" which fails the regex test against /^Emerg_/) However, since you<br>
> have break="never", the parser continues on to the next condition inside<br>
> this extension. Had you done break="on-false" (or no break attribute) then<br>
> the parser would have moved on to the next extension in the dialplan.<br>
><br>
> The second condition (orange) also fails. Again, you have break="never", so<br>
> even though it fails, the parser moves on to the next condition.<br>
><br>
> The third condition (green) passes, so the parser adds the <action> to the<br>
> task list. (Since you have inline="true" the action gets executed<br>
> immediately during dialplan parsing instead later on during the "execution<br>
> phase".)<br>
><br>
> In other words, the log output is exactly what I would expect it to be.<br>
><br>
> As to your other question about anti-actions in a stack: this also is a<br>
> common question. It looks like you are trying to do something like this:<br>
><br>
> IF (cond1 AND cond2 AND cond3) THEN<br>
> do actions<br>
> ELSE<br>
> do other actions<br>
> ENDIF<br>
><br>
> You cannot do this particular construct just with conditions and<br>
> anti-actions. Instead you'll need the brand spanking new "regex" syntax<br>
> mentioned here:<br>
> <a href="http://wiki.freeswitch.org/wiki/Dialplan_XML#Multiple_Conditions_.28Logical_OR.2C_XOR.29" target="_blank">http://wiki.freeswitch.org/wiki/Dialplan_XML#Multiple_Conditions_.28Logical_OR.2C_XOR.29</a><br>
><br>
> So, to do what you wanted to do in the second example (in your second post)<br>
> you could try this:<br>
><br>
> <condition regex="all"><br>
> <regex field="${sip_gateway}" expression="^${default_provider}$"/><br>
> <regex field="${emergency_call}" expression="^true$"/><br>
> <regex field="${db(select/emergency/autoanswer)}" expression="^1$"/><br>
> <!-- the following actions get executed if all regexes PASS --><br>
><br>
> <action application="set" data="call_timeout=60"/><br>
> <action application="set"<br>
> data="effective_caller_id_name=${regex(${caller_id_name}|^Emerg(_.*)$|Auto%1)}"/><br>
> <action application="set" data="autoanswered=true"/><br>
> <action application="answer" data=""/><br>
> <action application="set"<br>
> data="group_confirm_file=/usr/local/freeswitch/sounds/en/us/callie/emergency/press_to_accept.wav"/><br>
> <action application="set" data="group_confirm_key=1"/><br>
> <action application="bridge"<br>
> data="user/1000@${domain_name},sofia/gateway/1006_7217/${mobile_number}"/><br>
> <!-- the following anti-actions are executed if any of the regexes FAIL<br>
> --><br>
><br>
> <anti-action application="set"<br>
> data="effective_caller_id_name=${regex(${caller_id_name}|^Emerg(_.*)$|NotAuto%1)}"/><br>
> <anti-action application="set" data="call_timeout=30"/><br>
> <anti-action application="set" data="autoanswered=false"/><br>
> <anti-action application="set"<br>
> data="group_confirm_file=/usr/local/freeswitch/sounds/en/us/callie/emergency/press_to_accept.wav"/><br>
> <anti-action application="set" data="group_confirm_key=1"/><br>
> <anti-action application="bridge"<br>
> data="user/1000@${domain_name},sofia/gateway/1006_7217/${mobile_number}"/><br>
> </condition><br>
><br>
><br>
> The <condition regex="all"> tells the parser, "Hey, execute the <action>'s<br>
> only if all regexes PASS, otherwise execute any <anti-action>'s". That<br>
> should give you what you need.<br>
><br>
> Hope this helps!<br>
><br>
> -Michael<br>
><br>
><br>
><br>
><br>
> On Sat, Jan 14, 2012 at 7:39 PM, Herman Griffin <<a href="mailto:herman.griffin@gmail.com">herman.griffin@gmail.com</a>><br>
> wrote:<br>
>><br>
>> Hello everyone,<br>
>><br>
>> In irc SwK said that freeswitch AND operator is lazy. To me this means<br>
>> that if a condition is set to break=true and it evaluates to FAIL,<br>
>> then the that break=never will invert the meaning of FAIL; Change it<br>
>> to a PASS . But why doesn't break=false behave in this same manner<br>
>> when there is only a single condition?<br>
>><br>
>> Take this call trace and dialplan for example. I use a single<br>
>> condition with break=false. However, unlike the stacked conditions,<br>
>> the action is not executed when the single condition evaluates to<br>
>> FAIL. Why doesn't break=never cause the action to be executed in a non<br>
>> stacked condition?<br>
>><br>
>> Call trace:<br>
>><br>
>> Dialplan: sofia/external/<a href="mailto:Unknown@72.37.252.18">Unknown@72.37.252.18</a> Regex (FAIL)<br>
>> [emergency_set_variables] ${caller_id_name}(Unknown) =~ /^Emerg_/<br>
>> break=never<br>
>> Dialplan: sofia/external/<a href="mailto:Unknown@72.37.252.18">Unknown@72.37.252.18</a> Date/TimeMatch (FAIL)<br>
>> [emergency_set_variables] break=never<br>
>> Dialplan: sofia/external/<a href="mailto:Unknown@72.37.252.18">Unknown@72.37.252.18</a> Date/Time Match (PASS)<br>
>> [emergency_set_variables] break=never<br>
>> Dialplan: sofia/external/<a href="mailto:Unknown@72.37.252.18">Unknown@72.37.252.18</a> Action set(open=true) INLINE<br>
>> EXECUTE sofia/external/<a href="mailto:Unknown@72.37.252.18">Unknown@72.37.252.18</a> set(open=true)<br>
>><br>
>> Dialplan:<br>
>><br>
>> <condition field="${caller_id_name}" expression="^Emerg_" break="never"><br>
>> <action application="set" data="emergency_call=true" inline="true"/><br>
>> </condition><br>
>><br>
>> <condition wday="2-6" time-of-day="22:00-23:59" break="never"><br>
>> <action application="set" data="open=true" inline="true"/><br>
>> </condition><br>
>><br>
>> <condition wday="1,7" time-of-day="05:00-23:59" break="never"><br>
>> <action application="set" data="open=true" inline="true"/><br>
>> </condition><br>
>><br>
>> -------------------------------------------------<br>
>><br>
>> I also getting confusing behavior with anti-action and stacked<br>
>> condition. I expect the anti-action to be executed if any of the<br>
>> stacked conditions evaluates to FAIL. However, in the case below, the<br>
>> extension simply breaks if any of the condition evaluates to FAIL.<br>
>><br>
>> Call trace:<br>
>><br>
>> Dialplan: sofia/external/<a href="mailto:Unknown@72.37.252.18">Unknown@72.37.252.18</a> parsing<br>
>> [public->emergency_bridge] continue=true<br>
>> Dialplan: sofia/external/<a href="mailto:Unknown@72.37.252.18">Unknown@72.37.252.18</a> Regex (PASS)<br>
>> [emergency_bridge] ${sip_gateway}(1006_7217) =~ /^1006_7217$/<br>
>> break=on-false<br>
>> Dialplan: sofia/external/<a href="mailto:Unknown@72.37.252.18">Unknown@72.37.252.18</a> Regex (FAIL)<br>
>> [emergency_bridge] ${emergency_call}() =~ /^true$/ break=on-false<br>
>> Dialplan: sofia/external/<a href="mailto:Unknown@72.37.252.18">Unknown@72.37.252.18</a> parsing<br>
>> [public->public_did] continue=false <-- [[MOVES ON TO ANOTHER<br>
>> EXTENSION WITH EXECUTING THE anti-action]]<br>
>><br>
>> Dialplan:<br>
>><br>
>> <condition field="${sip_gateway}" expression="^${default_provider}$"/><br>
>> <condition field="${emergency_call}" expression="^true$"/><br>
>> <condition field="${db(select/emergency/autoanswer)}" expression="^1$"><br>
>> <action application="set" data="call_timeout=60"/><br>
>> <action application="set"<br>
>><br>
>> data="effective_caller_id_name=${regex(${caller_id_name}|^Emerg(_.*)$|Auto%1)}"/><br>
>> <action application="set" data="autoanswered=true"/><br>
>> <action application="answer" data=""/><br>
>> <action application="set"<br>
>><br>
>> data="group_confirm_file=/usr/local/freeswitch/sounds/en/us/callie/emergency/press_to_accept.wav"/><br>
>> <action application="set" data="group_confirm_key=1"/><br>
>> <action application="bridge"<br>
>> data="user/1000@${domain_name},sofia/gateway/1006_7217/${mobile_number}"/><br>
>><br>
>> <anti-action application="set"<br>
>><br>
>> data="effective_caller_id_name=${regex(${caller_id_name}|^Emerg(_.*)$|NotAuto%1)}"/><br>
>> <anti-action application="set" data="call_timeout=30"/><br>
>> <anti-action application="set" data="autoanswered=false"/><br>
>> <anti-action application="set"<br>
>><br>
>> data="group_confirm_file=/usr/local/freeswitch/sounds/en/us/callie/emergency/press_to_accept.wav"/><br>
>> <anti-action application="set" data="group_confirm_key=1"/><br>
>> <anti-action application="bridge"<br>
>> data="user/1000@${domain_name},sofia/gateway/1006_7217/${mobile_number}"/><br>
>> </condition><br>
>> </extension><br>
>><br>
>><br>
>> SwK suggested that I use a script language, which is probably what<br>
>> I'll end up doing. However, I'm very interested in understanding why<br>
>> the scenarios above. Are these bugs or are they just counter intuitive<br>
>> rules that we must simply memorize?<br>
>><br>
>> Thanks for your input.<br>
>> Herman Griffin<br>
>><br>
>><br>
>><br>
>> On Sat, Jan 14, 2012 at 11:42 AM, Jeff Lenk <<a href="mailto:jeff@jefflenk.com">jeff@jefflenk.com</a>> wrote:<br>
>> > By putting the break=never you are defeating the "and" processing.<br>
>> > Remove<br>
>> > that.<br>
>> ><br>
>> > Move the second group into its own extension.<br>
>> ><br>
>> > --<br>
>> > View this message in context:<br>
>> > <a href="http://freeswitch-users.2379917.n2.nabble.com/Stacked-conditions-are-not-acting-like-logical-AND-tp7188082p7188271.html" target="_blank">http://freeswitch-users.2379917.n2.nabble.com/Stacked-conditions-are-not-acting-like-logical-AND-tp7188082p7188271.html</a><br>
>> > Sent from the freeswitch-users mailing list archive at Nabble.com.<br>
><br>
><br>
><br>
><br>
</div></div><div class="HOEnZb"><div class="h5">> _________________________________________________________________________<br>
> Professional FreeSWITCH Consulting Services:<br>
> <a href="mailto:consulting@freeswitch.org">consulting@freeswitch.org</a><br>
> <a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br>
><br>
> FreeSWITCH-powered IP PBX: The CudaTel Communication Server<br>
> <a href="http://www.cudatel.com" target="_blank">http://www.cudatel.com</a><br>
><br>
> Official FreeSWITCH Sites<br>
> <a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
> <a href="http://wiki.freeswitch.org" target="_blank">http://wiki.freeswitch.org</a><br>
> <a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br>
><br>
> FreeSWITCH-users mailing list<br>
> <a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
> <a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
> UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
> <a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
><br>
<br>
_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a href="mailto:consulting@freeswitch.org">consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br>
<br>
FreeSWITCH-powered IP PBX: The CudaTel Communication Server<br>
<a href="http://www.cudatel.com" target="_blank">http://www.cudatel.com</a><br>
<br>
Official FreeSWITCH Sites<br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<a href="http://wiki.freeswitch.org" target="_blank">http://wiki.freeswitch.org</a><br>
<a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br>
<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
</div></div></blockquote></div><br></div></div>