Hack X-GOOGLE-TOKEN support into gloox and use it in clementine.

This commit is contained in:
John Maguire 2011-03-01 16:03:04 +00:00
parent a3b78a0043
commit 86919cc0ff
9 changed files with 49 additions and 10 deletions

View File

@ -361,6 +361,9 @@ namespace gloox
if( tag->hasChildWithCData( mech, "NTLM" ) ) if( tag->hasChildWithCData( mech, "NTLM" ) )
mechs |= SaslMechNTLM; mechs |= SaslMechNTLM;
if( tag->hasChildWithCData( mech, "X-GOOGLE-TOKEN" ) )
mechs |= SaslMechGoogleToken;
return mechs; return mechs;
} }
@ -393,6 +396,13 @@ namespace gloox
notifyStreamEvent( StreamEventAuthentication ); notifyStreamEvent( StreamEventAuthentication );
startSASL( SaslMechPlain ); startSASL( SaslMechPlain );
} }
else if( m_streamFeatures & SaslMechGoogleToken &&
m_availableSaslMechs & SaslMechGoogleToken
&& !m_forceNonSasl )
{
notifyStreamEvent( StreamEventAuthentication );
startSASL( SaslMechGoogleToken );
}
else if( m_streamFeatures & StreamFeatureIqAuth || m_forceNonSasl ) else if( m_streamFeatures & StreamFeatureIqAuth || m_forceNonSasl )
{ {
notifyStreamEvent( StreamEventAuthentication ); notifyStreamEvent( StreamEventAuthentication );

View File

@ -515,6 +515,17 @@ namespace gloox
#endif #endif
break; break;
} }
case SaslMechGoogleToken:
{
a->addAttribute("mechanism", "X-GOOGLE-TOKEN");
std::string tmp;
tmp += '\0';
tmp += m_jid.username();
tmp += '\0';
tmp += m_password;
a->setCData( Base64::encode64( tmp ) );
break;
}
default: default:
break; break;
} }

View File

@ -719,6 +719,7 @@ namespace gloox
SaslMechExternal = 2048, /**< SASL EXTERNAL according to RFC 2222 Section 7.4. */ SaslMechExternal = 2048, /**< SASL EXTERNAL according to RFC 2222 Section 7.4. */
SaslMechGssapi = 4096, /**< SASL GSSAPI (Win32 only). */ SaslMechGssapi = 4096, /**< SASL GSSAPI (Win32 only). */
SaslMechNTLM = 8192, /**< SASL NTLM (Win32 only). */ SaslMechNTLM = 8192, /**< SASL NTLM (Win32 only). */
SaslMechGoogleToken = 16384, /**< SASL X-GOOGLE-TOKEN. */
SaslMechAll = 65535 /**< Includes all supported SASL mechanisms. */ SaslMechAll = 65535 /**< Includes all supported SASL mechanisms. */
}; };

View File

