File indexing completed on 2024-10-06 03:39:36
0001 /* 0002 SPDX-License-Identifier: LGPL-2.0-or-later 0003 SPDX-FileCopyrightText: 2000 Waldo Bastian <bastian@kde.org> 0004 SPDX-FileCopyrightText: 2000 David Faure <faure@kde.org> 0005 SPDX-FileCopyrightText: 2000 Stephan Kulow <coolo@kde.org> 0006 SPDX-FileCopyrightText: 2007 Thiago Macieira <thiago@kde.org> 0007 SPDX-FileCopyrightText: 2019-2022 Harald Sitter <sitter@kde.org> 0008 */ 0009 0010 #include "workerbase.h" 0011 #include "workerbase_p.h" 0012 0013 #include <commands_p.h> 0014 0015 namespace KIO 0016 { 0017 0018 WorkerBase::WorkerBase(const QByteArray &protocol, const QByteArray &poolSocket, const QByteArray &appSocket) 0019 : d(new WorkerBasePrivate(protocol, poolSocket, appSocket, this)) 0020 { 0021 } 0022 0023 WorkerBase::~WorkerBase() = default; 0024 0025 void WorkerBase::dispatchLoop() 0026 { 0027 d->bridge.dispatchLoop(); 0028 } 0029 0030 void WorkerBase::connectWorker(const QString &address) 0031 { 0032 d->bridge.connectSlave(address); 0033 } 0034 0035 void WorkerBase::disconnectWorker() 0036 { 0037 d->bridge.disconnectSlave(); 0038 } 0039 0040 void WorkerBase::setMetaData(const QString &key, const QString &value) 0041 { 0042 d->bridge.setMetaData(key, value); 0043 } 0044 0045 QString WorkerBase::metaData(const QString &key) const 0046 { 0047 return d->bridge.metaData(key); 0048 } 0049 0050 MetaData WorkerBase::allMetaData() const 0051 { 0052 return d->bridge.allMetaData(); 0053 } 0054 0055 bool WorkerBase::hasMetaData(const QString &key) const 0056 { 0057 return d->bridge.hasMetaData(key); 0058 } 0059 0060 QMap<QString, QVariant> WorkerBase::mapConfig() const 0061 { 0062 return d->bridge.mapConfig(); 0063 } 0064 0065 bool WorkerBase::configValue(const QString &key, bool defaultValue) const 0066 { 0067 return d->bridge.configValue(key, defaultValue); 0068 } 0069 0070 int WorkerBase::configValue(const QString &key, int defaultValue) const 0071 { 0072 return d->bridge.configValue(key, defaultValue); 0073 } 0074 0075 QString WorkerBase::configValue(const QString &key, const QString &defaultValue) const 0076 { 0077 return d->bridge.configValue(key, defaultValue); 0078 } 0079 0080 KConfigGroup *WorkerBase::config() 0081 { 0082 return d->bridge.config(); 0083 } 0084 0085 void WorkerBase::sendMetaData() 0086 { 0087 d->bridge.sendMetaData(); 0088 } 0089 0090 void WorkerBase::sendAndKeepMetaData() 0091 { 0092 d->bridge.sendAndKeepMetaData(); 0093 } 0094 0095 KRemoteEncoding *WorkerBase::remoteEncoding() 0096 { 0097 return d->bridge.remoteEncoding(); 0098 } 0099 0100 void WorkerBase::data(const QByteArray &data) 0101 { 0102 d->bridge.data(data); 0103 } 0104 0105 void WorkerBase::dataReq() 0106 { 0107 d->bridge.dataReq(); 0108 } 0109 0110 void WorkerBase::workerStatus(const QString &host, bool connected) 0111 { 0112 d->bridge.slaveStatus(host, connected); 0113 } 0114 0115 void WorkerBase::canResume() 0116 { 0117 d->bridge.canResume(); 0118 } 0119 0120 void WorkerBase::totalSize(KIO::filesize_t _bytes) 0121 { 0122 d->bridge.totalSize(_bytes); 0123 } 0124 0125 void WorkerBase::processedSize(KIO::filesize_t _bytes) 0126 { 0127 d->bridge.processedSize(_bytes); 0128 } 0129 0130 void WorkerBase::written(KIO::filesize_t _bytes) 0131 { 0132 d->bridge.written(_bytes); 0133 } 0134 0135 void WorkerBase::position(KIO::filesize_t _pos) 0136 { 0137 d->bridge.position(_pos); 0138 } 0139 0140 void WorkerBase::truncated(KIO::filesize_t _length) 0141 { 0142 d->bridge.truncated(_length); 0143 } 0144 0145 void WorkerBase::speed(unsigned long _bytes_per_second) 0146 { 0147 d->bridge.speed(_bytes_per_second); 0148 } 0149 0150 void WorkerBase::redirection(const QUrl &_url) 0151 { 0152 d->bridge.redirection(_url); 0153 } 0154 0155 void WorkerBase::errorPage() 0156 { 0157 d->bridge.errorPage(); 0158 } 0159 0160 void WorkerBase::mimeType(const QString &_type) 0161 { 0162 d->bridge.mimeType(_type); 0163 } 0164 0165 void WorkerBase::exit() 0166 { 0167 d->bridge.exit(); 0168 } 0169 0170 void WorkerBase::warning(const QString &_msg) 0171 { 0172 d->bridge.warning(_msg); 0173 } 0174 0175 void WorkerBase::infoMessage(const QString &_msg) 0176 { 0177 d->bridge.infoMessage(_msg); 0178 } 0179 0180 void WorkerBase::statEntry(const UDSEntry &entry) 0181 { 0182 d->bridge.statEntry(entry); 0183 } 0184 0185 void WorkerBase::listEntry(const UDSEntry &entry) 0186 { 0187 d->bridge.listEntry(entry); 0188 } 0189 0190 void WorkerBase::listEntries(const UDSEntryList &list) 0191 { 0192 d->bridge.listEntries(list); 0193 } 0194 0195 void WorkerBase::appConnectionMade() 0196 { 0197 } // No response! 0198 0199 void WorkerBase::setHost(QString const &, quint16, QString const &, QString const &) 0200 { 0201 } // No response! 0202 0203 WorkerResult WorkerBase::openConnection() 0204 { 0205 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_CONNECT)); 0206 } 0207 0208 void WorkerBase::closeConnection() 0209 { 0210 } // No response! 0211 0212 WorkerResult WorkerBase::stat(QUrl const &) 0213 { 0214 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_STAT)); 0215 } 0216 0217 WorkerResult WorkerBase::put(QUrl const &, int, JobFlags) 0218 { 0219 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_PUT)); 0220 } 0221 0222 WorkerResult WorkerBase::special(const QByteArray &) 0223 { 0224 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_SPECIAL)); 0225 } 0226 0227 WorkerResult WorkerBase::listDir(QUrl const &) 0228 { 0229 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_LISTDIR)); 0230 } 0231 0232 WorkerResult WorkerBase::get(QUrl const &) 0233 { 0234 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_GET)); 0235 } 0236 0237 WorkerResult WorkerBase::open(QUrl const &, QIODevice::OpenMode) 0238 { 0239 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_OPEN)); 0240 } 0241 0242 WorkerResult WorkerBase::read(KIO::filesize_t) 0243 { 0244 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_READ)); 0245 } 0246 0247 WorkerResult WorkerBase::write(const QByteArray &) 0248 { 0249 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_WRITE)); 0250 } 0251 0252 WorkerResult WorkerBase::seek(KIO::filesize_t) 0253 { 0254 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_SEEK)); 0255 } 0256 0257 WorkerResult WorkerBase::truncate(KIO::filesize_t) 0258 { 0259 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_TRUNCATE)); 0260 } 0261 0262 WorkerResult WorkerBase::close() 0263 { 0264 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_CLOSE)); 0265 } 0266 0267 WorkerResult WorkerBase::mimetype(QUrl const &url) 0268 { 0269 return get(url); 0270 } 0271 0272 WorkerResult WorkerBase::rename(QUrl const &, QUrl const &, JobFlags) 0273 { 0274 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_RENAME)); 0275 } 0276 0277 WorkerResult WorkerBase::symlink(QString const &, QUrl const &, JobFlags) 0278 { 0279 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_SYMLINK)); 0280 } 0281 0282 WorkerResult WorkerBase::copy(QUrl const &, QUrl const &, int, JobFlags) 0283 { 0284 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_COPY)); 0285 } 0286 0287 WorkerResult WorkerBase::del(QUrl const &, bool) 0288 { 0289 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_DEL)); 0290 } 0291 0292 WorkerResult WorkerBase::mkdir(QUrl const &, int) 0293 { 0294 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_MKDIR)); 0295 } 0296 0297 WorkerResult WorkerBase::chmod(QUrl const &, int) 0298 { 0299 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_CHMOD)); 0300 } 0301 0302 WorkerResult WorkerBase::setModificationTime(QUrl const &, const QDateTime &) 0303 { 0304 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_SETMODIFICATIONTIME)); 0305 } 0306 0307 WorkerResult WorkerBase::chown(QUrl const &, const QString &, const QString &) 0308 { 0309 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_CHOWN)); 0310 } 0311 0312 WorkerResult WorkerBase::fileSystemFreeSpace(const QUrl &) 0313 { 0314 return WorkerResult::fail(ERR_UNSUPPORTED_ACTION, unsupportedActionErrorString(d->protocolName(), CMD_FILESYSTEMFREESPACE)); 0315 } 0316 0317 void WorkerBase::worker_status() 0318 { 0319 workerStatus(QString(), false); 0320 } 0321 0322 void WorkerBase::reparseConfiguration() 0323 { 0324 // base implementation called by bridge 0325 } 0326 0327 int WorkerBase::openPasswordDialog(AuthInfo &info, const QString &errorMsg) 0328 { 0329 return d->bridge.openPasswordDialogV2(info, errorMsg); 0330 } 0331 0332 int WorkerBase::messageBox(MessageBoxType type, const QString &text, const QString &title, const QString &primaryActionText, const QString &secondaryActionText) 0333 { 0334 return messageBox(text, type, title, primaryActionText, secondaryActionText, QString()); 0335 } 0336 0337 int WorkerBase::messageBox(const QString &text, 0338 MessageBoxType type, 0339 const QString &title, 0340 const QString &primaryActionText, 0341 const QString &secondaryActionText, 0342 const QString &dontAskAgainName) 0343 { 0344 return d->bridge.messageBox(text, static_cast<SlaveBase::MessageBoxType>(type), title, primaryActionText, secondaryActionText, dontAskAgainName); 0345 } 0346 0347 int WorkerBase::sslError(const QVariantMap &sslData) 0348 { 0349 return d->bridge.sslError(sslData); 0350 } 0351 0352 bool WorkerBase::canResume(KIO::filesize_t offset) 0353 { 0354 return d->bridge.canResume(offset); 0355 } 0356 0357 int WorkerBase::waitForAnswer(int expected1, int expected2, QByteArray &data, int *pCmd) 0358 { 0359 return d->bridge.waitForAnswer(expected1, expected2, data, pCmd); 0360 } 0361 0362 int WorkerBase::readData(QByteArray &buffer) 0363 { 0364 return d->bridge.readData(buffer); 0365 } 0366 0367 void WorkerBase::setTimeoutSpecialCommand(int timeout, const QByteArray &data) 0368 { 0369 d->bridge.setTimeoutSpecialCommand(timeout, data); 0370 } 0371 0372 bool WorkerBase::checkCachedAuthentication(AuthInfo &info) 0373 { 0374 return d->bridge.checkCachedAuthentication(info); 0375 } 0376 0377 bool WorkerBase::cacheAuthentication(const AuthInfo &info) 0378 { 0379 return d->bridge.cacheAuthentication(info); 0380 } 0381 0382 int WorkerBase::connectTimeout() 0383 { 0384 return d->bridge.connectTimeout(); 0385 } 0386 0387 int WorkerBase::proxyConnectTimeout() 0388 { 0389 return d->bridge.proxyConnectTimeout(); 0390 } 0391 0392 int WorkerBase::responseTimeout() 0393 { 0394 return d->bridge.responseTimeout(); 0395 } 0396 0397 int WorkerBase::readTimeout() 0398 { 0399 return d->bridge.readTimeout(); 0400 } 0401 0402 bool WorkerBase::wasKilled() const 0403 { 0404 return d->bridge.wasKilled(); 0405 } 0406 0407 void WorkerBase::lookupHost(const QString &host) 0408 { 0409 return d->bridge.lookupHost(host); 0410 } 0411 0412 int WorkerBase::waitForHostInfo(QHostInfo &info) 0413 { 0414 return d->bridge.waitForHostInfo(info); 0415 } 0416 0417 PrivilegeOperationStatus WorkerBase::requestPrivilegeOperation(const QString &operationDetails) 0418 { 0419 return d->bridge.requestPrivilegeOperation(operationDetails); 0420 } 0421 0422 void WorkerBase::addTemporaryAuthorization(const QString &action) 0423 { 0424 d->bridge.addTemporaryAuthorization(action); 0425 } 0426 0427 class WorkerResultPrivate 0428 { 0429 public: 0430 bool success; 0431 int error; 0432 QString errorString; 0433 }; 0434 0435 WorkerResult::~WorkerResult() = default; 0436 0437 WorkerResult::WorkerResult(const WorkerResult &rhs) 0438 : d(std::make_unique<WorkerResultPrivate>(*rhs.d)) 0439 { 0440 } 0441 0442 WorkerResult &WorkerResult::operator=(const WorkerResult &rhs) 0443 { 0444 if (this == &rhs) { 0445 return *this; 0446 } 0447 d = std::make_unique<WorkerResultPrivate>(*rhs.d); 0448 return *this; 0449 } 0450 0451 WorkerResult::WorkerResult(WorkerResult &&) noexcept = default; 0452 WorkerResult &WorkerResult::operator=(WorkerResult &&) noexcept = default; 0453 0454 bool WorkerResult::success() const 0455 { 0456 return d->success; 0457 } 0458 0459 int WorkerResult::error() const 0460 { 0461 return d->error; 0462 } 0463 0464 QString WorkerResult::errorString() const 0465 { 0466 return d->errorString; 0467 } 0468 0469 Q_REQUIRED_RESULT WorkerResult WorkerResult::fail(int _error, const QString &_errorString) 0470 { 0471 return WorkerResult(std::make_unique<WorkerResultPrivate>(WorkerResultPrivate{false, _error, _errorString})); 0472 } 0473 0474 Q_REQUIRED_RESULT WorkerResult WorkerResult::pass() 0475 { 0476 return WorkerResult(std::make_unique<WorkerResultPrivate>(WorkerResultPrivate{true, 0, QString()})); 0477 } 0478 0479 WorkerResult::WorkerResult(std::unique_ptr<WorkerResultPrivate> &&dptr) 0480 : d(std::move(dptr)) 0481 { 0482 } 0483 0484 void WorkerBase::setIncomingMetaData(const KIO::MetaData &metaData) 0485 { 0486 d->bridge.setIncomingMetaData(metaData); 0487 } 0488 } // namespace KIO