示例#1
0
def _process_node(self,xmlnode):
    """Process first level element of the stream.

    The element may be stream error or features, StartTLS
    request/response, SASL request/response or a stanza.

    :Parameters:
        - `xmlnode`: XML node describing the element
    """
    ns_uri=xmlnode.ns().getContent()
    if ns_uri=="http://etherx.jabber.org/streams":
        self._process_stream_node(xmlnode)
        return

    if ns_uri==self.default_ns_uri:
        stanza=streambase.stanza_factory(xmlnode, self)
        stanza.handler_frees = False
        self.lock.release()
        try:
            self.process_stanza(stanza)
        finally:
            self.lock.acquire()
            if not stanza.handler_frees:
                stanza.free()
    else:
        self.__logger.debug("Unhandled node: %r" % (xmlnode.serialize(),))
示例#2
0
    def message_from_shazbot(self, data):
        doc = libxml2.parseDoc(data)
        node = doc.getRootElement()

        # Change the from to the full JID
        stanza = stanza_factory(node)
        stanza.set_from(self.game_jid)

        stream = self.get_stream()

        # Have to register Iq stanzas or we'll lose the reply
        if stanza.stanza_type == 'iq':
            if stanza.get_type() in ('get', 'set'):
                stream.set_response_handlers(stanza, self.game_iq_success, self.game_iq_error)

        stream.send(stanza)
        doc.freeDoc()
示例#3
0
    def _process_node(self, node):
        """Process first level element of the stream.

        Handle component handshake (authentication) element, and
        treat elements in "jabber:component:accept", "jabber:client"
        and "jabber:server" equally (pass to `self.process_stanza`).
        All other elements are passed to `Stream._process_node`.

        :Parameters:
            - `node`: XML node describing the element
        """
        ns = node.ns()
        if ns:
            ns_uri = node.ns().getContent()
        if (not ns or ns_uri == "jabber:component:accept") and node.name == "handshake":
            if self.initiator and not self.authenticated:
                self.authenticated = 1
                self.state_change("authenticated", self.me)
                self._post_auth()
                return
            elif not self.authenticated and node.getContent() == self._compute_handshake():
                self.peer = self.me
                n = common_doc.newChild(None, "handshake", None)
                self._write_node(n)
                n.unlinkNode()
                n.freeNode()
                self.peer_authenticated = 1
                self.state_change("authenticated", self.peer)
                self._post_auth()
                return
            else:
                self._send_stream_error("not-authorized")
                raise FatalComponentStreamError, "Hanshake error."

        if ns_uri in ("jabber:component:accept", "jabber:client", "jabber:server"):
            stanza = stanza_factory(node)
            self.lock.release()
            try:
                self.process_stanza(stanza)
            finally:
                self.lock.acquire()
                stanza.free()
            return
        return Stream._process_node(self, node)
示例#4
0
    def _process_node(self,node):
        """Process first level element of the stream.

        Handle component handshake (authentication) element, and
        treat elements in "jabber:component:accept", "jabber:client"
        and "jabber:server" equally (pass to `self.process_stanza`).
        All other elements are passed to `Stream._process_node`.

        :Parameters:
            - `node`: XML node describing the element
        """
        ns=node.ns()
        if ns:
            ns_uri=node.ns().getContent()
        if (not ns or ns_uri=="jabber:component:accept") and node.name=="handshake":
            if self.initiator and not self.authenticated:
                self.authenticated=1
                self.state_change("authenticated",self.me)
                self._post_auth()
                return
            elif not self.authenticated and node.getContent()==self._compute_handshake():
                self.peer=self.me
                n=common_doc.newChild(None,"handshake",None)
                self._write_node(n)
                n.unlinkNode()
                n.freeNode()
                self.peer_authenticated=1
                self.state_change("authenticated",self.peer)
                self._post_auth()
                return
            else:
                self._send_stream_error("not-authorized")
                raise FatalComponentStreamError,"Hanshake error."

        if ns_uri in ("jabber:component:accept","jabber:client","jabber:server"):
            stanza=stanza_factory(node)
            self.lock.release()
            try:
                self.process_stanza(stanza)
            finally:
                self.lock.acquire()
                stanza.free()
            return
        return Stream._process_node(self,node)