rem: if (t->flags&T_IS_CANCELLED_FLAG) {  if (t->uac[branch].last_received<=0) cancel_branch(t, branch);
add: if (t->uac[branch].flags&T_UAC_TO_CANCEL_FLAG) {  cancel_branch(t, branch);  t->uac[branch].flags &= ~(T_UAC_TO_CANCEL_FLAG);
context: int reply_received( struct sip_msg  *p_msg ){	int msg_status;	int last_uac_status;	int branch;	int reply_status;	char *ack;	unsigned int ack_len;	unsigned int timer;	/* has the transaction completed now and we need to clean-up? */	branch_bm_t cancel_bitmap;	struct ua_client *uac;	struct cell *t;	str next_hop;	struct usr_avp **backup_list;	/* make sure we know the associated transaction ... */	if (t_check(p_msg, &branch ) == -1) return 1;		/*... if there is none, tell the core router to fwd statelessly */	t = get_t();	if ((t == 0) || (t == T_UNDEFINED)) return 1;	cancel_bitmap=0;	msg_status=p_msg->REPLY_STATUS;	uac=&t->uac[branch];	DBG("DEBUG: reply_received: org. status uas=%d, "		"uac[%d]=%d local=%d is_invite=%d)\n",		t->uas.status, branch, uac->last_received, 		is_local(t), is_invite(t));	last_uac_status=uac->last_received;	/* it's a cancel ... ? */	if (get_cseq(p_msg)->method.len == CANCEL_LEN 	&& memcmp( get_cseq(p_msg)->method.s, CANCEL, CANCEL_LEN) == 0	 /* .. which is not e2e ? ... */	&& is_invite(t) ) {		/* ... then just stop timers */		reset_timer( &uac->local_cancel.retr_timer);		if ( msg_status >= 200 ) {				reset_timer( &uac->local_cancel.fr_timer);		}		DBG("DEBUG: reply to local CANCEL processed\n");		goto done;	}	/* *** stop timers *** */	/* stop retransmission */	reset_timer(&uac->request.retr_timer);		/* stop final response timer only if I got a final response */	if ( msg_status >= 200 ) {		reset_timer( &uac->request.fr_timer);	}	/* acknowledge negative INVITE replies (do it before detailed	 * on_reply processing, which may take very long, like if it	 * is attempted to establish a TCP connection to a fail-over dst */	if (is_invite(t)) {		if (msg_status >= 300) {			ack = build_ack(p_msg, t, branch, &ack_len);			if (ack) {				SEND_PR_BUFFER(&uac->request, ack, ack_len);				shm_free(ack);			}		} else if (is_local(t) && msg_status >= 200) {			ack = build_local_ack(p_msg, t, branch, &ack_len, &next_hop);			if (ack) {				if (send_local_ack(p_msg, &next_hop, ack, ack_len) < 0) {					LOG(L_ERR, "Error while sending local ACK\n");				}				shm_free(ack);			}		}	}	/* processing of on_reply block */	if (t->on_reply) {		rmode = MODE_ONREPLY;		/* transfer transaction flag to message context */		if (t->uas.request) p_msg->flags = t->uas.request->flags;		/* set the as avp_list the one from transaction */		backup_list = set_avp_list(&t->user_avps);		run_actions(onreply_rlist[t->on_reply], p_msg);		/* transfer current message context back to t */		if (t->uas.request) t->uas.request->flags=p_msg->flags;		/* restore original avp list */		set_avp_list( backup_list );	}	/* lock the reply*/	LOCK_REPLIES( t );	if (t->flags&T_IS_CANCELLED_FLAG) {		/* reply for an already canceled transaction -> if the brnach		 * was not cancelled due missing reply, fo it now */		if (t->uac[branch].last_received<=0)			cancel_branch(t, branch);	}	if (is_local(t)) {		reply_status = local_reply(t,p_msg, branch,msg_status,&cancel_bitmap);		if (reply_status == RPS_COMPLETED) {			cleanup_uac_timers(t);			if (is_invite(t)) cancel_uacs(t, cancel_bitmap);			/* There is no need to call set_final_timer because we know			 * that the transaction is local */			put_on_wait(t);		}	} else {		reply_status = relay_reply(t,p_msg,branch,msg_status,&cancel_bitmap);		/* clean-up the transaction when transaction completed */		if (reply_status == RPS_COMPLETED) {			/* no more UAC FR/RETR (if I received a 2xx, there may			 * be still pending branches ...			 */			cleanup_uac_timers(t);			if (is_invite(t)) cancel_uacs(t, cancel_bitmap);			/* FR for negative INVITES, WAIT anything else */			/* set_final_timer(t); */		}	}		if (reply_status == RPS_ERROR)		goto done;		/* update FR/RETR timers on provisional replies */	if (msg_status < 200 && (restart_fr_on_each_reply ||	((last_uac_status<msg_status) &&	((msg_status >= 180) || (last_uac_status == 0)))	) ) { /* provisional now */		if (is_invite(t)) {			/* invite: change FR to longer FR_INV, do not			 * attempt to restart retransmission any more			 */			backup_list = set_avp_list(&t->user_avps);			if (!fr_inv_avp2timer(&timer)) {				DBG("reply_received: FR_INV_TIMER = %d\n", timer);				set_timer(&uac->request.fr_timer,					  FR_INV_TIMER_LIST, &timer);			} else {				set_timer(& uac->request.fr_timer, FR_INV_TIMER_LIST, 0);			}			set_avp_list(backup_list);		} else {			/* non-invite: restart retransmissions (slow now) */			uac->request.retr_list = RT_T2;			set_timer(&uac->request.retr_timer, RT_T2, 0);		}	} /* provisional replies */	done:	/* we are done with the transaction, so unref it - the reference	 * was incremented by t_check() function -bogdan*/	t_unref(p_msg);	/* don't try to relay statelessly neither on success	 * (we forwarded statefully) nor on error; on troubles, 	 * simply do nothing; that will make the other party to 	 * retransmit; hopefuly, we'll then be better off 	 */	return 0;}