2 # Copyright (C) 2006-2008 Georgia Public Library Service
4 # Author: David J. Fiander
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of version 2 of the GNU General Public
8 # License as published by the Free Software Foundation.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public
16 # License along with this program; if not, write to the Free
17 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 from time import strftime;
24 def SipSocket(host='localhost', port=5300):
26 so.connect((host, port))
29 def login(so, uname='scclient', passwd='clientpwd', locn='The basement',
31 port = so.getpeername()[1]
33 resp = send(so, '9300CN%s|CO%s|CP%s|' % (uname, passwd, locn), seqno)
34 print "Received", repr(resp)
35 print "Verified: ", verify(resp)
37 raise "Logging in is only support for the raw transport on port 5300"
39 def send(so, msg, seqno=0):
41 msg += 'AY' + str(seqno)[0] + 'AZ'
42 msg += ('%04X' % calculate_cksum(msg))
44 print 'Sending', repr(msg)
47 return resp, verify(resp)
49 def calculate_cksum(msg):
50 return (-reduce(operator.add, map(ord, msg)) & 0xFFFF)
53 return(strftime("%Y%m%d %H%M%S"))
56 if msg[-1] == '\r': msg = msg[:-2]
57 if msg[-6:-4] == 'AZ':
58 cksum = calculate_cksum(msg[:-4])
59 return (msg[-4:] == ('%04X' % cksum))
60 # If there's no checksum, then the message is ok