On Feb 24, 2010 at 09:35, Klaus Feichtinger <klaus.feichtinger(a)gmx.net> wrote:
Hello,
I have a question regarding the "SWITCH" statement from the core of
sip-router / kamailio.
In the news publication
(
http://www.kamailio.org/dokuwiki/doku.php/features:new-in-3.0.x) I found a
description that the switch statement now supports "regular expression for
matching string".
However, when I try the example (as displayed on the wiki page) I get
different error messages. The example that I've tested looks like:
switch($rU) {
case /^123/:
sl_send_reply("200", "yippie - ^123 works");
case /^124.*/:
sl_send_reply("200", "yippie - ^124.* works");
break;
}
The example is wrong (I'll fix it).
It should be:
case /"^123":
/^123/ is interpreted as a bad integer expression.
So use quotes and no ending '/'.
BTW: case /"^1"+"2"+"3": will work too (any expression
resulting in a
static string will do).
Worst case was using the first case with the case label "/^123/".
That resulted in a segmentation fault (!) with following error messages:
loading modules under /usr/lib/kamailio/
0(23229) : <core> [cfg.y:3329]: parse error in config file
/usr/local/etc/kamailio/kamailio.cfg, line 374, column 16: syntax error
0(23229) : <core> [cfg.y:3329]: parse error in config file
/usr/local/etc/kamailio/kamailio.cfg, line 374, column 16: bad expression
Segmentation fault
Yes, it's some parse error gone wrong (I'll fix it too).
When I added ".*" to /^123/ as in case "/^124.*/" the error message
was:
loading modules under /usr/lib/kamailio/
0(23256) : <core> [cfg.y:3329]: parse error in config file
/usr/local/etc/kamailio/kamailio.cfg, line 374, column 15: syntax error
0(23256) : <core> [cfg.y:3329]: parse error in config file
/usr/local/etc/kamailio/kamailio.cfg, line 374, column 15: bad case label
0(23256) : <core> [cfg.y:3329]: parse error in config file
/usr/local/etc/kamailio/kamailio.cfg, line 374, column 15: bad case
0(23256) : <core> [cfg.y:3329]: parse error in config file
/usr/local/etc/kamailio/kamailio.cfg, line 379, column 5: bad switch body
What does sip-router / kamailio now REALLY support? Is the information about RegEx a
mistake on the web page or is only the syntax wrong? However, in the CoreCookbook no entry
can be found regarding RegEx for switch statement......
Only the syntax is wrong.
Andrei