1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 """Generic XMPP stream implementation.
19
20 Normative reference:
21 - `RFC 3920 <http://www.ietf.org/rfc/rfc3920.txt>`__
22 """
23
24 __docformat__="restructuredtext en"
25
26 import logging
27
28 from pyxmpp.streambase import StreamBase
29 from pyxmpp.streamtls import StreamTLSMixIn
30 from pyxmpp.streamsasl import StreamSASLMixIn
31
32 -class Stream(StreamTLSMixIn,StreamSASLMixIn,StreamBase):
33 """Generic XMPP stream class.
34
35 Responsible for establishing connection, parsing the stream,
36 StartTLS encryption and SASL authentication negotiation
37 and usage, dispatching received stanzas to apopriate handlers
38 and sending application's stanzas.
39
40 Whenever we say "stream" here we actually mean two streams
41 (incoming and outgoing) of one connections, as defined by the XMPP
42 specification.
43
44 :Ivariables:
45 - `lock`: RLock object used to synchronize access to Stream object.
46 - `features`: stream features as annouced by the initiator.
47 - `me`: local stream endpoint JID.
48 - `peer`: remote stream endpoint JID.
49 - `process_all_stanzas`: when `True` then all stanzas received are
50 considered local.
51 - `tls`: TLS connection object.
52 - `initiator`: `True` if local stream endpoint is the initiating entity.
53 - `_reader`: the stream reader object (push parser) for the stream.
54 """
55 - def __init__(self, default_ns, extra_ns = (), sasl_mechanisms = (),
56 tls_settings = None, keepalive = 0, owner = None):
57 """Initialize Stream object
58
59 :Parameters:
60 - `default_ns`: stream's default namespace ("jabber:client" for
61 client, "jabber:server" for server, etc.)
62 - `extra_ns`: sequence of extra namespace URIs to be defined for
63 the stream.
64 - `sasl_mechanisms`: sequence of SASL mechanisms allowed for
65 authentication. Currently "PLAIN", "DIGEST-MD5" and "GSSAPI" are supported.
66 - `tls_settings`: settings for StartTLS -- `TLSSettings` instance.
67 - `keepalive`: keepalive output interval. 0 to disable.
68 - `owner`: `Client`, `Component` or similar object "owning" this stream.
69 """
70 StreamBase.__init__(self, default_ns, extra_ns, keepalive, owner)
71 StreamTLSMixIn.__init__(self, tls_settings)
72 StreamSASLMixIn.__init__(self, sasl_mechanisms)
73 self.__logger = logging.getLogger("pyxmpp.Stream")
74
81
92
94 """Process first level element of the stream.
95
96 The element may be stream error or features, StartTLS
97 request/response, SASL request/response or a stanza.
98
99 :Parameters:
100 - `xmlnode`: XML node describing the element
101 """
102 if self._process_node_tls(xmlnode):
103 return
104 if self._process_node_sasl(xmlnode):
105 return
106 StreamBase._process_node(self,xmlnode)
107
120
121
122