Skip to content

Commit

Permalink
Make authenticate and sending as optional in Stack.app, bug fix for i…
Browse files Browse the repository at this point in the history
…ncorrect uri check in send message, bug fix to do not set viaUri.port to source if rport is not present to work with Columbia sipd, bug fix to treat localhost and 127.0.0.1 also as isLocal for the uri.
  • Loading branch information
kundan10 committed Sep 24, 2011
1 parent dd6080c commit 716052a
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/std/rfc3261.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ def authenticate(self, ua, header): header.password='mypass'; return True
def createTimer(self, cbObj): return timerObject
'the returned timer object must have start() and stop() methods, a delay (int)
attribute, and should invoke cbObj.timedout(timer) when the timer expires.'
Only the authenticate and sending methods are optional. All others are mandatory.
The application must invoke the following callback on the stack:
stack.received(data, src)
Expand Down Expand Up @@ -398,7 +399,7 @@ def send(self, data, dest=None, transport=None):
'''Send a data (Message) to given dest (URI or hostPort), or using the Via header of
response message if dest is missing.'''
if dest and isinstance(dest, URI):
if not uri.host: raise ValueError, 'No host in destination uri'
if not dest.uri.host: raise ValueError, 'No host in destination uri'
dest = (dest.host, dest.port or self.transport.type == 'tls' and self.transport.secure and 5061 or 5060)
if isinstance(data, Message):
if data.method: # request
Expand All @@ -420,8 +421,9 @@ def received(self, data, src):
via = m.first('Via')
if via.viaUri.host != src[0] or via.viaUri.port != src[1]:
via['received'], via.viaUri.host = src[0], src[0]
if 'rport' in via: via['rport'] = src[1]
via.viaUri.port = src[1]
if 'rport' in via:
via['rport'] = src[1]
via.viaUri.port = src[1]
self._receivedRequest(m, uri)
elif m.response: # response: call receivedResponse
self._receivedResponse(m, uri)
Expand Down Expand Up @@ -520,12 +522,12 @@ def _receivedResponse(self, r, uri):

# following are the main API methods to indicate events from UAS/UAC/Dialog
def createServer(self, request, uri): return self.app.createServer(request, uri, self)
def sending(self, ua, message): self.app.sending(ua, message, self)
def sending(self, ua, message): return self.app.sending(ua, message, self) if hasattr(self.app, 'sending') else None
def receivedRequest(self, ua, request): self.app.receivedRequest(ua, request, self)
def receivedResponse(self, ua, response): self.app.receivedResponse(ua, response, self)
def cancelled(self, ua, request): self.app.cancelled(ua, request, self)
def dialogCreated(self, dialog, ua): self.app.dialogCreated(dialog, ua, self)
def authenticate(self, ua, header): return self.app.authenticate(ua, header, self)
def authenticate(self, ua, header): return self.app.authenticate(ua, header, self) if hasattr(self.app, 'authenticate') else False
def createTimer(self, obj): return self.app.createTimer(obj, self)

def findDialog(self, arg):
Expand Down Expand Up @@ -632,7 +634,6 @@ def equals(t1, r, t2):
# and r['Call-ID'].value == t['Call-ID'].value and r.CSeq.value == t.CSeq.value \
# and r.From.tag == t.From.tag and t2.server == t1.server
a = r.To.value.uri == t.To.value.uri
if _debug: print r.From.value.uri, t.From.value.uri
a = a and (r.From.value.uri == t.From.value.uri)
a = a and (r['Call-ID'].value == t['Call-ID'].value)
a = a and (r.CSeq.value == t.CSeq.value)
Expand Down Expand Up @@ -1429,7 +1430,7 @@ def receivedRequest(self, transaction, request):

def isLocal(self, uri):
'''Check whether the give uri represents local address (host:port) ?'''
return self.stack.transport.host == uri.host and (self.stack.transport.port == uri.port or uri.port == 0 and self.stack.transport.port == 5060)
return (self.stack.transport.host == uri.host or uri.host in ('localhost', '127.0.0.1')) and (self.stack.transport.port == uri.port or not uri.port and self.stack.transport.port == 5060) # TODO: what about 5061 for sips

def sendResponse(self, response, responsetext=None, content=None, contentType=None, createDialog=True):
'''Invoke the base class to send a response to original UAS. Create a transaction beforehand if needed.'''
Expand Down

0 comments on commit 716052a

Please sign in to comment.