mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-22 13:43:11 +02:00
Merge remote-tracking branch 'origin/master' into spotifyplaylists
This commit is contained in:
@@ -43,7 +43,7 @@ ACLRegistry::ACLRegistry( QObject* parent )
|
|||||||
: QObject( parent )
|
: QObject( parent )
|
||||||
{
|
{
|
||||||
s_instance = this;
|
s_instance = this;
|
||||||
//qRegisterMetaType< QHash< QString, QHash< QString, ACL > > >("ACLRegistry::ACLCacheHash");
|
qRegisterMetaType< ACLRegistry::ACL >("ACLRegistry::ACL");
|
||||||
|
|
||||||
m_cache = TomahawkSettings::instance()->aclEntries();
|
m_cache = TomahawkSettings::instance()->aclEntries();
|
||||||
}
|
}
|
||||||
@@ -54,11 +54,14 @@ ACLRegistry::~ACLRegistry()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ACLRegistry::ACL
|
void
|
||||||
ACLRegistry::isAuthorizedPeer( const QString& dbid, ACLRegistry::ACL globalType, const QString &username )
|
ACLRegistry::isAuthorizedPeer( const QString& dbid, ACLRegistry::ACL globalType, const QString &username )
|
||||||
{
|
{
|
||||||
if ( QThread::currentThread() != TOMAHAWK_APPLICATION::instance()->thread() )
|
if ( QThread::currentThread() != TOMAHAWK_APPLICATION::instance()->thread() )
|
||||||
return globalType;
|
{
|
||||||
|
emit aclResult( dbid, globalType );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
qDebug() << "Current cache keys =" << m_cache.keys();
|
qDebug() << "Current cache keys =" << m_cache.keys();
|
||||||
if( m_cache.contains( dbid ) )
|
if( m_cache.contains( dbid ) )
|
||||||
@@ -67,17 +70,22 @@ ACLRegistry::isAuthorizedPeer( const QString& dbid, ACLRegistry::ACL globalType,
|
|||||||
if( peerHash.contains( "global" ) )
|
if( peerHash.contains( "global" ) )
|
||||||
{
|
{
|
||||||
registerAlias( dbid, username );
|
registerAlias( dbid, username );
|
||||||
return ACLRegistry::ACL( peerHash[ "global" ].toInt() );
|
emit aclResult( dbid, ACLRegistry::ACL( peerHash[ "global" ].toInt() ) );
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( globalType == ACLRegistry::NotFound )
|
if ( globalType == ACLRegistry::NotFound )
|
||||||
return globalType;
|
{
|
||||||
|
emit aclResult( dbid, globalType );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
peerHash[ "global" ] = int( globalType );
|
peerHash[ "global" ] = int( globalType );
|
||||||
m_cache[ dbid ] = peerHash;
|
m_cache[ dbid ] = peerHash;
|
||||||
save();
|
save();
|
||||||
registerAlias( dbid, username );
|
registerAlias( dbid, username );
|
||||||
return globalType;
|
emit aclResult( dbid, globalType );
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ACLRegistry::ACL acl = globalType;
|
ACLRegistry::ACL acl = globalType;
|
||||||
@@ -88,14 +96,18 @@ ACLRegistry::isAuthorizedPeer( const QString& dbid, ACLRegistry::ACL globalType,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ( acl == ACLRegistry::NotFound || acl == ACLRegistry::AllowOnce || acl == ACLRegistry::DenyOnce )
|
if ( acl == ACLRegistry::NotFound || acl == ACLRegistry::AllowOnce || acl == ACLRegistry::DenyOnce )
|
||||||
return acl;
|
{
|
||||||
|
emit aclResult( dbid, acl );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QVariantHash peerHash;
|
QVariantHash peerHash;
|
||||||
peerHash[ "global" ] = int( acl );
|
peerHash[ "global" ] = int( acl );
|
||||||
m_cache[ dbid ] = peerHash;
|
m_cache[ dbid ] = peerHash;
|
||||||
save();
|
save();
|
||||||
registerAlias( dbid, username );
|
registerAlias( dbid, username );
|
||||||
return acl;
|
emit aclResult( dbid, acl );
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -49,16 +49,6 @@ public:
|
|||||||
ACLRegistry( QObject *parent = 0 );
|
ACLRegistry( QObject *parent = 0 );
|
||||||
~ACLRegistry();
|
~ACLRegistry();
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Checks if peer is authorized; optionally, can authorize peer with given type if not found
|
|
||||||
*
|
|
||||||
* @param dbid DBID of peer
|
|
||||||
* @param globalType Global ACL to store if peer not found; if ACLRegistry::NotFound, does not store the peer Defaults to ACLRegistry::NotFound.
|
|
||||||
* @param username If not empty, will store the given username along with the new ACL value. Defaults to QString().
|
|
||||||
* @return ACLRegistry::ACL
|
|
||||||
**/
|
|
||||||
ACLRegistry::ACL isAuthorizedPeer( const QString &dbid, ACLRegistry::ACL globalType = ACLRegistry::NotFound, const QString &username = QString() );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Registers the global ACL value for this peer
|
* @brief Registers the global ACL value for this peer
|
||||||
*
|
*
|
||||||
@@ -87,6 +77,21 @@ public:
|
|||||||
**/
|
**/
|
||||||
void registerAlias( const QString &dbid, const QString &username );
|
void registerAlias( const QString &dbid, const QString &username );
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void aclResult( QString nodeid, ACLRegistry::ACL peerStatus );
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
/**
|
||||||
|
* @brief Checks if peer is authorized; optionally, can authorize peer with given type if not found
|
||||||
|
*
|
||||||
|
* @param dbid DBID of peer
|
||||||
|
* @param globalType Global ACL to store if peer not found; if ACLRegistry::NotFound, does not store the peer Defaults to ACLRegistry::NotFound.
|
||||||
|
* @param username If not empty, will store the given username along with the new ACL value. Defaults to QString().
|
||||||
|
* @return ACLRegistry::ACL
|
||||||
|
**/
|
||||||
|
void isAuthorizedPeer( const QString &dbid, ACLRegistry::ACL globalType = ACLRegistry::NotFound, const QString &username = QString() );
|
||||||
|
|
||||||
|
|
||||||
#ifndef ENABLE_HEADLESS
|
#ifndef ENABLE_HEADLESS
|
||||||
ACLRegistry::ACL getUserDecision( const QString &username );
|
ACLRegistry::ACL getUserDecision( const QString &username );
|
||||||
#endif
|
#endif
|
||||||
|
@@ -184,7 +184,41 @@ Connection::start( QTcpSocket* sock )
|
|||||||
m_name = QString( "peer[%1]" ).arg( m_sock->peerAddress().toString() );
|
m_name = QString( "peer[%1]" ).arg( m_sock->peerAddress().toString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
QTimer::singleShot( 0, this, SLOT( doSetup() ) );
|
QTimer::singleShot( 0, this, SLOT( checkACL() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Connection::checkACL()
|
||||||
|
{
|
||||||
|
if ( !property( "nodeid" ).isValid() )
|
||||||
|
{
|
||||||
|
QTimer::singleShot( 0, this, SLOT( doSetup() ) );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString nodeid = property( "nodeid" ).toString();
|
||||||
|
tDebug( LOGVERBOSE ) << "Checking ACL for" << name();
|
||||||
|
connect( ACLRegistry::instance(), SIGNAL( aclResult( QString, ACLRegistry::ACL ) ), this, SLOT( checkACLResult( QString, ACLRegistry::ACL ) ), Qt::QueuedConnection );
|
||||||
|
QMetaObject::invokeMethod( ACLRegistry::instance(), "isAuthorizedPeer", Qt::QueuedConnection, Q_ARG( QString, nodeid ), Q_ARG( ACLRegistry::ACL, ACLRegistry::NotFound ), Q_ARG( QString, name() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
Connection::checkACLResult( const QString &nodeid, ACLRegistry::ACL peerStatus )
|
||||||
|
{
|
||||||
|
if ( nodeid != property( "nodeid" ).toString() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
disconnect( ACLRegistry::instance(), SIGNAL( aclResult( QString, ACLRegistry::ACL ) ) );
|
||||||
|
tDebug( LOGVERBOSE ) << "ACL status is" << peerStatus;
|
||||||
|
if ( peerStatus == ACLRegistry::Allow || peerStatus == ACLRegistry::AllowOnce )
|
||||||
|
{
|
||||||
|
QTimer::singleShot( 0, this, SLOT( doSetup() ) );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -38,6 +38,7 @@
|
|||||||
|
|
||||||
#include "msg.h"
|
#include "msg.h"
|
||||||
#include "msgprocessor.h"
|
#include "msgprocessor.h"
|
||||||
|
#include "libtomahawk/aclregistry.h"
|
||||||
|
|
||||||
#include "dllmacro.h"
|
#include "dllmacro.h"
|
||||||
|
|
||||||
@@ -118,6 +119,8 @@ private slots:
|
|||||||
void socketDisconnectedError( QAbstractSocket::SocketError );
|
void socketDisconnectedError( QAbstractSocket::SocketError );
|
||||||
void readyRead();
|
void readyRead();
|
||||||
void doSetup();
|
void doSetup();
|
||||||
|
void checkACL();
|
||||||
|
void checkACLResult( const QString &id, ACLRegistry::ACL peerStatus );
|
||||||
void authCheckTimeout();
|
void authCheckTimeout();
|
||||||
void bytesWritten( qint64 );
|
void bytesWritten( qint64 );
|
||||||
void calcStats();
|
void calcStats();
|
||||||
|
@@ -39,7 +39,6 @@
|
|||||||
|
|
||||||
#include "portfwdthread.h"
|
#include "portfwdthread.h"
|
||||||
#include "tomahawksettings.h"
|
#include "tomahawksettings.h"
|
||||||
#include "libtomahawk/aclregistry.h"
|
|
||||||
#include "utils/tomahawkutils.h"
|
#include "utils/tomahawkutils.h"
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
|
|
||||||
@@ -671,12 +670,9 @@ Servent::claimOffer( ControlConnection* cc, const QString &nodeid, const QString
|
|||||||
|
|
||||||
if( !nodeid.isEmpty() )
|
if( !nodeid.isEmpty() )
|
||||||
{
|
{
|
||||||
|
// Used by the connection for the ACL check
|
||||||
// If there isn't a nodeid it's not the first connection and will already have been stopped
|
// If there isn't a nodeid it's not the first connection and will already have been stopped
|
||||||
if( !checkACL( conn, nodeid ) )
|
conn.data()->setProperty( "nodeid", nodeid );
|
||||||
{
|
|
||||||
tLog() << "Connection not allowed due to ACL";
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( conn.data()->onceOnly() )
|
if( conn.data()->onceOnly() )
|
||||||
@@ -704,22 +700,6 @@ Servent::claimOffer( ControlConnection* cc, const QString &nodeid, const QString
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
Servent::checkACL( const QWeakPointer< Connection > conn, const QString &nodeid ) const
|
|
||||||
{
|
|
||||||
if ( conn.isNull() )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
tDebug( LOGVERBOSE ) << "Checking ACL for" << conn.data()->name();
|
|
||||||
ACLRegistry::ACL peerStatus = ACLRegistry::instance()->isAuthorizedPeer( nodeid, ACLRegistry::NotFound, conn.data()->name() );
|
|
||||||
tDebug( LOGVERBOSE ) << "ACL status is" << peerStatus;
|
|
||||||
if ( peerStatus == ACLRegistry::Allow || peerStatus == ACLRegistry::AllowOnce )
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QSharedPointer<QIODevice>
|
QSharedPointer<QIODevice>
|
||||||
Servent::remoteIODeviceFactory( const result_ptr& result )
|
Servent::remoteIODeviceFactory( const result_ptr& result )
|
||||||
{
|
{
|
||||||
|
@@ -155,7 +155,6 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
bool isValidExternalIP( const QHostAddress& addr ) const;
|
bool isValidExternalIP( const QHostAddress& addr ) const;
|
||||||
void handoverSocket( Connection* conn, QTcpSocketExtra* sock );
|
void handoverSocket( Connection* conn, QTcpSocketExtra* sock );
|
||||||
bool checkACL( const QWeakPointer< Connection > conn, const QString &nodeid ) const;
|
|
||||||
void printCurrentTransfers();
|
void printCurrentTransfers();
|
||||||
|
|
||||||
QJson::Parser parser;
|
QJson::Parser parser;
|
||||||
|
@@ -252,8 +252,11 @@ PlaylistModel::trackResolved( bool )
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_waitingForResolved.removeAll( q );
|
if ( m_waitingForResolved.contains( q ) )
|
||||||
disconnect( q, SIGNAL( resolvingFinished( bool ) ), this, SLOT( trackResolved( bool ) ) );
|
{
|
||||||
|
m_waitingForResolved.removeAll( q );
|
||||||
|
disconnect( q, SIGNAL( resolvingFinished( bool ) ), this, SLOT( trackResolved( bool ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
if ( m_waitingForResolved.isEmpty() )
|
if ( m_waitingForResolved.isEmpty() )
|
||||||
{
|
{
|
||||||
@@ -451,6 +454,7 @@ PlaylistModel::remove( const QModelIndex& index, bool moreToCome )
|
|||||||
|
|
||||||
if ( item && m_waitingForResolved.contains( item->query().data() ) )
|
if ( item && m_waitingForResolved.contains( item->query().data() ) )
|
||||||
{
|
{
|
||||||
|
disconnect( item->query().data(), SIGNAL( resolvingFinished( bool ) ), this, SLOT( trackResolved( bool ) ) );
|
||||||
m_waitingForResolved.removeAll( item->query().data() );
|
m_waitingForResolved.removeAll( item->query().data() );
|
||||||
if ( m_waitingForResolved.isEmpty() )
|
if ( m_waitingForResolved.isEmpty() )
|
||||||
emit loadingFinished();
|
emit loadingFinished();
|
||||||
|
Reference in New Issue
Block a user