PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
XMPP::C2S::StreamHandler Class Reference

This class handles the client side of a C2S (Client to Server) XMPP stream. More...

#include <xmpp_c2s.h>

Inheritance diagram for XMPP::C2S::StreamHandler:
Collaboration diagram for XMPP::C2S::StreamHandler:

Public Member Functions

 StreamHandler (const JID &jid, const PString &pwd, PBoolean newAccount=false)
 
 ~StreamHandler ()
 
virtual PBoolean IsEstablished () const
 
virtual PBoolean Start (Transport *transport=0)
 
PBoolean Send (Stanza *stanza)
 
Request the delivery of the specified stanza

NOTE: the StreamHandler takes ownership of the stanza and will take care of deleting it. More...

 
void SetVersion (WORD major, WORD minor)
 
void GetVersion (WORD &major, WORD &minor) const
 
const JIDGetJID () const
 
PNotifierListSessionEstablishedHandlers ()
 
These notifier lists after when a client session is

established (i.e. More...

 
PNotifierListSessionReleasedHandlers ()
 
PNotifierListErrorHandlers ()
 
These notifier lists are fired when a XMPP stanza or a

stream error is received. More...

 
PNotifierListMessageHandlers ()
 
PNotifierListPresenceHandlers ()
 
PNotifierListIQHandlers ()
 
PNotifierListIQNamespaceHandlers (const PString &xml_namespace)
 A notifier list for a specific namespace. More...
 
PNotifierListMessageSenderHandlers (const JID &from)
 A notifier list for a particular message originator. More...
 
virtual PBoolean DiscoverItems (const PString &jid, const PNotifier &responseHandler, const PString &node=PString::Empty())
 JEP-0030 Service Discovery access methods. More...
 
virtual PBoolean DiscoverInfo (const PString &jid, const PNotifier &responseHandler, const PString &node=PString::Empty())
 
- Public Member Functions inherited from XMPP::BaseStreamHandler
 BaseStreamHandler ()
 
 ~BaseStreamHandler ()
 
virtual PBoolean Stop (const PString &error=PString::Empty())
 
void SetAutoReconnect (PBoolean b=true, long timeout=1000)
 
void AddNotifier (const PNotifierTemplate< PXMLElement & > &notifier)
 
StreamGetStream () const
 
virtual PBoolean Write (const void *buf, PINDEX len)
 
virtual PBoolean Write (const PString &data)
 
virtual PBoolean Write (const PXML &pdu)
 
virtual void Main ()
 User override function for the main execution routine of the thread. More...
 
- Public Member Functions inherited from PThread
bool IsAutoDelete () const
 
int PXBlockOnChildTerminate (int pid, const PTimeInterval &timeout)
 
int PXBlockOnIO (int handle, int type, const PTimeInterval &timeout)
 
void PXAbortBlock () const
 
void PrintOn (ostream &strm) const
 Standard stream print function. More...
 
 P_DECLARE_TRACED_ENUM (Priority, LowestPriority, LowPriority, NormalPriority, HighPriority, HighestPriority)
 Codes for thread priorities. More...
 
 PThread (PINDEX stack, AutoDeleteFlag deletion=AutoDeleteThread, Priority priorityLevel=NormalPriority, const PString &threadName=PString::Empty())
 Create a new thread instance. More...
 
 ~PThread ()
 Destroy the thread, this simply calls the Terminate() function with all its restrictions and penalties. More...
 
virtual void Restart ()
 Restart a terminated thread using the same stack priority etc that was current when the thread terminated. More...
 
virtual void Terminate ()
 Terminate the thread. More...
 
virtual PBoolean IsTerminated () const
 Determine if the thread has been terminated or ran to completion. More...
 
void WaitForTermination () const
 Block and wait for the thread to terminate. More...
 
PBoolean WaitForTermination (const PTimeInterval &maxWait) const
 Block and wait for the thread to terminate. More...
 
virtual void Suspend (PBoolean susp=true)
 Suspend or resume the thread. More...
 
virtual void Resume ()
 Resume thread execution, this is identical to Suspend(false). More...
 
virtual PBoolean IsSuspended () const
 Determine if the thread is currently suspended. More...
 
virtual void SetPriority (Priority priorityLevel)
 Set the priority of the thread relative to other threads in the current process. More...
 
virtual Priority GetPriority () const
 Get the current priority of the thread in the current process. More...
 
virtual void SetAutoDelete (AutoDeleteFlag deletion=AutoDeleteThread)
 Set the flag indicating thread object is to be automatically deleted when the thread ends. More...
 
void SetNoAutoDelete ()
 Reet the flag indicating thread object is to be automatically deleted when the thread ends. More...
 
virtual PString GetThreadName () const
 Get the name of the thread. More...
 
virtual void SetThreadName (const PString &name)
 Change the name of the thread. More...
 
 PPROFILE_EXCLUDE (PThreadIdentifier GetThreadId() const )
 
 PPROFILE_EXCLUDE (static PThreadIdentifier GetCurrentThreadId())
 
 PPROFILE_EXCLUDE (PUniqueThreadIdentifier GetUniqueIdentifier() const )
 
 PPROFILE_EXCLUDE (static PUniqueThreadIdentifier GetCurrentUniqueIdentifier())
 
 PPROFILE_EXCLUDE (static PINDEX GetTotalCount())
 
 PPROFILE_EXCLUDE (bool GetTimes(Times &times))
 
 PPROFILE_EXCLUDE (static bool GetTimes(PThreadIdentifier id, Times &times))
 
 PPROFILE_EXCLUDE (static void GetTimes(std::vector< Times > &times))
 
- Public Member Functions inherited from PObject
__inline unsigned GetTraceContextIdentifier () const
 Get PTRACE context identifier. More...
 
__inline void SetTraceContextIdentifier (unsigned id)
 
__inline void SetTraceContextIdentifier (const PObject &obj)
 
__inline void SetTraceContextIdentifier (const PObject *obj)
 
__inline void CopyTraceContextIdentifier (PObject &obj) const
 
__inline void CopyTraceContextIdentifier (PObject *obj) const
 
virtual ~PObject ()
 
__inline const char * GetClass () const
 
__inline bool IsClass (const char *name) const
 
__inline const PObjectPTraceObjectInstance () const
 
virtual PObjectClone () const
 Create a copy of the class on the heap. More...
 
template<class CLS >
CLS * CloneAs () const
 As for Clone() but converts to specified type. More...
 
virtual PINDEX HashFunction () const
 This function yields a hash value required by the PDictionary class. More...
 
virtual Comparison Compare (const PObject &obj) const
 Compare the two objects and return their relative rank. More...
 
virtual Comparison CompareObjectMemoryDirect (const PObject &obj) const
 Determine the byte wise comparison of two objects. More...
 
bool operator== (const PObject &obj) const
 Compare the two objects. More...
 
bool operator!= (const PObject &obj) const
 Compare the two objects. More...
 
bool operator< (const PObject &obj) const
 Compare the two objects. More...
 
bool operator> (const PObject &obj) const
 Compare the two objects. More...
 
bool operator<= (const PObject &obj) const
 Compare the two objects. More...
 
bool operator>= (const PObject &obj) const
 Compare the two objects. More...
 
virtual void ReadFrom (istream &strm)
 Input the contents of the object from the stream. More...
 

Protected Types

enum  StreamState {
  Null, RegStarted, TLSStarted, SASLStarted,
  NonSASLStarted, StreamSent, BindSent, SessionSent,
  Established
}
 
- Protected Types inherited from PThread
enum  Type { e_IsAutoDelete, e_IsManualDelete, e_IsProcess, e_IsExternal }
 

Protected Member Functions

virtual void OnOpen (Stream &stream, INT)
 
virtual void OnClose (Stream &stream, INT)
 
virtual void StartRegistration ()
 
virtual void StartAuthNegotiation ()
 
virtual void OnSessionEstablished ()
 
virtual void OnSessionReleased ()
 
virtual void OnElement (PXMLElement &pdu)
 
virtual void OnError (PXMLElement &pdu)
 
virtual void OnMessage (XMPP::Message &pdu)
 
virtual void OnPresence (XMPP::Presence &pdu)
 
virtual void OnIQ (XMPP::IQ &pdu)
 
virtual void HandleNullState (PXMLElement &pdu)
 
virtual void HandleRegStartedState (PXMLElement &pdu)
 
virtual void HandleTLSStartedState (PXMLElement &pdu)
 
virtual void HandleSASLStartedState (PXMLElement &pdu)
 
virtual void HandleNonSASLStartedState (PXMLElement &pdu)
 
virtual void HandleStreamSentState (PXMLElement &pdu)
 
virtual void HandleBindSentState (PXMLElement &pdu)
 
virtual void HandleSessionSentState (PXMLElement &pdu)
 
virtual void HandleEstablishedState (PXMLElement &pdu)
 
virtual PBoolean Discover (const PString &xmlns, const PString &jid, const PNotifier &responseHandler, const PString &node)
 
 PDECLARE_MUTEX (m_PendingIQsLock)
 
virtual void SetState (StreamState s)
 
- Protected Member Functions inherited from XMPP::BaseStreamHandler
 PDECLARE_NOTIFIER (Stream, BaseStreamHandler, OnOpen)
 
 PDECLARE_NOTIFIER (Stream, BaseStreamHandler, OnClose)
 
- Protected Member Functions inherited from PObject
 PObject ()
 Constructor for PObject, made protected so cannot ever create one on its own. More...
 

Protected Attributes

WORD m_VersionMajor
 
WORD m_VersionMinor
 
PString m_StreamID
 
PBoolean m_NewAccount
 
JID m_JID
 
const PString m_Password
 
PSASLClient m_SASL
 
PString m_Mechanism
 
PBoolean m_HasBind
 
PBoolean m_HasSession
 
PNotifierList m_SessionEstablishedHandlers
 
PNotifierList m_SessionReleasedHandlers
 
PNotifierList m_ErrorHandlers
 
PNotifierList m_MessageHandlers
 
PNotifierList m_PresenceHandlers
 
PNotifierList m_IQHandlers
 
PDictionary< PString,
PNotifierList
m_IQNamespaceHandlers
 
PDictionary< JID, PNotifierListm_MessageSenderHandlers
 
StanzaList m_PendingIQs
 
StreamState m_State
 
- Protected Attributes inherited from XMPP::BaseStreamHandler
Streamm_Stream
 
bool m_AutoReconnect
 
PTimeInterval m_ReconnectTimeout
 
PNotifierListTemplate
< PXMLElement & > 
m_ElementHandlers
 
- Protected Attributes inherited from PThread
enum PThread::Type m_type
 
PINDEX m_originalStackSize
 
PString m_threadName
 
PCriticalSection m_threadNameMutex
 
PThreadIdentifier m_threadId
 
PUniqueThreadIdentifier m_uniqueId
 
- Protected Attributes inherited from PObject
unsigned m_traceContextIdentifier
 

Additional Inherited Members

- Public Types inherited from PThread
enum  AutoDeleteFlag { AutoDeleteThread, NoAutoDeleteThread }
 Codes for thread autodelete flag. More...
 
- Public Types inherited from PObject
enum  Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 }
 Result of the comparison operation performed by the Compare() function. More...
 
