From a3f3e3933c4a2522e233917a6795c6e9d677e65c Mon Sep 17 00:00:00 2001 From: "Felix (xq) Queißner" Date: Tue, 16 Jun 2020 22:01:59 +0200 Subject: Refactoring: Changes internal structure of requests and unifies a lot of code. Now all errors are handled the same. --- src/protocolhandler.hpp | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/protocolhandler.hpp (limited to 'src/protocolhandler.hpp') diff --git a/src/protocolhandler.hpp b/src/protocolhandler.hpp new file mode 100644 index 0000000..f4ae9eb --- /dev/null +++ b/src/protocolhandler.hpp @@ -0,0 +1,59 @@ +#ifndef GENERICPROTOCOLCLIENT_HPP +#define GENERICPROTOCOLCLIENT_HPP + +#include + +#include "cryptoidentity.hpp" + +class ProtocolHandler : public QObject +{ + Q_OBJECT +public: + enum NetworkError { + UnknownError, //!< There was an unhandled network error + ProtocolViolation, //!< The server responded with something unexpected and violated the protocol + HostNotFound, //!< The host + ResourceNotFound, //!< The requested resource was not found on the server + BadRequest, //!< Our client misbehaved and did a request the server cannot understand + ProxyRequest, //!< We requested to + InternalServerError, + InvalidClientCertificate, + UntrustedHost, //!< We don't know the host, and we don't trust it + MistrustedHost, //!< We know the host and it's not the server identity we've seen before + Unauthorized, //!< The requested resource could not be accessed. + TlsFailure, //!< Unspecified TLS failure + }; +public: + explicit ProtocolHandler(QObject *parent = nullptr); + + virtual bool supportsScheme(QString const & scheme) const = 0; + + virtual bool startRequest(QUrl const & url) = 0; + + virtual bool isInProgress() const = 0; + + virtual bool cancelRequest() = 0; + + virtual bool enableClientCertificate(CryptoIdentity const & ident); + virtual void disableClientCertificate(); +signals: + //! We successfully transferred some bytes from the server + void requestProgress(qint64 transferred); + + //! The request completed with the given data and mime type + void requestComplete(QByteArray const & data, QString const & mime); + + //! Server redirected us to another URL + void redirected(QUrl const & uri, bool is_permanent); + + //! The server needs some information from the user to process this query. + void inputRequired(QString const & user_query); + + //! There was an error while processing the request + void networkError(NetworkError error, QString const & reason); + + //! The server wants us to use a client certificate + void certificateRequired(QString const & info); +}; + +#endif // GENERICPROTOCOLCLIENT_HPP -- cgit v1.2.3