Location>code7788 >text

Condition string matching problem

Popularity:944 ℃/2024-08-07 17:45:44

summarize

freeswitch is a simple and easy to use VOIP open source softswitch platform.

fs uses the dialplan configuration file to execute business processes, condition condition variable configuration is bound to be used, here to record an error in the configuration process demonstration.

matrix

CentOS 7.9

freeswitch 1.10.7

Description of the problem

The dialplan configuration is as follows, with the intention of executing different apps depending on the value of the channel variable ${poolType}.

<context name="saxb_bind_axb">
<extension name="saxb_bind_axb" continue="true">
<condition field="${call_result}" expression="0" break="never">
<condition field="${poolType}" expression="APP" break="never">
<action application="saxb_bind_axb" />
<action application="transfer" data="${destination_number} XML saxb_bridge"/>
</condition>

<condition field="${poolType}" expression="SIP" break="never">
<action application="transfer" data="${destination_number} XML saxb_bridge"/>
</condition>

<condition field="${poolType}" expression="AX" break="never">
<action application="saxb_bind_ax" />
<action application="transfer" data="${destination_number} XML saxb_bridge"/>
</condition>

<condition field="${poolType}" expression="AXB" break="never">
<action application="saxb_bind_axb" />
<action application="transfer" data="${destination_number} XML saxb_bridge"/>
</condition>

<anti-action application="transfer" data="${destination_number} XML saxb_get_ax2"/>
</condition>
</extension>
</context>

problematic phenomenon

The log after the call is initiated is as follows, where the channel variable ${poolType} has the value of AXB, but both the AX and AXB branches were matched successfully and PASSed, and the business process executed the wrong branch.

2024-07-29 16:10:48.492821 [INFO] mod_dialplan_xml.c:637 Processing 10011 <10011>->13987654321 in context saxb_bind_axb

Dialplan: sofia/external/[email protected] parsing [saxb_bind_axb->saxb_bind_axb] continue=true

Dialplan: sofia/external/[email protected] Regex (PASS) [saxb_bind_axb] ${call_result}(0) =~ /0/ break=never

|--- Dialplan: Processing recursive conditions level:1 [saxb_bind_axb_recur_1] require-nested=TRUE

|--- Dialplan: sofia/external/[email protected] Regex (FAIL) [saxb_bind_axb_recur_1] ${poolType}(AXB) =~ /APP/ break=never

|--- Dialplan: sofia/external/[email protected] Regex (FAIL) [saxb_bind_axb_recur_1] ${poolType}(AXB) =~ /SIP/ break=never

|--- Dialplan: sofia/external/[email protected] Regex (PASS) [saxb_bind_axb_recur_1] ${poolType}(AXB) =~ /AX/ break=never

|--- Dialplan: sofia/external/[email protected] Action saxb_bind_ax()

|--- Dialplan: sofia/external/[email protected] Action transfer(${destination_number} XML saxb_bridge)

|--- Dialplan: sofia/external/[email protected] Regex (PASS) [saxb_bind_axb_recur_1] ${poolType}(AXB) =~ /AXB/ break=never

|--- Dialplan: sofia/external/[email protected] Action saxb_bind_axb()

|--- Dialplan: sofia/external/[email protected] Action transfer(${destination_number} XML saxb_bridge)

 

Problem analysis

<condition field="${poolType}" expression="AX" break="never">

The default pattern match is not an exact match, so it can also match through.

prescription

Modify the configuration as follows, changing the "AX" string to "^AX$".

<condition field="${poolType}" expression="^AX$" break="never">

The test results are as follows.

|--- Dialplan: sofia/external/[email protected] Regex (FAIL) [saxb_bind_axb_recur_1] ${poolType}(AXB) =~ /^AX$/ break=never

Condition Matching Rule

In FreeSWITCH's dialplan, condition is a very powerful feature that allows you to match and execute different commands based on specific conditions. condition can match various types of strings including, but not limited to, user inputs, call variables, environment variables, and so on.

 

Here are some common condition matching rules.

Exact match:

Use the equal sign == for exact matching. If the expression on the left is exactly the same as the string on the right, the condition is true.

<condition field="destination_number" expression="^13712345678$">

 

Regular expression matching:

Use =~ for regular expression matching. FreeSWITCH supports Perl-compatible regular expressions.

<condition field="destination_number" expression="^137[1-9]\d{7}$">

 

Grouping:

Use | to match multiple values.

<condition field="destination_number" expression="^13712345678|13799999999$">

 

Multi-conditional combinations.

<conditionregex="all|any|xor">
<regexfield="some_field"expression="Some Value"/>
<regexfield="another_field"expression="^Another Value$"/>
<action(s)...>
<anti-action(s)...>
</condition>

 

asterisk mode. This mode is not as flexible as xml mode, and is supposed to be compatible with older versions of overmode.

<condition field="destination_number" expression="_13712345678">

summarize

The fs dialplan configuration is convenient, but also error prone.

 

nothing but the usual

seek the truth and obtain it