16 #include "capabilities.h"
17 #include "rostermanager.h"
21 #include "nonsaslauth.h"
23 #include "stanzaextensionfactory.h"
24 #include "stanzaextension.h"
26 #include "connectiontls.h"
27 #include "connectioncompression.h"
30 #if !defined( _WIN32 ) && !defined( _WIN32_WCE )
40 Client::ResourceBind::ResourceBind(
const std::string& resource,
bool bind )
47 Client::ResourceBind::ResourceBind(
const Tag* tag )
53 if( tag->name() ==
"unbind" )
55 else if( tag->name() ==
"bind" )
60 if( tag->hasChild(
"jid" ) )
61 m_jid.setJID( tag->findChild(
"jid" )->cdata() );
62 else if( tag->hasChild(
"resource" ) )
63 m_resource = tag->findChild(
"resource" )->cdata();
68 Client::ResourceBind::~ResourceBind()
72 const std::string& Client::ResourceBind::filterString()
const
79 Tag* Client::ResourceBind::tag()
const
84 Tag* t =
new Tag( m_bind ?
"bind" :
"unbind" );
87 if( m_bind && m_resource.empty() && m_jid )
88 new Tag( t,
"jid", m_jid.full() );
90 new Tag( t,
"resource", m_resource );
97 Tag* Client::SessionCreation::tag()
const
99 Tag* t =
new Tag(
"session" );
108 m_rosterManager( 0 ), m_auth( 0 ),
109 m_presence(
Presence::Available,
JID() ), m_resourceBound( false ),
110 m_forceNonSasl( false ), m_manageRoster( true ),
111 m_streamFeatures( 0 )
119 m_rosterManager( 0 ), m_auth( 0 ),
120 m_presence(
Presence::Available,
JID() ), m_resourceBound( false ),
121 m_forceNonSasl( false ), m_manageRoster( true ),
122 m_streamFeatures( 0 )
131 delete m_rosterManager;
149 bool Client::handleNormalNode(
Tag* tag )
153 m_streamFeatures = getStreamFeatures( tag );
160 " TLS but TLS support is not compiled into gloox." );
163 " TLS but the server didn't offer TLS." );
178 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." );
179 negotiateCompression( StreamFeatureCompressZlib );
196 " any auth mechanisms we know about" );
206 #if defined( _WIN32 ) && !defined( __SYMBIAN32__ )
230 else if( hasCompression()
232 && ( m_streamFeatures & StreamFeatureCompressZlib ) )
235 negotiateCompression( StreamFeatureCompressZlib );
250 "support any auth mechanisms we know about" );
256 const std::string& name = tag->
name();
257 const std::string& xmlns = tag->
xmlns();
273 else if( name ==
"failure" )
322 int Client::getStreamFeatures( Tag* tag )
324 if( tag->name() !=
"features" || tag->xmlns() !=
XMLNS_STREAM )
330 features |= StreamFeatureStartTls;
333 features |= getSaslMechs( tag->findChild(
"mechanisms" ) );
336 features |= StreamFeatureBind;
345 features |= StreamFeatureIqAuth;
351 features |= getCompressionMethods( tag->findChild(
"compression" ) );
359 int Client::getSaslMechs( Tag* tag )
363 const std::string mech =
"mechanism";
365 if( tag->hasChildWithCData( mech,
"DIGEST-MD5" ) )
368 if( tag->hasChildWithCData( mech,
"PLAIN" ) )
371 if( tag->hasChildWithCData( mech,
"ANONYMOUS" ) )
374 if( tag->hasChildWithCData( mech,
"EXTERNAL" ) )
377 if( tag->hasChildWithCData( mech,
"GSSAPI" ) )
378 mechs |= SaslMechGssapi;
380 if( tag->hasChildWithCData( mech,
"NTLM" ) )
381 mechs |= SaslMechNTLM;
386 int Client::getCompressionMethods( Tag* tag )
390 if( tag->hasChildWithCData(
"method",
"zlib" ) )
391 meths |= StreamFeatureCompressZlib;
393 if( tag->hasChildWithCData(
"method",
"lzw" ) )
415 else if( m_streamFeatures & StreamFeatureIqAuth || m_forceNonSasl )
426 void Client::handleIqIDForward(
const IQ& iq,
int context )
430 case CtxResourceUnbind:
433 case CtxResourceBind:
434 processResourceBind( iq );
436 case CtxSessionEstablishment:
437 processCreateSession( iq );
444 bool Client::bindOperation(
const std::string& resource,
bool bind )
452 send( iq,
this, bind ? CtxResourceBind : CtxResourceUnbind );
461 if( !( m_streamFeatures & StreamFeatureUnbind ) )
467 void Client::processResourceBind(
const IQ& iq )
474 if( !rb || !rb->jid() )
481 m_resourceBound =
true;
501 void Client::createSession()
506 send( iq,
this, CtxSessionEstablishment );
509 void Client::processCreateSession(
const IQ& iq )
511 switch( iq.subtype() )
528 if( method == StreamFeatureCompressZlib )
529 new Tag( t,
"method",
"zlib" );
532 new Tag( t,
"method",
"lzw" );
538 const std::string& status )
543 sendPresence( m_presence );
547 const std::string& status )
549 Presence p( pres, to, status, priority );
553 void Client::sendPresence(
Presence& pres )
563 m_manageRoster =
false;
564 delete m_rosterManager;
575 void Client::connected()
582 m_rosterManager->
fill();
594 void Client::rosterFilled()
596 sendPresence( m_presence );
608 m_resourceBound =
false;
610 m_streamFeatures = 0;
614 void Client::cleanup()
617 m_resourceBound =
false;
618 m_streamFeatures = 0;