Match by IP address and call a number

In the following example, the particular extension will be selected only if the IP address of the calling endpoint is 192.168.1.1. In the second condition, the dialed number is extracted in variable $1 and put in the data of the bridge application, in order to dial out to IP address 192.168.2.2.

<extension name="Test1"> 
  <condition field="network_addr"  
    expression="^192.168.1.1$"/> 
  <condition field="destination_number" expression="^(d+)$"> 
    <action application="bridge"  
      data="sofia/profilename/[email protected]"/> 
  </condition> 
</extension> 

The first condition field is terminated by a slash. The last condition field that contains the action tag is terminated by a regular </condition> tag. Also, note that the preceding example is not the same as this example:

<extension name="Test1Wrong"> 
  <condition field="destination_number" expression="^(d+)$"/> 
  <condition field="network_addr" 
    expression="^192.168.1.1$"> 
    <action application="bridge"  
      data="sofia/profilename/[email protected]"/> 
  </condition> 
</extension> 

The Test1Wrong example will not route the call properly because the variable $1 will not have any value, since the destination number was matched in a different condition, field.

You can also solve the Test1Wrong example by setting a variable in the first condition which you then use inside the second condition's action:

<extension name="Test1.2"> 
  <condition field="destination_number" expression="^(d+)$"> 
    <action application="set" data="dialed_number=$1"/> 
  </condition> 
  <condition field="network_addr"  
    expression="^192.168.1.1$"> 
    <action application="bridge"   
      data="sofia/profile/${dialed_number}@192.168.2.2"/> 
  </condition> 
</extension> 

You cannot use a variable set inside an extension for further conditions/matches as the extension is evaluated when the action is called.

If you need to do different actions based on a variable set inside an extension, you need to either use execute_extension to transfer the call for the variable to be set, or use inline processing. (See the section Inline execution earlier in this chapter.)

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset