diff options
| author | Felix (xq) Queißner <git@mq32.de> | 2020-06-17 01:29:30 +0200 |
|---|---|---|
| committer | Felix (xq) Queißner <git@mq32.de> | 2020-06-17 01:29:30 +0200 |
| commit | 5b14fc424462a5d3a5a509bd177c04e9cba2ce17 (patch) | |
| tree | ad5e9b685be26d22d570ba4788a9b01a65ceb531 /src/geminiclient.cpp | |
| parent | 03253a724b6fdb3f511510d10c3e62615e305cf2 (diff) | |
| download | kristall-5b14fc424462a5d3a5a509bd177c04e9cba2ce17.tar.gz | |
Makes gemini protocol handler a bit more robust.Makes style preview a file in about: instead of hardcoding it. Starts to implement the options menu for redirection configuration.
Diffstat (limited to 'src/geminiclient.cpp')
| -rw-r--r-- | src/geminiclient.cpp | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/src/geminiclient.cpp b/src/geminiclient.cpp index a21eea4..80f5742 100644 --- a/src/geminiclient.cpp +++ b/src/geminiclient.cpp @@ -9,6 +9,9 @@ GeminiClient::GeminiClient() : ProtocolHandler(nullptr) connect(&socket, &QSslSocket::encrypted, this, &GeminiClient::socketEncrypted); connect(&socket, &QSslSocket::readyRead, this, &GeminiClient::socketReadyRead); connect(&socket, &QSslSocket::disconnected, this, &GeminiClient::socketDisconnected); + connect(&socket, &QSslSocket::stateChanged, [](QSslSocket::SocketState state) { + qDebug() << "Socket state changed to " << state; + }); connect(&socket, QOverload<const QList<QSslError> &>::of(&QSslSocket::sslErrors), this, &GeminiClient::sslErrors); #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) @@ -33,8 +36,12 @@ bool GeminiClient::startRequest(const QUrl &url) if(url.scheme() != "gemini") return false; - if(socket.isOpen()) - return false; + if(socket.state() != QTcpSocket::UnconnectedState) { + socket.disconnectFromHost(); + socket.close(); + if(not socket.waitForDisconnected(1500)) + return false; + } QSslConfiguration ssl_config; ssl_config.setProtocol(QSsl::TlsV1_2); @@ -61,16 +68,24 @@ bool GeminiClient::startRequest(const QUrl &url) bool GeminiClient::isInProgress() const { - return socket.isOpen(); + return (socket.state() != QTcpSocket::UnconnectedState); } bool GeminiClient::cancelRequest() { - this->is_receiving_body = false; - this->socket.close(); - this->buffer.clear(); - this->body.clear(); - return true; + if(isInProgress()) + { + this->is_receiving_body = false; + this->socket.disconnectFromHost(); + this->socket.close(); + this->buffer.clear(); + this->body.clear(); + return this->socket.waitForDisconnected(250); + } + else + { + return true; + } } bool GeminiClient::enableClientCertificate(const CryptoIdentity &ident) @@ -130,6 +145,11 @@ void GeminiClient::socketReadyRead() emit networkError(ProtocolViolation, "Line is too short for valid protocol"); return; } + if(buffer.size() >= 1200) + { + emit networkError(ProtocolViolation, "response too large!"); + socket.close(); + } if(buffer[buffer.size() - 1] != '\r') { socket.close(); qDebug() << buffer; @@ -246,6 +266,11 @@ void GeminiClient::socketReadyRead() assert(false and "unreachable"); } } + if((buffer.size() + response.size()) >= 1200) + { + emit networkError(ProtocolViolation, "META too large!"); + socket.close(); + } buffer.append(response); } } |
