Hello,

you can also convert the header value to integer using the transformation {s.int}, that's safer if you need to do other types of comparison such as > or <, because comparing string values might give the result you don't expect,

Cheers,
Daniel

On Friday, September 13, 2019, Joel Serrano <joel@textplus.com> wrote:
I think I found the solution to my problem: I'm comparing to 0 (number) when I should be comparing to "0" (string)?

Using:

...
        if ($hdr(Expires)=="0" || $sel(contact.expires)=="0") {
...

Is working as expected.

Sorry for the noise!
Joel.


On Thu, Sep 12, 2019 at 5:50 PM Joel Serrano <joel@textplus.com> wrote:
Hello, 

I'm running into what I believe a weird situation when comparing <null> to 0.

I have the following lines:

        xlog("L_NOTICE", "DEBUG: sel(contact.expires)=$sel(contact.expires) - hdr(Expires)=$hdr(Expires)\n");
        if ($hdr(Expires)==0 || $sel(contact.expires)==0) {
            xlog("L_NOTICE", "[end] removed user location\n");
        } else {
            xlog("L_NOTICE", "[end] saved user location\n");
        }


I registered with 3 devices, one sends expires as header, another as contact param, and the last uses both header AND contact param.

My surprise was this:


1- Both header and contact param:
Sep 12 19:37:48 csbc01 csbc[8036]: NOTICE: {1 4 REGISTER 02c3ea6ee623916d37532188031017c9@0:0:0:0:0:0:0:0} <script>: DEBUG: sel(contact.expires)=600 - hdr(Expires)=600
Sep 12 19:37:48 csbc01 csbc[8036]: NOTICE: {1 4 REGISTER 02c3ea6ee623916d37532188031017c9@0:0:0:0:0:0:0:0} <script>: [end] saved user location
2- Only contact param:
Sep 12 19:36:15 csbc01 csbc[8035]: NOTICE: {1 40629 REGISTER f2cbaa53-eabfd633@84.121.150.224} <script>: DEBUG: sel(contact.expires)=600 - hdr(Expires)=<null>
Sep 12 19:36:15 csbc01 csbc[8035]: NOTICE: {1 40629 REGISTER f2cbaa53-eabfd633@84.121.150.224} <script>: [end] removed user location
2- Only header:
Sep 12 19:29:33 csbc01 csbc[8033]: NOTICE: {1 402 REGISTER 2_1804628355@192.168.30.31} <script>: DEBUG: sel(contact.expires)=<null> - hdr(Expires)=3600
Sep 12 19:29:33 csbc01 csbc[8033]: NOTICE: {1 402 REGISTER 2_1804628355@192.168.30.31} <script>: [end] removed user location


I can workaround the header by using is_present_hf() before comparing, I can also probably parse the $ct to see if it has some Expires in it, but I really want to know if my understanding is incorrect and I'm doing something wrong or if this is a bug?

Thanks!
Joel.



--
Daniel-Constantin Mierla - http://www.asipto.com
http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda