[PATCH] WevdavJob

Best, Jan-Pascal van j.p.vanbest at tbm.tudelft.nl
Mon Jun 10 09:40:24 BST 2002


Hi all,

As promised, a first attempt to a DavJob class. There are two parts to
this:
- A "generic webdav" special(), with the url and the webdav method as
parameters and the XML request provided on the dataReq() signal.
- The DavJob class itself. I derived it from TransferJob. It sets the
static data that TRansferJob feeds to the kioslave, and when the IOslave
is finished, interprets the results to a QDomDocument for easy use by
the application part.
- Some convenience methods in davjob.cpp for directly accessing certain
webdav
methods. Maybe more derived class will be necessary for specific
functions,
like locking.

I'm appending a patch file after this method, plus the new davjob.h and
davjob.cpp classes. The patch also makes http.h public, since the
application
needs access to the webdav method numbers. 

Issues: 
- Maybe we should publish the HTTPProtocol::HTTPMETHOD constants
  somewhere else without publishing the whole HTTPProtocol?
- I made DavJob a derivative of TransferJob. Another option would
  be to derive it from SimpleJob and have a subjob TransferJob, but
  that would add another layer of indirection. And it's quite simple
  this way, ewbdav request are really a lot like transfers.
- the KIO::davSearch isn't finished yet, I'm still arguing with our
  exchange server about what queries it will accept...

Your comments?

Cheers

Jan-Pascal

Index: kio/kio/Makefile.am
===================================================================
RCS file: /home/kde/kdelibs/kio/kio/Makefile.am,v
retrieving revision 1.191
diff -u -3 -p -r1.191 Makefile.am
--- kio/kio/Makefile.am	2002/05/25 18:04:52	1.191
+++ kio/kio/Makefile.am	2002/06/10 07:56:27
@@ -38,7 +38,7 @@ libksycoca_la_SOURCES = \
 	kautomount.cpp krun.cpp \
 	kfileitem.cpp kdirlister.cpp kimageio.cpp \
 	yacc.c lex.c  \
-	chmodjob.cpp kscan.cpp ktar.cpp kzip.cpp previewjob.cpp
metainfojob.cpp \
+	chmodjob.cpp kscan.cpp ktar.cpp kzip.cpp previewjob.cpp
metainfojob.cpp davjob.cpp \
 	kdatatool.cpp karchive.cpp kfilefilter.cpp \
 	kfilemetainfo.cpp
 
@@ -97,7 +97,7 @@ kioinclude_HEADERS = connection.h \
 	observer.h chmodjob.h uiserver_stub.h \
         kpac.h kmdbase.h authinfo.h \
 	ioslave_defaults.h http_slave_defaults.h previewjob.h
thumbcreator.h \
-	metainfojob.h
+	metainfojob.h davjob.h
 
 # Internal - kprotocolinfofactory.h is old stuff
 noinst_HEADERS = kservicetypefactory.h kservicefactory.h \
Index: kioslave/http/Makefile.am
===================================================================
RCS file: /home/kde/kdelibs/kioslave/http/Makefile.am,v
retrieving revision 1.44
diff -u -3 -p -r1.44 Makefile.am
--- kioslave/http/Makefile.am	2002/05/25 18:00:10	1.44
+++ kioslave/http/Makefile.am	2002/06/10 07:56:27
@@ -25,7 +25,8 @@ kio_http_cache_cleaner_la_SOURCES = http
 kio_http_cache_cleaner_la_LIBADD  = $(LIB_KIO)
 kio_http_cache_cleaner_la_LDFLAGS = -module -avoid-version
 
-noinst_HEADERS = http.h
+# noinst_HEADERS = http.h
+include_HEADERS = http.h
 
 kdelnkdir = $(kde_servicesdir)
 kdelnk_DATA = http_cache_cleaner.desktop http.protocol https.protocol \
Index: kioslave/http/http.cc
===================================================================
RCS file: /home/kde/kdelibs/kioslave/http/http.cc,v
retrieving revision 1.507
diff -u -3 -p -r1.507 http.cc
--- kioslave/http/http.cc	2002/06/06 06:25:08	1.507
+++ kioslave/http/http.cc	2002/06/10 07:56:29
@@ -610,6 +610,27 @@ void HTTPProtocol::davStatList( const KU
   }
 }
 
