[sr-dev] trouble with testing $var
Andrei Pelinescu-Onciul
andrei at iptel.org
Mon Nov 9 18:54:41 CET 2009
On Nov 08, 2009 at 12:55, Juha Heinanen <jh at tutpro.com> wrote:
> i wrote alias_contact() function and seems to work fine. i have not
> yet written handle_alias(), but tried to first use scripting means for
> that. that led into trouble with testing is $var has value.
>
> i have this piece of code:
>
> xlog("L_INFO", "R-URI is <$ru>\n");
> $var(tmp) = $(ru{uri.param,alias});
> xlog("L_INFO", "Alias param is <$var(tmp)>\n");
> if ($var(tmp)) {
> xlog("L_INFO", "Alias param is <$var(tmp)>\n");
> $du = $var(tmp);
^^^^^^^^
shouldn't it be $du = "sip:" + $var(tmp) ?
> xlog("L_INFO", "Routing in-dialog $rm from <$fu> to <$du>\n");
> } else {
> xlog("L_INFO", "Routing in-dialog $rm from <$fu> to <$ru>\n");
> }
>
> and i get to syslog:
>
> Nov 8 12:51:10 localhost /usr/sbin/sip-proxy[4506]: INFO: R-URI is <sip:jh_test_fi at 192.98.101.10:5074;transport=tcp;alias="192.98.101.10:55375;transport=tcp">
> Nov 8 12:51:10 localhost /usr/sbin/sip-proxy[4506]: INFO: Alias param is <192.98.101.10:55375;transport=tcp>
> Nov 8 12:51:10 localhost /usr/sbin/sip-proxy[4506]: INFO: Routing in-dialog BYE from <sip:test at as.test.fi> to <sip:jh_test_fi at 192.98.101.10:5074;transport=tcp;alias="192.98.101.10:55375;transport=tcp">
>
> why does the test
>
> if ($var(tmp)) {
>
> fail to figure out that $var(tmp) has value?
You should use if ($var(tmp)!="").
if ($var(tmp)) works only for integers. If $var(tmp) is not integer and
not a string of the form "1234", it will evaluate to 0 in an integer
context. The if() it's an integer context (no boolean context in sr).
Andrei
More information about the sr-dev
mailing list