KIO

mkdirjob.cpp
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 2000 Stephan Kulow <[email protected]>
4  SPDX-FileCopyrightText: 2000-2009 David Faure <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #include "mkdirjob.h"
10 #include "job.h"
11 #include "job_p.h"
12 #include "kiocoredebug.h"
13 #include <kurlauthorized.h>
14 #include <slave.h>
15 
16 using namespace KIO;
17 
18 class KIO::MkdirJobPrivate : public SimpleJobPrivate
19 {
20 public:
21  MkdirJobPrivate(const QUrl &url, int command, const QByteArray &packedArgs)
22  : SimpleJobPrivate(url, command, packedArgs)
23  {
24  }
25  QUrl m_redirectionURL;
26  void slotRedirection(const QUrl &url);
27 
28  /**
29  * @internal
30  * Called by the scheduler when a @p slave gets to
31  * work on this job.
32  * @param slave the slave that starts working on this job
33  */
34  void start(Slave *slave) override;
35 
36  Q_DECLARE_PUBLIC(MkdirJob)
37 
38  static inline MkdirJob *newJob(const QUrl &url, int command, const QByteArray &packedArgs)
39  {
40  MkdirJob *job = new MkdirJob(*new MkdirJobPrivate(url, command, packedArgs));
42  return job;
43  }
44 };
45 
46 MkdirJob::MkdirJob(MkdirJobPrivate &dd)
47  : SimpleJob(dd)
48 {
49 }
50 
51 MkdirJob::~MkdirJob()
52 {
53 }
54 
55 void MkdirJobPrivate::start(Slave *slave)
56 {
57  Q_Q(MkdirJob);
58  q->connect(slave, &KIO::SlaveInterface::redirection, q, [this](const QUrl &url) {
59  slotRedirection(url);
60  });
61 
63 }
64 
65 // Worker got a redirection request
66 void MkdirJobPrivate::slotRedirection(const QUrl &url)
67 {
68  Q_Q(MkdirJob);
69  // qDebug() << url;
70  if (!KUrlAuthorized::authorizeUrlAction(QStringLiteral("redirect"), m_url, url)) {
71  qCWarning(KIO_CORE) << "Redirection from" << m_url << "to" << url << "REJECTED!";
72  q->setError(ERR_ACCESS_DENIED);
73  q->setErrorText(url.toDisplayString());
74  return;
75  }
76  m_redirectionURL = url; // We'll remember that when the job finishes
77  // Tell the user that we haven't finished yet
78  Q_EMIT q->redirection(q, m_redirectionURL);
79 }
80 
81 void MkdirJob::slotFinished()
82 {
83  Q_D(MkdirJob);
84 
85  if (!d->m_redirectionURL.isEmpty() && d->m_redirectionURL.isValid()) {
86  // qDebug() << "MkdirJob: Redirection to " << m_redirectionURL;
87  if (queryMetaData(QStringLiteral("permanent-redirect")) == QLatin1String("true")) {
88  Q_EMIT permanentRedirection(this, d->m_url, d->m_redirectionURL);
89  }
90 
91  if (d->m_redirectionHandlingEnabled) {
92  QUrl dummyUrl;
93  int permissions;
94  QDataStream istream(d->m_packedArgs);
95  istream >> dummyUrl >> permissions;
96 
97  d->m_packedArgs.truncate(0);
98  QDataStream stream(&d->m_packedArgs, QIODevice::WriteOnly);
99  stream << d->m_redirectionURL << permissions;
100 
101  d->restartAfterRedirection(&d->m_redirectionURL);
102  return;
103  }
104  }
105 
106  // Return slave to the scheduler
108 }
109 
110 KIO::MkdirJob *KIO::mkdir(const QUrl &url, int permissions)
111 {
112  // qDebug() << "mkdir " << url;
113  KIO_ARGS << url << permissions;
114  return MkdirJobPrivate::newJob(url, CMD_MKDIR, packedArgs);
115 }
116 
117 #include "moc_mkdirjob.cpp"
Q_EMITQ_EMIT
Q_SCRIPTABLE Q_NOREPLY void start()
bool authorizeUrlAction(const QString &action, const QUrl &baseURL, const QUrl &destURL)
Returns whether a certain URL related action is authorized.
QString queryMetaData(const QString &key)
Query meta data received from the worker.
Definition: job.cpp:217
virtual void slotFinished()
Called when the worker marks the job as finished.
Definition: simplejob.cpp:200
KIOCORE_EXPORT KJobUiDelegate * createDefaultJobUiDelegate()
Convenience method: use default factory, if there's one, to create a delegate and return it.
void setUiDelegate(KJobUiDelegate *delegate)
A namespace for KIO globals.
void permanentRedirection(KIO::Job *job, const QUrl &fromUrl, const QUrl &toUrl)
Signals a permanent redirection.
Q_D(Todo)
KIOCORE_EXPORT MkdirJob * mkdir(const QUrl &url, int permissions=-1)
Creates a single directory.
Definition: mkdirjob.cpp:110
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Nov 30 2023 03:52:31 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.