Tuesday, April 20, 2010

Kamailio 3.0.x - DYK-04 - switch

Match regular expressions with switch statement

See also: Kamailio 3.0.x - DYK - Table of Content

Starting with 3.0.0, you can use regular expressions to match switch cases - you have to use a '/' (slash) before case value to tell it is regular expression. For example, match dialed number against country codes:
switch($rU) {
case /"^\+1": # calls to USA
case /"^\+49": # calls to Germany
default: # calls to other destinations
First, it is one statement construct, therefore is faster than a set of IFs:
if($rU=~"^\+1") {...}
else if($rU=~"^\+49") {...}
else {...}
Then, the config file is better structured, being easier now to manage and follow prefix based routing rules.

No comments:

Post a Comment