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:
parent
061254ed12
commit
7687e2a429
@ -185,6 +185,12 @@ QLocalServer::SocketOptions QLocalServer::socketOptions() const
|
|||||||
return d->socketOptions;
|
return d->socketOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QBindable<QLocalServer::SocketOptions> QLocalServer::bindableSocketOptions()
|
||||||
|
{
|
||||||
|
Q_D(QLocalServer);
|
||||||
|
return &d->socketOptions;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\since 5.10
|
\since 5.10
|
||||||
Returns the native socket descriptor the server uses to listen
|
Returns the native socket descriptor the server uses to listen
|
||||||
|
@ -43,6 +43,8 @@
|
|||||||
#include <QtNetwork/qtnetworkglobal.h>
|
#include <QtNetwork/qtnetworkglobal.h>
|
||||||
#include <QtNetwork/qabstractsocket.h>
|
#include <QtNetwork/qabstractsocket.h>
|
||||||
|
|
||||||
|
#include <QtCore/qproperty.h>
|
||||||
|
|
||||||
QT_REQUIRE_CONFIG(localserver);
|
QT_REQUIRE_CONFIG(localserver);
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
@ -54,7 +56,7 @@ class Q_NETWORK_EXPORT QLocalServer : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_DECLARE_PRIVATE(QLocalServer)
|
Q_DECLARE_PRIVATE(QLocalServer)
|
||||||
Q_PROPERTY(SocketOptions socketOptions READ socketOptions WRITE setSocketOptions)
|
Q_PROPERTY(SocketOptions socketOptions READ socketOptions WRITE setSocketOptions BINDABLE bindableSocketOptions)
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void newConnection();
|
void newConnection();
|
||||||
@ -91,6 +93,7 @@ public:
|
|||||||
|
|
||||||
void setSocketOptions(SocketOptions options);
|
void setSocketOptions(SocketOptions options);
|
||||||
SocketOptions socketOptions() const;
|
SocketOptions socketOptions() const;
|
||||||
|
QBindable<SocketOptions> bindableSocketOptions();
|
||||||
|
|
||||||
qintptr socketDescriptor() const;
|
qintptr socketDescriptor() const;
|
||||||
|
|
||||||
|
@ -126,7 +126,8 @@ public:
|
|||||||
QQueue<QLocalSocket*> pendingConnections;
|
QQueue<QLocalSocket*> pendingConnections;
|
||||||
QString errorString;
|
QString errorString;
|
||||||
QAbstractSocket::SocketError error;
|
QAbstractSocket::SocketError error;
|
||||||
QLocalServer::SocketOptions socketOptions;
|
|
||||||
|
Q_OBJECT_BINDABLE_PROPERTY(QLocalServerPrivate, QLocalServer::SocketOptions, socketOptions)
|
||||||
};
|
};
|
||||||
|
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
@ -94,7 +94,8 @@ bool QLocalServerPrivate::listen(const QString &requestedServerName)
|
|||||||
QScopedPointer<QTemporaryDir> tempDir;
|
QScopedPointer<QTemporaryDir> tempDir;
|
||||||
|
|
||||||
// Check any of the flags
|
// Check any of the flags
|
||||||
if (socketOptions & QLocalServer::WorldAccessOption) {
|
const auto options = socketOptions.value();
|
||||||
|
if (options & QLocalServer::WorldAccessOption) {
|
||||||
QFileInfo serverNameFileInfo(fullServerName);
|
QFileInfo serverNameFileInfo(fullServerName);
|
||||||
tempDir.reset(new QTemporaryDir(serverNameFileInfo.absolutePath() + QLatin1Char('/')));
|
tempDir.reset(new QTemporaryDir(serverNameFileInfo.absolutePath() + QLatin1Char('/')));
|
||||||
if (!tempDir->isValid()) {
|
if (!tempDir->isValid()) {
|
||||||
@ -121,7 +122,7 @@ bool QLocalServerPrivate::listen(const QString &requestedServerName)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (socketOptions & QLocalServer::WorldAccessOption) {
|
if (options & QLocalServer::WorldAccessOption) {
|
||||||
if (sizeof(addr.sun_path) < (uint)encodedTempPath.size() + 1) {
|
if (sizeof(addr.sun_path) < (uint)encodedTempPath.size() + 1) {
|
||||||
setError(QLatin1String("QLocalServer::listen"));
|
setError(QLatin1String("QLocalServer::listen"));
|
||||||
closeServer();
|
closeServer();
|
||||||
@ -157,16 +158,16 @@ bool QLocalServerPrivate::listen(const QString &requestedServerName)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (socketOptions & QLocalServer::WorldAccessOption) {
|
if (options & QLocalServer::WorldAccessOption) {
|
||||||
mode_t mode = 000;
|
mode_t mode = 000;
|
||||||
|
|
||||||
if (socketOptions & QLocalServer::UserAccessOption)
|
if (options & QLocalServer::UserAccessOption)
|
||||||
mode |= S_IRWXU;
|
mode |= S_IRWXU;
|
||||||
|
|
||||||
if (socketOptions & QLocalServer::GroupAccessOption)
|
if (options & QLocalServer::GroupAccessOption)
|
||||||
mode |= S_IRWXG;
|
mode |= S_IRWXG;
|
||||||
|
|
||||||
if (socketOptions & QLocalServer::OtherAccessOption)
|
if (options & QLocalServer::OtherAccessOption)
|
||||||
mode |= S_IRWXO;
|
mode |= S_IRWXO;
|
||||||
|
|
||||||
if (::chmod(encodedTempPath.constData(), mode) == -1) {
|
if (::chmod(encodedTempPath.constData(), mode) == -1) {
|
||||||
|
@ -77,7 +77,7 @@ bool QLocalServerPrivate::addListener()
|
|||||||
QByteArray tokenGroupBuffer;
|
QByteArray tokenGroupBuffer;
|
||||||
|
|
||||||
// create security descriptor if access options were specified
|
// create security descriptor if access options were specified
|
||||||
if ((socketOptions & QLocalServer::WorldAccessOption)) {
|
if ((socketOptions.value() & QLocalServer::WorldAccessOption)) {
|
||||||
pSD.reset(new SECURITY_DESCRIPTOR);
|
pSD.reset(new SECURITY_DESCRIPTOR);
|
||||||
if (!InitializeSecurityDescriptor(pSD.data(), SECURITY_DESCRIPTOR_REVISION)) {
|
if (!InitializeSecurityDescriptor(pSD.data(), SECURITY_DESCRIPTOR_REVISION)) {
|
||||||
setError(QLatin1String("QLocalServerPrivate::addListener"));
|
setError(QLatin1String("QLocalServerPrivate::addListener"));
|
||||||
@ -143,21 +143,21 @@ bool QLocalServerPrivate::addListener()
|
|||||||
auto acl = reinterpret_cast<PACL>(aclBuffer.data());
|
auto acl = reinterpret_cast<PACL>(aclBuffer.data());
|
||||||
InitializeAcl(acl, aclSize, ACL_REVISION_DS);
|
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)) {
|
if (!AddAccessAllowedAce(acl, ACL_REVISION, FILE_ALL_ACCESS, pTokenUser->User.Sid)) {
|
||||||
setError(QLatin1String("QLocalServerPrivate::addListener"));
|
setError(QLatin1String("QLocalServerPrivate::addListener"));
|
||||||
FreeSid(worldSID);
|
FreeSid(worldSID);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (socketOptions & QLocalServer::GroupAccessOption) {
|
if (socketOptions.value() & QLocalServer::GroupAccessOption) {
|
||||||
if (!AddAccessAllowedAce(acl, ACL_REVISION, FILE_ALL_ACCESS, pTokenGroup->PrimaryGroup)) {
|
if (!AddAccessAllowedAce(acl, ACL_REVISION, FILE_ALL_ACCESS, pTokenGroup->PrimaryGroup)) {
|
||||||
setError(QLatin1String("QLocalServerPrivate::addListener"));
|
setError(QLatin1String("QLocalServerPrivate::addListener"));
|
||||||
FreeSid(worldSID);
|
FreeSid(worldSID);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (socketOptions & QLocalServer::OtherAccessOption) {
|
if (socketOptions.value() & QLocalServer::OtherAccessOption) {
|
||||||
if (!AddAccessAllowedAce(acl, ACL_REVISION, FILE_ALL_ACCESS, worldSID)) {
|
if (!AddAccessAllowedAce(acl, ACL_REVISION, FILE_ALL_ACCESS, worldSID)) {
|
||||||
setError(QLatin1String("QLocalServerPrivate::addListener"));
|
setError(QLatin1String("QLocalServerPrivate::addListener"));
|
||||||
FreeSid(worldSID);
|
FreeSid(worldSID);
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
#include <qtextstream.h>
|
#include <qtextstream.h>
|
||||||
#include <qdatastream.h>
|
#include <qdatastream.h>
|
||||||
#include <qelapsedtimer.h>
|
#include <qelapsedtimer.h>
|
||||||
|
#include <qproperty.h>
|
||||||
#include <QtNetwork/qlocalsocket.h>
|
#include <QtNetwork/qlocalsocket.h>
|
||||||
#include <QtNetwork/qlocalserver.h>
|
#include <QtNetwork/qlocalserver.h>
|
||||||
|
|
||||||
@ -126,6 +127,7 @@ private slots:
|
|||||||
void verifyListenWithDescriptor();
|
void verifyListenWithDescriptor();
|
||||||
void verifyListenWithDescriptor_data();
|
void verifyListenWithDescriptor_data();
|
||||||
|
|
||||||
|
void serverBindingsAndProperties();
|
||||||
};
|
};
|
||||||
|
|
||||||
tst_QLocalSocket::tst_QLocalSocket()
|
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)
|
QTEST_MAIN(tst_QLocalSocket)
|
||||||
#include "tst_qlocalsocket.moc"
|
#include "tst_qlocalsocket.moc"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user