Compare commits
1 Commits
a884a5295b
...
clearbuf
Author | SHA1 | Date | |
---|---|---|---|
2ed0f86fd4 |
18
lmwsip.py
18
lmwsip.py
@@ -26,7 +26,7 @@ Support for:
|
||||
|
||||
def __init__(self, user=None, password=None,
|
||||
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])
|
||||
|
||||
user(optinal): Lmw user name
|
||||
@@ -38,6 +38,7 @@ ssl(optional): Default true
|
||||
check_ssl(optional): true
|
||||
timeout(optional): 10
|
||||
log(optional): None
|
||||
clearbuf(optinal): None
|
||||
|
||||
Opens the connection and logs in
|
||||
"""
|
||||
@@ -49,6 +50,7 @@ Opens the connection and logs in
|
||||
self.ssl = ssl
|
||||
self.check_ssl = check_ssl
|
||||
self.timeout = timeout
|
||||
self.clearbuf = clearbuf
|
||||
self._socket = None
|
||||
if (log != None):
|
||||
self.log = log
|
||||
@@ -130,6 +132,19 @@ connects to lmw with tcp using the values of the object creation.
|
||||
pass
|
||||
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):
|
||||
"""send(sipcmd)
|
||||
|
||||
@@ -141,6 +156,7 @@ send a sip command to the server
|
||||
if re.match("^LI", logcmd, re.IGNORECASE):
|
||||
logcmd = re.sub(",.*", ", ******", logcmd)
|
||||
self.log.debug("LmwSip.send(%s)" % logcmd)
|
||||
self.emptysocket()
|
||||
self._socket.sendall(sipcmd.encode('ascii'))
|
||||
except Exception as e:
|
||||
self.log.error("LmwSip.send(%s) failed: %s", sipcmd, e)
|
||||
|
Reference in New Issue
Block a user