Skip to content

Commit

Permalink
Fix missing from tag and branch creation
Browse files Browse the repository at this point in the history
  • Loading branch information
emiago committed Jun 17, 2023
1 parent 7474ae8 commit 500f9f5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
8 changes: 7 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ func clientRequestBuildReq(c *Client, req *sip.Request) error {
// A valid SIP request formulated by a UAC MUST, at a minimum, contain
// the following header fields: To, From, CSeq, Call-ID, Max-Forwards,
// and Via;
ClientRequestAddVia(c, req)
if _, exists := req.Via(); !exists {
// Multi VIA value must be manually added
ClientRequestAddVia(c, req)
}

if _, exists := req.From(); !exists {
from := sip.FromHeader{
Expand All @@ -103,7 +106,9 @@ func clientRequestBuildReq(c *Client, req *sip.Request) error {
UriParams: sip.NewParams(),
Headers: sip.NewParams(),
},
Params: sip.NewParams(),
}
from.Params.Add("tag", sip.GenerateTagN(16))
req.AppendHeader(&from)
}

Expand All @@ -117,6 +122,7 @@ func clientRequestBuildReq(c *Client, req *sip.Request) error {
UriParams: req.Recipient.UriParams,
Headers: req.Recipient.Headers,
},
Params: sip.NewParams(),
}
req.AppendHeader(&to)
}
Expand Down
2 changes: 1 addition & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestClientRequestBuild(t *testing.T) {

from, exists := req.From()
assert.True(t, exists)
assert.Equal(t, "\"sipgo\" <sip:[email protected]>", from.Value())
assert.Equal(t, "\"sipgo\" <sip:[email protected]>;tag="+from.Params["tag"], from.Value())

to, exists := req.To()
assert.True(t, exists)
Expand Down
1 change: 0 additions & 1 deletion sip/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,6 @@ func (h *RecordRouteHeader) cloneFirst() *RecordRouteHeader {
// Copy all headers of one type from one message to another.
// Appending to any headers that were already there.
func CopyHeaders(name string, from, to Message) {
name = HeaderToLower(name)
for _, h := range from.GetHeaders(name) {
to.AppendHeader(h.headerClone())
}
Expand Down
10 changes: 8 additions & 2 deletions sip/sip.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,16 @@ func GenerateBranchN(n int) string {
}

func generateBranchStringWrite(sb *strings.Builder, n int) {
sb.Grow(len(RFC3261BranchMagicCookie) + 33)
sb.Grow(len(RFC3261BranchMagicCookie) + n + 1)
sb.WriteString(RFC3261BranchMagicCookie)
sb.WriteString(".")
RandStringBytesMask(sb, 32)
RandStringBytesMask(sb, n)
}

func GenerateTagN(n int) string {
sb := &strings.Builder{}
RandStringBytesMask(sb, n)
return sb.String()
}

// DefaultPort returns protocol default port by network.
Expand Down

0 comments on commit 500f9f5

Please sign in to comment.