* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
+#include "identserver.h"
+
#include <limits>
#include "corenetwork.h"
-#include "identserver.h"
-#include "logger.h"
-IdentServer::IdentServer(QObject *parent)
+IdentServer::IdentServer(QObject* parent)
: QObject(parent)
{
- connect(&_server, SIGNAL(newConnection()), this, SLOT(incomingConnection()));
- connect(&_v6server, SIGNAL(newConnection()), this, SLOT(incomingConnection()));
+ connect(&_server, &QTcpServer::newConnection, this, &IdentServer::incomingConnection);
+ connect(&_v6server, &QTcpServer::newConnection, this, &IdentServer::incomingConnection);
}
-
bool IdentServer::startListening()
{
uint16_t port = Quassel::optionValue("ident-port").toUShort();
bool success = false;
if (_v6server.listen(QHostAddress("::1"), port)) {
- quInfo() << qPrintable(
- tr("Listening for identd clients on IPv6 %1 port %2")
- .arg("::1")
- .arg(_v6server.serverPort())
- );
+ qInfo() << qPrintable(tr("Listening for identd clients on IPv6 %1 port %2").arg("::1").arg(_v6server.serverPort()));
success = true;
}
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())
- );
+ qInfo() << qPrintable(tr("Listening for identd clients on IPv4 %1 port %2").arg("127.0.0.1").arg(_server.serverPort()));
success = true;
}
if (!success) {
- quError() << qPrintable(tr("Identd could not open any network interfaces to listen on! No identd functionality will be available"));
+ qWarning() << qPrintable(tr("Identd could not open any network interfaces to listen on! No identd functionality will be available"));
}
return success;
}
-
-void IdentServer::stopListening(const QString &msg)
+void IdentServer::stopListening(const QString& msg)
{
bool wasListening = false;
if (wasListening) {
if (msg.isEmpty())
- quInfo() << "No longer listening for identd clients.";
+ qInfo() << "No longer listening for identd clients.";
else
- quInfo() << qPrintable(msg);
+ qInfo() << qPrintable(msg);
}
}
-
void IdentServer::incomingConnection()
{
- auto server = qobject_cast<QTcpServer *>(sender());
+ auto server = qobject_cast<QTcpServer*>(sender());
Q_ASSERT(server);
while (server->hasPendingConnections()) {
- QTcpSocket *socket = server->nextPendingConnection();
- connect(socket, SIGNAL(readyRead()), this, SLOT(respond()));
- connect(socket, SIGNAL(disconnected()), socket, SLOT(deleteLater()));
+ QTcpSocket* socket = server->nextPendingConnection();
+ connect(socket, &QIODevice::readyRead, this, &IdentServer::respond);
+ connect(socket, &QAbstractSocket::disconnected, socket, &QObject::deleteLater);
}
}
-
void IdentServer::respond()
{
- QTcpSocket *socket = qobject_cast<QTcpSocket *>(sender());
+ auto* socket = qobject_cast<QTcpSocket*>(sender());
Q_ASSERT(socket);
qint64 transactionId = _socketId;
}
}
-
-void Request::respondSuccess(const QString &user)
+void Request::respondSuccess(const QString& user)
{
if (socket) {
QString data = query + " : USERID : Quassel : " + user + "\r\n";
}
}
-
-void Request::respondError(const QString &error)
+void Request::respondError(const QString& error)
{
if (socket) {
QString data = query + " : ERROR : " + error + "\r\n";
}
}
-
bool IdentServer::responseAvailable(Request request) const
{
if (!_connections.contains(request.localPort)) {
return true;
}
-
-void 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)
- const CoreNetwork *network = qobject_cast<CoreNetwork *>(sender());
- _connections[localPort] = network->coreSession()->strictCompliantIdent(identity);;
+ const CoreNetwork* network = qobject_cast<CoreNetwork*>(sender());
+ _connections[localPort] = network->coreSession()->strictCompliantIdent(identity);
+ ;
processWaiting(socketId);
}
-
-void 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)
processWaiting(socketId);
}
-
qint64 IdentServer::addWaitingSocket()
{
qint64 newSocketId = _socketId++;
return newSocketId;
}
-
qint64 IdentServer::lowestSocketId() const
{
if (_waiting.empty()) {
return _waiting.front();
}
-
void IdentServer::removeWaitingSocket(qint64 socketId)
{
_waiting.remove(socketId);
}
-
void IdentServer::processWaiting(qint64 socketId)
{
removeWaitingSocket(socketId);
});
}
-
-bool operator==(const Request &a, const Request &b)
+bool operator==(const Request& a, const Request& b)
{
return a.requestId == b.requestId;
}