Package xmpp :: Module session :: Class Session
[show private | hide private]
[frames | no frames]

Class Session


The Session class instance is used for storing all session-related info like credentials, socket/xml stream/session state flags, roster items (in case of client type connection) etc. Session object have no means of discovering is any info is ready to be read. Instead you should use poll() (recomended) or select() methods for this purpose. Session can be one of two types: 'server' and 'client'. 'server' session handles inbound connection and 'client' one used to create an outbound one. Session instance have multitude of internal attributes. The most imporant is the 'peer' one. It is set once the peer is authenticated (client).
Method Summary
  __init__(self, socket, owner, xmlns, peer)
When the session is created it's type (client/server) is determined from the beginning.
  enqueue(self, stanza)
Takes Protocol instance as argument.
  feature(self, feature)
Declare some stream feature as activated one.
  flush_queue(self)
Put the "immidiatedly send" queue content on the wire.
  push_queue(self, failreason)
If stream is authenticated than move items from "send" queue to "immidiatedly send" queue.
  receive(self)
Reads all pending incoming data.
  sendnow(self, chunk)
Put chunk into "immidiatedly send" queue.
  set_session_state(self, newstate)
Change the session state.
  set_socket_state(self, newstate)
Change the underlaying socket state.
  set_stream_state(self, newstate)
Change the underlaying XML stream state Stream starts with STREAM__NOT_OPENED and then proceeds with STREAM__OPENED, STREAM__CLOSING and STREAM__CLOSED states.
  start_feature(self, f)
Declare some feature as "negotiating now" to prevent other features from start negotiating.
  StartStream(self)
This method is used to initialise the internal xml expat parser and to send initial stream header (in case of client connection).
  stop_feature(self, f)
Declare some feature as "negotiated" to allow other features start negotiating.
  terminate_stream(self, error, unregister)
Notify the peer about stream closure.
  unfeature(self, feature)
Declare some feature as illegal.

Method Details

__init__(self, socket, owner, xmlns=None, peer=None)
(Constructor)

When the session is created it's type (client/server) is determined from the beginning. socket argument is the pre-created socket-like object. It must have the following methods: send, recv, fileno, close. owner is the 'master' instance that have Dispatcher plugged into it and generally will take care about all session events. xmlns is the stream namespace that will be used. Client must set this argument If server sets this argument than stream will be dropped if opened with some another namespace. peer is the name of peer instance. This is the flag that differentiates client session from server session. Client must set it to the name of the server that will be connected, server must leave this argument alone.

enqueue(self, stanza)

Takes Protocol instance as argument. Puts stanza into "send" fifo queue. Items into the send queue are hold until stream authenticated. After that this method is effectively the same as "sendnow" method.

feature(self, feature)

Declare some stream feature as activated one.

flush_queue(self)

Put the "immidiatedly send" queue content on the wire. Blocks until at least one byte sent.

push_queue(self, failreason='urn:ietf:params:xml:ns:xmpp-stanzas recipient-unavailable')

If stream is authenticated than move items from "send" queue to "immidiatedly send" queue. Else if the stream is failed then return all queued stanzas with error passed as argument. Otherwise do nothing.

receive(self)

Reads all pending incoming data. Raises IOError on disconnection. Blocks until at least one byte is read.

sendnow(self, chunk)

Put chunk into "immidiatedly send" queue. Should only be used for auth/TLS stuff and like. If you just want to shedule regular stanza for delivery use enqueue method.

set_session_state(self, newstate)

Change the session state. Session starts with SESSION_NOT_AUTHED state and then comes through SESSION_AUTHED, SESSION_BOUND, SESSION_OPENED and SESSION_CLOSED states.

set_socket_state(self, newstate)

Change the underlaying socket state. Socket starts with SOCKET_UNCONNECTED state and then proceeds (possibly) to SOCKET_ALIVE and then to SOCKET_DEAD

set_stream_state(self, newstate)

Change the underlaying XML stream state Stream starts with STREAM__NOT_OPENED and then proceeds with STREAM__OPENED, STREAM__CLOSING and STREAM__CLOSED states. Note that some features (like TLS and SASL) requires stream re-start so this state can have non-linear changes.

start_feature(self, f)

Declare some feature as "negotiating now" to prevent other features from start negotiating.

StartStream(self)

This method is used to initialise the internal xml expat parser and to send initial stream header (in case of client connection). Should be used after initial connection and after every stream restart.

stop_feature(self, f)

Declare some feature as "negotiated" to allow other features start negotiating.

terminate_stream(self, error=None, unregister=1)

Notify the peer about stream closure. Ensure that xmlstream is not brokes - i.e. if the stream isn't opened yet - open it before closure. If the error condition is specified than create a stream error and send it along with closing stream tag. Emulate receiving 'unavailable' type presence just before stream closure.

unfeature(self, feature)

Declare some feature as illegal. Illegal features can not be used. Example: BIND feature becomes illegal after Non-SASL auth.

Generated by Epydoc 2.1 on Thu Oct 5 23:57:40 2006 http://epydoc.sf.net