[PATCH] davjob stuff

Best, Jan-Pascal van j.p.vanbest at tbm.tudelft.nl
Thu Jul 4 08:53:47 BST 2002


Hi all,

I've wrapped up the davjob patches. I think they're ready 
for inclusion. This is what this patch does:

- Add a DavJob class in kio/kio/davjob.[h,cpp]. A DavJob is mostly
a TransferJob, but you can give the webdav method to call and
the result is given as a convenient QDomDocument.
- Move definitions of the HTTP_METHOD enum to 
interfaces/kio/http.h which is exported. This is needed
for generic WebDAV calls 
- In HTTPProtocol::davStatList(), cleanup some namespace stuff
- In HTTPProtocol::httpOpen(), for DAV_PROPFIND, set davData 
to true to indicate there's more to come, and read metadata
"davDepth" for the depth: header, if supplied (else use current
intelligence).
- Introduce a special() in http.cc for generic WebDAV actions

any comments or suggestions? Is this ready to check in?

Cheers

Jan-Pascal


=============== kdelibs/interfaces/kio/http.h ==================

/* 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 KIOSLAVE_HTTP_H_
#define KIOSLAVE_HTTP_H_


namespace KIO {

  /** HTTP / DAV method **/
  enum HTTP_METHOD {HTTP_GET, HTTP_PUT, HTTP_POST, HTTP_HEAD,
HTTP_DELETE,
                    HTTP_OPTIONS, DAV_PROPFIND, DAV_PROPPATCH,
DAV_MKCOL,
                    DAV_COPY, DAV_MOVE, DAV_LOCK, DAV_UNLOCK, DAV_SEARCH
};


};

#endif

=============== kdelibs/interfaces/kio/Makefile.am =================

kioincludedir = $(includedir)/kio
kioinclude_HEADERS = http.h

=============== kdelibs/kio/kio/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 method,
                    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* davPropFind( const KURL& url, const QDomDocument& properties,
QString depth, bool showProgressInfo=true );
   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=true ); 

};

#endif

=============== kdelibs/kio/kio/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/http.h>
#include <kio/davjob.h>
#include <kio/job.h>
#include <kio/slaveinterface.h>

using namespace KIO;

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

DavJob::DavJob( const KURL& url, int method, 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 << method;
  // 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, true );
  TransferJob::slotFinished();
}

/* Convenience methods */

DavJob* KIO::davPropFind( const KURL& url, const QDomDocument&
properties, QString depth, bool showProgressInfo )
{
  DavJob *job = new DavJob( url, (int) KIO::DAV_PROPFIND,
properties.toString(), showProgressInfo );
  job->addMetaData( "davDepth", depth );
  return job;
}


DavJob* KIO::davPropPatch( const KURL& url, const QDomDocument&
properties, bool showProgressInfo )
{
  return new DavJob( url, (int) KIO::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, KIO::DAV_SEARCH, doc.toString(),
showProgressInfo );
}


=================== DIFFS ================================

