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

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