Esempio n. 1
0
 /**
  * Parses the request body
  */
 protected function __construct()
 {
     parent::__construct();
     // Get and parse the input (= request body)
     $input = $this->inputstring();
     if (!strlen($input)) {
         throw new DAV_Status(DAV::HTTP_BAD_REQUEST, 'Missing required request entity.');
     }
     $document = new DOMDocument();
     if (preg_match('/xmlns:[a-zA-Z0-9]*=""/', $input) || !@$document->loadXML($input, LIBXML_NOCDATA | LIBXML_NOENT | LIBXML_NSCLEAN | LIBXML_NOWARNING | LIBXML_NOERROR)) {
         throw new DAV_Status(DAV::HTTP_BAD_REQUEST, 'Request body is not well-formed XML.');
     }
     // Determine the type of REPORT request
     $documentElement = $document->documentElement;
     $reportType = $documentElement->namespaceURI . ' ' . $documentElement->localName;
     $this->type = @self::$SUPPORTED_REPORTS[$reportType];
     if (!$this->type) {
         throw new DAV_Status(DAV::HTTP_UNPROCESSABLE_ENTITY, 'Unsupported REPORT type.');
     }
     $xpath = new DOMXPath($document);
     $xpath->registerNamespace('D', 'DAV:');
     // Each REPORT type has its own method to parse the request
     $parse = 'parse_' . $this->type;
     $this->{$parse}($document, $xpath);
 }
Esempio n. 2
0
 /**
  * Enter description here...
  *
  * @throws DAV_Status
  */
 protected function __construct()
 {
     parent::__construct();
     $this->init_timeout();
     $input = $this->inputstring();
     if (empty($input)) {
         return;
     }
     // New lock!
     $this->newlock = true;
     $document = new DOMDocument();
     if (preg_match('/xmlns:[a-zA-Z0-9]*=""/', $input) || !@$document->loadXML($input, LIBXML_NOCDATA | LIBXML_NOENT | LIBXML_NSCLEAN | LIBXML_NOWARNING | LIBXML_NOERROR)) {
         throw new DAV_Status(DAV::HTTP_BAD_REQUEST, 'Request body is not well-formed XML.');
     }
     $xpath = new DOMXPath($document);
     $xpath->registerNamespace('D', 'DAV:');
     if ((int) $xpath->evaluate('count(/D:lockinfo/D:lockscope/D:shared)') > 0) {
         throw new DAV_Status(DAV::HTTP_NOT_IMPLEMENTED, 'Shared locks are not supported.');
     } elseif ((int) $xpath->evaluate('count(/D:lockinfo/D:lockscope/D:exclusive)') !== 1) {
         throw new DAV_Status(DAV::HTTP_BAD_REQUEST, 'No <lockscope/> element in LOCK request, hmm.');
     }
     if ((int) $xpath->evaluate('count(/D:lockinfo/D:locktype/D:write)') !== 1) {
         throw new DAV_Status(DAV::HTTP_UNPROCESSABLE_ENTITY, 'Unknown lock type in request body');
     }
     $ownerlist = $xpath->query('/D:lockinfo/D:owner');
     if ($ownerlist->length) {
         $ownerxml = '';
         $ownerchildnodes = $ownerlist->item(0)->childNodes;
         for ($i = 0; $child = $ownerchildnodes->item($i); $i++) {
             $ownerxml .= DAV::recursiveSerialize($child);
         }
         $this->owner = trim($ownerxml);
     }
 }
