[OpenSIPS-Users] dbalias and location lookup branching
John Sliney
John.Sliney at lcs.com
Wed Sep 27 16:01:24 UTC 2023
Thanks for the response Ravzan,
I attempted what I think is the mentioned solution, and apologies if this is not correct as I do not have a firm grasp of how osips handles branching, but by removing the branch route and doing location lookup in the main route right after the db_alias lookup if there are multiple sip users that dbalias resolves to then it's not looking up location for those branches, just the main branch.
### CODE ###
alias_db_lookup("dbaliases");
if ( !lookup("location") ) {
sl_send_reply(404, "User not found");
return(0);
}
### CODE ###
So branched INVITEs are just getting routed without being looked up, which routes them back to osips. Is there a way to call the lookup in the main route and have it perform location lookups for all the branches created by dbalias lookup?
And in the previous sample that I linked with lookups called from the branch_route, calls will work as long as there's a UAS to call. So as long as there's 1 branch that hasn't been dropped it will send that out, the only issue is if there are no possible endpoints. So if there's no sip users for that extension or no registrations for all sip users, I was trying to check the return code from t_relay and expected if there were no branches then relay would return a -3 response code but it seemingly still returns a 1 and a 500 SIP response is sent back to the UAC. If I can get the t_relay to just return a -3 then all my problems are solved I think. Or if there's a way to check before the relay if there are still branches to send and if not then respond 404.
________________________________
No, this is not the solution :).
The problem is you are calling t_relay, but after you evaluate each
branch, it turns out t_relay does not actually relay anything, hence it
returns an error.
The proper way to do this is to figure out whether you do need to send
any branches before calling t_relay() - this means that after the
alias_db_lookup, you can simply call the lookup() function - if that
fails, you should reply with a 404.
But what I am missing is the 500 message - what happened with the call
to the actual extension? Because from your script, it appears you still
want to keep it as a branch, don't you? Isn't that branch properly sent?
Also, the 500 sent to the client is very likely sent by the
sl_reply_error() function - you can replace it with a 404. However, I'd
still refactor everything to handle the branches in the main processing
context, not in the branch route.
My 2cents, best regards,
Răzvan Crainea
OpenSIPS Core Developer / SIPhub CTO
http://www.opensips-solutions.com / https://www.siphub.com
On 9/27/23 13:54, M S wrote:
> Maybe a send_reply(404) after if(!lookup(location)), instead of drop?
>
> On Tue, Sep 26, 2023 at 8:30 PM John Sliney <John.Sliney at lcs.com
> <mailto:John.Sliney at lcs.com>> wrote:
>
> Hi,
>
> I’m currently attempting to take an INVITE from an Asterisk server
> that is requesting an extension number, perform dbalias lookups to
> have extensions turned into sip users (x1000 -> test_hardphone) and
> then do location lookups on those sip users. There can be multiple
> sip users for each extension and multiple locations for each sip user.
>
> Using the code below partially works but when there are no location
> entries for the requested sip user, OpenSIPS returns a 500 and
> prints out “ERROR: t_forward_nonack failed” how can I
> have OpenSIPS instead respond with a 404?
>
> ### CODE ###
>
> modparam("alias_db", "append_branches", 1)
>
> route {
> if ( is_from_gw() ) {
> alias_db_lookup("dbaliases");
> t_on_branch("sip_user_branch");
> }
> route(relay);
> return(0);
> }
>
> branch_route[sip_user_branch] {
> route(lookup_sip_user);
> }
>
> route[lookup_sip_user] {
> if ( ! lookup("location") ) {
> drop();
> }
> }
>
> route[relay] {
> if ( ! t_relay() ) {
> sl_reply_error();
> rtpproxy_unforce();
> return(0);
> }
> }
>
> ### CODE ###
>
> Any help would be appreciated, Thanks
> _______________________________________________
> Users mailing list
> Users at lists.opensips.org <mailto:Users at lists.opensips.org>
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
> <http://lists.opensips.org/cgi-bin/mailman/listinfo/users>
>
>
> _______________________________________________
> Users mailing list
> Users at lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
_______________________________________________
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/20230927/ca2a85b4/attachment-0001.html>
More information about the Users
mailing list