浏览代码

uac: Fix From/To header restore with dialog store

When replacing From/To header and using dialog module to store original
URIs (modparam restore_dlg=1), restoring of headers does not work for
replies to in-dialog requests sent upstream.
Add in-dialog request's direction to TM callback parameter, so correct
URIs are restored for replies to upstream in-dialog requests.
Bastian Triller 2 月之前
父节点
当前提交
0d4ffb74a9
共有 1 个文件被更改,包括 16 次插入5 次删除
  1. 16 5
      src/modules/uac/replace.c

+ 16 - 5
src/modules/uac/replace.c

@@ -810,15 +810,22 @@ void restore_uris_reply(struct cell *t, int type, struct tmcb_params *p)
 	struct sip_msg *req;
 	struct sip_msg *rpl;
 	int_str avp_value;
+	unsigned int direction = 0;
 
 	if(!t || !t->uas.request || !p->rpl)
 		return;
 
+	if(*p->param) {
+		direction = (unsigned int)(unsigned long)*p->param;
+	}
+
 	req = t->uas.request;
 	rpl = p->rpl;
 
-	if(req->msg_flags & FL_USE_UAC_FROM) {
-
+	if(((req->msg_flags & FL_USE_UAC_FROM)
+			   && (!direction || direction == DLG_DIR_DOWNSTREAM))
+			|| ((req->msg_flags & FL_USE_UAC_TO)
+					&& direction == DLG_DIR_UPSTREAM)) {
 		/* parse FROM in reply */
 		if(parse_from_header(rpl) < 0) {
 			LM_ERR("failed to find/parse FROM hdr\n");
@@ -835,8 +842,11 @@ void restore_uris_reply(struct cell *t, int type, struct tmcb_params *p)
 			LM_ERR("failed to restore FROM\n");
 		}
 	}
-	if(req->msg_flags & FL_USE_UAC_TO) {
 
+	if(((req->msg_flags & FL_USE_UAC_TO)
+			   && (!direction || direction == DLG_DIR_DOWNSTREAM))
+			|| ((req->msg_flags & FL_USE_UAC_FROM)
+					&& direction == DLG_DIR_UPSTREAM)) {
 		/* parse TO in reply */
 		if(rpl->to == 0
 				&& (parse_headers(rpl, HDR_TO_F, 0) != 0 || rpl->to == 0)) {
@@ -997,8 +1007,9 @@ static void replace_callback(
 	/* register tm callback to change replies,
 	 * but only if not registered earlier */
 	if(!(msg->msg_flags & (FL_USE_UAC_FROM | FL_USE_UAC_TO))
-			&& uac_tmb.register_tmcb(
-					   msg, 0, TMCB_RESPONSE_IN, restore_uris_reply, 0, 0)
+			&& uac_tmb.register_tmcb(msg, 0, TMCB_RESPONSE_IN,
+					   restore_uris_reply,
+					   (void *)(unsigned long)_params->direction, 0)
 					   != 1) {
 		LM_ERR("failed to install TM callback\n");
 		return;