Browse code

uac: restore first display name then uri with dialog callback

- same as for rr callback, otherwise the new header can be malformed:
the case of initial INVITE with From URI having no angle brackets and goes
out with display name and angle brackets, the ACK for 200ok results with
From broken when forwarded
- backport of commit efa6c6a9bf13c430d5be5146168d1ded4c39dba7 (master)
- backport of commit 1a49cc015609c8701057d5a9cf50f68db61870c1 (5.4)

Daniel-Constantin Mierla authored on 07/09/2020 18:35:28
Showing 1 changed files
... ...
@@ -936,26 +936,6 @@ static void replace_callback(struct dlg_cell *dlg, int type,
936 936
 			old_uri.len, old_uri.s, new_display->len, new_display->s,
937 937
 			new_uri->len, new_uri->s);
938 938
 
939
-	/* duplicate the decoded value */
940
-	p = pkg_malloc( new_uri->len);
941
-	if (!p) {
942
-		LM_ERR("no more pkg mem\n");
943
-		return;
944
-	}
945
-	memcpy( p, new_uri->s, new_uri->len);
946
-
947
-	/* build del/add lumps */
948
-	l = del_lump( msg, old_uri.s-msg->buf, old_uri.len, 0);
949
-	if (l==0) {
950
-		LM_ERR("del lump failed\n");
951
-		goto free;
952
-	}
953
-
954
-	if (insert_new_lump_after( l, p, new_uri->len, 0)==0) {
955
-		LM_ERR("insert new lump failed\n");
956
-		goto free;
957
-	}
958
-
959 939
 	/* deal with display name */
960 940
 	l = 0;
961 941
 	/* first remove the existing display */
... ...
@@ -966,8 +946,8 @@ static void replace_callback(struct dlg_cell *dlg, int type,
966 946
 		l = del_lump(msg, body->display.s-msg->buf, body->display.len, 0);
967 947
 		if (l==0) {
968 948
 			LM_ERR("display del lump failed\n");
969
-			goto free;
970
-			}
949
+			return;
950
+		}
971 951
 	}
972 952
 	if (new_display->s && new_display->len > 0) {
973 953
 		LM_DBG("inserting display [%.*s]\n",
... ...
@@ -976,20 +956,40 @@ static void replace_callback(struct dlg_cell *dlg, int type,
976 956
 		buf.s = pkg_malloc(new_display->len + 2);
977 957
 		if (buf.s==0) {
978 958
 			LM_ERR("no more pkg mem\n");
979
-			goto free;
959
+			return;
980 960
 		}
981 961
 		memcpy( buf.s, new_display->s, new_display->len);
982 962
 		buf.len = new_display->len;
983 963
 		if (l==0 && (l=get_display_anchor(msg, hdr, body, &buf)) == 0) {
984 964
 			LM_ERR("failed to insert anchor\n");
985
-			goto free2;
965
+			goto free1;
986 966
 		}
987 967
 		if (insert_new_lump_after(l, buf.s, buf.len, 0) == 0) {
988 968
 			LM_ERR("insert new display lump failed\n");
989
-			goto free2;
969
+			goto free1;
990 970
 		}
991 971
 	}
992 972
 
973
+	/* uri - duplicate the decoded value */
974
+	p = pkg_malloc( new_uri->len);
975
+	if (!p) {
976
+		LM_ERR("no more pkg mem\n");
977
+		return;
978
+	}
979
+	memcpy( p, new_uri->s, new_uri->len);
980
+
981
+	/* build del/add lumps */
982
+	l = del_lump( msg, old_uri.s-msg->buf, old_uri.len, 0);
983
+	if (l==0) {
984
+		LM_ERR("del lump failed\n");
985
+		goto free2;
986
+	}
987
+
988
+	if (insert_new_lump_after( l, p, new_uri->len, 0)==0) {
989
+		LM_ERR("insert new lump failed\n");
990
+		goto free2;
991
+	}
992
+
993 993
 	/* register tm callback to change replies,
994 994
 	 * but only if not registered earlier */
995 995
 	if (!(msg->msg_flags & (FL_USE_UAC_FROM|FL_USE_UAC_TO)) &&
... ...
@@ -1003,10 +1003,10 @@ static void replace_callback(struct dlg_cell *dlg, int type,
1003 1003
 	return;
1004 1004
 
1005 1005
 free2:
1006
-	pkg_free(buf.s);
1007
-
1008
-free:
1009 1006
 	pkg_free(p);
1007
+
1008
+free1:
1009
+	pkg_free(buf.s);
1010 1010
 }
1011 1011
 
1012 1012