Libkdav2

davjobbase.cpp
1 /*
2  Copyright (c) 2014 Gregory Oestreicher <[email protected]>
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 
23 using namespace KDAV2;
24 
25 struct DavJobBasePrivate {
26  Error mError;
27 };
28 
29 DavJobBase::DavJobBase(QObject *parent)
30  : KJob(parent)
31  , d(std::unique_ptr<DavJobBasePrivate>(new DavJobBasePrivate()))
32 {
33 }
34 
35 DavJobBase::~DavJobBase()
36 {
37 }
38 
40 {
41  return d->mError.httpStatusCode();
42 }
43 
44 unsigned int DavJobBase::latestResponseCode() const
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 
82 Error DavJobBase::davError() const
83 {
84  return Error((KDAV2::ErrorNumber)error(), d->mError.httpStatusCode(), d->mError.responseCode(), d->mError.errorText(), d->mError.jobErrorCode());
85 }
86 
87 void DavJobBase::setErrorTextFromDavError()
88 {
90 }
91 
92 void DavJobBase::setDavError(const Error &error)
93 {
94  d->mError = error;
95  setError(error.errorNumber());
96  setErrorText(error.description());
97 }
98 
99 void DavJobBase::setErrorFromJob(DavJob *job, ErrorNumber errNo)
100 {
101  setDavError(Error{errNo, job->httpStatusCode(), job->responseCode(), job->errorText(), job->error()});
102 }
unsigned int latestHttpStatusCode() const
Get the latest http status code.
Definition: davjobbase.cpp:39
bool hasConflict() const
Check if the job failed because of a conflict.
Definition: davjobbase.cpp:77
bool canRetryLater() const
Check if the job can be retried later.
Definition: davjobbase.cpp:49
void setError(int errorCode)
void description(KJob *job, const QString &title, const QPair< QString, QString > &field1=QPair< QString, QString >(), const QPair< QString, QString > &field2=QPair< QString, QString >())
void setErrorText(const QString &errorText)
unsigned int latestResponseCode() const
Get the response code.
Definition: davjobbase.cpp:44
Error davError() const
Returns a instance of the KDAV2:Error to be able to translate the error.
Definition: davjobbase.cpp:82
void setErrorFromJob(DavJob *, ErrorNumber jobErrorCode=ERR_PROBLEM_WITH_REQUEST)
Set the error of this job from a failed DavJob (executed by this job).
Definition: davjobbase.cpp:99
int error() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jan 27 2022 23:10:33 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.