Index: interfaces/Makefile.am
===================================================================
RCS file: /home/kde/kdelibs/interfaces/Makefile.am,v
retrieving revision 1.29
diff -u -3 -p -r1.29 Makefile.am
--- interfaces/Makefile.am2002/05/28 21:02:161.29
+++ interfaces/Makefile.am2002/07/04 05:33:04
@@ -1,4 +1,4 @@
-SUBDIRS = ktexteditor kscript kregexpeditor kmediaplayer
+SUBDIRS = ktexteditor kscript kregexpeditor kmediaplayer kio

 DOXYGEN_REFERENCES = kdecore kdefx kdeui kparts dcop
 DOXYGEN_EXCLUDE = kscript/sample/*

Index: kio/kio/Makefile.am
===================================================================
RCS file: /home/kde/kdelibs/kio/kio/Makefile.am,v
retrieving revision 1.194
diff -u -3 -p -r1.194 Makefile.am
--- kio/kio/Makefile.am2002/06/21 10:43:511.194
+++ kio/kio/Makefile.am2002/07/04 05:33:10
@@ -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 kar.cpp ktar.cpp kzip.cpp previewjob.cpp
metainfojob.cpp \
+chmodjob.cpp kscan.cpp kar.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/http.cc
===================================================================
RCS file: /home/kde/kdelibs/kioslave/http/http.cc,v
retrieving revision 1.518
diff -u -3 -p -r1.518 http.cc
--- kioslave/http/http.cc2002/06/25 21:31:541.518
+++ kioslave/http/http.cc2002/07/04 05:33:15
@@ -522,7 +522,7 @@ void HTTPProtocol::davStatList( const KU
     // We are only after certain features...
     QCString request;
     request = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"
-    "<propfind xmlns:D=\"DAV:\">";
+    "<D:propfind xmlns:D=\"DAV:\">";

     // insert additional XML request from the davRequestResponse
metadata
     if ( hasMetaData( "davRequestResponse" ) )
@@ -542,9 +542,9 @@ void HTTPProtocol::davStatList( const KU
       "<D:supportedlock/>"
       "<D:lockdiscovery/>"
       "<D:resourcetype/>"
-      "</prop>";
+      "</D:prop>";
     }
-    request += "</propfind>";
+    request += "</D:propfind>";

     davSetRequest( request );
   }
@@ -616,6 +616,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( ' ' );
@@ -1881,11 +1902,18 @@ bool HTTPProtocol::httpOpen()
       break;
   case DAV_PROPFIND:
       header = "PROPFIND ";
+      davData = true;
       davHeader = "Depth: ";
-      if ( m_request.davData.depth == 2 )
-        davHeader += "infinity";
-      else
-        davHeader += QString("%1").arg( m_request.davData.depth );
+      if ( hasMetaData( "davDepth" ) ) {
+        kdDebug(7113) << "Reading DAV depth from metadata: " <<
metaData( "davDepth" ) << endl;
+        davHeader += metaData( "davDepth" );
+      } else
+      {
+        if ( m_request.davData.depth == 2 )
+          davHeader += "infinity";
+        else
+          davHeader += QString("%1").arg( m_request.davData.depth );
+      }
       davHeader += "\r\n";
       m_bCachedWrite = false; // Do not put any result in the cache
       break;
@@ -3477,6 +3505,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.135
diff -u -3 -p -r1.135 http.h
--- kioslave/http/http.h2002/06/14 20:08:221.135
+++ kioslave/http/http.h2002/07/04 05:33:15
@@ -36,14 +36,18 @@

 #include <kurl.h>
 #include "kio/tcpslavebase.h"
+#include "kio/http.h"

 class DCOPClient;
 class QDomElement;
+class QDomNodeList;

 namespace KIO {
     class AuthInfo;
 }

+using namespace KIO;
+
 class HTTPProtocol : public QObject, public KIO::TCPSlaveBase
 {
   Q_OBJECT
@@ -59,9 +63,10 @@ public:
   enum HTTP_AUTH   {AUTH_None, AUTH_Basic, AUTH_Digest};

   /** HTTP / DAV method **/
-  enum HTTP_METHOD {HTTP_GET, HTTP_PUT, HTTP_POST, HTTP_HEAD,
HTTP_DELETE,
-                    HTTP_OPTIONS, DAV_PROPFIND, DAV_PROPPATCH,
DAV_MKCOL,
-                    DAV_COPY, DAV_MOVE, DAV_LOCK, DAV_UNLOCK,
DAV_SEARCH };
+  // Removed to interfaces/kio/http.h
+  //enum HTTP_METHOD {HTTP_GET, HTTP_PUT, HTTP_POST, HTTP_HEAD,
HTTP_DELETE,
+  //                  HTTP_OPTIONS, DAV_PROPFIND, DAV_PROPPATCH,
DAV_MKCOL,
+  //                  DAV_COPY, DAV_MOVE, DAV_LOCK, DAV_UNLOCK,
DAV_SEARCH };

   /** State of the current Connection **/
   typedef struct
@@ -142,6 +147,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,




More information about the kfm-devel mailing list