5.3. Using Replacements in Rules

In many cases, the conditions values and parameters of actions are not known in advance: they depend on elements of processed SIP messages and results of the message processing. Therefore, it is possible to compose the parameters of special strings that refer to SIP processing status. These strings are called “replacements” and are denoted by a dollar (“$”) sign followed by an identifier. Each instance of a replacement is replaced by its value when the rule is evaluated.

For example, $aU  is a replacement for the User part of the P-Asserted-Identity header; $th is a replacement for the host part of the To header. The action Set R-URI with the parameter set to sip:$aU@$th  combines mentioned parts of P-Asserted-Identity and To headers of the incoming request and puts them into the request URI of the outgoing request.

All supported replacements are listed in the table below.

Note that these special characters should be backslash-escaped as follows:

  • \ → \\
  • $ → \$

It is important to know that if a mediation action (Section SIP Mediation) changes content of SIP message, the substitution expression will refer to the value after modification. E.g., if you apply the rule action “SetFrom(sip:new@from.com)”, $fu will return new@from.com!

 Repl. group   Replacements  Description
$r $r. request-URI; note that the expression refers to current request URI which may be changed during the course of request processing
  $ru user@host[:port] part of request URI
  $rU R-URI User
  $rd R-URI Domain (host:port)
  $rh R-URI Host
  $rp R-URI Port
  $rP R-URI Parameters
$f $f. From header
  $fu user@host[:port] part of From URI
  $fU From User
  $fd From Domain (host:port)
  $fh From Host
  $fp From Port
  $fn From Display name
  $fP From Parameters
  $ft From Tag
  $fH From header Headers
$t $t. To header
  $tu user@host[:port] part of To URI
  $tU To User
  $td To Domain (host:port)
  $th To Host
  $tp To Port
  $tn To Display name
  $tP To Parameters
  $tt To Tag
  $tH To header Headers
$a $a. P-Asserted-Identity header
  $au user@host[:port] part of P-Asserted-Identity URI
  $aU P-Asserted-Identity User
  $ad P-Asserted-Identity Domain (host:port)
  $ah P-Asserted-Identity Host
  $ap P-Asserted-Identity Port
  $aP P-Asserted-Identity Parameters
  $at P-Asserted-Identity Tag
  $aH P-Asserted-Identity Headers
$p $p. P-Preferred-Identity header
  $pu user@host[:port] part of P-Preferred-Identity URI
  $pU P-Preferred-Identity User
  $pd P-Preferred-Identity Domain (host:port)
  $ph P-Preferred-Identity Host
  $pp P-Preferred-Identity Port
  $pP P-Preferred-Identity Parameters
  $pt P-Preferred-Identity Tag
  $pH P-Preferred-Identity Headers
$c $ci Call-ID
$C $C. complete Contact-HF
  $Ci user@host[:port], port is included if present in Contact-HF
  $Cx x’ is anything supported for other URIs
$s $si Source (remote) IP address
  $sp Source (remote) port number
$d $di expected destination host
  $dp expected destination port
$R $Ri Destination (local/received) IP address
$R $RI Destination IP address – like above but when a public IP is configured on the receiving interface, its value is used instead.
  $Rp Destination (local/received) port number
  $Rf local/received interface id (0=default)
  $Rn local/received interface name (SBC interface name)
  $RI local/received interface public IP
$H $H(headername) value of header with the name headername; not applicable to from/to/ruri/contact for which specific replacements must be used
  $HU(headername) header headername (as URI) User
  $Hd(headername) header headername (as URI) domain (host:port)
  $Hu(headername) header headername (as URI) URI
  $Hd(headername) header headername (as URI) domain (host:port)
  $Hh(headername) header headername (as URI) host
  $Hp(headername) header headername (as URI) port
  $Hn(headername) header headername (as URI) display name
  $Hp(headername) header headername (as URI) parameters
  $HH(headername) header headername (as URI) headers
$m $m request method
$V $V(gui.varname) value of Call Variable varname
$B $B(cnum.rnum) value of backreference with rnum  number from the condition with cnum  number
$U $Ua register cache: originating AoR
  $UA register cache: originating alias
$_ $_u(value) value to uppercase
  $_l(value) value to lowercase
  $_s(value) length of value (size)
  $_5(value) MD5 of value
  $_r(value) random number 0..value, e.g. $_r(5) gives 0, 1, 2, 3 or 4
$# $#(value) value URL-encoded
$time $time(value) time format as described in the libc strftime() function. ie: $time(%m-%d-%y-%H-%M)
$attr $attr(value) value of the given global attribute
$cntr $cntr(value) value of the given counter defined by User Defined Counters

5.3.1. Example Use of Replacement Expressions

In the following example, see Fig. Using Replacements, we set up the outgoing INVITE request as follows:

  • set Request URI of the outgoing INVITE request to the user part of the P-Asserted-Identity header ($aU) combined with the host part of the To header ($th) of the incoming INVITE request
  • set host part of the To header to the value of the P-NextHop-IP header ($H(P-NextHop-IP)) of the incoming INVITE request (the user part will not be changed)
  • convert the user part and the host part of the From header into lower case (<sip:$_l($fU)@_l($fh)>).
_images/10000000000003C7000002A85277406C.png

Figure 1: Using Replacements

The effects of this transformation on a SIP message is depicted in Fig. Effects of using replacements:

_images/10000201000001B20000014FA33D4A32.png

Figure 2: Effects of using replacements

Table Of Contents

Previous topic

5.2. Defining Rules

Next topic

5.4. Using Regular Expression Backreferences in Rules

This Page