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 )
39 Client::ResourceBind::ResourceBind(
const std::string& resource,
bool bind )
46 Client::ResourceBind::ResourceBind(
const Tag* tag )
52 if( tag->name() ==
"unbind" )
54 else if( tag->name() ==
"bind" )
59 if( tag->hasChild(
"jid" ) )
60 m_jid.setJID( tag->findChild(
"jid" )->cdata() );
61 else if( tag->hasChild(
"resource" ) )
62 m_resource = tag->findChild(
"resource" )->cdata();
67 Client::ResourceBind::~ResourceBind()
71 const std::string& Client::ResourceBind::filterString()
const
78 Tag* Client::ResourceBind::tag()
const
83 Tag* t =
new Tag( m_bind ?
"bind" :
"unbind" );
86 if( m_bind && m_resource.empty() && m_jid )
87 new Tag( t,
"jid", m_jid.full() );
89 new Tag( t,
"resource", m_resource );
96 Tag* Client::SessionCreation::tag()
const
98 Tag* t =
new Tag(
"session" );
107 m_rosterManager( 0 ), m_auth( 0 ),
108 m_presence(
Presence::Available,
JID() ), m_resourceBound( false ),
109 m_forceNonSasl( false ), m_manageRoster( true ),
110 m_streamFeatures( 0 )
118 m_rosterManager( 0 ), m_auth( 0 ),
119 m_presence(
Presence::Available,
JID() ), m_resourceBound( false ),
120 m_forceNonSasl( false ), m_manageRoster( true ),
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 );
190 " any auth mechanisms we know about" );
200 #if defined( _WIN32 ) && !defined( __SYMBIAN32__ )
225 && ( m_streamFeatures & StreamFeatureCompressZlib ) )
228 negotiateCompression( StreamFeatureCompressZlib );
243 "support any auth mechanisms we know about" );
249 const std::string& name = tag->
name(),
261 else if( name ==
"failure" )
305 int Client::getStreamFeatures( Tag* tag )
307 if( tag->name() !=
"features" || tag->xmlns() !=
XMLNS_STREAM )
313 features |= StreamFeatureStartTls;
316 features |= getSaslMechs( tag->findChild(
"mechanisms" ) );
319 features |= StreamFeatureBind;
328 features |= StreamFeatureIqAuth;
334 features |= getCompressionMethods( tag->findChild(
"compression" ) );
342 int Client::getSaslMechs( Tag* tag )
346 const std::string mech =
"mechanism";
348 if( tag->hasChildWithCData( mech,
"DIGEST-MD5" ) )
351 if( tag->hasChildWithCData( mech,
"PLAIN" ) )
354 if( tag->hasChildWithCData( mech,
"ANONYMOUS" ) )
357 if( tag->hasChildWithCData( mech,
"EXTERNAL" ) )
360 if( tag->hasChildWithCData( mech,
"GSSAPI" ) )
361 mechs |= SaslMechGssapi;
363 if( tag->hasChildWithCData( mech,
"NTLM" ) )
364 mechs |= SaslMechNTLM;
369 int Client::getCompressionMethods( Tag* tag )
373 if( tag->hasChildWithCData(
"method",
"zlib" ) )
374 meths |= StreamFeatureCompressZlib;
376 if( tag->hasChildWithCData(
"method",
"lzw" ) )
398 else if( m_streamFeatures & StreamFeatureIqAuth || m_forceNonSasl )
409 void Client::handleIqIDForward(
const IQ& iq,
int context )
413 case CtxResourceUnbind:
416 case CtxResourceBind:
417 processResourceBind( iq );
419 case CtxSessionEstablishment:
420 processCreateSession( iq );
427 bool Client::bindOperation(
const std::string& resource,
bool bind )
435 send( iq,
this, bind ? CtxResourceBind : CtxResourceUnbind );
441 if( !( m_streamFeatures & StreamFeatureUnbind ) )
449 void Client::processResourceBind(
const IQ& iq )
456 if( !rb || !rb->jid() )
463 m_resourceBound =
true;
483 void Client::createSession()
488 send( iq,
this, CtxSessionEstablishment );
491 void Client::processCreateSession(
const IQ& iq )
493 switch( iq.subtype() )
510 if( method == StreamFeatureCompressZlib )
511 new Tag( t,
"method",
"zlib" );
514 new Tag( t,
"method",
"lzw" );
520 const std::string& status )
525 sendPresence( m_presence );
529 const std::string& status )
531 Presence p( pres, to, status, priority );
535 void Client::sendPresence(
Presence& pres )
545 m_manageRoster =
false;
546 delete m_rosterManager;
557 void Client::connected()
564 m_rosterManager->
fill();
576 void Client::rosterFilled()
578 sendPresence( m_presence );
590 m_resourceBound =
false;
592 m_streamFeatures = 0;
596 void Client::cleanup()
599 m_resourceBound =
false;
600 m_streamFeatures = 0;
void processSASLChallenge(const std::string &challenge)
bool setServer(const std::string &server)
const std::string XMLNS_COMPRESSION
const std::string XMLNS_STREAM_TLS
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 processSASLSuccess()
void setUsername(const std::string &username)
virtual const std::string & username() const
void notifyOnResourceBind(const std::string &resource)
const std::string XMLNS_CLIENT
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)
bool bindResource(const std::string &resource)
An abstraction of a presence stanza.
void warn(LogArea area, const std::string &message) const
ConnectionState state() const
const std::string XMLNS_STREAM_SESSION
void setPriority(int priority)
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
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 notifyStreamEvent(StreamEvent event)
void setAuthed(bool authed)
const std::string XMLNS_STREAM_IQREGISTER
virtual const std::string & password() const
std::string m_selectedResource
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)