diff options
| author | Felix (xq) Queißner <git@mq32.de> | 2020-06-08 20:45:08 +0200 |
|---|---|---|
| committer | Felix (xq) Queißner <git@mq32.de> | 2020-06-08 20:45:08 +0200 |
| commit | 4276fd7662167fbabf78edf75e75a85218dff4a5 (patch) | |
| tree | f7009b55f9bbdecc77477d3f3191e5aef8356a86 /src/fingerclient.cpp | |
| parent | 24adf0b41746449a163cfd2daaa2feefd67e9d57 (diff) | |
| download | kristall-4276fd7662167fbabf78edf75e75a85218dff4a5.tar.gz | |
Adds support for finger protocol.
Diffstat (limited to 'src/fingerclient.cpp')
| -rw-r--r-- | src/fingerclient.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/fingerclient.cpp b/src/fingerclient.cpp new file mode 100644 index 0000000..b696341 --- /dev/null +++ b/src/fingerclient.cpp @@ -0,0 +1,65 @@ +#include "fingerclient.hpp" +#include "ioutil.hpp" + +FingerClient::FingerClient(QObject *parent) : QObject(parent) +{ + connect(&socket, &QTcpSocket::connected, this, &FingerClient::on_connected); + connect(&socket, &QTcpSocket::readyRead, this, &FingerClient::on_readRead); + connect(&socket, &QTcpSocket::disconnected, this, &FingerClient::on_finished); +} + +FingerClient::~FingerClient() +{ + +} + +bool FingerClient::startRequest(const QUrl &url) +{ + 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/plain"); + was_cancelled = true; + } + body.clear(); +} |
