mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-05 13:47:26 +02:00
Make access to Connection->nodeid thread-safe
This commit is contained in:
@@ -311,7 +311,10 @@ Connection::start( QTcpSocket* sock )
|
|||||||
void
|
void
|
||||||
Connection::checkACL()
|
Connection::checkACL()
|
||||||
{
|
{
|
||||||
if ( d_func()->nodeid.isEmpty() )
|
Q_D( Connection );
|
||||||
|
QReadLocker nodeidLocker( &d->nodeidLock );
|
||||||
|
|
||||||
|
if ( d->nodeid.isEmpty() )
|
||||||
{
|
{
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Not checking ACL, nodeid is empty";
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Not checking ACL, nodeid is empty";
|
||||||
QTimer::singleShot( 0, this, SLOT( doSetup() ) );
|
QTimer::singleShot( 0, this, SLOT( doSetup() ) );
|
||||||
@@ -328,7 +331,7 @@ Connection::checkACL()
|
|||||||
connect( ACLRegistry::instance(), SIGNAL( aclResult( QString, QString, Tomahawk::ACLStatus::Type ) ),
|
connect( ACLRegistry::instance(), SIGNAL( aclResult( QString, QString, Tomahawk::ACLStatus::Type ) ),
|
||||||
this, SLOT( checkACLResult( QString, QString, Tomahawk::ACLStatus::Type ) ),
|
this, SLOT( checkACLResult( QString, QString, Tomahawk::ACLStatus::Type ) ),
|
||||||
Qt::QueuedConnection );
|
Qt::QueuedConnection );
|
||||||
QMetaObject::invokeMethod( ACLRegistry::instance(), "isAuthorizedUser", Qt::QueuedConnection, Q_ARG( QString, d_func()->nodeid ), Q_ARG( QString, bareName() ), Q_ARG( Tomahawk::ACLStatus::Type, Tomahawk::ACLStatus::NotFound ) );
|
QMetaObject::invokeMethod( ACLRegistry::instance(), "isAuthorizedUser", Qt::QueuedConnection, Q_ARG( QString, d->nodeid ), Q_ARG( QString, bareName() ), Q_ARG( Tomahawk::ACLStatus::Type, Tomahawk::ACLStatus::NotFound ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -341,9 +344,12 @@ Connection::bareName() const
|
|||||||
void
|
void
|
||||||
Connection::checkACLResult( const QString &nodeid, const QString &username, Tomahawk::ACLStatus::Type peerStatus )
|
Connection::checkACLResult( const QString &nodeid, const QString &username, Tomahawk::ACLStatus::Type peerStatus )
|
||||||
{
|
{
|
||||||
if ( nodeid != d_func()->nodeid )
|
Q_D( Connection );
|
||||||
|
QReadLocker nodeidLocker( &d->nodeidLock );
|
||||||
|
|
||||||
|
if ( nodeid != d->nodeid )
|
||||||
{
|
{
|
||||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << QString( "nodeid (%1) not ours (%2) for user %3" ).arg( nodeid ).arg( d_func()->nodeid ).arg( username );
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << QString( "nodeid (%1) not ours (%2) for user %3" ).arg( nodeid ).arg( d->nodeid ).arg( username );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ( username != bareName() )
|
if ( username != bareName() )
|
||||||
@@ -494,13 +500,17 @@ Connection::setId( const QString& id )
|
|||||||
QString
|
QString
|
||||||
Connection::nodeId() const
|
Connection::nodeId() const
|
||||||
{
|
{
|
||||||
return d_func()->nodeid;
|
Q_D( const Connection );
|
||||||
|
QReadLocker locker( &d->nodeidLock );
|
||||||
|
return d->nodeid;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Connection::setNodeId( const QString& nodeid )
|
Connection::setNodeId( const QString& nodeid )
|
||||||
{
|
{
|
||||||
d_func()->nodeid = nodeid;
|
Q_D( Connection );
|
||||||
|
QWriteLocker locker( &d->nodeidLock );
|
||||||
|
d->nodeid = nodeid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include "MsgProcessor.h"
|
#include "MsgProcessor.h"
|
||||||
|
|
||||||
|
#include <QReadWriteLock>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
@@ -67,6 +68,7 @@ private:
|
|||||||
QString id;
|
QString id;
|
||||||
QString name;
|
QString name;
|
||||||
QString nodeid;
|
QString nodeid;
|
||||||
|
mutable QReadWriteLock nodeidLock;
|
||||||
msg_ptr msg;
|
msg_ptr msg;
|
||||||
msg_ptr firstmsg;
|
msg_ptr firstmsg;
|
||||||
int peerport;
|
int peerport;
|
||||||
|
Reference in New Issue
Block a user