diff --git a/src/accounts/xmpp/sip/XmppSip.cpp b/src/accounts/xmpp/sip/XmppSip.cpp index 16dee9d43..e97e7e642 100644 --- a/src/accounts/xmpp/sip/XmppSip.cpp +++ b/src/accounts/xmpp/sip/XmppSip.cpp @@ -879,12 +879,22 @@ XmppSipPlugin::onNewIq( const Jreen::IQ& iq ) Jreen::SoftwareVersion::Ptr softwareVersion = iq.payload(); 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() ) diff --git a/src/accounts/xmpp/sip/XmppSip.h b/src/accounts/xmpp/sip/XmppSip.h index b40456a94..8f03d9dbd 100644 --- a/src/accounts/xmpp/sip/XmppSip.h +++ b/src/accounts/xmpp/sip/XmppSip.h @@ -153,7 +153,10 @@ private: enum IqContext { NoContext, RequestDisco, RequestedDisco, SipMessageSent, RequestedVCard, RequestVersion, RequestedVersion }; AvatarManager* m_avatarManager; Jreen::PubSub::Manager* m_pubSubManager; - QMap peersWaitingForSip; + QMap< QString, Tomahawk::peerinfo_ptr > peersWaitingForSip; + QMap< QString, Tomahawk::peerinfo_ptr > peersWaitingForVersionString; + QMap< QString, QList< SipInfo > > sipinfosQueue; + QMutex peerQueueMutex; }; #endif diff --git a/src/libtomahawk/network/ConnectionManager.cpp b/src/libtomahawk/network/ConnectionManager.cpp index d8cce351b..407ee4d5e 100644 --- a/src/libtomahawk/network/ConnectionManager.cpp +++ b/src/libtomahawk/network/ConnectionManager.cpp @@ -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() ) { diff --git a/src/libtomahawk/network/Servent.cpp b/src/libtomahawk/network/Servent.cpp index 274428988..3d65ecacd 100644 --- a/src/libtomahawk/network/Servent.cpp +++ b/src/libtomahawk/network/Servent.cpp @@ -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() << info );