Package pyxmpp :: Module clientstream :: Class ClientStream |
[hide private]

# Class ClientStream

source code

               streamtls.StreamTLSMixIn --+
                                          |
          sasl.core.PasswordManager --+   |
                                      |   |
             streamsasl.StreamSASLMixIn --+
                                          |
    stanzaprocessor.StanzaProcessor --+   |
                                      |   |
             xmlextra.StreamHandler --+   |
                                      |   |
                  streambase.StreamBase --+
                                          |
                              stream.Stream --+
                                              |
                                             ClientStream

Known Subclasses:
  - jabber.clientstream.LegacyClientStream

Handles XMPP-IM client connection stream.

Both client and server side of the connection is supported. This class handles client SASL authentication, authorisation and resource binding.

This class is not ready for handling of legacy Jabber servers, as it doesn't provide legacy authentication.

Instance Methods | [hide private]
__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. | source code
_connect(self, server=None, port=None) Same as ClientStream.connect but assume self.lock is acquired. | source code
_get_stream_features(self) Include resource binding feature in the stream features list. | source code
_post_connect(self) Initialize authentication when the connection is established and we are the initiator. | source code
_reset(self) Reset ClientStream object state, making the object ready to handle new connections. | source code
_try_auth(self) Try to authenticate using the first one of allowed authentication methods left. | source code
accept(self, sock) Accept an incoming client connection. | source code
`bool` |
check_authzid(self, authzid, extra_info=None) Check authorization id provided by the client. | source code
`unicode` |
choose_realm(self, realm_list) Choose authentication realm from the list provided by the server. | source code
connect(self, server=None, port=None) Establish a client connection to a server. | source code
do_bind(self, stanza) Do the resource binding requested by a client connected. | source code
fix_in_stanza(self, stanza) Fix an incoming stanza. | source code
fix_out_stanza(self, stanza) Fix outgoing stanza. | source code
(`unicode`,`str`) |
get_password(self, username, realm=None, acceptable_formats=`(``'``plain``'``)`) Get a user password for the SASL authentication. | source code
`list` of `unicode` |
get_realms(self) Get realms available for client authentication. | source code
get_serv_host(self) Get the service host name for SASL authentication. | source code
get_serv_name(self) Get the service name for SASL authentication. | source code
get_serv_type(self) Get the server name for SASL authentication. | source code
Inherited from `stream.Stream` (private): `_got_features`, `_make_stream_features`, `_process_node` Inherited from `streamtls.StreamTLSMixIn`: `get_tls_connection`, `tls_is_certificate_valid` Inherited from `streamtls.StreamTLSMixIn` (private): `_handle_tls_features`, `_make_stream_tls_features`, `_make_tls_connection`, `_process`, `_process_node_tls`, `_process_tls_node`, `_read`, `_read_tls`, `_request_tls`, `_reset_tls`, `_write_raw` Inherited from `streamsasl.StreamSASLMixIn` (private): `_handle_sasl_features`, `_make_stream_sasl_features`, `_process_node_sasl`, `_process_sasl_abort`, `_process_sasl_auth`, `_process_sasl_challenge`, `_process_sasl_failure`, `_process_sasl_node`, `_process_sasl_response`, `_process_sasl_success`, `_reset_sasl`, `_sasl_authenticate` Inherited from `sasl.core.PasswordManager`: `check_password`, `generate_nonce` Inherited from `streambase.StreamBase`: `__del__`, `bind`, `check_to`, `close`, `connected`, `disconnect`, `error`, `fileno`, `generate_id`, `idle`, `loop`, `loop_iter`, `process`, `process_stream_error`, `send`, `stanza`, `stanza_start`, `state_change`, `stream_end`, `stream_start`, `write_raw` Inherited from `streambase.StreamBase` (private): `_accept`, `_bind_error`, `_bind_success`, `_close`, `_connect_socket`, `_disconnect`, `_feed_reader`, `_idle`, `_loop_iter`, `_make_reader`, `_post_auth`, `_process_stream_node`, `_restart_stream`, `_send`, `_send_stream_end`, `_send_stream_error`, `_send_stream_features`, `_send_stream_start`, `_write_node` Inherited from `stanzaprocessor.StanzaProcessor`: `process_iq`, `process_message`, `process_presence`, `process_response`, `process_stanza`, `route_stanza`, `set_iq_get_handler`, `set_iq_set_handler`, `set_message_handler`, `set_presence_handler`, `set_response_handlers`, `unset_iq_get_handler`, `unset_iq_set_handler` Inherited from `stanzaprocessor.StanzaProcessor` (private): `_set_response_handlers` Inherited from `xmlextra.StreamHandler`: `warning` Inherited from `xmlextra.StreamHandler` (private): `_stanza`, `_stream_end`, `_stream_start`

Instance Variables | [hide private]
: `list` of `str` | auth_methods : allowed authentication methods.
: pyxmpp.JID | my_jid : requested local JID.
: `str` | password : user's password.
: `int` | port : port number to use.
: `str` | server : server to use.
Inherited from `stream.Stream`: `features`, `initiator`, `lock`, `me`, `peer`, `process_all_stanzas`, `tls` Inherited from `stream.Stream` (private): `_reader` Inherited from `streambase.StreamBase`: `owner`