- Static Public Member Functions inherited from PThread
static bool WaitAndDelete (PThread *&thread, const PTimeInterval &maxWait=10000, PMutex *mutex=NULL, bool lock=true)
 Wait for thread termination and delete object. More...
 
static void Sleep (const PTimeInterval &delay)
 Suspend the current thread for the specified amount of time. More...
 
static PString GetThreadName (PThreadIdentifier id)
 Get the name of the thread. More...
 
static PString GetCurrentThreadName ()
 Get the current threads name. More...
 
static PString GetIdentifiersAsString (PThreadIdentifier tid, PUniqueThreadIdentifier uid)
 Convert to thread identifers as a string. More...
 
static void GetTimes (std::list< Times > &times)
 
static void GetTimes (std::set< Times > &times)
 
static int GetPercentageCPU (Times &previousTimes, const PTimeInterval &period=PTimeInterval(0, 1), PThreadIdentifier id=PNullThreadIdentifier)
 Calculate the percentage CPU used over a period of time. More...
 
static unsigned GetNumProcessors ()
 Get number of processors, or processor cores, this machine has available. More...
 
static PThreadCurrent ()
 Get the currently running thread object instance. More...
 
static void Yield ()
 Yield to another thread without blocking. More...
 
static PThreadCreate (const PNotifier &notifier, INT parameter=0, AutoDeleteFlag deletion=AutoDeleteThread, Priority priorityLevel=NormalPriority, const PString &threadName=PString::Empty(), PINDEX stackSize=0)
 Create a simple thread executing the specified notifier. More...
 
