1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 07:49:42 +01:00

Wait for versionString in Xmpp until telling Servent SipInfos

This commit is contained in:
Uwe L. Korn 2013-05-23 18:36:06 +02:00
parent 9b7dd0110b
commit 39e630876e
4 changed files with 39 additions and 5 deletions

View File

@ -879,12 +879,22 @@ XmppSipPlugin::onNewIq( const Jreen::IQ& iq )
Jreen::SoftwareVersion::Ptr softwareVersion = iq.payload<Jreen::SoftwareVersion>();
if ( softwareVersion )
{
QMutexLocker locker( &peerQueueMutex );
QString versionString = QString( "%1 %2 %3" ).arg( softwareVersion->name(), softwareVersion->os(), softwareVersion->version() );
qDebug() << Q_FUNC_INFO << "Received software version for" << iq.from().full() << ":" << versionString;
Tomahawk::peerinfo_ptr peerInfo = PeerInfo::get( this, iq.from().full() );
if ( !peerInfo.isNull() )
{
peerInfo->setVersionString( versionString );
if ( sipinfosQueue.contains( iq.from().full() ) )
{
peerInfo->setSipInfos( sipinfosQueue.value( iq.from().full() ) );
sipinfosQueue.remove( iq.from().full() );
}
if ( peersWaitingForVersionString.contains( iq.from().full() ) )
{
peersWaitingForVersionString.remove( iq.from().full() );
}
}
}
}
@ -905,6 +915,7 @@ XmppSipPlugin::onNewIq( const Jreen::IQ& iq )
TomahawkXmppMessage::Ptr sipMessage = iq.payload< TomahawkXmppMessage >();
if ( sipMessage )
{
QMutexLocker locker( &peerQueueMutex );
iq.accept();
tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Received Sip Information from:" << iq.from().full();
@ -921,7 +932,15 @@ XmppSipPlugin::onNewIq( const Jreen::IQ& iq )
tDebug() << Q_FUNC_INFO << "no valid peerInfo for" << iq.from().full();
return;
}
peerInfo->setSipInfos( sipMessage->sipInfos() );
if ( peerInfo->versionString().isEmpty() )
{
// If we do not have a version string, this peerInfo is still queued. So we queue its SipInfo until we have a valid version string.
sipinfosQueue[iq.from().full()] = sipMessage->sipInfos();
}
else
{
peerInfo->setSipInfos( sipMessage->sipInfos() );
}
// If we stored a reference for this peer in our sip-waiting-queue, remove it.
if ( peersWaitingForSip.contains( iq.from().full() ) )
{
@ -968,12 +987,21 @@ XmppSipPlugin::handlePeerStatus( const Jreen::JID& jid, Jreen::Presence::Type pr
Tomahawk::peerinfo_ptr peerInfo = PeerInfo::get( this, fulljid );
if ( !peerInfo.isNull() )
{
QMutexLocker locker( &peerQueueMutex );
peerInfo->setStatus( PeerInfo::Offline );
// If we stored a reference for this peer in our sip-waiting-queue, remove it.
if ( peersWaitingForSip.contains( fulljid ) )
{
peersWaitingForSip.remove( fulljid );
}
if ( peersWaitingForVersionString.contains( fulljid ) )
{
peersWaitingForVersionString.remove( fulljid );
}
if ( sipinfosQueue.contains( fulljid ) )
{
sipinfosQueue.remove( fulljid );
}
}
return;
@ -985,6 +1013,7 @@ XmppSipPlugin::handlePeerStatus( const Jreen::JID& jid, Jreen::Presence::Type pr
{
qDebug() << Q_FUNC_INFO << "* Peer goes online:" << fulljid;
QMutexLocker locker( &peerQueueMutex );
m_peers[ jid ] = presenceType;
Tomahawk::peerinfo_ptr peerInfo = PeerInfo::get( this, fulljid, PeerInfo::AutoCreate );
@ -992,6 +1021,7 @@ XmppSipPlugin::handlePeerStatus( const Jreen::JID& jid, Jreen::Presence::Type pr
peerInfo->setStatus( PeerInfo::Online );
peerInfo->setFriendlyName( m_jidsNames.value( jid.bare() ) );
peersWaitingForSip[fulljid] = peerInfo;
peersWaitingForVersionString[fulljid] = peerInfo;
#ifndef ENABLE_HEADLESS
if ( !m_avatarManager->avatar( jid.bare() ).isNull() )

View File

@ -153,7 +153,10 @@ private:
enum IqContext { NoContext, RequestDisco, RequestedDisco, SipMessageSent, RequestedVCard, RequestVersion, RequestedVersion };
AvatarManager* m_avatarManager;
Jreen::PubSub::Manager* m_pubSubManager;
QMap<QString, Tomahawk::peerinfo_ptr> peersWaitingForSip;
QMap< QString, Tomahawk::peerinfo_ptr > peersWaitingForSip;
QMap< QString, Tomahawk::peerinfo_ptr > peersWaitingForVersionString;
QMap< QString, QList< SipInfo > > sipinfosQueue;
QMutex peerQueueMutex;
};
#endif

View File

@ -46,10 +46,11 @@ ConnectionManager::handleSipInfoPrivate( const Tomahawk::peerinfo_ptr &peerInfo
{
m_mutex.lock();
// Respect different behaviour before 0.7.99
if ( !peerInfo->versionString().isEmpty() && TomahawkUtils::compareVersionStrings( peerInfo->versionString(), "Tomahawk Player EmptyOS 0.7.99" ) < 0)
peerInfoDebug( peerInfo ) << Q_FUNC_INFO << "Trying to connect to client with version " << peerInfo->versionString().split(' ').last() << TomahawkUtils::compareVersionStrings( peerInfo->versionString().split(' ').last(), "0.7.99" );
if ( !peerInfo->versionString().isEmpty() && TomahawkUtils::compareVersionStrings( peerInfo->versionString().split(' ').last(), "0.7.99" ) < 0)
{
peerInfoDebug( peerInfo ) << Q_FUNC_INFO << "Using old-style (<0.7.99) connection order.";
SipInfo we = Servent::getSipInfoForOldVersions( Servent::instance()->getLocalSipInfos( QString(), QString() ) );
SipInfo we = Servent::getSipInfoForOldVersions( Servent::instance()->getLocalSipInfos( QString( "default" ), QString( "default" ) ) );
SipInfo they = peerInfo->sipInfos().first();
if ( they.isVisible() )
{

View File

@ -485,7 +485,7 @@ Servent::registerPeer( const Tomahawk::peerinfo_ptr& peerInfo )
// The offer should be removed after some time or we will build up a heap of unused PeerInfos
registerLazyOffer( key, peerInfo, nodeid, sipInfos.length() * 1.5 * CONNECT_TIMEOUT );
// SipInfos were single-value before 0.7.999
if ( !peerInfo->versionString().isEmpty() && TomahawkUtils::compareVersionStrings( peerInfo->versionString(), "Tomahawk Player EmptyOS 0.7.99" ) < 0)
if ( !peerInfo->versionString().isEmpty() && TomahawkUtils::compareVersionStrings( peerInfo->versionString().split(' ').last(), "0.7.99" ) < 0)
{
SipInfo info = getSipInfoForOldVersions( sipInfos );
peerInfo->sendLocalSipInfos( QList<SipInfo>() << info );