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

Class ClientStream

StanzaProcessor --+        
                  |        
  StreamHandler --+        
                  |        
         StreamBase --+    
                      |    
PasswordManager --+   |    
                  |   |    
    StreamSASLMixIn --+    
                      |    
     StreamTLSMixIn --+    
                      |    
                 Stream --+
                          |
                         ClientStream

Known Subclasses:
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.


Method Summary
  __init__(self, jid, password, server, port, auth_methods, tls_settings, keepalive)
Initialize the ClientStream object.
  accept(self, sock)
Accept an incoming client connection.
bool check_authzid(self, authzid, extra_info)
Check authorization id provided by the client.
unicode choose_realm(self, realm_list)
Choose authentication realm from the list provided by the server.
  connect(self, server, port)
Establish a client connection to a server.
  do_bind(self, stanza)
Do the resource binding requested by a client connected.
  fix_in_stanza(self, stanza)
Fix an incoming stanza.
  fix_out_stanza(self, stanza)
Fix outgoing stanza.
(unicode,`str`) get_password(self, username, realm, acceptable_formats)
Get a user password for the SASL authentication.
list of unicode get_realms(self)
Get realms available for client authentication.
  get_serv_host(self)
Get the service host name for SASL authentication.
  get_serv_name(self)
Get the service name for SASL authentication.
  get_serv_type(self)
Get the server name for SASL authentication.
    Inherited from StreamTLSMixIn
  get_tls_connection(self)
Get the TLS connection object for the stream.
    Inherited from PasswordManager
bool check_password(self, username, password, realm)
Check the password validity.
str generate_nonce(self)
Generate a random string for digest authentication challenges.
    Inherited from StreamBase
  __del__(self)
  bind(self, resource)
Bind to a resource.
  check_to(self, to)
Check "to" attribute of received stream header.
  close(self)
Forcibly close the connection and clear the stream state.
  connected(self)
Check if stream is connected.
  disconnect(self)
Gracefully close the connection.
  error(self, descr)
Handle stream XML parse error.
  fileno(self)
Return filedescriptor of the stream socket.
  generate_id(self)
Generate a random and unique stream ID.
  idle(self)
Do some housekeeping (cache expiration, timeout handling).
  loop(self, timeout)
Simple "main loop" for the stream.
  loop_iter(self, timeout)
Single iteration of a simple "main loop" for the stream.
  process(self)
Process stream's pending events.
  process_stream_error(self, err)
Process stream error element received.
  send(self, stanza)
Write stanza to the stream.
  stanza(self, _unused, node)
Process stanza (first level child element of the stream).
  stanza_start(self, doc, node)
Process stanza (first level child element of the stream) start tag -- do nothing.
  state_change(self, state, arg)
Called when connection state is changed.
  stream_end(self, _unused)
Process </stream:stream> (stream end) tag received from peer.
  stream_start(self, doc)
Process <stream:stream> (stream start) tag received from peer.
  write_raw(self, data)
Write raw data to the stream socket.
    Inherited from StanzaProcessor
  process_iq(self, stanza)
Process IQ stanza received.
  process_message(self, stanza)
Process message stanza.
  process_presence(self, stanza)
Process presence stanza.
  process_stanza(self, stanza)
Process stanza received from the stream.
  route_stanza(self, stanza)
Process stanza not addressed to us.
  set_iq_get_handler(self, element, namespace, handler)
Set <iq type="get"/> handler.
  set_iq_set_handler(self, element, namespace, handler)
Set <iq type="set"/> handler.
  set_message_handler(self, typ, handler, namespace, priority)
Set a handler for <message/> stanzas.
  set_presence_handler(self, typ, handler, namespace, priority)
Set a handler for <presence/> stanzas.
  set_response_handlers(self, iq, res_handler, err_handler, timeout_handler, timeout)
Set response handler for an IQ "get" or "set" stanza.
  unset_iq_get_handler(self, element, namespace)
Remove <iq type="get"/> handler.
  unset_iq_set_handler(self, element, namespace)
