1 Commits

Author SHA1 Message Date
2ed0f86fd4 clearbuf patch? 2020-06-22 17:30:13 +02:00

View File

@@ -26,7 +26,7 @@ Support for:
def __init__(self, user=None, password=None, def __init__(self, user=None, password=None,
host="sip-lmw.rws.nl", port=443, meetnet="LMW", ssl = True, host="sip-lmw.rws.nl", port=443, meetnet="LMW", ssl = True,
check_ssl = True, timeout = 10, log = None): check_ssl = True, timeout = 10, log = None, clearbuf = False):
"""LmwSip(user, password, [host], [port], [meetnet], [ssl], [check_ssl], [timeout], [log]) """LmwSip(user, password, [host], [port], [meetnet], [ssl], [check_ssl], [timeout], [log])
user(optinal): Lmw user name user(optinal): Lmw user name
@@ -38,6 +38,7 @@ ssl(optional): Default true
check_ssl(optional): true check_ssl(optional): true
timeout(optional): 10 timeout(optional): 10
log(optional): None log(optional): None
clearbuf(optinal): None
Opens the connection and logs in Opens the connection and logs in
""" """
@@ -49,6 +50,7 @@ Opens the connection and logs in
self.ssl = ssl self.ssl = ssl
self.check_ssl = check_ssl self.check_ssl = check_ssl
self.timeout = timeout self.timeout = timeout
self.clearbuf = clearbuf
self._socket = None self._socket = None
if (log != None): if (log != None):
self.log = log self.log = log
@@ -130,6 +132,19 @@ connects to lmw with tcp using the values of the object creation.
pass pass
self._socket = None self._socket = None
def emptysocket(self):
"""emptysocket()
If clearbuf read all the data from the socket and ignore it.
"""
if self._socket != None and self.clearbuf:
try:
self._socket.settimeout(0)
b = self._socket.recv(4096)
except Exception as e:
pass
self._socket.settimeout(self.timeout)
def send(self, sipcmd): def send(self, sipcmd):
"""send(sipcmd) """send(sipcmd)
@@ -141,6 +156,7 @@ send a sip command to the server
if re.match("^LI", logcmd, re.IGNORECASE): if re.match("^LI", logcmd, re.IGNORECASE):
logcmd = re.sub(",.*", ", ******", logcmd) logcmd = re.sub(",.*", ", ******", logcmd)
self.log.debug("LmwSip.send(%s)" % logcmd) self.log.debug("LmwSip.send(%s)" % logcmd)
self.emptysocket()
self._socket.sendall(sipcmd.encode('ascii')) self._socket.sendall(sipcmd.encode('ascii'))
except Exception as e: except Exception as e:
self.log.error("LmwSip.send(%s) failed: %s", sipcmd, e) self.log.error("LmwSip.send(%s) failed: %s", sipcmd, e)