Skip to content

Commit

Permalink
Handle media negotiation exceptions in the response processing
Browse files Browse the repository at this point in the history
gracefully.
  • Loading branch information
sobomax committed Jul 28, 2024
1 parent 6e67716 commit 17d2778
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
10 changes: 4 additions & 6 deletions sippy/UacStateRinging.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@
from sippy.SipAddress import SipAddress
from sippy.SipRoute import SipRoute
from sippy.UaStateGeneric import UaStateGeneric
from sippy.UacStateTrying import UacStateTrying
from sippy.CCEvents import CCEventRing, CCEventConnect, CCEventFail, CCEventRedirect, \
CCEventDisconnect, CCEventPreConnect

class UacStateRinging(UaStateGeneric):
class UacStateRinging(UacStateTrying):
sname = 'Ringing(UAC)'
triedauth = False

def recvResponse(self, resp, tr):
def _recvResponse(self, resp, tr):
body = resp.getBody()
code, reason = resp.getSCode()
scode = (code, reason, body)
Expand Down Expand Up @@ -104,10 +105,7 @@ def recvResponse(self, resp, tr):
self.ua.rAddr = self.ua.routes[0].getTAddr()
else:
self.ua.rAddr = self.ua.rTarget.getTAddr()
req = self.ua.genRequest('BYE')
self.ua.lCSeq += 1
self.ua.global_config['_sip_tm'].newTransaction(req, \
laddress = self.ua.source_address, compact = self.ua.compact_sip)
self.genBYE()
return (UaStateFailed, self.ua.fail_cbs, resp.rtime, self.ua.origin, scode[0])
self.ua.rUri.setTag(tag)
if not self.ua.late_media or body is None:
Expand Down
31 changes: 26 additions & 5 deletions sippy/UacStateTrying.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@
from sippy.Time.Timeout import TimeoutAbsMono
from sippy.CCEvents import CCEventRing, CCEventConnect, CCEventFail, CCEventRedirect, \
CCEventDisconnect, CCEventPreConnect
from sippy.Exceptions.SipParseError import SdpParseError
from sippy.Exceptions.RtpProxyError import RtpProxyError

class UacStateTrying(UaStateGeneric):
sname = 'Trying(UAC)'
triedauth = False

def recvResponse(self, resp, tr):
def _recvResponse(self, resp, tr):
body = resp.getBody()
code, reason = resp.getSCode()
scode = (code, reason, body)
Expand Down Expand Up @@ -122,10 +124,7 @@ def recvResponse(self, resp, tr):
self.ua.rAddr = self.ua.routes[0].getTAddr()
else:
self.ua.rAddr = self.ua.rTarget.getTAddr()
req = self.ua.genRequest('BYE')
self.ua.lCSeq += 1
self.ua.global_config['_sip_tm'].newTransaction(req, \
laddress = self.ua.source_address, compact = self.ua.compact_sip)
self.genBYE()
return (UaStateFailed, self.ua.fail_cbs, resp.rtime, self.ua.origin, scode[0])
self.ua.rUri.setTag(tag)
if not self.ua.late_media or body is None:
Expand Down Expand Up @@ -186,6 +185,28 @@ def recvEvent(self, event):
#print 'wrong event %s in the Trying state' % event
return None

def genBYE(self):
req = self.ua.genRequest('BYE')
self.ua.lCSeq += 1
self.ua.global_config['_sip_tm'].newTransaction(req, \
laddress = self.ua.source_address, compact = self.ua.compact_sip)

def recvResponse(self, resp, tr):
try:
return self._recvResponse(resp, tr)
except (RtpProxyError, SdpParseError) as ex:
scode = (ex.code, ex.msg)
event = CCEventFail(scode, rtime = resp.rtime, origin = self.ua.origin)
event.reason = ex.getReason()
code = resp.getSCode()[0]
if code < 200:
self.ua.global_config['_sip_tm'].cancelTransaction(self.ua.tr, reason = event.reason)
elif code >= 200 and code < 300:
self.genBYE()
self.ua.equeue.append(event)
self.ua.disconnect_ts = resp.rtime
return (UaStateFailed, self.ua.fail_cbs, resp.rtime, self.ua.origin, ex.code)

if not 'UacStateRinging' in globals():
from sippy.UacStateRinging import UacStateRinging
if not 'UaStateFailed' in globals():
Expand Down

0 comments on commit 17d2778

Please sign in to comment.