コード例 #1
0
ファイル: test_db.py プロジェクト: gitter-badger/bumper-1
def test_client_db():
    bumper.db = "tests/tmp.db"  # Set db location for testing
    bumper.client_add("user_123", "realm_123", "resource_123")
    assert bumper.client_get("resource_123")  # Test client was added

    bumper.client_set_mqtt("resource_123", True)
    assert bumper.client_get("resource_123")[
        "mqtt_connection"]  # Test that mqtt was set True for client

    bumper.client_set_xmpp("resource_123", False)
    assert (bumper.client_get("resource_123")["xmpp_connection"] == False
            )  # Test that xmpp was set False for client
    assert (len(bumper.get_disconnected_xmpp_clients()) == 1
            )  # Test len of connected xmpp clients is 1
コード例 #2
0
ファイル: xmppserver.py プロジェクト: erkkah/bumper
    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))
コード例 #3
0
    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))