Libkdav2

davjobbase.cpp
1/*
2 Copyright (c) 2014 Gregory Oestreicher <greg@kamago.net>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17*/
18
19#include "davjobbase.h"
20
21#include "davjob.h"
22
23using namespace KDAV2;
24
25struct DavJobBasePrivate {
26 Error mError;
27};
28
29DavJobBase::DavJobBase(QObject *parent)
30 : KJob(parent)
31 , d(std::unique_ptr<DavJobBasePrivate>(new DavJobBasePrivate()))
32{
33}
34
35DavJobBase::~DavJobBase()
36{
37}
38
40{
41 return d->mError.httpStatusCode();
42}
43
45{
46 return d->mError.responseCode();
47}
48
50{
51 switch (latestHttpStatusCode()) {
52 case 0:
53 // Likely a timeout or a connection failure.
54 if (error()) {
55 return true;
56 }
57 break;
58 case 401: // Authentication required
59 case 402: // Payment required
60 case 407: // Proxy authentication required
61 case 408: // Request timeout
62 case 423: // Locked
63 case 429: // Too many requests
64 case 501:
65 case 502:
66 case 503:
67 case 504:
68 case 507: // Insufficient storage
69 case 511: // Network authentication required
70 return true;
71 default:
72 break;
73 }
74 return false;
75}
76
78{
79 return latestHttpStatusCode() == 412;
80}
81
83{
84 return Error((KDAV2::ErrorNumber)error(), d->mError.httpStatusCode(), d->mError.responseCode(), d->mError.errorText(), d->mError.jobErrorCode());
85}
86
87void DavJobBase::setErrorTextFromDavError()
88{
90}
91
92void DavJobBase::setDavError(const Error &error)
93{
94 d->mError = error;
95 setError(error.errorNumber());
96 setErrorText(error.description());
97}
98
99void DavJobBase::setErrorFromJob(DavJob *job, ErrorNumber errNo)
100{
101 setDavError(Error{errNo, job->httpStatusCode(), job->responseCode(), job->errorText(), job->error()});
102}
unsigned int latestResponseCode() const
Get the response code.
bool canRetryLater() const
Check if the job can be retried later.
void setErrorFromJob(DavJob *, ErrorNumber jobErrorCode=ERR_PROBLEM_WITH_REQUEST)
Set the error of this job from a failed DavJob (executed by this job).
bool hasConflict() const
Check if the job failed because of a conflict.
Error davError() const
Returns a instance of the KDAV2:Error to be able to translate the error.
unsigned int latestHttpStatusCode() const
Get the latest http status code.
void setErrorText(const QString &errorText)
void description(KJob *job, const QString &title, const QPair< QString, QString > &field1=QPair< QString, QString >(), const QPair< QString, QString > &field2=QPair< QString, QString >())
int error() const
void setError(int errorCode)
QString errorText() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:05 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.