On Mon, December 21, 2009 9:51 pm, Alex Balashov wrote:
also possible
is to use it: if (! $avp(s:lnp_prefix)) which is shorter
and don't rely on the avpops module to test for null. (In sr the
"defined" operator can be used for the same purpose.
I thought that would evaluate the numerical expression value of the AVP,
not
whether it is null?
If you use the ' ! ' operator, it will evaluate the integer expression,
which of course fail if you have a string avp content:
$avp(s:test) = "foobar";
if (! $avp(s:test)) {
xlog(" ! ");
}
if (! defined $avp(s:test)) {
xlog("! defined");
}
if (strlen($avp(s:test)) == 0) {
xlog(" strlen ");
}
Dec 21 23:01:45 laptop ../../ser[18709]: WARNING: <core> [rvalue.c:987]:
automatic string to int conversion for "foobar" failed
Dec 21 23:01:45 laptop ../../ser[18709]: WARNING: <core> [rvalue.c:1839]:
rval expression conversion to int failed (54,8-54,19)
Dec 21 23:01:45 laptop ../../ser[18709]: ERROR: <script>: !
If the AVP is not defined, i get this output:
Dec 21 23:14:30 laptop ../../ser[20028]: ERROR: <script>: !
Dec 21 23:14:30 laptop ../../ser[20028]: ERROR: <script>: ! defined
Dec 21 23:14:30 laptop ../../ser[20028]: ERROR: <script>: strlen
If I set the AVP to the empty string, i get this output:
Dec 21 23:15:54 laptop ../../ser[20152]: ERROR: <script>: !
Dec 21 23:15:54 laptop ../../ser[20152]: ERROR: <script>: strlen
I did also a test on kamailio, it seems that the 'defined' operator is not
equivalent to the ' ! ' operator here, as the latter evaluate to true also
if the $avp is the empty string. If also tried with to test for a not
existing header with $hdr() on sip-router, this is equivalent to the not
defined AVP.
Regards,
Henning