[SR-Users] Gracefully dropping all branches
Andreas Granig
agranig at sipwise.com
Wed Feb 20 13:01:56 CET 2019
Hi,
Setting a message-wide flag when dropping at least one branch, and the approach of checking if t_relay(0x02) failed, then sending a t_reply() if that flag is set (otherwise a sl_reply_error()), is the most simple and elegant way, as I don’t have to track anything in a table. Works like charm, thanks a lot!
Best,
Andreas
> On 20.02.2019, at 12:30, Daniel-Constantin Mierla <miconda at gmail.com> wrote:
>
> Hello,
>
> On 20.02.19 11:58, Andreas Granig wrote:
>> Hi all,
>>
>> I’ve a scenario where after lookup() I get multiple branches, and I want to drop some or all of them based on some filter criteria in a branch route before sending requests out. Problem is that if all branches are dropped, kamailio replies with some implicitly generated 500 server error since there are no more branches, but I want to send a 404 or 480 instead.
>>
>> Is there a way to determine if I’m processing the last active branch (so all others have been dropped already), so I can send a graceful reply like 404 or 480 instead of dropping this last branch as well if I decide I have to filter that one too?
>>
>> I’m thinking of a hash table table or something to track and decrease the number of branches for a call, and based on a flag (whether one of the previous branches has been sent out or all have been dropped so far) either drop the last branch or reply with an error. However I’m wondering if kamailio comes with a mechanism to determine the branch state out of the box?
>>
> At this moment I do not recall any variable or function to indicate you
> process last branch, nor to say if any other branches is active. It
> should not be hard to add something like that, though -- eventually part
> of $T() or $T_branch().
>
> Probably you can do it now with some operations in config:
>
> - after lookup location you have $branch(count) saying the number of
> additional branches (besides the R-URI destination)
>
> - in branch_route, you have $T(branch_index) giving the index of the
> current branch
>
> If you don't drop a branch, you can mark it via a transaction flag or
> using htable. When you get to the last branch, test if you have one
> active and if not, send your reply.
>
> On the other hand, iirc, either t_relay() is not replying internally
> (not sure by heart right now) or there should be a way to disable
> sending internal errors from tm. Anyhow, t_relay() should return false
> when no branch is forwarded, then you can send your own reply instead of
> using sl_reply_error().
>
> Cheers,
> Daniel
>
> --
> Daniel-Constantin Mierla -- www.asipto.com
> www.twitter.com/miconda -- www.linkedin.com/in/miconda
> Kamailio World Conference - May 6-8, 2019 -- www.kamailioworld.com
> Kamailio Advanced Training - Mar 4-6, 2019 in Berlin; Mar 25-27, 2019, in Washington, DC, USA -- www.asipto.com
>
More information about the sr-users
mailing list