| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2014 Gregory Oestreicher <greg@kamago.net> |
| 3 | |
| 4 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 5 | */ |
| 6 | |
| 7 | #ifndef KDAV_DAVJOBBASE_H |
| 8 | #define KDAV_DAVJOBBASE_H |
| 9 | |
| 10 | #include "kdav_export.h" |
| 11 | |
| 12 | #include <KJob> |
| 13 | |
| 14 | #include <memory> |
| 15 | |
| 16 | namespace KDAV |
| 17 | { |
| 18 | class DavJobBasePrivate; |
| 19 | class Error; |
| 20 | |
| 21 | /*! |
| 22 | * \class KDAV::DavJobBase |
| 23 | * \inheaderfile KDAV/DavJobBase |
| 24 | * \inmodule KDAV |
| 25 | * |
| 26 | * \brief base class for the jobs used by the resource. |
| 27 | */ |
| 28 | class KDAV_EXPORT DavJobBase : public KJob |
| 29 | { |
| 30 | Q_OBJECT |
| 31 | |
| 32 | public: |
| 33 | explicit DavJobBase(QObject *parent = nullptr); |
| 34 | ~DavJobBase() override; |
| 35 | |
| 36 | /*! |
| 37 | * Get the latest response code. |
| 38 | * |
| 39 | * If no response code has been set then 0 will be returned, but will |
| 40 | * be meaningless unless error() is non-zero. In that case this means |
| 41 | * that the latest error was not at the HTTP level. |
| 42 | */ |
| 43 | Q_REQUIRED_RESULT int latestResponseCode() const; |
| 44 | |
| 45 | /*! |
| 46 | * Check if the job can be retried later. |
| 47 | * |
| 48 | * This will return true for transient errors, i.e. if the response code |
| 49 | * is either zero and error() is set or if the HTTP response code hints |
| 50 | * at a temporary error. |
| 51 | * |
| 52 | * The HTTP response codes considered retryable are: |
| 53 | * \list |
| 54 | * \li 401 |
| 55 | * \li 402 |
| 56 | * \li 407 |
| 57 | * \li 408 |
| 58 | * \li 423 |
| 59 | * \li 429 |
| 60 | * \li 501 to 504, inclusive |
| 61 | * \li 507 |
| 62 | * \li 511 |
| 63 | * \endlist |
| 64 | */ |
| 65 | Q_REQUIRED_RESULT bool canRetryLater() const; |
| 66 | |
| 67 | /*! |
| 68 | * Check if the job failed because of a conflict |
| 69 | */ |
| 70 | Q_REQUIRED_RESULT bool hasConflict() const; |
| 71 | |
| 72 | /*! |
| 73 | * Returns a instance of the KDAV:Error to be able to translate the error |
| 74 | */ |
| 75 | Q_REQUIRED_RESULT Error davError() const; |
| 76 | |
| 77 | protected: |
| 78 | Q_DECL_HIDDEN explicit DavJobBase(DavJobBasePrivate *dd, QObject *parent = nullptr); |
| 79 | std::unique_ptr<DavJobBasePrivate> d_ptr; |
| 80 | |
| 81 | private: |
| 82 | Q_DECLARE_PRIVATE(DavJobBase) |
| 83 | }; |
| 84 | } |
| 85 | |
| 86 | #endif |
| 87 | |