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

KIO

davjob.cpp
Go to the documentation of this file.
00001 // -*- c++ -*-
00002 /* This file is part of the KDE libraries
00003     Copyright (C) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018     Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "davjob.h"
00022 
00023 #include <kurl.h>
00024 
00025 #include <QtCore/QObject>
00026 #include <QtCore/QCharRef>
00027 #include <QtCore/QMutableStringListIterator>
00028 #include <QtCore/QPointer>
00029 #include <QtXml/QDomDocument>
00030 
00031 #include <sys/types.h>
00032 #include <sys/stat.h>
00033 
00034 #include <kdebug.h>
00035 #include <kio/http.h>
00036 
00037 #include "jobclasses.h"
00038 #include "global.h"
00039 #include "job.h"
00040 #include "job_p.h"
00041 
00042 #include "jobuidelegate.h"
00043 
00044 using namespace KIO;
00045 
00047 class KIO::DavJobPrivate: public KIO::TransferJobPrivate
00048 {
00049 public:
00050     DavJobPrivate(const KUrl& url)
00051         : TransferJobPrivate(url, KIO::CMD_SPECIAL, QByteArray(), QByteArray())
00052         {}
00053     QByteArray savedStaticData;
00054     QByteArray str_response;
00055     QDomDocument m_response;
00056     //TransferJob *m_subJob;
00057     //bool m_suspended;
00058 
00059     Q_DECLARE_PUBLIC(DavJob)
00060 
00061     static inline DavJob *newJob(const KUrl &url, int method, const QString &request,
00062                                  JobFlags flags)
00063     {
00064         DavJob *job = new DavJob(*new DavJobPrivate(url), method, request);
00065         job->setUiDelegate(new JobUiDelegate);
00066         if (!(flags & HideProgressInfo))
00067             KIO::getJobTracker()->registerJob(job);
00068         return job;
00069     }
00070 };
00071 
00072 DavJob::DavJob(DavJobPrivate &dd, int method, const QString &request)
00073     : TransferJob(dd)
00074 {
00075   // We couldn't set the args when calling the parent constructor,
00076   // so do it now.
00077   Q_D(DavJob);
00078   QDataStream stream( &d->m_packedArgs, QIODevice::WriteOnly );
00079   stream << (int) 7 << d->m_url << method;
00080   // Same for static data
00081   if ( ! request.isEmpty() ) {
00082     d->staticData = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + request.toUtf8();
00083     d->staticData.truncate( d->staticData.size() - 1 );
00084     d->savedStaticData = d->staticData;
00085     stream << static_cast<qint64>( d->staticData.size() );
00086   }
00087   else {
00088     stream << static_cast<qint64>( -1 );
00089   }
00090 }
00091 
00092 QDomDocument& DavJob::response()
00093 {
00094     return d_func()->m_response;
00095 }
00096 
00097 void DavJob::slotData( const QByteArray& data )
00098 {
00099   Q_D(DavJob);
00100   if(d->m_redirectionURL.isEmpty() || !d->m_redirectionURL.isValid() || error()) {
00101     unsigned int oldSize = d->str_response.size();
00102     d->str_response.resize( oldSize + data.size() );
00103     memcpy( d->str_response.data() + oldSize, data.data(), data.size() );
00104   }
00105 }
00106 
00107 void DavJob::slotFinished()
00108 {
00109   Q_D(DavJob);
00110   // kDebug(7113) << d->str_response;
00111     if (!d->m_redirectionURL.isEmpty() && d->m_redirectionURL.isValid() &&
00112             (d->m_command == CMD_SPECIAL)) {
00113         QDataStream istream( d->m_packedArgs );
00114         int s_cmd, s_method;
00115     qint64 s_size;
00116         KUrl s_url;
00117         istream >> s_cmd;
00118         istream >> s_url;
00119         istream >> s_method;
00120     istream >> s_size;
00121         // PROPFIND
00122         if ( (s_cmd == 7) && (s_method == (int)KIO::DAV_PROPFIND) ) {
00123             d->m_packedArgs.truncate(0);
00124             QDataStream stream( &d->m_packedArgs, QIODevice::WriteOnly );
00125             stream << (int)7 << d->m_redirectionURL << (int)KIO::DAV_PROPFIND << s_size;
00126         }
00127   } else if ( ! d->m_response.setContent( d->str_response, true ) ) {
00128         // An error occurred parsing the XML response
00129         QDomElement root = d->m_response.createElementNS( "DAV:", "error-report" );
00130         d->m_response.appendChild( root );
00131 
00132         QDomElement el = d->m_response.createElementNS( "DAV:", "offending-response" );
00133     QDomText textnode = d->m_response.createTextNode( d->str_response );
00134         el.appendChild( textnode );
00135         root.appendChild( el );
00136     }
00137   // kDebug(7113) << d->m_response.toString();
00138     TransferJob::slotFinished();
00139     d->staticData = d->savedStaticData; // Need to send DAV request to this host too
00140 }
00141 
00142 /* Convenience methods */
00143 
00144 DavJob* KIO::davPropFind( const KUrl& url, const QDomDocument& properties, const QString &depth, JobFlags flags )
00145 {
00146     DavJob *job = DavJobPrivate::newJob(url, (int) KIO::DAV_PROPFIND, properties.toString(), flags);
00147     job->addMetaData( "davDepth", depth );
00148     return job;
00149 }
00150 
00151 
00152 DavJob* KIO::davPropPatch( const KUrl& url, const QDomDocument& properties, JobFlags flags )
00153 {
00154     return DavJobPrivate::newJob(url, (int) KIO::DAV_PROPPATCH, properties.toString(),
00155                                  flags);
00156 }
00157 
00158 DavJob* KIO::davSearch( const KUrl& url, const QString& nsURI, const QString& qName, const QString& query, JobFlags flags )
00159 {
00160   QDomDocument doc;
00161   QDomElement searchrequest = doc.createElementNS( "DAV:", "searchrequest" );
00162   QDomElement searchelement = doc.createElementNS( nsURI, qName );
00163   QDomText text = doc.createTextNode( query );
00164   searchelement.appendChild( text );
00165   searchrequest.appendChild( searchelement );
00166   doc.appendChild( searchrequest );
00167   return DavJobPrivate::newJob(url, KIO::DAV_SEARCH, doc.toString(), flags);
00168 }
00169 
00170 DavJob* KIO::davReport( const KUrl& url, const QString& report, const QString &depth, JobFlags flags )
00171 {
00172     DavJob *job = DavJobPrivate::newJob(url, (int) KIO::DAV_REPORT, report, flags);
00173     job->addMetaData( "davDepth", depth );
00174     return job;
00175 }
00176 
00177 #include "davjob.moc"

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

Skip menu "kdelibs"
  • 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
Generated for kdelibs by doxygen 1.7.5
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal