Пример #1
0
    def accept(self,sock):
        """Accept an incoming client connection.

        [server only]

        :Parameters:
            - `sock`: a listening socket."""
        Stream.accept(self,sock,self.my_jid)
Пример #2
0
    def accept(self, sock):
        """Accept an incoming client connection.

        [server only]

        :Parameters:
            - `sock`: a listening socket."""
        Stream.accept(self, sock, self.my_jid)
Пример #3
0
    def fix_in_stanza(self,stanza):
        """Fix an incoming stanza.

        Ona server replace the sender address with authorized client JID."""
        if self.initiator:
            Stream.fix_in_stanza(self,stanza)
        else:
            stanza.set_from(self.peer)
Пример #4
0
    def fix_in_stanza(self, stanza):
        """Fix an incoming stanza.

        Ona server replace the sender address with authorized client JID."""
        if self.initiator:
            Stream.fix_in_stanza(self, stanza)
        else:
            stanza.set_from(self.peer)
Пример #5
0
    def stream_start(self, doc):
        """Process <stream:stream> (stream start) tag received from peer.

        Call `Stream.stream_start`, but ignore any `HostMismatch` error.

        :Parameters:
            - `doc`: document created by the parser"""
        try:
            Stream.stream_start(self, doc)
        except HostMismatch:
            pass
Пример #6
0
 def _connect(self,server=None,port=None):
     """Same as `ComponentStream.connect` but assume `self.lock` is acquired."""
     if self.me.node or self.me.resource:
         raise Value, "Component JID may have only domain defined"
     if not server:
         server=self.server
     if not port:
         port=self.port
     if not server or not port:
         raise ValueError, "Server or port not given"
     Stream._connect(self,server,port,None,self.me)
Пример #7
0
 def _connect(self, server=None, port=None):
     """Same as `ComponentStream.connect` but assume `self.lock` is acquired."""
     if self.me.node or self.me.resource:
         raise Value, "Component JID may have only domain defined"
     if not server:
         server = self.server
     if not port:
         port = self.port
     if not server or not port:
         raise ValueError, "Server or port not given"
     Stream._connect(self, server, port, None, self.me)
Пример #8
0
    def stream_start(self,doc):
        """Process <stream:stream> (stream start) tag received from peer.

        Call `Stream.stream_start`, but ignore any `HostMismatch` error.

        :Parameters:
            - `doc`: document created by the parser"""
        try:
            Stream.stream_start(self,doc)
        except HostMismatch:
            pass
Пример #9
0
    def __init__(self,
                 jid,
                 password=None,
                 server=None,
                 port=None,
                 auth_methods=("sasl:DIGEST-MD5", ),
                 tls_settings=None,
                 keepalive=0,
                 owner=None):
        """Initialize the ClientStream object.

        :Parameters:
            - `jid`: local JID.
            - `password`: user's password.
            - `server`: server to use. If not given then address will be derived form the JID.
            - `port`: port number to use. If not given then address will be derived form the JID.
            - `auth_methods`: sallowed authentication methods. SASL authentication mechanisms
              in the list should be prefixed with "sasl:" string.
            - `tls_settings`: settings for StartTLS -- `TLSSettings` instance.
            - `keepalive`: keepalive output interval. 0 to disable.
            - `owner`: `Client`, `Component` or similar object "owning" this stream.
        :Types:
            - `jid`: `pyxmpp.JID`
            - `password`: `unicode`
            - `server`: `unicode`
            - `port`: `int`
            - `auth_methods`: sequence of `str`
            - `tls_settings`: `pyxmpp.TLSSettings`
            - `keepalive`: `int`
        """
        sasl_mechanisms = []
        for m in auth_methods:
            if not m.startswith("sasl:"):
                continue
            m = m[5:].upper()
            sasl_mechanisms.append(m)
        Stream.__init__(self,
                        "jabber:client",
                        sasl_mechanisms=sasl_mechanisms,
                        tls_settings=tls_settings,
                        keepalive=keepalive,
                        owner=owner)
        self.server = server
        self.port = port
        self.password = password
        self.auth_methods = auth_methods
        self.my_jid = jid
        self.me = None
        self._auth_methods_left = None
        self.__logger = logging.getLogger("pyxmpp.ClientStream")
Пример #10
0
    def __init__(self, jid, password=None, server=None, port=None,
            auth_methods = ("sasl:DIGEST-MD5",),
            tls_settings = None, keepalive = 0, owner = None):
        """Initialize the ClientStream object.

        :Parameters:
            - `jid`: local JID.
            - `password`: user's password.
            - `server`: server to use. If not given then address will be derived form the JID.
            - `port`: port number to use. If not given then address will be derived form the JID.
            - `auth_methods`: sallowed authentication methods. SASL authentication mechanisms
              in the list should be prefixed with "sasl:" string.
            - `tls_settings`: settings for StartTLS -- `TLSSettings` instance.
            - `keepalive`: keepalive output interval. 0 to disable.
            - `owner`: `Client`, `Component` or similar object "owning" this stream.
        :Types:
            - `jid`: `pyxmpp.JID`
            - `password`: `unicode`
            - `server`: `unicode`
            - `port`: `int`
            - `auth_methods`: sequence of `str`
            - `tls_settings`: `pyxmpp.TLSSettings`
            - `keepalive`: `int`
        """
        sasl_mechanisms=[]
        for m in auth_methods:
            if not m.startswith("sasl:"):
                continue
            m=m[5:].upper()
            sasl_mechanisms.append(m)
        Stream.__init__(self, "jabber:client",
                    sasl_mechanisms = sasl_mechanisms,
                    tls_settings = tls_settings,
                    keepalive = keepalive,
                    owner = owner)
        self.server=server
        self.port=port
        self.password=password
        self.auth_methods=auth_methods
        self.my_jid=jid
        self.me = None
        self._auth_methods_left = None
        self.__logger=logging.getLogger("pyxmpp.ClientStream")
