File indexing completed on 2024-09-15 03:38:34
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 2000 Stephan Kulow <coolo@kde.org> 0004 SPDX-FileCopyrightText: 2000-2009 David Faure <faure@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #include "mkdirjob.h" 0010 #include "job.h" 0011 #include "job_p.h" 0012 #include "kiocoredebug.h" 0013 #include <kurlauthorized.h> 0014 #include <worker_p.h> 0015 0016 using namespace KIO; 0017 0018 class KIO::MkdirJobPrivate : public SimpleJobPrivate 0019 { 0020 public: 0021 MkdirJobPrivate(const QUrl &url, int command, const QByteArray &packedArgs) 0022 : SimpleJobPrivate(url, command, packedArgs) 0023 { 0024 } 0025 QUrl m_redirectionURL; 0026 void slotRedirection(const QUrl &url); 0027 0028 /** 0029 * @internal 0030 * Called by the scheduler when a @p worker gets to 0031 * work on this job. 0032 * @param worker the worker that starts working on this job 0033 */ 0034 void start(Worker *worker) override; 0035 0036 Q_DECLARE_PUBLIC(MkdirJob) 0037 0038 static inline MkdirJob *newJob(const QUrl &url, int command, const QByteArray &packedArgs) 0039 { 0040 MkdirJob *job = new MkdirJob(*new MkdirJobPrivate(url, command, packedArgs)); 0041 job->setUiDelegate(KIO::createDefaultJobUiDelegate()); 0042 return job; 0043 } 0044 }; 0045 0046 MkdirJob::MkdirJob(MkdirJobPrivate &dd) 0047 : SimpleJob(dd) 0048 { 0049 } 0050 0051 MkdirJob::~MkdirJob() 0052 { 0053 } 0054 0055 void MkdirJobPrivate::start(Worker *worker) 0056 { 0057 Q_Q(MkdirJob); 0058 q->connect(worker, &KIO::WorkerInterface::redirection, q, [this](const QUrl &url) { 0059 slotRedirection(url); 0060 }); 0061 0062 SimpleJobPrivate::start(worker); 0063 } 0064 0065 // Worker got a redirection request 0066 void MkdirJobPrivate::slotRedirection(const QUrl &url) 0067 { 0068 Q_Q(MkdirJob); 0069 // qDebug() << url; 0070 if (!KUrlAuthorized::authorizeUrlAction(QStringLiteral("redirect"), m_url, url)) { 0071 qCWarning(KIO_CORE) << "Redirection from" << m_url << "to" << url << "REJECTED!"; 0072 q->setError(ERR_ACCESS_DENIED); 0073 q->setErrorText(url.toDisplayString()); 0074 return; 0075 } 0076 m_redirectionURL = url; // We'll remember that when the job finishes 0077 // Tell the user that we haven't finished yet 0078 Q_EMIT q->redirection(q, m_redirectionURL); 0079 } 0080 0081 void MkdirJob::slotFinished() 0082 { 0083 Q_D(MkdirJob); 0084 0085 if (!d->m_redirectionURL.isEmpty() && d->m_redirectionURL.isValid()) { 0086 // qDebug() << "MkdirJob: Redirection to " << m_redirectionURL; 0087 if (queryMetaData(QStringLiteral("permanent-redirect")) == QLatin1String("true")) { 0088 Q_EMIT permanentRedirection(this, d->m_url, d->m_redirectionURL); 0089 } 0090 0091 if (d->m_redirectionHandlingEnabled) { 0092 QUrl dummyUrl; 0093 int permissions; 0094 QDataStream istream(d->m_packedArgs); 0095 istream >> dummyUrl >> permissions; 0096 0097 d->m_packedArgs.truncate(0); 0098 QDataStream stream(&d->m_packedArgs, QIODevice::WriteOnly); 0099 stream << d->m_redirectionURL << permissions; 0100 0101 d->restartAfterRedirection(&d->m_redirectionURL); 0102 return; 0103 } 0104 } 0105 0106 // Return worker to the scheduler 0107 SimpleJob::slotFinished(); 0108 } 0109 0110 KIO::MkdirJob *KIO::mkdir(const QUrl &url, int permissions) 0111 { 0112 // qDebug() << "mkdir " << url; 0113 KIO_ARGS << url << permissions; 0114 return MkdirJobPrivate::newJob(url, CMD_MKDIR, packedArgs); 0115 } 0116 0117 #include "moc_mkdirjob.cpp"