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 ),
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 ),
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 )
674 sendPresence( m_presence );
678 const std::string& status )
680 Presence p( pres, to, status, priority );
684 void Client::sendPresence(
Presence& pres )
694 m_manageRoster =
false;
695 delete m_rosterManager;
706 void Client::connected()
713 m_rosterManager->
fill();
725 void Client::rosterFilled()
727 sendPresence( m_presence );
747 m_resourceBound =
false;
749 m_streamFeatures = 0;
753 void Client::cleanup()
756 m_resourceBound =
false;
757 m_streamFeatures = 0;