[OpenSIPS-Users] Get IP/Port of registered user (or from Location table?)

Liviu Chircu liviu at opensips.org
Mon Nov 18 10:50:11 CET 2013


Hello bluerain,

Everything you said makes perfect sense and, surprisingly, it is (and 
should be) the expected behaviour, given that exact piece of code.

In a *switch *statement, the default behaviour is to go to the *next 
block* if a block does not end with the *break* keyword. It is normal 
for that script to perform exactly 4 lookups.

Your code now becomes:

"

case -1:
$var(aor)="sip:FRANK101 at 22.22.22.22:5062";
if(!lookup("location","","$var(aor)")) {
	t_reply("404","Not Found new $rc");
	exit;
}
break;

case -3:
#$var(aor)="sip:FRANK101 at 22.22.22.22:5062";
#if(!lookup("location","","$var(aor)")) {
	t_newtran();
	t_reply("404","Not Found");
	exit;
#}
break;

...

"

Best regards,

Liviu Chircu
OpenSIPS Developer
http://www.opensips-solutions.com

On 11/18/2013 03:14 AM, bluerain wrote:
> 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)="sip:FRANK101 at 22.22.22.22:5062";
> 						if(!lookup("location","","$var(aor)")) {
> 							t_reply("404","Not Found new $rc");
> 							exit;
> 						}
> 					case -3:
> 						#$var(aor)="sip:FRANK101 at 22.22.22.22:5062";
> 						#if(!lookup("location","","$var(aor)")) {
> 							t_newtran();
> 							t_reply("404","Not Found");
> 							exit;
> 						#}
> 					case -2:
> 						#$var(aor)="sip:FRANK101 at 22.22.22.22:5062";
> 						#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: http://opensips-open-sip-server.1449251.n2.nabble.com/Get-IP-Port-of-registered-user-or-from-Location-table-tp7588494p7588550.html
> Sent from the OpenSIPS - Users mailing list archive at Nabble.com.
>
> _______________________________________________
> Users mailing list
> Users at lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/users/attachments/20131118/925abbf4/attachment.htm>


More information about the Users mailing list