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 modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 from time import strftime;
23 def SipSocket(host='localhost', port=5300):
25 so.connect((host, port))
28 def login(so, uname='scclient', passwd='clientpwd', locn='The basement',
30 port = so.getpeername()[1]
32 resp = send(so, '9300CN%s|CO%s|CP%s|' % (uname, passwd, locn), seqno)
33 print "Received", repr(resp)
34 print "Verified: ", verify(resp)
36 raise "Logging in is only support for the raw transport on port 5300"
38 def send(so, msg, seqno=0):
40 msg += 'AY' + str(seqno)[0] + 'AZ'
41 msg += ('%04X' % calculate_cksum(msg))
43 print 'Sending', repr(msg)
46 return resp, verify(resp)
48 def calculate_cksum(msg):
49 return (-reduce(operator.add, map(ord, msg)) & 0xFFFF)
52 return(strftime("%Y%m%d %H%M%S"))
55 if msg[-1] == '\r': msg = msg[:-2]
56 if msg[-6:-4] == 'AZ':
57 cksum = calculate_cksum(msg[:-4])
58 return (msg[-4:] == ('%04X' % cksum))
59 # If there's no checksum, then the message is ok