[PATCH] WevdavJob
Best, Jan-Pascal van
j.p.vanbest at tbm.tudelft.nl
Tue Jun 11 09:21:38 BST 2002
> > The others will probably have something to say about making
> http.h public,
> > though.
>
> Yes, making http.h public is not an option. Better take them
> out and put them
> in a header file of their own. (Or put them in a suitable
> header file of kio if you can find one)
I could think of two options for this:
- job.h, but it's a bit weird to have http.h include job.h
- global.h, not really fitting either.
If we make a new header file, for the moment containing
only the HTTP_METHOD enum, I think it should be
named http rather than webdav, since it regards http
methods, too. I added a new dir kio under
kdelibs/interfaces/kio, that only contains http.h
(and Makefile.am), since http.h (in its exported version)
is needed by both davjob and by applications, if they use
DavJob without the convenience methods.
DavJob itself is the same as in the previous patch, with
the exception that DavJob::slotFinished now properly
parses XML namespaces.
Your comments?
Cheers
Jan-Pascal
--
Jan-Pascal van Best
Delft University of Technology
http://www.tbm.tudelft.nl/webstaf/janb/index.htm
Following:
- Patch to kdelibs
- kdelibs/interfaces/kio/http.h
- kdelibs/interfaces/kio/Makefile.am
- kdelibs/kio/kio/davjob.h
- kdelibs/kio/kio/davjob.cpp
============== PATCH ==============
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.am 2002/05/28 21:02:16 1.29
+++ interfaces/Makefile.am 2002/06/11 07:50:28
@@ -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.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/11 07:50:31
@@ -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/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/11 07:50:32
@@ -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/11 07:50:35
@@ -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
@@ -143,6 +148,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,
============== kdelibs/interfaces/kio/Makefile.am ==============
kioincludedir = $(includedir)/kio
kioinclude_HEADERS = http.h
============== kdelibs/interfaces/kio/http.h ==============
/*
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/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* 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
============== 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();
}
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 );
}
More information about the kfm-devel
mailing list