MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / t_pick_branch

Function t_pick_branch

modules/tm/t_reply.c:808–857  ·  view source on GitHub ↗

select a branch for forwarding; returns: * 0..X ... branch number * -1 ... error * -2 ... can't decide yet -- incomplete branches present */

Source from the content-addressed store, hash-verified

806 * -2 ... can't decide yet -- incomplete branches present
807 */
808static inline int t_pick_branch( struct cell *t, int *res_code, int *do_cancel)
809{
810 #define PHONY_NO_WAIT(_t,_uac) \
811 ((_uac)->br_flags && (_uac)->br_flags<=(_t)->nr_of_outgoings)
812 int lowest_b, lowest_s, b, prio;
813 unsigned int cancelled;
814 struct ua_client* uac;
815
816 lowest_b=-1; lowest_s=999;
817 cancelled = was_cancelled(t);
818 *do_cancel = 0;
819 for ( b=t->first_branch; b<t->nr_of_outgoings ; b++ ) {
820 uac = & TM_BRANCH( t, b);
821 if ( (uac->flags & T_UAC_IS_PHONY) && (
822 /* skip PHONY branches if the transaction was canceled by UAC;
823 * a phony branch is used just to force the transaction to wait for
824 * more branches, but if canceled, it makes no sense to wait anymore;
825 * Exception - do not ignore the branch if there is reply pushed
826 * on that branch, like an internal timeout or so */
827 (t->flags & T_WAS_CANCELLED_FLAG && uac->last_received<299)
828 ||
829 /* also skip a PHONY branch if it has a true setting about how
830 * many branches are to be waited. The max branch idx to be waited
831 * is stored in the 'br_flags' flags of the uac */
832 PHONY_NO_WAIT(t,uac)
833 ))
834 continue;
835 /* skip 'empty branches' */
836 if (!uac->request.buffer.s) continue;
837 /* there is still an unfinished UAC transaction; wait now! */
838 if ( uac->last_received<200 ) {
839 if (uac->br_flags & minor_branch_flag) {
840 *do_cancel = 1;
841 continue; /* if last branch, lowest_b remains -1 */
842 }
843 return -2;
844 }
845 /* compare against the priority of the current branch */
846 prio = branch_prio(uac->last_received,cancelled);
847 if ( (lowest_b==-1) || (prio<lowest_s) ) {
848 lowest_b = b;
849 lowest_s = prio;
850 }
851 } /* find lowest branch */
852 LM_DBG("picked branch %d, code %d (prio=%d)\n",
853 lowest_b,lowest_b==-1 ? -1 : TM_BRANCH(t,lowest_b).last_received,lowest_s);
854
855 *res_code=lowest_s;
856 return lowest_b;
857}
858
859
860/* Quick and harmless test to see if the transaction still has

Callers 1

t_should_relay_responseFunction · 0.85

Calls 1

branch_prioFunction · 0.85

Tested by

no test coverage detected