[SR-Users] switch() - case: with intervals?

Daniel-Constantin Mierla miconda at gmail.com
Fri Oct 29 10:48:26 CEST 2010


Hello,


On 10/28/10 3:35 PM, "Nicolas Rüger" wrote:
> Hello,
>
> I wonder if there's a chance to use SWITCH in kamailio.cfg with intervals or ranges???

no it is not possible now, you can have many 'case' values like:

swiych($var(x)) {
    case 1:
    case 2:
    case 4:
    case 8:
         ....
    break;
    ...
}

Apart of doing "if" conditions with greater and less ops, an option, 
just for a nicer look maybe, would be to convert to some string and use 
regexp matching in switch:

$var(match) = "#" + $var(x) + "#";

switch($var(match)) {
    case /"#1#2#4#8#":
       ...
}

But still no interval, so you need to list always all the values.

Cheers,
Daniel

> There's nothing to find in core cookbook about ranges with SWITCH.
>
> something like:
>
>   switch ( $var(i) ){
>
>     case 1..10:
>
>         # instructions...
>
>     break;
>
>     case [11-20]:
>
>         # instructions...
>
>     break;
>
>     default:
>        # default instructions
>   }
>
>
> Thank you...
>
> Regards,
>
> Nicolas

-- 
Daniel-Constantin Mierla
http://www.asipto.com




More information about the sr-users mailing list