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 )
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" );
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" );
105 m_rosterManager( 0 ), m_auth( 0 ),
106 m_presence(
Presence::Available,
JID() ), m_resourceBound( false ),
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 ),
118 m_presence(
Presence::Available,
JID() ), m_resourceBound( false ),
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 in." );
163 && ( m_streamFeatures & StreamFeatureStartTls ) )
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." );
173 negotiateCompression( StreamFeatureCompressZlib );
181 sendStreamManagement();
194 " any auth mechanisms we know about" );
204 #if defined( _WIN32 ) && !defined( __SYMBIAN32__ )
229 && ( m_streamFeatures & StreamFeatureCompressZlib ) )
232 negotiateCompression( StreamFeatureCompressZlib );
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 )
372 features |= StreamFeatureStartTls;
375 features |= getSaslMechs( tag->findChild(
"mechanisms" ) );
387 features |= StreamFeatureIqAuth;
393 features |= getCompressionMethods( tag->findChild(
"compression" ) );
404 int Client::getSaslMechs( Tag* tag )
408 const std::string mech =
"mechanism";
410 if( tag->hasChildWithCData( mech,
"SCRAM-SHA-1-PLUS" ) )
413 if( tag->hasChildWithCData( mech,
"SCRAM-SHA-1" ) )
416 if( tag->hasChildWithCData( mech,
"DIGEST-MD5" ) )
419 if( tag->hasChildWithCData( mech,
"PLAIN" ) )
422 if( tag->hasChildWithCData( mech,
"ANONYMOUS" ) )
425 if( tag->hasChildWithCData( mech,
"EXTERNAL" ) )
428 if( tag->hasChildWithCData( mech,
"GSSAPI" ) )
429 mechs |= SaslMechGssapi;
431 if( tag->hasChildWithCData( mech,
"NTLM" ) )
432 mechs |= SaslMechNTLM;
437 int Client::getCompressionMethods( Tag* tag )
441 if( tag->hasChildWithCData(
"method",
"zlib" ) )
442 meths |= StreamFeatureCompressZlib;
444 if( tag->hasChildWithCData(
"method",
"lzw" ) )
479 else if( m_streamFeatures & StreamFeatureIqAuth || m_forceNonSasl )
490 void Client::handleIqIDForward(
const IQ& iq,
int context )
494 case CtxResourceUnbind:
497 case CtxResourceBind:
498 processResourceBind( iq );
500 case CtxSessionEstablishment:
501 processCreateSession( iq );
508 bool Client::bindOperation(
const std::string& resource,
bool bind )
516 send( iq,
this, bind ? CtxResourceBind : CtxResourceUnbind );
525 if( !( m_streamFeatures & StreamFeatureUnbind ) )
531 void Client::processResourceBind(
const IQ& iq )
538 if( !rb || !rb->jid() )
545 m_resourceBound =
true;
550 sendStreamManagement();
581 if( m_smWanted && m_resourceBound )
582 sendStreamManagement();
585 void Client::sendStreamManagement()
593 Tag* e =
new Tag(
"enable" );
604 Tag* r =
new Tag(
"resume" );
607 r->addAttribute(
"previd", m_smId );
632 void Client::createSession()
637 send( iq,
this, CtxSessionEstablishment );
640 void Client::processCreateSession(
const IQ& iq )
642 switch( iq.subtype() )
659 if( method == StreamFeatureCompressZlib )
660 new Tag( t,
"method",
"zlib" );
663 new Tag( t,
"method",
"lzw" );
669 const std::string& status )
675 sendPresence( m_presence );
679 const std::string& status )
681 Presence p( pres, to, status, priority );
685 void Client::sendPresence(
Presence& pres )
695 m_manageRoster =
false;
696 delete m_rosterManager;
707 void Client::connected()
714 m_rosterManager->
fill();
726 void Client::rosterFilled()
728 sendPresence( m_presence );
748 m_resourceBound =
false;
750 m_streamFeatures = 0;
754 void Client::cleanup()
757 m_resourceBound =
false;
758 m_streamFeatures = 0;
void processSASLChallenge(const std::string &challenge)
bool setXmlns(const std::string &xmlns, const std::string &prefix=EmptyString)
bool setServer(const std::string &server)
bool setResource(const std::string &resource)
const std::string XMLNS_COMPRESSION
const std::string XMLNS_STREAM_TLS
const std::string XMLNS_STREAM_MANAGEMENT
const std::string XMLNS_STREAM_IQAUTH
void doAuth(const std::string &sid)
void err(LogArea area, const std::string &message) const
const std::string XMLNS_STREAM_SASL
An abstraction of an IQ stanza.
void addStatus(const std::string &status, const std::string &lang=EmptyString)
void addExtension(const StanzaExtension *se)
void setUsername(const std::string &username)
virtual const std::string & username() const
void notifyOnResourceBind(const std::string &resource)
const std::string XMLNS_CLIENT
virtual bool hasChannelBinding() const
void registerStanzaExtension(StanzaExtension *ext)
This class is an implementation of XEP-0078 (Non-SASL Authentication).
Client(const std::string &server)
void notifyOnResourceBindError(const Error *error)
GLOOX_DEPRECATED std::string m_selectedResource
void reqStreamManagement()
bool bindResource(const std::string &resource)
An abstraction of a presence stanza.
void warn(LogArea area, const std::string &message) const
void setStreamManagement(bool enable=true, bool resume=true)
ConnectionState state() const
const std::string XMLNS_STREAM_SESSION
bool processSASLSuccess(const std::string &payload)
void setPriority(int priority)
The namespace for the gloox library.
const std::string & xmlns() const
bool setUsername(const std::string &username)
StanzaExtensionList m_presenceExtensions
void notifyOnSessionCreateError(const Error *error)
void setPresence(PresenceType type)
CompressionBase * m_compression
This class implements Jabber/XMPP roster handling in the jabber:iq:roster namespace.
const std::string & findAttribute(const std::string &name) const
const std::string XMLNS_STREAM_COMPRESS
virtual void disconnect(ConnectionError reason)
const std::string cdata() const
void setIdentity(const std::string &category, const std::string &type, const std::string &name=EmptyString)
const std::string XMLNS_STREAM
const std::string & serverRaw() const
bool addAttribute(Attribute *attr)
virtual bool handshake()=0
bool resourceprep(const std::string &resource, std::string &out)
void processSASLError(Tag *tag)
std::string m_clientCerts
const std::string & resource() const
const std::string & name() const
const std::string getID()
const Error * error() const
void dbg(LogArea area, const std::string &message) const
const std::string & resource() const
This is an implementation of XEP-0115 (Entity Capabilities).
void ackStreamManagement()
void notifyStreamEvent(StreamEvent event)
void checkQueue(int handled, bool resend)
void setAuthed(bool authed)
const std::string XMLNS_STREAM_IQREGISTER
virtual const std::string & password() const
void startSASL(SaslMechanism type)
const std::string XMLNS_STREAM_BIND
const std::string EmptyString
This is the common base class for a Jabber/XMPP Client and a Jabber Component.
const StanzaExtension * findExtension(int type) const
This is an abstraction of an XML element.
bool selectResource(const std::string &resource)