def _handle_bind(self, xml): try: bot = bumper.bot_get(self.uid) if bot: bumper.bot_set_xmpp(bot["did"], True) client = bumper.client_get(self.clientresource) if client: bumper.client_set_xmpp(client["resource"], True) clientbindxml = xml.getchildren() clientresourcexml = clientbindxml[0].getchildren() if self.devclass: # its a bot self.name = "XMPP_Client_{}_{}".format(self.uid, self.devclass) self.bumper_jid = "{}@{}.ecorobot.net/atom".format( self.uid, self.devclass ) xmppserverlog.debug("new bot {}".format(self.uid)) res = '<iq type="result" id="{}"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>{}</jid></bind></iq>'.format( xml.get("id"), self.bumper_jid ) elif len(clientresourcexml) > 0: self.clientresource = clientresourcexml[0].text self.name = "XMPP_Client_{}".format(self.clientresource) self.bumper_jid = "{}@{}/{}".format( self.uid, XMPPServer.server_id, self.clientresource ) xmppserverlog.debug( "new client {} using resource {}".format( self.uid, self.clientresource ) ) res = '<iq type="result" id="{}"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>{}</jid></bind></iq>'.format( xml.get("id"), self.bumper_jid ) else: self.name = "XMPP_Client_{}_{}".format(self.uid, self.address) self.bumper_jid = "{}@{}".format(self.uid, XMPPServer.server_id) xmppserverlog.debug("new client {}".format(self.uid)) res = '<iq type="result" id="{}"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>{}</jid></bind></iq>'.format( xml.get("id"), self.bumper_jid ) self._set_state("BIND") self.send(res) except Exception as e: xmppserverlog.exception("{}".format(e))
def _disconnect(self): try: bot = bumper.bot_get(self.uid) if bot: bumper.bot_set_xmpp(bot["did"], False) client = bumper.client_get(self.clientresource) if client: bumper.client_set_xmpp(client["resource"], False) self.transport.close() except Exception as e: xmppserverlog.error("{}".format(e))
def test_bot_db(): bumper.db = "tests/tmp.db" # Set db location for testing bumper.bot_add("sn_123", "did_123", "dev_123", "res_123", "co_123") assert_true(bumper.bot_get("did_123")) # Test that bot was added to db bumper.bot_set_nick("did_123", "nick_123") assert_equals(bumper.bot_get("did_123")["nick"], "nick_123") # Test that nick was added to bot bumper.bot_set_mqtt("did_123", True) assert_true(bumper.bot_get("did_123") ["mqtt_connection"]) # Test that mqtt was set True for bot bumper.bot_set_xmpp("did_123", True) assert_true(bumper.bot_get("did_123") ["xmpp_connection"]) # Test that xmpp was set True for bot bumper.bot_remove("did_123") assert_false(bumper.bot_get("did_123")) # Test that bot is no longer in db