+void HTTPProtocol::davGeneric( const KURL& url, HTTP_METHOD method )
+{
+  kdDebug(7113) << "(" << m_pid << ") HTTPProtocol::davGeneric " <<
url.url()
+                << endl;
+
+  if ( !checkRequestURL( url ) )
+    return;
+
+  // check to make sure this host supports WebDAV
+  if ( !davHostOk() )
+    return;
+
+  // WebDAV method
+  m_request.method = method;
+  m_request.query = QString::null;
+  m_request.cache = CC_Reload;
+  m_request.doProxy = m_bUseProxy;
+
+  retrieveContent( false );
+}
+
 int HTTPProtocol::codeFromResponse( const QString& response )
 {
   int firstSpace = response.find( ' ' );
@@ -3463,6 +3484,13 @@ void HTTPProtocol::special( const QByteA
       stream >> url;
       davUnlock( url );
       break;
+    }
+    case 7: // Generic WebDAV
+    {
+      KURL url;
+      int method;
+      stream >> url >> method; 
+      davGeneric( url, (HTTP_METHOD) method );
     }
     default:
       // Some command we don't understand.
Index: kioslave/http/http.h
===================================================================
RCS file: /home/kde/kdelibs/kioslave/http/http.h,v
retrieving revision 1.132
diff -u -3 -p -r1.132 http.h
--- kioslave/http/http.h	2002/06/06 06:25:08	1.132
+++ kioslave/http/http.h	2002/06/10 07:56:32
@@ -39,6 +39,7 @@
 
 class DCOPClient;
 class QDomElement;
+class QDomNodeList;
 
 namespace KIO {
     class AuthInfo;
@@ -143,6 +144,9 @@ public:
 
   // ask the host whether it supports WebDAV & cache this info
   bool davHostOk();
+
+  // send generic DAV request
+  void davGeneric( const KURL& url, HTTP_METHOD method );
 
   // Send requests to lock and unlock resources
   void davLock( const KURL& url, const QString& scope,


================= DAVJOB.H ==============================

// -*- c++ -*-
/* This file is part of the KDE libraries
    Copyright (C) 2002 Jan-Pascal van Best <janpascal at vanbest.org>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#ifndef __kio_davjob_h__
#define __kio_davjob_h__

#include <kurl.h>

#include <qobject.h>
#include <qptrlist.h>
#include <qstring.h>
#include <qstringlist.h>
#include <qguardedptr.h>
#include <qdom.h>

#include <sys/types.h>
#include <sys/stat.h>

#include <kio/jobclasses.h>
#include <kio/global.h>

class Observer;
class QTimer;

namespace KIO {

    class Slave;
    class SlaveInterface;

    /**
     * The transfer job pumps data into and/or out of a Slave.
     * Data is sent to the slave on request of the slave (@ref dataReq).
     * If data coming from the slave can not be handled, the
     * reading of data from the slave should be suspended.
     */
    class DavJob : public TransferJob {
    Q_OBJECT

    public:
      DavJob( const KURL& url, int command,
              const QString& request, bool showProgressInfo );

	QDomDocument& response() { return m_response; }

    protected slots:
      virtual void slotFinished();
      virtual void slotData( const QByteArray &data);

    protected:
      bool m_suspended;
      TransferJob *m_subJob;

    private:
	class DavJobPrivate* d;
	QString m_str_response;
	QDomDocument m_response;
   };

   DavJob* davPropPatch( const KURL& url, const QDomDocument&
properties, bool showProgressInfo=true );
   DavJob* davSearch( const KURL &url, const QString& nsURI, const
QString& qName, const QString& query, bool showProgressInfo ); 
};

#endif

================= DAVJOB.CPP ==============================

// -*- c++ -*-
/* This file is part of the KDE libraries
    Copyright (C) 2002 Jan-Pascal van Best <janpascal at vanbest.org>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#include <kurl.h>

#include <qobject.h>
#include <qptrlist.h>
#include <qstring.h>
#include <qstringlist.h>
#include <qguardedptr.h>
#include <qdom.h>

#include <sys/types.h>
#include <sys/stat.h>

#include <kdebug.h>
#include <kio/jobclasses.h>
#include <kio/global.h>
#include <kio/davjob.h>
#include <kio/job.h>
#include <kio/slaveinterface.h>
#include <http.h>

using namespace KIO;

#define KIO_ARGS QByteArray packedArgs; QDataStream stream( packedArgs,
IO_WriteOnly ); stream

DavJob::DavJob( const KURL& url, int command, const QString& request,
bool showProgressInfo )
  : TransferJob( url, KIO::CMD_SPECIAL, QByteArray(), QByteArray(),
showProgressInfo )
{
  // We couldn't set the args when calling the parent constructor,
  // so do it now.
  QDataStream stream( m_packedArgs, IO_WriteOnly );
  stream << (int) 7 << url << command;
  // Same for static data
  staticData = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
request.utf8();
  staticData.truncate( staticData.size() - 1 );
}

void DavJob::slotData( const QByteArray& data ) 
{
  m_str_response.append( QString( data ) );
}

void DavJob::slotFinished()
{
  kdDebug() << "DavJob::slotFinished()" << endl;
  kdDebug() << m_str_response << endl;
	 
  m_response.setContent( m_str_response );
  TransferJob::slotFinished();
}

DavJob* KIO::davPropPatch( const KURL& url, const QDomDocument&
properties, bool showProgressInfo )
{
  return new DavJob( url, (int) HTTPProtocol::DAV_PROPPATCH,
properties.toString(), showProgressInfo );
}

DavJob* KIO::davSearch( const KURL& url, const QString& nsURI, const
QString& qName, const QString& query, bool showProgressInfo )
{
  QDomDocument doc;
  QDomElement searchrequest = doc.createElementNS( "DAV:",
"searchrequest" );
  QDomElement searchelement = doc.createElementNS( nsURI, qName );
  QDomText text = doc.createTextNode( query );
  searchelement.appendChild( text );
  searchrequest.appendChild( searchelement );
  doc.appendChild( searchrequest );
  return new DavJob( url, (int) HTTPProtocol::DAV_SEARCH,
doc.toString(), showProgressInfo );
}





More information about the kfm-devel mailing list