Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for RFC3264. #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 38 additions & 6 deletions sippy/CCEvents.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def __init__(self, data = None, rtime = None, origin = None):
def getData(self):
return self.data

def getBody(self):
return None

def getCopy(self):
cself = self.__class__(self.data, self.rtime, self.origin)
if self.reason != None:
Expand All @@ -73,17 +76,34 @@ def getCopy(self):
def onUacSetupComplete(self, uac):
pass

def getBody(self):
if self.data != None:
return self.data[4]
return None

class CCEventRing(CCEventGeneric):
name = 'CCEventRing'
pass

def getBody(self):
if self.data != None:
return self.data[2]
return None

class CCEventPreConnect(CCEventGeneric):
name = 'CCEventPreConnect'
pass

def getBody(self):
if self.data != None:
return self.data[2]
return None

class CCEventConnect(CCEventGeneric):
name = 'CCEventConnect'
pass

def getBody(self):
if self.data != None:
return self.data[2]
return None

class CCEventUpdate(CCEventGeneric):
name = 'CCEventUpdate'
Expand All @@ -94,13 +114,20 @@ def getCopy(self):
cself.max_forwards = self.max_forwards
return cself

def getBody(self):
return self.data

class CCEventInfo(CCEventGeneric):
name = 'CCEventInfo'
pass

def getBody(self):
return self.data

class CCEventDisconnect(CCEventGeneric):
name = 'CCEventDisconnect'
pass

def getBody(self):
return None

from sippy.SipHeader import SipHeader
from sippy.SipWarning import SipWarning
Expand All @@ -119,6 +146,11 @@ def getCopy(self):
def setWarning(self, eistr):
self.warning = SipHeader(body = SipWarning(text = eistr))

def getBody(self):
return None

class CCEventRedirect(CCEventGeneric):
name = 'CCEventRedirect'
pass

def getBody(self):
return None
24 changes: 12 additions & 12 deletions sippy/Rtp_proxy_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,8 @@ class _rtpps_side(object):
codecs = None
raddress = None
laddress = None
origin = None
oh_remote = None
repacketize = None

def __init__(self):
self.origin = SdpOrigin()

def update(self, rtpps, remote_ip, remote_port, result_callback, options = '', index = 0, \
atype = 'IP4', *callback_parameters):
command = 'U'
Expand Down Expand Up @@ -219,15 +214,20 @@ def _sdp_change_finish(self, cb_args, rtpps, sdp_body, sect, sects, result_callb
fidx = sect.a_headers.index(a_header) + 1
sect.a_headers.insert(fidx, 'ptime:%d' % self.repacketize)
if len([x for x in sects if x.needs_update]) == 0:
if self.oh_remote != None:
if self.oh_remote.session_id != sdp_body.content.o_header.session_id:
self.origin = SdpOrigin()
elif self.oh_remote.version != sdp_body.content.o_header.version:
self.origin.version += 1
self.oh_remote = sdp_body.content.o_header.getCopy()
sdp_body.content.o_header = self.origin.getCopy()
if rtpps.insert_nortpp:
sdp_body.content += 'a=nortpproxy:yes\r\n'
sdp_body.content += 'a=nortpproxy:yes\r\n'
# RFC4566
# *******
# For privacy reasons, it is sometimes desirable to obfuscate the
# username and IP address of the session originator. If this is a
# concern, an arbitrary <username> and private <unicast-address> MAY be
# chosen to populate the "o=" field, provided that these are selected
# in a manner that does not affect the global uniqueness of the field.
# *******
sdp_body.content.o_header.address = '192.0.2.1' # 192.0.2.0/24 (TEST-NET-1)
sdp_body.content.o_header.network_type = 'IN'
sdp_body.content.o_header.address_type = 'IP4'
sdp_body.needs_update = False
result_callback(sdp_body)

Expand Down
38 changes: 38 additions & 0 deletions sippy/SdpSession.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright (c) 2003-2005 Maxim Sobolev. All rights reserved.
# Copyright (c) 2006-2019 Sippy Software, Inc. All rights reserved.
#
# Warning: This computer program is protected by copyright law and
# international treaties. Unauthorized reproduction or distribution of this
# program, or any portion of it, may result in severe civil and criminal
# penalties, and will be prosecuted under the maximum extent possible under
# law.

from SdpOrigin import SdpOrigin

class SdpSession:
last_origin = None
origin = None

def __init__(self, origin = None):
if origin != None:
self.origin = origin
else:
self.origin = SdpOrigin()

def fixup_version(self, event):
body = event.getBody()
if body == None:
return # no SDP so there is nothing to do
try:
body.parse()
except:
# not an SDP
return
new_origin = body.content.o_header.getCopy()
if self.last_origin != None:
if self.last_origin.session_id != new_origin.session_id or \
self.last_origin.version != new_origin.version:
self.origin.version += 1
self.last_origin = new_origin
body.content.o_header = self.origin.getCopy()
body.needs_update = False
15 changes: 14 additions & 1 deletion sippy/b2bua_radius.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
from sippy.StatefulProxy import StatefulProxy
from sippy.misc import daemonize
from sippy.B2BRoute import B2BRoute
from sippy.SdpOrigin import SdpOrigin
from sippy.SdpSession import SdpSession

import gc, getopt, os
from re import sub
Expand Down Expand Up @@ -102,6 +104,17 @@ class CCStateDead(object):
class CCStateDisconnecting(object):
sname = 'Disconnecting'

class RFC3264UA(UA):
def __init__(self, *args, **kwargs):
origin = SdpOrigin()
origin.address = '192.0.2.1' # 192.0.2.0/24 (TEST-NET-1)
self.sdp_session = SdpSession(origin)
UA.__init__(self, *args, **kwargs)

def recvEvent(self, event):
self.sdp_session.fixup_version(event)
return UA.recvEvent(self, event)

class CallController(object):
id = 1
uaA = None
Expand All @@ -127,7 +140,7 @@ def __init__(self, remote_ip, source, global_config, pass_headers):
self.id = CallController.id
CallController.id += 1
self.global_config = global_config
self.uaA = UA(self.global_config, event_cb = self.recvEvent, conn_cbs = (self.aConn,), disc_cbs = (self.aDisc,), \
self.uaA = RFC3264UA(self.global_config, event_cb = self.recvEvent, conn_cbs = (self.aConn,), disc_cbs = (self.aDisc,), \
fail_cbs = (self.aDisc,), dead_cbs = (self.aDead,))
self.uaA.kaInterval = self.global_config['keepalive_ans']
self.uaA.local_ua = self.global_config['_uaname']
Expand Down