Port QLocalServer to the new property system

Task-number: QTBUG-85520
Change-Id: Iee43a2e9e2d4847dad3b8be345d562af9aa3b690
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
This commit is contained in:
Timur Pocheptsov 2020-12-17 12:47:02 +01:00
parent 061254ed12
commit 7687e2a429
6 changed files with 39 additions and 12 deletions

View File

@ -185,6 +185,12 @@ QLocalServer::SocketOptions QLocalServer::socketOptions() const
return d->socketOptions;
}
QBindable<QLocalServer::SocketOptions> QLocalServer::bindableSocketOptions()
{
Q_D(QLocalServer);
return &d->socketOptions;
}
/*!
\since 5.10
Returns the native socket descriptor the server uses to listen

View File

@ -43,6 +43,8 @@
#include <QtNetwork/qtnetworkglobal.h>
#include <QtNetwork/qabstractsocket.h>
#include <QtCore/qproperty.h>
QT_REQUIRE_CONFIG(localserver);
QT_BEGIN_NAMESPACE
@ -54,7 +56,7 @@ class Q_NETWORK_EXPORT QLocalServer : public QObject
{
Q_OBJECT
Q_DECLARE_PRIVATE(QLocalServer)
Q_PROPERTY(SocketOptions socketOptions READ socketOptions WRITE setSocketOptions)
Q_PROPERTY(SocketOptions socketOptions READ socketOptions WRITE setSocketOptions BINDABLE bindableSocketOptions)
Q_SIGNALS:
void newConnection();
@ -91,6 +93,7 @@ public:
void setSocketOptions(SocketOptions options);
SocketOptions socketOptions() const;
QBindable<SocketOptions> bindableSocketOptions();
qintptr socketDescriptor() const;

View File

@ -126,7 +126,8 @@ public:
QQueue<QLocalSocket*> pendingConnections;
QString errorString;
QAbstractSocket::SocketError error;
QLocalServer::SocketOptions socketOptions;
Q_OBJECT_BINDABLE_PROPERTY(QLocalServerPrivate, QLocalServer::SocketOptions, socketOptions)
};
QT_END_NAMESPACE

View File

@ -94,7 +94,8 @@ bool QLocalServerPrivate::listen(const QString &requestedServerName)
QScopedPointer<QTemporaryDir> tempDir;
// Check any of the flags
if (socketOptions & QLocalServer::WorldAccessOption) {
const auto options = socketOptions.value();
if (options & QLocalServer::WorldAccessOption) {
QFileInfo serverNameFileInfo(fullServerName);
tempDir.reset(new QTemporaryDir(serverNameFileInfo.absolutePath() + QLatin1Char('/')));
if (!tempDir->isValid()) {
@ -121,7 +122,7 @@ bool QLocalServerPrivate::listen(const QString &requestedServerName)
return false;
}
if (socketOptions & QLocalServer::WorldAccessOption) {
if (options & QLocalServer::WorldAccessOption) {
if (sizeof(addr.sun_path) < (uint)encodedTempPath.size() + 1) {
setError(QLatin1String("QLocalServer::listen"));
closeServer();
@ -157,16 +158,16 @@ bool QLocalServerPrivate::listen(const QString &requestedServerName)
return false;
}
if (socketOptions & QLocalServer::WorldAccessOption) {
if (options & QLocalServer::WorldAccessOption) {
mode_t mode = 000;
if (socketOptions & QLocalServer::UserAccessOption)
if (options & QLocalServer::UserAccessOption)
mode |= S_IRWXU;
if (socketOptions & QLocalServer::GroupAccessOption)
if (options & QLocalServer::GroupAccessOption)
mode |= S_IRWXG;
if (socketOptions & QLocalServer::OtherAccessOption)
if (options & QLocalServer::OtherAccessOption)
mode |= S_IRWXO;
if (::chmod(encodedTempPath.constData(), mode) == -1) {

View File

@ -77,7 +77,7 @@ bool QLocalServerPrivate::addListener()
QByteArray tokenGroupBuffer;
// create security descriptor if access options were specified
if ((socketOptions & QLocalServer::WorldAccessOption)) {
if ((socketOptions.value() & QLocalServer::WorldAccessOption)) {
pSD.reset(new SECURITY_DESCRIPTOR);
if (!InitializeSecurityDescriptor(pSD.data(), SECURITY_DESCRIPTOR_REVISION)) {
setError(QLatin1String("QLocalServerPrivate::addListener"));
@ -143,21 +143,21 @@ bool QLocalServerPrivate::addListener()
auto acl = reinterpret_cast<PACL>(aclBuffer.data());
InitializeAcl(acl, aclSize, ACL_REVISION_DS);
if (socketOptions & QLocalServer::UserAccessOption) {
if (socketOptions.value() & QLocalServer::UserAccessOption) {
if (!AddAccessAllowedAce(acl, ACL_REVISION, FILE_ALL_ACCESS, pTokenUser->User.Sid)) {
setError(QLatin1String("QLocalServerPrivate::addListener"));
FreeSid(worldSID);
return false;
}
}
if (socketOptions & QLocalServer::GroupAccessOption) {
if (socketOptions.value() & QLocalServer::GroupAccessOption) {
if (!AddAccessAllowedAce(acl, ACL_REVISION, FILE_ALL_ACCESS, pTokenGroup->PrimaryGroup)) {
setError(QLatin1String("QLocalServerPrivate::addListener"));
FreeSid(worldSID);
return false;
}
}
if (socketOptions & QLocalServer::OtherAccessOption) {
if (socketOptions.value() & QLocalServer::OtherAccessOption) {
if (!AddAccessAllowedAce(acl, ACL_REVISION, FILE_ALL_ACCESS, worldSID)) {
setError(QLatin1String("QLocalServerPrivate::addListener"));
FreeSid(worldSID);

View File

@ -38,6 +38,7 @@
#include <qtextstream.h>
#include <qdatastream.h>
#include <qelapsedtimer.h>
#include <qproperty.h>
#include <QtNetwork/qlocalsocket.h>
#include <QtNetwork/qlocalserver.h>
@ -126,6 +127,7 @@ private slots:
void verifyListenWithDescriptor();
void verifyListenWithDescriptor_data();
void serverBindingsAndProperties();
};
tst_QLocalSocket::tst_QLocalSocket()
@ -1426,6 +1428,20 @@ void tst_QLocalSocket::verifyListenWithDescriptor_data()
}
void tst_QLocalSocket::serverBindingsAndProperties()
{
QLocalServer server;
QProperty<QLocalServer::SocketOptions> sockOpts;
server.bindableSocketOptions().setBinding(Qt::makePropertyBinding(sockOpts));
sockOpts = QLocalServer::GroupAccessOption | QLocalServer::UserAccessOption;
QCOMPARE(server.socketOptions(), sockOpts.value());
sockOpts.setBinding(server.bindableSocketOptions().makeBinding());
server.setSocketOptions(QLocalServer::OtherAccessOption);
QCOMPARE(sockOpts.value(), QLocalServer::OtherAccessOption);
}
QTEST_MAIN(tst_QLocalSocket)
#include "tst_qlocalsocket.moc"