[PATCH] webdav search

Best, Jan-Pascal van j.p.vanbest at tbm.tudelft.nl
Mon May 6 08:52:12 BST 2002


Oops. It seems the outlook web access cannot make proper attachments
even of text files. I'll just paste the patch here. Beware of line
wrapping.

Jan-Pascal

Index: http.cc
===================================================================
RCS file: /home/kde/kdelibs/kioslave/http/http.cc,v
retrieving revision 1.497
diff -u -3 -p -r1.497 http.cc
--- http.cc	4 May 2002 01:58:25 -0000	1.497
+++ http.cc	6 May 2002 07:12:14 -0000
@@ -459,10 +459,21 @@ void HTTPProtocol::listDir( const KURL& 
   if ( !checkRequestURL( url ) )
     return;
 
-  davStatList( url, false );
+  if ( m_protocol == "webdav" || m_protocol == "webdavs" )
+  {
+    // Maybe it's a disguised SEARCH...
+    QString query = metaData("davSearchQuery");
+    if ( !query.isEmpty() ) 
+    {
+      davStatList( url, STATLIST_SEARCH, query );
+      return;
+    }
+  }
+  
+  davStatList( url, STATLIST_LIST );
 }
 
-void HTTPProtocol::davStatList( const KURL& url, bool stat )
+void HTTPProtocol::davStatList( const KURL& url, const STATLISTMETHOD
method /* = STATLIST_STAT */ , const QString &query /* = QString::null
*/ )
 {
   UDSEntry entry;
   UDSAtom atom;
@@ -471,14 +482,25 @@ void HTTPProtocol::davStatList( const KU
   if ( !davHostOk() )
     return;
 
-  // WebDAV Stat or List...
-  m_request.method = DAV_PROPFIND;
+  m_request.method = method == STATLIST_SEARCH ? DAV_SEARCH :
DAV_PROPFIND;
   m_request.query = QString::null;
   m_request.cache = CC_Reload;
   m_request.doProxy = m_bUseProxy;
-  m_request.davData.depth = stat ? 0 : 1;
-  if (!stat)
+  m_request.davData.depth = method == STATLIST_LIST ? 1 : 0;
+  if (method == STATLIST_LIST)
      m_request.url.adjustPath(+1);
+     
+  if ( method == STATLIST_SEARCH )
+  {
+    QCString request = "<?xml version=\"1.0\"?>\r\n";
+    request.append( "<D:searchrequest xmlns:D=\"DAV:\">\r\n" );
+    request.append( query.utf8() );
+    request.append( "</D:searchrequest>\r\n" );
+
+    // insert the document into the POST buffer, kill trailing zero
byte
+    m_bufPOST = request;
+    if (m_bufPOST.size()) m_bufPOST.truncate( m_bufPOST.size() - 1 );
+  }
 
   retrieveContent( true );
 
@@ -497,7 +519,7 @@ void HTTPProtocol::davStatList( const KU
       KURL thisURL = KURL::decode_string( href.text() );
 
       // don't list the base dir of a listDir()
-      if ( !stat && thisURL.path(+1).length() == url.path(+1).length()
)
+      if ( method==STATLIST_LIST && thisURL.path(+1).length() ==
url.path(+1).length() )
         continue;
 
       atom.m_uds = KIO::UDS_NAME;
@@ -508,7 +530,7 @@ void HTTPProtocol::davStatList( const KU
 
       davParsePropstats( propstats, entry );
 
-      if ( stat )
+      if ( method == STATLIST_STAT )
       {
         // return an item
         statEntry( entry );
@@ -527,7 +549,7 @@ void HTTPProtocol::davStatList( const KU
     }
   }
 
-  if ( stat )
+  if ( method == STATLIST_STAT )
   {
     error( ERR_DOES_NOT_EXIST, url.prettyURL() );
   }
@@ -1215,6 +1326,9 @@ QString HTTPProtocol::davError( int code
     case DAV_LOCK:
       action = i18n( "lock the specified file or directory" );
       break;
+    case DAV_SEARCH:
+      action = i18n( "search in the specified directory" );
+      break;
     case DAV_UNLOCK:
       action = i18n( "unlock the specified file or directory" );
       break;
@@ -1880,6 +1994,11 @@ bool HTTPProtocol::httpOpen()
       davHeader = "Lock-token: " + metaData("davLockToken") + "\r\n";
       m_bCachedWrite = false; // Do not put any result in the cache
       break;
+  case DAV_SEARCH:
+      header = "SEARCH ";
+      davData = true;
+      m_bCachedWrite = false;
+      break;
   }
 
   if ( isSSLTunnelEnabled() )
@@ -2100,17 +2218,29 @@ bool HTTPProtocol::httpOpen()
     if ( m_state.doProxy && !m_bIsTunneled )
       header += proxyAuthenticationHeader();
   }
-
-  // add extra header elements for WebDAV
-  if ( !davHeader.isNull() )
-    header += davHeader;
-
-  if ( m_protocol == "webdav" || m_protocol == "webdavs" )
+  
+  if ( m_protocol == "webdav" || m_protocol == "webdavs" ) 
+  {
     header += davProcessLocks();
+    
+    // add extra webdav headers, if supplied
+    QString davExtraHeader = metaData("dav-header");
+    if ( !davExtraHeader.isEmpty() )
+      davHeader += davExtraHeader;
+
+    // Set content type of webdav data
+    if (davData)
+      davHeader += "Content-Type: text/xml; charset=utf-8\r\n";
+  
+    // add extra header elements for WebDAV
+    if ( !davHeader.isNull() )
+     header += davHeader;
+  }
 
-  if ( !moreData )
+  if ( !moreData && !davData)
     header += "\r\n";  /* end header */
-
+    
   kdDebug(7103) << "(" << m_pid << ") ============ Sending Header:" <<
endl;
 
   QStringList headerOutput = QStringList::split("\r\n", header);
Index: http.h
===================================================================
RCS file: /home/kde/kdelibs/kioslave/http/http.h,v
retrieving revision 1.129
diff -u -3 -p -r1.129 http.h
--- http.h	4 May 2002 05:33:05 -0000	1.129
+++ http.h	6 May 2002 07:12:14 -0000
@@ -61,7 +61,7 @@ public:
   /** 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_COPY, DAV_MOVE, DAV_LOCK, DAV_UNLOCK,
DAV_SEARCH };
 
   /** State of the current Connection **/
   typedef struct
@@ -134,7 +134,7 @@ public:
                     bool _resume );
 
 //----------------- Re-implemented methods for WebDAV -----------
-  virtual void listDir( const KURL& url );
+  virtual void listDir( const KURL& url ); // For the SEARCH method,
provide metadata "davSearchQuery"
   virtual void mkdir( const KURL& url, int _permissions );
 
   virtual void rename( const KURL& src, const KURL& dest, bool
overwrite );
@@ -237,8 +237,10 @@ protected:
 
   /**
    * Performs a WebDAV stat or list
+   * query is only relevant if method==STATLIST_SEARCH
    */
-  void davStatList( const KURL& url, bool stat = true );
+  enum STATLISTMETHOD { STATLIST_STAT, STATLIST_LIST, STATLIST_SEARCH
};
+  void davStatList( const KURL& url, STATLISTMETHOD method =
STATLIST_STAT, const QString &query = QString::null );
   void davParsePropstats( const QDomNodeList& propstats, KIO::UDSEntry&
entry );
   void davParseActiveLocks( const QDomNodeList& activeLocks,
                             uint& lockCount );
Index: README.webdav
===================================================================
RCS file: /home/kde/kdelibs/kioslave/http/README.webdav,v
retrieving revision 1.3
diff -u -3 -p -r1.3 README.webdav
--- README.webdav	20 Jan 2002 12:15:09 -0000	1.3
+++ README.webdav	6 May 2002 07:12:14 -0000
@@ -26,6 +26,12 @@ are passed as element davSource.
 
 Content languages are passed as element davContentLanguage.
 
+Extra webdav headers are passed as metadata element dav-header
+
+For doing a webdav SEARCH, use listDir() and set the metadata element 
+davSearchQuery to the search query. The root element of this query
should be like
+<d:basicsearch> or <d:sql>.
+
 === CREATING A LOCK ===
 To create a lock, call a special request, with the following data:
 








-------------- next part --------------
A non-text attachment was scrubbed...
Name: winmail.dat
Type: application/ms-tnef
Size: 5570 bytes
Desc: not available
URL: <https://mail.kde.org/mailman/private/kfm-devel/attachments/20020506/a6a54cde/attachment.bin>


More information about the kfm-devel mailing list