Script Operators
Assignments, string and arithmetic operations can be done directly in the configuration file.
Assignment
Section titled “Assignment”Assignments can be done as in C, using the = (equal) operator. Note that not all script variables can be written; some are read-only. Check the list of variables to see which ones are writable.
$var(a) = 123;$ru = "sip:user@domain";There is a special assignment operator, := (colon equal), that can be used with AVPs. If the right-hand value is null, all AVPs with that name are deleted. Otherwise, the new value overwrites any existing values for AVPs with that name (in other words, it deletes the existing AVPs with the same name and adds a new one with the right-hand value).
$avp(val) := 123;String operations
Section titled “String operations”For strings, ’+’ is available to concatenate.
$var(a) = "test";$var(b) = "sip:" + $var(a) + "@" + $fd;Arithmetic and bitwise operations
Section titled “Arithmetic and bitwise operations”For numbers, one can use:
-
- : plus
-
- : minus
- / : divide
-
- : multiply
- % : modulo
- | : bitwise OR
- & : bitwise AND
- ^ : bitwise XOR
- ~ : bitwise NOT
- << : bitwise left shift
- >> : bitwise right shift
Example:
$var(a) = 4 + ( 7 & ( ~2 ) );Arithmetic expressions can be used in condition expressions via test operator ’ [ … ] ’.
if( [ $var(a) & 4 ] ) log("var a has third bit set\n");