why does test
if ($var(test)) ...
fail even when $var(test) has a non-empty string value?
the test works, if i do it like this:
if ($var(test) != 0) ...
i'm pretty sure that in k also the first version of the test works.
-- juha
look at this:
$var(test) = "foo"; if ($var(test)) { xlog("L_INFO", "EXTR: $var(test) has value\n"); } else { xlog("L_INFO", "EXTR: $var(test) does NOT have value\n"); }
$var(test) = 1; if ($var(test)) { xlog("L_INFO", "EXTR: $var(test) has value\n"); } else { xlog("L_INFO", "EXTR: $var(test) does NOT have value\n"); }
prints
Sep 2 14:17:23 localhost /usr/sbin/sip-router[14295]: INFO: EXTR: foo does NOT have value Sep 2 14:17:23 localhost /usr/sbin/sip-router[14295]: INFO: EXTR: 1 has value
this is not good and makes programming VERY error prone.
-- juha
it would be nice if someohe who knows could summarize, how to test if these have a value assigned to them:
- $var - $pseudo_variable (for example, message item) - $avp - @select - htable entry - what else there is that can be assigned a value
it would be VERY desirable that one way to do the test would work for all of above, before the first release of sr comes out.
-- juha
On 02.09.2009 14:14 Uhr, Juha Heinanen wrote:
why does test
if ($var(test)) ...
fail even when $var(test) has a non-empty string value?
indeed, I checked the sources, SR core tries to convert the str to int and fails in above case.
I can make a patch so to return true for PV is they have a value with len!=0, if feels to be right for the rest -- it is what I would expect as well.
However, maybe Andrei can detail more about the logic behind.
Cheers, Daniel
the test works, if i do it like this:
if ($var(test) != 0) ...
i'm pretty sure that in k also the first version of the test works.
Daniel-Constantin Mierla writes:
I can make a patch so to return true for PV is they have a value with len!=0, if feels to be right for the rest -- it is what I would expect as well.
that would be great.
However, maybe Andrei can detail more about the logic behind.
i hope there isn't any :-).
-- juha
On 03.09.2009 18:39 Uhr, Juha Heinanen wrote:
Daniel-Constantin Mierla writes:
I can make a patch so to return true for PV is they have a value with len!=0, if feels to be right for the rest -- it is what I would expect as well.
that would be great.
I see that
if("somestring")
is false always as well. We should get to a common/coherent behavior for all cases, not only for PVs -- other opinions?
For me, a string that has len>0 should return true in above condition as well as int that is !=0.
Cheers, Daniel
However, maybe Andrei can detail more about the logic behind.
i hope there isn't any :-).
-- juha
sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
On Thursday 03 September 2009 17:06:35 Daniel-Constantin Mierla wrote:
I see that
if("somestring")
is false always as well. We should get to a common/coherent behavior for all cases, not only for PVs -- other opinions?
For me, a string that has len>0 should return true in above condition as well as int that is !=0.
I agree with that.