@ -30,6 +30,8 @@ target_link_libraries(xrme
${QT_LIBRARIES} ${QT_LIBRARIES}
) )
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
# Install library # Install library
install(TARGETS xrme install(TARGETS xrme
RUNTIME DESTINATION bin RUNTIME DESTINATION bin

View File

@ -49,8 +49,8 @@ struct Connection::Private : public gloox::ConnectionListener,
media_player_(NULL), media_player_(NULL),
remote_control_(NULL), remote_control_(NULL),
spontaneous_disconnect_(true), spontaneous_disconnect_(true),
media_player_extension_(new MediaPlayerExtension()), media_player_extension_(NULL),
remote_control_extension_(new RemoteControlExtension()) {} remote_control_extension_(NULL) {}
static const char* kDefaultServer; static const char* kDefaultServer;
static const char* kDefaultJIDResource; static const char* kDefaultJIDResource;
@ -251,6 +251,8 @@ bool Connection::Connect() {
d->client_->disco()->setVersion(d->agent_name_.toUtf8().constData(), std::string()); d->client_->disco()->setVersion(d->agent_name_.toUtf8().constData(), std::string());
d->client_->disco()->addFeature(kXmlnsXrme); d->client_->disco()->addFeature(kXmlnsXrme);
d->media_player_extension_ = new MediaPlayerExtension;
d->remote_control_extension_ = new RemoteControlExtension;
d->client_->registerStanzaExtension(d->media_player_extension_); d->client_->registerStanzaExtension(d->media_player_extension_);
d->client_->registerStanzaExtension(d->remote_control_extension_); d->client_->registerStanzaExtension(d->remote_control_extension_);
@ -262,6 +264,8 @@ bool Connection::Connect() {
// Set presence // Set presence
d->client_->setPresence(gloox::Presence::Available, -128); d->client_->setPresence(gloox::Presence::Available, -128);
d->client_->setSASLMechanisms(gloox::SaslMechGoogleToken);
// Connect // Connect
if (!d->client_->connect(false)) { if (!d->client_->connect(false)) {
d->client_.reset(); d->client_.reset();

View File

@ -243,6 +243,8 @@ if(ENABLE_REMOTE AND HAVE_GNUTLS)
set(HAVE_REMOTE ON) set(HAVE_REMOTE ON)
add_subdirectory(3rdparty/gloox) add_subdirectory(3rdparty/gloox)
add_subdirectory(3rdparty/libxrme) add_subdirectory(3rdparty/libxrme)
include_directories(3rdparty)
include_directories(3rdparty/libxrme)
endif(ENABLE_REMOTE AND HAVE_GNUTLS) endif(ENABLE_REMOTE AND HAVE_GNUTLS)
set(HAVE_STATIC_SQLITE ${STATIC_SQLITE}) set(HAVE_STATIC_SQLITE ${STATIC_SQLITE})

View File

@ -52,7 +52,7 @@ void Remote::ReloadSettings() {
s.beginGroup(RemoteConfig::kSettingsGroup); s.beginGroup(RemoteConfig::kSettingsGroup);
QString username = s.value("username").toString(); QString username = s.value("username").toString();
QString password = s.value("password").toString(); QString password = s.value("token").toString();
QString agent_name = s.value("agent_name", RemoteConfig::DefaultAgentName()).toString(); QString agent_name = s.value("agent_name", RemoteConfig::DefaultAgentName()).toString();
// Have the settings changed? // Have the settings changed?

View File

@ -84,19 +84,27 @@ void RemoteConfig::ValidateFinished() {
QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender()); QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
Q_ASSERT(reply); Q_ASSERT(reply);
reply->deleteLater(); reply->deleteLater();
QString data = QString::fromUtf8(reply->readAll());
QVariant status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute); QVariant status_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
if (reply->error() != QNetworkReply::NoError || !status_code.isValid() || status_code.toInt() != 200) { if (reply->error() == QNetworkReply::NoError && status_code.isValid() && status_code.toInt() == 200) {
AuthenticationComplete(false); QStringList params = data.split('\n');
return; foreach (const QString& param, params) {
if (param.startsWith("Auth=")) {
AuthenticationComplete(param.split('=')[1]);
return;
}
}
} }
AuthenticationComplete(true); AuthenticationComplete(QString::null);
} }
void RemoteConfig::AuthenticationComplete(bool success) { void RemoteConfig::AuthenticationComplete(const QString& token) {
if (!waiting_for_auth_) if (!waiting_for_auth_)
return; // Wasn't us that was waiting for auth return; // Wasn't us that was waiting for auth
const bool success = !token.isNull();
ui_->busy->hide(); ui_->busy->hide();
waiting_for_auth_ = false; waiting_for_auth_ = false;
@ -106,6 +114,7 @@ void RemoteConfig::AuthenticationComplete(bool success) {
QSettings s; QSettings s;
s.beginGroup(kSettingsGroup); s.beginGroup(kSettingsGroup);
s.setValue("password", ui_->password->text()); s.setValue("password", ui_->password->text());
s.setValue("token", token);
ui_->password->clear(); ui_->password->clear();
} }

View File

@ -46,7 +46,7 @@ class RemoteConfig : public QWidget {
void ValidationComplete(bool success); void ValidationComplete(bool success);
private slots: private slots:
void AuthenticationComplete(bool success); void AuthenticationComplete(const QString& token);
void SignOut(); void SignOut();
void ValidateFinished(); void ValidateFinished();