kio
davjob.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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 QByteArray str_response;
00050 };
00051
00052 DavJob::DavJob( const KURL& url, int method, const QString& request, bool showProgressInfo )
00053 : TransferJob( url, KIO::CMD_SPECIAL, QByteArray(), QByteArray(), showProgressInfo )
00054 {
00055 d = new DavJobPrivate;
00056
00057
00058 QDataStream stream( m_packedArgs, IO_WriteOnly );
00059 stream << (int) 7 << url << method;
00060
00061 if ( ! request.isEmpty() && ! request.isNull() ) {
00062 staticData = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + request.utf8();
00063 staticData.truncate( staticData.size() - 1 );
00064 d->savedStaticData = staticData.copy();
00065 }
00066 }
00067
00068 void DavJob::slotData( const QByteArray& data )
00069 {
00070 if(m_redirectionURL.isEmpty() || !m_redirectionURL.isValid() || m_error) {
00071 unsigned int oldSize = d->str_response.size();
00072 d->str_response.resize( oldSize + data.size() );
00073 memcpy( d->str_response.data() + oldSize, data.data(), data.size() );
00074 }
00075 }
00076
00077 void DavJob::slotFinished()
00078 {
00079
00080
00081 if (!m_redirectionURL.isEmpty() && m_redirectionURL.isValid() && (m_command == CMD_SPECIAL)) {
00082 QDataStream istream( m_packedArgs, IO_ReadOnly );
00083 int s_cmd, s_method;
00084 KURL s_url;
00085 istream >> s_cmd;
00086 istream >> s_url;
00087 istream >> s_method;
00088
00089 if ( (s_cmd == 7) && (s_method == (int)KIO::DAV_PROPFIND) ) {
00090 m_packedArgs.truncate(0);
00091 QDataStream stream( m_packedArgs, IO_WriteOnly );
00092 stream << (int)7 << m_redirectionURL << (int)KIO::DAV_PROPFIND;
00093 }
00094 } else if ( ! m_response.setContent( d->str_response, true ) ) {
00095
00096 QDomElement root = m_response.createElementNS( "DAV:", "error-report" );
00097 m_response.appendChild( root );
00098
00099 QDomElement el = m_response.createElementNS( "DAV:", "offending-response" );
00100 QDomText textnode = m_response.createTextNode( d->str_response );
00101 el.appendChild( textnode );
00102 root.appendChild( el );
00103 delete d;
00104 d = 0;
00105 } else {
00106 delete d;
00107 d = 0;
00108 }
00109
00110 TransferJob::slotFinished();
00111 if( d ) staticData = d->savedStaticData.copy();
00112 }
00113
00114
00115
00116
00117 DavJob* KIO::davPropFind( const KURL& url, const QDomDocument& properties, QString depth, bool showProgressInfo )
00118 {
00119 DavJob *job = new DavJob( url, (int) KIO::DAV_PROPFIND, properties.toString(), showProgressInfo );
00120 job->addMetaData( "davDepth", depth );
00121 return job;
00122 }
00123
00124
00125 DavJob* KIO::davPropPatch( const KURL& url, const QDomDocument& properties, bool showProgressInfo )
00126 {
00127 return new DavJob( url, (int) KIO::DAV_PROPPATCH, properties.toString(), showProgressInfo );
00128 }
00129
00130 DavJob* KIO::davSearch( const KURL& url, const QString& nsURI, const QString& qName, const QString& query, bool showProgressInfo )
00131 {
00132 QDomDocument doc;
00133 QDomElement searchrequest = doc.createElementNS( "DAV:", "searchrequest" );
00134 QDomElement searchelement = doc.createElementNS( nsURI, qName );
00135 QDomText text = doc.createTextNode( query );
00136 searchelement.appendChild( text );
00137 searchrequest.appendChild( searchelement );
00138 doc.appendChild( searchrequest );
00139 return new DavJob( url, KIO::DAV_SEARCH, doc.toString(), showProgressInfo );
00140 }
00141
00142 #include "davjob.moc"