Example #1
0
 def iqReceived(self, cnx, iq):
     queries = iq.getChildren() # there should be only one
     if 0 == len(queries):
         return
     ns = queries[0].getNamespace()
     typ = iq.getType()
     requester = UserAccount(iq.getFrom())
     if NS_VCARD == ns and ('get' == typ):
         reply = iq.buildReply('result')
         query = reply.getQuery()
         if requester == self or requester.isAdmin():
             query.addChild('FN', payload=[self.jid])
         query.addChild('NICKNAME', payload=[self.username])
         cnx.send(reply)
         raise NodeProcessed
     Addressable.iqReceived(self, cnx, iq)
Example #2
0
 def iqReceived(self, cnx, iq):
     queries = iq.getChildren() # there should be only one
     if 0 == len(queries):
         return
     ns = queries[0].getNamespace()
     typ = iq.getType()
     if NS_VCARD == ns and ('get' == typ):
         reply = iq.buildReply('result')
         query = reply.getQuery()
         query.addChild('FN', payload=[self.address])
         #TODO: More generic URL generation
         query.addChild('URL', payload=[_(DEFAULT, 'url_bitcoin_address').format(address=self.address)])
         pic = self.qrCode(level='H', formt='PNG')
         if pic is not None:
             photo = query.addChild('PHOTO')
             photo.addChild('TYPE', payload='image/png')
             from base64 import b64encode
             photo.addChild('BINVAL', payload=[b64encode(pic)])
         cnx.send(reply)
         raise NodeProcessed
     Addressable.iqReceived(self, cnx, iq)
Example #3
0
 def iqReceived(self, cnx, iq):
     '''IQ handler for the component'''
     typ = iq.getType()
     queries = iq.getChildren() # there should be only one
     if 0 == len(queries):
         return
     ns = queries[0].getNamespace()
     debug("OK we're handling IQ %s, ns=%s" % (typ, ns))
     if NS_REGISTER == ns:
         if 'set' == typ:
             children = iq.getQueryChildren()
             if (0 != len(children)) and ('remove' == children[0].getName()):
                 self.unregistrationRequested(iq)
             else:
                 self.registrationRequested(iq)
             raise NodeProcessed
         elif 'get' == typ:
             instructions = Node('instructions')
             username = Node('username')
             user = UserAccount(iq.getFrom())
             registered = user.isRegistered()
             if registered:
                 instructions.setData(_(REGISTRATION, 'set_username'))
                 username.setData(user.username)
             else:
                 debug("A new user is preparing a registration")
                 instructions.setData(_(REGISTRATION, 'introduction'))
             reply = iq.buildReply('result')
             query = reply.getQuery()
             if registered:
                 query.addChild('registered')
             query.addChild(node=instructions)
             query.addChild(node=username)
             cnx.send(reply)
             raise NodeProcessed
         else:
             # Unkown namespace and type. The default handler will take care of it if we don't raise NodeProcessed.
             debug("Unknown IQ with ns '%s' and type '%s'." % (ns, typ))
     elif NS_GATEWAY == ns:
         if 'get' == typ:
             reply = iq.buildReply('result')
             query = reply.getQuery()
             query.addChild('desc', payload=[_(ROSTER, 'address2jid_description')])
             query.addChild('prompt', payload=[_(ROSTER, 'address2jid_prompt')])
             cnx.send(reply)
             raise NodeProcessed
         elif 'set' == typ:
             children = iq.getQueryChildren()
             if (0 != len(children)) and ('prompt' == children[0].getName()):
                 prompt = children[0].getData()
                 debug("Someone wants to convert %s into a JID" % prompt)
                 jid = Node('jid')
                 try:
                     jid.setData(Address(prompt).jid)
                 except InvalidBitcoinAddressError:
                     try:
                         jid.setData(UserAccount(prompt).getLocalJID())
                     except UnknownUserError:
                         reply = iq.buildReply(typ='error')
                         reply.addChild(node=ErrorNode('item-not-found', 404, 'cancel', _(ROSTER, 'address2jid_invalid')))
                         cnx.send(reply)
                         raise NodeProcessed
                 reply = iq.buildReply('result')
                 query = reply.getQuery()
                 query.addChild(node=jid)
                 cnx.send(reply)
                 raise NodeProcessed
     elif NS_VCARD == ns:
         if 'get' == typ:
             reply = iq.buildReply('result')
             query = reply.getQuery()
             query.addChild('FN', payload=["%s v%s" % (LIB_NAME, LIB_VERSION)])
             query.addChild('DESC', payload=[LIB_DESCRIPTION])
             cnx.send(reply)
             raise NodeProcessed
     Addressable.iqReceived(self, cnx, iq)