Yate
JBClientStream Class Reference

A client to server stream. More...

#include <yatejabber.h>

Inheritance diagram for JBClientStream:
JBStream RefObject DebugEnabler Mutex GenObject Lockable

Public Member Functions

 JBClientStream (JBEngine *engine, Socket *socket, bool ssl=false)
 
 JBClientStream (JBEngine *engine, const JabberID &jid, const String &account, const NamedList &params, const char *name=0, const char *serverHost=0)
 
const Stringaccount () const
 
GenObjectuserData ()
 
void userData (GenObject *data)
 
virtual JBClientStreamclientStream ()
 
virtual XmlElementbuildPing (const String &stanzaId)
 
void bind (const String &resource, const char *id, XMPPError::Type error=XMPPError::NoError)
 
bool requestRegister (bool data, bool set=true, const String &newPass=String::empty())
 
- Public Member Functions inherited from JBStream
virtual ~JBStream ()
 
int type () const
 
int xmlns () const
 
State state () const
 
bool incoming () const
 
bool outgoing () const
 
JBEngineengine () const
 
const char * name () const
 
const Stringid () const
 
bool isId (const String &str)
 
const JabberIDlocal () const
 
void local (JabberID &jid)
 
void setLocal (const char *jid)
 
const JabberIDremote () const
 
void remote (JabberID &jid)
 
bool remoteAddr (SocketAddr &addr)
 
bool localAddr (SocketAddr &addr)
 
int flags () const
 
bool flag (int mask) const
 
void setTlsRequired (bool set)
 
bool haveData ()
 
void connectAddr (String &addr, int &port, String &localip, int &stat, ObjList &srvs, bool *isRedirect=0) const
 
const StringserverHost () const
 
void setRosterRequested (bool ok)
 
bool setAvailableResource (bool ok, bool positive=true)
 
bool readSocket (char *buf, unsigned int len)
 
virtual JBServerStreamserverStream ()
 
virtual JBClusterStreamclusterStream ()
 
JBEventgetEvent (u_int64_t time=Time::msecNow())
 
bool sendStanza (XmlElement *&xml)
 
bool sendStreamXml (State newState, XmlElement *first, XmlElement *second=0, XmlElement *third=0)
 
void start (XMPPFeatureList *features=0, XmlElement *caps=0, bool useVer1=true)
 
bool authenticated (bool ok, const String &rsp=String::empty(), XMPPError::Type error=XMPPError::NotAuthorized, const char *username=0, const char *id=0, const char *resource=0)
 
void terminate (int location, bool destroy, XmlElement *xml, int error=XMPPError::NoError, const char *reason="", bool final=false, bool genEvent=true, const char *content=0)
 
virtual void connectTerminated (Socket *&sock)
 
virtual bool connecting (bool sync, int stat, ObjList &srvs)
 
virtual void * getObject (const String &name) const
 
const char * stateName () const
 
const char * typeName () const
 
void buildSha1Digest (String &buf, const String &secret)
 
virtual const StringtoString () const
 
- Public Member Functions inherited from RefObject
 RefObject ()
 
virtual ~RefObject ()
 
virtual bool alive () const
 
bool ref ()
 
bool deref ()
 
int refcount () const
 
virtual void destruct ()
 
- Public Member Functions inherited from GenObject
 GenObject ()
 
virtual ~GenObject ()
 
virtual const StringtraceId () const
 
NamedCountergetObjCounter () const
 
NamedCountersetObjCounter (NamedCounter *counter)
 
- Public Member Functions inherited from DebugEnabler
 DebugEnabler (int level=TelEngine::debugLevel(), bool enabled=true)
 
int debugLevel () const
 
int debugLevel (int level)
 
bool debugEnabled () const
 
void debugEnabled (bool enable)
 
const char * debugName () const
 
bool debugAt (int level) const
 
bool debugChained () const
 
void debugChain (const DebugEnabler *chain=0)
 
void debugCopy (const DebugEnabler *original=0)
 
- Public Member Functions inherited from Mutex
 Mutex (bool recursive=false, const char *name=0)
 
 Mutex (const Mutex &original)
 
 ~Mutex ()
 
Mutexoperator= (const Mutex &original)
 
virtual bool lock (long maxwait=-1)
 
virtual bool unlock ()
 
virtual bool locked () const
 
const char * owner () const
 
bool recursive () const
 
- Public Member Functions inherited from Lockable
virtual ~Lockable ()
 
virtual bool check (long maxwait=-1)
 
virtual bool unlockAll ()
 

Protected Member Functions

virtual bool processRunning (XmlElement *xml, const JabberID &from, const JabberID &to)
 
virtual bool processStart (const XmlElement *xml, const JabberID &from, const JabberID &to)
 
virtual bool processAuth (XmlElement *xml, const JabberID &from, const JabberID &to)
 
virtual bool processRegister (XmlElement *xml, const JabberID &from, const JabberID &to)
 
