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

View File

@ -515,6 +515,17 @@ namespace gloox
#endif
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:
break;
}

View File

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

View File

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

View File

@ -49,8 +49,8 @@ struct Connection::Private : public gloox::ConnectionListener,
media_player_(NULL),
remote_control_(NULL),
spontaneous_disconnect_(true),
media_player_extension_(new MediaPlayerExtension()),
remote_control_extension_(new RemoteControlExtension()) {}
media_player_extension_(NULL),
remote_control_extension_(NULL) {}
static const char* kDefaultServer;
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()->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->remote_control_extension_);
@ -262,6 +264,8 @@ bool Connection::Connect() {
// Set presence
d->client_->setPresence(gloox::Presence::Available, -128);
d->client_->setSASLMechanisms(gloox::SaslMechGoogleToken);
// Connect
if (!d->client_->connect(false)) {
d->client_.reset();

View File

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

View File

@ -52,7 +52,7 @@ void Remote::ReloadSettings() {
s.beginGroup(RemoteConfig::kSettingsGroup);
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();
// Have the settings changed?

View File

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

View File

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