File indexing completed on 2024-11-17 04:44:02
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 #include "davjobbase.h" 0020 0021 #include "davjob.h" 0022 0023 using namespace KDAV2; 0024 0025 struct DavJobBasePrivate { 0026 Error mError; 0027 }; 0028 0029 DavJobBase::DavJobBase(QObject *parent) 0030 : KJob(parent) 0031 , d(std::unique_ptr<DavJobBasePrivate>(new DavJobBasePrivate())) 0032 { 0033 } 0034 0035 DavJobBase::~DavJobBase() 0036 { 0037 } 0038 0039 unsigned int DavJobBase::latestHttpStatusCode() const 0040 { 0041 return d->mError.httpStatusCode(); 0042 } 0043 0044 unsigned int DavJobBase::latestResponseCode() const 0045 { 0046 return d->mError.responseCode(); 0047 } 0048 0049 bool DavJobBase::canRetryLater() const 0050 { 0051 switch (latestHttpStatusCode()) { 0052 case 0: 0053 // Likely a timeout or a connection failure. 0054 if (error()) { 0055 return true; 0056 } 0057 break; 0058 case 401: // Authentication required 0059 case 402: // Payment required 0060 case 407: // Proxy authentication required 0061 case 408: // Request timeout 0062 case 423: // Locked 0063 case 429: // Too many requests 0064 case 501: 0065 case 502: 0066 case 503: 0067 case 504: 0068 case 507: // Insufficient storage 0069 case 511: // Network authentication required 0070 return true; 0071 default: 0072 break; 0073 } 0074 return false; 0075 } 0076 0077 bool DavJobBase::hasConflict() const 0078 { 0079 return latestHttpStatusCode() == 412; 0080 } 0081 0082 Error DavJobBase::davError() const 0083 { 0084 return Error((KDAV2::ErrorNumber)error(), d->mError.httpStatusCode(), d->mError.responseCode(), d->mError.errorText(), d->mError.jobErrorCode()); 0085 } 0086 0087 void DavJobBase::setErrorTextFromDavError() 0088 { 0089 setErrorText(davError().description()); 0090 } 0091 0092 void DavJobBase::setDavError(const Error &error) 0093 { 0094 d->mError = error; 0095 setError(error.errorNumber()); 0096 setErrorText(error.description()); 0097 } 0098 0099 void DavJobBase::setErrorFromJob(DavJob *job, ErrorNumber errNo) 0100 { 0101 setDavError(Error{errNo, job->httpStatusCode(), job->responseCode(), job->errorText(), job->error()}); 0102 }