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