[SR-Dev] script parsing: string switch support

Daniel-Constantin Mierla miconda at gmail.com
Fri Feb 20 16:20:58 CET 2009



On 02/20/2009 01:22 PM, Andrei Pelinescu-Onciul wrote:
> On Feb 20, 2009 at 11:15, Daniel-Constantin Mierla <miconda at gmail.com> wrote:
>   
>> Hello Andrei,
>>
>> On 02/20/2009 12:50 AM, Andrei Pelinescu-Onciul wrote:
>>     
>>> [...]
>>>
>>> script parsing: string switch support
>>>  
>>>       
>> that's great, thanks. From the next example, to understand the the case 
>> can take expression that evaluates to static strings or integers?
>>     
>
> Yes.
> There are the following restriction:
>
> - case labels must be static (no vars allowed)
> - in the same switch you can have only one type of case labels: strings
>   or integers (1)
> - the first case label sets the required type for all the others
>  (so if your first case label is a string => all the other must be
>  strings, if it's an integer all the other must be integers).
>   
ok.

> (1) - could be changed in some cases (e.g. string case with some int
> label allowed, which could be automatically converted to string), but I
>  think it would too confusing and I disallowed it (in general having
>  mixed types in a switch() are 99% an error).
>   

> I still think that using a different switch() name for strings will be
> less confusing (e.g. switch() for integers and match() for strings).
>   

I prefer single type case value instead of mixed (as it is in kamailio 
now, but somehow useless and confusing, I doubt someone is using it), 
but not two different statements. I think switch as it is now is just fine.

> Any opinion on how to differentiate regular expressions from strings?
> Right now a '/' in front means a regular expression (but there's no way
> to specify case insensitive match for example).
>   
What about '~' which is the one used in IF.

>   
>> Now, with while and switch in there I can work to get most of my configs 
>> working with sip-router.
>>     
>
> Warning: the while works only with integers :-)
>   

Do you mean that the expression has to evaluate to int? This has to be 
relaxed for strings and NULL for PVs. I will have a look latter.

Cheers,
Daniel

>
> Andrei
>
> _______________________________________________
> sr-dev mailing list
> sr-dev at lists.sip-router.org
> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
>
>   

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




More information about the sr-dev mailing list