Skip to content

Commit

Permalink
fix: always update dialog remote tag from message
Browse files Browse the repository at this point in the history
Remove conditional remote tag checks and ensure tag is always updated
from incoming message's To header. This fixes inconsistencies in dialog
state management and improves reliability of SIP message handling across
all response types (including 503 and other error responses).
  • Loading branch information
moha-abdi committed Nov 27, 2024
1 parent 204d401 commit 439cab1
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions PySIP/sip_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,7 @@ async def message_handler(self, msg: SipMessage):

if msg.status == SIPStatus(401) and msg.method == "INVITE":
# Handling the auth of the invite
if not self.dialogue.remote_tag:
self.dialogue.remote_tag = msg.to_tag or ""
self.dialogue.remote_tag = msg.to_tag
transaction = self.dialogue.find_transaction(msg.branch)
if not transaction:
return
Expand All @@ -664,8 +663,7 @@ async def message_handler(self, msg: SipMessage):
and self.username not in msg.get_header("To")
):
# Handling successfull invite response
if not self.dialogue.remote_tag:
self.dialogue.remote_tag = msg.to_tag or "" # setting it if not set
self.dialogue.remote_tag = msg.to_tag or "" # setting it if not set
logger.log(logging.DEBUG, "INVITE Successfull, dialog is established.")
transaction = self.dialogue.add_transaction(
self.sip_core.gen_branch(), "ACK"
Expand All @@ -683,8 +681,7 @@ async def message_handler(self, msg: SipMessage):
CallState.RINGING if msg.status is SIPStatus(180) else CallState.DIALING
)
await self.update_call_state(st)
if not self.dialogue.remote_tag:
self.dialogue.remote_tag = msg.to_tag or "" # setting it if not already
self.dialogue.remote_tag = msg.to_tag or "" # setting it if not already
self.dialogue.auth_retry_count = 0 # reset the auth counter
pass

Expand Down Expand Up @@ -751,8 +748,8 @@ async def error_handler(self, msg: SipMessage):
if not msg.status:
return

if not self.dialogue.remote_tag:
self.dialogue.remote_tag = msg.to_tag or ""
# reset the remote tag
self.dialogue.remote_tag = msg.to_tag or ""

if not 400 <= msg.status.code <= 699:
return
Expand Down

0 comments on commit 439cab1

Please sign in to comment.