<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Hello bluerain,<br>
      <br>
      Everything you said makes perfect sense and, surprisingly, it is
      (and should be) the expected behaviour, given that exact piece of
      code.<br>
      <br>
      In a <b>switch </b>statement, the default behaviour is to go to
      the <b>next block</b> if a block does not end with the <b>break</b>
      keyword. It is normal for that script to perform exactly 4
      lookups.<br>
      <br>
      Your code now becomes:<br>
      <br>
      "<br>
      <pre wrap="">case -1: 
$var(aor)=<a class="moz-txt-link-rfc2396E" href="mailto:sip:FRANK101@22.22.22.22:5062">"sip:FRANK101@22.22.22.22:5062"</a>;
if(!lookup("location","","$var(aor)")) {
        t_reply("404","Not Found new $rc");
        exit;
}
break;

case -3:
#$var(aor)=<a class="moz-txt-link-rfc2396E" href="mailto:sip:FRANK101@22.22.22.22:5062">"sip:FRANK101@22.22.22.22:5062"</a>;
#if(!lookup("location","","$var(aor)")) {
        t_newtran();
        t_reply("404","Not Found");
        exit;
#}
break;

...
</pre>
      "<br>
      <br>
      Best regards,<br>
      <pre class="moz-signature" cols="72">Liviu Chircu
OpenSIPS Developer
<a class="moz-txt-link-freetext" href="http://www.opensips-solutions.com">http://www.opensips-solutions.com</a></pre>
      On 11/18/2013 03:14 AM, bluerain wrote:<br>
    </div>
    <blockquote cite="mid:1384737281645-7588550.post@n2.nabble.com"
      type="cite">
      <pre wrap="">Hello Liviu,

thanks for your help again!  Ok, so I tried that and is weird, is kinda
working but is working weirdly.  Not sure, maybe I don't truely understand
how opensips works?  But here is my code:

        if (is_method("INVITE")) {

                        trace_dialog();

                        if (!lookup("location","m")){
                                switch($rc) 
                                {
                                        case -1: 
                                                $var(aor)=<a class="moz-txt-link-rfc2396E" href="mailto:sip:FRANK101@22.22.22.22:5062">"sip:FRANK101@22.22.22.22:5062"</a>;
                                                if(!lookup("location","","$var(aor)")) {
                                                        t_reply("404","Not Found new $rc");
                                                        exit;
                                                }
                                        case -3:
                                                #$var(aor)=<a class="moz-txt-link-rfc2396E" href="mailto:sip:FRANK101@22.22.22.22:5062">"sip:FRANK101@22.22.22.22:5062"</a>;
                                                #if(!lookup("location","","$var(aor)")) {
                                                        t_newtran();
                                                        t_reply("404","Not Found");
                                                        exit;
                                                #}
                                        case -2:
                                                #$var(aor)=<a class="moz-txt-link-rfc2396E" href="mailto:sip:FRANK101@22.22.22.22:5062">"sip:FRANK101@22.22.22.22:5062"</a>;
                                                #if(!lookup("location","","$var(aor)")) {
                                                        sl_send_reply("405", "Method Not Allowed");
                                                        exit;
                                                #}
                                }
                        }

                        route(relay);
                }

So if I use the code above, it would reply "404","Not Found" which means the
lookup() function returned "-3"

And then if I unquote the all the "#" in "-3" section", since that is where
the error happend, now when I sent the INVITE, it would return "405 Method
Not Allowed", which means now lookup() function returned "-2"

So lastly if I unquote the "#"in "-2", the call actually worked!  But it
seems the code must got iterated 3 times before it reach the "method not
found" section and thus finally sent the call out?

So what I mean is that if I sent an "unknown" user in the INVITE, from the
code above, it will jump to "-1" section (because it return error code -1)
and then when it execute again the lookup() in the "-1" section, it jump to
-3 and then execute lookup() again in "-3" and then finally it jump to "-2"
to execute the finally lookup.  Why?

Shouldn't it simply jump to "-1" and then do the lookup("frank101") which IS
IN THE LOCATION table and then proceed with jumping to the route(relay) and
FRANK101 phone should ring, no?

but instead it seems it looped back into the "invite" and then do the lookup
again with blah errors, until it finally reach the finally possibility of
"-2", then call works... weird, why?

Thank you!




--
View this message in context: <a class="moz-txt-link-freetext" href="http://opensips-open-sip-server.1449251.n2.nabble.com/Get-IP-Port-of-registered-user-or-from-Location-table-tp7588494p7588550.html">http://opensips-open-sip-server.1449251.n2.nabble.com/Get-IP-Port-of-registered-user-or-from-Location-table-tp7588494p7588550.html</a>
Sent from the OpenSIPS - Users mailing list archive at Nabble.com.

_______________________________________________
Users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Users@lists.opensips.org">Users@lists.opensips.org</a>
<a class="moz-txt-link-freetext" href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>