File indexing completed on 2024-06-23 05:09:39

0001 /*
0002     Copyright (c) 2014 Gregory Oestreicher <greg@kamago.net>
0003 
0004     This program is free software; you can redistribute it and/or modify
0005     it under the terms of the GNU General Public License as published by
0006     the Free Software Foundation; either version 2 of the License, or
0007     (at your option) any later version.
0008 
0009     This program is distributed in the hope that it will be useful,
0010     but WITHOUT ANY WARRANTY; without even the implied warranty of
0011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0012     GNU General Public License for more details.
0013 
0014     You should have received a copy of the GNU General Public License
0015     along with this program; if not, write to the Free Software
0016     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0017 */
0018 
0019 #ifndef KDAV2_DAVJOBBASE_H
0020 #define KDAV2_DAVJOBBASE_H
0021 
0022 #include <memory>
0023 #include "kpimkdav2_export.h"
0024 #include <KJob>
0025 #include "daverror.h"
0026 
0027 struct DavJobBasePrivate;
0028 
0029 namespace KDAV2
0030 {
0031 class Error;
0032 class DavJob;
0033 
0034 /**
0035  * @short base class for the jobs used by the resource.
0036  */
0037 class KPIMKDAV2_EXPORT DavJobBase : public KJob
0038 {
0039     Q_OBJECT
0040 
0041 public:
0042     explicit DavJobBase(QObject *parent = nullptr);
0043     ~DavJobBase();
0044 
0045     /**
0046      * Get the latest http status code.
0047      *
0048      * If no response code has been set then 0 will be returned, but will
0049      * be meaningless unless error() is non-zero. In that case this means
0050      * that the latest error was not at the HTTP level.
0051      */
0052     unsigned int latestHttpStatusCode() const;
0053 
0054     /**
0055      * Get the response code.
0056      *
0057      * This is a QNetworkReply::NetworkError
0058      *
0059      * If no response code has been set then 0 will be returned, but will
0060      * be meaningless unless error() is non-zero. In that case this means
0061      * that the latest error was not at the HTTP level.
0062      *
0063      */
0064     unsigned int latestResponseCode() const;
0065 
0066     /**
0067      * Check if the job can be retried later.
0068      *
0069      * This will return true for transient errors, i.e. if the response code
0070      * is either zero and error() is set or if the HTTP response code hints
0071      * at a temporary error.
0072      *
0073      * The HTTP response codes considered retryable are:
0074      *   - 401
0075      *   - 402
0076      *   - 407
0077      *   - 408
0078      *   - 423
0079      *   - 429
0080      *   - 501 to 504, inclusive
0081      *   - 507
0082      *   - 511
0083      */
0084     bool canRetryLater() const;
0085 
0086     /**
0087      * Check if the job failed because of a conflict
0088      */
0089     bool hasConflict() const;
0090 
0091     /**
0092      * Returns a instance of the KDAV2:Error to be able to translate the error
0093      */
0094     Error davError() const;
0095 
0096 protected:
0097     void setErrorTextFromDavError();
0098     void setDavError(const Error &error);
0099 
0100     /**
0101      * Set the error of this job from a failed DavJob (executed by this job).
0102      */
0103     void setErrorFromJob(DavJob*, ErrorNumber jobErrorCode = ERR_PROBLEM_WITH_REQUEST);
0104 private:
0105     std::unique_ptr<DavJobBasePrivate> d;
0106 };
0107 
0108 }
0109 
0110 #endif