From b6e9d7c790a9327b0bee0263308a90a8272226c4 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Wed, 13 Apr 2022 11:43:17 +0200 Subject: [PATCH] sgsip: reuse via from INVITE request for ACK of failure responses - GH #4 --- sgsip/sgsip.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/sgsip/sgsip.go b/sgsip/sgsip.go index c98ee33..3446029 100644 --- a/sgsip/sgsip.go +++ b/sgsip/sgsip.go @@ -1071,17 +1071,21 @@ func SGSIPInviteToACKString(invReq *SGSIPMessage, invRpl *SGSIPMessage, outputSt for _, h := range invReq.Headers { switch h.HType { case HeaderTypeVia: - sList := strings.SplitN(h.Body, ";branch=", 2) - if len(sList) < 2 { + if invRpl.FLine.Code >= 300 { sb.WriteString(h.Name + ": " + h.Body + "\r\n") } else { - idxSCol := strings.Index(sList[1], ";") - if idxSCol < 0 { - sb.WriteString(h.Name + ": " + sList[0] + ";branch=" + - viaBranchCookie + uuid.New().String() + "\r\n") + sList := strings.SplitN(h.Body, ";branch=", 2) + if len(sList) < 2 { + sb.WriteString(h.Name + ": " + h.Body + "\r\n") } else { - sb.WriteString(h.Name + ": " + sList[0] + ";branch=" + - viaBranchCookie + uuid.New().String() + sList[1][idxSCol:] + "\r\n") + idxSCol := strings.Index(sList[1], ";") + if idxSCol < 0 { + sb.WriteString(h.Name + ": " + sList[0] + ";branch=" + + viaBranchCookie + uuid.New().String() + "\r\n") + } else { + sb.WriteString(h.Name + ": " + sList[0] + ";branch=" + + viaBranchCookie + uuid.New().String() + sList[1][idxSCol:] + "\r\n") + } } } case HeaderTypeFrom: