Bug 19180: Add vendor name to breadcrumbs when closing an order
[koha.git] / C4 / SIP / acstest.py
blob02eb4bd272024f6fbebdd8944ad6303b62689128
1 import operator
2 import socket
3 from time import strftime;
5 def SipSocket(host='localhost', port=5300):
6 so = socket.socket()
7 so.connect((host, port))
8 return so
10 def login(so, uname='scclient', passwd='clientpwd', locn='The basement',
11 seqno=0):
12 port = so.getpeername()[1]
13 if port == 5300:
14 resp = send(so, '9300CN%s|CO%s|CP%s|' % (uname, passwd, locn), seqno)
15 print "Received", repr(resp)
16 print "Verified: ", verify(resp)
17 else:
18 raise "Logging in is only support for the raw transport on port 5300"
20 def send(so, msg, seqno=0):
21 if seqno:
22 msg += 'AY' + str(seqno)[0] + 'AZ'
23 msg += ('%04X' % calculate_cksum(msg))
24 msg += '\r'
25 print 'Sending', repr(msg)
26 so.send(msg)
27 resp = so.recv(1000)
28 return resp, verify(resp)
30 def calculate_cksum(msg):
31 return (-reduce(operator.add, map(ord, msg)) & 0xFFFF)
33 def sipdate():
34 return(strftime("%Y%m%d %H%M%S"))
36 def verify(msg):
37 if msg[-1] == '\r': msg = msg[:-2]
38 if msg[-6:-4] == 'AZ':
39 cksum = calculate_cksum(msg[:-4])
40 return (msg[-4:] == ('%04X' % cksum))
41 # If there's no checksum, then the message is ok
42 return True