@@ -21,15 +21,15 @@ import (
2121
2222// SessionKey - Session Key for Session Storage
2323type SessionKey struct {
24- CallID sip.CallID
25- BranchID sip.MaybeString
24+ CallID sip.CallID
25+ TagID sip.MaybeString
2626}
2727
2828// NewSessionKey - Build a Session Key quickly
29- func NewSessionKey (callID sip.CallID , branchID sip.MaybeString ) SessionKey {
29+ func NewSessionKey (callID sip.CallID , tagID sip.MaybeString ) SessionKey {
3030return SessionKey {
31- CallID : callID ,
32- BranchID : branchID ,
31+ CallID : callID ,
32+ TagID : tagID ,
3333}
3434}
3535
@@ -188,9 +188,10 @@ func (ua *UserAgent) InviteWithContext(ctx context.Context, profile *account.Pro
188188}
189189
190190callID , ok := (* request ).CallID ()
191- if ok {
192- branchID := utils .GetBranchID (* request )
193- if v , found := ua .iss .Load (NewSessionKey (* callID , branchID )); found {
191+ fromHeader , ok2 := (* request ).From ()
192+ if ok && ok2 {
193+ fromTag , _ := fromHeader .Params .Get ("tag" )
194+ if v , found := ua .iss .Load (NewSessionKey (* callID , fromTag )); found {
194195return v .(* session.Session ), nil
195196}
196197}
@@ -233,11 +234,12 @@ func (ua *UserAgent) handleBye(request sip.Request, tx sip.ServerTransaction) {
233234
234235tx .Respond (response )
235236callID , ok := request .CallID ()
236- if ok {
237- branchID := utils .GetBranchID (request )
238- if v , found := ua .iss .Load (NewSessionKey (* callID , branchID )); found {
237+ toHeader , ok2 := request .To ()
238+ if ok && ok2 {
239+ toTag , _ := toHeader .Params .Get ("tag" )
240+ if v , found := ua .iss .Load (NewSessionKey (* callID , toTag )); found {
239241is := v .(* session.Session )
240- ua .iss .Delete (NewSessionKey (* callID , branchID ))
242+ ua .iss .Delete (NewSessionKey (* callID , toTag ))
241243var transaction sip.Transaction = tx .(sip.Transaction )
242244ua .handleInviteState (is , & request , & response , session .Terminated , & transaction )
243245}
@@ -251,11 +253,12 @@ func (ua *UserAgent) handleCancel(request sip.Request, tx sip.ServerTransaction)
251253tx .Respond (response )
252254
253255callID , ok := request .CallID ()
254- if ok {
255- branchID := utils .GetBranchID (request )
256- if v , found := ua .iss .Load (NewSessionKey (* callID , branchID )); found {
256+ fromHeader , ok2 := request .From ()
257+ if ok && ok2 {
258+ fromTag , _ := fromHeader .Params .Get ("tag" )
259+ if v , found := ua .iss .Load (NewSessionKey (* callID , fromTag )); found {
257260is := v .(* session.Session )
258- ua .iss .Delete (NewSessionKey (* callID , branchID ))
261+ ua .iss .Delete (NewSessionKey (* callID , fromTag ))
259262var transaction sip.Transaction = tx .(sip.Transaction )
260263is .SetState (session .Canceled )
261264ua .handleInviteState (is , & request , nil , session .Canceled , & transaction )
@@ -266,9 +269,10 @@ func (ua *UserAgent) handleCancel(request sip.Request, tx sip.ServerTransaction)
266269func (ua * UserAgent ) handleACK (request sip.Request , tx sip.ServerTransaction ) {
267270ua .Log ().Debugf ("handleACK => %s, body => %s" , request .Short (), request .Body ())
268271callID , ok := request .CallID ()
269- if ok {
270- branchID := utils .GetBranchID (request )
271- if v , found := ua .iss .Load (NewSessionKey (* callID , branchID )); found {
272+ fromHeader , ok2 := request .From ()
273+ if ok && ok2 {
274+ fromTag , _ := fromHeader .Params .Get ("tag" )
275+ if v , found := ua .iss .Load (NewSessionKey (* callID , fromTag )); found {
272276// handle Ringing or Processing with sdp
273277is := v .(* session.Session )
274278is .SetState (session .Confirmed )
@@ -282,10 +286,11 @@ func (ua *UserAgent) handleInvite(request sip.Request, tx sip.ServerTransaction)
282286ua .Log ().Debugf ("handleInvite => %s, body => %s" , request .Short (), request .Body ())
283287
284288callID , ok := request .CallID ()
285- if ok {
289+ fromHeader , ok2 := request .From ()
290+ if ok && ok2 {
291+ fromTag , _ := fromHeader .Params .Get ("tag" )
286292var transaction sip.Transaction = tx .(sip.Transaction )
287- branchID := utils .GetBranchID (request )
288- v , found := ua .iss .Load (NewSessionKey (* callID , branchID ))
293+ v , found := ua .iss .Load (NewSessionKey (* callID , fromTag ))
289294if toHdr , ok := request .To (); ok && toHdr .Params .Has ("tag" ) {
290295if found {
291296is := v .(* session.Session )
@@ -307,7 +312,7 @@ func (ua *UserAgent) handleInvite(request sip.Request, tx sip.ServerTransaction)
307312contactHdr .Address = contactAddr
308313
309314is := session .NewInviteSession (ua .RequestWithContext , "UAS" , contactHdr , request , * callID , transaction , session .Incoming , ua .Log ())
310- ua .iss .Store (NewSessionKey (* callID , branchID ), is )
315+ ua .iss .Store (NewSessionKey (* callID , fromTag ), is )
311316is .SetState (session .InviteReceived )
312317ua .handleInviteState (is , & request , nil , session .InviteReceived , & transaction )
313318is .SetState (session .WaitingForAnswer )
@@ -320,10 +325,12 @@ func (ua *UserAgent) handleInvite(request sip.Request, tx sip.ServerTransaction)
320325if cancel != nil {
321326ua .Log ().Debugf ("Cancel => %s, body => %s" , cancel .Short (), cancel .Body ())
322327response := sip .NewResponseFromRequest (cancel .MessageID (), cancel , 200 , "OK" , "" )
323- if callID , ok := response .CallID (); ok {
324- branchID := utils .GetBranchID (cancel )
325- if v , found := ua .iss .Load (NewSessionKey (* callID , branchID )); found {
326- ua .iss .Delete (NewSessionKey (* callID , branchID ))
328+ callID , ok := response .CallID ()
329+ fromHeader , ok2 := request .From ()
330+ if ok && ok2 {
331+ fromTag , _ := fromHeader .Params .Get ("tag" )
332+ if v , found := ua .iss .Load (NewSessionKey (* callID , fromTag )); found {
333+ ua .iss .Delete (NewSessionKey (* callID , fromTag ))
327334is := v .(* session.Session )
328335is .SetState (session .Canceled )
329336ua .handleInviteState (is , & request , & response , session .Canceled , nil )
@@ -358,14 +365,17 @@ func (ua *UserAgent) RequestWithContext(ctx context.Context, request sip.Request
358365var cts sip.Transaction = tx .(sip.Transaction )
359366
360367if request .IsInvite () {
361- if callID , ok := request .CallID (); ok {
362- branchID := utils .GetBranchID (request )
363- if _ , found := ua .iss .Load (NewSessionKey (* callID , branchID )); ! found {
368+
369+ callID , ok := request .CallID ()
370+ fromHeader , ok2 := request .From ()
371+ if ok && ok2 {
372+ fromTag , _ := fromHeader .Params .Get ("tag" )
373+ if _ , found := ua .iss .Load (NewSessionKey (* callID , fromTag )); ! found {
364374contactHdr , _ := request .Contact ()
365375contactAddr := ua .updateContact2UAAddr (request .Transport (), contactHdr .Address )
366376contactHdr .Address = contactAddr
367377is := session .NewInviteSession (ua .RequestWithContext , "UAC" , contactHdr , request , * callID , cts , session .Outgoing , ua .Log ())
368- ua .iss .Store (NewSessionKey (* callID , branchID ), is )
378+ ua .iss .Store (NewSessionKey (* callID , fromTag ), is )
369379is .ProvideOffer (request .Body ())
370380is .SetState (session .InviteSent )
371381ua .handleInviteState (is , & request , nil , session .InviteSent , & cts )
@@ -491,9 +501,10 @@ func (ua *UserAgent) RequestWithContext(ctx context.Context, request sip.Request
491501select {
492502case provisional := <- provisionals :
493503callID , ok := provisional .CallID ()
494- if ok {
495- branchID := utils .GetBranchID (provisional )
496- if v , found := ua .iss .Load (NewSessionKey (* callID , branchID )); found {
504+ fromHeader , ok2 := provisional .From ()
505+ if ok && ok2 {
506+ fromTag , _ := fromHeader .Params .Get ("tag" )
507+ if v , found := ua .iss .Load (NewSessionKey (* callID , fromTag )); found {
497508is := v .(* session.Session )
498509is .StoreResponse (provisional )
499510// handle Ringing or Processing with sdp
@@ -514,28 +525,30 @@ func (ua *UserAgent) RequestWithContext(ctx context.Context, request sip.Request
514525request := (err .(* sip.RequestError )).Request
515526response := (err .(* sip.RequestError )).Response
516527callID , ok := request .CallID ()
517- if ok {
518- branchID := utils .GetBranchID (request )
519- if v , found := ua .iss .Load (NewSessionKey (* callID , branchID )); found {
528+ fromHeader , ok2 := request .From ()
529+ if ok && ok2 {
530+ fromTag , _ := fromHeader .Params .Get ("tag" )
531+ if v , found := ua .iss .Load (NewSessionKey (* callID , fromTag )); found {
520532is := v .(* session.Session )
521- ua .iss .Delete (NewSessionKey (* callID , branchID ))
533+ ua .iss .Delete (NewSessionKey (* callID , fromTag ))
522534is .SetState (session .Failure )
523535ua .handleInviteState (is , & request , & response , session .Failure , nil )
524536}
525537}
526538return nil , err
527539case response := <- responses :
528540callID , ok := response .CallID ()
529- if ok {
530- branchID := utils .GetBranchID (response )
531- if v , found := ua .iss .Load (NewSessionKey (* callID , branchID )); found {
541+ fromHeader , ok2 := request .From ()
542+ if ok && ok2 {
543+ fromTag , _ := fromHeader .Params .Get ("tag" )
544+ if v , found := ua .iss .Load (NewSessionKey (* callID , fromTag )); found {
532545if request .IsInvite () {
533546is := v .(* session.Session )
534547is .SetState (session .Confirmed )
535548ua .handleInviteState (is , & request , & response , session .Confirmed , nil )
536549} else if request .Method () == sip .BYE {
537550is := v .(* session.Session )
538- ua .iss .Delete (NewSessionKey (* callID , branchID ))
551+ ua .iss .Delete (NewSessionKey (* callID , fromTag ))
539552is .SetState (session .Terminated )
540553ua .handleInviteState (is , & request , & response , session .Terminated , nil )
541554}
0 commit comments