1/*
2 SPDX-License-Identifier: LGPL-2.0-or-later
3 SPDX-FileCopyrightText: 2000 Waldo Bastian <bastian@kde.org>
4 SPDX-FileCopyrightText: 2000 David Faure <faure@kde.org>
5 SPDX-FileCopyrightText: 2000 Stephan Kulow <coolo@kde.org>
6 SPDX-FileCopyrightText: 2007 Thiago Macieira <thiago@kde.org>
7 SPDX-FileCopyrightText: 2019-2022 Harald Sitter <sitter@kde.org>
8*/
9
10#include "workerbase.h"
11#include "workerbase_p.h"
12
13#include <commands_p.h>
14
15namespace KIO
16{
17
18WorkerBase::WorkerBase(const QByteArray &protocol, const QByteArray &poolSocket, const QByteArray &appSocket)
19 : d(new WorkerBasePrivate(protocol, poolSocket, appSocket, this))
20{
21}
22
23WorkerBase::~WorkerBase() = default;
24
25void WorkerBase::dispatchLoop()
26{
27 d->bridge.dispatchLoop();
28}
29
30void WorkerBase::connectWorker(const QString &address)
31{
32 d->bridge.connectSlave(path: address);
33}
34
35void WorkerBase::disconnectWorker()
36{
37 d->bridge.disconnectSlave();
38}
39
40void WorkerBase::setMetaData(const QString &key, const QString &value)
41{
42 d->bridge.setMetaData(key, value);
43}
44
45QString WorkerBase::metaData(const QString &key) const
46{
47 return d->bridge.metaData(key);
48}
49
50MetaData WorkerBase::allMetaData() const
51{
52 return d->bridge.allMetaData();
53}
54
55bool WorkerBase::hasMetaData(const QString &key) const
56{
57 return d->bridge.hasMetaData(key);
58}
59
60QMap<QString, QVariant> WorkerBase::mapConfig() const
61{
62 return d->bridge.mapConfig();
63}
64
65bool WorkerBase::configValue(const QString &key, bool defaultValue) const
66{
67 return d->bridge.configValue(key, defaultValue);
68}
69
70int WorkerBase::configValue(const QString &key, int defaultValue) const
71{
72 return d->bridge.configValue(key, defaultValue);
73}
74
75QString WorkerBase::configValue(const QString &key, const QString &defaultValue) const
76{
77 return d->bridge.configValue(key, defaultValue);
78}
79
80KConfigGroup *WorkerBase::config()
81{
82 return d->bridge.config();
83}
84
85void WorkerBase::sendMetaData()
86{
87 d->bridge.sendMetaData();
88}
89
90void WorkerBase::sendAndKeepMetaData()
91{
92 d->bridge.sendAndKeepMetaData();
93}
94
95KRemoteEncoding *WorkerBase::remoteEncoding()
96{
97 return d->bridge.remoteEncoding();
98}
99
100void WorkerBase::data(const QByteArray &data)
101{
102 d->bridge.data(data);
103}
104
105void WorkerBase::dataReq()
106{
107 d->bridge.dataReq();
108}
109
110void WorkerBase::workerStatus(const QString &host, bool connected)
111{
112 d->bridge.slaveStatus(host, connected);
113}
114
115void WorkerBase::canResume()
116{
117 d->bridge.canResume();
118}
119
120void WorkerBase::totalSize(KIO::filesize_t _bytes)
121{
122 d->bridge.totalSize(_bytes);
123}
124
125void WorkerBase::processedSize(KIO::filesize_t _bytes)
126{
127 d->bridge.processedSize(_bytes);
128}
129
130void WorkerBase::written(KIO::filesize_t _bytes)
131{
132 d->bridge.written(_bytes);
133}
134
135void WorkerBase::position(KIO::filesize_t _pos)
136{
137 d->bridge.position(_pos);
138}
139
140void WorkerBase::truncated(KIO::filesize_t _length)
141{
142 d->bridge.truncated(_length);
143}
144
145void WorkerBase::speed(unsigned long _bytes_per_second)
146{
147 d->bridge.speed(_bytes_per_second);
148}
149
150void WorkerBase::redirection(const QUrl &_url)
151{
152 d->bridge.redirection(_url);
153}
154
155#if KIOCORE_BUILD_DEPRECATED_SINCE(6, 3)
156void WorkerBase::errorPage()
157{
158}
159#endif
160
161void WorkerBase::mimeType(const QString &_type)
162{
163 d->bridge.mimeType(_type);
164}
165
166void WorkerBase::exit()
167{
168 d->bridge.exit();
169}
170
171void WorkerBase::warning(const QString &_msg)
172{
173 d->bridge.warning(msg: _msg);
174}
175
176void WorkerBase::infoMessage(const QString &_msg)
177{
178 d->bridge.infoMessage(msg: _msg);
179}
180
181void WorkerBase::statEntry(const UDSEntry &entry)
182{
183 d->bridge.statEntry(entry: entry);
184}
185
186void WorkerBase::listEntry(const UDSEntry &entry)
187{
188 d->bridge.listEntry(entry);
189}
190
191void WorkerBase::listEntries(const UDSEntryList &list)
192{
193 d->bridge.listEntries(entry: list);
194}
195
196void WorkerBase::appConnectionMade()
197{
198} // No response!
199
200void WorkerBase::setHost(QString const &, quint16, QString const &, QString const &)
201{
202} // No response!
203
204WorkerResult WorkerBase::openConnection()
205{
206 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_CONNECT));
207}
208
209void WorkerBase::closeConnection()
210{
211} // No response!
212
213WorkerResult WorkerBase::stat(QUrl const &)
214{
215 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_STAT));
216}
217
218WorkerResult WorkerBase::put(QUrl const &, int, JobFlags)
219{
220 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_PUT));
221}
222
223WorkerResult WorkerBase::special(const QByteArray &)
224{
225 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_SPECIAL));
226}
227
228WorkerResult WorkerBase::listDir(QUrl const &)
229{
230 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_LISTDIR));
231}
232
233WorkerResult WorkerBase::get(QUrl const &)
234{
235 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_GET));
236}
237
238WorkerResult WorkerBase::open(QUrl const &, QIODevice::OpenMode)
239{
240 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_OPEN));
241}
242
243WorkerResult WorkerBase::read(KIO::filesize_t)
244{
245 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_READ));
246}
247
248WorkerResult WorkerBase::write(const QByteArray &)
249{
250 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_WRITE));
251}
252
253WorkerResult WorkerBase::seek(KIO::filesize_t)
254{
255 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_SEEK));
256}
257
258WorkerResult WorkerBase::truncate(KIO::filesize_t)
259{
260 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_TRUNCATE));
261}
262
263WorkerResult WorkerBase::close()
264{
265 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_CLOSE));
266}
267
268WorkerResult WorkerBase::mimetype(QUrl const &url)
269{
270 return get(url);
271}
272
273WorkerResult WorkerBase::rename(QUrl const &, QUrl const &, JobFlags)
274{
275 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_RENAME));
276}
277
278WorkerResult WorkerBase::symlink(QString const &, QUrl const &, JobFlags)
279{
280 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_SYMLINK));
281}
282
283WorkerResult WorkerBase::copy(QUrl const &, QUrl const &, int, JobFlags)
284{
285 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_COPY));
286}
287
288WorkerResult WorkerBase::del(QUrl const &, bool)
289{
290 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_DEL));
291}
292
293WorkerResult WorkerBase::mkdir(QUrl const &, int)
294{
295 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_MKDIR));
296}
297
298WorkerResult WorkerBase::chmod(QUrl const &, int)
299{
300 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_CHMOD));
301}
302
303WorkerResult WorkerBase::setModificationTime(QUrl const &, const QDateTime &)
304{
305 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_SETMODIFICATIONTIME));
306}
307
308WorkerResult WorkerBase::chown(QUrl const &, const QString &, const QString &)
309{
310 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_CHOWN));
311}
312
313WorkerResult WorkerBase::fileSystemFreeSpace(const QUrl &)
314{
315 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_FILESYSTEMFREESPACE));
316}
317
318void WorkerBase::worker_status()
319{
320 workerStatus(host: QString(), connected: false);
321}
322
323void WorkerBase::reparseConfiguration()
324{
325 // base implementation called by bridge
326}
327
328int WorkerBase::openPasswordDialog(AuthInfo &info, const QString &errorMsg)
329{
330 return d->bridge.openPasswordDialogV2(info, errorMsg);
331}
332
333int WorkerBase::messageBox(MessageBoxType type, const QString &text, const QString &title, const QString &primaryActionText, const QString &secondaryActionText)
334{
335 return messageBox(text, type, title, primaryActionText, secondaryActionText, dontAskAgainName: QString());
336}
337
338int WorkerBase::messageBox(const QString &text,
339 MessageBoxType type,
340 const QString &title,
341 const QString &primaryActionText,
342 const QString &secondaryActionText,
343 const QString &dontAskAgainName)
344{
345 return d->bridge.messageBox(text, type: static_cast<SlaveBase::MessageBoxType>(type), title, primaryActionText, secondaryActionText, dontAskAgainName);
346}
347
348int WorkerBase::sslError(const QVariantMap &sslData)
349{
350 return d->bridge.sslError(sslData);
351}
352
353bool WorkerBase::canResume(KIO::filesize_t offset)
354{
355 return d->bridge.canResume(offset);
356}
357
358int WorkerBase::waitForAnswer(int expected1, int expected2, QByteArray &data, int *pCmd)
359{
360 return d->bridge.waitForAnswer(expected1, expected2, data, pCmd);
361}
362
363int WorkerBase::readData(QByteArray &buffer)
364{
365 return d->bridge.readData(buffer);
366}
367
368void WorkerBase::setTimeoutSpecialCommand(int timeout, const QByteArray &data)
369{
370 d->bridge.setTimeoutSpecialCommand(timeout, data);
371}
372
373bool WorkerBase::checkCachedAuthentication(AuthInfo &info)
374{
375 return d->bridge.checkCachedAuthentication(info);
376}
377
378bool WorkerBase::cacheAuthentication(const AuthInfo &info)
379{
380 return d->bridge.cacheAuthentication(info);
381}
382
383#if KIOCORE_BUILD_DEPRECATED_SINCE(6, 11)
384int WorkerBase::connectTimeout()
385{
386 return d->bridge.connectTimeout();
387}
388#endif
389
390#if KIOCORE_BUILD_DEPRECATED_SINCE(6, 11)
391int WorkerBase::proxyConnectTimeout()
392{
393 return d->bridge.proxyConnectTimeout();
394}
395#endif
396
397#if KIOCORE_BUILD_DEPRECATED_SINCE(6, 11)
398int WorkerBase::responseTimeout()
399{
400 return d->bridge.responseTimeout();
401}
402#endif
403
404#if KIOCORE_BUILD_DEPRECATED_SINCE(6, 11)
405int WorkerBase::readTimeout()
406{
407 return d->bridge.readTimeout();
408}
409#endif
410
411bool WorkerBase::wasKilled() const
412{
413 return d->bridge.wasKilled();
414}
415
416void WorkerBase::lookupHost(const QString &host)
417{
418 return d->bridge.lookupHost(host);
419}
420
421int WorkerBase::waitForHostInfo(QHostInfo &info)
422{
423 return d->bridge.waitForHostInfo(info);
424}
425
426PrivilegeOperationStatus WorkerBase::requestPrivilegeOperation(const QString &operationDetails)
427{
428 return d->bridge.requestPrivilegeOperation(operationDetails);
429}
430
431void WorkerBase::addTemporaryAuthorization(const QString &action)
432{
433 d->bridge.addTemporaryAuthorization(action);
434}
435
436class WorkerResultPrivate
437{
438public:
439 bool success;
440 int error;
441 QString errorString;
442};
443
444WorkerResult::~WorkerResult() = default;
445
446WorkerResult::WorkerResult(const WorkerResult &rhs)
447 : d(std::make_unique<WorkerResultPrivate>(args&: *rhs.d))
448{
449}
450
451WorkerResult &WorkerResult::operator=(const WorkerResult &rhs)
452{
453 if (this == &rhs) {
454 return *this;
455 }
456 d = std::make_unique<WorkerResultPrivate>(args&: *rhs.d);
457 return *this;
458}
459
460WorkerResult::WorkerResult(WorkerResult &&) noexcept = default;
461WorkerResult &WorkerResult::operator=(WorkerResult &&) noexcept = default;
462
463bool WorkerResult::success() const
464{
465 return d->success;
466}
467
468int WorkerResult::error() const
469{
470 return d->error;
471}
472
473QString WorkerResult::errorString() const
474{
475 return d->errorString;
476}
477
478Q_REQUIRED_RESULT WorkerResult WorkerResult::fail(int _error, const QString &_errorString)
479{
480 return WorkerResult(std::make_unique<WorkerResultPrivate>(args: WorkerResultPrivate{.success: false, .error: _error, .errorString: _errorString}));
481}
482
483Q_REQUIRED_RESULT WorkerResult WorkerResult::pass()
484{
485 return WorkerResult(std::make_unique<WorkerResultPrivate>(args: WorkerResultPrivate{.success: true, .error: 0, .errorString: QString()}));
486}
487
488WorkerResult::WorkerResult(std::unique_ptr<WorkerResultPrivate> &&dptr)
489 : d(std::move(dptr))
490{
491}
492
493void WorkerBase::setIncomingMetaData(const KIO::MetaData &metaData)
494{
495 d->bridge.setIncomingMetaData(metaData);
496}
497} // namespace KIO
498

source code of kio/src/core/workerbase.cpp