diff options
| author | Felix (xq) Queißner <git@mq32.de> | 2020-06-22 21:10:04 +0200 |
|---|---|---|
| committer | Felix (xq) Queißner <git@mq32.de> | 2020-06-22 21:10:04 +0200 |
| commit | 75ec461eeaa851cb5c53f4cfffc434e3e529ed1d (patch) | |
| tree | 3944737340718ca3675381aa06636045d397e780 /src/protocols/fingerclient.cpp | |
| parent | 8dbfb0890560fd1cd698d06fa05ac868c4db8576 (diff) | |
| download | kristall-75ec461eeaa851cb5c53f4cfffc434e3e529ed1d.tar.gz | |
Restructures the project source and cleans up a bit
Diffstat (limited to 'src/protocols/fingerclient.cpp')
| -rw-r--r-- | src/protocols/fingerclient.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/protocols/fingerclient.cpp b/src/protocols/fingerclient.cpp new file mode 100644 index 0000000..1c9a6a3 --- /dev/null +++ b/src/protocols/fingerclient.cpp @@ -0,0 +1,83 @@ +#include "fingerclient.hpp" +#include "ioutil.hpp" + +FingerClient::FingerClient() : ProtocolHandler(nullptr) +{ + connect(&socket, &QTcpSocket::connected, this, &FingerClient::on_connected); + connect(&socket, &QTcpSocket::readyRead, this, &FingerClient::on_readRead); + connect(&socket, &QTcpSocket::disconnected, this, &FingerClient::on_finished); + +#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) + connect(&socket, &QTcpSocket::errorOccurred, this, &FingerClient::on_socketError); +#else + connect(&socket, QOverload<QAbstractSocket::SocketError>::of(&QTcpSocket::error), this, &FingerClient::on_socketError); +#endif +} + +FingerClient::~FingerClient() +{ + +} + +bool FingerClient::supportsScheme(const QString &scheme) const +{ + return (scheme == "finger"); +} + +bool FingerClient::startRequest(const QUrl &url, RequestOptions options) +{ + Q_UNUSED(options) + + if(isInProgress()) + return false; + + if(url.scheme() != "finger") + return false; + + this->requested_user = url.userName(); + this->was_cancelled = false; + socket.connectToHost(url.host(), url.port(79)); + + return true; +} + +bool FingerClient::isInProgress() const +{ + return socket.isOpen(); +} + +bool FingerClient::cancelRequest() +{ + was_cancelled = true; + socket.close(); + body.clear(); + return true; +} + +void FingerClient::on_connected() +{ + auto blob = (requested_user + "\r\n").toUtf8(); + + IoUtil::writeAll(socket, blob); +} + +void FingerClient::on_readRead() +{ + body.append(socket.readAll()); + emit this->requestProgress(body.size()); +} + +void FingerClient::on_finished() +{ + if(not was_cancelled) + { + emit this->requestComplete(this->body, "text/finger"); + was_cancelled = true; + } + body.clear(); +} + +void FingerClient::on_socketError(QAbstractSocket::SocketError error_code) +{ + this->emitNetworkError(error_code, socket.errorString()); +} |
