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

Function swap_msg_branches

dset.c:722–786  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

720
721
722int swap_msg_branches(struct sip_msg *msg, int src_idx, int dst_idx)
723{
724 struct dset_ctx *dsct = get_dset_ctx();
725 struct msg_branch_wrap *brs;
726 struct msg_branch_wrap bk;
727 struct usr_avp *bk_attrs;
728
729 if (src_idx==dst_idx)
730 /* this is a NOP */
731 return 0;
732
733 /* no branches have been added yet */
734 if (!dsct)
735 return -1;
736
737 if ( (src_idx>0 && src_idx>=dsct->nr_branches)
738 || (dst_idx>0 && dst_idx>=dsct->nr_branches) ) {
739 LM_ERR("overflow in src [%d] or dst [%d] indexes (having %d)\n",
740 src_idx, dst_idx, dsct->nr_branches);
741 return -1;
742 }
743
744 brs = dsct->branches;
745
746 /* to avoid useless cloning of the attr lists, better detach them
747 * before doing anything and swap them at the end */
748
749 /* backup the info from dst branch, so we can write into it */
750 if (dst_idx>=0) {
751 /* detach the attrs */
752 bk_attrs = brs[dst_idx].branch.attrs;
753 brs[dst_idx].branch.attrs = NULL;
754 /* backup the dst branch */
755 bk = brs[dst_idx];
756 _post_copy_branch_update( &bk );
757 } else {
758 /* detach the attrs */
759 bk_attrs = dsct->ruri_attrs;
760 dsct->ruri_attrs = NULL;
761 /* backup the msg branch */
762 if (_msg_2_branch(dsct, msg, &bk)<0)
763 return -1;
764 }
765
766 /* copy dst over src */
767 if (_copy_branch( msg, dsct, src_idx, dst_idx)<0)
768 return -1;
769
770 /* now copy the original dst (from bk) into src */
771 if (src_idx>=0) {
772 /* copy bk into a branch */
773 brs[src_idx] = bk;
774 _post_copy_branch_update( brs+src_idx );
775 /* attach the dst list of attrs */
776 brs[src_idx].branch.attrs = bk_attrs;
777 } else {
778 /* copy bk in msg */
779 if (_branch_2_msg( dsct, &bk, msg)<0)

Callers 1

w_swap_msg_branchesFunction · 0.85

Calls 3

_msg_2_branchFunction · 0.85
_copy_branchFunction · 0.85
_branch_2_msgFunction · 0.85

Tested by

no test coverage detected