Author: ts
Date: Wed Sep 19 15:46:38 2007
New Revision: 6200

Log:
- Completed parsing of LOCK request.
- Added results.

Added:
    trunk/Webdav/tests/clients/rfc/lock_1/request/result.ser   (with props)
    trunk/Webdav/tests/clients/rfc/lock_2/request/result.ser   (with props)
    trunk/Webdav/tests/clients/rfc/lock_3/request/result.ser   (with props)
Modified:
    trunk/Webdav/src/transport.php

Modified: trunk/Webdav/src/transport.php
==============================================================================
--- trunk/Webdav/src/transport.php [iso-8859-1] (original)
+++ trunk/Webdav/src/transport.php [iso-8859-1] Wed Sep 19 15:46:38 2007
@@ -29,6 +29,7 @@
         'Depth'       => 'HTTP_DEPTH',
         'Destination' => 'HTTP_DESTINATION',
         'Overwrite'   => 'HTTP_OVERWRITE',
+        'Timeout'     => 'HTTP_TIMEOUT',
     );
 
     /**
@@ -84,6 +85,27 @@
     }
 
     /**
+     * Returns a DOMDocument from the given XML.
+     * Creates a new DOMDocument and loads the given XML string with settings
+     * appropriate to work with it.
+     * 
+     * @param sting $xml 
+     * @return DOMDocument|false
+     */
+    protected function loadDom( $xml )
+    {
+        $dom = new DOMDocument();
+        if ( $dom->loadXML(
+                $xml,
+                LIBXML_NOWARNING | LIBXML_NSCLEAN | LIBXML_NOBLANKS
+             ) === false )
+        {
+            return false;
+        }
+        return $dom;
+    }
+
+    /**
      * Returns an array with the given headers.
      * Checks for the availability of headers in $headerNamess, given as an 
array
      * of header names, and parses them according to their format. 
@@ -173,8 +195,7 @@
             return $request;
         }
 
-        $dom = new DOMDocument();
-        if ( $dom->loadXML( $body, LIBXML_NOWARNING | LIBXML_NSCLEAN | 
LIBXML_NOBLANKS ) === false )
+        if ( ( $dom = $this->loadDom( $body ) ) === false )
         {
             throw new ezcWebdavInvalidRequestBodyException(
                 'COPY',
@@ -252,7 +273,68 @@
      */
     protected function parseLockRequest( $uri, $body )
     {
-        return new ezcWebdavLockRequest( $uri );
+        $request = new ezcWebdavLockRequest( $uri );
+
+        $request->setHeaders(
+            $this->parseHeaders(
+                array( 'Depth', 'Timeout' )
+            )
+        );
+
+        if ( trim( $body ) === '' )
+        {
+            return $request;
+        }
+
+        if ( ( $dom = $this->loadDom( $body ) ) === false )
+        {
+            throw new ezcWebdavInvalidRequestBodyException(
+                'LOCK',
+                "Could not open XML as DOMDocument: '{$body}'."
+            );
+        }
+        
+        if ( $dom->documentElement->localName !== 'lockinfo' )
+        {
+            throw new ezcWebdavInvalidRequestBodyException(
+                'LOCK',
+                "Expected XML element <lockinfo />, received 
<{$dom->documentElement->localName} />."
+            );
+        }
+
+        $lockTypeElements  = $dom->documentElement->getElementsByTagnameNS( 
'DAV:', 'locktype' );
+        $lockScopeElements = $dom->documentElement->getElementsByTagnameNS( 
'DAV:', 'lockscope' );
+        $ownerElements     = $dom->documentElement->getElementsByTagnameNS( 
'DAV:', 'owner' );
+
+        if ( $lockTypeElements->length === 0 )
+        {
+            throw new ezcWebdavInvalidRequestBodyException(
+                'LOCK',
+                "Expected XML element <locktype /> as child of <lockinfo /> in 
namespace DAV: which was not found."
+            );
+        }
+        if ( $lockScopeElements->length === 0 )
+        {
+            throw new ezcWebdavInvalidRequestBodyException(
+                'LOCK',
+                "Expected XML element <lockscope /> as child of <lockinfo /> 
in namespace DAV: which was not found."
+            );
+        }
+
+        // @TODO is the following not restrictive enough?
+        $request->lockInfo = new ezcWebdavRequestLockInfoContent(
+            ( $lockScopeElements->item( 0 )->firstChild->localName === 
'exclusive'
+                ? ezcWebdavLockRequest::SCOPE_EXCLUSIVE
+                : ezcWebdavLockRequest::SCOPE_SHARED ),
+            ( $lockTypeElements->item( 0 )->firstChild->localName === 'read'
+                ? ezcWebdavLockRequest::TYPE_READ
+                : ezcWebdavLockRequest::TYPE_WRITE ),
+            ( $ownerElements->length > 0 
+                ? $ownerElements->item( 0 )->textContent
+                : null )
+        );
+
+        return $request;
     }
 
     // PROPFIND
@@ -278,8 +360,7 @@
             )
         );
 
-        $dom = new DOMDocument();
-        if ( $dom->loadXML( $body, LIBXML_NOWARNING | LIBXML_NSCLEAN | 
LIBXML_NOBLANKS ) === false )
+        if ( ( $dom = $this->loadDom( $body ) ) === false )
         {
             throw new ezcWebdavInvalidRequestBodyException(
                 'PROPFIND',

Added: trunk/Webdav/tests/clients/rfc/lock_1/request/result.ser
==============================================================================
Binary file - no diff available.

Propchange: trunk/Webdav/tests/clients/rfc/lock_1/request/result.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: trunk/Webdav/tests/clients/rfc/lock_2/request/result.ser
==============================================================================
Binary file - no diff available.

Propchange: trunk/Webdav/tests/clients/rfc/lock_2/request/result.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: trunk/Webdav/tests/clients/rfc/lock_3/request/result.ser
==============================================================================
Binary file - no diff available.

Propchange: trunk/Webdav/tests/clients/rfc/lock_3/request/result.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream


-- 
svn-components mailing list
[EMAIL PROTECTED]
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to