• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KIO

  • kio
  • kio
davjob.cpp
Go to the documentation of this file.
1// -*- c++ -*-
2/* This file is part of the KDE libraries
3 Copyright (C) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#include "davjob.h"
22
23#include <kurl.h>
24
25#include <QtCore/QObject>
26#include <QtCore/QCharRef>
27#include <QtCore/QMutableStringListIterator>
28#include <QtCore/QPointer>
29#include <QtXml/QDomDocument>
30
31#include <sys/types.h>
32#include <sys/stat.h>
33
34#include <kdebug.h>
35#include <kio/http.h>
36
37#include "jobclasses.h"
38#include "global.h"
39#include "job.h"
40#include "job_p.h"
41
42#include "jobuidelegate.h"
43
44using namespace KIO;
45
47class KIO::DavJobPrivate: public KIO::TransferJobPrivate
48{
49public:
50 DavJobPrivate(const KUrl& url)
51 : TransferJobPrivate(url, KIO::CMD_SPECIAL, QByteArray(), QByteArray())
52 {}
53 QByteArray savedStaticData;
54 QByteArray str_response;
55 QDomDocument m_response;
56 //TransferJob *m_subJob;
57 //bool m_suspended;
58
59 Q_DECLARE_PUBLIC(DavJob)
60
61 static inline DavJob *newJob(const KUrl &url, int method, const QString &request,
62 JobFlags flags)
63 {
64 DavJob *job = new DavJob(*new DavJobPrivate(url), method, request);
65 job->setUiDelegate(new JobUiDelegate);
66 if (!(flags & HideProgressInfo))
67 KIO::getJobTracker()->registerJob(job);
68 return job;
69 }
70};
71
72DavJob::DavJob(DavJobPrivate &dd, int method, const QString &request)
73 : TransferJob(dd)
74{
75 // We couldn't set the args when calling the parent constructor,
76 // so do it now.
77 Q_D(DavJob);
78 QDataStream stream( &d->m_packedArgs, QIODevice::WriteOnly );
79 stream << (int) 7 << d->m_url << method;
80 // Same for static data
81 if ( ! request.isEmpty() ) {
82 d->staticData = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + request.toUtf8();
83 d->staticData.truncate( d->staticData.size() - 1 );
84 d->savedStaticData = d->staticData;
85 stream << static_cast<qint64>( d->staticData.size() );
86 }
87 else {
88 stream << static_cast<qint64>( -1 );
89 }
90}
91
92QDomDocument& DavJob::response()
93{
94 return d_func()->m_response;
95}
96
97void DavJob::slotData( const QByteArray& data )
98{
99 Q_D(DavJob);
100 if(d->m_redirectionURL.isEmpty() || !d->m_redirectionURL.isValid() || error()) {
101 unsigned int oldSize = d->str_response.size();
102 d->str_response.resize( oldSize + data.size() );
103 memcpy( d->str_response.data() + oldSize, data.data(), data.size() );
104 }
105}
106
107void DavJob::slotFinished()
108{
109 Q_D(DavJob);
110 // kDebug(7113) << d->str_response;
111 if (!d->m_redirectionURL.isEmpty() && d->m_redirectionURL.isValid() &&
112 (d->m_command == CMD_SPECIAL)) {
113 QDataStream istream( d->m_packedArgs );
114 int s_cmd, s_method;
115 qint64 s_size;
116 KUrl s_url;
117 istream >> s_cmd;
118 istream >> s_url;
119 istream >> s_method;
120 istream >> s_size;
121 // PROPFIND
122 if ( (s_cmd == 7) && (s_method == (int)KIO::DAV_PROPFIND) ) {
123 d->m_packedArgs.truncate(0);
124 QDataStream stream( &d->m_packedArgs, QIODevice::WriteOnly );
125 stream << (int)7 << d->m_redirectionURL << (int)KIO::DAV_PROPFIND << s_size;
126 }
127 } else if ( ! d->m_response.setContent( d->str_response, true ) ) {
128 // An error occurred parsing the XML response
129 QDomElement root = d->m_response.createElementNS( "DAV:", "error-report" );
130 d->m_response.appendChild( root );
131
132 QDomElement el = d->m_response.createElementNS( "DAV:", "offending-response" );
133 QDomText textnode = d->m_response.createTextNode( d->str_response );
134 el.appendChild( textnode );
135 root.appendChild( el );
136 }
137 // kDebug(7113) << d->m_response.toString();
138 TransferJob::slotFinished();
139 d->staticData = d->savedStaticData; // Need to send DAV request to this host too
140}
141
142/* Convenience methods */
143
144DavJob* KIO::davPropFind( const KUrl& url, const QDomDocument& properties, const QString &depth, JobFlags flags )
145{
146 DavJob *job = DavJobPrivate::newJob(url, (int) KIO::DAV_PROPFIND, properties.toString(), flags);
147 job->addMetaData( "davDepth", depth );
148 return job;
149}
150
151
152DavJob* KIO::davPropPatch( const KUrl& url, const QDomDocument& properties, JobFlags flags )
153{
154 return DavJobPrivate::newJob(url, (int) KIO::DAV_PROPPATCH, properties.toString(),
155 flags);
156}
157
158DavJob* KIO::davSearch( const KUrl& url, const QString& nsURI, const QString& qName, const QString& query, JobFlags flags )
159{
160 QDomDocument doc;
161 QDomElement searchrequest = doc.createElementNS( "DAV:", "searchrequest" );
162 QDomElement searchelement = doc.createElementNS( nsURI, qName );
163 QDomText text = doc.createTextNode( query );
164 searchelement.appendChild( text );
165 searchrequest.appendChild( searchelement );
166 doc.appendChild( searchrequest );
167 return DavJobPrivate::newJob(url, KIO::DAV_SEARCH, doc.toString(), flags);
168}
169
170DavJob* KIO::davReport( const KUrl& url, const QString& report, const QString &depth, JobFlags flags )
171{
172 DavJob *job = DavJobPrivate::newJob(url, (int) KIO::DAV_REPORT, report, flags);
173 job->addMetaData( "davDepth", depth );
174 return job;
175}
176
177#include "davjob.moc"
KIO::DavJob
The transfer job pumps data into and/or out of a Slave.
Definition: davjob.h:54
KIO::DavJob::slotFinished
virtual void slotFinished()
Definition: davjob.cpp:107
KIO::DavJob::DavJob
DavJob(DavJobPrivate &dd, int, const QString &)
Definition: davjob.cpp:72
KIO::DavJob::slotData
virtual void slotData(const QByteArray &data)
Definition: davjob.cpp:97
KIO::DavJob::response
QDomDocument & response()
Returns the response as a QDomDocument.
Definition: davjob.cpp:92
KIO::JobUiDelegate
A UI delegate tuned to be used with KIO Jobs.
Definition: jobuidelegate.h:40
KIO::Job::addMetaData
void addMetaData(const QString &key, const QString &value)
Add key/value pair to the meta data that is sent to the slave.
Definition: job.cpp:264
KIO::TransferJobPrivate
Definition: job_p.h:260
KIO::TransferJobPrivate::newJob
static TransferJob * newJob(const KUrl &url, int command, const QByteArray &packedArgs, const QByteArray &_staticData, JobFlags flags)
Definition: job_p.h:317
KIO::TransferJob
The transfer job pumps data into and/or out of a Slave.
Definition: jobclasses.h:555
KIO::TransferJob::data
void data(KIO::Job *job, const QByteArray &data)
Data from the slave has arrived.
KIO::TransferJob::slotFinished
virtual void slotFinished()
Definition: job.cpp:1043
KJobTrackerInterface::registerJob
virtual void registerJob(KJob *job)
KJob::error
int error() const
KJob::setUiDelegate
void setUiDelegate(KJobUiDelegate *delegate)
KUrl
davjob.h
global.h
job.h
job_p.h
jobclasses.h
jobuidelegate.h
kdebug.h
kurl.h
KIO
A namespace for KIO globals.
Definition: kbookmarkmenu.h:55
KIO::davPropFind
DavJob * davPropFind(const KUrl &url, const QDomDocument &properties, const QString &depth, JobFlags flags=DefaultFlags)
Creates a new DavJob that issues a PROPFIND command.
Definition: davjob.cpp:144
KIO::CMD_SPECIAL
@ CMD_SPECIAL
Definition: global.h:169
KIO::davReport
DavJob * davReport(const KUrl &url, const QString &report, const QString &depth, JobFlags flags=DefaultFlags)
Creates a new DavJob that issues a REPORT command.
Definition: davjob.cpp:170
KIO::davPropPatch
DavJob * davPropPatch(const KUrl &url, const QDomDocument &properties, JobFlags flags=DefaultFlags)
Creates a new DavJob that issues a PROPPATCH command.
Definition: davjob.cpp:152
KIO::HideProgressInfo
@ HideProgressInfo
Hide progress information dialog, i.e.
Definition: jobclasses.h:51
KIO::getJobTracker
KJobTrackerInterface * getJobTracker()
Definition: global.cpp:1246
KIO::davSearch
DavJob * davSearch(const KUrl &url, const QString &nsURI, const QString &qName, const QString &query, JobFlags flags=DefaultFlags)
Creates a new DavJob that issues a SEARCH command.
Definition: davjob.cpp:158
properties
KGuiItem properties()
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal