Skip to content

Commit

Permalink
Refine exception handling in the filter_SDP(), reference
Browse files Browse the repository at this point in the history
nested SDP callback weakly, so that rtpproxy session can be
destroyed on disconnect.
  • Loading branch information
sobomax committed Jul 28, 2024
1 parent f2b150e commit 4507c9d
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions sippy/b2bua_radius.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import sys
from functools import partial
from os.path import dirname, join as p_join
from weakref import ref as weakref_ref
sys.path.append(p_join(dirname(sys.argv[0]), '..'))

from sippy.Core.EventDispatcher import ED2
Expand Down Expand Up @@ -154,13 +155,16 @@ def __init__(self, remote_ip, source, req_source, req_target, global_config, pas
self.uaA.on_remote_sdp_change = self.filter_SDP

def filter_SDP(self, body, done_cb, prev_orc = None):
if prev_orc is not None and (prev_orc:=prev_orc()) is None:
return
try:
body.parse()
except Exception as ex:
exx = SdpParseError(f'{ex}')
exx.msg = 'Malformed SDP body'
exx.code = 400
raise exx from ex
except Exception as exception:
is_spe = isinstance(exception, SdpParseError)
if not is_spe:
dump_exception('can\'t parse SDP body', extra = body.content)
result_callback(None, ex=exception)
return
allowed_pts = self.global_config['_allowed_pts']
for sect in body.content.sections:
mbody = sect.m_header
Expand All @@ -170,7 +174,8 @@ def filter_SDP(self, body, done_cb, prev_orc = None):
_allowed_pts = [x if isinstance(x, int) else sect.getPTbyName(x) for x in allowed_pts]
mbody.formats = [x for x in mbody.formats if x in _allowed_pts]
if len(mbody.formats) == 0:
raise SdpParseError()
result_callback(None, ex=SdpParseError())
return
if old_len > len(mbody.formats):
sect.optimize_a()
if prev_orc is not None:
Expand Down Expand Up @@ -349,6 +354,8 @@ def placeOriginate(self, oroute):
self.proxied = True
if '_allowed_pts' in self.global_config:
prev_orc = self.uaO.on_remote_sdp_change
if prev_orc is not None:
prev_orc = weakref_ref(prev_orc)
self.uaO.on_remote_sdp_change = partial(self.filter_SDP, prev_orc=prev_orc)
self.uaO.kaInterval = self.global_config['keepalive_orig']
if 'group_timeout' in oroute.params:
Expand Down

0 comments on commit 4507c9d

Please sign in to comment.