virtual void destroyed ()
 
bool startAuth ()
 
bool bind ()
 
- Protected Member Functions inherited from JBStream
 JBStream (JBEngine *engine, Socket *socket, Type t, bool ssl=false)
 
 JBStream (JBEngine *engine, Type t, const JabberID &local, const JabberID &remote, const char *name=0, const NamedList *params=0, const char *serverHost=0)
 
virtual bool canProcess (u_int64_t time)
 
virtual void process (u_int64_t time)
 
virtual void checkTimeouts (u_int64_t time)
 
virtual void resetConnection (Socket *sock=0)
 
virtual XmlElementbuildStreamStart ()
 
virtual bool processCompressing (XmlElement *xml, const JabberID &from, const JabberID &to)
 
bool processStreamStart (const XmlElement *xml)
 
bool handleCompressReq (XmlElement *xml)
 
bool streamError (XmlElement *xml)
 
bool getJids (XmlElement *xml, JabberID &from, JabberID &to)
 
bool checkStanzaRecv (XmlElement *xml, JabberID &from, JabberID &to)
 
void changeState (State newState, u_int64_t time=Time::msecNow())
 
XmlElementcheckCompress ()
 
void checkPendingEvent ()
 
bool sendPending (bool streamOnly=false)
 
bool writeSocket (const void *data, unsigned int &len)
 
void updateFromRemoteDef ()
 
XMPPFeaturefirstRequiredFeature ()
 
bool dropXml (XmlElement *&xml, const char *reason)
 
bool destroyDropXml (XmlElement *&xml, XMPPError::Type error, const char *reason)
 
void setFlags (int mask)
 
void resetFlags (int mask)
 
void setSecured ()
 
void setIdleTimer (u_int64_t msecNow=Time::msecNow())
 
void resetPing ()
 
XmlElementsetNextPing (bool force)
 
void generateIdIndex (String &buf, const char *extra=0)
 
- Protected Member Functions inherited from RefObject
virtual void zeroRefs ()
 
bool resurrect ()
 
- Protected Member Functions inherited from DebugEnabler
void debugName (const char *name)
 

Friends

class JBStream
 

Additional Inherited Members

- Public Types inherited from JBStream
enum  Type {
  c2s = 0 , s2s , comp , cluster ,
  TypeCount
}
 
enum  State {
  Idle = 0 , Connecting , WaitStart , Starting ,
  Features , WaitTlsRsp , Securing , Auth ,
  Challenge , Compressing , Register , Running ,
  Destroy
}
 
enum  Flags {
  NoAutoRestart = 0x00000001 , TlsRequired = 0x00000002 , AllowPlainAuth = 0x00000004 , DialbackOnly = 0x00000008 ,
  RegisterUser = 0x00000010 , Compress = 0x00000020 , InError = 0x00000080 , RosterRequested = 0x00000100 ,
  AvailableResource = 0x00000200 , PositivePriority = 0x00000400 , SetCompressed = 0x00010000 , StreamSecured = 0x00020000 ,
  StreamTls = 0x00040000 , StreamAuthenticated = 0x00080000 , StreamRemoteVer1 = 0x00100000 , StreamLocalVer1 = 0x00200000 ,
  StreamWaitBindRsp = 0x01000000 , StreamWaitSessRsp = 0x02000000 , StreamWaitChallenge = 0x04000000 , StreamWaitChgRsp = 0x08000000 ,
  StreamRfc3920Chg = 0x10000000 , StreamCompressed = 0x20000000 , StreamCanCompress = 0x40000000 , StreamFlags = 0x000000ff ,
  InternalFlags = 0xffff0000
}
 
- Static Public Member Functions inherited from JBStream
static Type lookupType (const char *text, Type defVal=TypeCount)
 
- Static Public Member Functions inherited from RefObject
static bool alive (const RefObject *obj)
 
static bool efficientIncDec ()
 
- Static Public Member Functions inherited from GenObject
static void * getObject (const String &name, const GenObject *obj)
 
static bool getObjCounting ()
 
static void setObjCounting (bool enable)
 
static NamedCountergetObjCounter (const String &name, bool create=true)
 
static ObjListgetObjCounters ()
 
- Static Public Member Functions inherited from Mutex
static int count ()
 
static int locks ()
 
static bool efficientTimedLock ()
 
- Static Public Member Functions inherited from Lockable
static void wait (unsigned long maxwait)
 
static unsigned long wait ()
 
static void startUsingNow ()
 
static void enableSafety (bool safe=true)
 
static bool safety ()
 
- Public Attributes inherited from JBStream
SASLm_sasl
 
- Static Public Attributes inherited from JBStream
static const TokenDict s_stateName []
 
static const TokenDict s_flagName []
 
static const TokenDict s_typeName []
 
- Protected Attributes inherited from JBStream
State m_state
 
String m_id
 
JabberID m_local
 
JabberID m_remote
 
String m_serverHost
 
int m_flags
 