Esempio n. 3
0
 /**
  * Enter description here...
  *
  * @throws DAV_Status
  */
 protected function __construct()
 {
     parent::__construct();
     // Parse the Timeout: request header:
     if (!isset($_SERVER['HTTP_LOCK_TOKEN']) || !preg_match('@^\\s*<([^>]+)>\\s*$@', $_SERVER['HTTP_LOCK_TOKEN'], $matches)) {
         throw new DAV_Status(DAV::HTTP_BAD_REQUEST, 'Missing required Lock-Token: header.');
     }
     $this->locktoken = $matches[1];
 }
 /**
  * Constructor.
  */
 protected function __construct()
 {
     parent::__construct();
     /*
      * RFC4918 §9.1:
      * A client may choose not to submit a request body.  An empty PROPFIND
      * request body MUST be treated as if it were an 'allprop' request.
      */
     $input = $this->inputstring();
     if (!strlen($input)) {
         $this->requestType = 'allprop';
         return;
     }
     $document = new DOMDocument();
     if (preg_match('/xmlns:[a-zA-Z0-9]*=""/', $input) || !@$document->loadXML($input, LIBXML_NOCDATA | LIBXML_NOENT | LIBXML_NSCLEAN)) {
         throw new DAV_Status(DAV::HTTP_BAD_REQUEST, 'Request body is not well-formed XML.');
     }
     $xpath = new DOMXPath($document);
     $xpath->registerNamespace('D', 'DAV:');
     if ($xpath->evaluate('count(/D:propfind/D:propname)')) {
         $this->requestType = 'propname';
     } elseif ($xpath->evaluate('count(/D:propfind/D:prop)')) {
         $this->requestType = 'prop';
         $nodelist = $xpath->query('/D:propfind/D:prop/*');
         for ($i = 0; $i < $nodelist->length; $i++) {
             $element = $nodelist->item($i);
             $this->props[] = "{$element->namespaceURI} {$element->localName}";
         }
     } elseif ($xpath->evaluate('count(/D:propfind/D:allprop)')) {
         $this->requestType = 'allprop';
         $nodelist = $xpath->query('/D:propfind/D:include/*');
         for ($i = 0; $i < $nodelist->length; $i++) {
             $element = $nodelist->item($i);
             $this->props[] = "{$element->namespaceURI} {$element->localName}";
         }
     } else {
         throw new DAV_Status(DAV::HTTP_UNPROCESSABLE_ENTITY, 'No request type in XML request body.');
     }
     $this->props = array_unique($this->props);
 }
 /**
  * Parse the request body
  */
 protected function __construct()
 {
     parent::__construct();
     $input = $this->inputString();
     $document = new DOMDocument();
     if (preg_match('/xmlns:[a-zA-Z0-9]*=""/', $input) || !@$document->loadXML($input, LIBXML_NOCDATA | LIBXML_NOENT | LIBXML_NSCLEAN | LIBXML_NOWARNING | LIBXML_NOERROR)) {
         throw new DAV_Status(DAV::HTTP_BAD_REQUEST, 'Request body is not well-formed XML.');
     }
     $xpath = new DOMXPath($document);
     $xpath->registerNamespace('D', 'DAV:');
     $nodelist = $xpath->query('/D:propertyupdate/*/D:prop/*');
     for ($i = 0; $i < $nodelist->length; $i++) {
         $element = $nodelist->item($i);
         if ('DAV:' !== $element->parentNode->parentNode->namespaceURI) {
             continue;
         }
         if ('remove' === $element->parentNode->parentNode->localName) {
             $this->props["{$element->namespaceURI} {$element->localName}"] = null;
         } else {
             $xml = '';
             for ($j = 0; $child = $element->childNodes->item($j); $j++) {
                 $xml .= DAV::recursiveSerialize($child);
             }
             $this->props["{$element->namespaceURI} {$element->localName}"] = $xml;
         }
     }
     //  $nodelist = $xpath->query('/D:propertyupdate/D:remove/D:prop/*');
     //  for ($i = 0; $i < $nodelist->length; $i++) {
     //    $element = $nodelist->item($i);
     //        $xml = '';
     //    for ($j = 0; $child = $element->childNodes->item($j); $j++)
     //      $xml .= DAV::recursiveSerialize($child);
     //    $this->props["{$element->namespaceURI} {$element->localName}"] = null;
     //  }
     // DEBUG
 }
