14 # include "../config.h.win"
15 #elif defined( _WIN32_WCE )
16 # include "../config.h.win"
22 #include "rostermanager.h"
25 #include "nonsaslauth.h"
27 #include "stanzaextensionfactory.h"
28 #include "stanzaextension.h"
31 #if !defined( _WIN32 ) && !defined( _WIN32_WCE )
47 m_rosterManager( 0 ), m_auth( 0 ),
48 m_presence(
PresenceAvailable ), m_resourceBound( false ), m_forceNonSasl( false ),
49 m_manageRoster( true ), m_doAuth( false ),
50 m_streamFeatures( 0 ), m_priority( 0 )
58 m_rosterManager( 0 ), m_auth( 0 ),
59 m_presence(
PresenceAvailable ), m_resourceBound( false ), m_forceNonSasl( false ),
60 m_manageRoster( true ), m_doAuth( true ),
61 m_streamFeatures( 0 ), m_priority( 0 )
69 const std::string& server,
const std::string& resource,
int port )
71 m_rosterManager( 0 ), m_auth( 0 ),
72 m_presence(
PresenceAvailable ), m_resourceBound( false ), m_forceNonSasl( false ),
73 m_manageRoster( true ), m_doAuth( true ),
74 m_streamFeatures( 0 ), m_priority( 0 )
86 delete m_rosterManager;
102 bool Client::handleNormalNode(
Stanza *stanza )
104 if( stanza->
name() ==
"stream:features" )
106 m_streamFeatures = getStreamFeatures( stanza );
112 "Client is configured to require TLS but either the server didn't offer TLS or "
113 "TLS support is not compiled in." );
116 else if( m_tls >
TLSDisabled && m_encryption && !m_encryptionActive
117 && ( m_streamFeatures & StreamFeatureStartTls ) )
137 "the server doesn't support any auth mechanisms we know about" );
141 else if( m_doAuth && !m_clientCerts.empty() && !m_clientKey.empty()
151 startSASL( SaslMechGssapi );
158 startSASL( SaslMechAnonymous );
166 else if( m_compress && m_compression && !m_compressionActive
170 negotiateCompression( StreamFeatureCompressZlib );
185 "fallback: the server doesn't support any auth mechanisms we know about" );
195 m_encryptionActive =
true;
212 m_compressionActive =
true;
218 processSASLChallenge( stanza->
cdata() );
223 processSASLError( stanza );
236 processResourceBind( stanza );
238 else if( ( stanza->
name() ==
"iq" ) && stanza->
hasAttribute(
"id",
"session" ) )
240 processCreateSession( stanza );
249 int Client::getStreamFeatures( Stanza *stanza )
251 if( stanza->name() !=
"stream:features" )
257 features |= StreamFeatureStartTls;
260 features |= getSaslMechs( stanza->findChild(
"mechanisms" ) );
269 features |= StreamFeatureIqAuth;
275 features |= getCompressionMethods( stanza->findChild(
"compression" ) );
283 int Client::getSaslMechs( Tag *tag )
287 if( tag->hasChildWithCData(
"mechanism",
"DIGEST-MD5" ) )
290 if( tag->hasChildWithCData(
"mechanism",
"PLAIN" ) )
293 if( tag->hasChildWithCData(
"mechanism",
"ANONYMOUS" ) )
296 if( tag->hasChildWithCData(
"mechanism",
"EXTERNAL" ) )
299 if( tag->hasChildWithCData(
"mechanism",
"GSSAPI" ) )
300 mechs |= SaslMechGssapi;
305 int Client::getCompressionMethods( Tag *tag )
309 if( tag->hasChildWithCData(
"method",
"zlib" ) )
310 meths |= StreamFeatureCompressZlib;
312 if( tag->hasChildWithCData(
"method",
"lzw" ) )
334 else if( m_streamFeatures & StreamFeatureIqAuth || m_forceNonSasl )
347 if( !m_resourceBound )
349 Tag *iq =
new Tag(
"iq" );
352 Tag *b =
new Tag( iq,
"bind" );
361 void Client::processResourceBind(
Stanza *stanza )
370 m_resourceBound =
true;
380 Tag *error = stanza->
findChild(
"error" );
381 if( stanza->
hasChild(
"error",
"type",
"modify" )
386 else if( stanza->
hasChild(
"error",
"type",
"cancel" ) )
404 void Client::createSession()
407 Tag *iq =
new Tag(
"iq" );
408 iq->addAttribute(
"type",
"set" );
409 iq->addAttribute(
"id",
"session" );
410 Tag *s =
new Tag( iq,
"session" );
416 void Client::processCreateSession( Stanza *stanza )
418 switch( stanza->subtype() )
427 Tag *error = stanza->findChild(
"error" );
428 if( stanza->hasChild(
"error",
"type",
"wait" )
433 else if( stanza->hasChild(
"error",
"type",
"auth" )
438 else if( stanza->hasChild(
"error",
"type",
"cancel" )
454 Tag *t =
new Tag(
"compress" );
457 if( method == StreamFeatureCompressZlib )
458 new Tag( t,
"method",
"zlib" );
461 new Tag( t,
"method",
"lzw" );
468 m_presenceExtensions.push_back( se );
473 StanzaExtensionList::iterator it = m_presenceExtensions.begin();
474 for( ; it != m_presenceExtensions.end(); ++it )
478 m_presenceExtensions.clear();
486 if( priority < -128 )
498 m_manageRoster =
false;
499 delete m_rosterManager;
510 void Client::sendPresence()
520 sprintf( tmp,
"%s", m_priority );
521 new Tag( p,
"priority", tmp );
523 std::ostringstream oss;
525 new Tag( p,
"priority", oss.str() );
527 StanzaExtensionList::const_iterator it = m_presenceExtensions.begin();
528 for( ; it != m_presenceExtensions.end(); ++it )
537 void Client::connected()
544 m_rosterManager->
fill();
556 void Client::rosterFilled()
570 m_resourceBound =
false;
572 m_streamFeatures = 0;
576 void Client::cleanup()
579 m_resourceBound =
false;
580 m_streamFeatures = 0;