Fix formatting and const-correctness.
storage.cpp
# needed for automoc
storage.cpp
# needed for automoc
if (Quassel::isOptionSet("oidentd")) {
_oidentdConfigGenerator = new OidentdConfigGenerator(this);
}
if (Quassel::isOptionSet("oidentd")) {
_oidentdConfigGenerator = new OidentdConfigGenerator(this);
}
if (Quassel::isOptionSet("ident-daemon")) {
_identServer = new IdentServer(_strictIdentEnabled, this);
if (Quassel::isOptionSet("ident-daemon")) {
_identServer = new IdentServer(_strictIdentEnabled, this);
if (!success)
quError() << qPrintable(tr("Could not open any network interfaces to listen on!"));
if (!success)
quError() << qPrintable(tr("Could not open any network interfaces to listen on!"));
- if (_identServer != nullptr) _identServer->startListening();
+ if (_identServer) {
+ _identServer->startListening();
+ }
void Core::stopListening(const QString &reason)
{
void Core::stopListening(const QString &reason)
{
- if (_identServer != nullptr) _identServer->stopListening(reason);
+ if (_identServer) {
+ _identServer->stopListening(reason);
+ }
bool wasListening = false;
if (_server.isListening()) {
bool wasListening = false;
if (_server.isListening()) {
#include "authenticator.h"
#include "bufferinfo.h"
#include "deferredptr.h"
#include "authenticator.h"
#include "bufferinfo.h"
#include "deferredptr.h"
+#include "identserver.h"
#include "message.h"
#include "oidentdconfiggenerator.h"
#include "sessionthread.h"
#include "storage.h"
#include "types.h"
#include "message.h"
#include "oidentdconfiggenerator.h"
#include "sessionthread.h"
#include "storage.h"
#include "types.h"
-#include "identserver.h"
class CoreAuthHandler;
class CoreSession;
class CoreAuthHandler;
class CoreSession;
QDateTime _startTime;
IdentServer *_identServer {nullptr};
QDateTime _startTime;
IdentServer *_identServer {nullptr};
bool _initialized{false};
bool _configured{false};
bool _initialized{false};
bool _configured{false};
#else
QTcpSocket socket;
#endif
#else
QTcpSocket socket;
#endif
CoreUserInputHandler *_userInputHandler;
CoreUserInputHandler *_userInputHandler;
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
-#include <logger.h>
-#include <set>
#include "corenetwork.h"
#include "identserver.h"
#include "corenetwork.h"
#include "identserver.h"
-IdentServer::IdentServer(bool strict, QObject *parent) : QObject(parent), _strict(strict), _socketId(0), _requestId(0) {
+IdentServer::IdentServer(bool strict, QObject *parent)
+ : QObject(parent)
+ , _strict(strict)
+{
connect(&_server, SIGNAL(newConnection()), this, SLOT(incomingConnection()));
connect(&_v6server, SIGNAL(newConnection()), this, SLOT(incomingConnection()));
}
connect(&_server, SIGNAL(newConnection()), this, SLOT(incomingConnection()));
connect(&_v6server, SIGNAL(newConnection()), this, SLOT(incomingConnection()));
}
-IdentServer::~IdentServer() = default;
-bool IdentServer::startListening() {
+bool IdentServer::startListening()
+{
uint16_t port = Quassel::optionValue("ident-port").toUShort();
bool success = false;
uint16_t port = Quassel::optionValue("ident-port").toUShort();
bool success = false;
}
if (_server.listen(QHostAddress("127.0.0.1"), port)) {
}
if (_server.listen(QHostAddress("127.0.0.1"), port)) {
quInfo() << qPrintable(
tr("Listening for identd clients on IPv4 %1 port %2")
.arg("127.0.0.1")
.arg(_server.serverPort())
);
quInfo() << qPrintable(
tr("Listening for identd clients on IPv4 %1 port %2")
.arg("127.0.0.1")
.arg(_server.serverPort())
);
- quError() << qPrintable(
- tr("Identd could not open any network interfaces to listen on! No identd functionality will be available"));
+ quError() << qPrintable(tr("Identd could not open any network interfaces to listen on! No identd functionality will be available"));
-void IdentServer::stopListening(const QString &msg) {
+
+void IdentServer::stopListening(const QString &msg)
+{
bool wasListening = false;
bool wasListening = false;
if (_server.isListening()) {
wasListening = true;
_server.close();
if (_server.isListening()) {
wasListening = true;
_server.close();
wasListening = true;
_v6server.close();
}
wasListening = true;
_v6server.close();
}
if (wasListening) {
if (msg.isEmpty())
quInfo() << "No longer listening for identd clients.";
if (wasListening) {
if (msg.isEmpty())
quInfo() << "No longer listening for identd clients.";
-void IdentServer::incomingConnection() {
- auto *server = qobject_cast<QTcpServer *>(sender());
+
+void IdentServer::incomingConnection()
+{
+ auto server = qobject_cast<QTcpServer *>(sender());
Q_ASSERT(server);
while (server->hasPendingConnections()) {
QTcpSocket *socket = server->nextPendingConnection();
Q_ASSERT(server);
while (server->hasPendingConnections()) {
QTcpSocket *socket = server->nextPendingConnection();
-void IdentServer::respond() {
+
+void IdentServer::respond()
+{
QTcpSocket *socket = qobject_cast<QTcpSocket *>(sender());
Q_ASSERT(socket);
QTcpSocket *socket = qobject_cast<QTcpSocket *>(sender());
Q_ASSERT(socket);
Request request{socket, localPort, query, transactionId, _requestId++};
if (!success) {
request.respondError("INVALID-PORT");
Request request{socket, localPort, query, transactionId, _requestId++};
if (!success) {
request.respondError("INVALID-PORT");
- } else if (responseAvailable(request)) {
+ }
+ else if (responseAvailable(request)) {
- } else if (lowestSocketId() < transactionId) {
+ }
+ else if (lowestSocketId() < transactionId) {
_requestQueue.emplace_back(request);
_requestQueue.emplace_back(request);
request.respondError("NO-USER");
}
}
request.respondError("NO-USER");
}
}
-void Request::respondSuccess(const QString &user) {
+
+void Request::respondSuccess(const QString &user)
+{
QString data = query + " : USERID : Quassel : " + user + "\r\n";
socket->write(data.toUtf8());
QString data = query + " : USERID : Quassel : " + user + "\r\n";
socket->write(data.toUtf8());
-void Request::respondError(const QString &error) {
+
+void Request::respondError(const QString &error)
+{
QString data = query + " : ERROR : " + error + "\r\n";
socket->write(data.toUtf8());
QString data = query + " : ERROR : " + error + "\r\n";
socket->write(data.toUtf8());
-bool IdentServer::responseAvailable(Request request) {
+
+bool IdentServer::responseAvailable(Request request) const
+{
if (!_connections.contains(request.localPort)) {
return false;
}
if (!_connections.contains(request.localPort)) {
return false;
}
- QString user = _connections[request.localPort];
- request.respondSuccess(user);
+ request.respondSuccess(_connections[request.localPort]);
-bool IdentServer::addSocket(const CoreIdentity *identity, const QHostAddress &localAddress, quint16 localPort,
- const QHostAddress &peerAddress, quint16 peerPort, qint64 socketId) {
+
+void IdentServer::addSocket(const CoreIdentity *identity, const QHostAddress &localAddress, quint16 localPort,
+ const QHostAddress &peerAddress, quint16 peerPort, qint64 socketId)
+{
Q_UNUSED(localAddress)
Q_UNUSED(peerAddress)
Q_UNUSED(peerPort)
Q_UNUSED(localAddress)
Q_UNUSED(peerAddress)
Q_UNUSED(peerPort)
const CoreNetwork *network = qobject_cast<CoreNetwork *>(sender());
_connections[localPort] = network->coreSession()->strictCompliantIdent(identity);;
processWaiting(socketId);
const CoreNetwork *network = qobject_cast<CoreNetwork *>(sender());
_connections[localPort] = network->coreSession()->strictCompliantIdent(identity);;
processWaiting(socketId);
-bool IdentServer::removeSocket(const CoreIdentity *identity, const QHostAddress &localAddress, quint16 localPort,
- const QHostAddress &peerAddress, quint16 peerPort, qint64 socketId) {
+void IdentServer::removeSocket(const CoreIdentity *identity, const QHostAddress &localAddress, quint16 localPort,
+ const QHostAddress &peerAddress, quint16 peerPort, qint64 socketId)
+{
Q_UNUSED(identity)
Q_UNUSED(localAddress)
Q_UNUSED(peerAddress)
Q_UNUSED(identity)
Q_UNUSED(localAddress)
Q_UNUSED(peerAddress)
_connections.remove(localPort);
processWaiting(socketId);
_connections.remove(localPort);
processWaiting(socketId);
-qint64 IdentServer::addWaitingSocket() {
+
+qint64 IdentServer::addWaitingSocket()
+{
qint64 newSocketId = _socketId++;
_waiting.push_back(newSocketId);
return newSocketId;
}
qint64 newSocketId = _socketId++;
_waiting.push_back(newSocketId);
return newSocketId;
}
-qint64 IdentServer::lowestSocketId() {
+
+qint64 IdentServer::lowestSocketId() const
+{
if (_waiting.empty()) {
return std::numeric_limits<qint64>::max();
}
if (_waiting.empty()) {
return std::numeric_limits<qint64>::max();
}
return _waiting.front();
}
return _waiting.front();
}
-void IdentServer::removeWaitingSocket(qint64 socketId) {
+
+void IdentServer::removeWaitingSocket(qint64 socketId)
+{
_waiting.remove(socketId);
}
_waiting.remove(socketId);
}
-void IdentServer::processWaiting(qint64 socketId) {
+
+void IdentServer::processWaiting(qint64 socketId)
+{
removeWaitingSocket(socketId);
removeWaitingSocket(socketId);
- _requestQueue.remove_if([=](Request request) {
+
+ _requestQueue.remove_if([this, socketId](Request request) {
if (socketId < request.transactionId && responseAvailable(request)) {
return true;
if (socketId < request.transactionId && responseAvailable(request)) {
return true;
- } else if (lowestSocketId() < request.transactionId) {
+ }
+ else if (lowestSocketId() < request.transactionId) {
request.respondError("NO-USER");
return true;
}
});
}
request.respondError("NO-USER");
return true;
}
});
}
-bool operator==(const Request &a, const Request &b) {
+
+bool operator==(const Request &a, const Request &b)
+{
return a.requestId == b.requestId;
}
return a.requestId == b.requestId;
}
+#include <list>
+
+#include <QHash>
+#include <QObject>
+#include <QString>
#include <QTcpServer>
#include <QTcpSocket>
#include "coreidentity.h"
#include <QTcpServer>
#include <QTcpSocket>
#include "coreidentity.h"
QTcpSocket *socket;
uint16_t localPort;
QString query;
QTcpSocket *socket;
uint16_t localPort;
QString query;
void respondError(const QString &error);
};
void respondError(const QString &error);
};
-class IdentServer : public QObject {
-Q_OBJECT
+
+class IdentServer : public QObject
+{
+ Q_OBJECT
+
- IdentServer(bool strict, QObject *parent);
- ~IdentServer() override;
+ IdentServer(bool strict, QObject *parent = nullptr);
bool startListening();
void stopListening(const QString &msg);
qint64 addWaitingSocket();
bool startListening();
void stopListening(const QString &msg);
qint64 addWaitingSocket();
- bool addSocket(const CoreIdentity *identity, const QHostAddress &localAddress, quint16 localPort, const QHostAddress &peerAddress, quint16 peerPort, qint64 socketId);
- bool removeSocket(const CoreIdentity *identity, const QHostAddress &localAddress, quint16 localPort, const QHostAddress &peerAddress, quint16 peerPort, qint64 socketId);
+ void addSocket(const CoreIdentity *identity, const QHostAddress &localAddress, quint16 localPort, const QHostAddress &peerAddress, quint16 peerPort, qint64 socketId);
+ void removeSocket(const CoreIdentity *identity, const QHostAddress &localAddress, quint16 localPort, const QHostAddress &peerAddress, quint16 peerPort, qint64 socketId);
private slots:
void incomingConnection();
void respond();
private:
private slots:
void incomingConnection();
void respond();
private:
- bool responseAvailable(Request request);
-
- QString sysIdentForIdentity(const CoreIdentity *identity) const;
+ bool responseAvailable(Request request) const;
- qint64 lowestSocketId();
+ qint64 lowestSocketId() const;
void processWaiting(qint64 socketId);
void processWaiting(qint64 socketId);
QHash<uint16_t, QString> _connections;
std::list<Request> _requestQueue;
std::list<qint64> _waiting;
QHash<uint16_t, QString> _connections;
std::list<Request> _requestQueue;
std::list<qint64> _waiting;
- qint64 _socketId;
- qint64 _requestId;
+ qint64 _socketId{0};
+ qint64 _requestId{0};