XMPPNamespace::Type m_xmlns
 
XMPPFeatureList m_features
 
JBEventm_lastEvent
 
ObjList m_events
 
ObjList m_pending
 
unsigned int m_stanzaIndex
 
u_int64_t m_setupTimeout
 
u_int64_t m_startTimeout
 
u_int64_t m_pingTimeout
 
u_int64_t m_pingInterval
 
u_int64_t m_nextPing
 
u_int64_t m_idleTimeout
 
u_int64_t m_connectTimeout
 
unsigned int m_restart
 
u_int64_t m_timeToFillRestart
 
String m_pingId
 

Detailed Description

A client to server stream.

This class holds a client to server stream

Constructor & Destructor Documentation

◆ JBClientStream() [1/2]

JBClientStream ( JBEngine * engine,
Socket * socket,
bool ssl = false )

Constructor. Build an incoming stream from a socket

Parameters
engineEngine owning this stream
socketThe socket
sslTrue if the socket is already using SSL/TLS

References JBStream::engine().

Referenced by clientStream().

◆ JBClientStream() [2/2]

JBClientStream ( JBEngine * engine,
const JabberID & jid,
const String & account,
const NamedList & params,
const char * name = 0,
const char * serverHost = 0 )

Constructor. Build an outgoing stream

Parameters
engineEngine owning this stream
jidUser jid
accountAccount (stream) name
paramsStream parameters
nameOptional stream name
serverHostOptional server host to use instead of jid domain

References account(), JBStream::engine(), JBStream::name(), and JBStream::serverHost().

Member Function Documentation

◆ account()

const String & account ( ) const
inline

Retrieve stream's account

Returns
Stream account

Referenced by JBClientStream().

◆ bind() [1/2]

bool bind ( )
protected

Start resource binding on outgoing stream

Returns
True on success

◆ bind() [2/2]

void bind ( const String & resource,
const char * id,
XMPPError::Type error = XMPPError::NoError )

Bind a resource to an incoming stream. This method should be called after processing a Bind event This method is thread safe

Parameters
resourceResource to bind. Empty on error
idReceived bind request id
errorFailure reason. Ignored on success

◆ buildPing()

virtual XmlElement * buildPing ( const String & stanzaId)
virtual

Build a ping iq stanza

Parameters
stanzaIdStanza id
Returns
Valid XmlElement pointer

Reimplemented from JBStream.

◆ clientStream()

virtual JBClientStream * clientStream ( )
inlinevirtual

Get a client stream from this one

Returns
JBClientStream pointer

Reimplemented from JBStream.

References JBClientStream().

◆ destroyed()

virtual void destroyed ( )
protectedvirtual

Release memory

Reimplemented from JBStream.

◆ processAuth()

virtual bool processAuth ( XmlElement * xml,
const JabberID & from,
const JabberID & to )
protectedvirtual

Process elements in Auth state

Parameters
xmlReceived element (will be consumed)
fromAlready parsed source JID
toAlready parsed destination JID
Returns
False if stream termination was initiated

Reimplemented from JBStream.

◆ processRegister()

virtual bool processRegister ( XmlElement * xml,
const JabberID & from,
const JabberID & to )
protectedvirtual

Process elements in Register state

Parameters
xmlReceived element (will be consumed)
fromAlready parsed source JID
toAlready parsed destination JID
Returns
False if stream termination was initiated

Reimplemented from JBStream.

◆ processRunning()

virtual bool processRunning ( XmlElement * xml,
const JabberID & from,
const JabberID & to )
protectedvirtual

Process elements in Running state

Parameters
xmlReceived element (will be consumed)
fromAlready parsed source JID
toAlready parsed destination JID
Returns
False if stream termination was initiated

Reimplemented from JBStream.

◆ processStart()

virtual bool processStart ( const XmlElement * xml,
const JabberID & from,
const JabberID & to )
protectedvirtual

Process stream start elements while waiting for them

Parameters
xmlReceived xml element
fromThe 'from' attribute
toThe 'to' attribute
Returns
False if stream termination was initiated

Reimplemented from JBStream.

◆ requestRegister()

bool requestRegister ( bool data,
bool set = true,
const String & newPass = String::empty() )

Request account register or change on outgoing stream. This method is thread safe

Parameters
dataTrue to request registration/change, false to request info
setTrue to request new user registration, false to remove account from server
newPassNew password when requesting account setup on an already authenticated stream
Returns
True on success

References String::empty().

◆ startAuth()

bool startAuth ( )
protected

Start outgoing stream authentication

Returns
True on success

◆ userData() [1/2]

GenObject * userData ( )
inline

Retrieve stream's user data

Returns
GenObject pointer or 0

References GenObject::GenObject().

◆ userData() [2/2]

void userData ( GenObject * data)
inline

Set stream's user data. Transfer data ownership to the stream This method is thread safe

Parameters
dataData to set

References GenObject::GenObject(), and Mutex::lock().


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