Yate
JBServerStream Class Reference

A server to server stream. More...

#include <yatejabber.h>

Inheritance diagram for JBServerStream:
JBStream RefObject DebugEnabler Mutex GenObject Lockable

Public Member Functions

 JBServerStream (JBEngine *engine, Socket *socket, bool component=false)
 
 JBServerStream (JBEngine *engine, const JabberID &local, const JabberID &remote, const char *dbId=0, const char *dbKey=0, bool dbOnly=false, const NamedList *params=0)
 
 JBServerStream (JBEngine *engine, const JabberID &local, const JabberID &remote, const String *name=0, const NamedList *params=0)
 
bool dialback () const
 
const NamedListremoteDomains () const
 
bool hasRemoteDomain (const String &domain, bool auth=true)
 
NamedStringtakeDb ()
 
virtual JBServerStreamserverStream ()
 
bool sendDbVerify (const char *from, const char *to, const char *id, XMPPError::Type rsp=XMPPError::NoError)
 
bool sendDbResult (const JabberID &from, const JabberID &to, XMPPError::Type rsp=XMPPError::NoError)
 
bool sendDialback ()
 
bool startComp (const String &local=String::empty(), const String &remote=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 JBClientStreamclientStream ()
 
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 void destroyed ()
 
virtual bool processRunning (XmlElement *xml, const JabberID &from, const JabberID &to)
 
virtual XmlElementbuildStreamStart ()
 
virtual bool processStart (const XmlElement *xml, const JabberID &from, const JabberID &to)
 
virtual bool processAuth (XmlElement *xml, const JabberID &from, const JabberID &to)
 
bool processDbResult (XmlElement *xml, const JabberID &from, const JabberID &to)
 
void adjustDbRsp (XMPPError::Type &rsp)
 
- 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 XmlElementbuildPing (const String &stanzaId)
 
virtual bool processCompressing (XmlElement *xml, const JabberID &from, const JabberID &to)
 
virtual bool processRegister (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)
 

Protected Attributes

NamedList m_remoteDomains
 
- 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
 

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 []
 

Detailed Description

A server to server stream.

This class holds a server to server stream

Constructor & Destructor Documentation

◆ JBServerStream() [1/3]

JBServerStream ( JBEngine * engine,
Socket * socket,
bool component = false )

Constructor. Build an incoming stream from a socket

Parameters
engineEngine owning this stream
socketThe socket
componentTrue to build an external component stream

References JBStream::engine().

Referenced by serverStream().

◆ JBServerStream() [2/3]

JBServerStream ( JBEngine * engine,
const JabberID & local,
const JabberID & remote,
const char * dbId = 0,
const char * dbKey = 0,
bool dbOnly = false,
const NamedList * params = 0 )

Constructor. Build an outgoing stream

Parameters
engineEngine owning this stream
localLocal party jabber id
remoteRemote party jabber id
dbIdOptional dialback id (stream id)
dbKeyOptional dialback key to verify
dbOnlyTrue if this is a dialback only stream
paramsOptional stream parameters

References JBStream::engine(), JBStream::local(), and JBStream::remote().

◆ JBServerStream() [3/3]

JBServerStream ( JBEngine * engine,
const JabberID & local,
const JabberID & remote,
const String * name = 0,
const NamedList * params = 0 )

Constructor. Build an outgoing component stream

Parameters
engineEngine owning this stream
localLocal party jabber id
remoteRemote party jabber id
nameOptional stream name
paramsOptional stream parameters

References JBStream::engine(), JBStream::local(), JBStream::name(), and JBStream::remote().

Member Function Documentation

◆ adjustDbRsp()

void adjustDbRsp ( XMPPError::Type & rsp)
inlineprotected

Adjust a dialback response to avoid sending XEP 0220 'error' to a party not advertising rfc3920 version=1 (might not support it)

Parameters
rspThe response to adjust

References JBStream::flag(), and Mutex::lock().

◆ buildStreamStart()

virtual XmlElement * buildStreamStart ( )
protectedvirtual

Build a stream start XML element

Returns
XmlElement pointer

Reimplemented from JBStream.

◆ destroyed()

virtual void destroyed ( )
protectedvirtual

Release memory

Reimplemented from JBStream.

◆ dialback()

bool dialback ( ) const
inline

Check if this is an outgoing dialback stream

Returns
True if this stream is an outgoing dialback one

References JBStream::flag(), and JBStream::outgoing().

◆ hasRemoteDomain()

bool hasRemoteDomain ( const String & domain,
bool auth = true )
inline

Check if this stream has an already authenticated remote domain. This method is not thread safe

Parameters
domainDomain to check
authCheck if the domain is authenticated
Returns
True if a domain was found

References m_remoteDomains, and String::null().

◆ 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.

◆ processDbResult()

bool processDbResult ( XmlElement * xml,
const JabberID & from,
const JabberID & to )
protected

Process dialback key (db:result) requests

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

◆ 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.

◆ remoteDomains()

const NamedList & remoteDomains ( ) const
inline

Retrieve the list of remote domains. This method is not thread safe

Returns
The list of remote domains

References m_remoteDomains.

◆ sendDbResult()

bool sendDbResult ( const JabberID & from,
const JabberID & to,
XMPPError::Type rsp = XMPPError::NoError )

Send a dialback key response. Update the remote domains list. Terminate the stream if there are no more remote domains

Parameters
fromThe 'from' attribute
toThe 'to' attribute
rspThe response as enumeration: set it to NoError if valid, NotAuthorized if invalid or any other error to send a db:result error type
Returns
True on success

◆ sendDbVerify()

bool sendDbVerify ( const char * from,
const char * to,
const char * id,
XMPPError::Type rsp = XMPPError::NoError )

Send a dialback verify response

Parameters
fromThe 'from' attribute
toThe 'to' attribute
idThe 'id' attribute
rspThe response as enumeration: set it to NoError if valid, NotAuthorized if invalid or any other error to send a db:verify error type
Returns
True on success

◆ sendDialback()

bool sendDialback ( )

Send dialback data (key/verify)

Returns
False if stream termination was initiated

◆ serverStream()

virtual JBServerStream * serverStream ( )
inlinevirtual

Get a server stream from this one

Returns
JBServerStream pointer

Reimplemented from JBStream.

References JBServerStream().

◆ startComp()

bool startComp ( const String & local = String::empty(),
const String & remote = String::empty() )

Start a component stream (reply to received stream start). Send handshake if outgoing

Parameters
localLocal domain. Ignored if outgoing
remoteRemote domain. Ignored if outgoing
Returns
True on success

References String::empty(), JBStream::local(), and JBStream::remote().

◆ takeDb()

NamedString * takeDb ( )
inline

Take the dialback key from this stream

Returns
NamedString pointer or 0 if there is no dialback key held by this stream

References Mutex::lock().

Member Data Documentation

◆ m_remoteDomains

NamedList m_remoteDomains
protected

Incoming stream remote domains. Each element's value will contain the dialback key if not authenticated

Referenced by hasRemoteDomain(), and remoteDomains().


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