13 #include "authenticationhandler.h"
14 #include "featuresasl.h"
15 #include "streambase.h"
17 #include <gloox/adhoc.h>
18 #include <gloox/base64.h>
19 #include <gloox/dataform.h>
20 #include <gloox/gloox.h>
27 : m_state( SASLCanceled ), m_authHandler( authHandler )
33 static const std::string filter =
"/auth[@xmlns='" + gloox::XMLNS_STREAM_SASL +
"']";
46 t =
new gloox::Tag(
"mechanisms" );
47 t->setXmlns( gloox::XMLNS_STREAM_SASL );
48 new gloox::Tag( t,
"mechanism",
"PLAIN" );
50 m_state = SASLOffered;
56 void FeatureSASL::handleTag( gloox::Tag* _tag )
61 const gloox::Tag* auth = _tag->findTag(
"/auth/[@xmlns='" + gloox::XMLNS_STREAM_SASL +
"'][@mechanism='PLAIN']" );
62 if( m_state == SASLOffered && auth )
64 decodeSASLPLAIN( auth->cdata() );
68 m_state = SASLCanceled;
69 m_parent->
disconnect( gloox::ConnAuthenticationFailed );
72 void FeatureSASL::decodeSASLPLAIN(
const std::string& cdata )
74 const std::string decoded = gloox::Base64::decode64( cdata );
76 std::string::size_type pos = decoded.find(
'\0', 0 );
77 if( pos == std::string::npos )
79 m_parent->
disconnect( gloox::ConnAuthenticationFailed );
83 const gloox::JID authzid( decoded.substr( 0, pos ) );
85 std::string::size_type pos2 = decoded.find(
'\0', pos + 1 );
86 if( pos2 == std::string::npos )
88 m_parent->
disconnect( gloox::ConnAuthenticationFailed );
92 const std::string& authcid = decoded.substr( pos + 1, pos2 - 1 );
93 const std::string& password = decoded.substr( pos2 + 1 );
95 m_state = SASLChecking;
101 gloox::Tag* s =
new gloox::Tag( success ?
"success" :
"failure" );
102 s->setXmlns( gloox::XMLNS_STREAM_SASL );
111 const gloox::JID a( authzid );
117 std::string::size_type pos3 = authcid.find(
'@', 0 );
118 if( pos3 == std::string::npos )
124 const gloox::JID a( authcid );
130 m_state = SASLEnabled;
134 m_state = SASLCanceled;
135 m_parent->
disconnect( gloox::ConnAuthenticationFailed );