16 #include "capabilities.h"
17 #include "rostermanager.h"
21 #include "nonsaslauth.h"
23 #include "stanzaextensionfactory.h"
24 #include "stanzaextension.h"
29 #if !defined( _WIN32 ) && !defined( _WIN32_WCE )
37 Client::ResourceBind::ResourceBind(
const std::string& resource,
bool bind )
40 prep::resourceprep( resource, m_resource );
44 Client::ResourceBind::ResourceBind(
const Tag* tag )
50 if( tag->name() ==
"unbind" )
52 else if( tag->name() ==
"bind" )
57 if( tag->hasChild(
"jid" ) )
58 m_jid.setJID( tag->findChild(
"jid" )->cdata() );
59 else if( tag->hasChild(
"resource" ) )
60 m_resource = tag->findChild(
"resource" )->cdata();
65 Client::ResourceBind::~ResourceBind()
69 const std::string& Client::ResourceBind::filterString()
const
76 Tag* Client::ResourceBind::tag()
const
81 Tag* t =
new Tag( m_bind ?
"bind" :
"unbind" );
82 t->setXmlns( XMLNS_STREAM_BIND );
84 if( m_bind && m_resource.empty() && m_jid )
85 new Tag( t,
"jid", m_jid.full() );
87 new Tag( t,
"resource", m_resource );
94 Tag* Client::SessionCreation::tag()
const
96 Tag* t =
new Tag(
"session" );
97 t->setXmlns( XMLNS_STREAM_SESSION );
103 Client::Client(
const std::string& server )
105 m_rosterManager( 0 ), m_auth( 0 ),
107 m_forceNonSasl( false ), m_manageRoster( true ),
108 m_smId(
EmptyString ), m_smLocation(
EmptyString ), m_smResume( false ), m_smWanted( false ), m_smMax( 0 ),
109 m_streamFeatures( 0 )
117 m_rosterManager( 0 ), m_auth( 0 ),
119 m_forceNonSasl( false ), m_manageRoster( true ),
120 m_smId(
EmptyString ), m_smLocation(
EmptyString ), m_smResume( false ), m_smWanted( false ), m_smMax( 0 ),
121 m_streamFeatures( 0 )
130 delete m_rosterManager;
148 bool Client::handleNormalNode(
Tag* tag )
152 m_streamFeatures = getStreamFeatures( tag );
158 " TLS but either the server didn't offer TLS or"
159 " TLS support is not compiled into gloox." );
172 logInstance().
warn(
LogAreaClassClient,
"The server offers compression, but negotiating Compression at this stage is not recommended. See XEP-0170 for details. We'll continue anyway." );
181 sendStreamManagement();
194 " any auth mechanisms we know about" );
204 #if defined( _WIN32 ) && !defined( __SYMBIAN32__ )
247 "support any auth mechanisms we know about" );
253 const std::string& name = tag->
name(),
265 else if( name ==
"failure" )
314 m_smResume = ( ( res ==
"true" || res ==
"1" ) && !m_smId.empty() ) ?
true :
false;
364 int Client::getStreamFeatures( Tag* tag )
366 if( tag->name() !=
"features" || tag->xmlns() !=
XMLNS_STREAM )
375 features |= getSaslMechs( tag->findChild(
"mechanisms" ) );
393 features |= getCompressionMethods( tag->findChild(
"compression" ) );
407 int Client::getSaslMechs( Tag* tag )
411 const std::string mech =
"mechanism";
413 if( tag->hasChildWithCData( mech,
"SCRAM-SHA-1-PLUS" ) )
416 if( tag->hasChildWithCData( mech,
"SCRAM-SHA-1" ) )
419 if( tag->hasChildWithCData( mech,
"DIGEST-MD5" ) )
422 if( tag->hasChildWithCData( mech,
"PLAIN" ) )
425 if( tag->hasChildWithCData( mech,
"ANONYMOUS" ) )
428 if( tag->hasChildWithCData( mech,
"EXTERNAL" ) )
431 if( tag->hasChildWithCData( mech,
"GSSAPI" ) )
434 if( tag->hasChildWithCData( mech,
"NTLM" ) )
440 int Client::getCompressionMethods( Tag* tag )
444 if( tag->hasChildWithCData(
"method",
"zlib" ) )
447 if( tag->hasChildWithCData(
"method",
"lzw" ) )
493 void Client::handleIqIDForward(
const IQ& iq,
int context )
497 case CtxResourceUnbind:
500 case CtxResourceBind:
501 processResourceBind( iq );
503 case CtxSessionEstablishment:
504 processCreateSession( iq );
511 bool Client::bindOperation(
const std::string& resource,
bool bind )
519 send( iq,
this, bind ? CtxResourceBind : CtxResourceUnbind );
534 void Client::processResourceBind(
const IQ& iq )
541 if( !rb || !rb->jid() )
553 sendStreamManagement();
585 sendStreamManagement();
588 void Client::sendStreamManagement()
596 Tag* e =
new Tag(
"enable" );
607 Tag* r =
new Tag(
"resume" );
610 r->addAttribute(
"previd", m_smId );
638 void Client::createSession()
643 send( iq,
this, CtxSessionEstablishment );
646 void Client::processCreateSession(
const IQ& iq )
648 switch( iq.subtype() )
666 new Tag( t,
"method",
"zlib" );
669 new Tag( t,
"method",
"lzw" );
675 const std::string& status )
681 sendPresence( m_presence );
685 const std::string& status )
691 void Client::sendPresence(
Presence& pres )
701 m_manageRoster =
false;
702 delete m_rosterManager;
713 void Client::connected()
720 m_rosterManager->
fill();
732 void Client::rosterFilled()
734 sendPresence( m_presence );
756 m_streamFeatures = 0;
760 void Client::cleanup()
764 m_streamFeatures = 0;
This is an implementation of XEP-0115 (Entity Capabilities).
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
const std::string getID()
const std::string & server() const
void processSASLError(Tag *tag)
std::string m_clientCerts
void setAuthed(bool authed)
void checkQueue(int handled, bool resend)
void processSASLChallenge(const std::string &challenge)
ConnectionState state() const
virtual const std::string & username() const
StanzaExtensionList m_presenceExtensions
bool processSASLSuccess(const std::string &payload)
void notifyOnSessionCreateError(const Error *error)
CompressionBase * m_compression
virtual void disconnect(ConnectionError reason)
GLOOX_DEPRECATED std::string m_selectedResource
void notifyOnResourceBindError(const Error *error)
virtual const std::string & password() const
void startSASL(SaslMechanism type)
void notifyStreamEvent(StreamEvent event)
void registerStanzaExtension(StanzaExtension *ext)
void notifyOnResourceBind(const std::string &resource)
void reqStreamManagement()
Client(const std::string &server)
void setStreamManagement(bool enable=true, bool resume=true)
void setUsername(const std::string &username)
bool bindResource(const std::string &resource)
void ackStreamManagement()
const std::string & resource() const
bool selectResource(const std::string &resource)
void setIdentity(const std::string &category, const std::string &type, const std::string &name=EmptyString)
An abstraction of an IQ stanza.
const std::string & serverRaw() const
bool setServer(const std::string &server)
const std::string & resource() const
bool setResource(const std::string &resource)
bool setUsername(const std::string &username)
void warn(LogArea area, const std::string &message) const
void dbg(LogArea area, const std::string &message) const
void err(LogArea area, const std::string &message) const
This class is an implementation of XEP-0078 (Non-SASL Authentication).
void doAuth(const std::string &sid)
An abstraction of a presence stanza.
void setPriority(int priority)
void setPresence(PresenceType type)
void addStatus(const std::string &status, const std::string &lang=EmptyString)
This class implements Jabber/XMPP roster handling in the jabber:iq:roster namespace.
void addExtension(const StanzaExtension *se)
const Error * error() const
const StanzaExtension * findExtension(int type) const
virtual bool hasChannelBinding() const
virtual bool handshake()=0
This is an abstraction of an XML element.
const std::string xmlns() const
bool addAttribute(Attribute *attr)
const std::string cdata() const
const std::string & findAttribute(const std::string &name) const
const std::string & name() const
bool setXmlns(const std::string &xmlns, const std::string &prefix=EmptyString)
The namespace for the gloox library.
const std::string XMLNS_STREAM
const std::string XMLNS_STREAM_COMPRESS
@ StreamFeatureCompressDclz
@ StreamFeatureStreamManagement
@ StreamFeatureCompressZlib
@ StreamFeatureIqRegister
@ StreamFeatureClientStateIndication
const std::string XMLNS_STREAM_BIND
@ ConnAuthenticationFailed
const std::string XMLNS_STREAM_IQREGISTER
const std::string XMLNS_CLIENT
@ StreamEventResourceBinding
@ StreamEventAuthentication
@ StreamEventSMResumeFailed
@ StreamEventSMEnableFailed
@ StreamEventSessionCreation
const std::string XMLNS_STREAM_SASL
const std::string XMLNS_STREAM_SESSION
const std::string EmptyString
const std::string XMLNS_STREAM_IQAUTH
const std::string XMLNS_CLIENT_STATE_INDICATION
const std::string XMLNS_COMPRESSION
const std::string XMLNS_STREAM_TLS
const std::string XMLNS_STREAM_MANAGEMENT