rem: LOG(L_ERR, "ERROR: relay_reply: "
add: LOG(L_ERR, "ERROR:tm:relay_reply: "
context: enum rps relay_reply( struct cell *t, struct sip_msg *p_msg, int branch, 	unsigned int msg_status, branch_bm_t *cancel_bitmap ){	int relay;	int save_clone;	char *buf;	/* length of outbound reply */	unsigned int res_len;	int relayed_code;	struct sip_msg *relayed_msg;	struct bookmark bm;	int totag_retr;	enum rps reply_status;	/* retransmission structure of outbound reply and request */	struct retr_buf *uas_rb;	/* keep compiler warnings about use of uninit vars silent */	res_len=0;	buf=0;	relayed_msg=0;	relayed_code=0;	totag_retr=0;	/* remember, what was sent upstream to know whether we are	 * forwarding a first final reply or not */	/* *** store and relay message as needed *** */	reply_status = t_should_relay_response(t, msg_status, branch, 		&save_clone, &relay, cancel_bitmap, p_msg );	DBG("DEBUG: relay_reply: branch=%d, save=%d, relay=%d\n",		branch, save_clone, relay );	/* store the message if needed */	if (save_clone) /* save for later use, typically branch picking */	{		if (!store_reply( t, branch, p_msg ))			goto error01;	}	uas_rb = & t->uas.response;	if (relay >= 0 ) {		/* initialize sockets for outbound reply */		uas_rb->activ_type=msg_status;		/* only messages known to be relayed immediately will be		 * be called on; we do not evoke this callback on messages		 * stored in shmem -- they are fixed and one cannot change them		 * anyway */		if (msg_status<300 && branch==relay		&& has_tran_tmcbs(t,TMCB_RESPONSE_FWDED) ) {			run_trans_callbacks( TMCB_RESPONSE_FWDED, t, t->uas.request,				p_msg, msg_status );		}		/* try building the outbound reply from either the current		 * or a stored message */		relayed_msg = branch==relay ? p_msg :  t->uac[relay].reply;		if (relayed_msg==FAKED_REPLY) {			tm_stats->replied_localy++;			relayed_code = branch==relay				? msg_status : t->uac[relay].last_received;			if (relayed_code>=180 && t->uas.request->to 					&& (get_to(t->uas.request)->tag_value.s==0 			    		|| get_to(t->uas.request)->tag_value.len==0)) {				calc_crc_suffix( t->uas.request, tm_tag_suffix );				buf = build_res_buf_from_sip_req(						relayed_code,						error_text(relayed_code),						&tm_tag,						t->uas.request, &res_len, &bm );			} else {				buf = build_res_buf_from_sip_req( relayed_code,					error_text(relayed_code), 0/* no to-tag */,					t->uas.request, &res_len, &bm );			}		} else {			relayed_code=relayed_msg->REPLY_STATUS;			buf = build_res_buf_from_sip_res( relayed_msg, &res_len );			/* if we build a message from shmem, we need to remove			   via delete lumps which are now stirred in the shmem-ed			   structure			*/			if (branch!=relay) {				free_via_clen_lump(&relayed_msg->add_rm);			}		}		update_reply_stats( relayed_code );		if (!buf) {			LOG(L_ERR, "ERROR: relay_reply: "				"no mem for outbound reply buffer\n");			goto error02;		}		/* attempt to copy the message to UAS's shmem:		   - copy to-tag for ACK matching as well		   -  allocate little a bit more for provisional as		      larger messages are likely to follow and we will be 		      able to reuse the memory frag 		*/		uas_rb->buffer = (char*)shm_resize( uas_rb->buffer, res_len +			(msg_status<200 ?  REPLY_OVERBUFFER_LEN : 0));		if (!uas_rb->buffer) {			LOG(L_ERR, "ERROR: relay_reply: cannot alloc reply shmem\n");			goto error03;		}		uas_rb->buffer_len = res_len;		memcpy( uas_rb->buffer, buf, res_len );		if (relayed_msg==FAKED_REPLY) { /* to-tags for local replies */			update_local_tags(t, &bm, uas_rb->buffer, buf);		}		tm_stats->replied_localy++;		/* update the status ... */		t->uas.status = relayed_code;		t->relaied_reply_branch = relay;		if (is_invite(t) && relayed_msg!=FAKED_REPLY		&& relayed_code>=200 && relayed_code < 300		&& has_tran_tmcbs( t, TMCB_RESPONSE_OUT|TMCB_E2EACK_IN) ) {			totag_retr=update_totag_set(t, relayed_msg);		}	}; /* if relay ... */	UNLOCK_REPLIES( t );	/* Setup retransmission timer _before_ the reply is sent	 * to avoid race conditions	 */	if (reply_status == RPS_COMPLETED) {		set_final_timer(t);	}	/* send it now (from the private buffer) */	if (relay >= 0) {		SEND_PR_BUFFER( uas_rb, buf, res_len );		DBG("DEBUG: reply relayed. buf=%p: %.9s..., shmem=%p: %.9s\n", 			buf, buf, uas_rb->buffer, uas_rb->buffer );		if (!totag_retr && has_tran_tmcbs(t, TMCB_RESPONSE_OUT) ) {			run_trans_callbacks( TMCB_RESPONSE_OUT, t, t->uas.request,				relayed_msg, relayed_code);		}		pkg_free( buf );	}	/* success */	return reply_status;error03:	pkg_free( buf );error02:	if (save_clone) {		if (t->uac[branch].reply!=FAKED_REPLY)			sip_msg_free( t->uac[branch].reply );		t->uac[branch].reply = NULL;		}error01:	t_reply_unsafe( t, t->uas.request, 500, "Reply processing error" );	UNLOCK_REPLIES(t);	if (is_invite(t)) cancel_uacs( t, *cancel_bitmap );	/* a serious error occurred -- attempt to send an error reply;	   it will take care of clean-ups  */	/* failure */	return RPS_ERROR;}