Esempio n. 6
0
 /**
  * Enter description here...
  *
  * @throws DAV_Status
  */
 protected function __construct()
 {
     parent::__construct();
 }
Esempio n. 7
0
 /**
  * Parses the XML in the request body
  */
 protected function __construct()
 {
     parent::__construct();
     //  if ( !isset($_SERVER['CONTENT_LENGTH']) ||
     //       !$_SERVER['CONTENT_LENGTH'] )
     //    throw new DAV_Status(
     //      DAV::HTTP_UNPROCESSABLE_ENTITY,
     //      'Couldn\'t find a proppatch request body.'
     //    );
     // DEBUG
     $input = $this->inputstring();
     $document = new DOMDocument();
     if (preg_match('/xmlns:[a-zA-Z0-9]*=""/', $input) || !$document->loadXML($input, LIBXML_NOCDATA | LIBXML_NOENT | LIBXML_NSCLEAN | LIBXML_NOWARNING)) {
         throw new DAV_Status(DAV::HTTP_BAD_REQUEST, 'Request body is not well-formed XML.');
     }
     $xpath = new DOMXPath($document);
     $xpath->registerNamespace('D', 'DAV:');
     $nodelist = $xpath->query('/D:acl/D:ace');
     foreach ($nodelist as $ace) {
         // Find the principal element:
         $principal = $xpath->query("D:principal/* | D:invert/D:principal/*", $ace);
         if (1 !== $principal->length) {
             throw new DAV_Status(DAV::HTTP_UNPROCESSABLE_ENTITY, $principal->length . ' principals in ACE');
         }
         $principal = $principal->item(0);
         $p_invert = 'invert' === $principal->parentNode->parentNode->localName;
         $p = $principal->namespaceURI . ' ' . $principal->localName;
         if ('DAV: href' === $p) {
             $p_principal = trim($principal->textContent);
         } elseif (isset(DAVACL::$PRINCIPALS[$p])) {
             $p_principal = $p;
         } elseif ('DAV: property' === $p) {
             $e = $principal->firstChild;
             while ($e && XML_ELEMENT_NODE !== $e->nodeType) {
                 $e = $e->nextSibling;
             }
             if (!$e) {
                 throw new DAV_Status(DAV::HTTP_UNPROCESSABLE_ENTITY, "Missing property in ACE principal");
             }
             $p_principal = $e->namespaceURI . ' ' . $e->localName;
         } else {
             throw new DAV_Status(DAV::HTTP_UNPROCESSABLE_ENTITY, "Don't understand principal element '{$p}'");
         }
         // Find the grant or deny part:
         $granted = $xpath->query('D:grant/D:privilege/*', $ace);
         $denied = $xpath->query('D:deny/D:privilege/*', $ace);
         if ($granted->length && $denied->length or !$granted->length && !$denied->length) {
             throw new DAV_Status(DAV::HTTP_UNPROCESSABLE_ENTITY, 'Both grant and deny elements in ACE, or no privileges at all.');
         }
         if ($granted->length) {
             $privileges = $granted;
             $p_deny = false;
         } else {
             $privileges = $denied;
             $p_deny = true;
         }
         $p_privileges = array();
         foreach ($privileges as $p) {
             $p_privileges[] = $p->namespaceURI . ' ' . $p->localName;
         }
         // Finally, we look for the DAV:protected and DAV:inherited elements:
         $nodelist = $xpath->query('/D:ace/D:protected | /D:ace/D:inherited', $ace);
         if ($nodelist->length) {
             throw new DAV_Status(DAV::HTTP_UNPROCESSABLE_ENTITY, 'Cannot set protected or inherited ACEs');
         }
         $this->aces[] = new DAVACL_Element_ace($p_principal, $p_invert, $p_privileges, $p_deny);
     }
 }
Esempio n. 8
0
 /**
  * Makes sure the Content-Range header is parsed
  *
  * @throws DAV_Status
  */
 protected function __construct()
 {
     parent::__construct();
     $this->init_range();
 }