diff --git a/uPySip/DTMF.py b/uPySip/DTMF.py index e6e4380..2a99ef5 100644 --- a/uPySip/DTMF.py +++ b/uPySip/DTMF.py @@ -1,4 +1,5 @@ -import cmath,math +import cmath +import math import time import uPySip.aLaw diff --git a/uPySip/sipMachine.py b/uPySip/sipMachine.py index 239f00d..75adeb3 100644 --- a/uPySip/sipMachine.py +++ b/uPySip/sipMachine.py @@ -1,4 +1,9 @@ -import _thread +"""Module sip Machine. + +This module is a sip implementation in python + +""" + import uPySip.md5 import utime import socket @@ -8,22 +13,24 @@ import sys import os -debug=True +debug = True + def _randomChr(size): ret = "" a = 0 while a < size: - try: - b = os.urandom(10)[5] - if (b >= 48 and b < 58) or (b > 64 and b < 91) or (b > 97 and b < 123): - ret = '{}{}'.format(ret, chr(b)) - a = a+1 - except: - pass + b = os.urandom(10)[5] + + if (bytes([b]).isalpha()): + ret = '{}{}'.format(ret, chr(b)) + a = a+1 return ret + class User: + """Base User Class.""" + telNr = None agent = None cSeq = 0 @@ -33,16 +40,23 @@ class User: class UserA(User): + """User A.""" + userClient = None + def __init__(self): + """Init the Class.""" + self.branch = 'z9hG4bK-{}'.format(_randomChr(30)) + class UserB(User): toB = None viaB = None fromB = None sdp_o = None + class Auth: __RN = '\r\n' user = None @@ -53,50 +67,62 @@ class Auth: qop = None def __getUri(self, userB: UserB): - if userB.telNr == None: + if userB.telNr is None: return userB.agent - else: - return '{}@{}'.format(userB.telNr, userB.agent) + return '{}@{}'.format(userB.telNr, userB.agent) def __getAuth(self, userB: UserB): a1 = '{}:{}:{}'.format(self.user, self.realm, self.pwd) + print("- "+a1) ha1 = uPySip.md5.md5(a1.encode()).hexdigest() + print("- "+ha1) a2 = '{}:sip:{}'.format(self.types, self.__getUri(userB)) + print("- "+a2) ha2 = uPySip.md5.md5(a2.encode()).hexdigest() + print("- "+ha2) a3 = '{}:{}:{:0>8}:{}:{}:{}'.format( ha1, self.nonce, self.nonceCount, self.cnonce, self.qop, ha2) + print("- "+a3) return uPySip.md5.md5(a3.encode()).hexdigest() def getAuthorization(self, userB: UserB) -> str: - """function getAuthorization + """function getAuthorization Args: userB (UserB): UserB with telNr and agent Returns: - str: Sip Line for Authorization + str: Sip Line for Authorization """ self.nonceCount = 1 self.cnonce = uPySip.md5.md5('das ist ein Chaos'.encode()).hexdigest() response = self.__getAuth(userB) - return 'Authorization: Digest username="{}",realm="{}",nonce="{}",opaque="",uri="sip:{}",cnonce="{}",nc={:0>8},algorithm=MD5,qop="auth",response="{}"{}'.format( - self.user, self.realm, self.nonce, self.__getUri(userB), self.cnonce, self.nonceCount, response, self.__RN) + ret = 'Authorization: Digest username="{}"'.format(self.user) + ret = '{},realm="{}"'.format(ret, self.realm) + ret = '{},nonce="{}"'.format(ret, self.nonce) + ret = '{},opaque="",uri="sip:{}"'.format(ret, self.__getUri(userB)) + ret = '{},cnonce="{}"'.format(ret, self.cnonce) + ret = '{},nc={:0>8}'.format(ret, self.nonceCount) + ret = '{},algorithm=MD5,qop="auth",response="{}"{}'.format( + ret, response, self.__RN) + return ret + class SipMachine: - REGISTER = 0x00 - IDLE = 0x01 - RINGING = 0x02 - CALLING = 0x03 - TRYING = 0x0 - CALL_ACCEPT = 0x05 - ON_CALL = 0x06 - BYE=0x07 + REGISTER = b'x00' + IDLE = b'x01' + RINGING = b'x02' + CALLING = b'x03' + TRYING = b'x04' + CALL_ACCEPT = b'x05' + ON_CALL = b'x06' + BYE = b'x07' __userB = UserB() __userA = UserA() __auth = Auth() __RN = '\r\n' __INVITE = 'INVITE' __REGISTER = 'REGISTER' - __BYE='BYE' + __BYE = 'BYE' __status = REGISTER __key = '' __record = False @@ -112,19 +138,19 @@ class SipMachine: __proxyServer = None __proxyRegistrar = None __port = 5060 - __keyTimestamp=0 + __keyTimestamp = 0 - def __init__(self:str, user:str, pwd:str, telNr:str, userAgent:str, userClient:str, proxyServer:str, proxyRegistrar:str='192.168.1.1', port:str=5060): + def __init__(self: str, user: str, pwd: str, telNr: str, userAgent: str, userClient: str, proxyServer: str, proxyRegistrar: str = '192.168.1.1', port: str = 5060): """Init sipMachine Args: - user (str): sip User configure in proxyRegistrar - pwd (str): password configured in proxyRegistrar + user (str): sip User configure in proxyRegistrar + pwd (str): password configured in proxyRegistrar telNr (str): telephon number configured in proxyRegistrar userAgent (str): b2b user Agent name . userClient (str): ip Adress Client. proxyServer (str): ip Adress proxiServer. - proxyRegistrar (str, ): ip Adress proxyRegistrar most proxiServer . + proxyRegistrar (str, ): ip Adress proxyRegistrar most proxiServer. port (str, optional): [description]. Defaults to 5060. """ self.__auth.user = user @@ -137,11 +163,13 @@ def __init__(self:str, user:str, pwd:str, telNr:str, userAgent:str, userClient:s self.__userA.userClient = userClient self.__sock_sip_r = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.__sock_sip_r.bind(socket.getaddrinfo(self.__userA.userClient, port)[0][-1]) + self.__sock_sip_r.bind(socket.getaddrinfo( + self.__userA.userClient, port)[0][-1]) self.__sock_sip_r.listen(0) self.__sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - self.__sock.bind(socket.getaddrinfo(self.__userA.userClient, 17000)[0][-1]) + self.__sock.bind(socket.getaddrinfo( + self.__userA.userClient, 17000)[0][-1]) self.__polling_object = select.poll() @@ -150,7 +178,7 @@ def __init__(self:str, user:str, pwd:str, telNr:str, userAgent:str, userClient:s self.__sipRegister(self.__userA, self.__auth) self.__call = False - self.__path='/sd/wilk.aLaw' + self.__path = '/sd/wilk.aLaw' # path=__file__.replace('sipMachine.py','data.pcmA') # f=open(path,'wb') @@ -160,7 +188,7 @@ def __init__(self:str, user:str, pwd:str, telNr:str, userAgent:str, userClient:s # f.write(k) # f.close() - def loop(self)->bytes: + def loop(self) -> bytes: """ loop in main Returns: @@ -175,62 +203,66 @@ def loop(self)->bytes: ready_list = self.__polling_object.poll() for fd in ready_list: if fd[1] & select.POLLIN: - if self.__f_sip != None: + if self.__f_sip is not None: if fd[0] == self.__f_sip.fileno() or fd[0] == self.__f_sip: self.__readSIPdata() if fd[0] == self.__sock.fileno() or fd[0] == self.__sock: self.__recive() if fd[0] == self.__sock_sip_r.fileno() or fd[0] == self.__sock_sip_r: - if self.__f_sip != None: + if self.__f_sip is not None: self.__closeConnection() - (a, b) = self.__sock_sip_r.accept() - self.__setConnection(a) + a = self.__sock_sip_r.accept() + self.__setConnection(a[0]) gc.collect() if self.__call: - if debug: print('start') + if debug: + print('start') f = open(self.__path, 'rb') v = memoryview(self.__buffer) - l = f.readinto(v[12:]) + li = f.readinto(v[12:]) t = utime.ticks_ms() - i=0 - while l == 160: + i = 0 + while li == 160: if utime.ticks_ms()-t >= 20: - i+=1 + i += 1 t = utime.ticks_ms() self.__send(self.server_addressS) - l = f.readinto(v[12:]) - if i%20==0: #Bad solution + li = f.readinto(v[12:]) + if i % 20 == 0: # Bad solution gc.collect() f.close() self.__call = False - if debug:print('end') - if sys.platform!='linux': - if debug:print(gc.mem_free()) + if debug: + print('end') + if sys.platform != 'linux': + if debug: + print(gc.mem_free()) return self.__status - def bye(self,auth=None): + def bye(self, auth=None): """ terminate the call Args: auth ([type], optional): [description]. Defaults to None. """ - self.__userA.cSeq+=1 + self.__userA.cSeq += 1 self.__setConnection() - self.__writeSIPdata('BYE sip:{}@{} SIP/2.0{}'.format(self.__userA.telNr,self.__userA.userClient, self.__RN)) + self.__writeSIPdata( + 'BYE sip:{}@{} SIP/2.0{}'.format(self.__userA.telNr, self.__userA.userClient, self.__RN)) self.__getVia(self.__userA) self.__getMaxForwards() self.__getFrom(self.__userA) self.__getTo(self.__userB) self.__getCallID(self.__userA) - self.__getCSeq(self.__userA.cSeq, self.__BYE) - if auth != None: - self.__auth.types=self.__BYE + self.__getCSeq(self.__userA.cSeq, self.__BYE) + if auth is not None: + self.__auth.types = self.__BYE self.__writeSIPdata(self.__auth.getAuthorization(self.__userB)) self.__getContentLength() - self.__writeSIPdata(self.__RN) - self.__status = self.BYE + self.__writeSIPdata(self.__RN) + self.__status = self.BYE - def invite(self, telNr:str, userAgent=None): + def invite(self, telNr: str, userAgent=None): """make a call Args: @@ -240,12 +272,12 @@ def invite(self, telNr:str, userAgent=None): self.__setConnection() self.__userB.sdp_o = 25 self.__userB.telNr = telNr - if userAgent == None: + if userAgent is None: self.__userB.agent = self.__userA.agent else: self.__userB.agent = userAgent self.__userA.callId = _randomChr(7) - self.__userA.tagFrom =_randomChr(30) + self.__userA.tagFrom = _randomChr(30) self.__userA.cSeq += 1 self.__auth.nonce = None self.__sipInvite(self.__userB, self.__userA, self.__auth) @@ -257,7 +289,7 @@ def acceptCall(self): self.__sipOK(self.__userB, self.__userA) self.__status = self.CALL_ACCEPT - def getTelNrB(self)->str: + def getTelNrB(self) -> str: """ get the tel nr of the ringing call Returns: @@ -265,7 +297,7 @@ def getTelNrB(self)->str: """ return self.__userB.fromB.split('sip:')[1].split('@')[0] - def getKeyPressed(self)->str: + def getKeyPressed(self) -> str: """ get the pressed key on the phone b Returns: @@ -274,27 +306,28 @@ def getKeyPressed(self)->str: key = self.__key self.__key = '' return key - - def play(self,path): - """Ply the pcmAlaw file + + def play(self, path): + """Ply the pcmAlaw file Args: - path (str): path to the pcmAlaw file + path (str): path to the pcmAlaw file """ - self.__path=path - self.__call=True + self.__path = path + self.__call = True - def __sipRegister(self, userA: UserA, auth: Auth = None): + def __sipRegister(self, userA: UserA, auth: Auth): self.__setConnection() userB = UserB() userB.telNr = None userB.agent = self.__proxyRegistrar - if auth.nonce != None: + if auth.nonce is not None: userA.cSeq += 1 auth.types = self.__REGISTER else: - userA.callId =_randomChr(7) - self.__writeSIPdata('REGISTER sip:{} SIP/2.0{}'.format(self.__proxyRegistrar, self.__RN)) + userA.callId = _randomChr(7) + self.__writeSIPdata( + 'REGISTER sip:{} SIP/2.0{}'.format(self.__proxyRegistrar, self.__RN)) self.__getVia(userA) self.__getMaxForwards() self.__getTo(userA) @@ -303,7 +336,7 @@ def __sipRegister(self, userA: UserA, auth: Auth = None): self.__getCSeq(userA.cSeq, self.__REGISTER) self.__getContact(userA) self.__getAllow() - if auth.nonce != None: + if auth.nonce is not None: self.__writeSIPdata(self.__auth.getAuthorization(userB)) self.__getContentLength() self.__writeSIPdata(self.__RN) @@ -316,21 +349,20 @@ def __sipOK(self, userB: UserB, userA: UserA = None): self.__writeSIPdata(userB.toB) self.__writeSIPdata(userB.callId) self.__writeSIPdata(userB.cSeq) - if userA != None: + if userA is not None: conten = self.__getConten(userB, userA.userClient) contentLength = len(conten) self.__getContact(userA) self.__getContentType() self.__getContentLength(contentLength) self.__writeSIPdata(self.__RN) - if userA != None: + if userA is not None: self.__writeSIPdata(conten) def __getConten(self, userB: UserB, userClient): conten = '' conten = '{}{}{}'.format(conten, 'v=0', self.__RN) - conten = '{}{} {} {} {} {}{}'.format( - conten, 'o=-', int(userB.sdp_o)+1, int(userB.sdp_o)+1, 'IN IP4', userClient, self.__RN) + conten = '{}{} {} {} {} {}{}'.format(conten, 'o=-', int(userB.sdp_o)+1, int(userB.sdp_o)+1, 'IN IP4', userClient, self.__RN) conten = '{}{}{}'.format(conten, 's=-', self.__RN) conten = '{}{} {}{}'.format(conten, 'c=IN IP4', userClient, self.__RN) conten = '{}{}{}'.format(conten, 't=0 0', self.__RN) @@ -354,11 +386,11 @@ def __sipRinging(self, userB: UserB, userA: UserA): self.__getContentLength() self.__writeSIPdata(self.__RN) - def __sipInvite(self, userB: UserB, userA: UserA, auth: Auth = None): + def __sipInvite(self, userB: UserB, userA: UserA, auth: Auth): self.__userB.tagTo = '' conten = self.__getConten(userB, userA.userClient) contentLength = len(conten) - if auth.nonce != None: + if auth.nonce is not None: userA.cSeq += 1 auth.types = self.__INVITE self.__getInvite(userB) @@ -368,7 +400,7 @@ def __sipInvite(self, userB: UserB, userA: UserA, auth: Auth = None): self.__getTo(userB) self.__getCallID(userA) self.__getCSeq(userA.cSeq, self.__INVITE) - if auth.nonce != None: + if auth.nonce is not None: self.__writeSIPdata(self.__auth.getAuthorization(userB)) self.__getContact(userA) self.__getContentType() @@ -376,7 +408,7 @@ def __sipInvite(self, userB: UserB, userA: UserA, auth: Auth = None): self.__writeSIPdata(self.__RN) self.__writeSIPdata(conten) - def __sipACK(self, userB: UserB, userA: UserA, auth: Auth): + def __sipACK(self, userB: UserB, userA: UserA,d): self.__getACK(userB.telNr, userB.agent, self.__port) self.__getVia(userA) self.__getMaxForwards() @@ -387,14 +419,14 @@ def __sipACK(self, userB: UserB, userA: UserA, auth: Auth): self.__getContentLength() self.__writeSIPdata(self.__RN) - def __getVia(self, user) -> str: + def __getVia(self, user): self.__writeSIPdata('Via: SIP/2.0/TCP {}:{};branch={}{}'.format( user.userClient, self.__port, user.branch, self.__RN)) - def __getMaxForwards(self) -> str: + def __getMaxForwards(self): self.__writeSIPdata('Max-Forwards: 70{}'.format(self.__RN)) - def __getTo(self, user: User) -> str: + def __getTo(self, user: User): if len(user.tagTo) > 0: self.__writeSIPdata('To: ;tag={}{}'.format( user.telNr, user.agent, user.tagTo, self.__RN)) @@ -402,40 +434,41 @@ def __getTo(self, user: User) -> str: self.__writeSIPdata('To: {}'.format( user.telNr, user.agent, self.__RN)) - def __getFrom(self, userA: UserA) -> str: - self.__writeSIPdata('From: ;tag={}{}'.format(userA.telNr, userA.agent, userA.tagFrom, self.__RN)) + def __getFrom(self, userA: UserA): + self.__writeSIPdata( + 'From: ;tag={}{}'.format(userA.telNr, userA.agent, userA.tagFrom, self.__RN)) - def __getCallID(self, userA: UserA) -> str: + def __getCallID(self, userA: UserA): self.__writeSIPdata( 'Call-ID: {}@{}{}'.format(userA.callId, userA.agent, self.__RN)) - def __getCSeq(self, cSeq, typ) -> str: + def __getCSeq(self, cSeq, typ): self.__writeSIPdata('CSeq: {} {}{}'.format(cSeq, typ, self.__RN)) - def __getContact(self, user: User) -> str: + def __getContact(self, user: User): self.__writeSIPdata('Contact: {}'.format( user.telNr, user.userClient, self.__RN)) - def __getExpires(self, expires) -> str: + def __getExpires(self, expires): return 'Expires: {}{}'.format(expires, self.__RN) - def __getContentLength(self, contentLength=0) -> str: + def __getContentLength(self, contentLength=0): self.__writeSIPdata( 'Content-Length: {}{}'.format(contentLength, self.__RN)) - def __getACK(self, telNr, agent, port) -> str: + def __getACK(self, telNr, agent, port): self.__writeSIPdata( 'ACK sip:{}@{}:{} SIP/2.0{}'.format(telNr, agent, port, self.__RN)) - def __getAllow(self) -> str: + def __getAllow(self): self.__writeSIPdata( 'Allow: INVITE,ACK,OPTIONS,BYE,CANCEL,SUBSCRIBE,NOTIFY,REFER,MESSAGE,INFO,PING{}'.format(self.__RN)) - def __getInvite(self, user: User) -> str: + def __getInvite(self, user: User): self.__writeSIPdata( 'INVITE sip:{}@{} SIP/2.0{}'.format(user.telNr, user.agent, self.__RN)) - def __getContentType(self) -> str: + def __getContentType(self): self.__writeSIPdata( 'Content-Type: application/sdp{}'.format(self.__RN)) @@ -514,7 +547,8 @@ def __exec(self): pass elif self.CSeqTyp == self.__INVITE and self.responseCodes == '200': self.__call = True - self.server_addressS = socket.getaddrinfo(self.__proxyServer, self.pcmuPort)[0][-1] + self.server_addressS = socket.getaddrinfo( + self.__proxyServer, self.pcmuPort)[0][-1] self.__sipACK(self.__userB, self.__userA, self.__auth) self.__status = self.ON_CALL self.__closeConnection() @@ -523,10 +557,11 @@ def __exec(self): self.__sipRinging(self.__userB, self.__userA) self.__status = self.RINGING elif self.CSeqTyp == 'ACK' and self.responseCodes == 'ACK sip:': - self.server_addressS = socket.getaddrinfo(self.__proxyServer, self.pcmuPort)[0][-1] + self.server_addressS = socket.getaddrinfo( + self.__proxyServer, self.pcmuPort)[0][-1] self.__call = True self.__closeConnection() - self.__status = self.ON_CALL + self.__status = self.ON_CALL elif self.CSeqTyp == 'BYE' and self.responseCodes == 'BYE sip:': self.__sipOK(self.__userB) self.__call = False @@ -544,12 +579,14 @@ def __exec(self): def __readSIPdata(self): try: data = self.__f_sip.readline() - if debug:print('-', data.decode(), end='') + if debug: + print('-', data.decode(), end='') if (data == b'\r\n'): if (self.___contentLenght > 0): data = self.__f_sip.read(self.___contentLenght).decode() for k in data.split('\r\n'): - if debug:print('*', k) + if debug: + print('*', k) self.__parser(k.encode()) self.__exec() elif len(data) > 0: @@ -558,7 +595,8 @@ def __readSIPdata(self): self.logger.error("exception from sock_read.recvfrom {}".format(e)) def __writeSIPdata(self, message): - if debug:print(message, end='') + if debug: + print(message, end='') self.__f_sip.write(message.encode()) def __send(self, server_addressS): @@ -577,38 +615,37 @@ def __send(self, server_addressS): def __recive(self): try: - (data, proxyServer) = self.__sock.recvfrom(180) - a = uPySip.DTMF.DTMF().getKey(data) - if a[1] > 500000 : - if int.from_bytes(data[4:8],'big')-self.__keyTimestamp>3000: + data = self.__sock.recvfrom(180) + a = uPySip.DTMF.DTMF().getKey(data[0]) + if a[1] > 500000: + if int.from_bytes(data[4:8], 'big')-self.__keyTimestamp > 3000: self.__key = a[0] - self.__keyTimestamp=int.from_bytes(data[4:8],'big') - + self.__keyTimestamp = int.from_bytes(data[4:8], 'big') except OSError as msg: print("Socket Error: {}".format(msg)) def __setConnection(self, __sock_SIP=None): gc.collect() - if self.__sock_SIP == None: + if self.__sock_SIP is None: self.__sock_SIP = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.__sock_SIP.connect(socket.getaddrinfo(self.__proxyServer, self.__port)[0][-1]) - if __sock_SIP != None: + self.__sock_SIP.connect(socket.getaddrinfo( + self.__proxyServer, self.__port)[0][-1]) + if __sock_SIP is not None: self.__sock_SIP = __sock_SIP - if self.__f_sip == None: - if debug:print('** on') - self.__f_sip = self.__sock_SIP.makefile('rwb',0) + if self.__f_sip is None: + if debug: + print('** on') + self.__f_sip = self.__sock_SIP.makefile('rwb', 0) self.__polling_object.register(self.__f_sip) self.__userB.viaB = '' def __closeConnection(self): - if debug:print('** off') + if debug: + print('** off') self.__polling_object.unregister(self.__f_sip) self.__f_sip.close() self.__sock_SIP.close() self.__f_sip = None self.__sock_SIP = None gc.collect() - - - diff --git a/uPySip/test.py b/uPySip/test.py new file mode 100644 index 0000000..a27e6c7 --- /dev/null +++ b/uPySip/test.py @@ -0,0 +1,80 @@ +import os +import md5 + +def _randomChr(size): + ret = "" + a = 0 + while a < size: + b = os.urandom(10)[5] + + if (bytes([b]).isalpha()): + ret = '{}{}'.format(ret, chr(b)) + a = a+1 + return ret + +class User: + """Base User Class.""" + + telNr = None + agent = None + cSeq = 0 + callId = None + tagTo = "" + tagFrom = _randomChr(30) + +class UserB(User): + toB = None + viaB = None + fromB = None + sdp_o = None + +class Auth: + __RN = '\r\n' + user = "relleum" + pwd = "jutkk7x1" + realm = "Home" + types = "REGISTER" + nonce = "535a8a2bb603502035ed0cbb" + qop = "auth" + + def __getUri(self, userB: UserB): + if userB.telNr is None: + return userB.agent + return '{}@{}'.format(userB.telNr, userB.agent) + + def __getAuth(self, userB: UserB): + a1 = '{}:{}:{}'.format(self.user, self.realm, self.pwd) + ha1 = md5.md5(a1.encode()).hexdigest() + a2 = '{}:sip:{}'.format(self.types, self.__getUri(userB)) + ha2 = md5.md5(a2.encode()).hexdigest() + a3 = '{}:{}:{:0>8}:{}:{}:{}'.format( + ha1, self.nonce, self.nonceCount, self.cnonce, self.qop, ha2) + return md5.md5(a3.encode()).hexdigest() + + def getAuthorization(self, userB: UserB) -> str: + """function getAuthorization + Args: + userB (UserB): UserB with telNr and agent + + Returns: + str: Sip Line for Authorization + """ + self.nonceCount = 1 + self.cnonce = md5.md5('das ist ein Chaos'.encode()).hexdigest() + response = self.__getAuth(userB) + ret = 'Authorization: Digest username="{}"'.format(self.user) + ret = '{},realm="{}"'.format(ret, self.realm) + ret = '{},nonce="{}"'.format(ret, self.nonce) + ret = '{},opaque="",uri="sip:{}"'.format(ret, self.__getUri(userB)) + ret = '{},cnonce="{}"'.format(ret, self.cnonce) + ret = '{},nc={:0>8}'.format(ret, self.nonceCount) + ret = '{},algorithm=MD5,qop="auth",response="{}"{}'.format( + ret, response, self.__RN) + return ret + +user =UserB() +user.agent='192.168.1.1' +aut=Auth() +k=aut.getAuthorization(user) +print(k) + diff --git a/uSipB2Bua.py b/uSipB2Bua.py index bf92386..37314d5 100644 --- a/uSipB2Bua.py +++ b/uSipB2Bua.py @@ -1,51 +1,49 @@ import uPySip.sipMachine import sys import utime -import gc -port=5060 -server='192.168.1.1' -client1='192.168.1.113' -client2='192.168.1.119' -telId1=225 -telid2=226 -if sys.platform=='linux': - client=client1 - telId=telId1 + +port = 5060 +server = '192.168.1.1' +client1 = '192.168.1.113' +client2 = '192.168.1.119' +telId1 = '220' +telid2 = '225' +if sys.platform == 'linux': + client = client1 + telId = telId1 else: - client=client2 - telId=telid2 + client = client2 + telId = telid2 -sipMachine=uPySip.sipMachine.SipMachine(user='relleum', pwd='jutkk7x1',telNr=telId,userAgent="b2b.domain",userClient=client,proxyServer=server,proxyRegistrar=server) -loop=True -first =False -warte=False +sipMachine = uPySip.sipMachine.SipMachine(user='relleum', pwd='jutkk7x1', telNr=telId, + userAgent="b2b.domain", userClient=client, proxyServer=server, proxyRegistrar=server) +loop = b'x00' +first = True +warte = False -while loop>=0: - loop=sipMachine.loop() - if loop==sipMachine.RINGING: - if int(sipMachine.getTelNrB())<300: +while loop >= b'x00': + loop = sipMachine.loop() + if loop == sipMachine.RINGING: + if int(sipMachine.getTelNrB()) < 300: sipMachine.acceptCall() - if sipMachine.IDLE!=loop: - pass - #print(loop) - if sipMachine.IDLE==loop: + warte = False + + elif sipMachine.IDLE == loop: if first: sipMachine.invite('222') - first=False - if sipMachine.ON_CALL==loop: - if warte and utime.ticks_ms()%5000==0: + first = False + elif sipMachine.ON_CALL == loop: + if warte and utime.ticks_ms() % 5000 == 0: sipMachine.play('/sd/warte.aLaw') - keyPressed=sipMachine.getKeyPressed() - if keyPressed!='': - if keyPressed=='0': - sipMachine.play('/sd/wilk.aLaw') - if keyPressed=='1': - sipMachine.play('/sd/info.aLaw') - if keyPressed=='2': - sipMachine.play('/sd/info.aLaw') - if keyPressed=='3': + keyPressed = sipMachine.getKeyPressed() + if keyPressed != '': + if keyPressed == '0': + sipMachine.play('/sd/wilk.aLaw') + if keyPressed == '1': + sipMachine.play('/sd/info.aLaw') + if keyPressed == '2': + sipMachine.play('/sd/info.aLaw') + if keyPressed == '3': sipMachine.play('/sd/warte.aLaw') - warte=True - else: - warte=False \ No newline at end of file + warte = True