diff options
| author | Felix (xq) Queißner <git@mq32.de> | 2020-06-16 22:01:59 +0200 |
|---|---|---|
| committer | Felix (xq) Queißner <git@mq32.de> | 2020-06-16 22:01:59 +0200 |
| commit | a3f3e3933c4a2522e233917a6795c6e9d677e65c (patch) | |
| tree | 6e1bd483bbd5e8ca6fee4566e544de48bfa754a6 /src/protocolhandler.hpp | |
| parent | bc18d9356828f1ae40d3b4ce5432b30ca13cfc15 (diff) | |
| download | kristall-a3f3e3933c4a2522e233917a6795c6e9d677e65c.tar.gz | |
Refactoring: Changes internal structure of requests and unifies a lot of code. Now all errors are handled the same.
Diffstat (limited to 'src/protocolhandler.hpp')
| -rw-r--r-- | src/protocolhandler.hpp | 59 |
1 files changed, 59 insertions, 0 deletions
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 <QObject> + +#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 |
