class JBStream

A Jabber stream. More...

Full nameTelEngine::JBStream
Definition#include <libs/yjingle/yatejabber.h>
InheritsTelEngine::RefObject [public ]
Inherited byJBClientStream, JBComponentStream
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Types

Public Methods

Public Static Methods

Public Members

Protected Types

Protected Methods

Protected Members


Detailed Description

Base class for all Jabber streams. Basic stream data processing: send/receive XML elements, keep stream state, generate events

enum State { Idle = 0, Connecting = 1, Started = 2, Securing = 3, Register = 4, Auth = 5, Running = 6, Destroy = 7, }

State

Stream state enumeration.

enum Error { ErrorNone = 0, ErrorContext, ErrorPending, ErrorNoSocket, }

Error

Values returned by send() methods.

enum Flags { AutoRestart = 0x0001, AllowPlainAuth = 0x0002, NoVersion1 = 0x0004, UseTls = 0x0008, UseSasl = 0x0010, AllowUnsafeSetup = 0x0020, StreamSecured = 0x0100, StreamAuthenticated = 0x0200, NoRemoteVersion1 = 0x0400, }

Flags

Stream behaviour options

 ~JBStream ()

~JBStream

[virtual]

Destructor. Gracefully close the stream and the socket

inline int  type ()

type

[const]

Get the type of this stream. See the protocol enumeration of the engine

Returns: The type of this stream

inline State  state ()

state

[const]

Get the stream state

Returns: The stream state as enumeration.

inline bool  outgoing ()

outgoing

[const]

Get the stream direction

Returns: True if the stream is an outgoing one

inline const String&  name ()

name

[const]

Get the stream's name

Returns: The stream's name

inline const String&  id ()

id

[const]

Get the stream id

Returns: The stream id

inline JBEngine*  engine ()

engine

[const]

Get the stream's owner

Returns: Pointer to the engine owning this stream

inline const JabberID&  local ()

local

[const]

Get the JID of the local side of this stream

Returns: The JID of the local side of this stream

inline const JabberID&  remote ()

remote

[const]

Get the JID of the remote side of this stream

Returns: The JID of the remote side of this stream

inline const SocketAddr&  addr ()

addr

[const]

Get the remote peer's address

Returns: The remote peer's address

inline bool  flag (int mask)

flag

[const]

Check if a given option (or option mask) is set

Parameters:
maskThe flag(s) to check

Returns: True if set

inline Mutex*  streamMutex ()

streamMutex

Get the stream mutex

Returns: The stream mutex

void  connect ()

connect

Connect the stream. Send stream start tag on success This method is thread safe

bool  receive ()

receive

Read data from socket and pass it to the parser. Terminate stream on socket or parser error. This method is thread safe

Returns: True if data was received

Error  sendStanza (XMLElement* stanza, const char* senderId = 0)

sendStanza

[virtual]

Send a stanza. This method is thread safe

Parameters:
stanzaElement to send
senderIdOptional sender's id. Used for notification events

Returns: The result of posting the stanza

JBEvent*  getEvent (u_int64_t time)

getEvent

Stream state and data processor. Increase restart counter. Restart stream if idle and auto restart. Extract an element from parser and construct an event. This method is thread safe

Parameters:
timeCurrent time

Returns: JBEvent pointer or 0

void  terminate (bool destroy, XMLElement* recvStanza, XMPPError::Type error, const char* reason, bool send, bool final = false, bool sendError = true)

terminate

Terminate stream. Send stream end tag or error. Remove pending stanzas without id. Deref stream if destroying. This method is thread safe

Parameters:
destroyTrue to destroy. False to terminate
recvStanzaReceived stanza, if any
errorTermination reason. Set it to NoError to send stream end tag
reasonOptional text to be added to the error stanza
sendTrue to send the stream end element
finalTrue if called from destructor
sendErrorTrue to send the error element (ignored if error is NoError)

inline void  removePending (const String& id, bool notify = false)

removePending

Remove pending stanzas with a given id. This method is thread safe

Parameters:
idThe id of stanzas to remove
notifyTrue to raise an event for each removed stanza

const String&  toString ()

toString

[const virtual]

Get the string representation of this stream

Returns: The string representation of this stream

Reimplemented from GenObject.

void*  getObject (const String& name)

getObject

[const virtual]

Get an object from this stream

Parameters:
nameThe name of the object to get

Reimplemented from GenObject.

const char*  lookupState (int state)

lookupState

[static]

Get the name of a stream state

Parameters:
stateThe requested state number

Returns: The name of the requested state

static TokenDict s_flagName[]

s_flagName[]

enum WaitState { WaitIdle, WaitStart, WaitFeatures, WaitBindRsp, WaitSessionRsp, WaitTlsRsp, WaitChallenge, WaitResponse, WaitAborted, }

WaitState

[protected]

Internal wait states enumeration. Defines what kind of XML is expected

 JBStream (JBEngine* engine, int type, XMPPServerInfo& info, const JabberID& localJid, const JabberID& remoteJid)

JBStream

[protected]

Constructor. Build an outgoing stream

Parameters:
engineThe engine that owns this stream
typeStream type
infoStructure containing data used to connect to remote server
localJidLocal party's JID
remoteJidRemote party's JID

inline  JBStream ()

JBStream

[protected]

Default constructor

void  destroyed ()

destroyed

[protected virtual]

Close the stream. Release memory

Reimplemented from RefObject.

bool  checkDestination (XMLElement* xml, bool& respond)

checkDestination

[protected virtual]

Check the 'to' attribute of a received element

Parameters:
xmlThe received element
respondAction to be taken when if not accepted. True to respond with an error, false to just drop it

Returns: False to reject it. If the stream is not in Running state, it will be terminated

XMLElement*  getStreamStart ()