Пример #11
0
 def _connect(self,server=None,port=None):
     """Same as `ClientStream.connect` but assume `self.lock` is acquired."""
     if not self.my_jid.node or not self.my_jid.resource:
         raise ClientStreamError,"Client JID must have username and resource"
     if not server:
         server=self.server
     if not port:
         port=self.port
     if server:
         self.__logger.debug("server: %r", (server,))
         service=None
     else:
         service="xmpp-client"
     if port is None:
         port=5222
     if server is None:
         server=self.my_jid.domain
     self.me=self.my_jid
     Stream._connect(self,server,port,service,self.my_jid.domain)
Пример #12
0
 def _connect(self, server=None, port=None):
     """Same as `ClientStream.connect` but assume `self.lock` is acquired."""
     if not self.my_jid.node or not self.my_jid.resource:
         raise ClientStreamError, "Client JID must have username and resource"
     if not server:
         server = self.server
     if not port:
         port = self.port
     if server:
         self.__logger.debug("server: %r", (server, ))
         service = None
     else:
         service = "xmpp-client"
     if port is None:
         port = 5222
     if server is None:
         server = self.my_jid.domain
     self.me = self.my_jid
     Stream._connect(self, server, port, service, self.my_jid.domain)
Пример #13
0
    def _get_stream_features(self):
        """Include resource binding feature in the stream features list.

        [server only]"""
        features = Stream._get_stream_features(self)
        if self.peer_authenticated:
            bind = features.newChild(None, "bind", None)
            ns = bind.newNs(BIND_NS, None)
            bind.setNs(ns)
            self.set_iq_set_handler("bind", BIND_NS, self.do_bind)
        return features
Пример #14
0
    def _get_stream_features(self):
        """Include resource binding feature in the stream features list.

        [server only]"""
        features=Stream._get_stream_features(self)
        if self.peer_authenticated:
            bind=features.newChild(None,"bind",None)
            ns=bind.newNs(BIND_NS,None)
            bind.setNs(ns)
            self.set_iq_set_handler("bind",BIND_NS,self.do_bind)
        return features
Пример #15
0
    def __init__(self, jid, secret, server, port, keepalive=0, owner=None):
        """Initialize a `ComponentStream` object.

        :Parameters:
            - `jid`: JID of the component.
            - `secret`: authentication secret.
            - `server`: server address.
            - `port`: TCP port number on the server.
            - `keepalive`: keepalive interval. 0 to disable.
            - `owner`: `Client`, `Component` or similar object "owning" this stream.
        """
        Stream.__init__(
            self, "jabber:component:accept", sasl_mechanisms=[], tls_settings=None, keepalive=keepalive, owner=owner
        )
        self.server = server
        self.port = port
        self.me = jid
        self.secret = secret
        self.process_all_stanzas = 1
        self.__logger = logging.getLogger("pyxmpp.jabberd.ComponentStream")
Пример #16
0
    def __init__(self, jid, secret, server, port, keepalive = 0, owner = None):
        """Initialize a `ComponentStream` object.

        :Parameters:
            - `jid`: JID of the component.
            - `secret`: authentication secret.
            - `server`: server address.
            - `port`: TCP port number on the server.
            - `keepalive`: keepalive interval. 0 to disable.
            - `owner`: `Client`, `Component` or similar object "owning" this stream.
        """
        Stream.__init__(self, "jabber:component:accept",
                    sasl_mechanisms = [],
                    tls_settings = None,
                    keepalive = keepalive,
                    owner = owner)
        self.server=server
        self.port=port
        self.me=jid
        self.secret=secret
        self.process_all_stanzas=1
        self.__logger=logging.getLogger("pyxmpp.jabberd.ComponentStream")
Пример #17
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)
Пример #18
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)
Пример #19
0
 def _reset(self):
     """Reset `ComponentStream` object state, making the object ready to
     handle new connections."""
     Stream._reset(self)
Пример #20
0
 def _reset(self):
     """Reset `ClientStream` object state, making the object ready to handle
     new connections."""
     Stream._reset(self)
     self._auth_methods_left = []
Пример #21
0
 def _reset(self):
     """Reset `ClientStream` object state, making the object ready to handle
     new connections."""
     Stream._reset(self)
     self._auth_methods_left=[]
Пример #22
0
 def _reset(self):
     """Reset `ComponentStream` object state, making the object ready to
     handle new connections."""
     Stream._reset(self)