Remove <iq type="set"/> handler.

Instance Variable Summary
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
  features: stream features as annouced by the initiator.
  initiator: True if local stream endpoint is the initiating entity.
  lock: RLock object used to synchronize access to Stream object.
  me: local stream endpoint JID.
  peer: remote stream endpoint JID.
  process_all_stanzas: when True then all stanzas received are considered local.
  tls: TLS connection object.

Method Details

__init__(self, jid, password=None, server=None, port=None, auth_methods=('sasl:DIGEST-MD5',), tls_settings=None, keepalive=0)
(Constructor)

Initialize the ClientStream object.
Parameters:
jid - local JID.
           (type=pyxmpp.JID)
password - user's password.
           (type=unicode)
server - server to use. If not given then address will be derived form the JID.
           (type=unicode)
port - port number to use. If not given then address will be derived form the JID.
           (type=int)
auth_methods - sallowed authentication methods. SASL authentication mechanisms in the list should be prefixed with "sasl:" string.
           (type=sequence of str)
tls_settings - settings for StartTLS -- TLSSettings instance.
           (type=pyxmpp.TLSSettings)
keepalive - keepalive output interval. 0 to disable.
           (type=int)
Overrides:
pyxmpp.stream.Stream.__init__

accept(self, sock)

Accept an incoming client connection.

[server only]

Parameters:
sock - a listening socket.
Overrides:
pyxmpp.streambase.StreamBase.accept

check_authzid(self, authzid, extra_info=None)

Check authorization id provided by the client.

[server only]

Parameters:
authzid - authorization id provided.
           (type=unicode)
extra_info - additional information about the user from the authentication backend. This mapping will usually contain at least 'username' item.
           (type=mapping)
Returns:
True if user is authorized to use that authzid.
           (type=bool)
Overrides:
pyxmpp.sasl.core.PasswordManager.check_authzid

choose_realm(self, realm_list)

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 - realm list provided by the server.
           (type=list of unicode)
Returns:
the realm chosen.
           (type=unicode)
Overrides:
pyxmpp.sasl.core.PasswordManager.choose_realm

connect(self, server=None, port=None)

Establish a client connection to a server.

[client only]

Parameters:
server - name or address of the server to use. Not recommended -- proper value should be derived automatically from the JID.
           (type=unicode)
port - port number of the server to use. Not recommended -- proper value should be derived automatically from the JID.
           (type=int)
Overrides:
pyxmpp.streambase.StreamBase.connect

do_bind(self, stanza)

Do the resource binding requested by a client connected.

[server only]

Parameters:
stanza - resource binding request stanza.
           (type=pyxmpp.Iq)

fix_in_stanza(self, stanza)

Fix an incoming stanza.

Ona server replace the sender address with authorized client JID.

Overrides:
pyxmpp.stanzaprocessor.StanzaProcessor.fix_in_stanza

fix_out_stanza(self, stanza)

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:
pyxmpp.stanzaprocessor.StanzaProcessor.fix_out_stanza

get_password(self, username, realm=None, acceptable_formats=('plain',))

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

get_realms(self)

Get realms available for client authentication.

[server only]

Returns:
list of realms.
           (type=list of unicode)
Overrides:
pyxmpp.sasl.core.PasswordManager.get_realms

get_serv_host(self)

Get the service host name for SASL authentication.
Returns:
domain of the own JID.
Overrides:
pyxmpp.sasl.core.PasswordManager.get_serv_host

get_serv_name(self)

Get the service name for SASL authentication.
Returns:
domain of the own JID.
Overrides:
pyxmpp.sasl.core.PasswordManager.get_serv_name

get_serv_type(self)

Get the server name for SASL authentication.
Returns:
'xmpp'.
Overrides:
pyxmpp.sasl.core.PasswordManager.get_serv_type

Instance Variable Details

auth_methods

allowed authentication methods.
Type:
list of str

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

password

user's password.
Type:
str

port

port number to use.
Type:
int

server

server to use.
Type:
str