getStreamStart

[protected virtual]

Get the starting stream element to be sent after stream connected

Returns: XMLElement pointer

XMLElement*  getAuthStart ()

getAuthStart

[protected virtual]

Get the authentication element to be sent when authentication starts

Returns: XMLElement pointer or 0 on failure

void  processRunning (XMLElement* xml)

processRunning

[protected virtual]

Process a received stanza in Running state

Parameters:
xmlValid XMLElement pointer

void  processRegister (XMLElement* xml)

processRegister

[protected virtual]

Process a received element in Register state. Descendants MUST consume the data

Parameters:
xmlValid XMLElement pointer

void  processAuth (XMLElement* xml)

processAuth

[protected virtual]

Process a received element in Auth state. Descendants MUST consume the data

Parameters:
xmlValid XMLElement pointer

void  processSecuring (XMLElement* xml)

processSecuring

[protected virtual]

Process a received element in Securing state. Descendants MUST consume the data. Drop the received element

Parameters:
xmlValid XMLElement pointer

void  processStarted (XMLElement* xml)

processStarted

[protected virtual]

Process a received element in Started state. Descendants MUST consume the data

Parameters:
xmlValid XMLElement pointer

void  streamRunning ()

streamRunning

[protected virtual]

Notify descendants when stream state changed to Running

JBEvent*  getIqEvent (XMLElement* xml, int iqType, XMPPError::Type& error)

getIqEvent

[protected]

Create an iq event from a received iq stanza

Parameters:
xmlReceived element
iqTypeThe iq type
errorError type if 0 is returned

Returns: JBEvent pointer or 0

bool  sendStreamStart ()

sendStreamStart

[protected]

Send declaration and stream start

Returns: True on success

bool  sendStreamXML (XMLElement* e, State newState)

sendStreamXML

[protected]

Send stream XML elements through the socket

Parameters:
eThe element to send
newStateThe new stream state on success

Returns: False if send failed (stream termination was initiated)

void  invalidStreamXML (XMLElement* xml, XMPPError::Type error, const char* reason)

invalidStreamXML

[protected]

Terminate stream on receiving invalid elements

Parameters:
xmlReceived element
errorTermination reason
reasonOptional text to be added to the error stanza

void  errorStreamXML (XMLElement* xml)

errorStreamXML

[protected]

Terminate stream on receiving stanza errors while not running

Parameters:
xmlReceived element

void  dropXML (XMLElement* xml, bool unexpected = true)

dropXML

[protected]

Drop an unexpected or unhandled element

Parameters:
xmlReceived element
unexpectedTrue if unexpected

void  changeState (State newState)

changeState

[protected]

Change stream's state. Raise a Running event when apropriate

Parameters:
newStatethe new stream state

bool  getStreamFeatures (XMLElement* features)

getStreamFeatures

[protected]

Clear the remote feature list. Parse the received element to fill it up. Terminate the stream on error (such as invalid namespace). If false is returned, don't re-use the received element

Parameters:
featuresFeatures element to parse

Returns: False if the stream is terminated

bool  startTls ()

startTls

[protected]

Start client TLS. Terminate the stream on error

Returns: True if TLS was initiated. False on failure: stream termination was initiated

bool  startRegister ()

startRegister

[protected]

Start client registration Terminate the stream on error

Returns: False if the stream is terminated

bool  startAuth ()

startAuth

[protected]

Start client authentication. Send first request to authenticate with the server. Terminate the stream on error

Returns: False if the stream is terminated

bool  sendAuthResponse (XMLElement* challenge = 0)

sendAuthResponse

[protected]

Send authentication response. Terminate the stream on error

Parameters:
challengeReceived challenge. If non 0 a SASL response is built and sent. If 0, a non-SASL response is sent (using handshaking for component and XEP-0078 for client streams)

Returns: False if the stream is terminated

void  buildSaslResponse (String& response, String* realm = 0, String* nonce = 0)

buildSaslResponse

[protected]

Build SASL authentication response (Plain or Digest MD5 SASL). A valid mechanism must be previously set

Parameters:
responseDestination string
realmReceived realm or 0 to use local jid. If 0, nonce param is ignored
nonceServer nonce if available

void  setClientAuthMechanism ()

setClientAuthMechanism

[protected]

Parse remote's features and pick an authentication mechanism to be used when requesting authentication

void  buildDigestMD5Sasl (String& dest, bool authenticate = true)

buildDigestMD5Sasl

[protected]

Build a Digest MD5 SASL (RFC 2831) to be sent with authentication responses

Parameters:
destDestination string
authenticateTrue if building a Digest MD5 challenge response, false if building a Digest MD5 to check a 'success' response

void  setRecvCount (int value)

setRecvCount

[protected]

Safely set receive count

Parameters:
valueThe new value of the receive count

bool  startIdleTimer (u_int64_t time = Time::msecNow())

startIdleTimer

[protected]

Start the idle timer if there are no pending stanzas

Parameters:
timeThe current time in miliseconds

Returns: True if started

inline JBEvent*  lastEvent ()

lastEvent

[protected]

Get last event from queue

Returns: JBEvent pointer or 0

String m_name

m_name

[protected]

String m_password

m_password

[protected]

JIDFeatureList m_localFeatures

m_localFeatures

[protected]

JIDFeatureList m_remoteFeatures

m_remoteFeatures

[protected]

int m_flags

m_flags

[protected]

unsigned int m_challengeCount

m_challengeCount

[protected]

WaitState m_waitState

m_waitState

[protected]

JIDFeatureSasl::Mechanism m_authMech

m_authMech

[protected]

ObjList m_events

m_events

[protected]

bool m_register

m_register

[protected]


Generated by: paulc on bussard on Wed Oct 21 01:57:30 2009, using kdoc 2.0a54.