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