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