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