Skip to content

Commit

Permalink
Merge branch 'master' of github.com:tayler6000/pyVoIP
Browse files Browse the repository at this point in the history
  • Loading branch information
tayler6000 committed Feb 16, 2022
2 parents 2f09674 + 83cff21 commit ae25af6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
29 changes: 17 additions & 12 deletions pyVoIP/SIP.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ def parseSIPMessage(self, data):

class SIPClient():
def __init__(self, server, port, username, password, myIP=None, myPort=5060, callCallback=None):
self.NSD = True
self.NSD = False
self.server = server
self.port = port
self.hostname = socket.gethostname()
Expand Down Expand Up @@ -569,6 +569,9 @@ def parseMessage(self, message):
debug("TODO: Add 400 Error on non processable request")

def start(self):
if self.NSD == True:
raise RunTimeError("Attempted to start already started SIPClient")
self.NSD = True
self.s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
#self.out = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.s.bind((self.myIP, self.myPort))
Expand Down Expand Up @@ -596,17 +599,19 @@ def genTag(self):
return tag

def genSIPVersionNotSupported(self, request):
regRequest = "SIP/2.0 505 SIP Version Not Supported\r\n"
regRequest += "Via: SIP/2.0/UDP "+request.headers['Via']['address'][0]+":"+request.headers['Via']['address'][1]+";branch="+request.headers['Via']['branch']+"\r\n"
regRequest += "From: "+request.headers['From']['raw']+";tag="+request.headers['From']['tag']+"\r\n"
regRequest += "To: "+request.headers['To']['raw']+";tag="+self.genTag()+"\r\n"
regRequest += "Call-ID: "+request.headers['Call-ID']+"\r\n"
regRequest += "CSeq: "+request.headers['CSeq']['check']+" "+request.headers['CSeq']['method']+"\r\n"
regRequest += "Contact: "+request.headers['Contact']+"\r\n" #TODO: Add Supported
regRequest += "User-Agent: pyVoIP """+pyVoIP.__version__+"\r\n"
regRequest += "Warning: 399 GS \"Unable to accept call\"\r\n"
regRequest += "Allow: "+(", ".join(pyVoIP.SIPCompatibleMethods))+"\r\n"
regRequest += "Content-Length: 0\r\n\r\n"
response = "SIP/2.0 505 SIP Version Not Supported\r\n"
response += "Via: SIP/2.0/UDP "+request.headers['Via']['address'][0]+":"+request.headers['Via']['address'][1]+";branch="+request.headers['Via']['branch']+"\r\n"
response += "From: "+request.headers['From']['raw']+";tag="+request.headers['From']['tag']+"\r\n"
response += "To: "+request.headers['To']['raw']+";tag="+self.genTag()+"\r\n"
response += "Call-ID: "+request.headers['Call-ID']+"\r\n"
response += "CSeq: "+request.headers['CSeq']['check']+" "+request.headers['CSeq']['method']+"\r\n"
response += "Contact: "+request.headers['Contact']+"\r\n" #TODO: Add Supported
response += "User-Agent: pyVoIP """+pyVoIP.__version__+"\r\n"
response += "Warning: 399 GS \"Unable to accept call\"\r\n"
response += "Allow: "+(", ".join(pyVoIP.SIPCompatibleMethods))+"\r\n"
response += "Content-Length: 0\r\n\r\n"

return response

def genAuthorization(self, request):
HA1 = hashlib.md5(self.username.encode('utf8')+b':'+request.authentication['realm'].encode('utf8')+b':'+self.password.encode('utf8')).hexdigest().encode('utf8')
Expand Down
8 changes: 6 additions & 2 deletions pyVoIP/VoIP.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,11 @@ def callback(self, request):
self.sip.out.sendto(ack.encode('utf8'), (self.server, self.port))

def start(self):
self.sip.start()
try:
self.sip.start()
except Exception:
self.sip.stop()
raise

def stop(self):
for x in self.calls.copy():
Expand All @@ -372,4 +376,4 @@ def call(self, number):
request, call_id, sess_id = self.sip.invite(number, medias, pyVoIP.RTP.TransmitType.SENDRECV)
self.calls[call_id] = VoIPCall(self, CallState.DIALING, request, sess_id, self.myIP, ms = medias)

return self.calls[call_id]
return self.calls[call_id]

0 comments on commit ae25af6

Please sign in to comment.