From 9b93c4d7c5a450607eca0174b1899e56d6a09a48 Mon Sep 17 00:00:00 2001 From: "Felix (xq) Queißner" Date: Wed, 10 Jun 2020 01:24:39 +0200 Subject: Improves gophermaps: Now handle '+' correctly, improves gopher protocol such that it now respects *the lone dot*. --- src/gopherclient.cpp | 12 ++++++++++-- src/gopherclient.hpp | 1 + src/gophermaprenderer.cpp | 17 +++++++++++++---- src/settingsdialog.ui | 10 +++++----- 4 files changed, 29 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/gopherclient.cpp b/src/gopherclient.cpp index 17faceb..2c2cdf5 100644 --- a/src/gopherclient.cpp +++ b/src/gopherclient.cpp @@ -34,7 +34,7 @@ bool GopherClient::startRequest(const QUrl &url) else if(type == "h") mime = "text/html"; else if(type == "s") mime = "audio/unknown"; - qDebug() << url << "→" << mime; + is_processing_binary = (type == "5") or (type == "9") or (type == "I") or (type == "g"); this->requested_url = url; this->was_cancelled = false; @@ -66,6 +66,15 @@ void GopherClient::on_connected() void GopherClient::on_readRead() { body.append(socket.readAll()); + + if(not is_processing_binary) { + // Strip the "lone dot" from gopher data + if(int index = body.indexOf(".\r\n"); index >= 0) { + body.resize(index); + socket.close(); + } + } + emit this->requestProgress(body.size()); } @@ -74,7 +83,6 @@ void GopherClient::on_finished() if(not was_cancelled) { emit this->requestComplete(this->body, mime); - was_cancelled = true; } body.clear(); diff --git a/src/gopherclient.hpp b/src/gopherclient.hpp index a2beb0c..f9913c5 100644 --- a/src/gopherclient.hpp +++ b/src/gopherclient.hpp @@ -37,6 +37,7 @@ private: QUrl requested_url; bool was_cancelled; QString mime; + bool is_processing_binary; }; #endif // GOPHERCLIENT_HPP diff --git a/src/gophermaprenderer.cpp b/src/gophermaprenderer.cpp index c705883..89f3905 100644 --- a/src/gophermaprenderer.cpp +++ b/src/gophermaprenderer.cpp @@ -51,6 +51,8 @@ std::unique_ptr GophermapRenderer::render(const QByteArray &input QTextBlockFormat non_list_format = cursor.blockFormat(); + char last_type = '1'; + QList lines = input.split('\n'); for (auto const &line : lines) { @@ -66,7 +68,9 @@ std::unique_ptr GophermapRenderer::render(const QByteArray &input QString icon; QString scheme = "gopher"; - switch (line.at(0)) + + auto type = line.at(0); + switch (type) { case '0': // Text File icon = "text"; @@ -125,12 +129,17 @@ std::unique_ptr GophermapRenderer::render(const QByteArray &input default: // unknown continue; } + if(type == '+') { + type = last_type; + } else { + last_type = type; + } QString title = items.at(0); // 1Phlog /phlog octotherp.org 70 + - if (line.at(0) == 'i') + if (type == 'i') { cursor.insertText(title + "\n", standard); } @@ -147,10 +156,10 @@ std::unique_ptr GophermapRenderer::render(const QByteArray &input dst_url = root_url.resolved(QUrl(items.at(1))).toString(); break; case 3: - dst_url = scheme + "://" + items.at(2) + "/" + line.mid(0, 1) + items.at(1); + dst_url = scheme + "://" + items.at(2) + "/" + QString(type) + items.at(1); break; default: - dst_url = scheme + "://" + items.at(2) + ":" + items.at(3) + "/" + line.mid(0, 1) + items.at(1); + dst_url = scheme + "://" + items.at(2) + ":" + items.at(3) + "/" + QString(type) + items.at(1); break; } diff --git a/src/settingsdialog.ui b/src/settingsdialog.ui index 75b84fe..23d1bc8 100644 --- a/src/settingsdialog.ui +++ b/src/settingsdialog.ui @@ -212,9 +212,9 @@ - + - Display error message + Use OS default handler buttonGroup @@ -222,9 +222,9 @@ - + - Use OS default handler + Display error message buttonGroup @@ -842,9 +842,9 @@ + - -- cgit v1.2.3