static PThreadCreate (const PNotifier &notifier, const PString &threadName)
 
- Static Public Member Functions inherited from PObject
static __inline void CopyTraceContextIdentifier (PObject &to, const PObject &from)
 
static __inline void CopyTraceContextIdentifier (PObject &to, const PObject *from)
 
static __inline void CopyTraceContextIdentifier (PObject *to, const PObject &from)
 
static __inline void CopyTraceContextIdentifier (PObject *to, const PObject *from)
 
static __inline const char * Class ()
 
static __inline const PObjectPTraceObjectInstance (const char *)
 
static __inline const PObjectPTraceObjectInstance (const PObject *obj)
 
template<typename T >
static Comparison Compare2 (T v1, T v2)
 Compare two types, returning Comparison type. More...
 
static Comparison InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size)
 Internal function caled from CompareObjectMemoryDirect() More...
 

Detailed Description

This class handles the client side of a C2S (Client to Server) XMPP stream.

Member Enumeration Documentation

Enumerator
Null 
RegStarted 
TLSStarted 
SASLStarted 
NonSASLStarted 

non SASL authentication (JEP-0078)

StreamSent 
BindSent 
SessionSent 
Established 

Constructor & Destructor Documentation

XMPP::C2S::StreamHandler::StreamHandler ( const JID jid,
const PString pwd,
PBoolean  newAccount = false 
)
XMPP::C2S::StreamHandler::~StreamHandler ( )