Method Details | [hide private]

### __init__(self, jid, password=None, server=None, port=None, auth_methods=`(``'``sasl:DIGEST-MD5``'``)`, tls_settings=None, keepalive=0, owner=None) (Constructor) | source code
Initialize the ClientStream object. Parameters: `jid` (: pyxmpp.JID) - : local JID. `password` (: `unicode`) - : user's password. `server` (: `unicode`) - : server to use. If not given then address will be derived form the JID. `port` (: `int`) - : port number to use. If not given then address will be derived form the JID. `auth_methods` (: sequence of `str`) - : sallowed authentication methods. SASL authentication mechanisms in the list should be prefixed with "sasl:" string. `tls_settings` (: pyxmpp.TLSSettings) - : settings for StartTLS -- TLSSettings instance. `keepalive` (: `int`) - : keepalive output interval. 0 to disable. `owner` - : Client, Component or similar object "owning" this stream. Overrides: xmlextra.StreamHandler.__init__

### _connect(self, server=None, port=None) | source code
Same as ClientStream.connect but assume self.lock is acquired. Overrides: streambase.StreamBase._connect

### _get_stream_features(self) | source code
Include resource binding feature in the stream features list. [server only]

### _post_connect(self) | source code
Initialize authentication when the connection is established and we are the initiator. Overrides: streambase.StreamBase._post_connect

### _reset(self) | source code
Reset ClientStream object state, making the object ready to handle new connections. Overrides: streambase.StreamBase._reset

### _try_auth(self) | source code
Try to authenticate using the first one of allowed authentication methods left. [client only]

### accept(self, sock) | source code
Accept an incoming client connection. [server only] Parameters: `sock` - : a listening socket. Overrides: streambase.StreamBase.accept

### check_authzid(self, authzid, extra_info=None) | source code
Check authorization id provided by the client. [server only] Parameters: `authzid` (: unicode) - : authorization id provided. `extra_info` (: mapping) - : additional information about the user from the authentication backend. This mapping will usually contain at least 'username' item. Returns: `bool` `True` if user is authorized to use that `authzid`. Overrides: sasl.core.PasswordManager.check_authzid

### choose_realm(self, realm_list) | source code
Choose authentication realm from the list provided by the server. [client only] Use domain of the own JID if no realm list was provided or the domain is on the list or the first realm on the list otherwise. Parameters: `realm_list` (: `list` of `unicode`) - : realm list provided by the server. Returns: `unicode` the realm chosen. Overrides: sasl.core.PasswordManager.choose_realm

### connect(self, server=None, port=None) | source code
Establish a client connection to a server. [client only] Parameters: `server` (: `unicode`) - : name or address of the server to use. Not recommended -- proper value should be derived automatically from the JID. `port` (: `int`) - : port number of the server to use. Not recommended -- proper value should be derived automatically from the JID. Overrides: streambase.StreamBase.connect

### do_bind(self, stanza) | source code
Do the resource binding requested by a client connected. [server only] Parameters: `stanza` (: pyxmpp.Iq) - : resource binding request stanza.

### fix_in_stanza(self, stanza) | source code
Fix an incoming stanza. Ona server replace the sender address with authorized client JID. Overrides: stanzaprocessor.StanzaProcessor.fix_in_stanza

### fix_out_stanza(self, stanza) | source code
Fix outgoing stanza. On a client clear the sender JID. On a server set the sender address to the own JID if the address is not set yet. Overrides: stanzaprocessor.StanzaProcessor.fix_out_stanza

### get_password(self, username, realm=None, acceptable_formats=`(``'``plain``'``)`) | source code
Get a user password for the SASL authentication. Parameters: `username` (: `unicode`) - : username used for authentication. `realm` (: `unicode`) - : realm used for authentication. `acceptable_formats` (: `list` of `str`) - : acceptable password encoding formats requested. Returns: (`unicode`,`str`) The password and the format name ('plain'). Overrides: sasl.core.PasswordManager.get_password

### get_realms(self) | source code
Get realms available for client authentication. [server only] Returns: `list` of `unicode` list of realms. Overrides: sasl.core.PasswordManager.get_realms

### get_serv_host(self) | source code
Get the service host name for SASL authentication. Returns: domain of the own JID. Overrides: sasl.core.PasswordManager.get_serv_host

### get_serv_name(self) | source code
Get the service name for SASL authentication. Returns: domain of the own JID. Overrides: sasl.core.PasswordManager.get_serv_name

### get_serv_type(self) | source code
Get the server name for SASL authentication. Returns: 'xmpp'. Overrides: sasl.core.PasswordManager.get_serv_type

Instance Variable Details | [hide private]

### my_jid : requested local JID. Please notice that this may differ from me, which is actual authorized JID after the resource binding. Type: : pyxmpp.JID