From 55fb025c413993b4e0f0cc257e9700ff7a5d7570 Mon Sep 17 00:00:00 2001 From: Justine Alexandra Roberts Tunney Date: Sat, 11 Apr 2015 15:34:07 -0400 Subject: [PATCH] Revert "Use byte slices for generic header fields." This reverts commit 115aceb0fa806194f01486d4d5bb6cd35631a708. Conflicts: sip/msg_test.go --- example/echo/echo_test.go | 2 +- example/options/options_test.go | 6 +- example/rawsip/rawsip_test.go | 2 +- sip/dialog.go | 2 +- sip/messages.go | 8 +- sip/msg.go | 229 ++++++++++++++++---------------- sip/msg_parse.go | 6 +- sip/msg_parse.rl | 2 +- sip/msg_test.go | 43 +++--- sip/route.go | 6 +- sip/sip.rl | 4 +- util/util.go | 19 +-- 12 files changed, 157 insertions(+), 172 deletions(-) diff --git a/example/echo/echo_test.go b/example/echo/echo_test.go index 4598ee8..0a6195a 100755 --- a/example/echo/echo_test.go +++ b/example/echo/echo_test.go @@ -204,7 +204,7 @@ func TestCallToEchoApp(t *testing.T) { Port: uint16(laddr.Port), }, }, - UserAgent: []byte("gosip/1.o"), + UserAgent: "gosip/1.o", Payload: sdp.New(rtpaddr, sdp.ULAWCodec, sdp.DTMFCodec), } diff --git a/example/options/options_test.go b/example/options/options_test.go index a4a5e9c..511d024 100755 --- a/example/options/options_test.go +++ b/example/options/options_test.go @@ -26,8 +26,8 @@ func TestOptions(t *testing.T) { CallID: util.GenerateCallID(), Method: "OPTIONS", CSeqMethod: "OPTIONS", - Accept: []byte("application/sdp"), - UserAgent: []byte("pokémon/1.o"), + Accept: "application/sdp", + UserAgent: "pokémon/1.o", Request: &sip.URI{ Scheme: "sip", User: "echo", @@ -84,7 +84,7 @@ func TestOptions(t *testing.T) { if !msg.IsResponse() || msg.Status != 200 || msg.Phrase != "OK" { t.Error("Not OK :[") } - if !bytes.Equal(options.CallID, msg.CallID) { + if options.CallID != msg.CallID { t.Error("CallID didnt match") } if options.CSeq != msg.CSeq || options.CSeqMethod != msg.CSeqMethod { diff --git a/example/rawsip/rawsip_test.go b/example/rawsip/rawsip_test.go index 7537c49..be703c3 100755 --- a/example/rawsip/rawsip_test.go +++ b/example/rawsip/rawsip_test.go @@ -41,7 +41,7 @@ func TestRawSIPOptions(t *testing.T) { "Max-Forwards: 70\r\n" + "To: \r\n" + "From: ;tag=" + fromtag + "\r\n" + - "Call-ID: " + string(callid) + "\r\n" + + "Call-ID: " + callid + "\r\n" + "CSeq: " + strconv.Itoa(cseq) + " OPTIONS\r\n" + "Contact: \r\n" + "User-Agent: pokémon/1.o\r\n" + diff --git a/sip/dialog.go b/sip/dialog.go index 0c306cf..b6007a3 100755 --- a/sip/dialog.go +++ b/sip/dialog.go @@ -248,7 +248,7 @@ func (dls *dialogState) handleMessage(msg *Msg) bool { dls.errChan <- errors.New("Remote UA is using a strange SIP version") return false } - if !bytes.Equal(msg.CallID, dls.request.CallID) { + if msg.CallID != dls.request.CallID { log.Printf("Received message doesn't match dialog") return dls.send(NewResponse(msg, StatusCallTransactionDoesNotExist)) } diff --git a/sip/messages.go b/sip/messages.go index 3f23907..5963d43 100644 --- a/sip/messages.go +++ b/sip/messages.go @@ -20,7 +20,7 @@ func NewRequest(tp *Transport, method string, to, from *Addr) *Msg { CallID: util.GenerateCallID(), CSeq: util.GenerateCSeq(), CSeqMethod: method, - UserAgent: []byte(GosipUA), + UserAgent: GosipUA, } } @@ -35,8 +35,8 @@ func NewResponse(msg *Msg, status int) *Msg { CSeq: msg.CSeq, CSeqMethod: msg.CSeqMethod, RecordRoute: msg.RecordRoute, - UserAgent: []byte(GosipUA), - Allow: []byte(GosipAllow), + UserAgent: GosipUA, + Allow: GosipAllow, } } @@ -54,7 +54,7 @@ func NewAck(msg, invite *Msg) *Msg { Route: msg.RecordRoute.Reversed(), Authorization: invite.Authorization, ProxyAuthorization: invite.ProxyAuthorization, - UserAgent: []byte(GosipUA), + UserAgent: GosipUA, } } diff --git a/sip/msg.go b/sip/msg.go index f69c095..439cb7b 100755 --- a/sip/msg.go +++ b/sip/msg.go @@ -30,56 +30,52 @@ type Msg struct { Route *Addr // Used for goose routing and loose routing RecordRoute *Addr // Used for loose routing Contact *Addr // Where we send response packets or nil - CallID []byte // Identifies call from INVITE to BYE; never empty, only absent + CallID string // Identifies call from invite to bye CSeq int // Counter for network packet ordering CSeqMethod string // Helps with matching to orig message MaxForwards int // 0 has context specific meaning - UserAgent []byte // Name of the SIP stack + UserAgent string // All the other RFC 3261 headers in plus some extras. - // - // These byte slices will be nil if absent, in which case the header never - // appeared. If they are empty, then the header did appear, but without a - // value. - Accept []byte - AcceptContact []byte - AcceptEncoding []byte - AcceptLanguage []byte - AlertInfo []byte - Allow []byte - AllowEvents []byte - AuthenticationInfo []byte - Authorization []byte - CallInfo []byte - ContentDisposition []byte - ContentEncoding []byte - ContentLanguage []byte - Date []byte - ErrorInfo []byte - Event []byte + Accept string + AcceptContact string + AcceptEncoding string + AcceptLanguage string + AlertInfo string + Allow string + AllowEvents string + AuthenticationInfo string + Authorization string + CallInfo string + ContentDisposition string + ContentEncoding string + ContentLanguage string + Date string + ErrorInfo string + Event string Expires int // Seconds registration should expire. - InReplyTo []byte - MIMEVersion []byte + InReplyTo string + MIMEVersion string MinExpires int // Registrars need this when responding - Organization []byte + Organization string PAssertedIdentity *Addr // P-Asserted-Identity or nil (used for PSTN ANI) - Priority []byte - ProxyAuthenticate []byte - ProxyAuthorization []byte - ProxyRequire []byte - ReferTo []byte - ReferredBy []byte + Priority string + ProxyAuthenticate string + ProxyAuthorization string + ProxyRequire string + ReferTo string + ReferredBy string RemotePartyID *Addr // Evil twin of P-Asserted-Identity. - ReplyTo []byte - Require []byte - RetryAfter []byte - Server []byte - Subject []byte - Supported []byte - Timestamp []byte - Unsupported []byte - WWWAuthenticate []byte - Warning []byte + ReplyTo string + Require string + RetryAfter string + Server string + Subject string + Supported string + Timestamp string + Unsupported string + WWWAuthenticate string + Warning string // Extension headers. XHeader *XHeader @@ -138,15 +134,14 @@ func (msg *Msg) Append(b *bytes.Buffer) { msg.appendVersion(b) b.WriteString("\r\n") } else { + if msg.Phrase == "" { + msg.Phrase = Phrase(msg.Status) + } msg.appendVersion(b) b.WriteString(" ") b.WriteString(strconv.Itoa(msg.Status)) b.WriteString(" ") - if msg.Phrase == "" { - b.WriteString(Phrase(msg.Status)) - } else { - b.WriteString(msg.Phrase) - } + b.WriteString(msg.Phrase) b.WriteString("\r\n") } @@ -183,7 +178,7 @@ func (msg *Msg) Append(b *bytes.Buffer) { } b.WriteString("Call-ID: ") - b.Write(msg.CallID) + b.WriteString(msg.CallID) b.WriteString("\r\n") b.WriteString("CSeq: ") @@ -192,9 +187,9 @@ func (msg *Msg) Append(b *bytes.Buffer) { b.WriteString(msg.CSeqMethod) b.WriteString("\r\n") - if msg.UserAgent != nil { + if msg.UserAgent != "" { b.WriteString("User-Agent: ") - b.Write(msg.UserAgent) + b.WriteString(msg.UserAgent) b.WriteString("\r\n") } @@ -208,93 +203,93 @@ func (msg *Msg) Append(b *bytes.Buffer) { } } - if msg.Accept != nil { + if msg.Accept != "" { b.WriteString("Accept: ") - b.Write(msg.Accept) + b.WriteString(msg.Accept) b.WriteString("\r\n") } - if msg.AcceptEncoding != nil { + if msg.AcceptEncoding != "" { b.WriteString("Accept-Encoding: ") - b.Write(msg.AcceptEncoding) + b.WriteString(msg.AcceptEncoding) b.WriteString("\r\n") } - if msg.AcceptLanguage != nil { + if msg.AcceptLanguage != "" { b.WriteString("Accept-Language: ") - b.Write(msg.AcceptLanguage) + b.WriteString(msg.AcceptLanguage) b.WriteString("\r\n") } - if msg.AlertInfo != nil { + if msg.AlertInfo != "" { b.WriteString("Alert-Info: ") - b.Write(msg.AlertInfo) + b.WriteString(msg.AlertInfo) b.WriteString("\r\n") } - if msg.Allow != nil { + if msg.Allow != "" { b.WriteString("Allow: ") - b.Write(msg.Allow) + b.WriteString(msg.Allow) b.WriteString("\r\n") } - if msg.AllowEvents != nil { + if msg.AllowEvents != "" { b.WriteString("Allow-Events: ") - b.Write(msg.AllowEvents) + b.WriteString(msg.AllowEvents) b.WriteString("\r\n") } - if msg.AuthenticationInfo != nil { + if msg.AuthenticationInfo != "" { b.WriteString("Authentication-Info: ") - b.Write(msg.AuthenticationInfo) + b.WriteString(msg.AuthenticationInfo) b.WriteString("\r\n") } - if msg.Authorization != nil { + if msg.Authorization != "" { b.WriteString("Authorization: ") - b.Write(msg.Authorization) + b.WriteString(msg.Authorization) b.WriteString("\r\n") } - if msg.CallInfo != nil { + if msg.CallInfo != "" { b.WriteString("Call-Info: ") - b.Write(msg.CallInfo) + b.WriteString(msg.CallInfo) b.WriteString("\r\n") } - if msg.ContentDisposition != nil { + if msg.ContentDisposition != "" { b.WriteString("Content-Disposition: ") - b.Write(msg.ContentDisposition) + b.WriteString(msg.ContentDisposition) b.WriteString("\r\n") } - if msg.ContentEncoding != nil { + if msg.ContentEncoding != "" { b.WriteString("Content-Encoding: ") - b.Write(msg.ContentEncoding) + b.WriteString(msg.ContentEncoding) b.WriteString("\r\n") } - if msg.ContentLanguage != nil { + if msg.ContentLanguage != "" { b.WriteString("Content-Language: ") - b.Write(msg.ContentLanguage) + b.WriteString(msg.ContentLanguage) b.WriteString("\r\n") } - if msg.Date != nil { + if msg.Date != "" { b.WriteString("Date: ") - b.Write(msg.Date) + b.WriteString(msg.Date) b.WriteString("\r\n") } - if msg.ErrorInfo != nil { + if msg.ErrorInfo != "" { b.WriteString("Error-Info: ") - b.Write(msg.ErrorInfo) + b.WriteString(msg.ErrorInfo) b.WriteString("\r\n") } - if msg.Event != nil { + if msg.Event != "" { b.WriteString("Event: ") - b.Write(msg.Event) + b.WriteString(msg.Event) b.WriteString("\r\n") } @@ -305,15 +300,15 @@ func (msg *Msg) Append(b *bytes.Buffer) { b.WriteString("\r\n") } - if msg.InReplyTo != nil { + if msg.InReplyTo != "" { b.WriteString("In-Reply-To: ") - b.Write(msg.InReplyTo) + b.WriteString(msg.InReplyTo) b.WriteString("\r\n") } - if msg.MIMEVersion != nil { + if msg.MIMEVersion != "" { b.WriteString("MIME-Version: ") - b.Write(msg.MIMEVersion) + b.WriteString(msg.MIMEVersion) b.WriteString("\r\n") } @@ -323,9 +318,9 @@ func (msg *Msg) Append(b *bytes.Buffer) { b.WriteString("\r\n") } - if msg.Organization != nil { + if msg.Organization != "" { b.WriteString("Organization: ") - b.Write(msg.Organization) + b.WriteString(msg.Organization) b.WriteString("\r\n") } @@ -335,39 +330,39 @@ func (msg *Msg) Append(b *bytes.Buffer) { b.WriteString("\r\n") } - if msg.Priority != nil { + if msg.Priority != "" { b.WriteString("Priority: ") - b.Write(msg.Priority) + b.WriteString(msg.Priority) b.WriteString("\r\n") } - if msg.ProxyAuthenticate != nil { + if msg.ProxyAuthenticate != "" { b.WriteString("Proxy-Authenticate: ") - b.Write(msg.ProxyAuthenticate) + b.WriteString(msg.ProxyAuthenticate) b.WriteString("\r\n") } - if msg.ProxyAuthorization != nil { + if msg.ProxyAuthorization != "" { b.WriteString("Proxy-Authorization: ") - b.Write(msg.ProxyAuthorization) + b.WriteString(msg.ProxyAuthorization) b.WriteString("\r\n") } - if msg.ProxyRequire != nil { + if msg.ProxyRequire != "" { b.WriteString("Proxy-Require: ") - b.Write(msg.ProxyRequire) + b.WriteString(msg.ProxyRequire) b.WriteString("\r\n") } - if msg.ReferTo != nil { + if msg.ReferTo != "" { b.WriteString("Refer-To: ") - b.Write(msg.ReferTo) + b.WriteString(msg.ReferTo) b.WriteString("\r\n") } - if msg.ReferredBy != nil { + if msg.ReferredBy != "" { b.WriteString("Referred-By: ") - b.Write(msg.ReferredBy) + b.WriteString(msg.ReferredBy) b.WriteString("\r\n") } @@ -377,63 +372,63 @@ func (msg *Msg) Append(b *bytes.Buffer) { b.WriteString("\r\n") } - if msg.ReplyTo != nil { + if msg.ReplyTo != "" { b.WriteString("Reply-To: ") - b.Write(msg.ReplyTo) + b.WriteString(msg.ReplyTo) b.WriteString("\r\n") } - if msg.Require != nil { + if msg.Require != "" { b.WriteString("Require: ") - b.Write(msg.Require) + b.WriteString(msg.Require) b.WriteString("\r\n") } - if msg.RetryAfter != nil { + if msg.RetryAfter != "" { b.WriteString("RetryAfter: ") - b.Write(msg.RetryAfter) + b.WriteString(msg.RetryAfter) b.WriteString("\r\n") } - if msg.Server != nil { + if msg.Server != "" { b.WriteString("Server: ") - b.Write(msg.Server) + b.WriteString(msg.Server) b.WriteString("\r\n") } - if msg.Subject != nil { + if msg.Subject != "" { b.WriteString("Subject: ") - b.Write(msg.Subject) + b.WriteString(msg.Subject) b.WriteString("\r\n") } - if msg.Supported != nil { + if msg.Supported != "" { b.WriteString("Supported: ") - b.Write(msg.Supported) + b.WriteString(msg.Supported) b.WriteString("\r\n") } - if msg.Timestamp != nil { + if msg.Timestamp != "" { b.WriteString("Timestamp: ") - b.Write(msg.Timestamp) + b.WriteString(msg.Timestamp) b.WriteString("\r\n") } - if msg.Unsupported != nil { + if msg.Unsupported != "" { b.WriteString("Unsupported: ") - b.Write(msg.Unsupported) + b.WriteString(msg.Unsupported) b.WriteString("\r\n") } - if msg.Warning != nil { + if msg.Warning != "" { b.WriteString("Warning: ") - b.Write(msg.Warning) + b.WriteString(msg.Warning) b.WriteString("\r\n") } - if msg.WWWAuthenticate != nil { + if msg.WWWAuthenticate != "" { b.WriteString("WWW-Authenticate: ") - b.Write(msg.WWWAuthenticate) + b.WriteString(msg.WWWAuthenticate) b.WriteString("\r\n") } diff --git a/sip/msg_parse.go b/sip/msg_parse.go index c642345..6b823e2 100644 --- a/sip/msg_parse.go +++ b/sip/msg_parse.go @@ -61,7 +61,7 @@ func ParseMsgBytes(data []byte) (msg *Msg, err error) { ctype := "" var name string var hex byte - var value *[]byte + var value *string var via *Via var addrp **Addr var addr *Addr @@ -9591,7 +9591,7 @@ tr403: { b := data[mark:p - 1] if value != nil { - *value = b + *value = string(b) } else { msg.XHeader = &XHeader{name, b, msg.XHeader} } @@ -11776,7 +11776,7 @@ tr553: tr557: //line sip.rl:202 - msg.CallID = data[mark:p] + msg.CallID = string(data[mark:p]) goto st381 tr643: diff --git a/sip/msg_parse.rl b/sip/msg_parse.rl index 4672893..623a441 100644 --- a/sip/msg_parse.rl +++ b/sip/msg_parse.rl @@ -38,7 +38,7 @@ func ParseMsgBytes(data []byte) (msg *Msg, err error) { ctype := "" var name string var hex byte - var value *[]byte + var value *string var via *Via var addrp **Addr var addr *Addr diff --git a/sip/msg_test.go b/sip/msg_test.go index e1e6495..78aa965 100755 --- a/sip/msg_test.go +++ b/sip/msg_test.go @@ -124,12 +124,12 @@ var msgTests = []msgTest{ VersionMajor: 2, Status: 200, Phrase: "OK", - Warning: []byte("Morning and evening\r\n" + + Warning: "Morning and evening\r\n" + " Maids heard the goblins cry:\r\n" + " “Come buy our orchard fruits,\r\n" + " Come buy, come buy:\r\n" + " Apples and quinces,\r\n" + - " Lemons and oranges"), + " Lemons and oranges", }, }, @@ -148,12 +148,12 @@ var msgTests = []msgTest{ VersionMajor: 2, Status: 200, Phrase: "OK", - Warning: []byte("Morning and evening\r\n" + + Warning: "Morning and evening\r\n" + " Maids heard the goblins cry:\r\n" + " “Come buy our orchard fruits,\r\n" + " Come buy, come buy:\r\n" + " Apples and quinces,\r\n" + - " Lemons and oranges"), + " Lemons and oranges", XHeader: &sip.XHeader{"X-LOL", []byte("omfg"), nil}, }, }, @@ -510,7 +510,7 @@ var msgTests = []msgTest{ VersionMajor: 2, Status: 200, Phrase: "OK", - Warning: []byte("Maids heard the goblins cry"), + Warning: "Maids heard the goblins cry", Via: &sip.Via{ Protocol: "SIP", Version: "2.0", @@ -686,7 +686,7 @@ var msgTests = []msgTest{ Method: "OPTIONS", CSeqMethod: "OPTIONS", MaxForwards: 60, - CallID: []byte("e71a163e-c440-474d-a4ec-5cd85a0309c6"), + CallID: "e71a163e-c440-474d-a4ec-5cd85a0309c6", CSeq: 36612, Request: &sip.URI{ Scheme: "sip", @@ -724,8 +724,8 @@ var msgTests = []msgTest{ Port: 42367, }, }, - UserAgent: []byte("ghoul/0.1"), - Accept: []byte("application/sdp"), + UserAgent: "ghoul/0.1", + Accept: "application/sdp", }, }, @@ -759,12 +759,12 @@ var msgTests = []msgTest{ VersionMajor: 2, Status: 200, Phrase: "OK", - CallID: []byte("99042736-d40b-4d96-a81b-867321443ff5"), + CallID: "99042736-d40b-4d96-a81b-867321443ff5", CSeq: 16378, CSeqMethod: "INVITE", - Server: []byte("Asterisk PBX 10.11.1"), - Allow: []byte("INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH"), - Supported: []byte("replaces, timer"), + Server: "Asterisk PBX 10.11.1", + Allow: "INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH", + Supported: "replaces, timer", Via: &sip.Via{ Protocol: "SIP", Version: "2.0", @@ -835,7 +835,7 @@ var msgTests = []msgTest{ VersionMajor: 2, Status: 200, Phrase: "OK", - CallID: []byte("042736d4-0bd9-4681-ab86-7321443ff58a"), + CallID: "042736d4-0bd9-4681-ab86-7321443ff58a", CSeq: 31109, CSeqMethod: "INVITE", Via: &sip.Via{ @@ -936,7 +936,7 @@ var msgTests = []msgTest{ Method: "INVITE", CSeqMethod: "INVITE", MaxForwards: 70, - CallID: []byte("87704115-03b8-122e-08b5-001bfcce6bdf"), + CallID: "87704115-03b8-122e-08b5-001bfcce6bdf", CSeq: 133097268, Request: &sip.URI{ Scheme: "sip", @@ -978,11 +978,11 @@ var msgTests = []msgTest{ // }, // }, }, - UserAgent: []byte("tube/0.1"), - Allow: []byte("INVITE, ACK, BYE, CANCEL, OPTIONS, PRACK, MESSAGE, SUBSCRIBE, NOTIFY, REFER, UPDATE, INFO"), - AllowEvents: []byte("talk"), - ContentDisposition: []byte("session"), - Supported: []byte("timer, 100rel"), + UserAgent: "tube/0.1", + Allow: "INVITE, ACK, BYE, CANCEL, OPTIONS, PRACK, MESSAGE, SUBSCRIBE, NOTIFY, REFER, UPDATE, INFO", + AllowEvents: "talk", + ContentDisposition: "session", + Supported: "timer, 100rel", Payload: &sip.MiscPayload{ T: "application/sdp-lol", D: []byte("v=0\r\n" + @@ -1065,10 +1065,9 @@ var msgTests = []msgTest{ Param: &sip.Param{"tag", "98asjd8", nil}, }, MaxForwards: 68, - CallID: []byte("wsinv.ndaksdj@192.0.2.1"), + CallID: "wsinv.ndaksdj@192.0.2.1", CSeq: 9, CSeqMethod: "INVITE", - Subject: []byte{}, Via: &sip.Via{ Protocol: "SIP", Version: "2.0", @@ -1157,7 +1156,7 @@ var msgTests = []msgTest{ msg: sip.Msg{ VersionMajor: 2, Method: "!interesting-Method0123456789_*+`.%indeed'~", - CallID: []byte("intmeth.word%ZK-!.*_+'@word`~)(><:\\/\"][?}{"), + CallID: "intmeth.word%ZK-!.*_+'@word`~)(><:\\/\"][?}{", CSeq: 139122385, CSeqMethod: "!interesting-Method0123456789_*+`.%indeed'~", MaxForwards: 255, diff --git a/sip/route.go b/sip/route.go index 1ba34db..84df40e 100644 --- a/sip/route.go +++ b/sip/route.go @@ -27,7 +27,7 @@ func PopulateMessage(via *Via, contact *Addr, msg *Msg) { msg.From = msg.Contact.Copy() msg.From.Uri.Param = nil } - if msg.CallID == nil { + if msg.CallID == "" { msg.CallID = util.GenerateCallID() } if msg.CSeq == 0 { @@ -39,8 +39,8 @@ func PopulateMessage(via *Via, contact *Addr, msg *Msg) { if msg.MaxForwards == 0 { msg.MaxForwards = 70 } - if msg.UserAgent == nil { - msg.UserAgent = []byte(GosipUA) + if msg.UserAgent == "" { + msg.UserAgent = GosipUA } if msg.Via.Param.Get("branch") == nil { msg.Via.Param = &Param{"branch", util.GenerateBranch(), msg.Via.Param} diff --git a/sip/sip.rl b/sip/sip.rl index 4eda3b8..4de7456 100644 --- a/sip/sip.rl +++ b/sip/sip.rl @@ -162,7 +162,7 @@ action name { action value {{ b := data[mark:p - 1] if value != nil { - *value = b + *value = string(b) } else { msg.XHeader = &XHeader{name, b, msg.XHeader} } @@ -200,7 +200,7 @@ action Addr { } action CallID { - msg.CallID = data[mark:p] + msg.CallID = string(data[mark:p]) } action ContentLength { diff --git a/util/util.go b/util/util.go index def66b2..e6ce0ac 100755 --- a/util/util.go +++ b/util/util.go @@ -1,7 +1,6 @@ package util import ( - "bytes" "encoding/hex" "math/rand" "net" @@ -71,21 +70,13 @@ func GenerateBranch() string { return "z9hG4bK-" + GenerateTag() } -// Generates a secure UUID4, e.g. f47ac10b-58cc-4372-a567-0e02b2c3d479 -func GenerateCallID() []byte { +// Generates a secure UUID4, e.g.f47ac10b-58cc-4372-a567-0e02b2c3d479 +func GenerateCallID() string { lol := randomBytes(15) digs := hex.EncodeToString(lol) - var b bytes.Buffer - b.WriteString(digs[0:8]) - b.WriteByte('-') - b.WriteString(digs[8:12]) - b.WriteString("-4") - b.WriteString(digs[12:15]) - b.WriteString("-a") - b.WriteString(digs[15:18]) - b.WriteByte('-') - b.WriteString(digs[18:]) - return b.Bytes() + uuid4 := digs[0:8] + "-" + digs[8:12] + "-4" + digs[12:15] + + "-a" + digs[15:18] + "-" + digs[18:] + return uuid4 } // Generates a random ID for an SDP.