Member Function Documentation

virtual PBoolean XMPP::C2S::StreamHandler::Discover ( const PString xmlns,
const PString jid,
const PNotifier responseHandler,
const PString node 
)
protectedvirtual
virtual PBoolean XMPP::C2S::StreamHandler::DiscoverInfo ( const PString jid,
const PNotifier responseHandler,
const PString node = PString::Empty() 
)
virtual
Parameters
jidJID to which a query will be send
responseHandlerHandler function for responses
nodeOptional node
virtual PBoolean XMPP::C2S::StreamHandler::DiscoverItems ( const PString jid,
const PNotifier responseHandler,
const PString node = PString::Empty() 
)
virtual

JEP-0030 Service Discovery access methods.

The response handler will receive a PIQ stanza (a smart pointer to a XMPP::IQ)

Parameters
jidJID to which a query will be send
responseHandlerHandler function for responses
nodeOptional node
PNotifierList& XMPP::C2S::StreamHandler::ErrorHandlers ( )
inline

These notifier lists are fired when a XMPP stanza or a

stream error is received.

For the notifier lists to be fired the stream must be already in the established state (i.e. after the bind and the session state). The parameter passed to the notifiers is a reference to the received pdu

References m_ErrorHandlers.

const JID& XMPP::C2S::StreamHandler::GetJID ( ) const
inline

References m_JID.

void XMPP::C2S::StreamHandler::GetVersion ( WORD &  major,
WORD &  minor 
) const
virtual void XMPP::C2S::StreamHandler::HandleBindSentState ( PXMLElement pdu)
protectedvirtual
virtual void XMPP::C2S::StreamHandler::HandleEstablishedState ( PXMLElement pdu)
protectedvirtual
virtual void XMPP::C2S::StreamHandler::HandleNonSASLStartedState ( PXMLElement pdu)
protectedvirtual
virtual void XMPP::C2S::StreamHandler::HandleNullState ( PXMLElement pdu)
protectedvirtual
virtual void XMPP::C2S::StreamHandler::HandleRegStartedState ( PXMLElement pdu)
protectedvirtual
virtual void XMPP::C2S::StreamHandler::HandleSASLStartedState ( PXMLElement pdu)
protectedvirtual
virtual void XMPP::C2S::StreamHandler::HandleSessionSentState ( PXMLElement pdu)
protectedvirtual
virtual void XMPP::C2S::StreamHandler::HandleStreamSentState ( PXMLElement pdu)
protectedvirtual
virtual void XMPP::C2S::StreamHandler::HandleTLSStartedState ( PXMLElement pdu)
protectedvirtual
PNotifierList& XMPP::C2S::StreamHandler::IQHandlers ( )
inline

References m_IQHandlers.

PNotifierList& XMPP::C2S::StreamHandler::IQNamespaceHandlers ( const PString xml_namespace)

A notifier list for a specific namespace.

The list will be fired only upon receiving an IQ with the child element of the specified namespace

virtual PBoolean XMPP::C2S::StreamHandler::IsEstablished ( ) const
inlinevirtual

References Established, and m_State.

PNotifierList& XMPP::C2S::StreamHandler::MessageHandlers ( )
inline

References m_MessageHandlers.

PNotifierList& XMPP::C2S::StreamHandler::MessageSenderHandlers ( const JID from)

A notifier list for a particular message originator.

The list will be fired only upon receiving a message from the specified jid. NOTE: if a matching notifier list is found and it's not emnpty, the generic MessageHandlers list IS NOT fired.

