kio Library API Documentation

davjob.cpp

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., 59 Temple Place - Suite 330, 00018 Boston, MA 02111-1307, USA. 00019 */ 00020 00021 #include <kurl.h> 00022 00023 #include <qobject.h> 00024 #include <qptrlist.h> 00025 #include <qstring.h> 00026 #include <qstringlist.h> 00027 #include <qguardedptr.h> 00028 #include <qdom.h> 00029 00030 #include <sys/types.h> 00031 #include <sys/stat.h> 00032 00033 #include <kdebug.h> 00034 #include <kio/jobclasses.h> 00035 #include <kio/global.h> 00036 #include <kio/http.h> 00037 #include <kio/davjob.h> 00038 #include <kio/job.h> 00039 #include <kio/slaveinterface.h> 00040 00041 #define KIO_ARGS QByteArray packedArgs; QDataStream stream( packedArgs, IO_WriteOnly ); stream 00042 00043 using namespace KIO; 00044 00045 class DavJob::DavJobPrivate 00046 { 00047 public: 00048 QByteArray savedStaticData; 00049 }; 00050 00051 DavJob::DavJob( const KURL& url, int method, const QString& request, bool showProgressInfo ) 00052 : TransferJob( url, KIO::CMD_SPECIAL, QByteArray(), QByteArray(), showProgressInfo ) 00053 { 00054 d = new DavJobPrivate; 00055 // We couldn't set the args when calling the parent constructor, 00056 // so do it now. 00057 QDataStream stream( m_packedArgs, IO_WriteOnly ); 00058 stream << (int) 7 << url << method; 00059 // Same for static data 00060 if ( ! request.isEmpty() && ! request.isNull() ) { 00061 staticData = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + request.utf8(); 00062 staticData.truncate( staticData.size() - 1 ); 00063 d->savedStaticData = staticData.copy(); 00064 } 00065 } 00066 00067 void DavJob::slotData( const QByteArray& data ) 00068 { 00069 if(m_redirectionURL.isEmpty() || !m_redirectionURL.isValid() || m_error) 00070 m_str_response.append( QString( data ) ); 00071 } 00072 00073 void DavJob::slotFinished() 00074 { 00075 // kdDebug() << "DavJob::slotFinished()" << endl; 00076 // kdDebug() << m_str_response << endl; 00077 if (!m_redirectionURL.isEmpty() && m_redirectionURL.isValid() && (m_command == CMD_SPECIAL)) { 00078 QDataStream istream( m_packedArgs, IO_ReadOnly ); 00079 int s_cmd, s_method; 00080 KURL s_url; 00081 istream >> s_cmd; 00082 istream >> s_url; 00083 istream >> s_method; 00084 // PROPFIND 00085 if ( (s_cmd == 7) && (s_method == (int)KIO::DAV_PROPFIND) ) { 00086 m_packedArgs.truncate(0); 00087 QDataStream stream( m_packedArgs, IO_WriteOnly ); 00088 stream << (int)7 << m_redirectionURL << (int)KIO::DAV_PROPFIND; 00089 } 00090 } else if ( ! m_response.setContent( m_str_response, true ) ) { 00091 // An error occurred parsing the XML response 00092 QDomElement root = m_response.createElementNS( "DAV:", "error-report" ); 00093 m_response.appendChild( root ); 00094 00095 QDomElement el = m_response.createElementNS( "DAV:", "offending-response" ); 00096 QDomText textnode = m_response.createTextNode( m_str_response ); 00097 el.appendChild( textnode ); 00098 root.appendChild( el ); 00099 delete d; // Should be in virtual destructor 00100 d = 0; 00101 } else { 00102 delete d; // Should be in virtual destructor 00103 d = 0; 00104 } 00105 00106 // kdDebug() << m_response.toString() << endl; 00107 TransferJob::slotFinished(); 00108 if( d ) staticData = d->savedStaticData.copy(); // Need to send DAV request to this host too 00109 } 00110 00111 /* Convenience methods */ 00112 00113 // KDE 4: Make it const QString & 00114 DavJob* KIO::davPropFind( const KURL& url, const QDomDocument& properties, QString depth, bool showProgressInfo ) 00115 { 00116 DavJob *job = new DavJob( url, (int) KIO::DAV_PROPFIND, properties.toString(), showProgressInfo ); 00117 job->addMetaData( "davDepth", depth ); 00118 return job; 00119 } 00120 00121 00122 DavJob* KIO::davPropPatch( const KURL& url, const QDomDocument& properties, bool showProgressInfo ) 00123 { 00124 return new DavJob( url, (int) KIO::DAV_PROPPATCH, properties.toString(), showProgressInfo ); 00125 } 00126 00127 DavJob* KIO::davSearch( const KURL& url, const QString& nsURI, const QString& qName, const QString& query, bool showProgressInfo ) 00128 { 00129 QDomDocument doc; 00130 QDomElement searchrequest = doc.createElementNS( "DAV:", "searchrequest" ); 00131 QDomElement searchelement = doc.createElementNS( nsURI, qName ); 00132 QDomText text = doc.createTextNode( query ); 00133 searchelement.appendChild( text ); 00134 searchrequest.appendChild( searchelement ); 00135 doc.appendChild( searchrequest ); 00136 return new DavJob( url, KIO::DAV_SEARCH, doc.toString(), showProgressInfo ); 00137 } 00138 00139 #include "davjob.moc"
KDE Logo
This file is part of the documentation for kio Library Version 3.4.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Apr 12 23:09:02 2005 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003