X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fauthhandler.cpp;h=eb8a00c92eaac7d43f7ce98bf7aebf15f05f3949;hp=bd5bbc456eb3cd1de8e6e7c406292d68f84f4a10;hb=c1cf157116de7fc3da96203aa6f03c38c7ebb650;hpb=9d54503555534a2c554f09a33df6afa33d6308ec diff --git a/src/common/authhandler.cpp b/src/common/authhandler.cpp index bd5bbc45..eb8a00c9 100644 --- a/src/common/authhandler.cpp +++ b/src/common/authhandler.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2014 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -20,45 +20,34 @@ #include "authhandler.h" -AuthHandler::AuthHandler(QObject *parent) - : QObject(parent), - _state(UnconnectedState), - _socket(0), - _disconnectedSent(false) -{ - -} +#include +#include "util.h" -AuthHandler::State AuthHandler::state() const -{ - return _state; -} - - -void AuthHandler::setState(AuthHandler::State state) -{ - if (_state != state) { - _state = state; - emit stateChanged(state); - } -} - +AuthHandler::AuthHandler(QObject* parent) + : QObject(parent) +{} -QTcpSocket *AuthHandler::socket() const +QTcpSocket* AuthHandler::socket() const { return _socket; } - -void AuthHandler::setSocket(QTcpSocket *socket) +void AuthHandler::setSocket(QTcpSocket* socket) { _socket = socket; - connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), SIGNAL(socketStateChanged(QAbstractSocket::SocketState))); - connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(onSocketError(QAbstractSocket::SocketError))); - connect(socket, SIGNAL(disconnected()), SLOT(onSocketDisconnected())); + connect(socket, selectOverload(&QTcpSocket::error), this, &AuthHandler::onSocketError); + connect(socket, &QAbstractSocket::disconnected, this, &AuthHandler::onSocketDisconnected); } +bool AuthHandler::isLocal() const +{ + if (socket()) { + if (socket()->peerAddress() == QHostAddress::LocalHost || socket()->peerAddress() == QHostAddress::LocalHostIPv6) + return true; + } + return false; +} // Some errors (e.g. connection refused) don't trigger a disconnected() from the socket, so send this explicitly // (but make sure it's only sent once!) @@ -74,7 +63,6 @@ void AuthHandler::onSocketError(QAbstractSocket::SocketError error) } } - void AuthHandler::onSocketDisconnected() { if (!_disconnectedSent) { @@ -83,13 +71,11 @@ void AuthHandler::onSocketDisconnected() } } - void AuthHandler::invalidMessage() { qWarning() << Q_FUNC_INFO << "No handler for message!"; } - void AuthHandler::close() { if (_socket && _socket->isOpen())