1
2 import CORBA, PortableServer
3 import authenticateIdl, authenticateIdl__POA
4 import clientIdl, clientIdl__POA
5 import serverIdl, serverIdl__POA
6 from xml.dom import minidom
7
8 def get_ior(server, service, port = 3412):
9 import httplib
10 conn = httplib.HTTPConnection(server, port)
11 conn.request("GET", "/%s.ior"%service)
12 resp = conn.getresponse()
13 if resp.status <> 200:
14 raise Exception("Can not find ior")
15 ior = resp.read()
16 conn.close()
17 return ior
18
19 class Blaster:
20
21 def __init__(self, server, port, argv):
22 self.server = server
23 self.port = port
24 self.orb = CORBA.ORB_init(argv, CORBA.ORB_ID)
25
26 def login(self, login, password, callback):
27 if callback:
28 self.poa = self.orb.resolve_initial_references("RootPOA")
29 self.poa._get_the_POAManager().activate()
30 id = self.poa.activate_object(callback)
31 obj = self.poa.id_to_reference(id)
32 self.callbackior = self.orb.object_to_string(obj)
33 else:
34 self.callbackior = ''
35 authior = get_ior(self.server, "AuthenticationService", self.port)
36 self.auth = self.orb.string_to_object(authior)
37 self.auth = self.auth._narrow(authenticateIdl.AuthServer)
38 if self.callbackior:
39 callbackpart="<callback type='IOR'>%s</callback>"%self.callbackior
40 else:
41 callbackpart=""
42 connectqos="""
43 <qos>
44 <securityService type="htpasswd" version="1.0">
45 <![CDATA[
46 <user>%s</user>
47 <passwd>%s</passwd>
48 ]]>
49 </securityService>
50 %s
51 </qos>
52 """%(login, password, callbackpart)
53 connectionxml = self.auth.connect(connectqos)
54 dom = minidom.parseString(connectionxml)
55 self.sessionId = dom.getElementsByTagName("session")[0].getAttribute("sessionId").encode()
56 self.serverIOR = dom.getElementsByTagName("serverRef")[0].firstChild.data.encode().strip()
57 obj = self.orb.string_to_object(self.serverIOR)
58 self.server = obj._narrow(serverIdl.Server)
59
60 def get(self, key, qos):
61 return self.server.get(key, qos)
62
63 def logout(self):
64 self.auth.disconnect(self.sessionId, "<qos/>")
65
66 def send(self, receiver, address, oid, content):
67 publishqos = """
68 <qos>
69 <destination queryType='EXACT' forceQueuing='true'>%s</destination>
70 <persistent/>
71 </qos>
72 """%receiver
73 key = '<key oid="%s"><address>%s</address></key>'%(oid, address)
74 msgUnit = serverIdl.MessageUnit(key, content, publishqos)
75 return self.server.publish(msgUnit)
syntax highlighted by Code2HTML, v. 0.9.1