virtual void XMPP::C2S::StreamHandler::OnClose ( Stream stream,
INT   
)
protectedvirtual
virtual void XMPP::C2S::StreamHandler::OnElement ( PXMLElement pdu)
protectedvirtual

Reimplemented from XMPP::BaseStreamHandler.

virtual void XMPP::C2S::StreamHandler::OnError ( PXMLElement pdu)
protectedvirtual
virtual void XMPP::C2S::StreamHandler::OnIQ ( XMPP::IQ pdu)
protectedvirtual
virtual void XMPP::C2S::StreamHandler::OnMessage ( XMPP::Message pdu)
protectedvirtual
virtual void XMPP::C2S::StreamHandler::OnOpen ( Stream stream,
INT   
)
protectedvirtual
virtual void XMPP::C2S::StreamHandler::OnPresence ( XMPP::Presence pdu)
protectedvirtual
virtual void XMPP::C2S::StreamHandler::OnSessionEstablished ( )
protectedvirtual
virtual void XMPP::C2S::StreamHandler::OnSessionReleased ( )
protectedvirtual
XMPP::C2S::StreamHandler::PDECLARE_MUTEX ( m_PendingIQsLock  )
protected
PNotifierList& XMPP::C2S::StreamHandler::PresenceHandlers ( )
inline

References m_PresenceHandlers.

PBoolean XMPP::C2S::StreamHandler::Send ( Stanza stanza)

Request the delivery of the specified stanza

NOTE: the StreamHandler takes ownership of the stanza and will take care of deleting it.

BIG NOTE: use this method and not Write() if you want to get a notification when an answer to an iq arrives

PNotifierList& XMPP::C2S::StreamHandler::SessionEstablishedHandlers ( )
inline

These notifier lists after when a client session is

established (i.e.

after the handshake and authentication steps are completed) or is released. The parameter passed to the notifiers is a reference to the stream handler

References m_SessionEstablishedHandlers.

PNotifierList& XMPP::C2S::StreamHandler::SessionReleasedHandlers ( )
inline
virtual void XMPP::C2S::StreamHandler::SetState ( StreamState  s)
protectedvirtual
void XMPP::C2S::StreamHandler::SetVersion ( WORD  major,
WORD  minor 
)
virtual PBoolean XMPP::C2S::StreamHandler::Start ( Transport transport = 0)
virtual

Reimplemented from XMPP::BaseStreamHandler.

virtual void XMPP::C2S::StreamHandler::StartAuthNegotiation ( )
protectedvirtual
virtual void XMPP::C2S::StreamHandler::StartRegistration ( )
protectedvirtual

Member Data Documentation

PNotifierList XMPP::C2S::StreamHandler::m_ErrorHandlers
protected

Referenced by ErrorHandlers().

PBoolean XMPP::C2S::StreamHandler::m_HasBind
protected
PBoolean XMPP::C2S::StreamHandler::m_HasSession
protected
PNotifierList XMPP::C2S::StreamHandler::m_IQHandlers
protected

Referenced by IQHandlers().

PDictionary<PString, PNotifierList> XMPP::C2S::StreamHandler::m_IQNamespaceHandlers
protected
JID XMPP::C2S::StreamHandler::m_JID
protected

Referenced by GetJID().

PString XMPP::C2S::StreamHandler::m_Mechanism
protected
PNotifierList XMPP::C2S::StreamHandler::m_MessageHandlers
protected

Referenced by MessageHandlers().

PDictionary<JID, PNotifierList> XMPP::C2S::StreamHandler::m_MessageSenderHandlers
protected
PBoolean XMPP::C2S::StreamHandler::m_NewAccount
protected
const PString XMPP::C2S::StreamHandler::m_Password
protected
StanzaList XMPP::C2S::StreamHandler::m_PendingIQs
protected
PNotifierList XMPP::C2S::StreamHandler::m_PresenceHandlers
protected

Referenced by PresenceHandlers().

PSASLClient XMPP::C2S::StreamHandler::m_SASL
protected
PNotifierList XMPP::C2S::StreamHandler::m_SessionEstablishedHandlers
protected
PNotifierList XMPP::C2S::StreamHandler::m_SessionReleasedHandlers
protected

Referenced by SessionReleasedHandlers().

StreamState XMPP::C2S::StreamHandler::m_State
protected

Referenced by IsEstablished().

PString XMPP::C2S::StreamHandler::m_StreamID
protected
WORD XMPP::C2S::StreamHandler::m_VersionMajor
protected
WORD XMPP::C2S::StreamHandler::m_VersionMinor
protected

The documentation for this class was generated from the following file: