- add debug output
- improve formatting of identd responses
else if (query.endsWith("\n"))
query.chop(1);
else if (query.endsWith("\n"))
query.chop(1);
+ qDebug() << "Received identd query" << query << "from" << socket->peerAddress();
+
QList<QByteArray> split = query.split(',');
QList<QByteArray> split = query.split(',');
+ bool successLocalPort = false;
+ bool successRemotePort = false;
- if (!split.empty()) {
- localPort = split[0].trimmed().toUShort(&success, 10);
+ quint16 remotePort = 0;
+ if (split.length() == 2) {
+ localPort = split[0].trimmed().toUShort(&successLocalPort, 10);
+ remotePort = split[1].trimmed().toUShort(&successRemotePort, 10);
- Request request{socket, localPort, query, transactionId, _requestId++};
- if (!success) {
+ Request request{socket, localPort, remotePort, query, transactionId, _requestId++};
+ if (!successLocalPort || !successRemotePort) {
request.respondError("INVALID-PORT");
}
else if (responseAvailable(request)) {
request.respondError("INVALID-PORT");
}
else if (responseAvailable(request)) {
void Request::respondSuccess(const QString& user)
{
if (socket) {
void Request::respondSuccess(const QString& user)
{
if (socket) {
- QString data = query + " : USERID : Quassel : " + user + "\r\n";
+ QString data = QString("%1, %2 : USERID : Quassel : %3\r\n")
+ .arg(QString::number(localPort))
+ .arg(QString::number(remotePort))
+ .arg(user);
+ qDebug() << "answering identd request from" << socket->peerAddress() << "with" << data;
socket->write(data.toUtf8());
socket->flush();
socket->write(data.toUtf8());
socket->flush();
+ QTimer::singleShot(DISCONNECTION_TIMEOUT, socket, &QTcpSocket::close);
}
}
void Request::respondError(const QString& error)
{
if (socket) {
}
}
void Request::respondError(const QString& error)
{
if (socket) {
- QString data = query + " : ERROR : " + error + "\r\n";
+ QString data = QString("%1, %2 : ERROR : %3\r\n")
+ .arg(QString::number(localPort))
+ .arg(QString::number(remotePort))
+ .arg(error);
+ qDebug() << "answering identd request from" << socket->peerAddress() << "with" << data;
socket->write(data.toUtf8());
socket->flush();
socket->write(data.toUtf8());
socket->flush();
+ QTimer::singleShot(DISCONNECTION_TIMEOUT, socket, &QTcpSocket::close);
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);
}
processWaiting(socketId);
}
{
QPointer<QTcpSocket> socket;
uint16_t localPort;
{
QPointer<QTcpSocket> socket;
uint16_t localPort;
QString query;
qint64 transactionId;
qint64 requestId;
QString query;
qint64 transactionId;
qint64 requestId;
void respondSuccess(const QString& user);
void respondError(const QString& error);
void respondSuccess(const QString& user);
void respondError(const QString& error);
+
+ const static int DISCONNECTION_TIMEOUT = 500;
};
class IdentServer : public QObject
};
class IdentServer : public QObject