Documentation

Documentation.Script-Statements-1-11 History

Hide minor edits - Show changes to output

March 20, 2014, at 08:29 PM by razvancrainea -
Changed lines 1-2 from:
!!!!!Documentation -> [[Documentation.Manuals|Manuals]] -> [[Documentation.Manual-1-11|Manual devel]] -> Script Statements
(:title Script Statements - devel :)
to:
!!!!!Documentation -> [[Documentation.Manuals|Manuals]] -> [[Documentation.Manual-1-11|Manual 1.11]] -> Script Statements
(:title Script Statements - 1.11 :)
Changed line 8 from:
|| %color=#185662%[+'''Script Statements devel'''+]%% ||
to:
|| %color=#185662%[+'''Script Statements v1.11'''+]%% ||
March 02, 2014, at 03:15 PM by liviu -
Changed line 153 from:
for ($var(it) in $(avp(arr)[*])) {
to:
for ($var(it) in $(avp(arr)[*]))
Changed lines 155-156 from:
}
to:
Changed line 157 from:
for ($var(ct) in $(ct[*])) {
to:
for ($var(ct) in $(ct[*]))
Changed lines 159-160 from:
}
to:
Changed line 161 from:
for ($var(via) in $(hdr(Via)[*])) {
to:
for ($var(via) in $(hdr(Via)[*]))
Deleted line 162:
}
March 02, 2014, at 03:14 PM by liviu -
Changed line 157 from:
# iterate through all Contact URIs from all Contact headers
to:
# iterate through all Contact URIs from each Contact header
March 02, 2014, at 03:13 PM by liviu -
Changed lines 143-144 from:
for each statement
to:
for each statement - easy iteration over indexed pseudo variables
Changed lines 147-153 from:
$avp(array) = 0;
$avp(array) = 1;
$avp(array) = 2;
$avp(array) = 3;
$avp(array) = 4;

for ($var(it) in $avp(array)) {
to:
$avp(arr) = 0;
$avp(arr) = 1;
$avp(arr) = 2;
$avp(arr) = 3;
$avp(arr) = 4;

for ($var(it) in $(avp(arr)[*])) {
Added lines 156-166:

# iterate through all Contact URIs from all Contact headers
for ($var(ct) in $(ct[*])) {
xlog("Contact: $var(ct)\n");
}

# iterate through all Via headers of a SIP request
for ($var(via) in $(hdr(Via)[*])) {
xlog("Found \"Via\" header: $var(via)\n");
}
October 18, 2013, at 06:25 PM by liviu -
Changed lines 141-143 from:
!!!!for( each)

for( each) statement
to:
!!!!for each

for each statement
October 18, 2013, at 06:25 PM by liviu -
Added lines 140-156:

!!!!for( each)

for( each) statement

Example of usage:
[@
$avp(array) = 0;
$avp(array) = 1;
$avp(array) = 2;
$avp(array) = 3;
$avp(array) = 4;

for ($var(it) in $avp(array)) {
xlog("array value: $var(it)\n");
}
@]
August 05, 2013, at 03:34 PM by razvancrainea -
Changed lines 1-2 from:
!!!!!Documentation -> [[Documentation.Manuals|Manuals]] -> [[Documentation.Manual-1-11|Manual 1.11]] -> Script Statements
(:title Script Statements - ver 1.11 :)
to:
!!!!!Documentation -> [[Documentation.Manuals|Manuals]] -> [[Documentation.Manual-1-11|Manual devel]] -> Script Statements
(:title Script Statements - devel :)
Changed line 8 from:
|| %color=#185662%[+'''Script Statements v1.11'''+]%% ||
to:
|| %color=#185662%[+'''Script Statements devel'''+]%% ||
August 05, 2013, at 01:59 PM by razvancrainea -
Added lines 1-139:
!!!!!Documentation -> [[Documentation.Manuals|Manuals]] -> [[Documentation.Manual-1-11|Manual 1.11]] -> Script Statements
(:title Script Statements - ver 1.11 :)
----
(:allVersions Script-Statements 1.11 :)

\\

|| %color=#185662%[+'''Script Statements v1.11'''+]%% ||

||[[Script-Operators-1-11|Prev]] || [[Script-CoreFunctions-1-11|Next]]||
----

(:toc-float Table of Content:)

Statements you can use in the '''OpenSIPS''' config file while building the routing logic.

!!!!if

IF-ELSE statement

Prototype:

[@
if (expr) {
actions;
} else {
actions;
}
@]

The 'expr' should be a valid logical expression.

The logical operators that can be used in the logical expressions:

* == - equal
* != - not equal
* =~ - regular expression matching (e.g. $rU =~ '^1800*' is "$rU begins with 1800" )
* !~ - regular expression not-matching
* > - greater
* >= - greater or equal
* < - less
* <= - less or equal
* && - logical AND
* || - logical OR
* ! - logical NOT
* [ ... ] - test operator - inside can be any arithmetic expression

Example of usage:

[@
if ( is_method("INVITE") && $rp==5060 )
{
log("this sip message is an invite\n");
} else {
log("this sip message is not an invite\n");
}
@]

!!!!switch

SWITCH statement - it can be used to test the value of a pseudo-variable.

IMPORTANT NOTE: 'break' can be used only to mark the end of a 'case' branch (as it is in shell scripts). If you are trying to use 'break' outside a 'case' block the script will return error -- you must use 'return' there.


Example of usage:
[@
route {
route(my_logic);
switch($retcode)
{
case -1:
log("process INVITE requests here\n");
break;
case 1:
log("process REGISTER requests here\n");
break;
case 2:
case 3:
log("process SUBSCRIBE and NOTIFY requests here\n");
break;
default:
log("process other requests here\n");
}

# switch of R-URI username
switch($rU)
{
case "101":
log("destination number is 101\n");
break;
case "102":
log("destination number is 102\n");
break;
case "103":
case "104":
log("destination number is 103 or 104\n");
break;
default:
log("unknown destination number\n");
}
}

route[my_logic]{
if(is_method("INVITE"))
{
return(-1);
};
if(is_method("REGISTER"))
return(1);
}
if(is_method("SUBSCRIBE"))
return(2);
}
if(is_method("NOTIFY"))
return(3);
}
return(-2);
}
@]

>>warning<<
Take care while using 'return' - 'return(0)' stops the execution of the script.
>><<


!!!!while

while statement

Example of usage:
[@
$var(i) = 0;
while($var(i) < 10)
{
xlog("counter: $var(i)\n");
$var(i) = $var(i) + 1;
}
@]

Page last modified on March 20, 2014, at 08:29 PM