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 );
444 if( !( m_streamFeatures & StreamFeatureUnbind ) )
450 void Client::processResourceBind(
const IQ& iq )
457 if( !rb || !rb->jid() )
464 m_resourceBound =
true;
484 void Client::createSession()
489 send( iq,
this, CtxSessionEstablishment );
492 void Client::processCreateSession(
const IQ& iq )
494 switch( iq.subtype() )
511 if( method == StreamFeatureCompressZlib )
512 new Tag( t,
"method",
"zlib" );
515 new Tag( t,
"method",
"lzw" );
521 const std::string& status )
526 sendPresence( m_presence );
530 const std::string& status )
532 Presence p( pres, to, status, priority );
536 void Client::sendPresence(
Presence& pres )
546 m_manageRoster =
false;
547 delete m_rosterManager;
558 void Client::connected()
565 m_rosterManager->
fill();
577 void Client::rosterFilled()
579 sendPresence( m_presence );
591 m_resourceBound =
false;
593 m_streamFeatures = 0;
597 void Client::cleanup()
600 m_resourceBound =
false;
601 m_streamFeatures = 0;