• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • 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 <kuiserverjobtracker.h>
00036 #include <kio/http.h>
00037 
00038 #include "jobclasses.h"
00039 #include "global.h"
00040 #include "job.h"
00041 #include "job_p.h"
00042 
00043 #include "jobuidelegate.h"
00044 
00045 using namespace KIO;
00046 
00048 class KIO::DavJobPrivate: public KIO::TransferJobPrivate
00049 {
00050 public:
00051     DavJobPrivate(const KUrl& url)
00052         : TransferJobPrivate(url, KIO::CMD_SPECIAL, QByteArray(), QByteArray())
00053         {}
00054     QByteArray savedStaticData;
00055     QByteArray str_response;
00056     QDomDocument m_response;
00057     //TransferJob *m_subJob;
00058     //bool m_suspended;
00059 
00060     Q_DECLARE_PUBLIC(DavJob)
00061 
00062     static inline DavJob *newJob(const KUrl &url, int method, const QString &request,
00063                                  JobFlags flags)
00064     {
00065         DavJob *job = new DavJob(*new DavJobPrivate(url), method, request);
00066         job->setUiDelegate(new JobUiDelegate);
00067         if (!(flags & HideProgressInfo))
00068             KIO::getJobTracker()->registerJob(job);
00069         return job;
00070     }
00071 };
00072 
00073 DavJob::DavJob(DavJobPrivate &dd, int method, const QString &request)
00074     : TransferJob(dd)
00075 {
00076   // We couldn't set the args when calling the parent constructor,
00077   // so do it now.
00078   Q_D(DavJob);
00079   QDataStream stream( &d->m_packedArgs, QIODevice::WriteOnly );
00080   stream << (int) 7 << d->m_url << method;
00081   // Same for static data
00082   if ( ! request.isEmpty() ) {
00083     d->staticData = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + request.toUtf8();
00084     d->staticData.truncate( d->staticData.size() - 1 );
00085     d->savedStaticData = d->staticData;
00086   }
00087 }
00088 
00089 QDomDocument& DavJob::response()
00090 {
00091     return d_func()->m_response;
00092 }
00093 
00094 void DavJob::slotData( const QByteArray& data )
00095 {
00096   Q_D(DavJob);
00097   if(d->m_redirectionURL.isEmpty() || !d->m_redirectionURL.isValid() || error()) {
00098     unsigned int oldSize = d->str_response.size();
00099     d->str_response.resize( oldSize + data.size() );
00100     memcpy( d->str_response.data() + oldSize, data.data(), data.size() );
00101   }
00102 }
00103 
00104 void DavJob::slotFinished()
00105 {
00106   Q_D(DavJob);
00107   // kDebug(7113) << d->str_response;
00108     if (!d->m_redirectionURL.isEmpty() && d->m_redirectionURL.isValid() &&
00109             (d->m_command == CMD_SPECIAL)) {
00110         QDataStream istream( d->m_packedArgs );
00111         int s_cmd, s_method;
00112         KUrl s_url;
00113         istream >> s_cmd;
00114         istream >> s_url;
00115         istream >> s_method;
00116         // PROPFIND
00117         if ( (s_cmd == 7) && (s_method == (int)KIO::DAV_PROPFIND) ) {
00118             d->m_packedArgs.truncate(0);
00119             QDataStream stream( &d->m_packedArgs, QIODevice::WriteOnly );
00120             stream << (int)7 << d->m_redirectionURL << (int)KIO::DAV_PROPFIND;
00121         }
00122   } else if ( ! d->m_response.setContent( d->str_response, true ) ) {
00123         // An error occurred parsing the XML response
00124         QDomElement root = d->m_response.createElementNS( "DAV:", "error-report" );
00125         d->m_response.appendChild( root );
00126 
00127         QDomElement el = d->m_response.createElementNS( "DAV:", "offending-response" );
00128     QDomText textnode = d->m_response.createTextNode( d->str_response );
00129         el.appendChild( textnode );
00130         root.appendChild( el );
00131     }
00132   // kDebug(7113) << d->m_response.toString();
00133     TransferJob::slotFinished();
00134     d->staticData = d->savedStaticData; // Need to send DAV request to this host too
00135 }
00136 
00137 /* Convenience methods */
00138 
00139 DavJob* KIO::davPropFind( const KUrl& url, const QDomDocument& properties, const QString &depth, JobFlags flags )
00140 {
00141     DavJob *job = DavJobPrivate::newJob(url, (int) KIO::DAV_PROPFIND, properties.toString(), flags);
00142     job->addMetaData( "davDepth", depth );
00143     return job;
00144 }
00145 
00146 
00147 DavJob* KIO::davPropPatch( const KUrl& url, const QDomDocument& properties, JobFlags flags )
00148 {
00149     return DavJobPrivate::newJob(url, (int) KIO::DAV_PROPPATCH, properties.toString(),
00150                                  flags);
00151 }
00152 
00153 DavJob* KIO::davSearch( const KUrl& url, const QString& nsURI, const QString& qName, const QString& query, JobFlags flags )
00154 {
00155   QDomDocument doc;
00156   QDomElement searchrequest = doc.createElementNS( "DAV:", "searchrequest" );
00157   QDomElement searchelement = doc.createElementNS( nsURI, qName );
00158   QDomText text = doc.createTextNode( query );
00159   searchelement.appendChild( text );
00160   searchrequest.appendChild( searchelement );
00161   doc.appendChild( searchrequest );
00162   return DavJobPrivate::newJob(url, KIO::DAV_SEARCH, doc.toString(), flags);
00163 }
00164 
00165 DavJob* KIO::davReport( const KUrl& url, const QString& report, const QString &depth, JobFlags flags )
00166 {
00167     DavJob *job = DavJobPrivate::newJob(url, (int) KIO::DAV_REPORT, report, flags);
00168     job->addMetaData( "davDepth", depth );
00169     return job;
00170 }
00171 
00172 #include "davjob.moc"

KIO

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • 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
  • KUtils
  • Nepomuk
  • Plasma
  •     Sodep
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.9-20090814
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