| 1 | ##Â Â jabber.py |
|---|
| 2 | ## |
|---|
| 3 | ##Â Â Copyright (C) 2001 Matthew Allum |
|---|
| 4 | ## |
|---|
| 5 | ##Â Â This program is free software; you can redistribute it and/or modify |
|---|
| 6 | ##Â Â it under the terms of the GNU Lesser General Public License as published |
|---|
| 7 | ##Â Â by the Free Software Foundation; either version 2, or (at your option) |
|---|
| 8 | ##Â Â any later version. |
|---|
| 9 | ## |
|---|
| 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 Lesser General Public License for more details. |
|---|
| 14 | ## |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | """\ |
|---|
| 18 | |
|---|
| 19 | __intro__ |
|---|
| 20 | |
|---|
| 21 | jabber.py is a Python module for the jabber instant messaging protocol. |
|---|
| 22 | jabber.py deals with the xml parsing and socket code, leaving the programmer |
|---|
| 23 | to concentrate on developing quality jabber based applications with Python. |
|---|
| 24 | |
|---|
| 25 | The eventual aim is to produce a fully featured easy to use library for |
|---|
| 26 | creating both jabber clients and servers. |
|---|
| 27 | |
|---|
| 28 | jabber.py requires at least python 2.0 and the XML expat parser module |
|---|
| 29 | ( included in the standard Python distrubution ). |
|---|
| 30 | |
|---|
| 31 | It is developed on Linux but should run happily on over Unix's and win32. |
|---|
| 32 | |
|---|
| 33 | __Usage__ |
|---|
| 34 | |
|---|
| 35 | jabber.py basically subclasses the xmlstream classs and provides the |
|---|
| 36 | processing of jabber protocol elements into object instances as well |
|---|
| 37 | 'helper' functions for parts of the protocol such as authentication |
|---|
| 38 | and roster management. |
|---|
| 39 | |
|---|
| 40 | An example of usage for a simple client would be ( only psuedo code !) |
|---|
| 41 | |
|---|
| 42 | <> Read documentation on jabber.org for the jabber protocol. |
|---|
| 43 | |
|---|
| 44 | <> Birth a jabber.Client object with your jabber servers host |
|---|
| 45 | |
|---|
| 46 | <> Define callback functions for the protocol elements you want to use |
|---|
| 47 | Â Â and optionally a disconnection. |
|---|
| 48 | |
|---|
| 49 | <> Authenticate with the server via auth method, or register via the |
|---|
| 50 | Â Â reg methods to get an account. |
|---|
| 51 | |
|---|
| 52 | <> Call requestRoster() and sendPresence() |
|---|
| 53 | |
|---|
| 54 | <> loop over process(). Send Iqs,messages and presences by birthing |
|---|
| 55 | Â Â them via there respective clients , manipulating them and using |
|---|
| 56 | Â Â the Client's send() method. |
|---|
| 57 | |
|---|
| 58 | <> Respond to incoming elements passed to your callback functions. |
|---|
| 59 | |
|---|
| 60 | <> Find bugs :) |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | """ |
|---|
| 64 | |
|---|
| 65 | # $Id$ |
|---|
| 66 | |
|---|
| 67 | import xmlstream |
|---|
| 68 | import sha, time |
|---|
| 69 | |
|---|
| 70 | debug=xmlstream.debug |
|---|
| 71 | |
|---|
| 72 | VERSION =Â xmlstream.VERSION |
|---|
| 73 | |
|---|
| 74 | False = 0; |
|---|
| 75 | True = 1; |
|---|
| 76 | |
|---|
| 77 | timeout =Â 300 |
|---|
| 78 | |
|---|
| 79 | DBG_INIT, DBG_ALWAYS = debug.DBG_INIT, debug.DBG_ALWAYS |
|---|
| 80 | DBG_DISPATCH =Â 'jb-dispatch'Â Â Â Â Â Â ;Â debug.debug_flags.append(Â DBG_DISPATCH ) |
|---|
| 81 | DBG_NODE =Â 'jb-node'Â Â Â Â Â Â Â Â Â Â ;Â debug.debug_flags.append(Â DBG_NODE) |
|---|
| 82 | DBG_NODE_IQ =Â 'jb-node-iq'Â Â Â Â Â Â Â ;Â debug.debug_flags.append(Â DBG_NODE_IQ ) |
|---|
| 83 | DBG_NODE_MESSAGE =Â 'jb-node-message'Â Â ;Â debug.debug_flags.append(Â DBG_NODE_MESSAGE ) |
|---|
| 84 | DBG_NODE_PRESENCE =Â 'jb-node-pressence'Â ;Â debug.debug_flags.append(Â DBG_NODE_PRESENCE ) |
|---|
| 85 | DBG_NODE_UNKNOWN =Â 'jb-node-unknown'Â Â ;Â debug.debug_flags.append(Â DBG_NODE_UNKNOWN ) |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | # |
|---|
| 89 | # JANA core namespaces |
|---|
| 90 | #Â from http://www.jabber.org/jana/namespaces.php as of 2003-01-12 |
|---|
| 91 | #Â "myname" means that namespace didnt have a name in the jabberd headers |
|---|
| 92 | # |
|---|
| 93 | NS_AGENTÂ Â Â =Â "jabber:iq:agent" |
|---|
| 94 | NS_AGENTSÂ Â Â =Â "jabber:iq:agents" |
|---|
| 95 | NS_AUTHÂ Â Â Â =Â "jabber:iq:auth" |
|---|
| 96 | NS_CLIENTÂ Â Â =Â "jabber:client" |
|---|
| 97 | NS_DELAYÂ Â Â =Â "jabber:x:delay" |
|---|
| 98 | NS_OOBÂ Â Â Â =Â "jabber:iq:oob" |
|---|
| 99 | NS_REGISTERÂ Â =Â "jabber:iq:register" |
|---|
| 100 | NS_ROSTERÂ Â Â =Â "jabber:iq:roster" |
|---|
| 101 | NS_XROSTERÂ Â =Â "jabber:x:roster"Â # myname |
|---|
| 102 | NS_SERVERÂ Â Â =Â "jabber:server" |
|---|
| 103 | NS_TIMEÂ Â Â Â =Â "jabber:iq:time" |
|---|
| 104 | NS_VERSIONÂ Â =Â "jabber:iq:version" |
|---|
| 105 | |
|---|
| 106 | NS_COMP_ACCEPTÂ =Â "jabber:component:accept"Â # myname |
|---|
| 107 | NS_COMP_CONNECT =Â "jabber:component:connect"Â # myname |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | # |
|---|
| 112 | # JANA JEP namespaces, ordered by JEP |
|---|
| 113 | #Â from http://www.jabber.org/jana/namespaces.php as of 2003-01-12 |
|---|
| 114 | #Â all names by jaclu |
|---|
| 115 | # |
|---|
| 116 | _NS_PROTOCOLÂ =Â "http://jabber.org/protocol"Â # base for other |
|---|
| 117 | NS_PASSÂ Â Â Â =Â "jabber:iq:pass"Â # JEP-0003 |
|---|
| 118 | NS_XDATAÂ Â Â =Â "jabber:x:data"Â # JEP-0004 |
|---|
| 119 | NS_RPCÂ Â Â Â =Â "jabber:iq:rpc"Â # JEP-0009 |
|---|
| 120 | NS_BROWSEÂ Â Â =Â "jabber:iq:browse"Â # JEP-0011 |
|---|
| 121 | NS_LASTÂ Â Â Â =Â "jabber:iq:last"Â #JEP-0012 |
|---|
| 122 | NS_PRIVACYÂ Â =Â "jabber:iq:privacy"Â # JEP-0016 |
|---|
| 123 | NS_XEVENTÂ Â Â =Â "jabber:x:event"Â # JEP-0022 |
|---|
| 124 | NS_XEXPIREÂ Â =Â "jabber:x:expire"Â # JEP-0023 |
|---|
| 125 | NS_XENCRYPTED =Â "jabber:x:encrypted"Â # JEP-0027 |
|---|
| 126 | NS_XSIGNEDÂ Â =Â "jabber:x:signed"Â # JEP-0027 |
|---|
| 127 | NS_P_MUCÂ Â Â =Â _NS_PROTOCOL +Â "/muc"Â # JEP-0045 |
|---|
| 128 | NS_VCARDÂ Â Â =Â "vcard-temp"Â # JEP-0054 |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | # |
|---|
| 132 | # Non JANA aproved, ordered by JEP |
|---|
| 133 | #Â all names by jaclu |
|---|
| 134 | # |
|---|
| 135 | _NS_P_DISCOÂ Â Â =Â _NS_PROTOCOL +Â "/disco"Â # base for other |
|---|
| 136 | NS_P_DISC_INFOÂ =Â _NS_P_DISCO +Â "#info"Â # JEP-0030 |
|---|
| 137 | NS_P_DISC_ITEMS =Â _NS_P_DISCO +Â "#items"Â # JEP-0030 |
|---|
| 138 | NS_P_COMMANDSÂ Â =Â _NS_PROTOCOL +Â "/commands"Â # JEP-0050 |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | """ |
|---|
| 142 | Â 2002-01-11 jaclu |
|---|
| 143 | |
|---|
| 144 | Â Defined in jabberd/lib/lib.h, but not JANA aproved and not used in jabber.py |
|---|
| 145 | Â so commented out, should/could propably be removed... |
|---|
| 146 | |
|---|
| 147 | Â NS_ADMINÂ Â Â = "jabber:iq:admin" |
|---|
| 148 | Â NS_AUTH_OKÂ Â = "jabber:iq:auth:0k" |
|---|
| 149 | Â NS_CONFERENCE = "jabber:iq:conference" |
|---|
| 150 | Â NS_ENVELOPEÂ Â = "jabber:x:envelope" |
|---|
| 151 | Â NS_FILTERÂ Â Â = "jabber:iq:filter" |
|---|
| 152 | Â NS_GATEWAYÂ Â = "jabber:iq:gateway" |
|---|
| 153 | Â NS_OFFLINEÂ Â = "jabber:x:offline" |
|---|
| 154 | Â NS_PRIVATEÂ Â = "jabber:iq:private" |
|---|
| 155 | Â NS_SEARCHÂ Â Â = "jabber:iq:search" |
|---|
| 156 | Â NS_XDBGINSERT = "jabber:xdb:ginsert" |
|---|
| 157 | Â NS_XDBNSLISTÂ = "jabber:xdb:nslist" |
|---|
| 158 | Â NS_XHTMLÂ Â Â = "http://www.w3.org/1999/xhtml" |
|---|
| 159 | Â NS_XOOBÂ Â Â Â = "jabber:x:oob" |
|---|
| 160 | Â NS_COMP_EXECUTE = "jabber:component:execute" # myname |
|---|
| 161 | """ |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | ## Possible constants for Roster class .... hmmm ## |
|---|
| 165 | RS_SUB_BOTHÂ Â =Â 0 |
|---|
| 166 | RS_SUB_FROMÂ Â =Â 1 |
|---|
| 167 | RS_SUB_TOÂ Â Â =Â 2 |
|---|
| 168 | |
|---|
| 169 | RS_ASK_SUBSCRIBEÂ Â =Â 1 |
|---|
| 170 | RS_ASK_UNSUBSCRIBE =Â 0 |
|---|
| 171 | |
|---|
| 172 | RS_EXT_ONLINEÂ Â =Â 2 |
|---|
| 173 | RS_EXT_OFFLINEÂ =Â 1 |
|---|
| 174 | RS_EXT_PENDINGÂ =Â 0 |
|---|
| 175 | |
|---|
| 176 | ############################################################################# |
|---|
| 177 | |
|---|
| 178 | def ustr(what): |
|---|
| 179 | Â Â """If sending object is already a unicode str, just |
|---|
| 180 | Â Â Â Â return it, otherwise convert it using xmlstream.ENCODING""" |
|---|
| 181 |   if type(what) == type(u''): |
|---|
| 182 | Â Â Â Â r =Â what |
|---|
| 183 | Â Â else: |
|---|
| 184 | Â Â Â Â try:Â r =Â what.__str__() |
|---|
| 185 |     except AttributeError: r = str(what) |
|---|
| 186 | Â Â Â Â # make sure __str__() didnt return a unicode |
|---|
| 187 |     if type(r) <> type(u''): |
|---|
| 188 | Â Â Â Â Â Â r =Â unicode(r,xmlstream.ENCODING,'replace') |
|---|
| 189 |   return r |
|---|
| 190 | xmlstream.ustr =Â ustr |
|---|
| 191 | |
|---|
| 192 | class NodeProcessed(Exception): pass  # currently only for Connection._expectedIqHandler |
|---|
| 193 | |
|---|
| 194 | class Connection(xmlstream.Client): |
|---|
| 195 | Â Â """Forms the base for both Client and Component Classes""" |
|---|
| 196 |   def __init__(self, host, port, namespace, |
|---|
| 197 |          debug=[], log=False, connection=xmlstream.TCP, hostIP=None, proxy=None): |
|---|
| 198 | |
|---|
| 199 |     xmlstream.Client.__init__(self, host, port, namespace, |
|---|
| 200 |                  debug=debug, log=log, |
|---|
| 201 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â connection=connection, |
|---|
| 202 |                  hostIP=hostIP, proxy=proxy) |
|---|
| 203 | Â Â Â Â self.handlers={} |
|---|
| 204 |     self.registerProtocol('unknown', Protocol) |
|---|
| 205 |     self.registerProtocol('iq', Iq) |
|---|
| 206 |     self.registerProtocol('message', Message) |
|---|
| 207 |     self.registerProtocol('presence', Presence) |
|---|
| 208 | |
|---|
| 209 | Â Â Â Â self.registerHandler('iq',self._expectedIqHandler,system=True) |
|---|
| 210 | |
|---|
| 211 | Â Â Â Â self._expected =Â {} |
|---|
| 212 | |
|---|
| 213 | Â Â Â Â self._id =Â 0; |
|---|
| 214 | |
|---|
| 215 | Â Â Â Â self.lastErr =Â '' |
|---|
| 216 | Â Â Â Â self.lastErrCode =Â 0 |
|---|
| 217 | |
|---|
| 218 |   def setMessageHandler(self, func, type='', chainOutput=False): |
|---|
| 219 | Â Â Â Â """Back compartibility method""" |
|---|
| 220 |     print "WARNING! setMessageHandler(...) method is obsolette, use registerHandler('message',...) instead." |
|---|
| 221 |     return self.registerHandler('message', func, type, chained=chainOutput) |
|---|
| 222 | |
|---|
| 223 |   def setPresenceHandler(self, func, type='', chainOutput=False): |
|---|
| 224 | Â Â Â Â """Back compartibility method""" |
|---|
| 225 |     print "WARNING! setPresenceHandler(...) method is obsolette, use registerHandler('presence',...) instead." |
|---|
| 226 |     return self.registerHandler('presence', func, type, chained=chainOutput) |
|---|
| 227 | |
|---|
| 228 |   def setIqHandler(self, func, type='', ns=''): |
|---|
| 229 | Â Â Â Â """Back compartibility method""" |
|---|
| 230 |     print "WARNING! setIqHandler(...) method is obsolette, use registerHandler('iq',...) instead." |
|---|
| 231 |     return self.registerHandler('iq', func, type, ns) |
|---|
| 232 | |
|---|
| 233 |   def header(self): |
|---|
| 234 | Â Â Â Â self.DEBUG("stream: sending initial header",DBG_INIT) |
|---|
| 235 |     str = u"<?xml version='1.0' encoding='UTF-8' ?>  \ |
|---|
| 236 | Â Â Â Â Â Â Â Â <stream:stream to='%s' xmlns='%s'"Â %Â (Â self._host, |
|---|
| 237 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â self._namespace ) |
|---|
| 238 | |
|---|
| 239 |     if self._outgoingID: str = str + " id='%s' " % self._outgoingID |
|---|
| 240 |     str = str + " xmlns:stream='http://etherx.jabber.org/streams'>" |
|---|
| 241 | Â Â Â Â self.send(str) |
|---|
| 242 | Â Â Â Â self.process(timeout) |
|---|
| 243 | |
|---|
| 244 |   def send(self, what): |
|---|
| 245 | Â Â Â Â """Sends a jabber protocol element (Node) to the server""" |
|---|
| 246 | Â Â Â Â xmlstream.Client.write(self,ustr(what)) |
|---|
| 247 | |
|---|
| 248 |   def _expectedIqHandler(self, conn, iq_obj): |
|---|
| 249 |     if iq_obj.getAttr('id') and \ |
|---|
| 250 | Â Â Â Â Â Â self._expected.has_key(iq_obj.getAttr('id')): |
|---|
| 251 | Â Â Â Â Â Â self._expected[iq_obj.getAttr('id')]Â =Â iq_obj |
|---|
| 252 |       raise NodeProcessed('No need for further Iq processing.') |
|---|
| 253 | |
|---|
| 254 |   def dispatch(self,stanza): |
|---|
| 255 | Â Â Â Â """Called internally when a 'protocol element' is received. |
|---|
| 256 | Â Â Â Â Â Â Builds the relevant jabber.py object and dispatches it |
|---|
| 257 | Â Â Â Â Â Â to a relevant function or callback.""" |
|---|
| 258 | Â Â Â Â name=stanza.getName() |
|---|
| 259 |     if not self.handlers.has_key(name): |
|---|
| 260 | Â Â Â Â Â Â self.DEBUG("whats a tag -> "Â +Â name,DBG_NODE_UNKNOWN) |
|---|
| 261 | Â Â Â Â Â Â name='unknown' |
|---|
| 262 | Â Â Â Â else: |
|---|
| 263 |       self.DEBUG("Got %s stanza"%name, DBG_NODE) |
|---|
| 264 | |
|---|
| 265 | Â Â Â Â stanza=self.handlers[name][type](node=stanza) |
|---|
| 266 | |
|---|
| 267 | Â Â Â Â typ=stanza.getType() |
|---|
| 268 |     if not typ: typ='' |
|---|
| 269 | Â Â Â Â try: |
|---|
| 270 | Â Â Â Â Â Â ns=stanza.getQuery() |
|---|
| 271 |       if not ns: ns='' |
|---|
| 272 | Â Â Â Â except:Â ns='' |
|---|
| 273 |     self.DEBUG("dispatch called for: name->%s ns->%s"%(name,ns),DBG_DISPATCH) |
|---|
| 274 | |
|---|
| 275 | Â Â Â Â typns=typ+ns |
|---|
| 276 |     if not self.handlers[name].has_key(ns): ns='' |
|---|
| 277 |     if not self.handlers[name].has_key(typ): typ='' |
|---|
| 278 |     if not self.handlers[name].has_key(typns): typns='' |
|---|
| 279 |     if typ==typns: typns='' |
|---|
| 280 | |
|---|
| 281 | Â Â Â Â chain=[] |
|---|
| 282 |     for key in ['default',typ,ns,typns]: # we will use all handlers: from very common to very particular |
|---|
| 283 |       if key: chain += self.handlers[name][key] |
|---|
| 284 | |
|---|
| 285 | Â Â Â Â output='' |
|---|
| 286 | Â Â Â Â user=True |
|---|
| 287 |     for handler in chain: |
|---|
| 288 | Â Â Â Â Â Â try: |
|---|
| 289 |         if user or handler['system']: |
|---|
| 290 |           if handler['chain']: output=handler['func'](self,stanza,output) |
|---|
| 291 | Â Â Â Â Â Â Â Â Â Â else:Â handler['func'](self,stanza) |
|---|
| 292 |       except NodeProcessed: user=False |
|---|
| 293 | |
|---|
| 294 |   def registerProtocol(self,tag_name,Proto): |
|---|
| 295 | Â Â Â Â """Registers a protocol in protocol processing chain. You MUST register |
|---|
| 296 | Â Â Â Â Â Â a protocol before you register any handler function for it. |
|---|
| 297 | Â Â Â Â Â Â First parameter, that passed to this function is the tag name that |
|---|
| 298 | Â Â Â Â Â Â belongs to all protocol elements. F.e.: message, presence, iq, xdb, ... |
|---|
| 299 | Â Â Â Â Â Â Second parameter is the [ancestor of] Protocol class, which instance will |
|---|
| 300 | Â Â Â Â Â Â built from the received node with call |
|---|
| 301 | |
|---|
| 302 | Â Â Â Â Â Â Â Â if received_packet.getName()==tag_name: |
|---|
| 303 | Â Â Â Â Â Â Â Â Â Â stanza = Proto(node = received_packet) |
|---|
| 304 | Â Â Â Â """ |
|---|
| 305 |     self.handlers[tag_name]={type:Proto, 'default':[]} |
|---|
| 306 | |
|---|
| 307 |   def registerHandler(self,name,handler,type='',ns='',chained=False, makefirst=False, system=False): |
|---|
| 308 | Â Â Â Â """Sets the callback func for processing incoming stanzas. |
|---|
| 309 | Â Â Â Â Â Â Multiple callback functions can be set which are called in |
|---|
| 310 | Â Â Â Â Â Â succession. Callback can optionally raise an NodeProcessed error to |
|---|
| 311 | Â Â Â Â Â Â stop stanza from further processing. A type and namespace attributes can |
|---|
| 312 | Â Â Â Â Â Â also be optionally passed so the callback is only called when a stanza of |
|---|
| 313 | Â Â Â Â Â Â this type is received. Namespace attribute MUST be omitted if you |
|---|
| 314 | Â Â Â Â Â Â registering an Iq processing handler. |
|---|
| 315 | |
|---|
| 316 | Â Â Â Â Â Â If 'chainOutput' is set to False (the default), the given function |
|---|
| 317 | Â Â Â Â Â Â should be defined as follows: |
|---|
| 318 | |
|---|
| 319 | Â Â Â Â Â Â Â Â def myCallback(c, p) |
|---|
| 320 | |
|---|
| 321 | Â Â Â Â Â Â Where the first parameter is the Client object, and the second |
|---|
| 322 | Â Â Â Â Â Â parameter is the [ancestor of] Protocol object representing the stanza |
|---|
| 323 | Â Â Â Â Â Â which was received. |
|---|
| 324 | |
|---|
| 325 | Â Â Â Â Â Â If 'chainOutput' is set to True, the output from the various |
|---|
| 326 |       handler functions will be chained together. In this case, |
|---|
| 327 | Â Â Â Â Â Â the given callback function should be defined like this: |
|---|
| 328 | |
|---|
| 329 | Â Â Â Â Â Â Â Â def myCallback(c, p, output) |
|---|
| 330 | |
|---|
| 331 | Â Â Â Â Â Â Where 'output' is the value returned by the previous |
|---|
| 332 |       callback function. For the first callback routine, 'output' will be |
|---|
| 333 | Â Â Â Â Â Â set to an empty string. |
|---|
| 334 | |
|---|
| 335 | Â Â Â Â Â Â 'makefirst' argument gives you control over handler prioriy in its type |
|---|
| 336 | Â Â Â Â Â Â and namespace scope. Note that handlers for particular type or namespace always |
|---|
| 337 | Â Â Â Â Â Â have lower priority that common handlers. |
|---|
| 338 | Â Â Â Â """ |
|---|
| 339 |     if not type and not ns: type='default' |
|---|
| 340 |     if not self.handlers[name].has_key(type+ns): self.handlers[name][type+ns]=[] |
|---|
| 341 |     if makefirst: self.handlers[name][type+ns].insert({'chain':chained,'func':handler,'system':system}) |
|---|
| 342 | Â Â Â Â else:Â self.handlers[name][type+ns].append({'chain':chained,'func':handler,'system':system}) |
|---|
| 343 | |
|---|
| 344 |   def setDisconnectHandler(self, func): |
|---|
| 345 | Â Â Â Â """Set the callback for a disconnect. |
|---|
| 346 | Â Â Â Â Â Â The given function will be called with a single parameter (the |
|---|
| 347 | Â Â Â Â Â Â connection object) when the connection is broken unexpectedly (eg, |
|---|
| 348 |       in response to sending badly formed XML). self.lastErr and |
|---|
| 349 | Â Â Â Â Â Â self.lastErrCode will be set to the error which caused the |
|---|
| 350 | Â Â Â Â Â Â disconnection, if any. |
|---|
| 351 | Â Â Â Â """ |
|---|
| 352 | Â Â Â Â self.disconnectHandler =Â func |
|---|
| 353 | |
|---|
| 354 | Â Â ## functions for sending element with ID's ## |
|---|
| 355 | |
|---|
| 356 |   def waitForResponse(self, ID, timeout=timeout): |
|---|
| 357 | Â Â Â Â """Blocks untils a protocol element with the given id is received. |
|---|
| 358 | Â Â Â Â Â Â If an error is received, waitForResponse returns None and |
|---|
| 359 |       self.lastErr and self.lastErrCode is set to the received error. If |
|---|
| 360 | Â Â Â Â Â Â the operation times out (which only happens if a timeout value is |
|---|
| 361 | Â Â Â Â Â Â given), waitForResponse will return None and self.lastErr will be |
|---|
| 362 | Â Â Â Â Â Â set to "Timeout". |
|---|
| 363 | Â Â Â Â Â Â Changed default from timeout=0 to timeout=300 to avoid hangs in |
|---|
| 364 | Â Â Â Â Â Â scripts and such. |
|---|
| 365 | Â Â Â Â Â Â If you _really_ want no timeout, just set it to 0""" |
|---|
| 366 | Â Â Â Â ID =Â ustr(ID) |
|---|
| 367 | Â Â Â Â self._expected[ID]Â =Â None |
|---|
| 368 | Â Â Â Â has_timed_out =Â False |
|---|
| 369 | |
|---|
| 370 | Â Â Â Â abort_time =Â time.time()Â +Â timeout |
|---|
| 371 |     if timeout: |
|---|
| 372 |       self.DEBUG("waiting with timeout:%s for %s" % (timeout,ustr(ID)),DBG_NODE_IQ) |
|---|
| 373 | Â Â Â Â else: |
|---|
| 374 | Â Â Â Â Â Â self.DEBUG("waiting for %s"Â %Â ustr(ID),DBG_NODE_IQ) |
|---|
| 375 | |
|---|
| 376 |     while (not self._expected[ID]) and not has_timed_out: |
|---|
| 377 |       if not self.process(0.2): return None |
|---|
| 378 |       if timeout and (time.time() > abort_time): |
|---|
| 379 | Â Â Â Â Â Â Â Â has_timed_out =Â True |
|---|
| 380 |     if has_timed_out: |
|---|
| 381 | Â Â Â Â Â Â self.lastErr =Â "Timeout" |
|---|
| 382 |       return None |
|---|
| 383 | Â Â Â Â response =Â self._expected[ID] |
|---|
| 384 |     del self._expected[ID] |
|---|
| 385 |     if response.getErrorCode(): |
|---|
| 386 |       self.lastErr   = response.getError() |
|---|
| 387 | Â Â Â Â Â Â self.lastErrCode =Â response.getErrorCode() |
|---|
| 388 |       return None |
|---|
| 389 |     return response |
|---|
| 390 | |
|---|
| 391 |   def SendAndWaitForResponse(self, obj, ID=None, timeout=timeout): |
|---|
| 392 | Â Â Â Â """Sends a protocol element object and blocks until a response with |
|---|
| 393 |       the same ID is received. The received protocol object is returned |
|---|
| 394 | Â Â Â Â Â Â as the function result. """ |
|---|
| 395 |     if ID is None : |
|---|
| 396 | Â Â Â Â Â Â ID =Â obj.getID() |
|---|
| 397 |       if ID is None: |
|---|
| 398 | Â Â Â Â Â Â Â Â ID =Â self.getAnID() |
|---|
| 399 | Â Â Â Â Â Â Â Â obj.setID(ID) |
|---|
| 400 | Â Â Â Â ID =Â ustr(ID) |
|---|
| 401 | Â Â Â Â self.send(obj) |
|---|
| 402 |     return self.waitForResponse(ID,timeout) |
|---|
| 403 | |
|---|
| 404 |   def getAnID(self): |
|---|
| 405 | Â Â Â Â """Returns a unique ID""" |
|---|
| 406 | Â Â Â Â self._id =Â self._id +Â 1 |
|---|
| 407 |     return ustr(self._id) |
|---|
| 408 | |
|---|
| 409 | ############################################################################# |
|---|
| 410 | |
|---|
| 411 | class Client(Connection): |
|---|
| 412 | Â Â """Class for managing a client connection to a jabber server.""" |
|---|
| 413 |   def __init__(self, host, port=5222, debug=[], log=False, |
|---|
| 414 |          connection=xmlstream.TCP, hostIP=None, proxy=None): |
|---|
| 415 | |
|---|
| 416 |     Connection.__init__(self, host, port, NS_CLIENT, debug, log, |
|---|
| 417 |               connection=connection, hostIP=hostIP, proxy=proxy) |
|---|
| 418 | |
|---|
| 419 | Â Â Â Â self.registerHandler('iq',self._IqRosterManage,'result',NS_ROSTER,system=True) |
|---|
| 420 | Â Â Â Â self.registerHandler('iq',self._IqRosterManage,'set',NS_ROSTER,system=True) |
|---|
| 421 | Â Â Â Â self.registerHandler('iq',self._IqRegisterResult,'result',NS_REGISTER,system=True) |
|---|
| 422 | Â Â Â Â self.registerHandler('iq',self._IqAgentsResult,'result',NS_AGENTS,system=True) |
|---|
| 423 | Â Â Â Â self.registerHandler('presence',self._presenceHandler,system=True) |
|---|
| 424 | |
|---|
| 425 | Â Â Â Â self._roster =Â Roster() |
|---|
| 426 | Â Â Â Â self._agents =Â {} |
|---|
| 427 | Â Â Â Â self._reg_info =Â {} |
|---|
| 428 | Â Â Â Â self._reg_agent =Â '' |
|---|
| 429 | |
|---|
| 430 |   def disconnect(self): |
|---|
| 431 | Â Â Â Â """Safely disconnects from the connected server""" |
|---|
| 432 | Â Â Â Â self.send(Presence(type='unavailable')) |
|---|
| 433 | Â Â Â Â xmlstream.Client.disconnect(self) |
|---|
| 434 | |
|---|
| 435 |   def sendPresence(self,type=None,priority=None,show=None,status=None): |
|---|
| 436 | Â Â Â Â """Sends a presence protocol element to the server. |
|---|
| 437 | Â Â Â Â Â Â Used to inform the server that you are online""" |
|---|
| 438 | Â Â Â Â self.send(Presence(type=type,priority=priority,show=show,status=status)) |
|---|
| 439 | |
|---|
| 440 | Â Â sendInitPresence=sendPresence |
|---|
| 441 | |
|---|
| 442 |   def _presenceHandler(self, conn, pres_obj): |
|---|
| 443 | Â Â Â Â who =Â ustr(pres_obj.getFrom()) |
|---|
| 444 |     type = pres_obj.getType() |
|---|
| 445 | Â Â Â Â self.DEBUG("presence type is %s"Â %Â type,DBG_NODE_PRESENCE) |
|---|
| 446 |     if type == 'available' or not type: |
|---|
| 447 |       self.DEBUG("roster setting %s to online" % who,DBG_NODE_PRESENCE) |
|---|
| 448 | Â Â Â Â Â Â self._roster._setOnline(who,'online') |
|---|
| 449 |     elif type == 'unavailable': |
|---|
| 450 |       self.DEBUG("roster setting %s to offline" % who,DBG_NODE_PRESENCE) |
|---|
| 451 | Â Â Â Â Â Â self._roster._setOnline(who,'offline') |
|---|
| 452 | Â Â Â Â self._roster._setShow(who,pres_obj.getShow()) |
|---|
| 453 | Â Â Â Â self._roster._setStatus(who,pres_obj.getStatus()) |
|---|
| 454 | |
|---|
| 455 |   def _IqRosterManage(self, conn, iq_obj): |
|---|
| 456 | Â Â Â Â "NS_ROSTER and type in [result,set]" |
|---|
| 457 |     for item in iq_obj.getQueryNode().getChildren(): |
|---|
| 458 |       jid = item.getAttr('jid') |
|---|
| 459 | Â Â Â Â Â Â name =Â item.getAttr('name') |
|---|
| 460 |       sub = item.getAttr('subscription') |
|---|
| 461 |       ask = item.getAttr('ask') |
|---|
| 462 | |
|---|
| 463 | Â Â Â Â Â Â groups =Â [] |
|---|
| 464 |       for group in item.getTags("group"): |
|---|
| 465 | Â Â Â Â Â Â Â Â groups.append(group.getData()) |
|---|
| 466 | |
|---|
| 467 |       if jid: |
|---|
| 468 |         if sub == 'remove' or sub == 'none': |
|---|
| 469 | Â Â Â Â Â Â Â Â Â Â self._roster._remove(jid) |
|---|
| 470 | Â Â Â Â Â Â Â Â else: |
|---|
| 471 |           self._roster._set(jid=jid, name=name, |
|---|
| 472 |                    groups=groups, sub=sub, |
|---|
| 473 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ask=ask) |
|---|
| 474 | Â Â Â Â Â Â else: |
|---|
| 475 | Â Â Â Â Â Â Â Â self.DEBUG("roster - jid not defined ?",DBG_NODE_IQ) |
|---|
| 476 | |
|---|
| 477 |   def _IqRegisterResult(self, conn, iq_obj): |
|---|
| 478 | Â Â Â Â "NS_REGISTER and type==result" |
|---|
| 479 | Â Â Â Â self._reg_info =Â {} |
|---|
| 480 |     for item in iq_obj.getQueryNode().getChildren(): |
|---|
| 481 | Â Â Â Â Â Â self._reg_info[item.getName()]Â =Â item.getData() |
|---|
| 482 | |
|---|
| 483 |   def _IqAgentsResult(self, conn, iq_obj): |
|---|
| 484 | Â Â Â Â "NS_AGENTS and type==result" |
|---|
| 485 | Â Â Â Â self.DEBUG("got agents result",DBG_NODE_IQ) |
|---|
| 486 | Â Â Â Â self._agents =Â {} |
|---|
| 487 |     for agent in iq_obj.getQueryNode().getChildren(): |
|---|
| 488 |       if agent.getName() == 'agent': ## hmmm |
|---|
| 489 | Â Â Â Â Â Â Â Â self._agents[agent.getAttr('jid')]Â =Â {} |
|---|
| 490 |         for info in agent.getChildren(): |
|---|
| 491 | Â Â Â Â Â Â Â Â Â Â self._agents[agent.getAttr('jid')][info.getName()]Â =Â info.getData() |
|---|
| 492 | |
|---|
| 493 |   def auth(self,username,passwd,resource): |
|---|
| 494 | Â Â Â Â """Authenticates and logs in to the specified jabber server |
|---|
| 495 | Â Â Â Â Â Â Automatically selects the 'best' authentication method |
|---|
| 496 | Â Â Â Â Â Â provided by the server. |
|---|
| 497 | Â Â Â Â Â Â Supports plain text, digest and zero-k authentication. |
|---|
| 498 | |
|---|
| 499 | Â Â Â Â Â Â Returns True if the login was successful, False otherwise. |
|---|
| 500 | Â Â Â Â """ |
|---|
| 501 | Â Â Â Â auth_get_iq =Â Iq(type='get') |
|---|
| 502 | Â Â Â Â auth_get_iq.setID('auth-get') |
|---|
| 503 | Â Â Â Â q =Â auth_get_iq.setQuery(NS_AUTH) |
|---|
| 504 | Â Â Â Â q.insertTag('username').insertData(username) |
|---|
| 505 | Â Â Â Â self.send(auth_get_iq) |
|---|
| 506 | |
|---|
| 507 | Â Â Â Â auth_response =Â self.waitForResponse("auth-get") |
|---|
| 508 |     if auth_response == None: |
|---|
| 509 |       return False # Error |
|---|
| 510 | Â Â Â Â else: |
|---|
| 511 | Â Â Â Â Â Â auth_ret_node =Â auth_response |
|---|
| 512 | |
|---|
| 513 | Â Â Â Â auth_ret_query =Â auth_ret_node.getTag('query') |
|---|
| 514 | Â Â Â Â self.DEBUG("auth-get node arrived!",(DBG_INIT,DBG_NODE_IQ)) |
|---|
| 515 | |
|---|
| 516 | Â Â Â Â auth_set_iq =Â Iq(type='set') |
|---|
| 517 | Â Â Â Â auth_set_iq.setID('auth-set') |
|---|
| 518 | |
|---|
| 519 | Â Â Â Â q =Â auth_set_iq.setQuery(NS_AUTH) |
|---|
| 520 | Â Â Â Â q.insertTag('username').insertData(username) |
|---|
| 521 | Â Â Â Â q.insertTag('resource').insertData(resource) |
|---|
| 522 | |
|---|
| 523 |     if auth_ret_query.getTag('token'): |
|---|
| 524 | |
|---|
| 525 | Â Â Â Â Â Â token =Â auth_ret_query.getTag('token').getData() |
|---|
| 526 | Â Â Â Â Â Â seq =Â auth_ret_query.getTag('sequence').getData() |
|---|
| 527 | Â Â Â Â Â Â self.DEBUG("zero-k authentication supported",(DBG_INIT,DBG_NODE_IQ)) |
|---|
| 528 |       hash = sha.new(sha.new(passwd).hexdigest()+token).hexdigest() |
|---|
| 529 |       for foo in xrange(int(seq)): hash = sha.new(hash).hexdigest() |
|---|
| 530 | Â Â Â Â Â Â q.insertTag('hash').insertData(hash) |
|---|
| 531 | |
|---|
| 532 |     elif auth_ret_query.getTag('digest'): |
|---|
| 533 | |
|---|
| 534 | Â Â Â Â Â Â self.DEBUG("digest authentication supported",(DBG_INIT,DBG_NODE_IQ)) |
|---|
| 535 | Â Â Â Â Â Â digest =Â q.insertTag('digest') |
|---|
| 536 | Â Â Â Â Â Â digest.insertData(sha.new( |
|---|
| 537 | Â Â Â Â Â Â Â Â self.getIncomingID()Â +Â passwd).hexdigest()Â ) |
|---|
| 538 | Â Â Â Â else: |
|---|
| 539 | Â Â Â Â Â Â self.DEBUG("plain text authentication supported",(DBG_INIT,DBG_NODE_IQ)) |
|---|
| 540 | Â Â Â Â Â Â q.insertTag('password').insertData(passwd) |
|---|
| 541 | |
|---|
| 542 | Â Â Â Â iq_result =Â self.SendAndWaitForResponse(auth_set_iq) |
|---|
| 543 | |
|---|
| 544 |     if iq_result==None: |
|---|
| 545 |        return False |
|---|
| 546 |     if iq_result.getError() is None: |
|---|
| 547 |       return True |
|---|
| 548 | Â Â Â Â else: |
|---|
| 549 |       self.lastErr   = iq_result.getError() |
|---|
| 550 | Â Â Â Â Â Â self.lastErrCode =Â iq_result.getErrorCode() |
|---|
| 551 | Â Â Â Â Â Â # raise error(iq_result.getError()) ? |
|---|
| 552 |       return False |
|---|
| 553 |     return True |
|---|
| 554 | |
|---|
| 555 | Â Â ## Roster 'helper' func's - also see the Roster class ## |
|---|
| 556 | |
|---|
| 557 |   def requestRoster(self): |
|---|
| 558 | Â Â Â Â """Requests the roster from the server and returns a |
|---|
| 559 | Â Â Â Â Â Â Roster() class instance.""" |
|---|
| 560 | Â Â Â Â rost_iq =Â Iq(type='get') |
|---|
| 561 | Â Â Â Â rost_iq.setQuery(NS_ROSTER) |
|---|
| 562 | Â Â Â Â self.SendAndWaitForResponse(rost_iq) |
|---|
| 563 | Â Â Â Â self.DEBUG("got roster response",DBG_NODE_IQ) |
|---|
| 564 | Â Â Â Â self.DEBUG("roster -> %s"Â %Â ustr(self._roster),DBG_NODE_IQ) |
|---|
| 565 |     return self._roster |
|---|
| 566 | |
|---|
| 567 | |
|---|
| 568 |   def getRoster(self): |
|---|
| 569 | Â Â Â Â """Returns the current Roster() class instance. Does |
|---|
| 570 | Â Â Â Â Â Â not contact the server.""" |
|---|
| 571 |     return self._roster |
|---|
| 572 | |
|---|
| 573 | |
|---|
| 574 |   def addRosterItem(self, jid): |
|---|
| 575 | Â Â Â Â """ Send off a request to subscribe to the given jid. |
|---|
| 576 | Â Â Â Â """ |
|---|
| 577 |     self.send(Presence(to=jid, type="subscribe")) |
|---|
| 578 | |
|---|
| 579 | |
|---|
| 580 |   def updateRosterItem(self, jid, name=None, groups=None): |
|---|
| 581 | Â Â Â Â """ Update the information stored in the roster about a roster item. |
|---|
| 582 | |
|---|
| 583 | Â Â Â Â Â Â 'jid' is the Jabber ID of the roster entry; 'name' is the value to |
|---|
| 584 | Â Â Â Â Â Â set the entry's name to, and 'groups' is a list of groups to which |
|---|
| 585 |       this roster entry can belong. If either 'name' or 'groups' is not |
|---|
| 586 | Â Â Â Â Â Â specified, that value is not updated in the roster. |
|---|
| 587 | Â Â Â Â """ |
|---|
| 588 | Â Â Â Â iq =Â Iq(type='set') |
|---|
| 589 | Â Â Â Â item =Â iq.setQuery(NS_ROSTER).insertTag('item') |
|---|
| 590 |     item.putAttr('jid', ustr(jid)) |
|---|
| 591 |     if name != None: item.putAttr('name', name) |
|---|
| 592 |     if groups != None: |
|---|
| 593 |       for group in groups: |
|---|
| 594 | Â Â Â Â Â Â Â Â item.insertTag('group').insertData(group) |
|---|
| 595 | Â Â Â Â dummy =Â self.SendAndWaitForResponse(iq)Â # Do we need to wait?? |
|---|
| 596 | |
|---|
| 597 | |
|---|
| 598 |   def removeRosterItem(self,jid): |
|---|
| 599 | Â Â Â Â """Removes an item with Jabber ID jid from both the |
|---|
| 600 | Â Â Â Â Â Â server's roster and the local internal Roster() |
|---|
| 601 | Â Â Â Â Â Â instance""" |
|---|
| 602 | Â Â Â Â rost_iq =Â Iq(type='set') |
|---|
| 603 | Â Â Â Â q =Â rost_iq.setQuery(NS_ROSTER).insertTag('item') |
|---|
| 604 |     q.putAttr('jid', ustr(jid)) |
|---|
| 605 |     q.putAttr('subscription', 'remove') |
|---|
| 606 | Â Â Â Â self.SendAndWaitForResponse(rost_iq) |
|---|
| 607 |     return self._roster |
|---|
| 608 | |
|---|
| 609 | Â Â ## Registration 'helper' funcs ## |
|---|
| 610 | |
|---|
| 611 |   def requestRegInfo(self,agent=''): |
|---|
| 612 | Â Â Â Â """Requests registration info from the server. |
|---|
| 613 | Â Â Â Â Â Â Returns the Iq object received from the server.""" |
|---|
| 614 | #Â Â Â Â if agent: agent = agent + '.' |
|---|
| 615 | Â Â Â Â self._reg_info =Â {} |
|---|
| 616 | #Â Â Â Â reg_iq = Iq(type='get', to = agent + self._host) |
|---|
| 617 |     reg_iq = Iq(type='get', to = agent) |
|---|
| 618 | Â Â Â Â reg_iq.setQuery(NS_REGISTER) |
|---|
| 619 | #Â Â Â Â self.DEBUG("Requesting reg info from %s%s:" % (agent, self._host), DBG_NODE_IQ) |
|---|
| 620 |     self.DEBUG("Requesting reg info from %s:" % agent, DBG_NODE_IQ) |
|---|
| 621 | Â Â Â Â self.DEBUG(ustr(reg_iq),DBG_NODE_IQ) |
|---|
| 622 |     return self.SendAndWaitForResponse(reg_iq) |
|---|
| 623 | |
|---|
| 624 | |
|---|
| 625 |   def getRegInfo(self): |
|---|
| 626 | Â Â Â Â """Returns a dictionary of fields requested by the server for a |
|---|
| 627 |       registration attempt. Each dictionary entry maps from the name of |
|---|
| 628 | Â Â Â Â Â Â the field to the field's current value (either as returned by the |
|---|
| 629 | Â Â Â Â Â Â server or set programmatically by calling self.setRegInfo(). """ |
|---|
| 630 |     return self._reg_info |
|---|
| 631 | |
|---|
| 632 | |
|---|
| 633 |   def setRegInfo(self,key,val): |
|---|
| 634 | Â Â Â Â """Sets a name/value attribute. Note: requestRegInfo must be |
|---|
| 635 | Â Â Â Â Â Â called before setting.""" |
|---|
| 636 | Â Â Â Â self._reg_info[key]Â =Â val |
|---|
| 637 | |
|---|
| 638 | |
|---|
| 639 |   def sendRegInfo(self, agent=None): |
|---|
| 640 | Â Â Â Â """Sends the populated registration dictionary back to the server""" |
|---|
| 641 | #Â Â Â Â if agent: agent = agent + '.' |
|---|
| 642 |     if agent is None: agent = '' |
|---|
| 643 | #Â Â Â Â reg_iq = Iq(to = agent + self._host, type='set') |
|---|
| 644 |     reg_iq = Iq(to = agent, type='set') |
|---|
| 645 | Â Â Â Â q =Â reg_iq.setQuery(NS_REGISTER) |
|---|
| 646 |     for info in self._reg_info.keys(): |
|---|
| 647 | Â Â Â Â Â Â q.insertTag(info).putData(self._reg_info[info]) |
|---|
| 648 |     return self.SendAndWaitForResponse(reg_iq) |
|---|
| 649 | |
|---|
| 650 | |
|---|
| 651 |   def deregister(self, agent=None): |
|---|
| 652 | Â Â Â Â """ Send off a request to deregister with the server or with the given |
|---|
| 653 |       agent. Returns True if successful, else False. |
|---|
| 654 | |
|---|
| 655 | Â Â Â Â Â Â Note that you must be authorised before attempting to deregister. |
|---|
| 656 | Â Â Â Â """ |
|---|
| 657 |     if agent: |
|---|
| 658 | #Â Â Â Â Â Â agent = agent + '.' |
|---|
| 659 | #Â Â Â Â Â Â self.send(Presence(to=agent+self._host,type='unsubscribed'))Â Â Â Â # This is enough f.e. for icqv7t or jit |
|---|
| 660 | Â Â Â Â Â Â self.send(Presence(to=agent,type='unsubscribed'))Â Â Â Â # This is enough f.e. for icqv7t or jit |
|---|
| 661 |     if agent is None: agent = '' |
|---|
| 662 | Â Â Â Â q =Â self.requestRegInfo() |
|---|
| 663 | Â Â Â Â kids =Â q.getQueryPayload() |
|---|
| 664 | Â Â Â Â keyTag =Â kids.getTag("key") |
|---|
| 665 | |
|---|
| 666 | #Â Â Â Â iq = Iq(to=agent+self._host, type="set") |
|---|
| 667 |     iq = Iq(to=agent, type="set") |
|---|
| 668 | Â Â Â Â iq.setQuery(NS_REGISTER) |
|---|
| 669 | Â Â Â Â iq.setQueryNode("") |
|---|
| 670 | Â Â Â Â q =Â iq.getQueryNode() |
|---|
| 671 |     if keyTag != None: |
|---|
| 672 | Â Â Â Â Â Â q.insertXML("<key>"Â +Â keyTag.getData()Â +Â "</key>") |
|---|
| 673 | Â Â Â Â q.insertXML("<remove/>") |
|---|
| 674 | |
|---|
| 675 | Â Â Â Â result =Â self.SendAndWaitForResponse(iq) |
|---|
| 676 | |
|---|
| 677 |     if result == None: |
|---|
| 678 |       return False |
|---|
| 679 |     elif result.getType() == "result": |
|---|
| 680 |       return True |
|---|
| 681 | Â Â Â Â else: |
|---|
| 682 |       return False |
|---|
| 683 | |
|---|
| 684 | Â Â ## Agent helper funcs ## |
|---|
| 685 | |
|---|
| 686 |   def requestAgents(self): |
|---|
| 687 |     """Requests a list of available agents. Returns a dictionary |
|---|
| 688 | Â Â Â Â Â Â containing information about each agent; each entry in the |
|---|
| 689 | Â Â Â Â Â Â dictionary maps the agent's JID to a dictionary of attributes |
|---|
| 690 | Â Â Â Â Â Â describing what that agent can do (as returned by the |
|---|
| 691 | Â Â Â Â Â Â NS_AGENTS query).""" |
|---|
| 692 | Â Â Â Â self._agents =Â {} |
|---|
| 693 | Â Â Â Â agents_iq =Â |
|---|