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
155void WorkerBase::errorPage()
156{
157 d->bridge.errorPage();
158}
159
160void WorkerBase::mimeType(const QString &_type)
161{
162 d->bridge.mimeType(_type);
163}
164
165void WorkerBase::exit()
166{
167 d->bridge.exit();
168}
169
170void WorkerBase::warning(const QString &_msg)
171{
172 d->bridge.warning(msg: _msg);
173}
174
175void WorkerBase::infoMessage(const QString &_msg)
176{
177 d->bridge.infoMessage(msg: _msg);
178}
179
180void WorkerBase::statEntry(const UDSEntry &entry)
181{
182 d->bridge.statEntry(entry: entry);
183}
184
185void WorkerBase::listEntry(const UDSEntry &entry)
186{
187 d->bridge.listEntry(entry);
188}
189
190void WorkerBase::listEntries(const UDSEntryList &list)
191{
192 d->bridge.listEntries(entry: list);
193}
194
195void WorkerBase::appConnectionMade()
196{
197} // No response!
198
199void WorkerBase::setHost(QString const &, quint16, QString const &, QString const &)
200{
201} // No response!
202
203WorkerResult WorkerBase::openConnection()
204{
205 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_CONNECT));
206}
207
208void WorkerBase::closeConnection()
209{
210} // No response!
211
212WorkerResult WorkerBase::stat(QUrl const &)
213{
214 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_STAT));
215}
216
217WorkerResult WorkerBase::put(QUrl const &, int, JobFlags)
218{
219 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_PUT));
220}
221
222WorkerResult WorkerBase::special(const QByteArray &)
223{
224 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_SPECIAL));
225}
226
227WorkerResult WorkerBase::listDir(QUrl const &)
228{
229 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_LISTDIR));
230}
231
232WorkerResult WorkerBase::get(QUrl const &)
233{
234 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_GET));
235}
236
237WorkerResult WorkerBase::open(QUrl const &, QIODevice::OpenMode)
238{
239 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_OPEN));
240}
241
242WorkerResult WorkerBase::read(KIO::filesize_t)
243{
244 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_READ));
245}
246
247WorkerResult WorkerBase::write(const QByteArray &)
248{
249 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_WRITE));
250}
251
252WorkerResult WorkerBase::seek(KIO::filesize_t)
253{
254 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_SEEK));
255}
256
257WorkerResult WorkerBase::truncate(KIO::filesize_t)
258{
259 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_TRUNCATE));
260}
261
262WorkerResult WorkerBase::close()
263{
264 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_CLOSE));
265}
266
267WorkerResult WorkerBase::mimetype(QUrl const &url)
268{
269 return get(url);
270}
271
272WorkerResult WorkerBase::rename(QUrl const &, QUrl const &, JobFlags)
273{
274 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_RENAME));
275}
276
277WorkerResult WorkerBase::symlink(QString const &, QUrl const &, JobFlags)
278{
279 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_SYMLINK));
280}
281
282WorkerResult WorkerBase::copy(QUrl const &, QUrl const &, int, JobFlags)
283{
284 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_COPY));
285}
286
287WorkerResult WorkerBase::del(QUrl const &, bool)
288{
289 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_DEL));
290}
291
292WorkerResult WorkerBase::mkdir(QUrl const &, int)
293{
294 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_MKDIR));
295}
296
297WorkerResult WorkerBase::chmod(QUrl const &, int)
298{
299 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_CHMOD));
300}
301
302WorkerResult WorkerBase::setModificationTime(QUrl const &, const QDateTime &)
303{
304 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_SETMODIFICATIONTIME));
305}
306
307WorkerResult WorkerBase::chown(QUrl const &, const QString &, const QString &)
308{
309 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_CHOWN));
310}
311
312WorkerResult WorkerBase::fileSystemFreeSpace(const QUrl &)
313{
314 return WorkerResult::fail(error: ERR_UNSUPPORTED_ACTION, errorString: unsupportedActionErrorString(protocol: d->protocolName(), cmd: CMD_FILESYSTEMFREESPACE));
315}
316
317void WorkerBase::worker_status()
318{
319 workerStatus(host: QString(), connected: false);
320}
321
322void WorkerBase::reparseConfiguration()
323{
324 // base implementation called by bridge
325}
326
327int WorkerBase::openPasswordDialog(AuthInfo &info, const QString &errorMsg)
328{
329 return d->bridge.openPasswordDialogV2(info, errorMsg);
330}
331
332int WorkerBase::messageBox(MessageBoxType type, const QString &text, const QString &title, const QString &primaryActionText, const QString &secondaryActionText)
333{
334 return messageBox(text, type, title, primaryActionText, secondaryActionText, dontAskAgainName: QString());
335}
336
337int WorkerBase::messageBox(const QString &text,
338 MessageBoxType type,
339 const QString &title,
340 const QString &primaryActionText,
341 const QString &secondaryActionText,
342 const QString &dontAskAgainName)
343{
344 return d->bridge.messageBox(text, type: static_cast<SlaveBase::MessageBoxType>(type), title, primaryActionText, secondaryActionText, dontAskAgainName);
345}
346
347int WorkerBase::sslError(const QVariantMap &sslData)
348{
349 return d->bridge.sslError(sslData);
350}
351
352bool WorkerBase::canResume(KIO::filesize_t offset)
353{
354 return d->bridge.canResume(offset);
355}
356
357int WorkerBase::waitForAnswer(int expected1, int expected2, QByteArray &data, int *pCmd)
358{
359 return d->bridge.waitForAnswer(expected1, expected2, data, pCmd);
360}
361
362int WorkerBase::readData(QByteArray &buffer)
363{
364 return d->bridge.readData(buffer);
365}
366
367void WorkerBase::setTimeoutSpecialCommand(int timeout, const QByteArray &data)
368{
369 d->bridge.setTimeoutSpecialCommand(timeout, data);
370}
371
372bool WorkerBase::checkCachedAuthentication(AuthInfo &info)
373{
374 return d->bridge.checkCachedAuthentication(info);
375}
376
377bool WorkerBase::cacheAuthentication(const AuthInfo &info)
378{
379 return d->bridge.cacheAuthentication(info);
380}
381
382int WorkerBase::connectTimeout()
383{
384 return d->bridge.connectTimeout();
385}
386
387int WorkerBase::proxyConnectTimeout()
388{
389 return d->bridge.proxyConnectTimeout();
390}
391
392int WorkerBase::responseTimeout()
393{
394 return d->bridge.responseTimeout();
395}
396
397int WorkerBase::readTimeout()
398{
399 return d->bridge.readTimeout();
400}
401
402bool WorkerBase::wasKilled() const
403{
404 return d->bridge.wasKilled();
405}
406
407void WorkerBase::lookupHost(const QString &host)
408{
409 return d->bridge.lookupHost(host);
410}
411
412int WorkerBase::waitForHostInfo(QHostInfo &info)
413{
414 return d->bridge.waitForHostInfo(info);
415}
416
417PrivilegeOperationStatus WorkerBase::requestPrivilegeOperation(const QString &operationDetails)
418{
419 return d->bridge.requestPrivilegeOperation(operationDetails);
420}
421
422void WorkerBase::addTemporaryAuthorization(const QString &action)
423{
424 d->bridge.addTemporaryAuthorization(action);
425}
426
427class WorkerResultPrivate
428{
429public:
430 bool success;
431 int error;
432 QString errorString;
433};
434
435WorkerResult::~WorkerResult() = default;
436
437WorkerResult::WorkerResult(const WorkerResult &rhs)
438 : d(std::make_unique<WorkerResultPrivate>(args&: *rhs.d))
439{
440}
441
442WorkerResult &WorkerResult::operator=(const WorkerResult &rhs)
443{
444 if (this == &rhs) {
445 return *this;
446 }
447 d = std::make_unique<WorkerResultPrivate>(args&: *rhs.d);
448 return *this;
449}
450
451WorkerResult::WorkerResult(WorkerResult &&) noexcept = default;
452WorkerResult &WorkerResult::operator=(WorkerResult &&) noexcept = default;
453
454bool WorkerResult::success() const
455{
456 return d->success;
457}
458
459int WorkerResult::error() const
460{
461 return d->error;
462}
463
464QString WorkerResult::errorString() const
465{
466 return d->errorString;
467}
468
469Q_REQUIRED_RESULT WorkerResult WorkerResult::fail(int _error, const QString &_errorString)
470{
471 return WorkerResult(std::make_unique<WorkerResultPrivate>(args: WorkerResultPrivate{.success: false, .error: _error, .errorString: _errorString}));
472}
473
474Q_REQUIRED_RESULT WorkerResult WorkerResult::pass()
475{
476 return WorkerResult(std::make_unique<WorkerResultPrivate>(args: WorkerResultPrivate{.success: true, .error: 0, .errorString: QString()}));
477}
478
479WorkerResult::WorkerResult(std::unique_ptr<WorkerResultPrivate> &&dptr)
480 : d(std::move(dptr))
481{
482}
483
484void WorkerBase::setIncomingMetaData(const KIO::MetaData &metaData)
485{
486 d->bridge.setIncomingMetaData(metaData);
487}
488} // namespace KIO
489

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