@@ -66,18 +66,18 @@ func hashPassword(password string) string {
6666 return hex .EncodeToString (hash [:8 ]) // Use first 8 bytes for shorter hash
6767}
6868
69- func (s * Server ) getInvite (from string ) * inProgressInvite {
69+ func (s * Server ) getInvite (sipCallID string ) * inProgressInvite {
7070 s .imu .Lock ()
7171 defer s .imu .Unlock ()
7272 for i := range s .inProgressInvites {
73- if s .inProgressInvites [i ].from == from {
73+ if s .inProgressInvites [i ].sipCallID == sipCallID {
7474 return s .inProgressInvites [i ]
7575 }
7676 }
7777 if len (s .inProgressInvites ) >= digestLimit {
7878 s .inProgressInvites = s .inProgressInvites [1 :]
7979 }
80- is := & inProgressInvite {from : from }
80+ is := & inProgressInvite {sipCallID : sipCallID }
8181 s .inProgressInvites = append (s .inProgressInvites , is )
8282 return is
8383}
@@ -103,8 +103,13 @@ func (s *Server) handleInviteAuth(log logger.Logger, req *sip.Request, tx sip.Se
103103 _ = tx .Respond (sip .NewResponseFromRequest (req , 100 , "Processing" , nil ))
104104 }
105105
106- inviteState := s .getInvite (from )
107- log = log .WithValues ("inviteStateFrom" , from )
106+ // Extract SIP Call ID for tracking in-progress invites
107+ sipCallID := ""
108+ if h := req .CallID (); h != nil {
109+ sipCallID = h .Value ()
110+ }
111+ inviteState := s .getInvite (sipCallID )
112+ log = log .WithValues ("inviteStateSipCallID" , sipCallID )
108113
109114 h := req .GetHeader ("Proxy-Authorization" )
110115 if h == nil {
@@ -144,8 +149,8 @@ func (s *Server) handleInviteAuth(log logger.Logger, req *sip.Request, tx sip.Se
144149
145150 // Check if we have a valid challenge state
146151 if inviteState .challenge .Realm == "" {
147- log .Warnw ("No challenge state found for authentication attempt" , nil ,
148- "from " , from ,
152+ log .Warnw ("No challenge state found for authentication attempt" , errors . New ( "missing challenge state" ) ,
153+ "sipCallID " , sipCallID ,
149154 "expectedRealm" , UserAgent ,
150155 )
151156 _ = tx .Respond (sip .NewResponseFromRequest (req , 401 , "Bad credentials" , nil ))
@@ -178,7 +183,7 @@ func (s *Server) handleInviteAuth(log logger.Logger, req *sip.Request, tx sip.Se
178183 )
179184
180185 if cred .Response != digCred .Response {
181- log .Warnw ("Authentication failed - response mismatch" , nil ,
186+ log .Warnw ("Authentication failed - response mismatch" , errors . New ( "response mismatch" ) ,
182187 "expectedResponse" , digCred .Response ,
183188 "receivedResponse" , cred .Response ,
184189 )
@@ -266,12 +271,19 @@ func (s *Server) processInvite(req *sip.Request, tx sip.ServerTransaction) (retE
266271 cc .Processing ()
267272 }
268273
274+ // Extract SIP Call ID directly from the request
275+ sipCallID := ""
276+ if h := req .CallID (); h != nil {
277+ sipCallID = h .Value ()
278+ }
279+
269280 callInfo := & rpc.SIPCall {
270- LkCallId : callID ,
271- SourceIp : src .Addr ().String (),
272- Address : ToSIPUri ("" , cc .Address ()),
273- From : ToSIPUri ("" , from ),
274- To : ToSIPUri ("" , to ),
281+ LkCallId : callID ,
282+ SipCallId : sipCallID ,
283+ SourceIp : src .Addr ().String (),
284+ Address : ToSIPUri ("" , cc .Address ()),
285+ From : ToSIPUri ("" , from ),
286+ To : ToSIPUri ("" , to ),
275287 }
276288 for _ , h := range cc .RemoteHeaders () {
277289 switch h := h .(type ) {
@@ -1150,14 +1162,17 @@ type sipInbound struct {
11501162}
11511163
11521164func (c * sipInbound ) ValidateInvite () error {
1165+ if c .callID == "" {
1166+ return errors .New ("no Call-ID header in INVITE" )
1167+ }
11531168 if c .from == nil {
1154- return errors .New ("no From header" )
1169+ return errors .New ("no From header in INVITE " )
11551170 }
11561171 if c .to == nil {
1157- return errors .New ("no To header" )
1172+ return errors .New ("no To header in INVITE " )
11581173 }
11591174 if c .tag == "" {
1160- return errors .New ("no tag in From" )
1175+ return errors .New ("no tag in From in INVITE " )
11611176 }
11621177 return nil
11631178}
0 commit comments